X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/f9f84c1e4389dc23e77b51dadd53410377128cfc..17e768a21c3d6877746fca24440600a9fea4da89:/lib/functions.php?ds=sidebyside diff --git a/lib/functions.php b/lib/functions.php index c26c5bc..e48534e 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -31,6 +31,47 @@ s2p ($s) return $p; } +/** + * 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) +{ + $m = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'; + $hex2bin = ['0000', # 0 + '0001', # 1 + '0010', # 2 + '0011', # 3 + '0100', # 4 + '0101', # 5 + '0110', # 6 + '0111', # 7 + '1000', # 8 + '1001', # 9 + '1010', # a + '1011', # b + '1100', # c + '1101', # d + '1110', # e + '1111']; # f + $o = ''; + $b = ''; + $i = 0; + # Convert long hex string to bin. + $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; + # Some few bits remaining ? + if ($i < 0 && $i > -6) + $o = $m{bindec (substr ($b, 0, $i + 6))} . $o; + return $o; +} + function jirafeau_human_size ($octets) { @@ -315,7 +356,7 @@ jirafeau_upload ($file, $one_time_download, $key, $time, $ip) NL . $md5. NL . ($one_time_download ? 'O' : 'R') . NL.date ('U') . NL. $ip . NL. $delete_link_code . NL); fclose ($handle); - $md5_link = md5_file ($link_tmp_name); + $md5_link = base_16_to_64 (md5_file ($link_tmp_name)); $l = s2p ("$md5_link"); if (!@mkdir (VAR_LINKS . $l, 0755, true) || !rename ($link_tmp_name, VAR_LINKS . $l . $md5_link)) @@ -446,11 +487,11 @@ jirafeau_admin_list ($name, $file_hash, $link_hash) { echo '
'; if (!empty ($name)) - echo $name . ' '; + echo t('Filename') . ": $name "; if (!empty ($file_hash)) - echo $file_hash . ' '; + echo t('file') . ": $file_hash "; if (!empty ($link_hash)) - echo $link_hash . ' '; + echo t('link') . ": $link_hash "; if (empty ($name) && empty ($file_hash) && empty ($link_hash)) echo t('List all files'); echo ''; @@ -489,15 +530,21 @@ jirafeau_admin_list ($name, $file_hash, $link_hash) continue; /* Filter. */ - if (!empty ($name) && $name != $l['file_name']) + if (!empty ($name) && !preg_match ("/$name/i", $l['file_name'])) continue; if (!empty ($file_hash) && $file_hash != $l['md5']) continue; - if (!empty ($link_hash) && $link_hash != $link) + if (!empty ($link_hash) && $link_hash != $node) continue; /* Print link informations. */ echo ''; - echo '' . $l['file_name'] . ''; + echo '' . + '
' . + '' . + '' . + '' . + '
'; + echo ''; echo '' . $l['mime_type'] . ''; echo '' . jirafeau_human_size ($l['file_size']) . ''; echo '' . ($l['time'] == -1 ? '' : strftime ('%c', $l['time'])) .