mirror of
https://github.com/VueFileManager/vuefilemanager.git
synced 2026-04-18 16:22:14 +00:00
safety functions helper
This commit is contained in:
@@ -16,6 +16,7 @@ use Illuminate\Support\Facades\Storage;
|
||||
use Intervention\Image\ImageManagerStatic as Image;
|
||||
use Illuminate\Database\Eloquent\ModelNotFoundException;
|
||||
|
||||
if (!function_exists('obfuscate_email')) {
|
||||
/**
|
||||
* Obfuscate email
|
||||
*
|
||||
@@ -30,7 +31,9 @@ function obfuscate_email($email)
|
||||
|
||||
return substr($name, 0, $len) . str_repeat('*', $len) . '@' . end($em);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_setting')) {
|
||||
/**
|
||||
* Get single value from settings table
|
||||
*
|
||||
@@ -41,7 +44,9 @@ function get_setting($setting)
|
||||
{
|
||||
return Setting::find($setting)->value ?? null;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_settings_in_json')) {
|
||||
/**
|
||||
* Get all app settings and return them as json
|
||||
*/
|
||||
@@ -53,7 +58,9 @@ function get_settings_in_json()
|
||||
->toJson()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_setup_status')) {
|
||||
/**
|
||||
* Check if setup wizard was passed
|
||||
*
|
||||
@@ -65,7 +72,9 @@ function get_setup_status()
|
||||
|
||||
return boolval($setup_success) ? 'setup-done' : 'setup-disclaimer';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('add_paragraphs')) {
|
||||
/**
|
||||
* Create paragraph from text
|
||||
*
|
||||
@@ -112,7 +121,9 @@ function add_paragraphs($str)
|
||||
|
||||
return $str;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('setEnvironmentValue')) {
|
||||
/**
|
||||
* Set environment value
|
||||
*
|
||||
@@ -139,10 +150,11 @@ function setEnvironmentValue(array $values)
|
||||
|
||||
$str = substr($str, 0, -1);
|
||||
|
||||
return ! (! file_put_contents($envFile, $str))
|
||||
;
|
||||
return !(!file_put_contents($envFile, $str));
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_invoice_number')) {
|
||||
/**
|
||||
* Get invoice number
|
||||
*
|
||||
@@ -158,7 +170,9 @@ function get_invoice_number()
|
||||
|
||||
return (int)$invoices->last()->order + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('cache_forget_many')) {
|
||||
/**
|
||||
* Forget many cache keys at once
|
||||
* @param $cache
|
||||
@@ -169,7 +183,9 @@ function cache_forget_many($cache)
|
||||
\Illuminate\Support\Facades\Cache::forget($item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_storage')) {
|
||||
/**
|
||||
* Get app version from config
|
||||
*
|
||||
@@ -179,7 +195,9 @@ function get_storage()
|
||||
{
|
||||
return env('FILESYSTEM_DRIVER');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_storage_driver')) {
|
||||
/**
|
||||
* Check if is running AWS s3 as storage
|
||||
*
|
||||
@@ -193,7 +211,9 @@ function is_storage_driver($driver)
|
||||
|
||||
return config('filesystems.default') === $driver;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_version')) {
|
||||
/**
|
||||
* Get app version from config
|
||||
*
|
||||
@@ -203,7 +223,9 @@ function get_version()
|
||||
{
|
||||
return config('vuefilemanager.version');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_demo')) {
|
||||
/**
|
||||
* Check if is demo
|
||||
*
|
||||
@@ -213,7 +235,9 @@ function is_demo()
|
||||
{
|
||||
return config('vuefilemanager.is_demo');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_demo_account')) {
|
||||
/**
|
||||
* Check if is demo
|
||||
*
|
||||
@@ -224,7 +248,9 @@ function is_demo_account($email)
|
||||
{
|
||||
return config('vuefilemanager.is_demo') && $email === 'howdy@hi5ve.digital';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_item')) {
|
||||
/**
|
||||
* Get folder or file item
|
||||
*
|
||||
@@ -238,7 +264,9 @@ function get_item($type, $id)
|
||||
|
||||
return ("App\\Models\\$model")::find($id);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_shared')) {
|
||||
/**
|
||||
* Get shared token
|
||||
*
|
||||
@@ -250,7 +278,9 @@ function get_shared($token)
|
||||
return Share::whereToken($token)
|
||||
->firstOrFail();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_editor')) {
|
||||
/**
|
||||
* Check if shared permission is editor
|
||||
*
|
||||
@@ -261,7 +291,9 @@ function is_editor($shared)
|
||||
{
|
||||
return $shared->permission === 'editor';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_visitor')) {
|
||||
/**
|
||||
* Check if shared permission is visitor
|
||||
*
|
||||
@@ -272,7 +304,9 @@ function is_visitor($shared)
|
||||
{
|
||||
return $shared->permission === 'visitor';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('store_avatar')) {
|
||||
/**
|
||||
* Store user avatar to storage
|
||||
*
|
||||
@@ -309,7 +343,9 @@ function store_avatar($request, $name)
|
||||
// Return path to image
|
||||
return "avatars/$image_path";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('store_system_image')) {
|
||||
/**
|
||||
* Store system image
|
||||
*
|
||||
@@ -334,7 +370,9 @@ function store_system_image($request, $name)
|
||||
// Return path to image
|
||||
return "system/$filename";
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('make_single_input')) {
|
||||
/**
|
||||
* Make input from request
|
||||
*
|
||||
@@ -352,7 +390,9 @@ function make_single_input($request)
|
||||
// Return input
|
||||
return $data;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('format_gigabytes')) {
|
||||
/**
|
||||
* Format integer to gigabytes
|
||||
*
|
||||
@@ -367,7 +407,9 @@ function format_gigabytes($gigabytes)
|
||||
|
||||
return Metric::gigabytes($gigabytes)->format('GB/');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('format_megabytes')) {
|
||||
/**
|
||||
* Format string to formated megabytes string
|
||||
*
|
||||
@@ -386,7 +428,9 @@ function format_megabytes($megabytes)
|
||||
|
||||
return $megabytes . 'MB';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('format_bytes')) {
|
||||
/**
|
||||
* Convert megabytes to bytes
|
||||
*
|
||||
@@ -397,7 +441,9 @@ function format_bytes($megabytes)
|
||||
{
|
||||
return Metric::megabytes($megabytes)->numberOfBytes();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_storage_fill_percentage')) {
|
||||
/**
|
||||
* Get storage usage in percent
|
||||
*
|
||||
@@ -420,7 +466,9 @@ function get_storage_fill_percentage($used, $capacity)
|
||||
// Return in 2 decimal
|
||||
return number_format((float)$progress, 2, '.', '');
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('user_storage_percentage')) {
|
||||
/**
|
||||
* Get user capacity fill by percentage
|
||||
*
|
||||
@@ -440,7 +488,9 @@ function user_storage_percentage($id, $additionals = null)
|
||||
|
||||
return get_storage_fill_percentage($used, $user->settings->storage_capacity);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('recursiveFind')) {
|
||||
/**
|
||||
* Find all key values in recursive array
|
||||
*
|
||||
@@ -462,7 +512,9 @@ function recursiveFind(array $array, $needle)
|
||||
|
||||
return $aHitList;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('appeared_once')) {
|
||||
/**
|
||||
* Get values which appears only once in array
|
||||
* @param $arr
|
||||
@@ -482,7 +534,9 @@ function appeared_once($arr)
|
||||
|
||||
return $single_time_comming_values_array;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('filter_folders_ids')) {
|
||||
/**
|
||||
* @param $folders
|
||||
* @param string $by_column
|
||||
@@ -494,7 +548,9 @@ function filter_folders_ids($folders, $by_column = 'id')
|
||||
|
||||
return appeared_once($folder_ids);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('format_date')) {
|
||||
/**
|
||||
* Format localized date
|
||||
*
|
||||
@@ -508,7 +564,9 @@ function format_date($date, $format = '%d. %B. %Y, %H:%M')
|
||||
|
||||
return $start->formatLocalized($format);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_file_type')) {
|
||||
/**
|
||||
* Get file type from mimetype
|
||||
*
|
||||
@@ -526,7 +584,9 @@ function get_file_type($file_mimetype)
|
||||
|
||||
return 'file';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('map_language_translations')) {
|
||||
/**
|
||||
* It map language translations as language key and language value
|
||||
*
|
||||
@@ -539,7 +599,9 @@ function map_language_translations($translations): Collection
|
||||
return [$string->key => $string->value];
|
||||
})->collapse();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_file_type_from_mimetype')) {
|
||||
/**
|
||||
* Get file type from mimetype
|
||||
*
|
||||
@@ -550,7 +612,9 @@ function get_file_type_from_mimetype($mimetype)
|
||||
{
|
||||
return explode('/', $mimetype)[1];
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_pretty_name')) {
|
||||
/**
|
||||
* Format pretty name file
|
||||
*
|
||||
@@ -573,7 +637,9 @@ function get_pretty_name($basename, $name, $mimetype)
|
||||
|
||||
return $name . '.' . $mimetype;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_image_meta_data')) {
|
||||
/**
|
||||
* Get exif data from jpeg image
|
||||
*
|
||||
@@ -591,7 +657,9 @@ function get_image_meta_data($file)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_default_language_translations')) {
|
||||
/**
|
||||
* @return Collection
|
||||
*/
|
||||
@@ -603,7 +671,9 @@ function get_default_language_translations(): Collection
|
||||
config('custom-language-translations'),
|
||||
])->collapse();
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('is_dev')) {
|
||||
/**
|
||||
* Check if app is in dev mode
|
||||
*
|
||||
@@ -613,7 +683,9 @@ function is_dev()
|
||||
{
|
||||
return env('APP_ENV') === 'local';
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('seems_utf8')) {
|
||||
/**
|
||||
* @param $str
|
||||
* @return bool
|
||||
@@ -656,7 +728,9 @@ function seems_utf8($str)
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('remove_accents')) {
|
||||
/**
|
||||
* Converts all accent characters to ASCII characters.
|
||||
*
|
||||
@@ -796,6 +870,9 @@ function remove_accents($string)
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('get_files_for_zip')) {
|
||||
|
||||
/**
|
||||
* Get all files from folder and get their folder location in VueFileManager directories
|
||||
@@ -834,7 +911,9 @@ function get_files_for_zip($folders, $files, $path = [])
|
||||
|
||||
return get_files_for_zip($folders->folders->first(), $files, $path);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('set_time_by_user_timezone')) {
|
||||
/**
|
||||
* Set time by user timezone GMT
|
||||
*
|
||||
@@ -853,7 +932,9 @@ function set_time_by_user_timezone($time)
|
||||
|
||||
return Carbon::parse($time);
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('__t')) {
|
||||
/**
|
||||
* Translate the given message.
|
||||
* @param $key
|
||||
@@ -890,7 +971,9 @@ function __t($key, $values = null): string
|
||||
|
||||
return $string;
|
||||
}
|
||||
}
|
||||
|
||||
if (!function_exists('replace_occurrence')) {
|
||||
/**
|
||||
* Replace string occurrence in __t() by their values
|
||||
*
|
||||
@@ -913,3 +996,4 @@ function replace_occurrence($string, $values)
|
||||
$string
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user