X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/blobdiff_plain/13e2e31c60052e3572ad1bb091bf81ae62f00aca..8d85f9772ae53ce6a1902a967205f8ff1a290795:/lib/functions.php diff --git a/lib/functions.php b/lib/functions.php index 868d76e..96f4c2f 100755 --- a/lib/functions.php +++ b/lib/functions.php @@ -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