X-Git-Url: https://git.p6c8.net/jirafeau.git/blobdiff_plain/8adcdf2e61aa2746235d99202ad07b59d0198b04..bd23d65292b6eda5c00e85ddce27235b5529a565:/lib/functions.php?ds=inline diff --git a/lib/functions.php b/lib/functions.php index 223fd8e..96f4c2f 100755 --- a/lib/functions.php +++ b/lib/functions.php @@ -60,8 +60,8 @@ base_16_to_64 ($num) $i = 0; # Convert long hex string to bin. $size = strlen ($num); - - $b .= $hex2bin{hexdec ($num{$i})}; + 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) @@ -1006,6 +1006,43 @@ jirafeau_block_init ($size) return $id . NL . $code; } +/** Get block size in bytes. + * @param $id identifier of the block + * @return block size in bytes + */ +function +jirafeau_block_get_size ($id) +{ + $p = VAR_BLOCK . s2p ($id) . $id; + if (!file_exists ($p)) + return "Error"; + + /* Check date. */ + $f = file ($p . '_infos'); + $date = trim ($f[0]); + $block_size = trim ($f[1]); + $stored_code = trim ($f[2]); + /* Update date. */ + if (date ('U') - $date > JIRAFEAU_HOUR + && date ('U') - $date < JIRAFEAU_MONTH) + { + if (file_put_contents ($p . '_infos', date ('U') . NL . $block_size . NL . $stored_code) === FALSE) + { + jirafeau_block_delete_ ($id); + return "Error"; + } + } + /* Remove data. */ + elseif (date ('U') - $date >= JIRAFEAU_MONTH) + { + echo date ('U'). " $date "; + jirafeau_block_delete_ ($id); + return "Error"; + } + + return $block_size; +} + /** * Read some data in a block. * @param $id identifier of the block