From: Jerome Jutteau Date: Mon, 25 Feb 2013 12:28:23 +0000 (+0000) Subject: Add block size query in script interface X-Git-Tag: 1.1~208 X-Git-Url: https://git.p6c8.net/jirafeau_mojo42.git/commitdiff_plain/8d85f9772ae53ce6a1902a967205f8ff1a290795?ds=inline;hp=13e2e31c60052e3572ad1bb091bf81ae62f00aca Add block size query in script interface --- 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 diff --git a/lib/lang/fr.php b/lib/lang/fr.php index 8e20a4b..fff1e96 100755 --- a/lib/lang/fr.php +++ b/lib/lang/fr.php @@ -164,6 +164,7 @@ $tr = array ( 'This interface permits to create a block of data filled with zeros.' => 'Cette interface permet de creer un bloque de données remplies de zeros.', 'You can read selected parts, write (using a code) and delete the block.' => 'Vous pouvez lire, écrire (en utilisant un code) et supprimer le bloque.', 'Blocks may be removed after a month of non usage.' => 'Les bloques non utilisés depuis plus d\'un mois seront probablement supprimés.', + 'Get block size' => 'Récupérer la taille d\'un bloque', 'Read data in a block' => 'Lire des données dans un bloque', 'Write data in a block' => 'Ecrire des données dans un bloque', 'First line is a block id the second line the edit/delete code.' => 'La premiere ligne est l\'identifiant du bloque, la seconde est son code d\'écriture/suppression.', diff --git a/script.php b/script.php index 45ca635..9bf9578 100755 --- a/script.php +++ b/script.php @@ -199,6 +199,15 @@ if ($_SERVER['REQUEST_METHOD'] == "GET" && count ($_GET) == 0) echo '

' . t('This will return brut text content.') . ' ' . t('First line is a block id the second line the edit/delete code.') . '

'; + echo '

' . t('Get block size') . ':

'; + echo '

'; + echo t('Send a GET query to') . ': ' . $web_root . 'script.php?get_block_size
'; + echo '
'; + echo t('Parameters') . ':
'; + echo "id=block_id (" . t('Required') . ")
"; + echo '

'; + echo '

' . t('This will return asked data or "Error" string.') . '

'; + echo '

' . t('Read data in a block') . ':

'; echo '

'; echo t('Send a GET query to') . ': ' . $web_root . 'script.php?read_block
'; @@ -574,6 +583,14 @@ elseif (isset ($_GET['init_block']) && $cfg['enable_blocks']) else echo jirafeau_block_init ($_POST['size']); } +/* Get block size. */ +elseif (isset ($_GET['get_block_size']) && $cfg['enable_blocks']) +{ + if (!isset ($_POST['id'])) + echo "Error"; + else + echo jirafeau_block_get_size ($_POST['id']); +} /* Read data in block. */ elseif (isset ($_GET['read_block']) && $cfg['enable_blocks']) {