$value) * @return string */ public static function button($nameId, array $attributes = []) { // Attributs par défaut $attributes = array_merge([ 'class' => '', 'disabled' => false, 'href' => 'javascript:void(0);', 'ico' => '', 'id' => $nameId, 'name' => $nameId, 'target' => '', 'uniqueSubmission' => false, 'value' => 'Bouton', 'help' => '' ], $attributes); // Retourne le html return sprintf( '%s', helper::sprintAttributes($attributes, ['class', 'disabled', 'ico', 'value']), $attributes['disabled'] ? 'disabled' : '', $attributes['class'], $attributes['uniqueSubmission'] ? 'uniqueSubmission' : '', $attributes['help'] ? ' title="' . $attributes['help'] . '" ': '', ($attributes['ico'] ? template::ico($attributes['ico'], 'right') : '') . $attributes['value'] ); } /** * Crée un champ captcha * @param string $nameId Nom et id du champ * @param array $attributes Attributs ($key => $value) * @return string */ public static function captcha($nameId, array $attributes = []) { // Attributs par défaut $attributes = array_merge([ 'class' => '', 'classWrapper' => '', 'help' => '', 'id' => $nameId, 'name' => $nameId, 'value' => '', 'limit' => false, // captcha simple 'type'=> 'alpha' // num(érique) ou alpha(bétique) ], $attributes); // Captcha quatre opérations // Limite addition et soustraction selon le type de captcha $numbers = [0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20]; $letters = ['u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a']; $limit = $attributes['limit'] ? count($letters)-1 : 10; // Tirage de l'opération mt_srand((float) microtime()*1000000); // Captcha simple limité à l'addition $operator = $attributes['limit'] ? mt_rand (1, 4) : 1; // Limite si multiplication ou division if ($operator > 2) { $limit = 10; } // Tirage des nombres mt_srand((float) microtime()*1000000); $firstNumber = mt_rand (1, $limit); mt_srand((float) microtime()*1000000); $secondNumber = mt_rand (1, $limit); // Permutation si addition ou soustraction if (($operator < 3) and ($firstNumber < $secondNumber)) { $temp = $firstNumber; $firstNumber = $secondNumber; $secondNumber = $temp; } // Icône de l'opérateur et calcul du résultat switch ($operator) { case 1: $operator = template::ico('plus'); $result = $firstNumber + $secondNumber; break; case 2: $operator = template::ico('minus'); $result = $firstNumber - $secondNumber; break; case 3: $operator = template::ico('cancel'); $result = $firstNumber * $secondNumber; break; case 4: $operator = template::ico('divide'); $limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2]; for ($i = 1; $i <= $firstNumber; $i++) { $limit = $limit2[$i-1]; } mt_srand((float) microtime()*1000000); $secondNumber = mt_rand(1, $limit); $firstNumber = $firstNumber * $secondNumber; $result = $firstNumber / $secondNumber; break; } // Hashage du résultat $result = password_hash($result, PASSWORD_BCRYPT); // Codage des valeurs de l'opération $firstLetter = uniqid(); $secondLetter = uniqid(); // Masquage image source pour éviter un décodage copy ('core/vendor/zwiico/png/' . $attributes['type'] . '/' . $letters[$firstNumber] . '.png', 'site/tmp/' . $firstLetter . '.png'); copy ('core/vendor/zwiico/png/' . $attributes['type'] . '/' . $letters[$secondNumber] . '.png', 'site/tmp/' . $secondLetter . '.png'); // Début du wrapper $html = '