Files
.github
admin
docs
install
pages_template
qrcode
scan
system
autoload
PEAR2
mail
Admin.php
App.php
Balance.php
File.php
Hookers.php
Http.php
Lang.php
Log.php
Message.php
Mikrotik.php
Package.php
Paginator.php
Parsedown.php
Password.php
Text.php
Timezone.php
User.php
Validator.php
index.html
cache
controllers
devices
lan
paymentgateway
plugin
uploads
vendor
.htaccess
api.php
boot.php
composer.json
composer.lock
cron.php
cron_reminder.php
index.html
orm.php
updates.json
ui
.gitignore
.htaccess_firewall
CHANGELOG.md
Dockerfile
LICENSE
README.md
composer.json
config.sample.php
docker-compose.example.yml
favicon.ico
index.php
init.php
radius.php
update.php
version.json
mitrobill/system/autoload/Lang.php

261 lines
7.3 KiB
PHP
Raw Normal View History

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;
2024-04-21 20:25:59 +07:00
if(is_array($_SESSION['Lang'])){
$_L = array_merge($_L, $_SESSION['Lang']);
}
2024-02-21 11:54:22 +07:00
$key = preg_replace('/\s+/', ' ', $key);
2024-02-13 13:54:01 +07:00
if (!empty($_L[$key])) {
return $_L[$key];
}
$val = $key;
2024-02-19 09:52:36 +07:00
$key = Lang::sanitize($key);
2024-02-13 17:41:55 +07:00
if (isset($_L[$key])) {
return $_L[$key];
2024-02-19 14:24:34 +07:00
} else if (isset($_L[$key])) {
2024-02-13 13:54:01 +07:00
return $_L[$key];
} else {
$iso = Lang::getIsoLang()[$config['language']];
2024-02-19 14:24:34 +07:00
if (empty($iso)) {
2024-02-13 17:41:55 +07:00
return $val;
}
2024-02-19 14:24:34 +07:00
if (!empty($iso) && !empty($val)) {
2024-02-13 13:54:01 +07:00
$temp = Lang::translate($val, $iso);
2024-02-19 14:24:34 +07:00
if (!empty($temp)) {
2024-02-13 13:54:01 +07:00
$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;
}
}
2024-02-19 14:24:34 +07:00
public static function sanitize($str)
{
2024-02-19 09:52:36 +07:00
return preg_replace("/[^A-Za-z0-9]/", '_', $str);;
}
2024-02-19 14:24:34 +07:00
public static function getIsoLang()
{
2024-02-13 13:54:01 +07:00
global $isolang;
2024-02-19 14:24:34 +07:00
if (empty($isolang) || count($isolang) == 0) {
$isolang = json_decode(file_get_contents(File::pathFixer("system/lan/country.json")), true);
2024-02-13 13:54:01 +07:00
}
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-19 14:24:34 +07:00
public static function timeElapsed($datetime, $full = false)
{
2024-06-19 15:25:58 +07:00
$now = new DateTime(date("Y-m-d H:i:s"));
2024-02-19 14:24:34 +07:00
$ago = new DateTime($datetime);
$diff = $now->diff($ago);
$diff->w = floor($diff->d / 7);
$diff->d -= $diff->w * 7;
$string = array(
'y' => Lang::T('year'),
'm' => Lang::T('month'),
'w' => Lang::T('week'),
'd' => Lang::T('day'),
'h' => Lang::T('hour'),
'i' => Lang::T('minute'),
's' => Lang::T('second'),
);
foreach ($string as $k => &$v) {
if ($diff->$k) {
2024-06-25 14:14:30 +07:00
$v = $diff->$k . ' ' . $v . ($diff->$k > 1 ? '' : '');
2024-02-19 14:24:34 +07:00
} else {
unset($string[$k]);
2024-02-07 13:32:33 +07:00
}
2024-02-19 14:24:34 +07:00
}
2024-06-19 15:25:58 +07:00
$when = "";
if(time()>strtotime($datetime)){
$when = Lang::T('ago');
}else{
2024-06-20 14:02:36 +07:00
$when = '';
2024-06-19 15:25:58 +07:00
}
2024-02-19 14:24:34 +07:00
if (!$full)
$string = array_slice($string, 0, 1);
2024-06-20 14:02:36 +07:00
if($string){
if(empty($when)){
return '<b>'. implode(', ', $string) .'</b>';
}else{
return implode(', ', $string) .' '. $when;
}
}else{
return Lang::T('just now');
}
2024-02-07 13:32:33 +07:00
}
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
2024-02-19 14:24:34 +07:00
public static function randomUpLowCase($text)
{
2023-10-18 17:23:47 +07:00
$jml = strlen($text);
$result = '';
2024-02-19 14:24:34 +07:00
for ($i = 0; $i < $jml; $i++) {
if (rand(0, 99) % 2) {
$result .= strtolower(substr($text, $i, 1));
} else {
$result .= substr($text, $i, 1);
2023-10-18 17:23:47 +07:00
}
}
return $result;
}
2024-01-16 10:32:59 +07:00
/**
* $pad_type
* 0 Left
* 1 right
* 2 center
* */
2024-02-19 14:24:34 +07:00
public static function pad($text, $pad_string = ' ', $pad_type = 0)
{
2024-01-16 10:32:59 +07:00
global $config;
$cols = 37;
2024-02-19 14:24:34 +07:00
if ($config['printer_cols']) {
2024-01-16 10:32:59 +07:00
$cols = $config['printer_cols'];
}
2024-01-16 11:41:12 +07:00
$text = trim($text);
$texts = explode("\n", $text);
2024-02-19 14:24:34 +07:00
if (count($texts) > 1) {
2024-01-16 11:41:12 +07:00
$text = '';
2024-02-19 14:24:34 +07:00
foreach ($texts as $t) {
$text .= self::pad(trim($t), $pad_string, $pad_type) . "\n";
2024-01-16 11:41:12 +07:00
}
return $text;
2024-02-19 14:24:34 +07:00
} else {
2024-01-16 11:41:12 +07:00
return str_pad(trim($text), $cols, $pad_string, $pad_type);
}
2024-01-16 10:32:59 +07:00
}
2024-02-19 14:24:34 +07:00
public static function pads($textLeft, $textRight, $pad_string = ' ')
{
2024-01-16 10:32:59 +07:00
global $config;
$cols = 37;
2024-02-19 14:24:34 +07:00
if ($config['printer_cols']) {
2024-01-16 10:32:59 +07:00
$cols = $config['printer_cols'];
}
2024-02-19 14:24:34 +07:00
return $textLeft . str_pad($textRight, $cols - strlen($textLeft), $pad_string, 0);
2024-01-16 10:32:59 +07:00
}
2024-02-13 13:54:01 +07:00
2024-02-19 14:24:34 +07:00
public static function translate($txt, $to = 'id')
{
2024-02-13 13:54:01 +07:00
$ch = curl_init();
2024-02-19 14:24:34 +07:00
curl_setopt($ch, CURLOPT_URL, "https://translate.google.com/m?hl=en&sl=en&tl=$to&ie=UTF-8&prev=_m&q=" . urlencode($txt));
2024-02-13 13:54:01 +07:00
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-19 14:24:34 +07:00
curl_setopt($ch, CURLOPT_HEADER, 0);
$hasil = curl_exec($ch);
2024-02-13 13:54:01 +07:00
curl_close($ch);
$temp = explode('<div class="result-container">', $hasil);
2024-02-19 14:24:34 +07:00
if (count($temp) > 0) {
2024-02-13 13:54:01 +07:00
$temp = explode("</div", $temp[1]);
2024-02-19 14:24:34 +07:00
if (!empty($temp[0])) {
2024-02-13 13:54:01 +07:00
return $temp[0];
}
}
return $txt;
}
2024-02-19 14:24:34 +07:00
public static function maskText($text){
$len = strlen($text);
if($len < 3){
return "***";
}else if($len<5){
return substr($text,0,1)."***".substr($text,-1,1);
}else if($len<8){
return substr($text,0,2)."***".substr($text,-2,2);
}else{
return substr($text,0,4)."******".substr($text,-3,3);
}
}
2022-09-10 16:08:10 +07:00
}