Filtres CMS 13.3.05

This commit is contained in:
Fred Tempez 2024-08-14 09:23:38 +02:00
parent 60455ae036
commit b8c5d613bc
3 changed files with 75 additions and 47 deletions

View File

@ -8,7 +8,7 @@ class helper
/** Filtres personnalisés */
const FILTER_BOOLEAN = 1;
const FILTER_DATETIME = 2;
const FILTER_DATETIME = 2; // filtre pour le champ de formulaire A conserver pour la compatibilité
const FILTER_FLOAT = 3;
const FILTER_ID = 4;
const FILTER_INT = 5;
@ -16,8 +16,14 @@ class helper
const FILTER_PASSWORD = 7;
const FILTER_STRING_LONG = 8;
const FILTER_STRING_SHORT = 9;
const FILTER_TIMESTAMP = 10;
const FILTER_TIMESTAMP = 10; // Saisie d'une date en locatime
const FILTER_URL = 11;
const FILTER_DATE = 12; // filtre pour le champ de formulaire
const FILTER_TIME = 13; // filtre pour le champ de formulair
const FILTER_MONTH = 14; // filtre pour le champ de formulair
const FILTER_YEAR = 16; // filtre pour le champ de formulair
/**
@ -29,12 +35,12 @@ class helper
// La traduction existe déjà dans le core
/*
if (array_key_exists($text, core::$dialog) === false && !empty($text)) {
$dialogues = json_decode(file_get_contents('core/module/install/ressource/i18n/fr_FR.json' ), true);
$data = array_merge($dialogues,[$text => '']);
file_put_contents ('core/module/install/ressource/i18n/fr_FR.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX);
}
*/
if (array_key_exists($text, core::$dialog) === false && !empty($text)) {
$dialogues = json_decode(file_get_contents('core/module/install/ressource/i18n/fr_FR.json' ), true);
$data = array_merge($dialogues,[$text => '']);
file_put_contents ('core/module/install/ressource/i18n/fr_FR.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX);
}
*/
return (array_key_exists($text, core::$dialog) && !empty(core::$dialog[$text]) ? core::$dialog[$text] : $text);
}
@ -77,7 +83,7 @@ class helper
// Créer la variable
$data = array_merge($data, [$text => '']);
}
file_put_contents('site/i18n/' . $to . '.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT), LOCK_EX);
file_put_contents('site/i18n/' . $to . '.json', json_encode($data, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT));
}
}
@ -193,7 +199,7 @@ class helper
{
// Creation du ZIP
$baseName = str_replace('/', '', helper::baseUrl(false, false));
$baseName = empty($baseName) ? 'Campus' : $baseName;
$baseName = empty($baseName) ? 'ZwiiCMS' : $baseName;
$fileName = $baseName . '-backup-' . date('Y-m-d-H-i-s', time()) . '.zip';
$zip = new ZipArchive();
$zip->open($folder . $fileName, ZipArchive::CREATE | ZipArchive::OVERWRITE);
@ -367,11 +373,10 @@ class helper
$version = helper::getOnlineVersion($channel);
$update = false;
if (!empty($version)) {
$update = version_compare(common::ZWII_VERSION, $version) == -1;
$update = version_compare(common::ZWII_VERSION, $version) == -1;
}
return $update;
}
/**
@ -390,10 +395,10 @@ class helper
'text' => self::relativeLuminanceW3C($rgba) > .22 ? "#222" : "#DDD",
'rgb' => 'rgb(' . $rgba[0] . ',' . $rgba[1] . ',' . $rgba[2] . ')',
'invert' => 'rgba (' .
($rgba[0] < 128 ? 255 : 0) . ',' .
($rgba[1] < 128 ? 255 : 0) . ',' .
($rgba[1] < 128 ? 255 : 0) . ',' .
($rgba[0] < 128 ? 255 : 0) . ')'
($rgba[0] < 128 ? 255 : 0) . ',' .
($rgba[1] < 128 ? 255 : 0) . ',' .
($rgba[1] < 128 ? 255 : 0) . ',' .
($rgba[0] < 128 ? 255 : 0) . ')'
];
}
@ -474,6 +479,11 @@ class helper
case self::FILTER_URL:
$text = filter_var($text, FILTER_SANITIZE_URL);
break;
case self::FILTER_DATE:
$text = date('Y-m-d', $text);
break;
case self::FILTER_TIME:
$text = date('H:i', $text);
}
return $text;
}

View File

@ -28,7 +28,7 @@ class template
$attributes['value'] = helper::translate($attributes['value']);
$attributes['help'] = helper::translate($attributes['help']);
// Retourne le html
return sprintf(
return sprintf(
'<a %s class="button %s %s %s" %s>%s</a>',
helper::sprintAttributes($attributes, ['class', 'disabled', 'ico', 'value']),
$attributes['disabled'] ? 'disabled' : '',
@ -65,12 +65,12 @@ class template
// 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;
$limit = $attributes['limit'] ? count($letters) - 1 : 10;
// Tirage de l'opération
mt_srand();
// Captcha simple limité à l'addition
$operator = $attributes['limit'] ? mt_rand(1, 4) : 1;
$operator = $attributes['limit'] ? mt_rand(1, 4) : 1;
// Limite si multiplication ou division
if ($operator > 2) {
@ -94,15 +94,15 @@ class template
switch ($operator) {
case 1:
$operator = template::ico('plus', ['fontSize' => '2em;']);
$result = $firstNumber + $secondNumber;
$result = $firstNumber + $secondNumber;
break;
case 2:
$operator = template::ico('minus', ['fontSize' => '2em;']);
$result = $firstNumber - $secondNumber;
$result = $firstNumber - $secondNumber;
break;
case 3:
$operator = template::ico('cancel', ['fontSize' => '2em;']);
$result = $firstNumber * $secondNumber;
$result = $firstNumber * $secondNumber;
break;
case 4:
$operator = template::ico('divide', ['fontSize' => '2em;']);
@ -112,7 +112,7 @@ class template
}
mt_srand();
$secondNumber = mt_rand(1, $limit);
$firstNumber = $firstNumber * $secondNumber;
$firstNumber = $firstNumber * $secondNumber;
$result = $firstNumber / $secondNumber;
break;
}
@ -125,8 +125,8 @@ class template
$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');
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
@ -134,7 +134,7 @@ class template
// Label
$html .= self::label(
$attributes['id'],
'<img class="captcha' . ucFirst($attributes['type']) . '" src="' . helper::baseUrl(false) . 'site/tmp/' . $firstLetter . '.png" />&nbsp;<strong>' . $operator . '</strong>&nbsp;<img class="captcha' . ucFirst($attributes['type']) . '" src="' . helper::baseUrl(false) . 'site/tmp/' . $secondLetter . '.png" />' . template::ico('eq', ['fontSize' => '2em;']),
'<img class="captcha' . ucFirst($attributes['type']) . '" src="' . helper::baseUrl(false) . 'site/tmp/' . $firstLetter . '.png" />&nbsp;<strong>' . $operator . '</strong>&nbsp;<img class="captcha' . ucFirst($attributes['type']) . '" src="' . helper::baseUrl(false) . 'site/tmp/' . $secondLetter . '.png" />' . template::ico('eq', ['fontSize' => '2em;']),
[
'help' => $attributes['help']
]
@ -224,7 +224,7 @@ class template
* Crée un champ date
* @param string $nameId Nom et id du champ
* @param array $attributes Attributs ($key => $value)
* @param string type date time datetime-local month week
* @param string type date seule ; time heure seule ; datetime-local (jour et heure)
* @return string
*/
public static function date($nameId, array $attributes = [])
@ -244,17 +244,32 @@ class template
'placeholder' => '',
'readonly' => false,
'value' => '',
'type'=> 'date',
'type' => 'date',
], $attributes);
// Traduction de l'aide et de l'étiquette
$attributes['label'] = helper::translate($attributes['label']);
$attributes['help'] = helper::translate($attributes['help']);
//$attributes['placeholder'] = helper::translate($attributes['placeholder']);
// Filtre selon le type
switch ($attributes['type']) {
case 'datetime-local':
$filter = helper::FILTER_TIMESTAMP;
break;
case 'date':
$filter = helper::FILTER_DATE; // Pour générer une valeur uniquement sur la date
break;
case 'time':
$filter = helper::FILTER_TIME; // Pour générer une valeur uniquement sur l'heure
break;
default:
$filter = null; // pas de filtre pour month and year
break;
}
// Sauvegarde des données en cas d'erreur
if ($attributes['before'] and array_key_exists($attributes['id'], common::$inputBefore)) {
$attributes['value'] = common::$inputBefore[$attributes['id']];
} else {
$attributes['value'] = ($attributes['value'] ? helper::filter($attributes['value'], helper::FILTER_TIMESTAMP) : '');
$attributes['value'] = ($attributes['value'] ? helper::filter($attributes['value'], $filter) : '');
}
// Début du wrapper
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
@ -284,7 +299,7 @@ class template
$html .= '</div>';
// Retourne le html
return $html;
}
}
/**
@ -346,14 +361,14 @@ class template
$html .= sprintf(
'<a
href="' .
helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php' .
'?relative_url=1' .
'&lang=' . $attributes['language'] .
'&field_id=' . $attributes['id'] .
'&type=' . $attributes['type'] .
'&akey=' . md5_file(core::DATA_DIR . 'core.json') .
($attributes['extensions'] ? '&extensions=' . $attributes['extensions'] : '')
. '"
helper::baseUrl(false) . 'core/vendor/filemanager/dialog.php' .
'?relative_url=1' .
'&lang=' . $attributes['language'] .
'&field_id=' . $attributes['id'] .
'&type=' . $attributes['type'] .
'&akey=' . md5_file(core::DATA_DIR . 'core.json') .
($attributes['extensions'] ? '&extensions=' . $attributes['extensions'] : '')
. '"
class="inputFile %s %s"
%s
data-lity
@ -471,7 +486,7 @@ class template
// Traduction de l'aide
$attributes['help'] = helper::translate($attributes['help']);
// Contenu de l'icône
$alt = $attributes['help'] ? $attributes['help'] : $ico;
$alt = $attributes['help'] ? $attributes['help'] : $ico;
$item = $attributes['href'] ? '<a id="' . $attributes['id'] . '" data-tippy-content="' . $attributes['help'] . '" alt="' . $alt . '" href="' . $attributes['href'] . '" ' . $attributes['attr'] . ' >' : '';
$item .= '<span class="zwiico-' . $ico . ($attributes['margin'] ? ' zwiico-margin-' . $attributes['margin'] : '') . ($attributes['animate'] ? ' animate-spin' : '') . '" style="font-size:' . $attributes['fontSize'] . '"><!----></span>';
$item .= ($attributes['href']) ? '</a>' : '';
@ -486,7 +501,7 @@ class template
*/
public static function flag($langId, $size = 'auto')
{
$lang = 'home';
$lang = 'fr_FR';
switch ($langId) {
case '':
break;
@ -496,6 +511,8 @@ class template
case 'selected':
if (isset($_SESSION['ZWII_SITE_CONTENT'])) {
$lang = $_SESSION['ZWII_SITE_CONTENT'];
} else {
$lang = 'fr_FR';
}
}
return '<img class="flag" src="' . helper::baseUrl(false) . 'core/vendor/i18n/png/' . $lang . '.png"
@ -684,12 +701,12 @@ class template
'label' => '',
'name' => $nameId,
'selected' => '',
'font' => [],
'font' => [],
'multiple' => ''
], $attributes);
// Traduction de l'aide et de l'étiquette
$attributes['label'] = helper::translate($attributes['label']);
$attributes['help'] = helper::translate($attributes['help']);
$attributes['help'] = helper::translate($attributes['help']);
// Stocker les fontes et remettre à zéro le tableau des fontes transmis pour éviter une erreur de sprintAttributes
if (empty($attributes['font']) === false) {
$fonts = $attributes['font'];
@ -726,7 +743,7 @@ class template
);
foreach ($options as $value => $text) {
// Select des liste de fontes
$html .= isset($fonts) ? sprintf(
$html .= isset($fonts) ? sprintf(
'<option value="%s"%s style="font-family: %s;">%s</option>',
$value,
$attributes['selected'] == $value ? ' selected' : '', // Double == pour ignorer le type de variable car $_POST change les types en string
@ -748,6 +765,7 @@ class template
return $html;
}
/**
* Crée une bulle de dialogue
* @param string $text Texte de la bulle
@ -779,7 +797,7 @@ class template
// Traduction de l'aide et de l'étiquette
$attributes['value'] = helper::translate($attributes['value']);
// Retourne le html
return sprintf(
return sprintf(
'<button type="submit" class="%s%s" %s>%s</button>',
$attributes['class'],
$attributes['uniqueSubmission'] ? 'uniqueSubmission' : '',
@ -807,7 +825,7 @@ class template
], $attributes);
// Traduction de l'aide et de l'étiquette
foreach ($head as $value) {
$head[array_search($value, $head)] = helper::translate($value);
$head[array_search($value, $head)] = helper::translate($value);
}
// Début du wrapper
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="tableWrapper ' . $attributes['classWrapper'] . '">';
@ -902,7 +920,7 @@ class template
$html .= self::notice($attributes['id'], $notice);
// Texte
$html .= sprintf(
'<input type="' . $attributes['type']. '" %s>',
'<input type="' . $attributes['type'] . '" %s>',
helper::sprintAttributes($attributes)
);
// Fin du wrapper

View File

@ -51,7 +51,7 @@ class common
const ACCESS_TIMER = 1800;
// Numéro de version
const ZWII_VERSION = '1.10.07';
const ZWII_VERSION = '1.10.08';
// URL autoupdate
const ZWII_UPDATE_URL = 'https://forge.chapril.org/ZwiiCMS-Team/campus-update/raw/branch/master/';