|
|
<?php
|
|
|
|
|
|
function tri_filemtime( $a, $b ) { return filemtime($a) - filemtime($b); }
|
|
|
|
|
|
// ---
|
|
|
// --- La config globale
|
|
|
// ---
|
|
|
chdir('/opt/TOPISTO/apps');
|
|
|
require_once '/opt/TOPISTO/apps/global/inc/config.php';
|
|
|
|
|
|
// ---
|
|
|
// --- External dependances
|
|
|
// ---
|
|
|
require TOPISTO_PATH.'/ressources/vendor/autoload.php';
|
|
|
|
|
|
// ---
|
|
|
// --- Internal dependances
|
|
|
// ---
|
|
|
require_once APP_PATH.'/blockchain/inc/block.php';
|
|
|
|
|
|
// ---
|
|
|
// --- Par défaut on cherche le dernier block
|
|
|
// ---
|
|
|
$block_hash = '*';
|
|
|
$methode='hasard';
|
|
|
$mode=9999;
|
|
|
|
|
|
// ---
|
|
|
// --- Le cas échéant, on cherche le block passé en argument
|
|
|
// ---
|
|
|
if (isset($_REQUEST['hash'])) $block_hash = $_REQUEST['hash'];
|
|
|
if (isset($_REQUEST['methode'])) $methode = $_REQUEST['methode'];
|
|
|
if (isset($_REQUEST['mode'])) $mode = intval($_REQUEST['mode']);
|
|
|
|
|
|
$img = null;
|
|
|
$str_mode = '';
|
|
|
if ($mode != 9999) $str_mode = '-'.$mode;
|
|
|
|
|
|
// ---
|
|
|
// --- Le cas général : on trouve le fichier image demandé
|
|
|
// ---
|
|
|
$imagefilename = DATA_PATH.'/'.$methode.'/'.$block_hash.$str_mode.'.png';
|
|
|
if (file_exists($imagefilename)) $img = imagecreatefrompng($imagefilename);
|
|
|
|
|
|
// ---
|
|
|
// --- "strict" est un flag qui indique que l'on veut précisément
|
|
|
// --- ce que les paramètres demandent
|
|
|
// ---
|
|
|
if (($img==null)&&(!isset($_REQUEST['strict'])))
|
|
|
{
|
|
|
//
|
|
|
// On n'a pas passé de HASH
|
|
|
//
|
|
|
if (($img==null)&&(!isset($_REQUEST['hash'])))
|
|
|
{
|
|
|
//
|
|
|
// On prend le dernier connu pour la méthode et le mode
|
|
|
//
|
|
|
$myarray = glob(DATA_PATH.'/'.$methode.'/*-'.$mode.'.png');
|
|
|
if (isset($myarray[0]))
|
|
|
{
|
|
|
usort( $myarray, tri_filemtime );
|
|
|
$img = imagecreatefrompng($myarray[0]);
|
|
|
}
|
|
|
//
|
|
|
// On prend le dernier connu pour la méthode tout mode confondu
|
|
|
//
|
|
|
if ($img==null)
|
|
|
{
|
|
|
$myarray = glob(DATA_PATH.'/'.$methode.'/*.png');
|
|
|
if (isset($myarray[0]))
|
|
|
{
|
|
|
usort( $myarray, tri_filemtime );
|
|
|
$img = imagecreatefrompng($myarray[0]);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//
|
|
|
// On a passé un HASH
|
|
|
//
|
|
|
if (($img==null)&&(isset($_REQUEST['hash'])))
|
|
|
{
|
|
|
//
|
|
|
// On cherche le bon HASH et la bonne méthode
|
|
|
//
|
|
|
$imagefilename = DATA_PATH.'/'.$methode.'/'.$block_hash.'.png';
|
|
|
if (($img==null)&&(file_exists($imagefilename)))
|
|
|
{
|
|
|
$img = imagecreatefrompng($imagefilename);
|
|
|
}
|
|
|
//
|
|
|
// En fait on s'en fiche de la méthode tant qu'on a le bon HASH
|
|
|
//
|
|
|
$imagefilename = DATA_PATH.'/hasard/'.$block_hash.'.png';
|
|
|
if (($img==null)&&(file_exists($imagefilename)))
|
|
|
{
|
|
|
$img = imagecreatefrompng($imagefilename);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//
|
|
|
// On n'a rien trouvé, donc on dessine ce qui est demandé
|
|
|
//
|
|
|
if ($img==null)
|
|
|
{
|
|
|
if ($mode == 9999) $mode = 0;
|
|
|
if ($block_hash == '*') $block_hash = blockchain::getLastCacheBlockHash();
|
|
|
if ($methode == 'hasard') $methode = 'treemap';
|
|
|
|
|
|
$imagefilename = DATA_PATH.'/'.$methode.'/'.$block_hash.'.png';
|
|
|
|
|
|
$the_block = blockchain::getBlockWithHash($block_hash);
|
|
|
if ($the_block === FALSE) die();
|
|
|
|
|
|
$the_name = blockchain::hash2SpecialName($the_block->hash);
|
|
|
if ($the_name == $the_block->hash) $the_name ='';
|
|
|
|
|
|
$bandeau = 50;
|
|
|
$marge = 25;
|
|
|
$text_border = 20;
|
|
|
$width = GRAPH_WIDTH;
|
|
|
$height = GRAPH_HEIGHT;
|
|
|
|
|
|
// Pour que l'image simple ait les proportions que l'image full
|
|
|
$width = $marge + ($width*2) + (2*$text_border);
|
|
|
$height = $marge + ($height*2);
|
|
|
|
|
|
$img_w = $width;
|
|
|
$img_h = $height+(2*$bandeau);
|
|
|
|
|
|
$type=2;
|
|
|
if (count($the_block->tx)==1) $type=4;
|
|
|
|
|
|
// création d'une image plus haute pour inclure bandeaux haut et bas
|
|
|
$img = imagecreatetruecolor($img_w, $img_h);
|
|
|
|
|
|
$param0 = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau);
|
|
|
|
|
|
$parametres = [];
|
|
|
$parametres['x'] = 0;
|
|
|
$parametres['y'] = $bandeau;
|
|
|
$parametres['width'] = $width;
|
|
|
$parametres['height'] = $height;
|
|
|
$parametres['methode'] = $mode;
|
|
|
$parametres['type'] = $type;
|
|
|
$parametres['transparent_color'] = $param0[0];
|
|
|
$parametres['background_color'] = $param0[1];
|
|
|
$parametres['font_color'] = $param0[2];
|
|
|
$parametres['fontname'] = $param0[3];
|
|
|
$parametres['font_RGB'] = $param0[4];
|
|
|
$parametres['background_RGB'] = $param0[5];
|
|
|
|
|
|
switch($methode)
|
|
|
{
|
|
|
case 'veraMolnar':
|
|
|
require_once APP_PATH.'/methode/veraMolnar/inc/treemap.php';
|
|
|
topisto_veraMolnar::DrawBlock($the_block, $img, $parametres);
|
|
|
break;
|
|
|
|
|
|
case 'treemapV2':
|
|
|
require_once APP_PATH.'/methode/treemapV2/inc/treemap.php';
|
|
|
topisto_treemap::DrawBlock($the_block, $img, $parametres);
|
|
|
break;
|
|
|
|
|
|
case 'treemap_fuzzy':
|
|
|
require_once APP_PATH.'/methode/treemap_fuzzy/inc/treemap.php';
|
|
|
topisto_treemap_fuzzy::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type);
|
|
|
break;
|
|
|
|
|
|
case 'spline':
|
|
|
require_once APP_PATH.'/methode/spline/inc/splines.php';
|
|
|
topisto_spline::DefaultDrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type);
|
|
|
break;
|
|
|
|
|
|
case 'spline_2':
|
|
|
require_once APP_PATH.'/methode/spline/inc/splines.php';
|
|
|
topisto_spline::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, 200, $type);
|
|
|
break;
|
|
|
|
|
|
case 'treemap' :
|
|
|
default:
|
|
|
require_once APP_PATH.'/methode/treemap/inc/treemap.php';
|
|
|
topisto_treemap::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
// Les textes
|
|
|
/*
|
|
|
* INUTILE depuis que blockchain::DrawBlockHeaderFooter ajoute elle-même les textes
|
|
|
*
|
|
|
putenv('GDFONTPATH='.RESS_PATH.'/fonts/');
|
|
|
$font = 'DS-DIGIB.TTF';
|
|
|
|
|
|
$fontColor = imagecolorallocate($img, 227,227,153);
|
|
|
$the_texte = "Height : ".$the_block->height;
|
|
|
imagettftext($img,18, 0, 5, $bandeau-5, $fontColor, $font, $the_texte);
|
|
|
$the_texte = "Inputs : ".$the_block->topisto_inputs;
|
|
|
if ($type == 4) $the_texte = "Reward : ".$the_block->topisto_reward;
|
|
|
imagettftext($img,15, 0, 5, $bandeau+$height+18, $fontColor, $font, $the_texte);
|
|
|
|
|
|
if ($the_name == '') $the_name = date('Ymd H:m:s', $the_block->time);
|
|
|
$bbox = imagettfbbox(14, 0, $font, $the_name);
|
|
|
imagettftext($img, 14, 0, ($img_w-3)-($bbox[2]-$bbox[0]), ($bandeau-5), $fontColor, $font, $the_name);
|
|
|
*/
|
|
|
|
|
|
// Sauvegarder l'image et ajouter
|
|
|
// - un lien sur le mode
|
|
|
// - un lien dans le dossier "hasard"
|
|
|
$imagefilename2 = str_replace(".png","-$mode.png", $imagefilename);
|
|
|
imagepng($img,$imagefilename2);
|
|
|
|
|
|
if (!file_exists($imagefilename)) link($imagefilename2, $imagefilename);
|
|
|
|
|
|
$imagefilename2 = str_replace("methode/$methode/","methode/hasard/", $imagefilename);
|
|
|
if (!file_exists($imagefilename2)) link($imagefilename, $imagefilename2);
|
|
|
}
|
|
|
|
|
|
$seconds_to_cache = 7200;
|
|
|
$ts = gmdate("D, d M Y H:i:s", time() + $seconds_to_cache) . " GMT";
|
|
|
header("Expires: $ts");
|
|
|
header("Pragma: cache");
|
|
|
header("Cache-Control: max-age=$seconds_to_cache");
|
|
|
header('Content-Type: image/png');
|
|
|
|
|
|
imagepng($img);
|
|
|
|
|
|
imagedestroy($img);
|
|
|
|
|
|
?>
|