forked from ZwiiCMS-Team/ZwiiCMS
Update template.class.php
This commit is contained in:
parent
5de144f947
commit
1915f554b7
@ -49,26 +49,30 @@ class template {
|
|||||||
'value' => '',
|
'value' => '',
|
||||||
'limit' => false
|
'limit' => false
|
||||||
], $attributes);
|
], $attributes);
|
||||||
|
|
||||||
// Tirage de l'opération et des nombres
|
// Tirage de l'opération et des nombres
|
||||||
|
// Correspondance tableau des images
|
||||||
$numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20);
|
$numbers = array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20);
|
||||||
$letters = array('u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a');
|
$letters = array('u','t','s','r','q','p','o','n','m','l','k','j','i','h','g','f','e','d','c','b','a');
|
||||||
|
|
||||||
|
// Détermination de la limitation
|
||||||
$limit = $attributes['limit'] ? count($letters)-1 : 10;
|
$limit = $attributes['limit'] ? count($letters)-1 : 10;
|
||||||
mt_srand((float) microtime()*1000000);
|
mt_srand((float) microtime()*1000000);
|
||||||
$operator = mt_rand (0, 3);
|
$operator = mt_rand (0, 3);
|
||||||
if ($operator > 1) {
|
|
||||||
$limit = 10;
|
// Limiter les valuers si pas une addition
|
||||||
}
|
if ($operator > 1) $limit = 10;
|
||||||
$firstNumber = mt_rand (1, $limit);
|
$firstNumber = mt_rand (1, $limit);
|
||||||
$secondNumber = mt_rand (1, $limit);
|
$secondNumber = mt_rand (1, $limit);
|
||||||
|
|
||||||
if ( ($operator < 2)
|
// Ordre des valeurs selon type d'opération
|
||||||
AND ($firstNumber < $secondNumber) )
|
if (($operator < 2) AND ($firstNumber < $secondNumber)) {
|
||||||
{
|
|
||||||
$temp = $firstNumber;
|
$temp = $firstNumber;
|
||||||
$firstNumber = $secondNumber;
|
$firstNumber = $secondNumber;
|
||||||
$secondNumber = $temp;
|
$secondNumber = $temp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Calcul du résultat et icône de l'opérateur
|
||||||
switch ($operator) {
|
switch ($operator) {
|
||||||
case 0:
|
case 0:
|
||||||
$operator = template::ico('plus');
|
$operator = template::ico('plus');
|
||||||
@ -84,40 +88,37 @@ class template {
|
|||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
$operator = template::ico('divide');
|
$operator = template::ico('divide');
|
||||||
switch ($firstNumber) {
|
$limit2 = [10, 10, 6, 5, 4, 3, 2, 2, 2, 2];
|
||||||
case 3:
|
for ($i = 1; $i <= $firstNumber; $i++) {
|
||||||
$limit = 6;
|
$limit = $limit2[$i-1];
|
||||||
break;
|
|
||||||
case 4:
|
|
||||||
$limit = 5;
|
|
||||||
break;
|
|
||||||
case 5:
|
|
||||||
$limit = 4;
|
|
||||||
break;
|
|
||||||
case 6:
|
|
||||||
$limit = 3;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
if ($firstNumber > 6) $limit = 2;
|
mt_srand((float) microtime()*1000000);
|
||||||
|
$secondNumber = mt_rand(1, $limit);
|
||||||
$secondNumber = mt_rand(1, $limit);
|
$firstNumber = $firstNumber * $secondNumber;
|
||||||
$firstNumber = $firstNumber * $secondNumber;
|
$result = $firstNumber / $secondNumber;
|
||||||
$result = $firstNumber / $secondNumber;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Hashage du résultat
|
||||||
$result = password_hash($result, PASSWORD_BCRYPT);
|
$result = password_hash($result, PASSWORD_BCRYPT);
|
||||||
|
|
||||||
|
// Codage des valeurs de l'opération
|
||||||
$firstLetter = uniqid();
|
$firstLetter = uniqid();
|
||||||
$secondLetter = uniqid();
|
$secondLetter = uniqid();
|
||||||
// Masquage image source
|
|
||||||
|
// Masquage image source pour éviter un décodage
|
||||||
copy ('core/vendor/zwiico/png/'.$letters[$firstNumber] . '.png', 'site/tmp/' . $firstLetter . '.png');
|
copy ('core/vendor/zwiico/png/'.$letters[$firstNumber] . '.png', 'site/tmp/' . $firstLetter . '.png');
|
||||||
copy ('core/vendor/zwiico/png/'.$letters[$secondNumber] . '.png', 'site/tmp/' . $secondLetter . '.png');
|
copy ('core/vendor/zwiico/png/'.$letters[$secondNumber] . '.png', 'site/tmp/' . $secondLetter . '.png');
|
||||||
|
|
||||||
// Début du wrapper
|
// Début du wrapper
|
||||||
$html = '<div class="captcha" id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
$html = '<div class="captcha" id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
|
||||||
|
|
||||||
// Label
|
// Label
|
||||||
$html .= self::label($attributes['id'],
|
$html .= self::label($attributes['id'],
|
||||||
'<img src="' . helper::baseUrl(false) . 'site/tmp/' . $firstLetter . '.png" /> <strong>' . $operator . '</strong> <img class="captchaNumber" src="' . helper::baseUrl(false) . 'site/tmp/' . $secondLetter . '.png" /> en chiffres ?', [
|
'<img src="' . helper::baseUrl(false) . 'site/tmp/' . $firstLetter . '.png" /> <strong>' . $operator . '</strong> <img class="captchaNumber" src="' . helper::baseUrl(false) . 'site/tmp/' . $secondLetter . '.png" /> en chiffres ?', [
|
||||||
'help' => $attributes['help']
|
'help' => $attributes['help']
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Notice
|
// Notice
|
||||||
$notice = '';
|
$notice = '';
|
||||||
if(array_key_exists($attributes['id'], common::$inputNotices)) {
|
if(array_key_exists($attributes['id'], common::$inputNotices)) {
|
||||||
@ -125,18 +126,22 @@ class template {
|
|||||||
$attributes['class'] .= ' notice';
|
$attributes['class'] .= ' notice';
|
||||||
}
|
}
|
||||||
$html .= self::notice($attributes['id'], $notice);
|
$html .= self::notice($attributes['id'], $notice);
|
||||||
|
|
||||||
// captcha
|
// captcha
|
||||||
$html .= sprintf(
|
$html .= sprintf(
|
||||||
'<input type="text" %s>',
|
'<input type="text" %s>',
|
||||||
helper::sprintAttributes($attributes)
|
helper::sprintAttributes($attributes)
|
||||||
);
|
);
|
||||||
|
|
||||||
// Champ résultat codé
|
// Champ résultat codé
|
||||||
$html .= self::hidden($attributes['id'] . 'Result', [
|
$html .= self::hidden($attributes['id'] . 'Result', [
|
||||||
'value' => $result,
|
'value' => $result,
|
||||||
'before' => false
|
'before' => false
|
||||||
]);
|
]);
|
||||||
|
|
||||||
// Fin du wrapper
|
// Fin du wrapper
|
||||||
$html .= '</div>';
|
$html .= '</div>';
|
||||||
|
|
||||||
// Retourne le html
|
// Retourne le html
|
||||||
return $html;
|
return $html;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user