Repository navigation
Expand file tree
/
Copy pathhelpers.php
More file actions
133 lines (115 loc) · 3.37 KB
/
Copy pathhelpers.php
File metadata and controls
133 lines (115 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<?php
use ProtoneMedia\LaravelFFMpeg\Support\FFMpeg;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\Collection;
if (!function_exists('get_current_route_name')) {
/**
* @param $route_name
* @param string $class
* @return mixed|string
*/
function get_current_route_name($route_name, string $class = 'active') {
return request()->route()->getName() == $route_name ? $class : '';
}
}
if (! function_exists('includeFilesInFolder')) {
/**
* Loops through a folder and requires all PHP files
* Searches sub-directories as well.
*
* @param $folder
*/
function includeFilesInFolder($folder)
{
try {
$rdi = new RecursiveDirectoryIterator($folder);
$it = new RecursiveIteratorIterator($rdi);
while ($it->valid()) {
if (! $it->isDot() && $it->isFile() && $it->isReadable() && $it->current()->getExtension() === 'php') {
require $it->key();
}
$it->next();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
if (! function_exists('includeRouteFiles')) {
/**
* @param $folder
*/
function includeRouteFiles($folder)
{
includeFilesInFolder($folder);
}
}
if (! function_exists('getVideoDurationInSeconds')) {
/**
* @param $path
* @param string $disk
* @return int
*/
function getVideoDurationInSeconds($path, string $disk = 'public'): int
{
return FFMpeg::fromDisk($disk)->open($path)->getDurationInSeconds();
}
}
if (! function_exists('percentageCalculate')) {
/**
* @param $value
* @param $total
* @return float|int
*/
function percentageCalculate($value, $total) {
return $value > 0 ? ($value/$total)*100 : 0;
}
}
if (! function_exists('getFrameFromSeconds')) {
/**
* @param $path
* @param int $seconds
* @param string $disk
* @return string
*/
function getFrameFromSeconds($path, int $seconds = 2 , string $disk = 'public'): string
{
return FFMpeg::fromDisk($disk)->open($path)->getFrameFromSeconds($seconds)->export()->getFrameContents();
}
}
if (! function_exists('humanFileSize')) {
function humanFileSize($bytes, $decimals = 2): string
{
$sz = 'BKMGTP';
$factor = floor((strlen($bytes) - 1) / 3);
return sprintf("%.{$decimals}f", $bytes / pow(1024, $factor)) . @$sz[$factor];
}
}
if (! function_exists('gravatar')) {
/**
* @param $value
* @param int $size
* @return string
*/
function gravatar($value, int $size = 80): string
{
$hash = md5(strtolower(trim( $value)));
return "https://www.gravatar.com/avatar/{$hash}?s={$size}&d=monsterid";
}
}
if (! function_exists('paginate')) {
/**
* @param $items
* @param int $perPage
* @param null $page
* @param array $options
* @return LengthAwarePaginator
*/
function paginate($items, $perPage = 15, $page = null, $options = [])
{
$page = $page ?: (Paginator::resolveCurrentPage() ?: 1);
$items = $items instanceof Collection ? $items : Collection::make($items);
return new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(), $perPage, $page, $options);
}
}