|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* rmarchiv.tk |
|
5
|
|
|
* (c) 2016-2017 by Marcel 'ryg' Hering |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace App\Helpers; |
|
9
|
|
|
|
|
10
|
|
|
use NotificationChannels\Discord\Discord; |
|
11
|
|
|
|
|
12
|
|
|
class MiscHelper |
|
13
|
|
|
{ |
|
14
|
|
|
/** |
|
15
|
|
|
* Get the hash of the current git HEAD. |
|
16
|
|
|
* |
|
17
|
|
|
* @param string $branch The git branch to check |
|
18
|
|
|
* |
|
19
|
|
|
* @return mixed Either the hash or a boolean false |
|
20
|
|
|
*/ |
|
21
|
|
|
public static function get_current_git_commit($branch = 'master') |
|
|
|
|
|
|
22
|
|
|
{ |
|
23
|
|
|
$rev = exec('git rev-parse --short HEAD'); |
|
24
|
|
|
|
|
25
|
|
|
return $rev; |
|
26
|
|
|
} |
|
27
|
|
|
|
|
28
|
|
|
public static function sendDiscord($content) |
|
|
|
|
|
|
29
|
|
|
{ |
|
30
|
|
|
$dc = Discord::class; |
|
|
|
|
|
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
public static function sendTelegram($content) |
|
34
|
|
|
{ |
|
35
|
|
|
\Telegram::sendMessage([ |
|
36
|
|
|
'chat_id' => 51419661, |
|
37
|
|
|
'text' => $content, |
|
38
|
|
|
'parse_mode' => 'markdown', |
|
39
|
|
|
'disable_web_page_preview' => true, |
|
40
|
|
|
]); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
public static function array_diff_assoc_recursive($array1, $array2) |
|
44
|
|
|
{ |
|
45
|
|
|
$difference = []; |
|
46
|
|
|
foreach ($array1 as $key => $value) { |
|
47
|
|
|
if (is_array($value)) { |
|
48
|
|
|
if (! isset($array2[$key]) || ! is_array($array2[$key])) { |
|
49
|
|
|
$difference[$key] = $value; |
|
50
|
|
|
} else { |
|
51
|
|
|
$new_diff = self::array_diff_assoc_recursive($value, $array2[$key]); |
|
52
|
|
|
if (! empty($new_diff)) { |
|
53
|
|
|
$difference[$key] = $new_diff; |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
} elseif (! array_key_exists($key, $array2) || $array2[$key] !== $value) { |
|
57
|
|
|
$difference[$key] = $value; |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return $difference; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public static function getPopularity($views, $max) |
|
65
|
|
|
{ |
|
66
|
|
|
if ($max == 0 || $views == 0) { |
|
67
|
|
|
$ret = 0; |
|
68
|
|
|
} else { |
|
69
|
|
|
$ret = ($views / $max) * 100; |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
return $ret; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
/** |
|
76
|
|
|
* @param int $size |
|
77
|
|
|
* |
|
78
|
|
|
* @return string |
|
79
|
|
|
*/ |
|
80
|
|
|
public static function getReadableBytes($size) |
|
81
|
|
|
{ |
|
82
|
|
|
$bytes = $size; |
|
83
|
|
|
|
|
84
|
|
|
if ($bytes == 0) { |
|
85
|
|
|
return '0.00 B'; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
$s = ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB', 'EiB', 'ZiB', 'YiB']; |
|
89
|
|
|
$e = floor(log($bytes, 1024)); |
|
90
|
|
|
|
|
91
|
|
|
return round($bytes / pow(1024, $e), 2).' '.$s[$e]; |
|
92
|
|
|
} |
|
93
|
|
|
} |
|
94
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.