+
+/**
+ * Transform a string in a path by seperating each letters by a '/'.
+ * @return path finishing with a '/'
+ */
+function
+s2p ($s)
+{
+ $p = '';
+ for ($i = 0; $i < strlen ($s); $i++)
+ $p .= $s{$i} . '/';
+ 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-_';
+ $o = '';
+ $b = '';
+ $i = 0;
+ $size = strlen ($num);
+ for ($i = 0; $i < $size; $i++)
+ $b .= base_convert ($num{$i}, 16, 2);
+ $size = strlen ($b);
+ for ($i = $size - 6; $i >= 0; $i -= 6)
+ $o = $m{bindec (substr ($b, $i, 6))} . $o;
+ if ($i < 0 && $i > -6)
+ $o = $m{bindec (substr ($b, 0, $i + 6))} . $o;
+ return $o;
+}
+
+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];
+}
+
+function
+jirafeau_clean_rm_link ($link)
+{
+ $p = s2p ("$link");
+ if (file_exists (VAR_LINKS . $p . $link))
+ unlink (VAR_LINKS . $p . $link);
+ $parse = VAR_LINKS . $p;
+ $scan = array();
+ while (file_exists ($parse)
+ && ($scan = scandir ($parse))
+ && count ($scan) == 2 // '.' and '..' folders => empty.
+ && basename ($parse) != basename (VAR_LINKS))
+ {
+ rmdir ($parse);
+ $parse = substr ($parse, 0, strlen($parse) - strlen(basename ($parse)) - 1);
+ }
+}
+
+function
+jirafeau_clean_rm_file ($md5)
+{
+ $p = s2p ("$md5");
+ if (file_exists (VAR_FILES . $p . $md5))
+ unlink (VAR_FILES . $p . $md5);
+ if (file_exists (VAR_FILES . $p . $md5 . '_count'))
+ unlink (VAR_FILES . $p . $md5 . '_count');
+ $parse = VAR_FILES . $p;
+ $scan = array();
+ while (file_exists ($parse)
+ && ($scan = scandir ($parse))
+ && count ($scan) == 2 // '.' and '..' folders => empty.
+ && basename ($parse) != basename (VAR_FILES))
+ {
+ rmdir ($parse);
+ $parse = substr ($parse, 0, strlen($parse) - strlen(basename ($parse)) - 1);
+ }
+}
+