| @ -0,0 +1,3 @@ | |||
| topisto - apps | |||
| Ce sont les applications déployées sur le serveur www.topisto.net | |||
| @ -0,0 +1,86 @@ | |||
| <?php | |||
| $url = 'http://x:m3lch1s3d3k@127.0.0.1:8332'; | |||
| $data = array("method" => "getbestblockhash"); | |||
| $json_data = json_encode($data); | |||
| $ch = curl_init($url); | |||
| curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |||
| curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); | |||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |||
| curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |||
| 'Content-Type: application/json', | |||
| 'Content-Length: ' . strlen($json_data)) | |||
| ); | |||
| $result = curl_exec($ch); | |||
| $obj_result = json_decode($result); | |||
| $block_hash = $obj_result->result; | |||
| $data = array("method" => "getblock", "params" => array($block_hash, 1, 1)); | |||
| $json_data = json_encode($data); | |||
| curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |||
| curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); | |||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |||
| curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |||
| 'Content-Type: application/json', | |||
| 'Content-Length: ' . strlen($json_data)) | |||
| ); | |||
| $result = curl_exec($ch); | |||
| $obj_result = json_decode($result); | |||
| $obj_result = $obj_result->result; | |||
| //var_dump($obj_result);die(); | |||
| //echo $result.PHP_EOL; | |||
| echo "----------------------------".PHP_EOL; | |||
| echo "##".$obj_result->hash.PHP_EOL; | |||
| echo "##".$obj_result->previousblockhash.PHP_EOL; | |||
| echo "##".$obj_result->nextblockhash.PHP_EOL; | |||
| echo "##".$obj_result->height.PHP_EOL; | |||
| $obj_result->topisto_inputs = 0; | |||
| $obj_result->topisto_outputs = 0; | |||
| $obj_result->topisto_fees = 0; | |||
| foreach($obj_result->tx as $transaction) | |||
| { | |||
| echo '>>>>'.$transaction->hash.PHP_EOL; | |||
| $transaction->topisto_inputs = 0; | |||
| foreach($transaction->vin as $tx_in) | |||
| { | |||
| if (isset($tx_in->txid)) | |||
| { | |||
| echo '======'.$tx_in->txid.PHP_EOL; | |||
| // { | |||
| // "method": "gettxout", | |||
| // "params": [ "'$txhash'", "'$index'", "'$includemempool'" ] | |||
| // } | |||
| $data = array("method" => "gettxout", "params" => array($tx_in->txid, $tx_in->vout, 0)); | |||
| $json_data = json_encode($data); | |||
| curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); | |||
| curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data); | |||
| curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |||
| curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |||
| 'Content-Type: application/json', | |||
| 'Content-Length: ' . strlen($json_data)) | |||
| ); | |||
| $result = curl_exec($ch); | |||
| $objet1 = json_decode($result); | |||
| if (isset($objet1->value)) $transaction->topisto_inputs += $objet1->value; | |||
| } | |||
| } | |||
| $transaction->topisto_outputs = 0; | |||
| foreach($transaction->vout as $tx_out) | |||
| if (isset($tx_out->value)) $transaction->topisto_outputs += $tx_out->value; | |||
| if (count($transaction->vin) == 0) $obj_result->topisto_fees += $transaction->topisto_outputs; | |||
| $obj_result->topisto_inputs += $transaction->topisto_inputs; | |||
| $obj_result->topisto_outputs += $transaction->topisto_outputs; | |||
| } | |||
| echo '##'.$obj_result->topisto_inputs.PHP_EOL; | |||
| echo '##'.$obj_result->topisto_outputs.PHP_EOL; | |||
| echo '##'.$obj_result->topisto_fees.PHP_EOL; | |||
| ?> | |||
| @ -0,0 +1,50 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../global/inc/config.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once 'inc/block.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- On interroge la blockchain | |||
| // --- => Ce qui a pour effet de placer le block dans le cache | |||
| // --- | |||
| $the_block = blockchain::getSpecialBlock($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| // --- | |||
| // --- On en recherche 3 sur approximativement 6 heures (36 blocks) | |||
| // --- | |||
| $max = 3; | |||
| $max2 = 36; | |||
| while(($max > 0)&&($max2 > 0)) | |||
| { | |||
| $block_hash = $the_block->prev_block; | |||
| if (!file_exists(DATA_PATH.'/json/'.$block_hash.'.zip')) | |||
| { | |||
| $max--; | |||
| echo 'CACHE '.$block_hash.' '.($the_block->height-1).PHP_EOL; | |||
| } | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| $max2--; | |||
| } | |||
| ?> | |||
| @ -0,0 +1,46 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../global/inc/config.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once 'inc/block.php'; | |||
| // --- | |||
| // --- On interroge la blockchain | |||
| // --- => Ce qui a pour effet de placer le block dans le cache | |||
| // --- | |||
| $block_hash = blockchain::getLastBlockHash(); | |||
| if ($block_hash === FALSE) die(); | |||
| echo 'LAST '.$block_hash.' ZIP OK PNG OK'; | |||
| for($i=0;$i<36;$i++) | |||
| { | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| echo ' '.$the_block->height.PHP_EOL; | |||
| if ($i == 35) break; | |||
| $block_hash = $the_block->prev_block; | |||
| echo 'PREV '.$block_hash.' '; | |||
| echo 'ZIP '; | |||
| if (file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) echo 'OK '; | |||
| else echo 'KO '; | |||
| echo 'PNG '; | |||
| if (file_exists(DATA_PATH.'/hasard/'.$the_block->hash.'.png')) echo 'OK'; | |||
| else echo 'KO'; | |||
| } | |||
| ?> | |||
| ~ | |||
| @ -0,0 +1,412 @@ | |||
| <?php | |||
| class blockchain | |||
| { | |||
| private static $url_info = 'https://blockchain.info/fr'; | |||
| private static $offline_block = OFFLINE_PATH.'/offline_block.zip'; | |||
| /* | |||
| * Liste de blocks spéciaux dans l'histoire du Bitcoin | |||
| * | |||
| * 'GENESIS' - Premier block de la blochain | |||
| * 'THE_ANSWER' - Block 42 (pour le fun) | |||
| * 'LUCIFER' - Block 666 (pour le fun) | |||
| * 'LEET' - Block 1337 (pour le fun) | |||
| * 'PIZZA' - Block 57035 : le block du pizza day, 22 05 2010 | |||
| * 'HALVING_1' - First halving, block 2100000, 28 11 2012 | |||
| * 'HALVING_2' - Second halving, block 420000, 09 07 2017 | |||
| * 'BIP_91_LOCK' - Block 477120 : Verouillage du BIP 91, 23/07/2017 | |||
| * 'BCC' - Block 478558 : Bitcoin Cash Fork 01/08/2017 | |||
| * 'SEGWIT_LOCK' - Block 479808 SEGWIT est verrouillé 09 08 2017 | |||
| * 'SEGWIT' - Block 481823 SEGWIT est activé 24 08 2017 | |||
| */ | |||
| private static $special_blocks = array ( | |||
| 'GENESIS' => '000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f', | |||
| 'THE_ANSWER' => '00000000314e90489514c787d615cea50003af2023796ccdd085b6bcc1fa28f5', | |||
| 'LUCIFER' => '00000000fc5b3c76f27f810ee775e480ae7fd604fd196b2d8da4257fcd39f4f9', | |||
| 'LEET' => '000000008bf44a528a09d203203a6a97c165cf53a92ecc27aed0b49b86a19564', | |||
| 'TOPISTO' => '000000000a73e64735a2b75c97ea674950a9018da1420d01328a918c9ff9852c', | |||
| 'PIZZA' => '00000000006de085dadb3ec413ef074022fe781121b467e98960280dd246bb00', | |||
| 'HALVING_1' => '000000000000048b95347e83192f69cf0366076336c639f9b7228e9ba171342e', | |||
| 'HALVING_2' => '000000000000000002cce816c0ab2c5c269cb081896b7dcb34b8422d6b74ffa1', | |||
| 'BIP_91_LOCK' => '0000000000000000015411ca4b35f7b48ecab015b14de5627b647e262ba0ec40', | |||
| 'BCC' => '00000000000000000019f112ec0a9982926f1258cdcc558dd7c3b7e5dc7fa148', | |||
| 'SEGWIT_LOCK' => '0000000000000000012e6060980c6475a9a8e62a1bf44b76c5d51f707d54522c', | |||
| 'SEGWIT' => '000000000000000000cbeff0b533f8e1189cf09dfbebf57a8ebe349362811b80', | |||
| 'HURRICANE_1' => '0000000000000000000fe6d521a187a5523d5cef6f6c178923ff82ffe5a0f372' | |||
| ); | |||
| // --- | |||
| // --- Retourne le nom d'un block à partie de son hash | |||
| // --- si ce n'est pas un block special, on renvoie le hash | |||
| // --- | |||
| public static function hash2SpecialName($block_hash) | |||
| { | |||
| foreach(self::$special_blocks as $key => $value) | |||
| if ($block_hash == $value) return $key; | |||
| return $block_hash; | |||
| } | |||
| // --- | |||
| // --- Accès aux blocks spéciaux | |||
| // --- On en rajoute un : le LAST block | |||
| // --- En fait toute valeur ne faisant pas partie des blocks connus | |||
| // --- | |||
| public static function getSpecialBlock($nom_du_block) | |||
| { | |||
| $block_hash = ''; | |||
| if (isset(self::$special_blocks[$nom_du_block])) $block_hash = self::$special_blocks[$nom_du_block]; | |||
| if (file_exists(self::$offline_block)) $block_hash = 'offline'; | |||
| if ($block_hash == '') $block_hash = self::getLastBlockHash(); | |||
| return self::getBlockWithHash($block_hash); | |||
| } | |||
| // --- | |||
| // --- Accès au dernier block en cache ... | |||
| // --- | |||
| public static function getLastCacheBlockHash() | |||
| { | |||
| // on commence par le cache d'images | |||
| $myarray = glob(DATA_PATH.'/hasard/*.png'); | |||
| if (isset($myarray[0])) | |||
| { | |||
| usort( $myarray, function( $a, $b ) { return filemtime($b) - filemtime($a); } ); | |||
| return substr(basename($myarray[0],'.png'),0,strlen(self::$special_blocks['GENESIS'])); | |||
| } | |||
| // S'il n'y a rien dans le cache d'images | |||
| $filename=DATA_PATH.'/finished_block_list.txt'; | |||
| if (file_exists($filename)) | |||
| { | |||
| $handle = fopen($filename, "r"); | |||
| if ($handle) | |||
| { | |||
| while (($buffer = fgets($handle, 4096)) !== false) { | |||
| $valeurs = explode(" ",$buffer); | |||
| if ($valeurs[0] == 'LAST') return $valeurs[1]; | |||
| } | |||
| } | |||
| } | |||
| return NULL; | |||
| } | |||
| // --- | |||
| // --- Accès au dernier block | |||
| // --- | |||
| public static function getLastBlockHash() | |||
| { | |||
| if (file_exists(self::$offline_block)) return 'offline'; | |||
| $filename=self::$url_info.'/latestblock'; | |||
| $message = file_get_contents($filename); | |||
| if ($message === FALSE) return FALSE; | |||
| $the_block = json_decode($message); | |||
| return $the_block->hash; | |||
| } | |||
| // --- | |||
| // --- Accès à partir du hash | |||
| // --- | |||
| public static function getBlockWithHash($block_hash) | |||
| { | |||
| // Si on est offline, peut importe le hash passé | |||
| if (!file_exists(self::$offline_block)) | |||
| { | |||
| if (!file_exists(DATA_PATH."/json/$block_hash.zip")) | |||
| { | |||
| $filename=self::$url_info.'/rawblock/'.$block_hash; | |||
| $message = file_get_contents($filename); | |||
| if ( $message === FALSE ) return FALSE; | |||
| $the_block = json_decode($message); | |||
| return self::saveBlockInTmpDir($the_block); | |||
| } | |||
| touch(DATA_PATH."/json/$block_hash.zip"); | |||
| } | |||
| return self::zip2Block($block_hash); | |||
| } | |||
| // --- | |||
| // --- Gestion du cache | |||
| // --- | |||
| private static function saveBlockInTmpDir($the_block) | |||
| { | |||
| if (file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) return $the_block; | |||
| if (!isset($the_block->topisto_inputs)) | |||
| { | |||
| $the_block->topisto_inputs = 0; | |||
| $the_block->topisto_outputs = 0; | |||
| $the_block->topisto_fees = 0; | |||
| $the_block->topisto_reward = 0; | |||
| foreach($the_block->tx as $transaction) | |||
| { | |||
| $tx_inputs = 0; | |||
| $tx_outputs = 0; | |||
| if (isset($transaction->inputs)) | |||
| foreach($transaction->inputs as $input) | |||
| if (isset($input->prev_out->value)) | |||
| $tx_inputs += $input->prev_out->value; | |||
| if (isset($transaction->out)) | |||
| foreach($transaction->out as $output) | |||
| if (isset($output->value)) | |||
| $tx_outputs += $output->value; | |||
| $tx_fees = abs($tx_inputs - $tx_outputs); | |||
| $the_block->topisto_inputs += $tx_inputs; | |||
| if ($tx_inputs == 0) | |||
| { | |||
| $the_block->topisto_reward += $tx_outputs; | |||
| continue; | |||
| } | |||
| $the_block->topisto_outputs += $tx_outputs; | |||
| $the_block->topisto_fees += $tx_fees; | |||
| } | |||
| // On retire les frais de la récompense | |||
| $the_block->topisto_reward -= $the_block->topisto_fees; | |||
| self::block2zip($the_block); | |||
| } | |||
| return $the_block; | |||
| } | |||
| private static function block2zip($the_block) | |||
| { | |||
| $zip = new ZipArchive(); | |||
| if($zip->open(DATA_PATH.'/json/'.$the_block->hash.'.zip', ZipArchive::CREATE) === true) | |||
| { | |||
| $zip->addFromString($the_block->hash.'.json', json_encode($the_block)); | |||
| $zip->close(); | |||
| } | |||
| } | |||
| private static function zip2Block($the_block_hash) | |||
| { | |||
| $local_hash = $the_block_hash; | |||
| $zipBlock = DATA_PATH."/json/$the_block_hash.zip"; | |||
| if (file_exists(self::$offline_block)) | |||
| { | |||
| $local_hash = 'offline'; | |||
| $zipBlock = self::$offline_block; | |||
| } | |||
| $zip = new ZipArchive; | |||
| if ($zip->open($zipBlock) === TRUE) { | |||
| $the_block = json_decode($zip->getFromName("$local_hash.json")); | |||
| $zip->close(); | |||
| return $the_block; | |||
| } | |||
| return NULL; | |||
| } | |||
| public static function DrawBlockHeaderFooter($the_block, $vImage, $hauteur) | |||
| { | |||
| $color_tab = [ | |||
| [ | |||
| [19,15,64], | |||
| [255,255,255] | |||
| ], | |||
| [ | |||
| [106,176,76], | |||
| [0,0,0] | |||
| ], | |||
| [ | |||
| [106,176,76], | |||
| [255,255,255] | |||
| ], | |||
| [ | |||
| [240,147,43], | |||
| [0,0,0] | |||
| ], | |||
| [ | |||
| [34,166,179], | |||
| [0,0,0] | |||
| ], | |||
| [ | |||
| [240,147,43], | |||
| [255,255,255] | |||
| ], | |||
| [ | |||
| [48,51,107], | |||
| [255,255,255] | |||
| ], | |||
| [ | |||
| [246, 229, 141], | |||
| [235,77,75] | |||
| ], | |||
| [ | |||
| [40, 40, 40], | |||
| [158,227,253] | |||
| ], | |||
| [ | |||
| [0, 0, 0], | |||
| [255, 255, 255] | |||
| ] | |||
| ]; | |||
| $color = rand(0,count($color_tab)-1); | |||
| // Rajout des HASHES | |||
| $white = imagecolorallocate($vImage, 254, 254, 254); | |||
| $black = imagecolorallocate($vImage, $color_tab[$color][1][0], $color_tab[$color][1][1], $color_tab[$color][1][2]); | |||
| $fond = imagecolorallocate($vImage, $color_tab[$color][0][0], $color_tab[$color][0][1], $color_tab[$color][0][2]); | |||
| $w = imagesx($vImage); | |||
| $h = imagesy($vImage); | |||
| // On rend le blanc transparent | |||
| imagecolortransparent($vImage, $white); | |||
| // On place un fond transparent | |||
| imagefilledrectangle($vImage, 0, 0, $w, $h, $white); | |||
| $len = strlen($the_block->hash); | |||
| $ratio_w = $w / $len; | |||
| $ratio_h = $hauteur / 32; // car hexadécimal | |||
| // Récupérer les hashes dans 2 tableaux | |||
| $tableau1 = str_split($the_block->hash); | |||
| $tableau2 = str_split($the_block->prev_block); | |||
| // Convertir les tableaux en liste de points | |||
| $points1 = []; | |||
| $points2 = []; | |||
| $points1[] = 0; | |||
| $points1[] = $hauteur - 1; | |||
| $points2[] = 0; | |||
| $points2[] = $hauteur - 1; | |||
| for($i=0;$i<$len;$i++) | |||
| { | |||
| // Le HASH | |||
| $coin_x1 = $ratio_w * $i; | |||
| $coin_x2 = $ratio_w * ($i + 1); | |||
| $coin_y1 = $hauteur; | |||
| $coin_y2 = hexdec($tableau1[$i])*$ratio_h; | |||
| $points1[] = $coin_x1; | |||
| $points1[] = $coin_y2; | |||
| $points1[] = $coin_x2; | |||
| $points1[] = $coin_y2; | |||
| // Le PREV HASH | |||
| $coin_x1 = $ratio_w * $i; | |||
| $coin_x2 = $ratio_w * ($i + 1); | |||
| $coin_y1 = $hauteur; | |||
| $coin_y2 = 16 - (hexdec($tableau2[$i])*$ratio_h); | |||
| $points2[] = $coin_x1; | |||
| $points2[] = $coin_y2; | |||
| $points2[] = $coin_x2; | |||
| $points2[] = $coin_y2; | |||
| } | |||
| // Rajouter un coin | |||
| $points1[] = $w; | |||
| $points1[] = $hauteur - 1; | |||
| $points2[] = $w; | |||
| $points2[] = $hauteur - 1; | |||
| // Inverser le PREV HASH | |||
| for($i=0;$i<count($points2);$i+=2) | |||
| { | |||
| $points2[$i+1] = ($h - 12) - $points2[$i+1]; | |||
| if ($points2[$i+1] >= $h) $points2[$i+1] = $h - 1; | |||
| } | |||
| // Dessiner le HASH | |||
| imagefilledpolygon($vImage, $points1, (count($points1)/2), $fond); | |||
| imagepolygon($vImage, $points1, (count($points1)/2), $black); | |||
| // dessiner le PREV HASH | |||
| imagefilledpolygon($vImage, $points2, (count($points2)/2), $fond); | |||
| imagepolygon($vImage, $points2, (count($points2)/2), $black); | |||
| // Rajout des textes | |||
| $the_name = blockchain::hash2SpecialName($the_block->hash); | |||
| if ($the_name == $the_block->hash) $the_name = date('Ymd H:i:s', $the_block->time); | |||
| putenv('GDFONTPATH='.RESS_PATH.'/fonts/'); | |||
| $font = 'DS-DIGIB.TTF'; | |||
| $the_texte = "Height : ".$the_block->height; | |||
| imagettftext($vImage,18, 0, 5, $hauteur-5, $black, $font, $the_texte); | |||
| $the_texte = "Inputs : ".$the_block->topisto_inputs; | |||
| if (count($the_block->tx)==1) $the_texte = "Reward : ".$the_block->topisto_reward; | |||
| imagettftext($vImage, 15, 0, 25, ($h - $hauteur)+18, $black, $font, $the_texte); | |||
| $bbox = imagettfbbox(14, 0, $font, $the_name); | |||
| imagettftext($vImage, 14, 0, ($w-3)-($bbox[2]-$bbox[0]), ($hauteur-5), $black, $font, $the_name); | |||
| return [$white, $fond, $black, $font, $color_tab[$color][1], $color_tab[$color][0]]; | |||
| } | |||
| public static function getTransactionData($the_block, $type=1) | |||
| { | |||
| // Cela a déjà été calculé | |||
| if (isset($the_block->data[$type])) return $the_block->data[$type]; | |||
| $data = []; | |||
| foreach($the_block->tx as $transaction) | |||
| { | |||
| $total_outputs = 0; | |||
| $total_inputs = 0; | |||
| $value = 0; | |||
| if (isset($transaction->out)) | |||
| foreach($transaction->out as $output) | |||
| if (isset($output->value)) | |||
| $total_outputs += $output->value; | |||
| if (isset($transaction->inputs)) | |||
| foreach($transaction->inputs as $input) | |||
| if (isset($input->prev_out->value)) | |||
| $total_inputs += $input->prev_out->value; | |||
| switch($type) | |||
| { | |||
| // OUTPUTS | |||
| case 1: | |||
| if ($total_inputs != 0) | |||
| $data[] = ["hash" => $transaction->hash, "value" => $total_outputs]; | |||
| break; | |||
| // INPUTS | |||
| case 2: | |||
| $data[] = ["hash" => $transaction->hash, "value" => $total_inputs]; | |||
| break; | |||
| // FEES | |||
| case 3: | |||
| if ($total_inputs != 0) | |||
| $data[] = ["hash" => $transaction->hash, "value" => ($total_outputs-$total_inputs)]; | |||
| break; | |||
| // REWARD | |||
| case 4: | |||
| if ($total_inputs == 0) | |||
| $data[] = ["hash" => $transaction->hash, "value" => $total_outputs]; | |||
| break; | |||
| } | |||
| } | |||
| if (!isset($the_block->data)) $the_block->data = []; | |||
| $the_block->data[$type] = $data; | |||
| return $data; | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,5 @@ | |||
| <?php | |||
| foreach (glob("/opt/Twitterbot/inc/*.php") as $filename) require_once($filename); | |||
| ?> | |||
| @ -0,0 +1,47 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../global/inc/config.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once 'inc/block.php'; | |||
| // --- | |||
| // --- On interroge la blockchain | |||
| // --- => Ce qui a pour effet de placer le block dans le cache | |||
| // --- | |||
| block_hash = blockchain::getLastCacheBlockHash(); | |||
| if ($block_hash === FALSE) die(); | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| echo 'LAST '.$block_hash.' '.$the_block->height.PHP_EOL; | |||
| $block_hash = blockchain::getLastBlockHash(); | |||
| if ($block_hash === FALSE) die(); | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| echo 'LAST '.$block_hash.' '.$the_block->height.PHP_EOL; | |||
| $the_block = blockchain::getSpecialBlock('LAST'); | |||
| if ($the_block === FALSE) die(); | |||
| echo 'LAST '.$the_block->hash." ".$the_block->height.PHP_EOL; | |||
| $max = 0; | |||
| // On se met en retard d'au moins un bloc ... | |||
| while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) | |||
| { | |||
| $block_hash = $the_block->prev_block; | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| // Mais pas plus de 5 blocs de retard ... | |||
| $max += 1;if ($max > 5) break; | |||
| } | |||
| echo 'LAST '.$the_block->hash." ".$the_block->height.PHP_EOL; | |||
| ?> | |||
| @ -0,0 +1,52 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../global/inc/config.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once 'inc/block.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| echo $block_hash.' '; | |||
| // --- | |||
| // --- On interroge la blockchain | |||
| // --- => Ce qui a pour effet de placer le block dans le cache | |||
| // --- | |||
| $the_block = blockchain::getSpecialBlock($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| if ($block_hash == 'LAST') | |||
| { | |||
| $max = 0; | |||
| // On se met en retard d'au moins un bloc ... | |||
| while(!file_exists(DATA_PATH.'/json/'.$the_block->hash.'.zip')) | |||
| { | |||
| $block_hash = $the_block->prev_block; | |||
| $the_block = blockchain::getSpecialBlock($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| // Mais pas plus de 5 blocs de retard ... | |||
| $max += 1;if ($max > 5) break; | |||
| } | |||
| } | |||
| echo $the_block->hash." ".$the_block->height.PHP_EOL; | |||
| ?> | |||
| @ -0,0 +1,23 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/blockchain_bot.flag | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "blockchain_bot is already running !" | |||
| exit 1 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/blockchain | |||
| rm -f $DATA_PATH/block_list.txt | |||
| php cache.php >> $DATA_PATH/block_list.txt | |||
| for BLOCK in GENESIS THE_ANSWER LUCIFER LEET TOPISTO PIZZA HALVING_1 HALVING_2 BIP_91_LOCK BCC SEGWIT_LOCK SEGWIT LAST | |||
| do | |||
| php robot.php $BLOCK >> $DATA_PATH/block_list.txt | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,18 @@ | |||
| #!/bin/bash | |||
| # | |||
| # VARIABLES | |||
| # | |||
| export APPS_PATH=`dirname "$(readlink -f "$0")"` | |||
| export TMP_PATH=$APPS_PATH/../tmp | |||
| export DATA_PATH=$APPS_PATH/../data | |||
| export FLAG_PATH=$APPS_PATH/../flags | |||
| MINUTE=`date +%M | sed 's/^0*//'` | |||
| DATE=`date +%Y%m%d0000` | |||
| # | |||
| # Clean OLD DATA | |||
| # | |||
| $APPS_PATH/scripts/clean_data.sh | |||
| @ -0,0 +1,26 @@ | |||
| <?php | |||
| // Settings | |||
| $install_dir=getcwd(); | |||
| $install_dir_array = explode('/',$install_dir); | |||
| $install_dir=''; | |||
| for($i=1;$i<count($install_dir_array);$i++) | |||
| { | |||
| if ($install_dir_array[$i] == 'apps') break; | |||
| $install_dir.='/'.$install_dir_array[$i]; | |||
| } | |||
| define('TOPISTO_PATH', $install_dir); | |||
| define('APP_PATH', TOPISTO_PATH.'/apps'); | |||
| define('RESS_PATH', TOPISTO_PATH.'/ressources'); | |||
| define('TMP_PATH', TOPISTO_PATH.'/tmp'); | |||
| define('DATA_PATH', TOPISTO_PATH.'/data'); | |||
| define('BIG_PATH', TOPISTO_PATH.'/big'); | |||
| define('SOLD_PATH', TOPISTO_PATH.'/sold'); | |||
| define('OFFLINE_PATH', RESS_PATH.'/offline'); | |||
| define('GRAPH_WIDTH', 400); | |||
| define('GRAPH_HEIGHT', 300); | |||
| ?> | |||
| @ -0,0 +1,8 @@ | |||
| <?php | |||
| require_once 'inc/config.php'; | |||
| echo getcwd().PHP_EOL; | |||
| echo APP_PATH.PHP_EOL; | |||
| ?> | |||
| @ -0,0 +1,16 @@ | |||
| #!/bin/bash | |||
| # | |||
| # VARIABLES | |||
| # | |||
| export APPS_PATH=`dirname "$(readlink -f "$0")"` | |||
| export TMP_PATH=$APPS_PATH/../tmp | |||
| export DATA_PATH=$APPS_PATH/../data | |||
| export FLAG_PATH=$APPS_PATH/../flags | |||
| MINUTE=`date +%M` | |||
| DATE=`date +%Y%m%d0000` | |||
| source methode/$1/robot.sh | |||
| #source twitter/twitterbot/robot.sh | |||
| @ -0,0 +1,111 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once APP_PATH.'/spline/inc/splines.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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 =''; | |||
| $mode = 0; | |||
| $iterations = 1; | |||
| $bandeau = 50; | |||
| $marge = 25; | |||
| $text_border = 20; | |||
| $width = GRAPH_WIDTH*8; | |||
| $height = GRAPH_HEIGHT*8; | |||
| $img_w = $marge + ($width*2) + (2*$text_border); | |||
| $img_h = $marge + ($height*2) + (2*$bandeau); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor( $img_w, $img_h); | |||
| // | |||
| // Les 4 parties du block : inputs, outputs, fees, reward | |||
| // | |||
| $mode=5; | |||
| $iterations=50; | |||
| $type=2; | |||
| $x0 = $text_border; $y0 = $bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| $type=1; | |||
| $x0 = $text_border+$marge+$width; $y0 = $bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| $type=3; | |||
| $x0 = $text_border; $y0 = $marge+$height+$bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| $type=4; | |||
| $x0 = $text_border+$marge+$width; $y0 = $marge+$height+$bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| $fond = imagecolorallocate($img, 40, 40, 40); | |||
| imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $text_border+$width, $bandeau, $text_border+$marge+$width, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); | |||
| // Les textes | |||
| putenv('GDFONTPATH='.RESS_PATH.'/fonts/'); | |||
| $font = 'DS-DIGIB.TTF'; | |||
| $fontColor = imagecolorallocate($img, 158,227,253); | |||
| $the_texte = "Height : ".$the_block->height; | |||
| imagettftext($img,18, 0, 5, $bandeau-5, $fontColor, $font, $the_texte); | |||
| $the_texte = "Inputs : ".$the_block->topisto_inputs; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); | |||
| $the_texte = "Outputs : ".$the_block->topisto_outputs; | |||
| imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+$height, $fontColor, $font, $the_texte); | |||
| $the_texte = "Fees : ".$the_block->topisto_fees; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| $the_texte = "Reward : ".$the_block->topisto_reward; | |||
| imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $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); | |||
| imagepng($img, BIG_PATH.'/full_spline/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,100 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once APP_PATH.'/methode/spline/inc/splines.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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 =''; | |||
| $mode = 0; | |||
| $iterations = 1; | |||
| $bandeau = 50; | |||
| $marge = 25; | |||
| $text_border = 20; | |||
| $width = GRAPH_WIDTH; | |||
| $height = GRAPH_HEIGHT; | |||
| $img_w = $marge + ($width*2) + (2*$text_border); | |||
| $img_h = $marge + ($height*2) + (2*$bandeau); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor( $img_w, $img_h); | |||
| $param_header = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| $tr_color = $param_header[0]; | |||
| $fond = $param_header[1]; | |||
| $font = $param_header[3]; | |||
| $fontColor = $param_header[2]; | |||
| // | |||
| // Les 4 parties du block : inputs, outputs, fees, reward | |||
| // | |||
| $mode=5; | |||
| $iterations=50; | |||
| $type=1; | |||
| $x0 = $text_border; $y0 = $bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $bandeau + $width*2, $height, $type); | |||
| $type=3; | |||
| $x0 = $text_border; $y0 = $marge+$height+$bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| $type=4; | |||
| $x0 = $text_border+$marge+$width; $y0 = $marge+$height+$bandeau; | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $text_border+$width, $bandeau + $height, $text_border+$marge+$width, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); | |||
| // Les textes | |||
| $the_texte = "Outputs : ".$the_block->topisto_inputs; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); | |||
| $the_texte = "Fees : ".$the_block->topisto_fees; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| $the_texte = "Reward : ".$the_block->topisto_reward; | |||
| imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| imagepng($img, DATA_PATH.'/full_spline/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,33 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/full_spline_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "full_spline_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/full_spline | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/full_spline/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/full_spline/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/full_spline/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/full_spline/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,84 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once APP_PATH.'/methode/treemap/inc/treemap.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=rand(0,5); | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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; | |||
| $img_w = $marge + ($width*2) + (2*$text_border); | |||
| $img_h = $marge + ($height*2) + (2*$bandeau); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor( $img_w, $img_h); | |||
| $param_header = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| $tr_color = $param_header[0]; | |||
| $fond = $param_header[1]; | |||
| $font = $param_header[3]; | |||
| $fontColor = $param_header[2]; | |||
| // Les parties du block : outputs, fees, reward | |||
| topisto_treemap::DrawBlock($the_block, $img, $text_border+0, $bandeau,$marge+($width*2), $height, $mode, 1); | |||
| topisto_treemap::DrawBlock($the_block, $img, $text_border+0, $marge+$height + $bandeau, $width, $height, $mode, 3); | |||
| topisto_treemap::DrawBlock($the_block, $img, $text_border+$marge+$width, $marge+$height + $bandeau, $width, $height, $mode, 4); | |||
| imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $text_border+$width, $bandeau + $height, $text_border+$marge+$width, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); | |||
| // Les textes | |||
| $the_texte = "Outputs : ".$the_block->topisto_inputs; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); | |||
| $the_texte = "Fees : ".$the_block->topisto_fees; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| $the_texte = "Reward : ".$the_block->topisto_reward; | |||
| imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| imagepng($img, DATA_PATH.'/full_treemap/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,33 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/full_treemap_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "treemap_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/full_treemap | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/full_treemap/$BLOCK-$MODE.png ] | |||
| then | |||
| php robot.php $BLOCK $((RANDOM % 6)) | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/full_treemap/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/full_treemap/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/full_treemap/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,82 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once APP_PATH.'/methode/treemap_fuzzy/inc/treemap.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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; | |||
| $img_w = $marge + ($width*2) + (2*$text_border); | |||
| $img_h = $marge + ($height*2) + (2*$bandeau); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor( $img_w, $img_h); | |||
| $param_header = blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| $tr_color = $param_header[0]; | |||
| $fond = $param_header[1]; | |||
| $font = $param_header[3]; | |||
| $fontColor = $param_header[2]; | |||
| // Les parties du block : outputs, fees, reward | |||
| topisto_treemap_fuzzy::DrawBlock($the_block, $img, $text_border+0, $bandeau,$marge+($width*2), $height, $mode, 1); | |||
| topisto_treemap_fuzzy::DrawBlock($the_block, $img, $text_border+0, $marge+$height + $bandeau, $width, $height, $mode, 3); | |||
| topisto_treemap_fuzzy::DrawBlock($the_block, $img, $text_border+$marge+$width, $marge+$height + $bandeau, $width, $height, $mode, 4); | |||
| imagefilledrectangle($img, 0, $bandeau, $text_border, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $img_w-$text_border, $bandeau, $img_w, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, $text_border+$width, $bandeau + $height, $text_border+$marge+$width, $img_h-$bandeau, $fond); | |||
| imagefilledrectangle($img, 0, $bandeau+$height, $img_w - $text_border, $bandeau+$marge+$height, $fond); | |||
| // Les textes | |||
| $the_texte = "Outputs : ".$the_block->topisto_inputs; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+$height, $fontColor, $font, $the_texte); | |||
| $the_texte = "Fees : ".$the_block->topisto_fees; | |||
| imagettftext($img,15, 90, $text_border-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| $the_texte = "Reward : ".$the_block->topisto_reward; | |||
| imagettftext($img,15, 90, $text_border+$width+$marge-3, $bandeau+(2*$height)+$marge-3, $fontColor, $font, $the_texte); | |||
| imagepng($img, DATA_PATH.'/full_treemap_fuzzy/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,32 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/full_treemap_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "treemap_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/full_treemap_fuzzy | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/full_treemap_fuzzy/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/full_treemap_fuzzy/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/full_treemap_fuzzy/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/full_treemap_fuzzy/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,57 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| $width = 840; | |||
| $height = 104; | |||
| $h = $height*6; | |||
| $final_hash = 'default'; | |||
| $img = imagecreatetruecolor($width, $h); | |||
| $tr = imagecolorallocate($img, 220, 220, 220); | |||
| imagecolortransparent($img, $tr); | |||
| imagefilledrectangle($img, 0, 0, $width, $height*6, $tr); | |||
| $handle = fopen(DATA_PATH.'/hashes2hashes/liste.txt', 'r'); | |||
| if ($handle) { | |||
| while (($hash = fgets($handle, 4096)) !== false) { | |||
| $hash = preg_replace('~[[:cntrl:]]~', '', $hash); | |||
| $split = explode(' ', $hash); | |||
| $hash = $split[1]; | |||
| if ($final_hash == 'default') $final_hash = $hash; | |||
| $hash = DATA_PATH.'/hashes/'.$hash.'.png'; | |||
| if (file_exists($hash)) | |||
| { | |||
| $h -= $height; | |||
| $src_img = imagecreatefrompng($hash); | |||
| if ($src_img) | |||
| { | |||
| if (FALSE === imagecopy($img, $src_img, 0, $h, 0, 0, $width, $height)) | |||
| echo "Erreur : problème de copie image".PHP_EOL; | |||
| } else echo "Erreur: ".$hash." ne semble pas être une image PNG".PHP_EOL; | |||
| } else echo "Erreur: ".$hash." n'a pas été trouvé".PHP_EOL; | |||
| } | |||
| if (!feof($handle)) { | |||
| echo "Erreur: fgets() a échoué".PHP_EOL; | |||
| } | |||
| fclose($handle); | |||
| } else echo "Erreur: fopen('".DATA_PATH."/hashes2hashes/liste.txt') a échoué".PHP_EOL; | |||
| imagepng($img, DATA_PATH.'/hashes2hashes/'.$final_hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,60 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../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 = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=rand(0, 5); | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| $bandeau = 50; | |||
| $marge = 0; | |||
| $text_border = 20; | |||
| $width = GRAPH_WIDTH; | |||
| $height = 2; | |||
| // 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); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| imagepng($img, DATA_PATH.'/hashes/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,42 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/hashes_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "hashes_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/hashes | |||
| for BLOCK in `grep LAST $DATA_PATH/block_list.txt | awk '{print $2}'` | |||
| do | |||
| if [ ! -f $DATA_PATH/hashes/$BLOCK.png ] | |||
| then | |||
| BLOCK_HEIGHT=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $3}'` | |||
| php robot.php $BLOCK $((RANDOM % 6)) | |||
| echo $BLOCK_HEIGHT $BLOCK >> $DATA_PATH/hashes2hashes/liste.txt | |||
| mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.new | |||
| sort -k1 -n $DATA_PATH/hashes2hashes/liste.new > $DATA_PATH/hashes2hashes/liste.txt | |||
| rm -f $DATA_PATH/hashes2hashes/liste.new | |||
| COMPTEUR=`wc -l $DATA_PATH/hashes2hashes/liste.txt | awk '{print $1}' ` | |||
| if [ $COMPTEUR -eq 6 ] | |||
| then | |||
| php assemble.php | |||
| rm -f $DATA_PATH/hashes2hashes/liste.old | |||
| mv $DATA_PATH/hashes2hashes/liste.txt $DATA_PATH/hashes2hashes/liste.old | |||
| fi | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/hashes/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/hashes/$BLOCK.png | |||
| fi | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,63 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../global/inc/config.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once 'inc/splines.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $iterations = 1; | |||
| if ($mode > 2) $iterations = 50; | |||
| if (isset($_REQUEST['iterations'])) $iterations=intval($_REQUEST['iterations']); | |||
| $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; | |||
| $width = GRAPH_WIDTH*8; | |||
| $height = GRAPH_HEIGHT*8; | |||
| $img_w = $width; | |||
| $img_h = $height+(2*$bandeau); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| $x0=0; $y0=$bandeau; | |||
| $type=2; | |||
| if (count($the_block->tx) == 1) $type = 4; | |||
| blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| topisto_spline::DefaultDrawBlock($the_block, $img, $x0, $y0, $width, $height, $type); | |||
| imagepng($img, BIG_PATH.'/spline/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,463 @@ | |||
| <?php | |||
| class ColorGradient | |||
| { | |||
| public $pct; | |||
| public $color; | |||
| public static function RGB2HSV($R, $G, $B) // RGB values: 0-255, 0-255, 0-255 | |||
| { // HSV values: 0-360, 0-100, 0-100 | |||
| // Convert the RGB byte-values to percentages | |||
| $R = ($R / 255); | |||
| $G = ($G / 255); | |||
| $B = ($B / 255); | |||
| // Calculate a few basic values, the maximum value of R,G,B, the | |||
| // minimum value, and the difference of the two (chroma). | |||
| $maxRGB = max($R, $G, $B); | |||
| $minRGB = min($R, $G, $B); | |||
| $chroma = $maxRGB - $minRGB; | |||
| // Value (also called Brightness) is the easiest component to calculate, | |||
| // and is simply the highest value among the R,G,B components. | |||
| // We multiply by 100 to turn the decimal into a readable percent value. | |||
| $computedV = 100 * $maxRGB; | |||
| // Special case if hueless (equal parts RGB make black, white, or grays) | |||
| // Note that Hue is technically undefined when chroma is zero, as | |||
| // attempting to calculate it would cause division by zero (see | |||
| // below), so most applications simply substitute a Hue of zero. | |||
| // Saturation will always be zero in this case, see below for details. | |||
| if ($chroma == 0) | |||
| return array(0, 0, $computedV); | |||
| // Saturation is also simple to compute, and is simply the chroma | |||
| // over the Value (or Brightness) | |||
| // Again, multiplied by 100 to get a percentage. | |||
| $computedS = 100 * ($chroma / $maxRGB); | |||
| // Calculate Hue component | |||
| // Hue is calculated on the "chromacity plane", which is represented | |||
| // as a 2D hexagon, divided into six 60-degree sectors. We calculate | |||
| // the bisecting angle as a value 0 <= x < 6, that represents which | |||
| // portion of which sector the line falls on. | |||
| if ($R == $minRGB) | |||
| $h = 3 - (($G - $B) / $chroma); | |||
| elseif ($B == $minRGB) | |||
| $h = 1 - (($R - $G) / $chroma); | |||
| else // $G == $minRGB | |||
| $h = 5 - (($B - $R) / $chroma); | |||
| // After we have the sector position, we multiply it by the size of | |||
| // each sector's arc (60 degrees) to obtain the angle in degrees. | |||
| $computedH = 60 * $h; | |||
| return array($computedH, $computedS, $computedV); | |||
| } | |||
| public static function HSV2RGB($h, $s, $v) | |||
| { | |||
| $s /= 256.0; | |||
| if ($s == 0.0) return array($v,$v,$v); | |||
| $h /= (256.0 / 6.0); | |||
| $i = floor($h); | |||
| $f = $h - $i; | |||
| $p = (integer)($v * (1.0 - $s)); | |||
| $q = (integer)($v * (1.0 - $s * $f)); | |||
| $t = (integer)($v * (1.0 - $s * (1.0 - $f))); | |||
| switch($i) { | |||
| case 0: return array($v,$t,$p); | |||
| case 1: return array($q,$v,$p); | |||
| case 2: return array($p,$v,$t); | |||
| case 3: return array($p,$q,$v); | |||
| case 4: return array($t,$p,$v); | |||
| default: return array($v,$p,$q); | |||
| } | |||
| } | |||
| public static function gradient($from_color, $to_color, $graduations = 10) | |||
| { | |||
| $graduations--; | |||
| $startcol = str_replace("#", "", $from_color); | |||
| $endcol = str_replace("#", "", $to_color); | |||
| $RedOrigin = hexdec(substr($startcol, 0, 2)); | |||
| $GrnOrigin = hexdec(substr($startcol, 2, 2)); | |||
| $BluOrigin = hexdec(substr($startcol, 4, 2)); | |||
| if ($graduations >= 2) { // for at least 3 colors | |||
| $GradientSizeRed = (hexdec(substr($endcol, 0, 2)) - $RedOrigin) / $graduations; //Graduation Size Red | |||
| $GradientSizeGrn = (hexdec(substr($endcol, 2, 2)) - $GrnOrigin) / $graduations; | |||
| $GradientSizeBlu = (hexdec(substr($endcol, 4, 2)) - $BluOrigin) / $graduations; | |||
| for ($i = 0; $i <= $graduations; $i++) { | |||
| $RetVal[$i] = strtoupper("#" . str_pad(dechex($RedOrigin + ($GradientSizeRed * $i)), 2, '0', STR_PAD_LEFT) . | |||
| str_pad(dechex($GrnOrigin + ($GradientSizeGrn * $i)), 2, '0', STR_PAD_LEFT) . | |||
| str_pad(dechex($BluOrigin + ($GradientSizeBlu * $i)), 2, '0', STR_PAD_LEFT)); | |||
| } | |||
| } elseif ($graduations == 1) { // exactlly 2 colors | |||
| $RetVal[] = $from_color; | |||
| $RetVal[] = $to_color; | |||
| } else { // one color | |||
| $RetVal[] = $from_color; | |||
| } | |||
| return $RetVal; | |||
| } | |||
| public static function hex2rgb($hex) { return sscanf($hex, "#%02x%02x%02x"); } | |||
| // --- | |||
| // --- Local fonctions | |||
| // --- | |||
| public static function rgb2hex($rgb) { | |||
| $hex = "#"; | |||
| $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT); | |||
| $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT); | |||
| $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT); | |||
| return $hex; // returns the hex value including the number sign (#) | |||
| } | |||
| } | |||
| class Plot | |||
| { | |||
| private $aCoords; | |||
| function __construct(&$aCoords) | |||
| { | |||
| $this->aCoords = &$aCoords; | |||
| } | |||
| public function drawLine($vImage, $vColor, $iPosX = 0, $imaxX = false) | |||
| { | |||
| $maxX = $imaxX; | |||
| if ($imaxX === false) $maxX = imagesx($vImage); | |||
| reset($this->aCoords); | |||
| list($iPrevX, $iPrevY) = each($this->aCoords); | |||
| while (list ($x, $y) = each($this->aCoords)) | |||
| { | |||
| $laCouleur = null; | |||
| if (!is_array($vColor)) $laCouleur = $vColor; | |||
| else | |||
| { | |||
| $s = count($vColor) - 1; | |||
| $laCouleur = $vColor[$s]->color; | |||
| $pct = $x / $maxX; | |||
| while(($s>0)&&($pct < $vColor[$s]->pct)) | |||
| { | |||
| $s -= 1; | |||
| $laCouleur = $vColor[$s]->color; | |||
| } | |||
| } | |||
| imageline($vImage, round($iPrevX), round($iPrevY), round($x), round($y), $laCouleur); | |||
| $iPrevX = $x; | |||
| $iPrevY = $y; | |||
| } | |||
| } | |||
| public function drawDots($vImage, $vColor, $iPosX = 0, $iPosY = false, $iDotSize = 1) { | |||
| if ($iPosY === false) | |||
| $iPosY = imagesy($vImage); | |||
| $vBorderColor = imagecolorallocate($vImage, 0, 0, 0); | |||
| foreach ($this->aCoords as $x => $y) { | |||
| imagefilledellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vColor); | |||
| imageellipse($vImage, $iPosX + round($x), $iPosY - round($y), $iDotSize, $iDotSize, $vBorderColor); | |||
| } | |||
| } | |||
| public function drawAxis($vImage, $vColor, $iPosX = 0, $iPosY = false) { | |||
| if ($iPosY === false) $iPosY = imagesy($vImage); | |||
| $vImageWidth = imagesx($vImage); | |||
| imageline($vImage, $iPosX, $iPosY, $iPosX, 0, $vColor); | |||
| imageline($vImage, $iPosX, $iPosY, $vImageWidth, $iPosY, $vColor); | |||
| imagefilledpolygon($vImage, array($iPosX, 0, $iPosX - 3, 5, $iPosX + 3, 5), 3, $vColor); | |||
| imagefilledpolygon($vImage, array($vImageWidth, $iPosY, $vImageWidth - 5, $iPosY - 3, $vImageWidth - 5, $iPosY + 3), 3, $vColor); | |||
| } | |||
| } | |||
| class CubicSplines | |||
| { | |||
| protected $aCoords; | |||
| protected $aCrdX; | |||
| protected $aCrdY; | |||
| protected $aSplines = array(); | |||
| protected $iMinX; | |||
| protected $iMaxX; | |||
| protected $iStep; | |||
| protected function prepareCoords(&$aCoords, $iStep, $iMinX = -1, $iMaxX = -1) { | |||
| $this->aCrdX = array(); | |||
| $this->aCrdY = array(); | |||
| $this->aCoords = array(); | |||
| ksort($aCoords); | |||
| foreach ($aCoords as $x => $y) { | |||
| $this->aCrdX[] = $x; | |||
| $this->aCrdY[] = $y; | |||
| } | |||
| $this->iMinX = $iMinX; | |||
| $this->iMaxX = $iMaxX; | |||
| if ($this->iMinX == -1) | |||
| $this->iMinX = min($this->aCrdX); | |||
| if ($this->iMaxX == -1) | |||
| $this->iMaxX = max($this->aCrdX); | |||
| $this->iStep = $iStep; | |||
| } | |||
| public function setInitCoords(&$aCoords, $iStep = 1, $iMinX = -1, $iMaxX = -1) { | |||
| $this->aSplines = array(); | |||
| if (count($aCoords) < 4) { | |||
| return false; | |||
| } | |||
| $this->prepareCoords($aCoords, $iStep, $iMinX, $iMaxX); | |||
| $this->buildSpline($this->aCrdX, $this->aCrdY, count($this->aCrdX)); | |||
| } | |||
| public function processCoords() { | |||
| for ($x = $this->iMinX; $x <= $this->iMaxX; $x += $this->iStep) { | |||
| $this->aCoords[$x] = $this->funcInterp($x); | |||
| } | |||
| return $this->aCoords; | |||
| } | |||
| private function buildSpline($x, $y, $n) { | |||
| for ($i = 0; $i < $n; ++$i) { | |||
| $this->aSplines[$i]['x'] = $x[$i]; | |||
| $this->aSplines[$i]['a'] = $y[$i]; | |||
| } | |||
| $this->aSplines[0]['c'] = $this->aSplines[$n - 1]['c'] = 0; | |||
| $alpha[0] = $beta[0] = 0; | |||
| for ($i = 1; $i < $n - 1; ++$i) { | |||
| $h_i = $x[$i] - $x[$i - 1]; | |||
| $h_i1 = $x[$i + 1] - $x[$i]; | |||
| $A = $h_i; | |||
| $C = 2.0 * ($h_i + $h_i1); | |||
| $B = $h_i1; | |||
| $F = 6.0 * (($y[$i + 1] - $y[$i]) / $h_i1 - ($y[$i] - $y[$i - 1]) / $h_i); | |||
| $z = ($A * $alpha[$i - 1] + $C); | |||
| $alpha[$i] = - $B / $z; | |||
| $beta[$i] = ($F - $A * $beta[$i - 1]) / $z; | |||
| } | |||
| for ($i = $n - 2; $i > 0; --$i) { | |||
| $this->aSplines[$i]['c'] = $alpha[$i] * $this->aSplines[$i + 1]['c'] + $beta[$i]; | |||
| } | |||
| for ($i = $n - 1; $i > 0; --$i) { | |||
| $h_i = $x[$i] - $x[$i - 1]; | |||
| $this->aSplines[$i]['d'] = ($this->aSplines[$i]['c'] - $this->aSplines[$i - 1]['c']) / $h_i; | |||
| $this->aSplines[$i]['b'] = $h_i * (2.0 * $this->aSplines[$i]['c'] + $this->aSplines[$i - 1]['c']) / 6.0 + ($y[$i] - $y[$i - 1]) / $h_i; | |||
| } | |||
| } | |||
| private function funcInterp($x) { | |||
| $n = count($this->aSplines); | |||
| if ($x <= $this->aSplines[0]['x']) { | |||
| $s = $this->aSplines[1]; | |||
| } else { | |||
| if ($x >= $this->aSplines[$n - 1]['x']) { | |||
| $s = $this->aSplines[$n - 1]; | |||
| } else { | |||
| $i = 0; | |||
| $j = $n - 1; | |||
| while ($i + 1 < $j) { | |||
| $k = $i + ($j - $i) / 2; | |||
| if ($x <= $this->aSplines[$k]['x']) { | |||
| $j = $k; | |||
| } else { | |||
| $i = $k; | |||
| } | |||
| } | |||
| $s = $this->aSplines[$j]; | |||
| } | |||
| } | |||
| $dx = ($x - $s['x']); | |||
| return $s['a'] + ($s['b'] + ($s['c'] / 2.0 + $s['d'] * $dx / 6.0) * $dx) * $dx; | |||
| } | |||
| } | |||
| define('TX_HASH_LEN',64); | |||
| class topisto_spline | |||
| { | |||
| public static function DefaultDrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, $type=1) | |||
| { | |||
| topisto_spline::DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, 3.5, 1, $type); | |||
| topisto_spline::DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, 5, 30, $type); | |||
| } | |||
| // | |||
| // modes | |||
| // - 0 : une droite de couleur uniforme | |||
| // - 1 : une droite en dégradé de couleur | |||
| // - 2 : une spline en dégradé de couleur passant les valeurs du hash de la transaction | |||
| // - 3 : la spline dessinée en 2 est atténuée à gauche et amplifiée à droite | |||
| // - 3.5 : idem mode 3, mais avec de la transparence | |||
| // - 4 : $iterations splines oscillants autour de la spline dessinée en 2 | |||
| // - 4.5 : les splines sont desssinées en transparence | |||
| // | |||
| public static function DrawBlock($the_block, $vImage, $x, $y, $graph_width, $graph_height, $mode, $iterations, $type=1) | |||
| { | |||
| $somme = 0; | |||
| $min =-1; | |||
| $max = 0; | |||
| $data = blockchain::getTransactionData($the_block, $type); | |||
| $local_iterations = $iterations; | |||
| $n_data = count($data); | |||
| $vBgColor = imagecolorallocate($vImage, 10, 10, 10); | |||
| imagefilledrectangle($vImage, $x, $y, $x+$graph_width, $y+$graph_height, $vBgColor); | |||
| // Calcul des min max | |||
| foreach($data as $v) | |||
| { | |||
| if ($v['value'] > $max) $max = $v['value']; | |||
| if (($v['value'] < $min)||($min == -1)) $min = $v['value']; | |||
| $somme += $v['value']; | |||
| } | |||
| if ($min == $max) $max = $min + 1; | |||
| if ($somme == 0) return; | |||
| // --- | |||
| // --- On se limite à 40 000 traits | |||
| // --- Pour des questions de performance | |||
| // --- | |||
| while(($n_data * $local_iterations)>40000) $local_iterations--; | |||
| $vColor = array(); | |||
| // Gestion de la transparence | |||
| $alpha = 125; | |||
| if ($mode < 4.5) $alpha = 0; | |||
| if ($mode == 3.5) $alpha = 100; | |||
| // On choisit des couleurs au hasard | |||
| $hex_val = array( | |||
| ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]), | |||
| ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]), | |||
| ColorGradient::rgb2hex([rand(0,255),rand(0,255),rand(0,255)]) | |||
| ); | |||
| // dan sla moitié des cas, on s'en tient au "dégradé de feu" | |||
| if (rand(0,100) > 50) $hex_val = array('#D2691E', '#FF8C00', '#EEEEEE'); | |||
| $rgbval = ColorGradient::hex2rgb($hex_val[0]); | |||
| $n = 0; | |||
| $vColor[$n] = new ColorGradient(); | |||
| $vColor[$n]->pct = 0; | |||
| $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); | |||
| $n += 1; | |||
| $vColor[$n] = new ColorGradient(); | |||
| $vColor[$n]->pct = 0.1; | |||
| $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); | |||
| if ($mode > 0) | |||
| { | |||
| $gradient = ColorGradient::gradient($hex_val[0], $hex_val[1], 60); | |||
| for($i=0;$i<60;$i++) | |||
| { | |||
| $rgbval = ColorGradient::hex2rgb($gradient[$i]); | |||
| $n += 1; | |||
| $vColor[$n] = new ColorGradient(); | |||
| $vColor[$n]->pct = (10+$i) / 100.0; | |||
| $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); | |||
| } | |||
| $gradient = ColorGradient::gradient($hex_val[1], $hex_val[2],30); | |||
| for($i=0;$i<30;$i++) | |||
| { | |||
| $rgbval = ColorGradient::hex2rgb($gradient[$i]); | |||
| $n += 1; | |||
| $vColor[$n] = new ColorGradient(); | |||
| $vColor[$n]->pct = (70+$i) / 100.0; | |||
| $vColor[$n]->color = imagecolorallocatealpha($vImage, $rgbval[0], $rgbval[1], $rgbval[2], $alpha); | |||
| } | |||
| } | |||
| ////////// | |||
| $oCurve = new CubicSplines(); | |||
| $marge_x = 10; | |||
| $marge_y = 20; | |||
| $coef = ($graph_height - (2*$marge_y)) / $somme; | |||
| $dx = $graph_width; | |||
| if ($mode > 0) $dx = round($dx / (TX_HASH_LEN+1)); | |||
| //$limite_x = $x + ($graph_width - $marge_x); | |||
| $limite_x = $x + $graph_width - $marge_x; | |||
| $h0 = 0; | |||
| $hauteur = $y + $marge_y; | |||
| $special_draw = (count($data) == 1); | |||
| foreach($data as $transaction) | |||
| { | |||
| // | |||
| // La nouvelle hauteur : cumule des montants de transaction | |||
| // | |||
| $hauteur += $coef * $transaction['value']; | |||
| // | |||
| // Cas des blocks qui n'ont qu'une seule transaction | |||
| // | |||
| if ($special_draw) $hauteur = $y + ($graph_height / 2); | |||
| // | |||
| // Ne pas tracer 2 lignes à la même hauteur | |||
| // | |||
| if ((floor($hauteur)-$h0)<2) continue; | |||
| $h0 = floor($hauteur); | |||
| // | |||
| // On va faire des itérations sur la transaction courante. | |||
| // A chaque itération, on va s'appuyer sur le hash de la transaction | |||
| // mais en introduisant du bruit. | |||
| // On va donc statistiquement tracer une courbe représentant le hash | |||
| // | |||
| for($j=0;$j<$local_iterations;$j++) | |||
| { | |||
| // | |||
| // On recommence en début de ligne | |||
| // | |||
| $x0 = $x + $marge_x; | |||
| // | |||
| // La première partie est une ligne droite | |||
| // | |||
| imageline($vImage, $x0, $h0, $x0+$dx, $h0, $vColor[0]->color); | |||
| $x0 += $dx; | |||
| // | |||
| // Le mode 0 consiste à tracer une droite de couleur uniforme | |||
| // | |||
| if (($mode == 0)||($x0 >= $limite_x)) continue; | |||
| $aCoords = array(); | |||
| $facteur = 1; | |||
| if ($mode > 2) $facteur = 0.04; | |||
| // | |||
| // On découpe la ligne en fonction du nombre de DIGIT | |||
| // dans le hash des transactions | |||
| // | |||
| $aCoords[$x0] = $h0; | |||
| for ($i = 0; $i < (TX_HASH_LEN-1); $i++) | |||
| { | |||
| $y0 = $h0; | |||
| if ($mode > 1) | |||
| { | |||
| $y0 += (hexdec($transaction['hash'][$i]) - 8) * $facteur; | |||
| $valeur = rand(-16, 16) * $facteur; | |||
| if ($mode > 2) $facteur += 0.02; | |||
| if ($mode > 3) $y0 += $valeur; | |||
| } | |||
| $x0 += $dx; | |||
| $aCoords[$x0] = $y0; | |||
| } | |||
| if ($oCurve) | |||
| { | |||
| $oCurve->setInitCoords($aCoords); | |||
| $r = $oCurve->processCoords(); | |||
| if ($r) | |||
| { | |||
| $curveGraph = new Plot($r); | |||
| $curveGraph->drawLine($vImage, $vColor, $x0, $limite_x); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,69 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once 'inc/splines.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $iterations = 1; | |||
| if ($mode > 2) $iterations = 200; | |||
| if (isset($argv[3])) $iterations=intval($argv[3]); | |||
| $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); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| $x0=0; $y0=$bandeau; | |||
| $type=2; | |||
| if (count($the_block->tx) == 1) $type = 4; | |||
| blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| topisto_spline::DrawBlock($the_block, $img, $x0, $y0, $width, $height, $mode, $iterations, $type); | |||
| imagepng($img, DATA_PATH.'/spline/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,33 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/spline_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "spline_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/spline | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/spline/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/spline/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/spline/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/spline/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,156 @@ | |||
| <?php | |||
| use codeagent\treemap\Treemap; | |||
| use codeagent\treemap\presenter\ImagePresenter; | |||
| use codeagent\treemap\presenter\NodeInfo; | |||
| use codeagent\treemap\Gradient; | |||
| // --- | |||
| // --- Local fonctions | |||
| // --- | |||
| function rgb2hex($rgb) { | |||
| $hex = "#"; | |||
| $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT); | |||
| $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT); | |||
| $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT); | |||
| return $hex; // returns the hex value including the number sign (#) | |||
| } | |||
| function hex2rgb($color){ | |||
| $color = str_replace('#', '', $color); | |||
| if (strlen($color) != 6){ return array(0,0,0); } | |||
| $rgb = array(); | |||
| for ($x=0;$x<3;$x++){ | |||
| $rgb[$x] = hexdec(substr($color,(2*$x),2)); | |||
| } | |||
| return $rgb; | |||
| } | |||
| class topisto_treemap | |||
| { | |||
| private static function getRGB($methode, $gradient, $factor) | |||
| { | |||
| switch($methode) | |||
| { | |||
| case 0: | |||
| $rgb = [rand(0,255),rand(0,255),rand(0,255)]; | |||
| break; | |||
| case 1: | |||
| $rgb = [80,80,80]; | |||
| break; | |||
| case 2: | |||
| $factor=rand(0,100); | |||
| $rgb = [255,255,255]; | |||
| if ($factor < 50 ) $rgb = [255,0,0]; | |||
| if ($factor < 25 ) $rgb = [0,0,255]; | |||
| if ($factor < 10 ) $rgb = [255,255,0]; | |||
| break; | |||
| case 3: | |||
| $rgb = hex2rgb($gradient[1]->color($factor)); | |||
| break; | |||
| case 4: | |||
| $rgb = hex2rgb($gradient[2]->color($factor)); | |||
| break; | |||
| case 999: | |||
| $rgb = hex2rgb($gradient[3]->color($factor)); | |||
| break; | |||
| default: | |||
| $rgb = hex2rgb($gradient[0]->color($factor)); | |||
| } | |||
| return $rgb; | |||
| } | |||
| public static function DrawBlock($the_block, $vImage, $x, $y, $width, $height, $methode, $type=1) | |||
| { | |||
| $full_area = $width * $height; | |||
| if ($full_area == 0) $full_area = 1; | |||
| $data = blockchain::getTransactionData($the_block, $type); | |||
| $vBgColor = imagecolorallocate($vImage, 10, 10, 10); | |||
| imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor); | |||
| // quelques gradient de couleurs ... | |||
| $rgb1 = [rand(0,255),rand(0,255),rand(0,255)]; | |||
| $rgb2 = [rand(0,255),rand(0,255),rand(0,255)]; | |||
| $gradient = []; | |||
| $gradient[] = new Gradient(['0.0' => '#f75557', '0.5' => '#646a82', '1.0' => '#5ad87b']); | |||
| $gradient[] = new Gradient(['0.0' => '#FF69B4', '1.0' => '#FF5555']); | |||
| $gradient[] = new Gradient(['0.0' => rgb2hex($rgb1), '1.0' => rgb2hex($rgb2)]); | |||
| $gradient[] = new Gradient(['0.0' => '#FFFFFF', '1.0' => '#000000']); | |||
| if ($type == 4) | |||
| { | |||
| // Cas particulier pour la récompense | |||
| $reward = 0; | |||
| foreach($data as $v) $reward += $v['value']; | |||
| $pct = $reward / 5000000000.0; | |||
| $w = round($width * $pct); | |||
| $h = round($height * $pct); | |||
| $x1 = $x + (($width/2) - ($w /2)); | |||
| $y1 = $y + (($height/2) - ($h /2)); | |||
| $rgb = self::getRGB($methode, $gradient, $pct*100); | |||
| $vFgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]); | |||
| $rgb = self::getRGB(999, $gradient, $pct*100); | |||
| $vBgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]); | |||
| if (($h < 2)&&($w< 2)) | |||
| { | |||
| imagesetpixel($vImage, $x1, $y1, $vFgColor); | |||
| } else { | |||
| $x2 = $x1 + $w; | |||
| $y2 = $y1 + $h; | |||
| imagefilledrectangle($vImage, $x1, $y1, $x2, $y2, $vFgColor); | |||
| imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor); | |||
| } | |||
| } else { | |||
| $treemap = new Treemap($data, $width, $height); | |||
| $map = $treemap->getMap(); | |||
| $m = count($map); | |||
| $flag_contour = true; | |||
| for($mm = 0; $mm < $m; $mm++) | |||
| { | |||
| $tx = $map[$mm]; | |||
| $factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0; | |||
| $x1 = $x + $tx['_rectangle']->left; | |||
| $y1 = $y + $tx['_rectangle']->top; | |||
| // if (($x1 == ($x+$width))||($x1 == ($y+$height))) break; | |||
| $rgb = self::getRGB($methode, $gradient, $factor); | |||
| // Pas de noir absolu | |||
| if (($rgb[0]+$rgb[1]+$rgb[2]) == 0) | |||
| $vFgColor = imagecolorallocate($vImage, 10, 10, 10); | |||
| else | |||
| $vFgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]); | |||
| $rgb = self::getRGB(999, $gradient, $factor); | |||
| $vBgColor = imagecolorallocate($vImage, $rgb[0], $rgb[1], $rgb[2]); | |||
| $x2 = $x1 + $tx['_rectangle']->width; | |||
| $y2 = $y1 + $tx['_rectangle']->height; | |||
| if ($x1 > ($x+$width)) $x1 = ($x+$width); | |||
| if ($y1 > ($y+$height)) $y1 = ($y+$height); | |||
| if ($x2 > ($x+$width)) $x2 = ($x+$width); | |||
| if ($y2 > ($y+$height)) $y2 = ($y+$height); | |||
| imagefilledrectangle($vImage, $x1, $y1, $x2, $y2, $vFgColor); | |||
| if ((($x2-$x1) > 2)||(($y2-$y1) > 2)) | |||
| imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,81 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once 'inc/treemap.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=rand(0, 5); | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| $type=2; | |||
| if (count($the_block->tx)==1) $type=4; | |||
| $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]; | |||
| topisto_treemap::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type); | |||
| imagepng($img, DATA_PATH.'/treemap/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,32 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/treemap_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "treemap_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/treemap | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/treemap/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK $((RANDOM % 6)) | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/treemap/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/treemap/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/treemap/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,118 @@ | |||
| <?php | |||
| use codeagent\treemap\Treemap; | |||
| use codeagent\treemap\presenter\ImagePresenter; | |||
| use codeagent\treemap\presenter\NodeInfo; | |||
| use codeagent\treemap\Gradient; | |||
| // --- | |||
| // --- Local fonctions | |||
| // --- | |||
| function rgb2hex($rgb) { | |||
| $hex = "#"; | |||
| $hex .= str_pad(dechex($rgb[0]), 2, "0", STR_PAD_LEFT); | |||
| $hex .= str_pad(dechex($rgb[1]), 2, "0", STR_PAD_LEFT); | |||
| $hex .= str_pad(dechex($rgb[2]), 2, "0", STR_PAD_LEFT); | |||
| return $hex; // returns the hex value including the number sign (#) | |||
| } | |||
| function hex2rgb($color){ | |||
| $color = str_replace('#', '', $color); | |||
| if (strlen($color) != 6){ return array(0,0,0); } | |||
| $rgb = array(); | |||
| for ($x=0;$x<3;$x++){ | |||
| $rgb[$x] = hexdec(substr($color,(2*$x),2)); | |||
| } | |||
| return $rgb; | |||
| } | |||
| class topisto_treemap | |||
| { | |||
| private static function getRGB($methode, $gradient, $factor) | |||
| { | |||
| switch($methode) | |||
| { | |||
| case 0: | |||
| $rgb = [rand(0,255),rand(0,255),rand(0,255)]; | |||
| break; | |||
| case 1: | |||
| $rgb = [80,80,80]; | |||
| break; | |||
| case 2: | |||
| $factor=rand(0,100); | |||
| $rgb = [255,255,255]; | |||
| if ($factor < 50 ) $rgb = [255,0,0]; | |||
| if ($factor < 25 ) $rgb = [0,0,255]; | |||
| if ($factor < 10 ) $rgb = [255,255,0]; | |||
| break; | |||
| case 3: | |||
| $rgb = hex2rgb($gradient[1]->color($factor)); | |||
| break; | |||
| case 4: | |||
| $rgb = hex2rgb($gradient[2]->color($factor)); | |||
| break; | |||
| case 999: | |||
| $rgb = hex2rgb($gradient[3]->color($factor)); | |||
| break; | |||
| default: | |||
| $rgb = hex2rgb($gradient[0]->color($factor)); | |||
| } | |||
| return $rgb; | |||
| } | |||
| public static function DrawBlock($the_block, $vImage, $parametres) | |||
| { | |||
| $type = 1; | |||
| if (isset($parametres['x'])) $x = $parametres['x']; | |||
| if (isset($parametres['y'])) $y = $parametres['y']; | |||
| if (isset($parametres['width'])) $width = $parametres['width']; | |||
| if (isset($parametres['height'])) $height = $parametres['height']; | |||
| if (isset($parametres['methode'])) $mode = $parametres['methode']; | |||
| if (isset($parametres['type'])) $type = $parametres['type']; | |||
| if (isset($parametres['font_color'])) $vBgColor = $parametres['font_color']; | |||
| if (isset($parametres['background_color'])) $vFgColor = $parametres['background_color']; | |||
| imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor); | |||
| $full_area = $width * $height; | |||
| if ($full_area == 0) $full_area = 1; | |||
| $data = blockchain::getTransactionData($the_block, $type); | |||
| $treemap = new Treemap($data, $width, $height); | |||
| $map = $treemap->getMap(); | |||
| $m = count($map); | |||
| $flag_contour = true; | |||
| for($mm = 0; $mm < $m; $mm++) | |||
| { | |||
| $tx = $map[$mm]; | |||
| $factor = (($tx['_rectangle']->width * $tx['_rectangle']->height) / $full_area)*100.0; | |||
| $x1 = $x + $tx['_rectangle']->left; | |||
| $y1 = $y + $tx['_rectangle']->top; | |||
| $x2 = $x1 + $tx['_rectangle']->width; | |||
| $y2 = $y1 + $tx['_rectangle']->height; | |||
| if ($x1 > ($x+$width)) $x1 = ($x+$width); | |||
| if ($y1 > ($y+$height)) $y1 = ($y+$height); | |||
| if ($x2 > ($x+$width)) $x2 = ($x+$width); | |||
| if ($y2 > ($y+$height)) $y2 = ($y+$height); | |||
| imagerectangle($vImage, $x1, $y1, $x2, $y2, $vBgColor); | |||
| } | |||
| imagerectangle($vImage, $x, $y, $x+$width-1, $y+$height, $vBgColor); | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,81 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once 'inc/treemap.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=rand(0, 5); | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| $type=2; | |||
| if (count($the_block->tx)==1) $type=4; | |||
| $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]; | |||
| topisto_treemap::DrawBlock($the_block, $img, $parametres); | |||
| imagepng($img, DATA_PATH.'/treemapV2/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,32 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/treemapV2_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "treemap_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/treemapV2 | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/treemapV2/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK $((RANDOM % 6)) | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/treemapV2/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/treemapV2/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/treemapV2/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,92 @@ | |||
| <?php | |||
| use codeagent\treemap\Treemap; | |||
| use codeagent\treemap\presenter\ImagePresenter; | |||
| use codeagent\treemap\presenter\NodeInfo; | |||
| use codeagent\treemap\Gradient; | |||
| function rgb2hex($rgb) | |||
| { | |||
| return "#0203FF"; | |||
| } | |||
| class topisto_treemap_fuzzy | |||
| { | |||
| public static function DrawBlock($the_block, $vImage, $x, $y, $width, $height, $mode, $type=1) | |||
| { | |||
| $min =-1; | |||
| $max = 0; | |||
| $data = blockchain::getTransactionData($the_block, $type); | |||
| $vBgColor = imagecolorallocate($vImage, 10, 10, 10); | |||
| imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor); | |||
| // Calcul des min max | |||
| foreach($data as $v) | |||
| { | |||
| if ($v['value'] > $max) $max = $v['value']; | |||
| if (($v['value'] < $min)||($min == -1)) $min = $v['value']; | |||
| } | |||
| if ($min == $max) $max = $min + 1; | |||
| $tDrawColor = array(); | |||
| $tDrawColor[0] = imagecolorallocatealpha($vImage, 140, 246, 138, 125); | |||
| $tDrawColor[1] = imagecolorallocatealpha($vImage, 200, 200, 200, 125); | |||
| $treemap = new Treemap($data, $width, $height); | |||
| $map = $treemap->getMap(); | |||
| $mm = count($map); | |||
| $mmax = $mm - 30; | |||
| foreach($map as $tx) | |||
| { | |||
| $x1 = $x + $tx['_rectangle']->left; | |||
| $y1 = $y + $tx['_rectangle']->top; | |||
| if (($tx['_rectangle']->height < 2)&&($tx['_rectangle']->width < 2)) | |||
| { | |||
| imagesetpixel($vImage, $x1, $y1, $tDrawColor[1]); | |||
| } else { | |||
| $x2 = $x1; | |||
| $y2 = $y1 + $tx['_rectangle']->height; | |||
| // if ($y2 >= ($height-$bandeau)) $y2 = ($height - $bandeau) - 1; | |||
| $x3 = $x1 + $tx['_rectangle']->width; | |||
| $y3 = $y2; | |||
| $x4 = $x3; | |||
| $y4 = $y1; | |||
| // ---- | |||
| $w = floor($tx['_rectangle']->width / 4); | |||
| $h = floor($tx['_rectangle']->height / 4); | |||
| $ww = floor(200*($mm/$mmax)); | |||
| $ww = $h * $w; | |||
| for($i=0;$i<$ww;$i++) | |||
| { | |||
| $vDrawColor2 = $tDrawColor[$i%2]; | |||
| $x1_1 = $x1 + floor($w*( rand(0, 100) / 100)); | |||
| $y1_1 = $y1 + floor($h*( rand(0, 100) / 100)); | |||
| $x2_1 = $x2 + floor($w*( rand(0, 100) / 100)); | |||
| $y2_1 = $y2 - floor($h*( rand(0, 100) / 100)); | |||
| $x3_1 = $x3 - floor($w*( rand(0, 100) / 100)); | |||
| $y3_1 = $y3 - floor($h*( rand(0, 100) / 100)); | |||
| $x4_1 = $x4 - floor($w*( rand(0, 100) / 100)); | |||
| $y4_1 = $y4 + floor($h*( rand(0, 100) / 100)); | |||
| imageline($vImage, $x1_1, $y1_1, $x2_1, $y2_1, $vDrawColor2); | |||
| imageline($vImage, $x2_1, $y2_1, $x3_1, $y3_1, $vDrawColor2); | |||
| imageline($vImage, $x3_1, $y3_1, $x4_1, $y4_1, $vDrawColor2); | |||
| imageline($vImage, $x4_1, $y4_1, $x1_1, $y1_1, $vDrawColor2); | |||
| } | |||
| } | |||
| $mm -= 1; | |||
| } | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,69 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once 'inc/treemap.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| $type=2; | |||
| if (count($the_block->tx)==1) $type = 4; | |||
| blockchain::DrawBlockHeaderFooter($the_block, $img, $bandeau); | |||
| topisto_treemap_fuzzy::DrawBlock($the_block, $img, 0, $bandeau, $width, $height, $mode, $type); | |||
| imagepng($img, DATA_PATH.'/treemap_fuzzy/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,33 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/treemap_fuzzy_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "treemap_fuzzy_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/treemap_fuzzy | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/treemap_fuzzy/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK $(( RANDOM % 6)) | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/treemap_fuzzy/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/treemap_fuzzy/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/treemap_fuzzy/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,103 @@ | |||
| <?php | |||
| use codeagent\treemap\Treemap; | |||
| use codeagent\treemap\presenter\ImagePresenter; | |||
| use codeagent\treemap\presenter\NodeInfo; | |||
| use codeagent\treemap\Gradient; | |||
| function rgb2hex($rgb) | |||
| { | |||
| return "#0203FF"; | |||
| } | |||
| class topisto_veraMolnar | |||
| { | |||
| public static function DrawBlock($the_block, $vImage, $parametres) | |||
| { | |||
| $type = 1; | |||
| if (isset($parametres['x'])) $x = $parametres['x']; | |||
| if (isset($parametres['y'])) $y = $parametres['y']; | |||
| if (isset($parametres['width'])) $width = $parametres['width']; | |||
| if (isset($parametres['height'])) $height = $parametres['height']; | |||
| if (isset($parametres['methode'])) $mode = $parametres['methode']; | |||
| if (isset($parametres['type'])) $type = $parametres['type']; | |||
| if (isset($parametres['font_color'])) $vFgColor = $parametres['font_color']; | |||
| if (isset($parametres['background_color'])) $vBgColor = $parametres['background_color']; | |||
| if (isset($parametres['font_RGB'])) $vFgRGB = $parametres['font_RGB']; | |||
| if (isset($parametres['background_RGB'])) $vBgRGB = $parametres['background_RGB']; | |||
| $min =-1; | |||
| $max = 0; | |||
| $data = blockchain::getTransactionData($the_block, $type); | |||
| // Inverser foreground et Background | |||
| imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vFgColor); | |||
| $vFgColor = imagecolorallocatealpha($vImage, $vBgRGB[0], $vBgRGB[1], $vBgRGB[2], 125); | |||
| //$vBgColor = imagecolorallocate($vImage, 10, 10, 10); | |||
| //imagefilledrectangle($vImage, $x, $y, $x+$width, $y+$height, $vBgColor); | |||
| // Calcul des min max | |||
| foreach($data as $v) | |||
| { | |||
| if ($v['value'] > $max) $max = $v['value']; | |||
| if (($v['value'] < $min)||($min == -1)) $min = $v['value']; | |||
| } | |||
| if ($min == $max) $max = $min + 1; | |||
| $treemap = new Treemap($data, $width, $height); | |||
| $map = $treemap->getMap(); | |||
| $mm = count($map); | |||
| $mmax = $mm - 30; | |||
| foreach($map as $tx) | |||
| { | |||
| $x1 = $x + $tx['_rectangle']->left; | |||
| $y1 = $y + $tx['_rectangle']->top; | |||
| if (($tx['_rectangle']->height < 2)&&($tx['_rectangle']->width < 2)) | |||
| { | |||
| imagesetpixel($vImage, $x1, $y1, $vFgColor); | |||
| } else { | |||
| $x2 = $x1; | |||
| $y2 = $y1 + $tx['_rectangle']->height; | |||
| // if ($y2 >= ($height-$bandeau)) $y2 = ($height - $bandeau) - 1; | |||
| $x3 = $x1 + $tx['_rectangle']->width; | |||
| $y3 = $y2; | |||
| $x4 = $x3; | |||
| $y4 = $y1; | |||
| // ---- | |||
| $w = floor($tx['_rectangle']->width / 4); | |||
| $h = floor($tx['_rectangle']->height / 4); | |||
| $ww = floor(200*($mm/$mmax)); | |||
| $ww = floor(($h * $w)*0.8); | |||
| if ($ww < 1) $ww = 1; | |||
| for($i=0;$i<$ww;$i++) | |||
| { | |||
| $x1_1 = $x1 + floor($w*( rand(0, 100) / 100)); | |||
| $y1_1 = $y1 + floor($h*( rand(0, 100) / 100)); | |||
| $x2_1 = $x2 + floor($w*( rand(0, 100) / 100)); | |||
| $y2_1 = $y2 - floor($h*( rand(0, 100) / 100)); | |||
| $x3_1 = $x3 - floor($w*( rand(0, 100) / 100)); | |||
| $y3_1 = $y3 - floor($h*( rand(0, 100) / 100)); | |||
| $x4_1 = $x4 - floor($w*( rand(0, 100) / 100)); | |||
| $y4_1 = $y4 + floor($h*( rand(0, 100) / 100)); | |||
| imageline($vImage, $x1_1, $y1_1, $x2_1, $y2_1, $vFgColor); | |||
| imageline($vImage, $x2_1, $y2_1, $x3_1, $y3_1, $vFgColor); | |||
| imageline($vImage, $x3_1, $y3_1, $x4_1, $y4_1, $vFgColor); | |||
| imageline($vImage, $x4_1, $y4_1, $x1_1, $y1_1, $vFgColor); | |||
| } | |||
| } | |||
| $mm -= 1; | |||
| } | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,83 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require_once 'inc/treemap.php'; | |||
| // --- | |||
| // --- Par défaut on cherche le dernier block | |||
| // --- | |||
| $block_hash = 'LAST'; | |||
| // --- | |||
| // --- Le cas échéant, on cherche block passé en argument | |||
| // --- | |||
| if (isset($argv[1])) $block_hash = $argv[1]; | |||
| $mode=8; | |||
| if (isset($argv[2])) $mode=intval($argv[2]); | |||
| $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); | |||
| // création d'une image plus haute pour inclure bandeaux haut et bas | |||
| $img = imagecreatetruecolor($img_w, $img_h); | |||
| $type=2; | |||
| if (count($the_block->tx)==1) $type = 4; | |||
| $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]; | |||
| topisto_veraMolnar::DrawBlock($the_block, $img, $parametres); | |||
| imagepng($img, DATA_PATH.'/veraMolnar/'.$the_block->hash.'.png'); | |||
| imagedestroy($img); | |||
| ?> | |||
| @ -0,0 +1,33 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/veraMolnar_bot.flag | |||
| date=`date +%Y%m%d0000` | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "veraMolnar_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/methode/veraMolnar | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| if [ ! -f $DATA_PATH/veraMolnar/$BLOCK.png ] | |||
| then | |||
| php robot.php $BLOCK $(( RANDOM % 6)) | |||
| fi | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" == "LAST" ] | |||
| then | |||
| touch $DATA_PATH/veraMolnar/$BLOCK.png | |||
| else | |||
| touch -t $date $DATA_PATH/veraMolnar/$BLOCK.png | |||
| fi | |||
| rm -f $DATA_PATH/hasard/$BLOCK.png | |||
| ln $DATA_PATH/veraMolnar/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| done | |||
| rm -f $flag | |||
| @ -0,0 +1,37 @@ | |||
| #!/bin/bash | |||
| # | |||
| # VARIABLES | |||
| # | |||
| export APPS_PATH=`dirname "$(readlink -f "$0")"` | |||
| export TMP_PATH=$APPS_PATH/../tmp | |||
| export DATA_PATH=$APPS_PATH/../data | |||
| export FLAG_PATH=$APPS_PATH/../flags | |||
| export MINUTE=`date +%M | sed 's/^0*//'` | |||
| export DATE=`date +%Y%m%d0000` | |||
| # | |||
| # Synchronize the Blockchain | |||
| # | |||
| $APPS_PATH/scripts/synchronize.sh | |||
| # | |||
| # Draw the HASHES | |||
| # | |||
| $APPS_PATH/scripts/hashes.sh | |||
| # | |||
| # Draw the BLOCKS | |||
| # | |||
| $APPS_PATH/scripts/blocks.sh | |||
| # | |||
| # Send a TWEET | |||
| # | |||
| $APPS_PATH/scripts/tweet.sh | |||
| # | |||
| # Clean OLD DATA | |||
| # | |||
| $APPS_PATH/scripts/clean_data.sh | |||
| @ -0,0 +1,138 @@ | |||
| #!/bin/bash | |||
| # | |||
| # VARIABLES | |||
| # | |||
| export APPS_PATH=`dirname "$(readlink -f "$0")"` | |||
| export TMP_PATH=$APPS_PATH/../tmp | |||
| export DATA_PATH=$APPS_PATH/../data | |||
| export FLAG_PATH=$APPS_PATH/../flags | |||
| MINUTE=`date +%M | sed 's/^0*//'` | |||
| DATE=`date +%Y%m%d0000` | |||
| # | |||
| # OUTILS | |||
| # | |||
| function debug | |||
| { | |||
| if [ -f $FLAG_PATH/debug ] | |||
| then | |||
| echo $1 | |||
| fi | |||
| } | |||
| function sortie | |||
| { | |||
| exit $1 | |||
| } | |||
| function succes | |||
| { | |||
| debug "SUCCES" | |||
| sortie 0 | |||
| } | |||
| function echec | |||
| { | |||
| debug "ECHEC" | |||
| sortie 1 | |||
| } | |||
| # synchro de la blockchain | |||
| if [ -f $FLAG_PATH/no_blockchain ] | |||
| then | |||
| debug "No Blockchain synchro" | |||
| else | |||
| debug "Update the Blockchain" | |||
| $APPS_PATH/blockchain/robot.sh 2>&1 | |||
| STATUS=$? | |||
| if [ ! $STATUS -eq 0 ] | |||
| then | |||
| echec | |||
| fi | |||
| fi | |||
| # | |||
| # Toujours placer la version HASHES | |||
| # | |||
| $APPS_PATH/methode/hashes/robot.sh | |||
| # | |||
| # CHOISIR UN MODE AU HASARD | |||
| # | |||
| ROBOT=`ls $APPS_PATH/methode | grep -v hashes | shuf | tail -n 1` | |||
| debug $ROBOT | |||
| # | |||
| # Y A PLUS QU'A ! | |||
| # | |||
| if [ ! -f $FLAG_PATH/no_$ROBOT ] | |||
| then | |||
| cd $APPS_PATH/methode/$ROBOT | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| # | |||
| # Pour renouveller l'affichage des blocs remarquables | |||
| # De temps en temps (15%), on efface le block | |||
| # | |||
| if [ $((RANDOM % 100)) -lt 15 ] | |||
| then | |||
| rm -f $DATA_PATH/$ROBOT/$BLOCK.png | |||
| fi | |||
| if [ ! -f $DATA_PATH/$ROBOT/$BLOCK.png ] | |||
| then | |||
| debug "Compute $DATA_PATH/$ROBOT/$BLOCK.png" | |||
| php robot.php $BLOCK | |||
| fi | |||
| # | |||
| # Les blocs remarquables sont anti datés à minuit | |||
| # Pour l'affichage et le nettoyage automatique | |||
| # | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" != "LAST" ] | |||
| then | |||
| touch -t $DATE $DATA_PATH/$ROBOT/$BLOCK.png | |||
| fi | |||
| if [ ! -f $DATA_PATH/hasard/$BLOCK.png ] | |||
| then | |||
| ln $DATA_PATH/$ROBOT/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| fi | |||
| done | |||
| fi | |||
| # | |||
| # TWEET toutes les 20 minutes | |||
| # | |||
| if [ 0 -eq $TWEET ] | |||
| then | |||
| debug "send a TWEET" | |||
| # tweet R. Topisto | |||
| $APPS_PATH/twitter/twitterbot/robot.sh 2>&1 | |||
| # "auto likes" from Topisto | |||
| $APPS_PATH/twitter/likebot/robot.sh 2>&1 | |||
| fi | |||
| # | |||
| # CLEAN OLD DATA | |||
| # | |||
| if [ -d $DATA_PATH ] | |||
| then | |||
| find $DATA_PATH -mtime +1 -type f -name *.png -exec rm -f {} \; | |||
| find $DATA_PATH -mtime +1 -type f -name *.zip -exec rm -f {} \; | |||
| fi | |||
| rm -f $DATA_PATH/finished_block_list.txt | |||
| grep -v CACHE $DATA_PATH/block_list.txt >> $DATA_PATH/finished_block_list.txt | |||
| # | |||
| # SORTIE AVEC SUCCES | |||
| # | |||
| succes | |||
| @ -0,0 +1,125 @@ | |||
| #!/bin/bash | |||
| lescript=`basename $0 .sh` | |||
| flag=$TMP_PATH/bot_$lescript.flag | |||
| # | |||
| # TOOLS | |||
| # | |||
| function debug | |||
| { | |||
| if [ -f $FLAG_PATH/debug ] | |||
| then | |||
| echo $1 | |||
| fi | |||
| } | |||
| function sortie | |||
| { | |||
| if [ -f $flag ] | |||
| then | |||
| rm -f $flag | |||
| fi | |||
| exit $1 | |||
| } | |||
| function succes | |||
| { | |||
| debug "SUCCES" | |||
| sortie 0 | |||
| } | |||
| function echec | |||
| { | |||
| debug "ECHEC" | |||
| exit 1 | |||
| } | |||
| # | |||
| # TEST DU FLAG | |||
| # | |||
| if [ -f $flag ] | |||
| then | |||
| debug "$0 is already running !" | |||
| echec | |||
| fi | |||
| touch $flag | |||
| # | |||
| # PARAMETRES PAR FICHIER FLAGS | |||
| # | |||
| if [ -f $FLAG_PATH/no_blocks ] | |||
| then | |||
| debug "No blocks" | |||
| echec | |||
| fi | |||
| # | |||
| # CHOISIR UNE METHODE AU HASARD | |||
| # | |||
| ROBOT=`ls $APPS_PATH/methode | grep -v hashes | shuf | tail -n 1` | |||
| debug $ROBOT | |||
| # | |||
| # Y A PLUS QU'A ! | |||
| # | |||
| if [ ! -f $FLAG_PATH/no_$ROBOT ] | |||
| then | |||
| cd $APPS_PATH/methode/$ROBOT | |||
| for BLOCK in `awk '{print $2}' $DATA_PATH/block_list.txt` | |||
| do | |||
| # | |||
| # Pour renouveller l'affichage des blocs remarquables | |||
| # De temps en temps (15%), on efface le block | |||
| # | |||
| if [ $((RANDOM % 100)) -lt 15 ] | |||
| then | |||
| rm -f $DATA_PATH/$ROBOT/$BLOCK.png | |||
| fi | |||
| # | |||
| # Si l'image n'existe pas, on la calcule | |||
| # | |||
| if [ ! -f $DATA_PATH/$ROBOT/$BLOCK.png ] | |||
| then | |||
| debug "Compute $DATA_PATH/$ROBOT/$BLOCK.png" | |||
| php robot.php $BLOCK | |||
| fi | |||
| # | |||
| # Les actions suivantes ne sont réalisées que si | |||
| # robot.php a produit une image | |||
| # | |||
| if [ -f $DATA_PATH/$ROBOT/$BLOCK.png ] | |||
| then | |||
| # | |||
| # Les blocs remarquables sont anti datés à minuit | |||
| # Pour l'affichage et le nettoyage automatique | |||
| # | |||
| BNAME=`grep $BLOCK $DATA_PATH/block_list.txt | awk '{print $1}'` | |||
| if [ "$BNAME" != "LAST" ] | |||
| then | |||
| touch -t $DATE $DATA_PATH/$ROBOT/$BLOCK.png | |||
| fi | |||
| # | |||
| # Maintenir le hasard | |||
| # | |||
| if [ ! -f $DATA_PATH/hasard/$BLOCK.png ] | |||
| then | |||
| ln $DATA_PATH/$ROBOT/$BLOCK.png $DATA_PATH/hasard/$BLOCK.png | |||
| fi | |||
| fi | |||
| done | |||
| fi | |||
| # | |||
| # List of finished blocks | |||
| # | |||
| rm -f $DATA_PATH/finished_block_list.txt | |||
| grep -v CACHE $DATA_PATH/block_list.txt >> $DATA_PATH/finished_block_list.txt | |||
| # | |||
| # SORTIE AVEC SUCCES | |||
| # | |||
| succes | |||
| @ -0,0 +1,23 @@ | |||
| #!/bin/bash | |||
| if [ "$#" -eq "0" ] | |||
| then | |||
| if [ -d $DATA_PATH ] | |||
| then | |||
| find $DATA_PATH -mtime +1 -type f -name *.png -exec rm -f {} \; | |||
| find $DATA_PATH -mtime +1 -type f -name *.zip -exec rm -f {} \; | |||
| fi | |||
| else | |||
| if [ "$1" -eq "FULL" ] | |||
| then | |||
| if [ -d $DATA_PATH ] | |||
| then | |||
| rm -f $DATA_PATH/*/* | |||
| fi | |||
| if [ -d $TMP_PATH ] | |||
| then | |||
| rm -f $TMP_PATH/* | |||
| fi | |||
| fi | |||
| fi | |||
| @ -0,0 +1,65 @@ | |||
| #!/bin/bash | |||
| lescript=`basename $0 .sh` | |||
| flag=$TMP_PATH/bot_$lescript.flag | |||
| # | |||
| # TOOLS | |||
| # | |||
| function debug | |||
| { | |||
| if [ -f $FLAG_PATH/debug ] | |||
| then | |||
| echo $1 | |||
| fi | |||
| } | |||
| function sortie | |||
| { | |||
| if [ -f $flag ] | |||
| then | |||
| rm -f $flag | |||
| fi | |||
| exit $1 | |||
| } | |||
| function succes | |||
| { | |||
| debug "SUCCES" | |||
| sortie 0 | |||
| } | |||
| function echec | |||
| { | |||
| debug "ECHEC" | |||
| sortie 1 | |||
| } | |||
| # | |||
| # TEST DU FLAG | |||
| # | |||
| if [ -f $flag ] | |||
| then | |||
| debug "$0 is already running !" | |||
| exit 1 | |||
| fi | |||
| touch $flag | |||
| # | |||
| # PARAMETRES PAR FICHIER FLAGS | |||
| # | |||
| if [ -f $FLAG_PATH/no_hashes ] | |||
| then | |||
| debug "No Hashes" | |||
| echec | |||
| fi | |||
| # | |||
| # Toujours placer la version HASHES | |||
| # | |||
| debug "Compute HASHES ..." | |||
| $APPS_PATH/methode/hashes/robot.sh | |||
| # | |||
| # SORTIE AVEC SUCCES | |||
| # | |||
| succes | |||
| @ -0,0 +1,21 @@ | |||
| #!/bin/bash | |||
| # | |||
| # VARIABLES | |||
| # | |||
| export APPS_PATH=`dirname "$(readlink -f "$0")"` | |||
| export TMP_PATH=$APPS_PATH/../tmp | |||
| export DATA_PATH=$APPS_PATH/../data | |||
| export FLAG_PATH=$APPS_PATH/../flags | |||
| MINUTE=`date +%M` | |||
| DATE=`date +%Y%m%d0000` | |||
| for methode in `ls $APPS_PATH/methode` | |||
| do | |||
| echo $methode | |||
| source $APPS_PATH/methode/$methode/robot.sh | |||
| done | |||
| @ -0,0 +1,68 @@ | |||
| #!/bin/bash | |||
| lescript=`basename $0 .sh` | |||
| flag=$TMP_PATH/bot_$lescript.flag | |||
| # | |||
| # TOOLS | |||
| # | |||
| function debug | |||
| { | |||
| if [ -f $FLAG_PATH/debug ] | |||
| then | |||
| echo $1 | |||
| fi | |||
| } | |||
| function sortie | |||
| { | |||
| if [ -f $flag ] | |||
| then | |||
| rm -f $flag | |||
| fi | |||
| exit $1 | |||
| } | |||
| function succes | |||
| { | |||
| debug "SUCCES" | |||
| sortie 0 | |||
| } | |||
| function echec | |||
| { | |||
| debug "ECHEC" | |||
| sortie 1 | |||
| } | |||
| # | |||
| # TEST DU FLAG | |||
| # | |||
| if [ -f $flag ] | |||
| then | |||
| debug "$0 is already running !" | |||
| exit 1 | |||
| fi | |||
| touch $flag | |||
| # | |||
| # Synchronize the Blockchain | |||
| # | |||
| if [ -f $FLAG_PATH/no_blockchain ] | |||
| then | |||
| debug "No Blockchain synchro" | |||
| echec | |||
| fi | |||
| debug "Update the Blockchain ..." | |||
| $APPS_PATH/blockchain/robot.sh 2>&1 | |||
| STATUS=$? | |||
| if [ ! $STATUS -eq 0 ] | |||
| then | |||
| echec | |||
| fi | |||
| # | |||
| # SORTIE AVEC SUCCES | |||
| # | |||
| succes | |||
| @ -0,0 +1,76 @@ | |||
| #!/bin/bash | |||
| lescript=`basename $0 .sh` | |||
| flag=$TMP_PATH/bot_$lescript.flag | |||
| # | |||
| # TOOLS | |||
| # | |||
| function debug | |||
| { | |||
| if [ -f $FLAG_PATH/debug ] | |||
| then | |||
| echo $1 | |||
| fi | |||
| } | |||
| function sortie | |||
| { | |||
| if [ -f $flag ] | |||
| then | |||
| rm -f $flag | |||
| fi | |||
| exit $1 | |||
| } | |||
| function succes | |||
| { | |||
| debug "SUCCES" | |||
| sortie 0 | |||
| } | |||
| function echec | |||
| { | |||
| debug "ECHEC" | |||
| sortie 1 | |||
| } | |||
| # | |||
| # TEST DU FLAG | |||
| # | |||
| if [ -f $flag ] | |||
| then | |||
| debug "$0 is already running !" | |||
| exit 1 | |||
| fi | |||
| touch $flag | |||
| # | |||
| # PARAMETRES PAR FICHIER FLAGS | |||
| # | |||
| if [ -f $FLAG_PATH/no_tweet ] | |||
| then | |||
| debug "No Tweet" | |||
| echec | |||
| fi | |||
| # | |||
| # TWEET | |||
| # | |||
| TWEET=3 | |||
| if [ $((MINUTE % $TWEET)) -eq 0 ] | |||
| then | |||
| debug "send a TWEET" | |||
| # tweet R. Topisto | |||
| $APPS_PATH/twitter/twitterbot/robot.sh 2>&1 | |||
| # "auto likes" from Topisto | |||
| $APPS_PATH/twitter/likebot/robot.sh 2>&1 | |||
| else | |||
| debug "no TWEET" | |||
| fi | |||
| # | |||
| # SORTIE AVEC SUCCES | |||
| # | |||
| succes | |||
| @ -0,0 +1,50 @@ | |||
| <?php | |||
| // --- | |||
| // --- Get last R. Topisto 's tweet | |||
| // --- Send a LIKE or ReTweet it. | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| use Abraham\TwitterOAuth\TwitterOAuth; | |||
| // Twitter OAuth Settings: | |||
| /* TOPISTO | |||
| define('CONSUMER_KEY', 'HBInbm93bM80z86XVJ34rtjxO'); | |||
| define('CONSUMER_SECRET', 'zpdSp8yv9R2VODgPRA0RZbiO7VE8vSPNLVNg9zI0HjWnJKADO8'); | |||
| define('ACCESS_TOKEN', '315679287-EjINhav5VbJPscb4h9pw3WwveeeX0ShpnIjcawDe'); | |||
| define('ACCESS_TOKEN_SECRET', 'SIFKfPYEoIdlAyeQKVS3y067uNFuLpy013wRycJ8VxNcd'); | |||
| */ | |||
| /* R. Topisto */ | |||
| define('CONSUMER_KEY', '9Ie6CjwM5eZSQu5Xnbel4PBqm'); | |||
| define('CONSUMER_SECRET', 'pI4ha5gW7Lft6Lg5xP7nH49Yqbm8PwLn1EP8D1qKg1q0SYd5t2'); | |||
| define('ACCESS_TOKEN', '840479603143630849-c3xFLJFvo77ubP1njoXHpFu9LQqKLR8'); | |||
| define('ACCESS_TOKEN_SECRET', 'EW4Zi10cQnNfoOunnEF1svJ3omz223U57G6KuYo5ZZ2Ls'); | |||
| $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); | |||
| $content = $twitter->get('account/verify_credentials'); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| $theSearch = [ | |||
| 'screen_name' => 'r_topisto', | |||
| 'count' => 1 | |||
| ]; | |||
| // --- | |||
| // --- envoi d'un LIKE | |||
| // --- | |||
| $results = $twitter->get('users/show', $theSearch); | |||
| $twitter->post('favorites/create', ['id' => $results->status->id_str]); | |||
| ?> | |||
| @ -0,0 +1,19 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/topisto_bot.flag | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "likebot_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/twitter/likebot | |||
| if [ 4 -gt $((RANDOM % 100)) ] | |||
| then | |||
| php topisto.php | |||
| fi | |||
| rm -f $flag | |||
| @ -0,0 +1 @@ | |||
| ["topisto42","UnnaxPayments","aureliusdrusus","solacedotcom","omgbtc","ohiobitcoin","LogicScience","redunisproject","Cryptocracy2020","fullstache","callblockapp","marketranger","TheCryptodamus","crypt0co","CryptoassetsUSA","Nadeem_nadi797","cryptomoneyz","BaseCyberSec","Tweetsintoabyss","anthkell98","grattonboy","mac_a_dam","devnullius","123wolfArmy","03018333860","JeffinkoGuru","BitJob_Team","rugigana","Crypto_info321","cointopic_","Chef_JeanPierre","Cienencom","btcltcdigger","AdzCoin_Gift","treyptrsn","n2yolo","SHL0M0ABADD0N","EdwardCulligan","promote_crypto","TheFutureShift","ErickCoval","RIMCorpPK","arhiezvanhoute1","ttoff85","actu_fintech","BeautyBubble","PDX_Trader","Yasirperdesi","cre8hyperledger","Thurse8","cre8capital","icobountyprogs","rob67803423","AphexTwin4ever"] | |||
| @ -0,0 +1,88 @@ | |||
| <?php | |||
| use Abraham\TwitterOAuth\TwitterOAuth; | |||
| // Twitter OAuth Settings: | |||
| /* TOPISTO | |||
| define('CONSUMER_KEY', 'HBInbm93bM80z86XVJ34rtjxO'); | |||
| define('CONSUMER_SECRET', 'zpdSp8yv9R2VODgPRA0RZbiO7VE8vSPNLVNg9zI0HjWnJKADO8'); | |||
| define('ACCESS_TOKEN', '315679287-EjINhav5VbJPscb4h9pw3WwveeeX0ShpnIjcawDe'); | |||
| define('ACCESS_TOKEN_SECRET', 'SIFKfPYEoIdlAyeQKVS3y067uNFuLpy013wRycJ8VxNcd'); | |||
| */ | |||
| /* R. Topisto */ | |||
| define('CONSUMER_KEY', '9Ie6CjwM5eZSQu5Xnbel4PBqm'); | |||
| define('CONSUMER_SECRET', 'pI4ha5gW7Lft6Lg5xP7nH49Yqbm8PwLn1EP8D1qKg1q0SYd5t2'); | |||
| define('ACCESS_TOKEN', '840479603143630849-c3xFLJFvo77ubP1njoXHpFu9LQqKLR8'); | |||
| define('ACCESS_TOKEN_SECRET', 'EW4Zi10cQnNfoOunnEF1svJ3omz223U57G6KuYo5ZZ2Ls'); | |||
| define('TWITTER_WIDTH', 880); | |||
| define('TWITTER_HEIGHT', 440); | |||
| class twitter | |||
| { | |||
| public static function tweet($message, $media='') | |||
| { | |||
| $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); | |||
| $content = $twitter->get('account/verify_credentials'); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| $parameters = array("status" => $message); | |||
| if (($media != NULL)&&($media != '')) | |||
| { | |||
| $imageMedia = $twitter->upload('media/upload', array('media' => $media)); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| $parameters = array( | |||
| "status" => $message, | |||
| "media_ids" => $imageMedia->media_id_string); | |||
| } | |||
| $statuses = $twitter->post("statuses/update", $parameters); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| return TRUE; | |||
| } | |||
| public static function thanksRetweet() | |||
| { | |||
| $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); | |||
| $content = $twitter->get('account/verify_credentials'); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| $results = $twitter->get('statuses/retweets_of_me'); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| /* TO DO */ | |||
| return TRUE; | |||
| } | |||
| public static function thanksFollowers() | |||
| { | |||
| $twitter = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, ACCESS_TOKEN, ACCESS_TOKEN_SECRET); | |||
| $content = $twitter->get('account/verify_credentials'); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| $results = $twitter->get('followers/list'); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| $followers = json_decode(file_get_contents('followers.json')); | |||
| foreach($results->users as $user) | |||
| if (!in_array($user->screen_name, $followers)) | |||
| { | |||
| $parameters = array("status" => '@'.$user->screen_name.' thanks following me !'); | |||
| $followers[] = $user->screen_name; | |||
| $statuses = $twitter->post("statuses/update", $parameters); | |||
| if ($twitter->getLastHttpCode() !== 200) return FALSE; | |||
| break; // Un à la fois ... | |||
| } | |||
| file_put_contents('followers.json', json_encode($followers)); | |||
| return TRUE; | |||
| } | |||
| } | |||
| ?> | |||
| @ -0,0 +1,78 @@ | |||
| <?php | |||
| // --- | |||
| // --- Listening to blockchain.info to get the last block | |||
| // --- Drawing the block as a Treemap | |||
| // --- Tweet it | |||
| // --- | |||
| // --- | |||
| // --- La config globale | |||
| // --- | |||
| require_once '../../global/inc/config.php'; | |||
| // --- | |||
| // --- External dependances | |||
| // --- | |||
| require TOPISTO_PATH.'/ressources/vendor/autoload.php'; | |||
| // --- | |||
| // --- Internal dependances | |||
| // --- | |||
| require_once APP_PATH.'/blockchain/inc/block.php'; | |||
| require 'inc/twitter.php'; | |||
| $methode='spline'; | |||
| if (isset($argv[3])) $methode=$argv[3]; | |||
| $block_hash = $argv[1]; | |||
| $the_block = blockchain::getBlockWithHash($block_hash); | |||
| if ($the_block === FALSE) die(); | |||
| // --- | |||
| // --- Remercier les followers | |||
| // --- | |||
| twitter::thanksFollowers(); | |||
| $image_file=DATA_PATH."/$methode/".$argv[1].'.png'; | |||
| if (file_exists($image_file)) | |||
| { | |||
| $image_origine = imagecreatefrompng($image_file); | |||
| $image_twitter = imagecreatetruecolor(TWITTER_WIDTH, TWITTER_HEIGHT); | |||
| $fond = imagecolorallocate($image_twitter, 255, 255, 255); | |||
| //imagecolortransparent($image_twitter, $fond); | |||
| imagefilledrectangle($image_twitter, 0, 0, TWITTER_WIDTH, TWITTER_HEIGHT, $fond); | |||
| $ratio = TWITTER_HEIGHT / imagesy($image_origine); | |||
| $new_width = $ratio * imagesx($image_origine); | |||
| $xpos = floor((TWITTER_WIDTH - $new_width) / 2); | |||
| $ypos = 0; | |||
| imagecopyresized($image_twitter, $image_origine, $xpos, $ypos, 0, 0, $new_width, TWITTER_HEIGHT, imagesx($image_origine), imagesy($image_origine)); | |||
| $image_file = DATA_PATH."/twitterbot/".$argv[1].'.png'; | |||
| imagepng($image_twitter,$image_file); | |||
| // --- | |||
| // --- Un petit peu de stéganographie ... | |||
| // --- | |||
| /* Ca fait des fichiers trop gros ! | |||
| $processor = new KzykHys\Steganography\Processor(); | |||
| $image = $processor->encode($image_file, 'TOPISTO is making art with block '.$the_block->height); | |||
| $image->write($image_file); | |||
| */ | |||
| // --- | |||
| // --- Tweet | |||
| // --- | |||
| $tweet = "#bitcoin #blockchain 's".PHP_EOL; | |||
| $tweet .= $argv[2]." Block, Height : ".$the_block->height.PHP_EOL; | |||
| $tweet .= "[ See more on www.topisto.net ]"; | |||
| $success = twitter::tweet($tweet, $image_file); | |||
| } | |||
| ?> | |||
| @ -0,0 +1,67 @@ | |||
| #!/bin/bash | |||
| flag=$TMP_PATH/twitterbot_bot.flag | |||
| if [ -f $flag ]; | |||
| then | |||
| echo "twitter_bot is already running !" | |||
| exit 0 | |||
| fi | |||
| touch $flag | |||
| cd $APPS_PATH/twitter/twitterbot | |||
| # | |||
| # Tweet pour un assemblage de hash | |||
| # | |||
| for fichier in `ls $DATA_PATH/hashes2hashes/*.png` | |||
| do | |||
| BLOCK=`basename $fichier .png` | |||
| if [ ! -f $DATA_PATH/twitterbot/assemblage_$BLOCK ] | |||
| then | |||
| php robot.php $BLOCK CONFIRMED hashes2hashes | |||
| touch $DATA_PATH/twitterbot/assemblage_$BLOCK | |||
| rm -f $flag | |||
| exit 0 | |||
| fi | |||
| done | |||
| # | |||
| # Se lancer pour un tweet sur un block unique | |||
| # | |||
| BLOCK_LINE=`tail -n 1 $DATA_PATH/block_list.txt` | |||
| BLOCK_HASH=`echo ${BLOCK_LINE} | awk '{print $2}'` | |||
| BLOCK_NAME=`echo ${BLOCK_LINE} | awk '{print $1}'` | |||
| BLOCK_HEIGHT=`echo ${BLOCK_LINE} | awk '{print $3}'` | |||
| # | |||
| # Dans 5% des cas, on tweet un bloc remarquable | |||
| # à la place du LAST | |||
| # | |||
| if [ 5 -gt $((RANDOM % 100)) ] | |||
| then | |||
| BLOCK_LINE=`grep -v $BLOCK_NAME $DATA_PATH/block_list.txt | shuf | head -n 1` | |||
| BLOCK_HASH=`echo ${BLOCK_LINE} | awk '{print $2}'` | |||
| BLOCK_NAME=`echo ${BLOCK_LINE} | awk '{print $1}'` | |||
| BLOCK_HEIGHT=`echo ${BLOCK_LINE} | awk '{print $3}'` | |||
| fi | |||
| if [ -f $DATA_PATH/hasard/$BLOCK_HASH.png ] | |||
| then | |||
| if [ ! -f $DATA_PATH/twitterbot/$BLOCK_HASH ] | |||
| then | |||
| echo Tweet for $BLOCK_HASH $BLOCK_NAME | |||
| php robot.php $BLOCK_HASH $BLOCK_NAME hasard $BLOCK_HEIGHT | |||
| # | |||
| # On met un marqueur pour ne pas retweeter | |||
| # plusieurs fois le LAST | |||
| # | |||
| if [[ "$BLOCK_NAME" == "LAST" ]] | |||
| then | |||
| touch $DATA_PATH/twitterbot/$BLOCK_HASH | |||
| fi | |||
| fi | |||
| fi | |||
| rm -f $flag | |||