$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)
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