Files
ProxyPanel/app/helpers.php
兔姬桑 ce9618236f 2.5.a 管理路由全面改写 与 代码拆分
1. 全面改写项目-管理面板的路由;
2. 拆分过于Contoller;
3. 优化了按钮过多的图表的显示;
4. 初步应用 Laravel的 表单验证功能;
5. 初步应用 Laravel的 component 功能 拆分/模块化前端代码;
6. 优化部分系统的判断逻辑;
7. 针对2.4.0以前的面板,追加辅助矫正数据库的sql文件;
2020-10-01 12:34:19 +08:00

103 lines
2.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
use App\Components\Helpers;
define('KB', 1024);
define('MB', 1048576);
define('GB', 1073741824);
define('TB', 1099511627776);
define('PB', 1125899906842624);
define('Minute', 60);
define('Hour', 3600);
define('Day', 86400);
define('Mbps', 125000);
// base64加密处理URL
if (!function_exists('base64url_encode')) {
function base64url_encode($data)
{
return strtr(base64_encode($data), ['+' => '-', '/' => '_', '=' => '']);
}
}
// base64解密处理URL
if (!function_exists('base64url_decode')) {
function base64url_decode($data)
{
return base64_decode(strtr($data, '-_', '+/'));
}
}
// 根据流量值自动转换单位输出
if (!function_exists('flowAutoShow')) {
function flowAutoShow($value)
{
$value = abs($value);
if ($value >= PB) {
return round($value / PB, 2)."PB";
}
if ($value >= TB) {
return round($value / TB, 2)."TB";
}
if ($value >= GB) {
return round($value / GB, 2)."GB";
}
if ($value >= MB) {
return round($value / MB, 2)."MB";
}
if ($value >= KB) {
return round($value / KB, 2)."KB";
}
return round($value, 2)."B";
}
}
// 秒转时间
if (!function_exists('seconds2time')) {
function seconds2time($seconds)
{
$day = floor($seconds / Day);
$hour = floor(($seconds % Day) / Hour);
$minute = floor((($seconds % Day) % Hour) / Minute);
if ($day > 0) {
return $day.'天'.$hour.'小时'.$minute.'分';
}
if ($hour != 0) {
return $hour.'小时'.$minute.'分';
}
return $minute.'分';
}
}
// 过滤emoji表情
if (!function_exists('filterEmoji')) {
function filterEmoji($str)
{
return preg_replace_callback('/./u', static function (array $match) {
return strlen($match[0]) >= 4 ? '' : $match[0];
}, $str);
}
}
// 获取系统设置
if (!function_exists('sysConfig')) {
function sysConfig($name)
{
$ret = Cache::tags('sysConfig')->get($name);
if (is_null($ret)) {
return Helpers::cacheSysConfig($name);
}
return $ret;
}
}