X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/b1ae88cfb28f1946b8d3afea9882e352938292b5..337d60b9d05113d8b2c5bdf9ada7ab9fe8225512:/lib/functions.php?ds=inline diff --git a/lib/functions.php b/lib/functions.php index 5c0c45f..e4bfbb5 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -23,12 +23,12 @@ * Transform a string in a path by seperating each letters by a '/'. * @return path finishing with a '/' */ -function -s2p ($s) +function s2p($s) { $p = ''; - for ($i = 0; $i < strlen ($s); $i++) + for ($i = 0; $i < strlen($s); $i++) { $p .= $s{$i} . '/'; + } return $p; } @@ -36,11 +36,10 @@ s2p ($s) * Convert base 16 to base 64 * @returns A string based on 64 characters (0-9, a-z, A-Z, "-" and "_") */ -function -base_16_to_64 ($num) +function base_16_to_64($num) { $m = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'; - $hex2bin = array ('0000', # 0 + $hex2bin = array('0000', # 0 '0001', # 1 '0010', # 2 '0011', # 3 @@ -60,16 +59,19 @@ base_16_to_64 ($num) $b = ''; $i = 0; # Convert long hex string to bin. - $size = strlen ($num); - for ($i = 0; $i < $size; $i++) - $b .= $hex2bin{hexdec ($num{$i})}; + $size = strlen($num); + for ($i = 0; $i < $size; $i++) { + $b .= $hex2bin{hexdec($num{$i})}; + } # Convert long bin to base 64. $size *= 4; - for ($i = $size - 6; $i >= 0; $i -= 6) - $o = $m{bindec (substr ($b, $i, 6))} . $o; + for ($i = $size - 6; $i >= 0; $i -= 6) { + $o = $m{bindec(substr($b, $i, 6))} . $o; + } # Some few bits remaining ? - if ($i < 0 && $i > -6) - $o = $m{bindec (substr ($b, 0, $i + 6))} . $o; + if ($i < 0 && $i > -6) { + $o = $m{bindec(substr($b, 0, $i + 6))} . $o; + } return $o; } @@ -78,80 +80,96 @@ base_16_to_64 ($num) * @param $l code length * @return random code. */ -function -jirafeau_gen_random ($l) +function jirafeau_gen_random($l) { - if ($l <= 0) + if ($l <= 0) { return 42; + } $code=""; - for ($i = 0; $i < $l; $i++) - $code .= dechex (rand (0, 15)); + for ($i = 0; $i < $l; $i++) { + $code .= dechex(rand(0, 15)); + } return $code; } -function -is_ssl() { - if ( isset($_SERVER['HTTPS']) ) { - if ( 'on' == strtolower($_SERVER['HTTPS']) || - '1' == $_SERVER['HTTPS'] ) +function is_ssl() +{ + if (isset($_SERVER['HTTPS'])) { + if ('on' == strtolower($_SERVER['HTTPS']) || + '1' == $_SERVER['HTTPS']) { return true; - } elseif ( isset($_SERVER['SERVER_PORT']) && ( '443' == $_SERVER['SERVER_PORT'] ) ) { + } + } elseif (isset($_SERVER['SERVER_PORT']) && ('443' == $_SERVER['SERVER_PORT'])) { return true; } elseif (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { - if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') + if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { return true; + } } return false; } -function -jirafeau_human_size ($octets) +function jirafeau_human_size($octets) { - $u = array ('B', 'KB', 'MB', 'GB', 'TB'); - $o = max ($octets, 0); - $p = min (floor (($o ? log ($o) : 0) / log (1024)), count ($u) - 1); - $o /= pow (1024, $p); - return round ($o, 1) . $u[$p]; + $u = array('B', 'KB', 'MB', 'GB', 'TB'); + $o = max($octets, 0); + $p = min(floor(($o ? log($o) : 0) / log(1024)), count($u) - 1); + $o /= pow(1024, $p); + return round($o, 1) . $u[$p]; } -function -jirafeau_clean_rm_link ($link) +// Convert UTC timestamp to a datetime field +function jirafeau_get_datetimefield($timestamp) { - $p = s2p ("$link"); - if (file_exists (VAR_LINKS . $p . $link)) - unlink (VAR_LINKS . $p . $link); + $content = '' + . strftime('%Y-%m-%d %H:%M', $timestamp) . ' (GMT)'; + return $content; +} + +function jirafeau_fatal_error($errorText, $cfg = array()) +{ + echo '
' . $errorText . '
' . $title. '
' . $description. '