|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of Blitz PHP framework. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) 2022 Dimitri Sitchet Tomkeu <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view |
|
9
|
|
|
* the LICENSE file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* ------- FUNCTION SCL_UPLOAD() -------- |
|
14
|
|
|
* |
|
15
|
|
|
* @brief Cette fonction permet de récupérer un fichier envoyer par formulaire |
|
16
|
|
|
* |
|
17
|
|
|
* @param array $input la super globale $_FILE['nom'] qui permet de récupérer toutes les informations concernant le fichier. |
|
18
|
|
|
* @param string $path le dossier du serveur où l'on souhaite ranger le fichier |
|
19
|
|
|
* @param int [$size] la taille maximale en Ko du fichier pouvant être téléchargé |
|
20
|
|
|
* @param string [$type] représente le type de fichier pouvant être téléchargé |
|
21
|
|
|
* Cette fonction prend en charge 6 types de fichier (image, video, audio, doc, zip, et web) |
|
22
|
|
|
* mais le type par défaut est 'all' pour spécifier que les 6 types ci-dessus (24 extensions) sont pris en compte |
|
23
|
|
|
* @param string [$output] le nom avec lequel le fichier sera enregistré. |
|
24
|
|
|
* |
|
25
|
|
|
* @return mixed renvoie true si tous s'est bien passé et en cas d'erreur, renvoie un tableau contenant le code de l'erreur et le message par defaut |
|
26
|
|
|
*/ |
|
27
|
|
|
function scl_upLoad($input, $path = '', $size = 2500000, $type = '', $output = '') |
|
28
|
|
|
{ |
|
29
|
|
|
// taille par défaut |
|
30
|
|
|
$size = (empty($size) || ! is_numeric($size)) ? 2500000 : $size; |
|
31
|
|
|
// Le dossier par defaut est la racine |
|
32
|
|
|
$path = (! empty($path) && ! file_exists($path)) ? '' : htmlspecialchars($path); |
|
33
|
|
|
|
|
34
|
|
|
if (! is_array($input)) { |
|
35
|
|
|
return [0, 'Entrée non valide']; |
|
36
|
|
|
} |
|
37
|
|
|
if (empty($input['tmp_name']) || empty($input['name']) || empty($input['size'])) { |
|
38
|
|
|
return [1, 'Informations d\'entrées incomplètes']; |
|
39
|
|
|
} |
|
40
|
|
|
if ($input['size'] > $size) { |
|
41
|
|
|
return [2, 'Fichier trop volumineux']; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
// vérification du type et définition des extensions autorisées |
|
45
|
|
|
if ($type === 'image') { |
|
46
|
|
|
$extensions = ['jpg', 'jpeg', 'png', 'gif']; |
|
47
|
|
|
} elseif ($type === 'audio') { |
|
48
|
|
|
$extensions = ['mp3', 'wav', 'mpeg']; |
|
49
|
|
|
} elseif ($type === 'video') { |
|
50
|
|
|
$extensions = ['mp4', 'avi', 'ogv', 'webm', 'flv', 'mov']; |
|
51
|
|
|
} elseif ($type === 'doc') { |
|
52
|
|
|
$extensions = ['txt', 'doc', 'docx', 'pdf']; |
|
53
|
|
|
} elseif ($type === 'web') { |
|
54
|
|
|
$extensions = ['htm', 'html', 'css', 'xml', 'js', 'json']; |
|
55
|
|
|
} elseif ($type === 'db') { |
|
56
|
|
|
$extensions = ['sql', 'vcf']; |
|
57
|
|
|
} elseif ($type === 'zip') { |
|
58
|
|
|
$extensions = ['zip', 'rar']; |
|
59
|
|
|
} else { |
|
60
|
|
|
// Si on veut travailler avec une(plusieurs) extensions spécifique du même type |
|
61
|
|
|
if (preg_match('#^(image|audio|video|doc|web|db|zip){1}/(.*?)$#i', $type)) { |
|
62
|
|
|
$extensions = explode('/', $type)[1]; |
|
63
|
|
|
if (empty($extensions)) { |
|
64
|
|
|
// Si il n y'a rien après le slash |
|
65
|
|
|
switch (explode('/', $type)[0]) { |
|
66
|
|
|
case 'image': |
|
67
|
|
|
$extensions = ['jpg', 'jpeg', 'png', 'gif']; |
|
68
|
|
|
break; |
|
69
|
|
|
|
|
70
|
|
|
case 'audio': |
|
71
|
|
|
$extensions = ['mp3', 'wav', 'mpeg']; |
|
72
|
|
|
break; |
|
73
|
|
|
|
|
74
|
|
|
case 'video': |
|
75
|
|
|
$extensions = ['mp4', 'avi', 'ogv', 'webm', 'flv', 'mov']; |
|
76
|
|
|
break; |
|
77
|
|
|
|
|
78
|
|
|
case 'doc': |
|
79
|
|
|
$extensions = ['txt', 'doc', 'docx', 'pdf']; |
|
80
|
|
|
break; |
|
81
|
|
|
|
|
82
|
|
|
case 'web': |
|
83
|
|
|
$extensions = ['htm', 'html', 'css', 'xml', 'js', 'json']; |
|
84
|
|
|
break; |
|
85
|
|
|
|
|
86
|
|
|
case 'db': |
|
87
|
|
|
$extensions = ['sql', 'vcf']; |
|
88
|
|
|
break; |
|
89
|
|
|
|
|
90
|
|
|
case 'zip': |
|
91
|
|
|
$extensions = ['zip', 'rar']; |
|
92
|
|
|
break; |
|
93
|
|
|
} |
|
94
|
|
|
} elseif (count(explode(',', $extensions)) < 2) { |
|
95
|
|
|
$extensions = [explode(',', $extensions)[0]]; // Si il y'a une seule extension |
|
96
|
|
|
} else { |
|
97
|
|
|
$ext = explode(',', $extensions); |
|
98
|
|
|
$extensions = []; // Si il y'a plusieurs extensions |
|
99
|
|
|
|
|
100
|
|
|
foreach ($ext as $ex) { |
|
101
|
|
|
$extensions[] = $ex; |
|
102
|
|
|
} |
|
103
|
|
|
} |
|
104
|
|
|
} else { |
|
105
|
|
|
$extensions = [ |
|
106
|
|
|
'jpg', 'jpeg', 'png', 'gif', 'mp3', 'wav', 'mpeg', 'mp4', 'avi', 'ogv', 'webm', 'flv', 'mov', 'txt', 'doc', 'docx', |
|
107
|
|
|
'pdf', 'htm', 'html', 'css', 'xml', 'js', 'json', 'sql', 'vcf', 'zip', 'rar', |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
if (! in_array(strtolower(pathinfo($input['name'])['extension']), $extensions, true)) { |
|
113
|
|
|
return [3, 'Extension non prise en charge']; |
|
114
|
|
|
} |
|
115
|
|
|
|
|
116
|
|
|
/* |
|
117
|
|
|
vérification de la valeur du nom d'enregistrement ($output) |
|
118
|
|
|
-- $extension = '0.' signifie qu'on ne change pas l'extension du fichier tandis que |
|
119
|
|
|
$extension = '1.' signifie qu'on change. donc nous sommes dans le cas où le '.extension' a été spécifié |
|
120
|
|
|
-- NB: ne pas confondre $extensions et $extension. l'un représente les différents extension autorisés et |
|
121
|
|
|
l'autre vérifie si l'extension originale du fichier doit être modifié ou non |
|
122
|
|
|
*/ |
|
123
|
|
|
if (empty($output)) { // Si on ne defini pas le nom de sortie... |
|
124
|
|
|
// on enregistre le fichier avec la date et l'heure courante |
|
125
|
|
|
$output = 'scl_' . date('Ymd') . '-' . date('His'); |
|
126
|
|
|
$extension = '0.'; |
|
127
|
|
|
} else { // Si on defini le nom de sortie... |
|
128
|
|
|
if (! empty(explode('.', $output)[1]) && in_array(strtolower(explode('.', $output)[1]), $extensions, true)) { // Si l'extension est presente dans ce nom et est valide... |
|
129
|
|
|
$out = explode('.', $output); |
|
130
|
|
|
$output = $out[0]; // On enregistre le fichier avec le nom specifié |
|
131
|
|
|
$extension = '1.' . $out[1]; // On enregistre le fichier avec l'extension specifié (changement d'extension) |
|
132
|
|
|
} else { // Sinon...on enregistre le fichier avec le nom specifié mais en conservant son extension |
|
133
|
|
|
$output = str_replace('.', '', $output); |
|
134
|
|
|
$output = str_replace(',', '', $output); |
|
135
|
|
|
$output = str_replace(';', '', $output); |
|
136
|
|
|
$extension = '0.'; |
|
137
|
|
|
} |
|
138
|
|
|
} |
|
139
|
|
|
// si on a prévu modifier l'extension du fichier |
|
140
|
|
|
if (explode('.', $extension)[0] === 1) { |
|
141
|
|
|
$extension = explode('.', $extension)[1]; // l'extension est le celui specifié |
|
142
|
|
|
} else { |
|
143
|
|
|
$extension = strtolower(pathinfo($input['name'])['extension']); // 'extension est celui de départ |
|
144
|
|
|
} |
|
145
|
|
|
|
|
146
|
|
|
// si le fichier n'a pas été téléchargé |
|
147
|
|
|
if (! move_uploaded_file($input['tmp_name'], $path . $output . '.' . $extension)) { |
|
148
|
|
|
return [4, 'Erreur de téléversement']; |
|
149
|
|
|
} |
|
150
|
|
|
|
|
151
|
|
|
return true; |
|
152
|
|
|
} |
|
153
|
|
|
|
|
154
|
|
|
/** |
|
155
|
|
|
* ------- FUNCTION SCL_MINIMIZEIMG() -------- |
|
156
|
|
|
* |
|
157
|
|
|
* @brief Cette fonction permet diminuer les dimensions d'une image |
|
158
|
|
|
* |
|
159
|
|
|
* @param string $src la source de l'image a redimentionner. |
|
160
|
|
|
* @param array|int [$size] le tableau contenant les nouvelles dimensions ou la dimension unique(hauteur = largeur). |
|
161
|
|
|
* @param bool [$relative] specifie si on redimensionne la photo proportionnellement aux dimensions initiales |
|
162
|
|
|
* |
|
163
|
|
|
* @return mixed renvoie true si tous s'est bien passé et en cas d'erreur, renvoie un tableau contenant le code de l'erreur et le message par defaut |
|
164
|
|
|
*/ |
|
165
|
|
|
function scl_minimizeImg($src, $size = [], $relative = false) |
|
166
|
|
|
{ |
|
167
|
|
|
// Si le fichier n'existe pas |
|
168
|
|
|
if (! file_exists($src)) { |
|
169
|
|
|
return [0, 'Fichier inexistant']; |
|
170
|
|
|
} |
|
171
|
|
|
// Si on n'envoi pas un tableau ou un nombre comme tailles |
|
172
|
|
|
if (empty($size) || (! is_array($size) && ! is_int($size))) { |
|
173
|
|
|
return [1, 'Mauvaises dimensions de redimensionnement']; |
|
174
|
|
|
} |
|
175
|
|
|
|
|
176
|
|
|
// Si on envoie un tableau comme $size |
|
177
|
|
|
if (is_array($size)) { |
|
178
|
|
|
// Si le tableau n'a pas 1 ou deux element |
|
179
|
|
|
if (count($size) < 1 || count($size) > 2) { |
|
180
|
|
|
return [2, 'Violation du nombre de dimension']; |
|
181
|
|
|
} |
|
182
|
|
|
// Si l'un des element du tableau n'est pas un nombre |
|
183
|
|
|
if (! is_int($size[0]) || (! empty($size[1]) && ! is_int($size[1]))) { |
|
184
|
|
|
return [3, 'Type de dimension inconnu']; |
|
185
|
|
|
} |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
// Les nouvelles dimensions |
|
189
|
|
|
$dimensions = ['x' => 0, 'y' => 0]; |
|
190
|
|
|
|
|
191
|
|
|
if (is_int($size)) { |
|
192
|
|
|
$dimensions['x'] = $size; |
|
193
|
|
|
$dimensions['y'] = $size; |
|
194
|
|
|
} else { |
|
195
|
|
|
if (count($size) === 1) { |
|
196
|
|
|
$dimensions['x'] = $size[0]; |
|
197
|
|
|
$dimensions['y'] = $size[0]; |
|
198
|
|
|
} else { |
|
199
|
|
|
$dimensions['x'] = $size[0]; |
|
200
|
|
|
$dimensions['y'] = $size[1]; |
|
201
|
|
|
} |
|
202
|
|
|
} |
|
203
|
|
|
|
|
204
|
|
|
if (preg_match('#\.jpe?g$#i', $src)) { |
|
205
|
|
|
$source = imagecreatefromjpeg($src); |
|
206
|
|
|
} |
|
207
|
|
|
if (preg_match('#\.png$#i', $src)) { |
|
208
|
|
|
$source = imagecreatefrompng($src); |
|
209
|
|
|
} |
|
210
|
|
|
if (preg_match('#\.gif$#i', $src)) { |
|
211
|
|
|
$source = imagecreatefromgif($src); |
|
212
|
|
|
} |
|
213
|
|
|
|
|
214
|
|
|
// Les dimensions de l'image source |
|
215
|
|
|
$l_s = imagesx($source); // Largeur |
|
216
|
|
|
$h_s = imagesy($source); // Hauteur |
|
217
|
|
|
|
|
218
|
|
|
// Les dimensions de la destination |
|
219
|
|
|
if ($relative) { |
|
220
|
|
|
$l_d = ($dimensions['x'] / 100) * $l_s; |
|
221
|
|
|
$h_d = ($dimensions['y'] / 100) * $h_s; |
|
222
|
|
|
} else { |
|
223
|
|
|
$l_d = ($dimensions['x'] <= 10) ? $l_s : $dimensions['x']; // Largeur |
|
224
|
|
|
$h_d = ($dimensions['y'] <= 10) ? $h_s : $dimensions['y']; // Hauteur |
|
225
|
|
|
} |
|
226
|
|
|
|
|
227
|
|
|
// On crée la miniature vide |
|
228
|
|
|
$destination = imagecreatetruecolor($l_d, $h_d); |
|
229
|
|
|
|
|
230
|
|
|
// On crée la miniature |
|
231
|
|
|
imagecopyresampled($destination, $source, 0, 0, 0, 0, $l_d, $h_d, $l_s, $h_s); |
|
232
|
|
|
|
|
233
|
|
|
// On enregistre la miniature |
|
234
|
|
|
if (preg_match('#\.jpe?g$#i', $src)) { |
|
235
|
|
|
$result = imagejpeg($destination, $src); |
|
236
|
|
|
} |
|
237
|
|
|
if (preg_match('#\.png$#i', $src)) { |
|
238
|
|
|
$result = imagepng($destination, $src); |
|
239
|
|
|
} |
|
240
|
|
|
if (preg_match('#\.gif$#i', $src)) { |
|
241
|
|
|
$result = imagegif($destination, $src); |
|
242
|
|
|
} |
|
243
|
|
|
|
|
244
|
|
|
return ($result === true) ? true : [5, 'Erreur lors du redimensionnement']; |
|
245
|
|
|
} |
|
246
|
|
|
|
|
247
|
|
|
/** |
|
248
|
|
|
* ------- FUNCTION SCL_GENERATEKEYS() -------- |
|
249
|
|
|
* |
|
250
|
|
|
* @brief Cette fonction permet de une chaine aléatoirement |
|
251
|
|
|
* |
|
252
|
|
|
* @param int [$nbr] le nombre de caractères de la clé. |
|
253
|
|
|
* @param int [$type] le type de clé à generer. |
|
254
|
|
|
* |
|
255
|
|
|
* @return string |
|
256
|
|
|
*/ |
|
257
|
|
|
function scl_generateKeys($nbr = 8, $type = 0) |
|
258
|
|
|
{ |
|
259
|
|
|
// Valeurs par défaut |
|
260
|
|
|
$nbr = (empty($nbr)) ? 8 : (int) $nbr; |
|
261
|
|
|
$nbr = (! is_int($nbr)) ? 8 : (int) $nbr; |
|
262
|
|
|
$nbr = ($nbr < 3 || $nbr > 64) ? 8 : (int) $nbr; |
|
263
|
|
|
|
|
264
|
|
|
switch ($type) { |
|
265
|
|
|
case 1: |
|
266
|
|
|
$chars = range('a', 'z'); |
|
267
|
|
|
break; // Caractères alphabetique minuscules |
|
268
|
|
|
|
|
269
|
|
|
case 2: |
|
270
|
|
|
$chars = range('A', 'Z'); |
|
271
|
|
|
break; // Caractères alphabetique majuscules |
|
272
|
|
|
|
|
273
|
|
|
case 3: |
|
274
|
|
|
$chars = range(0, 9); |
|
275
|
|
|
break; // Caractères numerique |
|
276
|
|
|
|
|
277
|
|
|
case 4: |
|
278
|
|
|
$chars = array_merge(range('a', 'z'), range('A', 'Z')); |
|
279
|
|
|
break; // Caractères alphabetique |
|
280
|
|
|
|
|
281
|
|
|
case 5: |
|
282
|
|
|
$chars = array_merge(range(0, 9), range('a', 'z')); |
|
283
|
|
|
break; // Caractères numerique et alphabetique minuscules |
|
284
|
|
|
|
|
285
|
|
|
case 6: |
|
286
|
|
|
$chars = array_merge(range(0, 9), range('A', 'Z')); |
|
287
|
|
|
break; // Caractères numerique et alphabetique majuscules |
|
288
|
|
|
|
|
289
|
|
|
default: |
|
290
|
|
|
$chars = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z')); |
|
291
|
|
|
break; // Tous les caractères |
|
292
|
|
|
} |
|
293
|
|
|
$return = ''; // Valeur de retour |
|
294
|
|
|
$nb_char = count($chars); // On compte le nombre de caractères disponible |
|
295
|
|
|
|
|
296
|
|
|
for ($i = 0; $i < $nbr; $i++) { |
|
297
|
|
|
// On tire un nombre au hasard parmi toutes les indexes de caracteres et on affiche le caracteres corespondant |
|
298
|
|
|
$return .= $chars[mt_rand(0, ($nb_char - 1))]; |
|
299
|
|
|
} |
|
300
|
|
|
|
|
301
|
|
|
return $return; |
|
302
|
|
|
} |
|
303
|
|
|
|
|
304
|
|
|
/** |
|
305
|
|
|
* ------- FUNCTION SCL_DATE() -------- |
|
306
|
|
|
* |
|
307
|
|
|
* @brief Cette fonction permet de formater une date |
|
308
|
|
|
* |
|
309
|
|
|
* @param string $date la date à formater |
|
310
|
|
|
* @param string [$format] le format de sortie |
|
311
|
|
|
* @param bool [$interval] specifie si l'interval va etre donné (true) ou pas (false) |
|
312
|
|
|
* @param string [$fuseau] le fuseau horaire |
|
313
|
|
|
* |
|
314
|
|
|
* @return string |
|
315
|
|
|
*/ |
|
316
|
|
|
function scl_date($date, $format = 'D, d M Y', $interval = true, $fuseau = 'Europe/Paris') |
|
317
|
|
|
{ |
|
318
|
|
|
// Valeurs par défaut |
|
319
|
|
|
$format = (empty($format) || ! is_string($format)) ? 'D, d M Y' : htmlspecialchars(trim($format)); // Le format de sortie, par défaut = D, d M Y |
|
320
|
|
|
$fuseau = (empty($fuseau) || ! is_string($fuseau)) ? 'Europe/Paris' : htmlspecialchars(trim($fuseau)); // fuseau horaire |
|
321
|
|
|
$interval = (! is_bool($interval)) ? true : $interval; // Specifie si on gere les intervales ou pas |
|
322
|
|
|
$interval = ($interval === false) ? false : true; // Specifie si on gere les intervales ou pas |
|
323
|
|
|
|
|
324
|
|
|
$date = new DateTime($date); // On contruit la date |
|
325
|
|
|
|
|
326
|
|
|
// Si on ne gere pas les intervales |
|
327
|
|
|
if ($interval === false) { |
|
328
|
|
|
// On renvoie la date formatée et dans le fuseau correspondant |
|
329
|
|
|
return $date/* ->setTimezone(new DateTimeZone($fuseau)) */ ->format($format); |
|
330
|
|
|
} |
|
331
|
|
|
|
|
332
|
|
|
// Si on gere les intervales |
|
333
|
|
|
$maintenant = new DateTime(date('Y-m-d H:i:s')); // recupere la date actuelle |
|
334
|
|
|
|
|
335
|
|
|
// On place les date dans le fuseau horaire souhaité |
|
336
|
|
|
$maintenant->setTimezone(new DateTimeZone($fuseau)); |
|
337
|
|
|
$date->setTimezone(new DateTimeZone($fuseau)); |
|
338
|
|
|
|
|
339
|
|
|
$dif = $maintenant->diff($date)->format('%d'); |
|
340
|
|
|
if ($dif < 0 || $dif > 3) { |
|
341
|
|
|
// Si sa fait plus de 3 jours ou la date n'est pas encore arriver |
|
342
|
|
|
$return = $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
343
|
|
|
} elseif ($dif > 1) { |
|
344
|
|
|
$return = $maintenant->diff($date)->format('There is %d days'); |
|
345
|
|
|
} elseif ($dif === 1) { |
|
346
|
|
|
$return = 'Yesterday at ' . $date->format('H') . 'h'; |
|
347
|
|
|
} else { |
|
348
|
|
|
// Si c'est aujourd'hui |
|
349
|
|
|
$dif = $maintenant->diff($date)->format('%h'); |
|
350
|
|
|
if ($dif < 0) { |
|
351
|
|
|
// Si l'heure est par hasard negatif, on renvoie la data normalement |
|
352
|
|
|
$return = $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
353
|
|
|
} elseif ($dif > 1) { |
|
354
|
|
|
$return = $maintenant->diff($date)->format('There is %h hours'); |
|
355
|
|
|
} else { |
|
356
|
|
|
$dif = $maintenant->diff($date)->format('%i'); |
|
357
|
|
|
if ($dif < 0) { |
|
358
|
|
|
$return = $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
359
|
|
|
} elseif ($dif > 1) { |
|
360
|
|
|
$return = $maintenant->diff($date)->format('There is a %i minutes'); |
|
361
|
|
|
} else { |
|
362
|
|
|
$dif = $maintenant->diff($date)->format('%s'); |
|
363
|
|
|
if ($dif < 0) { |
|
364
|
|
|
$return = $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
365
|
|
|
} elseif ($dif >= 10) { |
|
366
|
|
|
$return = $maintenant->diff($date)->format('There is %s seconds'); |
|
367
|
|
|
} else { |
|
368
|
|
|
$return = 'Now'; |
|
369
|
|
|
} |
|
370
|
|
|
} |
|
371
|
|
|
} |
|
372
|
|
|
} |
|
373
|
|
|
if ($maintenant->diff($date)->format('%y') >= 1 || $maintenant->diff($date)->format('%m') >= 1) { |
|
374
|
|
|
return $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
375
|
|
|
} |
|
376
|
|
|
if ($maintenant->format('d') < $date->format('d') && $maintenant->format('y-m') <= $date->format('y-m')) { |
|
377
|
|
|
return $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
378
|
|
|
} |
|
379
|
|
|
if ($maintenant < $date) { |
|
380
|
|
|
$dif = $date->diff($maintenant)->format('%y'); |
|
381
|
|
|
if ($dif > 1) { |
|
382
|
|
|
return $date->diff($maintenant)->format('In %y years'); |
|
383
|
|
|
} |
|
384
|
|
|
$dif = $date->diff($maintenant)->format('%m'); |
|
385
|
|
|
if ($dif > 1) { |
|
386
|
|
|
return $date->diff($maintenant)->format('In %m months'); |
|
387
|
|
|
} |
|
388
|
|
|
$dif = $date->diff($maintenant)->format('%d'); |
|
389
|
|
|
if ($dif > 1) { |
|
390
|
|
|
return $date->diff($maintenant)->format('In %d days'); |
|
391
|
|
|
} |
|
392
|
|
|
$dif = $date->diff($maintenant)->format('%h'); |
|
393
|
|
|
if ($dif < 0) { |
|
394
|
|
|
return $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
395
|
|
|
} |
|
396
|
|
|
if ($dif >= 1) { |
|
397
|
|
|
return $date->diff($maintenant)->format('In %h hours'); |
|
398
|
|
|
} |
|
399
|
|
|
$dif = $date->diff($maintenant)->format('%i'); |
|
400
|
|
|
if ($dif < 0) { |
|
401
|
|
|
return $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
402
|
|
|
} |
|
403
|
|
|
if ($dif >= 1) { |
|
404
|
|
|
return $date->diff($maintenant)->format('In %i minutes'); |
|
405
|
|
|
} |
|
406
|
|
|
|
|
407
|
|
|
return $date->setTimezone(new DateTimeZone($fuseau))->format($format); |
|
408
|
|
|
} |
|
409
|
|
|
|
|
410
|
|
|
return $return; |
|
411
|
|
|
} |
|
412
|
|
|
|
|
413
|
|
|
/** |
|
414
|
|
|
* ------- FUNCTION SCL_TRANSLATE_DATE() -------- |
|
415
|
|
|
* |
|
416
|
|
|
* @brief Cette fonction permet de traduire une date en une autre langue formater une date |
|
417
|
|
|
* |
|
418
|
|
|
* @param string $date la date à traduire |
|
419
|
|
|
* @param string [$lang] la langue de sortie |
|
420
|
|
|
* |
|
421
|
|
|
* @return string |
|
422
|
|
|
*/ |
|
423
|
|
|
function scl_translate_date($date, $lang = 'en') |
|
424
|
|
|
{ |
|
425
|
|
|
$lang = strtolower($lang); |
|
426
|
|
|
|
|
427
|
|
|
if ($lang === 'fr') { |
|
428
|
|
|
$date = preg_replace('#^Now?#iSu', 'Maintenant', $date); |
|
429
|
|
|
$date = preg_replace('#^There is(\s?a)?#iSu', 'Il y a', $date); |
|
430
|
|
|
$date = preg_replace('#^Yesterday at#iSu', 'Hier à', $date); |
|
431
|
|
|
$date = preg_replace('#^In#iSu', 'Dans', $date); |
|
432
|
|
|
|
|
433
|
|
|
$date = preg_replace('#years#iSu', 'ans', $date); |
|
434
|
|
|
$date = preg_replace('#months#iSu', 'mois', $date); |
|
435
|
|
|
$date = preg_replace('#days#iSu', 'jours', $date); |
|
436
|
|
|
$date = preg_replace('#hours#iSu', 'heures', $date); |
|
437
|
|
|
$date = preg_replace('#seconds#iSu', 'secondes', $date); |
|
438
|
|
|
|
|
439
|
|
|
$date = preg_replace('#Monday#iSu', 'Lundi', $date); |
|
440
|
|
|
$date = preg_replace('#Mon#iSu', 'Lun', $date); |
|
441
|
|
|
$date = preg_replace('#Tuesday#iSu', 'Mardi', $date); |
|
442
|
|
|
$date = preg_replace('#Tue#iSu', 'Mar', $date); |
|
443
|
|
|
$date = preg_replace('#Wednesday#iSu', 'Mercredi', $date); |
|
444
|
|
|
$date = preg_replace('#Wed#iSu', 'Mer', $date); |
|
445
|
|
|
$date = preg_replace('#Thursday#iSu', 'Jeudi', $date); |
|
446
|
|
|
$date = preg_replace('#Thu#iSu', 'Jeu', $date); |
|
447
|
|
|
$date = preg_replace('#Friday#iSu', 'Vendredi', $date); |
|
448
|
|
|
$date = preg_replace('#Fri#iSu', 'Ven', $date); |
|
449
|
|
|
$date = preg_replace('#Saturday#iSu', 'Samedi', $date); |
|
450
|
|
|
$date = preg_replace('#Sat#iSu', 'Sam', $date); |
|
451
|
|
|
$date = preg_replace('#Sunday#iSu', 'Dimanche', $date); |
|
452
|
|
|
$date = preg_replace('#Sun#iSu', 'Dim', $date); |
|
453
|
|
|
|
|
454
|
|
|
$date = preg_replace('#January#iSu', 'Janvier', $date); |
|
455
|
|
|
$date = preg_replace('#Jan#iSu', 'Jan', $date); |
|
456
|
|
|
$date = preg_replace('#February#iSu', 'Févier', $date); |
|
457
|
|
|
$date = preg_replace('#Feb#iSu', 'Fev', $date); |
|
458
|
|
|
$date = preg_replace('#March#iSu', 'Mars', $date); |
|
459
|
|
|
$date = preg_replace('#Mar#iSu', 'Mar', $date); |
|
460
|
|
|
$date = preg_replace('#April#iSu', 'Avril', $date); |
|
461
|
|
|
$date = preg_replace('#Apr#iSu', 'Avr', $date); |
|
462
|
|
|
$date = preg_replace('#May#iSu', 'Mai', $date); |
|
463
|
|
|
$date = preg_replace('#June#iSu', 'Juin', $date); |
|
464
|
|
|
$date = preg_replace('#Jun#iSu', 'Juin', $date); |
|
465
|
|
|
$date = preg_replace('#July#iSu', 'Juillet', $date); |
|
466
|
|
|
$date = preg_replace('#July?#iSu', 'Jui', $date); |
|
467
|
|
|
$date = preg_replace('#August#iSu', 'Août', $date); |
|
468
|
|
|
$date = preg_replace('#Aug#iSu', 'Août', $date); |
|
469
|
|
|
$date = preg_replace('#September#iSu', 'Septembre', $date); |
|
470
|
|
|
$date = preg_replace('#Sept?#iSu', 'Sept', $date); |
|
471
|
|
|
$date = preg_replace('#October#iSu', 'Octobre', $date); |
|
472
|
|
|
$date = preg_replace('#Oct#iSu', 'Oct', $date); |
|
473
|
|
|
$date = preg_replace('#November#iSu', 'Novembre', $date); |
|
474
|
|
|
$date = preg_replace('#Nov#iSu', 'Nov', $date); |
|
475
|
|
|
$date = preg_replace('#December#iSu', 'Décembre', $date); |
|
476
|
|
|
$date = preg_replace('#Dec#iSu', 'Déc', $date); |
|
477
|
|
|
} |
|
478
|
|
|
|
|
479
|
|
|
return $date; |
|
480
|
|
|
} |
|
481
|
|
|
|
|
482
|
|
|
/** |
|
483
|
|
|
* ------- FUNCTION SCL_HASH() -------- |
|
484
|
|
|
* |
|
485
|
|
|
* @brief Cette fonction permet d'hasher une chaine |
|
486
|
|
|
* |
|
487
|
|
|
* @param string $str la chaine caractères qu'on veut hasher |
|
488
|
|
|
* @param int [$lenght] la longueur de la chaine a sortir |
|
489
|
|
|
* @param mixed $key |
|
490
|
|
|
* |
|
491
|
|
|
* @return string |
|
492
|
|
|
*/ |
|
493
|
|
|
function scl_hash($str, $lenght = 128, $key = '') |
|
494
|
|
|
{ |
|
495
|
|
|
// Valeur par defaut |
|
496
|
|
|
$lenght = (empty($lenght) || ! is_int($lenght)) ? 128 : $lenght; |
|
497
|
|
|
// Valeurs minimale et maximale pour le haché |
|
498
|
|
|
$lenght = ($lenght < 50) ? 50 : $lenght; |
|
499
|
|
|
$lenght = ($lenght > 200) ? 200 : $lenght; |
|
500
|
|
|
|
|
501
|
|
|
$str = trim(htmlspecialchars($str)); // On echappe la chaine et on supprime les espaces de debut et de fin |
|
502
|
|
|
|
|
503
|
|
|
$code = strlen($str); // On recupere la logueur de la chaine |
|
504
|
|
|
$code = ($code * 200) * ($code / 50); // afin de creer un code |
|
505
|
|
|
|
|
506
|
|
|
// Le sel |
|
507
|
|
|
$sel1 = strlen($str); |
|
508
|
|
|
$sel2 = strlen($code); |
|
509
|
|
|
$sel = strlen($str . $code); |
|
510
|
|
|
|
|
511
|
|
|
// Le hashage commence ici |
|
512
|
|
|
$texte_hash_1 = hash('sha256', 'scl_' . $sel1 . $str . $sel2); // Premier hash avec le sha256 |
|
513
|
|
|
$texte_hash_2 = hash('sha512', $texte_hash_1 . $sel . '_hash'); // Deuxieme hash avec le sha512 |
|
514
|
|
|
|
|
515
|
|
|
// On divise les deux hash en 2 parties egales |
|
516
|
|
|
$texte_hash_1_1 = substr($texte_hash_1, 0, 32); |
|
517
|
|
|
$texte_hash_1_2 = substr($texte_hash_1, -32); // Les parties du premier hashé |
|
518
|
|
|
$texte_hash_2_1 = substr($texte_hash_2, 0, 64); |
|
519
|
|
|
$texte_hash_2_2 = substr($texte_hash_2, -64); // Les parties du deuxieme hashé |
|
520
|
|
|
|
|
521
|
|
|
$final = $texte_hash_1_1 . 'ec' . $texte_hash_2_1 . 'af' . $texte_hash_1_2 . '84' . $texte_hash_2_2 . '5f'; // On additionne les deux hashés en ajoutant un sel statique pour atteindre les 200 caract |
|
522
|
|
|
|
|
523
|
|
|
// On renvoi le hash avec la longueur souhaité |
|
524
|
|
|
return substr($final, 0, $lenght); |
|
525
|
|
|
} |
|
526
|
|
|
|
|
527
|
|
|
/** |
|
528
|
|
|
* ------- FUNCTION SCL_CYPHER() -------- |
|
529
|
|
|
* |
|
530
|
|
|
* @brief Cette fonction permet d'encrypter et de decrypter une chaine de caracteres |
|
531
|
|
|
* |
|
532
|
|
|
* @param string $str la chaine caractères qu'on veut encrypter ou decrypter |
|
533
|
|
|
* @param string [$action] l'action qu'on veut effectuer (encrypter/decrypter). |
|
534
|
|
|
* @param int [$repeat] le nombre de fois qu'on repete l'action |
|
535
|
|
|
* |
|
536
|
|
|
* @return string |
|
537
|
|
|
*/ |
|
538
|
|
|
function scl_cypher($str, $action = 'encrypt', $repeat = 0) |
|
539
|
|
|
{ |
|
540
|
|
|
// Valeur par defaut |
|
541
|
|
|
$action = strtolower($action); |
|
542
|
|
|
$action = ($action !== 'decrypt') ? 'encrypt' : 'decrypt'; |
|
543
|
|
|
$repeat = (! is_int($repeat) || $repeat < 1) ? 0 : $repeat; |
|
544
|
|
|
|
|
545
|
|
|
$chars = ''; // Les differents caractères entrés |
|
546
|
|
|
$size = strlen($str); |
|
547
|
|
|
|
|
548
|
|
|
for ($i = $size; $i > 1; $i--) { |
|
549
|
|
|
// On separes chaque caracteres du mot independament |
|
550
|
|
|
$chars .= substr($str, 0, 1) . ' '; |
|
551
|
|
|
$str = substr($str, 1); |
|
552
|
|
|
} |
|
553
|
|
|
if ($str !== '') { |
|
554
|
|
|
$chars .= $str; |
|
555
|
|
|
} else { |
|
556
|
|
|
$chars = substr($chars, 0, strlen($chars) - 1); |
|
557
|
|
|
} |
|
558
|
|
|
|
|
559
|
|
|
// Les entrées / sorties |
|
560
|
|
|
$inputs = [ |
|
561
|
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
|
562
|
|
|
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', |
|
563
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
|
564
|
|
|
]; |
|
565
|
|
|
$outputs = [ |
|
566
|
|
|
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', |
|
567
|
|
|
'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', |
|
568
|
|
|
'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', |
|
569
|
|
|
]; |
|
570
|
|
|
$chars = explode(' ', $chars); // On transforme la chaine précédement créée en tableau |
|
571
|
|
|
$return = ''; |
|
572
|
|
|
|
|
573
|
|
|
// On parcours tout le dit tableau (ie. on recupere les caracteres un a un) |
|
574
|
|
|
foreach ($chars as $val) { |
|
575
|
|
|
// Si le caractère est encryptable ou decryptable |
|
576
|
|
|
if (in_array($val, $inputs, true) && in_array($val, $outputs, true)) { |
|
577
|
|
|
// Si on veut encrypter |
|
578
|
|
|
if ($action === 'encrypt') { |
|
579
|
|
|
$num = array_search($val, $inputs, true); // On recupere l'index de la lettre |
|
580
|
|
|
$return .= $outputs[$num]; // et on ajoute le caractère d'encryptage correspondant |
|
581
|
|
|
} // sinon, on veut decrypter |
|
582
|
|
|
else { |
|
583
|
|
|
$num = array_search($val, $outputs, true); // On recupere l'index de la lettre |
|
584
|
|
|
$return .= $inputs[$num]; // et on ajoute le caractère de décryptage correspondant |
|
585
|
|
|
} |
|
586
|
|
|
} // Sinon |
|
587
|
|
|
else { |
|
588
|
|
|
$return .= $val; // On le laisse comme il est |
|
589
|
|
|
} |
|
590
|
|
|
} |
|
591
|
|
|
|
|
592
|
|
|
for ($i = 0; $i < $repeat; $i++) { |
|
593
|
|
|
$return = scl_cypher($return, $action); |
|
594
|
|
|
} |
|
595
|
|
|
|
|
596
|
|
|
return $return; // On renvoie la chaine encrypter ou decrypter |
|
597
|
|
|
} |
|
598
|
|
|
|
|
599
|
|
|
/** |
|
600
|
|
|
* ------- FUNCTION SCL_CRYPT() -------- |
|
601
|
|
|
* |
|
602
|
|
|
* @param string $str la chaine caractères qu'on veut e |
|
603
|
|
|
* |
|
604
|
|
|
* @brief Cette fonction permet d'encrypter et de decrypter une chaine de caracteres |
|
605
|
|
|
* |
|
606
|
|
|
* @param string $key la clé de chiffrement |
|
607
|
|
|
* @param string [$action] l'action qu'on veut effectuer (encrypter/decrypter). |
|
608
|
|
|
* |
|
609
|
|
|
* @return string |
|
610
|
|
|
*ncrypter ou decrypter |
|
611
|
|
|
*/ |
|
612
|
|
|
function scl_crypt($str, $key, $action = 'encrypt') |
|
613
|
|
|
{ |
|
614
|
|
|
// Valeur par defaut |
|
615
|
|
|
$action = strtolower($action); |
|
616
|
|
|
$action = ($action !== 'decrypt') ? 'encrypt' : 'decrypt'; |
|
617
|
|
|
|
|
618
|
|
|
$return = ''; // La valeur retournée |
|
619
|
|
|
|
|
620
|
|
|
// On protège la clé pour eviter les failles |
|
621
|
|
|
$code = strlen($key); |
|
622
|
|
|
$code = ($code * 4) * ($code / 3); |
|
623
|
|
|
$key = sha1(strlen($key) . $key . strlen($key . $code)); |
|
624
|
|
|
$key .= md5($code . $key . $code); |
|
625
|
|
|
|
|
626
|
|
|
$letter = -1; |
|
627
|
|
|
$str = ($action === 'encrypt') ? $str : base64_decode($str, true); |
|
628
|
|
|
$strlen = strlen($str); // Nombre de caractère de la chaine à traiter |
|
629
|
|
|
|
|
630
|
|
|
for ($i = 0; $i < $strlen; $i++) { |
|
631
|
|
|
$letter++; |
|
632
|
|
|
if ($letter > 31) { |
|
633
|
|
|
$letter = 0; |
|
634
|
|
|
} |
|
635
|
|
|
if ($action === 'encrypt') { |
|
636
|
|
|
$neword = ord($str[$i]) + ord($key[$letter]); |
|
637
|
|
|
if ($neword > 255) { |
|
638
|
|
|
$neword -= 256; |
|
639
|
|
|
} |
|
640
|
|
|
} else { |
|
641
|
|
|
$neword = ord($str[$i]) - ord($key[$letter]); |
|
642
|
|
|
if ($neword < 1) { |
|
643
|
|
|
$neword += 256; |
|
644
|
|
|
} |
|
645
|
|
|
} |
|
646
|
|
|
$return .= chr($neword); |
|
647
|
|
|
} |
|
648
|
|
|
|
|
649
|
|
|
return ($action === 'encrypt') ? base64_encode($return) : $return; |
|
650
|
|
|
// On renvoie la chaine encrypter ou decrypter |
|
651
|
|
|
} |
|
652
|
|
|
|
|
653
|
|
|
/** |
|
654
|
|
|
* ------- FUNCTION SCL_TRUNCATE() -------- |
|
655
|
|
|
* |
|
656
|
|
|
* @brief Cette fonction permet de couper une chaine de caractere |
|
657
|
|
|
* |
|
658
|
|
|
* @param string $str la chaine caractères qu'on veut couper |
|
659
|
|
|
* @param int $size est la longueur finale de la chaine apres la coupure |
|
660
|
|
|
* @param bool [$suspension] specifie si on ajoute les points de suspension à la fin (true) ou pas (false). |
|
661
|
|
|
* |
|
662
|
|
|
* @return string |
|
663
|
|
|
*/ |
|
664
|
|
|
function scl_truncate($str, $size, $suspension = false) |
|
665
|
|
|
{ |
|
666
|
|
|
// Valeur par defaut |
|
667
|
|
|
$str = htmlspecialchars($str); // On protege la chaine |
|
668
|
|
|
$size = (! is_numeric($size)) ? strlen($str) : $size; // Taille à couper |
|
669
|
|
|
|
|
670
|
|
|
$lenght = strlen($str); // longueur de la chaine |
|
671
|
|
|
if ($lenght > $size) { |
|
672
|
|
|
// Si la longueur initiale de la chaine est superieur à la taille qu'on veut |
|
673
|
|
|
$str = substr($str, 0, $size); // On coupe la chaine |
|
674
|
|
|
if ($suspension === true) { |
|
675
|
|
|
$str .= '...'; // On ajoute les suspension |
|
676
|
|
|
} |
|
677
|
|
|
} |
|
678
|
|
|
|
|
679
|
|
|
return $str; // On renvoie la chaine couper |
|
680
|
|
|
} |
|
681
|
|
|
|
|
682
|
|
|
/** |
|
683
|
|
|
* ------- FUNCTION SCL_SHORTENSTR() -------- |
|
684
|
|
|
* |
|
685
|
|
|
* @brief Cette fonction permet de couper une chaine de caractere |
|
686
|
|
|
* |
|
687
|
|
|
* @param string $str la chaine caractères qu'on veut couper |
|
688
|
|
|
* @param int $max est la longueur finale de la chaine apres la coupure |
|
689
|
|
|
* @param string [$sep] Le separateur entre le debut et la fin de la chaine |
|
690
|
|
|
* @param int [$width] Le nombre de fois qu'on doit repeter le separateur |
|
691
|
|
|
* |
|
692
|
|
|
* @return string |
|
693
|
|
|
* |
|
694
|
|
|
* @example |
|
695
|
|
|
* echo scl_shortenStr("J'aime le PHP et j'ose croire que cette fonction vous sera utile", 34); // J'aime le PHP et...vous sera utile |
|
696
|
|
|
*/ |
|
697
|
|
|
function scl_shortenStr($str, $max, $sep = '.', $width = 3) |
|
698
|
|
|
{ |
|
699
|
|
|
// Valeur par defaut |
|
700
|
|
|
$str = htmlspecialchars($str); // On protege la chaine |
|
701
|
|
|
$max = (! is_numeric($max)) ? strlen($str) : $max; // Taille à couper |
|
702
|
|
|
|
|
703
|
|
|
$length = strlen($str); // Nombre de caractères |
|
704
|
|
|
|
|
705
|
|
|
if ($length > $max) { |
|
706
|
|
|
$too_much_length = $length - $max + $width; // Nombre de caractères en trop |
|
707
|
|
|
if ($max < $width) { |
|
708
|
|
|
// Dans le cas où la largeur max est inférieur à la largeur du séparateur |
|
709
|
|
|
$width = $max; |
|
710
|
|
|
} |
|
711
|
|
|
$start = ceil($length / 2 - $too_much_length / 2); |
|
712
|
|
|
$str = substr($str, 0, $start) . str_repeat($sep, $width) . substr($str, floor($start + $too_much_length)); |
|
713
|
|
|
} |
|
714
|
|
|
|
|
715
|
|
|
return $str; |
|
716
|
|
|
} |
|
717
|
|
|
|
|
718
|
|
|
/** |
|
719
|
|
|
* ------- FUNCTION SCL_CLEANER() -------- |
|
720
|
|
|
* |
|
721
|
|
|
* @brief Cette fonction permet de suprimer les espace en debut et fin d'une chaine tout en echappant les entités html |
|
722
|
|
|
* |
|
723
|
|
|
* @param string $str la chaine caractères qu'on veut netoyer |
|
724
|
|
|
* |
|
725
|
|
|
* @return string |
|
726
|
|
|
*/ |
|
727
|
|
|
function scl_cleaner(&$str) |
|
728
|
|
|
{ |
|
729
|
|
|
if (is_array($str)) { |
|
730
|
|
|
foreach ($str as $key => $value) { |
|
731
|
|
|
if (is_string($value)) { |
|
732
|
|
|
$str[$key] = trim(htmlspecialchars($value)); |
|
733
|
|
|
} |
|
734
|
|
|
if (is_array($value)) { |
|
735
|
|
|
foreach ($value as $cle => $valeur) { |
|
736
|
|
|
$str[$key][$cle] = scl_cleaner($valeur); |
|
737
|
|
|
} |
|
738
|
|
|
} |
|
739
|
|
|
} |
|
740
|
|
|
} |
|
741
|
|
|
if (is_string($str)) { |
|
742
|
|
|
$str = trim(htmlspecialchars($str)); |
|
743
|
|
|
} |
|
744
|
|
|
|
|
745
|
|
|
return $str; // On renvoie la chaine netoyer |
|
746
|
|
|
} |
|
747
|
|
|
|
|
748
|
|
|
/** |
|
749
|
|
|
* ------- FUNCTION SCL_INCLUDE() -------- |
|
750
|
|
|
* |
|
751
|
|
|
* @brief Cette fonction permet inclure un fichier de maniere securiser dans une page web |
|
752
|
|
|
* |
|
753
|
|
|
* @param string $file le fichier a inclure |
|
754
|
|
|
* @param array|null $data |
|
755
|
|
|
* @param bool $exception |
|
756
|
|
|
* |
|
757
|
|
|
* @return void |
|
758
|
|
|
*/ |
|
759
|
|
|
function scl_include($file, $data = [], $exception = false) |
|
760
|
|
|
{ |
|
761
|
|
|
$file = trim(htmlspecialchars($file)); |
|
762
|
|
|
if (is_file($file) && file_exists($file)) { |
|
763
|
|
|
extract((array) $data); |
|
764
|
|
|
include_once $file; |
|
765
|
|
|
} elseif ($exception) { |
|
766
|
|
|
exit('SCL EXCEPTION : The file « <b>' . $file . '</b> » don\'t exist !'); |
|
767
|
|
|
} |
|
768
|
|
|
} |
|
769
|
|
|
|
|
770
|
|
|
/** |
|
771
|
|
|
* ------- FUNCTION SCL_DEBUG() -------- |
|
772
|
|
|
* |
|
773
|
|
|
* @brief Cette fonction permet de debuger une ou plusieurs variable |
|
774
|
|
|
* |
|
775
|
|
|
* @param mixed $var |
|
776
|
|
|
* @param bool $style specifie si on veut styliser le resultat ou pas (affichage classique de var_dump()) |
|
777
|
|
|
* |
|
778
|
|
|
* @return void |
|
779
|
|
|
*/ |
|
780
|
|
|
function scl_debug($var, $style = false) |
|
781
|
|
|
{ |
|
782
|
|
|
$vars = (array) $var; |
|
783
|
|
|
|
|
784
|
|
|
if (true !== (bool) $style) { |
|
785
|
|
|
echo "<pre style=\"background:#eee;padding:1em;border:1px inset #adb5bd;border-radius:5px;font-family:monospace;margin-top:0;margin-bottom:1rem;overflow:auto;-ms-overflow-style:scrollbar;\">\n"; |
|
786
|
|
|
|
|
787
|
|
|
foreach ($vars as $var) { |
|
788
|
|
|
var_dump($var); |
|
789
|
|
|
} |
|
790
|
|
|
echo "</pre>\n"; |
|
791
|
|
|
|
|
792
|
|
|
return; |
|
793
|
|
|
} |
|
794
|
|
|
|
|
795
|
|
|
echo "<pre style=\"background:#eee;padding:1em;border:1px inset #adb5bd;border-radius:5px;font-family:monospace;margin-top:0;margin-bottom:1rem;overflow:auto;-ms-overflow-style:scrollbar;\">\n"; |
|
796
|
|
|
$i = 0; |
|
797
|
|
|
|
|
798
|
|
|
foreach ($vars as $var) { |
|
799
|
|
|
if ($i !== 0) { |
|
800
|
|
|
echo '<hr style="height:1;margin:0;margin-top:1em;" color="#ddd" size="1">'; |
|
801
|
|
|
} |
|
802
|
|
|
$i++; |
|
803
|
|
|
|
|
804
|
|
|
echo '<span style="width:auto;display:inline-block; margin-bottom: .25em; font-weight:bold;font-family:\'Lato\', candara, \'Arial Narrow\', sans-serif; color:#6c17cb; font-style:italic">'; |
|
805
|
|
|
echo ucfirst(gettype($var)); |
|
806
|
|
|
if (is_object($var)) { |
|
807
|
|
|
echo ' | ' . get_class($var); |
|
808
|
|
|
} |
|
809
|
|
|
|
|
810
|
|
|
if (is_string($var)) { |
|
811
|
|
|
echo '<span style="width:auto;font-weight:lighter !important; display:inline-block; padding-left:.5em; color:crimson">(lenght : ' . strlen($var) . ')</span>'; |
|
812
|
|
|
} |
|
813
|
|
|
if (is_array($var)) { |
|
814
|
|
|
echo '<span style="width:auto;font-weight:lighter !important; display:inline-block; padding-left:.5em; color:crimson">(lenght : ' . count($var) . ')</span>'; |
|
815
|
|
|
} |
|
816
|
|
|
echo '</span>'; |
|
817
|
|
|
|
|
818
|
|
|
if (null === $var) { |
|
819
|
|
|
echo "\n\tNULL"; |
|
820
|
|
|
} elseif (is_string($var) || is_numeric($var)) { |
|
821
|
|
|
echo "\n\t" . $var; |
|
822
|
|
|
} elseif (is_bool($var)) { |
|
823
|
|
|
echo (true === $var) ? "\n\ttrue" : "\n\tfalse"; |
|
824
|
|
|
} elseif (is_array($var) || is_object($var)) { |
|
825
|
|
|
if (empty($var)) { |
|
826
|
|
|
echo "\n\tempty"; |
|
827
|
|
|
} else { |
|
828
|
|
|
foreach ($var as $key => $value) { |
|
829
|
|
|
echo "\n\t<span style=\"width:auto;display:inline-block; margin: .25em; 0\">"; |
|
830
|
|
|
echo '<b>' . $key . '</b> => '; |
|
831
|
|
|
if (is_array($value) || is_object($value)) { |
|
832
|
|
|
scl_debug($value); |
|
833
|
|
|
} else { |
|
834
|
|
|
if (is_bool($value)) { |
|
835
|
|
|
echo (true === $value) ? 'true' : 'false'; |
|
836
|
|
|
} else { |
|
837
|
|
|
echo $value; |
|
838
|
|
|
} |
|
839
|
|
|
echo '<span style="auto;font-weight:lighter !important; display:inline-block; padding-left:.5em; color:#eb7c55">[' . ucfirst(gettype($value)); |
|
840
|
|
|
if (is_string($value)) { |
|
841
|
|
|
echo '(' . strlen($value) . ')'; |
|
842
|
|
|
} |
|
843
|
|
|
echo ']</span>'; |
|
844
|
|
|
} |
|
845
|
|
|
echo '</span>'; |
|
846
|
|
|
} |
|
847
|
|
|
} |
|
848
|
|
|
} |
|
849
|
|
|
} |
|
850
|
|
|
echo '</pre>'; |
|
851
|
|
|
} |
|
852
|
|
|
|
|
853
|
|
|
/** |
|
854
|
|
|
* ------- FUNCTION SCL_BYTE2SIZE() -------- |
|
855
|
|
|
* |
|
856
|
|
|
* @brief Cette fonction donne le poids en byte, kb, mb en fonction du nombre de byte passé en parametre |
|
857
|
|
|
* |
|
858
|
|
|
* @param int $bytes |
|
859
|
|
|
* @param int $format |
|
860
|
|
|
* @param int $precision |
|
861
|
|
|
* |
|
862
|
|
|
* @return string |
|
863
|
|
|
*/ |
|
864
|
|
|
function scl_byte2size($bytes, $format = 1024, $precision = 2) |
|
865
|
|
|
{ |
|
866
|
|
|
$unit = ['B', 'KB', 'MB', 'GB', 'TB']; |
|
867
|
|
|
|
|
868
|
|
|
return @round($bytes / $format ** ($i = floor(log($bytes, $format))), $precision) . ' ' . $unit[$i]; |
|
869
|
|
|
} |
|
870
|
|
|
|
|
871
|
|
|
/** |
|
872
|
|
|
* ------- FUNCTION SCL_MOVESPECIALCHAR() -------- |
|
873
|
|
|
* |
|
874
|
|
|
* @brief Cette fonction permet d'enlever tous les caractères spéciaux (accents, points...) dans une chaine |
|
875
|
|
|
* |
|
876
|
|
|
* @param string $str est chaine à traiter. |
|
877
|
|
|
* @param bool [$leaveSpecialChar] specifie si on veut laisser les ponctuations (.,?/:) (true) ou les remplacer par les tirets (false) |
|
878
|
|
|
* @param bool [$UpperToLower] specifie si on veut laisser les majuscules (false) ou les transformer en minuscules (true) |
|
879
|
|
|
* @param array [$specialChars] La liste des caracteres speciaux a gerer |
|
880
|
|
|
* |
|
881
|
|
|
* @return string |
|
882
|
|
|
*/ |
|
883
|
|
|
function scl_moveSpecialChar($str, $leaveSpecialChar = false, $UpperToLower = true, $specialChars = []) |
|
884
|
|
|
{ |
|
885
|
|
|
// Valeurs par défaut |
|
886
|
|
|
$leaveSpecialChar = ($leaveSpecialChar !== false) ? true : false; |
|
887
|
|
|
$UpperToLower = ($UpperToLower !== false) ? true : false; |
|
888
|
|
|
|
|
889
|
|
|
// transformer les caractères accentués en entités HTML |
|
890
|
|
|
$str = htmlentities($str, ENT_NOQUOTES); |
|
891
|
|
|
// remplacer les entités HTML pour avoir juste le premier caractères non accentués. Exemple : "&ecute;" => "e", "&Ecute;" => "E", "à" => "a" ... |
|
892
|
|
|
$str = preg_replace('#&([A-za-z])(?:acute|grave|cedil|circ|orn|ring|slash|th|tilde|uml);#', '\1', $str); |
|
893
|
|
|
// Remplacer les ligatures tel que : ?, Æ ... . Exemple "œ" => "oe" |
|
894
|
|
|
$str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str); |
|
895
|
|
|
// Supprimer tout le reste |
|
896
|
|
|
$str = preg_replace('#&[^;]+;#', '', $str); |
|
897
|
|
|
|
|
898
|
|
|
// Si on ne veut pas avoir les caractères spéciaux |
|
899
|
|
|
if ($leaveSpecialChar === false) { |
|
900
|
|
|
// Caractères spéciaux à modifier en tirets |
|
901
|
|
|
$specialChars = array_merge([ |
|
902
|
|
|
' ', '?', '!', '.', ',', ':', ';', "'", '"', '/', '\\', '*', '+', '=', '%', |
|
903
|
|
|
'[', ']', '(', ')', '{', '}', '<', '>', '&', '$', '^', '@', 'µ', '£', '§', |
|
904
|
|
|
], $specialChars); |
|
905
|
|
|
$str = str_replace($specialChars, '-', $str); |
|
906
|
|
|
} |
|
907
|
|
|
$modifStr = true; |
|
908
|
|
|
|
|
909
|
|
|
while ($modifStr === true) { |
|
910
|
|
|
$modifStr = false; |
|
911
|
|
|
// On modifie tous les << -- >> par un seul << - >> |
|
912
|
|
|
if (preg_match('#--#iSu', $str)) { |
|
913
|
|
|
$str = str_replace('--', '-', $str); |
|
914
|
|
|
$modifStr = true; |
|
915
|
|
|
} |
|
916
|
|
|
// Si le dernier caractère est un tiret, on le supprime |
|
917
|
|
|
if (preg_match('#(-)+$#iSu', $str)) { |
|
918
|
|
|
$str = substr($str, 0, (strlen($str) - 1)); |
|
919
|
|
|
$modifStr = true; |
|
920
|
|
|
} |
|
921
|
|
|
} |
|
922
|
|
|
if ($UpperToLower === true) { |
|
923
|
|
|
// Si on veut transformer les majuscules en minuscules |
|
924
|
|
|
$str = strtolower($str); |
|
925
|
|
|
} |
|
926
|
|
|
|
|
927
|
|
|
return $str; |
|
928
|
|
|
} |
|
929
|
|
|
|
|
930
|
|
|
/** |
|
931
|
|
|
* ------- FUNCTION SCL_MOVEDUPLICATECHAR() -------- |
|
932
|
|
|
* |
|
933
|
|
|
* @brief Cette fonction permet d'enlever tous les caractères doublées dans une chaine |
|
934
|
|
|
* |
|
935
|
|
|
* @param string $str est la chaine à traiter. |
|
936
|
|
|
* |
|
937
|
|
|
* @return string |
|
938
|
|
|
*/ |
|
939
|
|
|
function scl_moveDuplicateChar($str) |
|
940
|
|
|
{ |
|
941
|
|
|
for ($ascii = 95; $ascii <= 123; $ascii++) { |
|
942
|
|
|
// le chiffre 3 permet de controler qu'il y a 3 fois de suite le meme caractère |
|
943
|
|
|
$str = preg_replace('#' . chr($ascii) . '{3,}#', chr($ascii), $str); |
|
944
|
|
|
} |
|
945
|
|
|
|
|
946
|
|
|
return $str; |
|
947
|
|
|
} |
|
948
|
|
|
|
|
949
|
|
|
/** |
|
950
|
|
|
* ------- FUNCTION SCL_SPLITINT() -------- |
|
951
|
|
|
* |
|
952
|
|
|
* @brief Cette fonction permet de segmenter un nombre |
|
953
|
|
|
* |
|
954
|
|
|
* @param float|int $nbr le nombre qu'on veut segmenter. |
|
955
|
|
|
* @param int [$pas] le pas de segmentation. |
|
956
|
|
|
* @param string [$separateur] le separateur des segments. |
|
957
|
|
|
* |
|
958
|
|
|
* @return string|void |
|
959
|
|
|
*/ |
|
960
|
|
|
function scl_splitInt($nbr, $pas = 3, $separateur = ' ') |
|
961
|
|
|
{ |
|
962
|
|
|
// Valeurs par défaut |
|
963
|
|
|
if (! is_numeric($nbr)) { |
|
964
|
|
|
return; |
|
965
|
|
|
} |
|
966
|
|
|
$pas = (! empty($pas) && is_int($pas)) ? $pas : 3; |
|
967
|
|
|
$separateur = (in_array($separateur, ['.', ' ', ',', '-', '/'], true)) ? $separateur : ' '; |
|
968
|
|
|
|
|
969
|
|
|
$return = ''; // Valeur renvoyée |
|
970
|
|
|
|
|
971
|
|
|
$nombre = explode('.', $nbr); |
|
972
|
|
|
$nbr = $nombre[0]; |
|
973
|
|
|
$virgule = (! empty($nombre[1])) ? '.' . $nombre[1] : ''; |
|
974
|
|
|
|
|
975
|
|
|
$lenght = strlen($nbr); // nombre de chiffre |
|
976
|
|
|
$nbr = strrev($nbr); // on inverse le nombre |
|
977
|
|
|
|
|
978
|
|
|
while ($lenght > $pas) { |
|
979
|
|
|
// On coupe le nombre après 3 ($pas) chiffres à partir de debut et on le stocke dans $return |
|
980
|
|
|
$return .= substr($nbr, 0, $pas) . $separateur; |
|
981
|
|
|
$nbr = substr($nbr, $pas); // On enleve les 3 ($pas) premier chiffres du nombre |
|
982
|
|
|
$lenght -= $pas; // Le nombre de chiffr du nombre diminue donc de 3 ($pas) |
|
983
|
|
|
} |
|
984
|
|
|
if ($nbr !== '') { |
|
985
|
|
|
$return .= $nbr; |
|
986
|
|
|
} else { |
|
987
|
|
|
$return = substr($return, 0, strlen($return) - 1); |
|
988
|
|
|
} |
|
989
|
|
|
|
|
990
|
|
|
// On inverse encore le nombre pour revenir à la valeur initiale et on le retourne |
|
991
|
|
|
return strrev($return) . '' . $virgule; |
|
992
|
|
|
} |
|
993
|
|
|
|
|
994
|
|
|
/** |
|
995
|
|
|
* ------- FUNCTION SCL_GETTAGS() -------- |
|
996
|
|
|
* |
|
997
|
|
|
* @brief Cette fonction permet de generer les mots clés d'un contenu |
|
998
|
|
|
* |
|
999
|
|
|
* @param string $content le contenu à partir duquel on va generer les mots clés. |
|
1000
|
|
|
* @param int [$nb_tags] le nombre de mots clés à generer. |
|
1001
|
|
|
* @param bool [$relief] specifie si les mots clés renvoyés doivent avoir une taille proportionnelle à leur frequence d'apparition (true) ou pas (false). |
|
1002
|
|
|
* @param array|string|null [$mots_a_banir] specifie une liste de mot a banir dans la recherche |
|
1003
|
|
|
* @param mixed|null $mots_a_bannir |
|
1004
|
|
|
* |
|
1005
|
|
|
* @return string |
|
1006
|
|
|
*/ |
|
1007
|
|
|
function scl_getTags($content, $nb_tags = 10, $relief = false, $mots_a_bannir = null) |
|
1008
|
|
|
{ |
|
1009
|
|
|
// Valeurs par défaut |
|
1010
|
|
|
$nb_tags = (empty($nb_tags)) ? 10 : (int) $nb_tags; |
|
1011
|
|
|
$relief = ($relief !== true) ? false : true; |
|
1012
|
|
|
|
|
1013
|
|
|
if (is_file($mots_a_bannir) && file_exists($mots_a_bannir)) { |
|
1014
|
|
|
$mots_a_bannir = file_get_contents($mots_a_bannir); |
|
1015
|
|
|
$mots_a_bannir = explode("\n", $mots_a_bannir); |
|
1016
|
|
|
} |
|
1017
|
|
|
$mots_a_bannir = array_merge([ |
|
1018
|
|
|
// ---------------Pronoms--------------- |
|
1019
|
|
|
'ELLE', 'ELLES', 'CETTE', 'IL', 'ILS', 'LUI', 'NOUS', 'VOUS', 'EUX', 'MOI', 'JE', 'TU', |
|
1020
|
|
|
|
|
1021
|
|
|
// ---------------Verbes etre et avoir--------------- |
|
1022
|
|
|
'SOMMES', 'ETES', 'SONT', 'ETAIS', 'ETAIS', 'ETAIT', 'ETIONS', 'ETIEZ', 'ETAIENT', 'FUMES', 'FUTES', |
|
1023
|
|
|
'FURENT', 'SERAI', 'SERAS', 'SERA', 'SERONS', 'SEREZ', 'SERONT', 'SOIS', 'SOIT', 'SOYONS', 'SOYEZ', |
|
1024
|
|
|
'SOIENT', 'FUSSE', 'FUSSES', 'FUT', 'FUSSIONS', 'FUSSIEZ', 'FUSSENT', 'AVONS', 'AVEZ', 'AVAIS', |
|
1025
|
|
|
'AVAIT', 'AVIONS', 'AVIEZ', 'AVAIENT', 'AURAI', 'AURAS', 'AURA', 'AURONS', 'AUREZ', 'AURONT', |
|
1026
|
|
|
'AURAIS', 'AURAIS', 'AURAIT', 'AURIONS', 'AURIEZ', 'AURAIENT', |
|
1027
|
|
|
|
|
1028
|
|
|
// ---------------Mot de liaison--------------- |
|
1029
|
|
|
'DANS', 'AVEC', 'AFIN', 'POUR', 'DONT', 'COMME', 'SELON', 'APRES', 'ENSUITE', 'QUAND', 'QUANT', |
|
1030
|
|
|
'PUIS', 'ENFIN', 'MAIS', 'CEPENDANT', 'TOUTEFOIS', 'NEANMOINS', 'POURTANT', 'SINON', 'SEULEMENT', |
|
1031
|
|
|
'MALGRE', 'QUOIQUE', 'TANDIS', 'ALORS', 'CERTES', 'EVIDEMMENT', 'EVIDENT', 'AINSI', 'SOIT', 'DONC', |
|
1032
|
|
|
'TOUT', 'TOUS', |
|
1033
|
|
|
|
|
1034
|
|
|
// ---------------Caracteres HTML--------------- |
|
1035
|
|
|
'AGRAVE', 'EACUTE', 'NBSP', |
|
1036
|
|
|
], (array) $mots_a_bannir); |
|
1037
|
|
|
|
|
1038
|
|
|
foreach ($mots_a_bannir as $banni) { |
|
1039
|
|
|
$content = preg_replace('#' . $banni . '#iSu', '', $content); // Supprime les mots à bannir |
|
1040
|
|
|
} |
|
1041
|
|
|
$content = preg_replace('#[^[:alpha:]]#', ' ', $content); // On ne garde que les chaines contenant des caractères |
|
1042
|
|
|
$content = preg_replace('#(\s|\b)[\w]{1,3}\s#i', ' ', $content); // On supprime les chaines inférieurs à 3 caractrèes |
|
1043
|
|
|
$content = preg_replace('/\s\s+/', ' ', $content); // Supprime les doubles espaces |
|
1044
|
|
|
|
|
1045
|
|
|
$content = explode(' ', $content); // On recupere chaque mot (separer de l'autre mot par un espace) |
|
1046
|
|
|
$nb_words = count($content); // On compte le nombre de mots du contenu |
|
1047
|
|
|
|
|
1048
|
|
|
$content = array_count_values($content); // Construit un tableau avec le nombre d'occurences de chaques mots |
|
1049
|
|
|
arsort($content); // Tri le tableau par valeur décroissante en gardant les index |
|
1050
|
|
|
$tags = array_slice($content, 0, $nb_tags, true); // Coupe le tableau pour n'obtenir que le nombre de mots souhaité |
|
1051
|
|
|
|
|
1052
|
|
|
foreach ($tags as &$value) { // Utilisation de & pour modifier la valeur |
|
1053
|
|
|
$value = round((($value / $nb_words) * 100), 2); |
|
1054
|
|
|
} |
|
1055
|
|
|
$render_array = []; |
|
1056
|
|
|
|
|
1057
|
|
|
foreach ($tags as $key => $value) { |
|
1058
|
|
|
// Si on veut voir en relief c'est-a-dire avec des taille qui dependent du nombre d'apparition des tags |
|
1059
|
|
|
if ($relief === true) { |
|
1060
|
|
|
$size = 6; |
|
1061
|
|
|
$size = $size + $size * $value; // Calcul de la taille du tag en fonction de sa fréquence d'apparition |
|
1062
|
|
|
$render_array[] = "<span style='font-size:" . $size . "px' class='tag'>" . strtoupper($key) . '</span> '; |
|
1063
|
|
|
} else { |
|
1064
|
|
|
$render_array[] = $key . ' '; |
|
1065
|
|
|
} |
|
1066
|
|
|
} |
|
1067
|
|
|
mt_srand((float) microtime() * 1000000); |
|
1068
|
|
|
shuffle($render_array); // On mélange aléatoirement le tableau |
|
1069
|
|
|
$return = ''; // La variable de retour |
|
1070
|
|
|
|
|
1071
|
|
|
foreach ($render_array as $value) { |
|
1072
|
|
|
$return .= $value; |
|
1073
|
|
|
} |
|
1074
|
|
|
|
|
1075
|
|
|
return $return; |
|
1076
|
|
|
} |
|
1077
|
|
|
|
|
1078
|
|
|
/** |
|
1079
|
|
|
* ------- FUNCTION SCL_INT2LETTER() -------- |
|
1080
|
|
|
* |
|
1081
|
|
|
* @brief Cette fonction convertie un entier en lettre (ex: 12 => douze) |
|
1082
|
|
|
* @credit { Author: zied9b | Url: http://codes-sources.commentcamarche.net/source/51285-chiffres-en-lettres} |
|
1083
|
|
|
* |
|
1084
|
|
|
* @param int $int |
|
1085
|
|
|
* |
|
1086
|
|
|
* @return string |
|
1087
|
|
|
*/ |
|
1088
|
|
|
function scl_int2letter($int) |
|
1089
|
|
|
{ |
|
1090
|
|
|
$int_val = (int) $int; |
|
1091
|
|
|
$real_val = (int) (round($int - (int) $int, 2) * 1000); |
|
1092
|
|
|
|
|
1093
|
|
|
if ($int_val === 0) { |
|
1094
|
|
|
return 'Zero'; |
|
1095
|
|
|
} |
|
1096
|
|
|
$return = ''; |
|
1097
|
|
|
|
|
1098
|
|
|
$dix_c = (int) ($real_val % 100 / 10); |
|
1099
|
|
|
$cent_c = (int) ($real_val % 1000 / 100); |
|
1100
|
|
|
$unite[1] = $int_val % 10; |
|
1101
|
|
|
$dix[1] = (int) ($int_val % 100 / 10); |
|
1102
|
|
|
$cent[1] = (int) ($int_val % 1000 / 100); |
|
1103
|
|
|
$unite[2] = (int) ($int_val % 10000 / 1000); |
|
1104
|
|
|
$dix[2] = (int) ($int_val % 100000 / 10000); |
|
1105
|
|
|
$cent[2] = (int) ($int_val % 1000000 / 100000); |
|
1106
|
|
|
$unite[3] = (int) ($int_val % 10000000 / 1000000); |
|
1107
|
|
|
$dix[3] = (int) ($int_val % 100000000 / 10000000); |
|
1108
|
|
|
$cent[3] = (int) ($int_val % 1000000000 / 100000000); |
|
1109
|
|
|
|
|
1110
|
|
|
$chif = ['', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf', 'dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix sept', 'dix huit', 'dix neuf']; |
|
1111
|
|
|
|
|
1112
|
|
|
$trio_c = ''; |
|
1113
|
|
|
|
|
1114
|
|
|
for ($i = 1; $i <= 3; $i++) { |
|
1115
|
|
|
$prim[$i] = ''; |
|
1116
|
|
|
$secon[$i] = ''; |
|
1117
|
|
|
$trio[$i] = ''; |
|
1118
|
|
|
|
|
1119
|
|
|
if ($dix[$i] === 0) { |
|
1120
|
|
|
$secon[$i] = ''; |
|
1121
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1122
|
|
|
} elseif ($dix[$i] === 1) { |
|
1123
|
|
|
$secon[$i] = ''; |
|
1124
|
|
|
$prim[$i] = $chif[($unite[$i] + 10)]; |
|
1125
|
|
|
} elseif ($dix[$i] === 2) { |
|
1126
|
|
|
if ($unite[$i] === 1) { |
|
1127
|
|
|
$secon[$i] = 'vingt et'; |
|
1128
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1129
|
|
|
} else { |
|
1130
|
|
|
$secon[$i] = 'vingt'; |
|
1131
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1132
|
|
|
} |
|
1133
|
|
|
} elseif ($dix[$i] === 3) { |
|
1134
|
|
|
if ($unite[$i] === 1) { |
|
1135
|
|
|
$secon[$i] = 'trente et'; |
|
1136
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1137
|
|
|
} else { |
|
1138
|
|
|
$secon[$i] = 'trente'; |
|
1139
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1140
|
|
|
} |
|
1141
|
|
|
} elseif ($dix[$i] === 4) { |
|
1142
|
|
|
if ($unite[$i] === 1) { |
|
1143
|
|
|
$secon[$i] = 'quarante et'; |
|
1144
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1145
|
|
|
} else { |
|
1146
|
|
|
$secon[$i] = 'quarante'; |
|
1147
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1148
|
|
|
} |
|
1149
|
|
|
} elseif ($dix[$i] === 5) { |
|
1150
|
|
|
if ($unite[$i] === 1) { |
|
1151
|
|
|
$secon[$i] = 'cinquante et'; |
|
1152
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1153
|
|
|
} else { |
|
1154
|
|
|
$secon[$i] = 'cinquante'; |
|
1155
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1156
|
|
|
} |
|
1157
|
|
|
} elseif ($dix[$i] === 6) { |
|
1158
|
|
|
if ($unite[$i] === 1) { |
|
1159
|
|
|
$secon[$i] = 'soixante et'; |
|
1160
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1161
|
|
|
} else { |
|
1162
|
|
|
$secon[$i] = 'soixante'; |
|
1163
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1164
|
|
|
} |
|
1165
|
|
|
} elseif ($dix[$i] === 7) { |
|
1166
|
|
|
if ($unite[$i] === 1) { |
|
1167
|
|
|
$secon[$i] = 'soixante et'; |
|
1168
|
|
|
$prim[$i] = $chif[$unite[$i] + 10]; |
|
1169
|
|
|
} else { |
|
1170
|
|
|
$secon[$i] = 'soixante'; |
|
1171
|
|
|
$prim[$i] = $chif[$unite[$i] + 10]; |
|
1172
|
|
|
} |
|
1173
|
|
|
} elseif ($dix[$i] === 8) { |
|
1174
|
|
|
if ($unite[$i] === 1) { |
|
1175
|
|
|
$secon[$i] = 'quatre-vingts et'; |
|
1176
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1177
|
|
|
} else { |
|
1178
|
|
|
$secon[$i] = 'quatre-vingt'; |
|
1179
|
|
|
$prim[$i] = $chif[$unite[$i]]; |
|
1180
|
|
|
} |
|
1181
|
|
|
} elseif ($dix[$i] === 9) { |
|
1182
|
|
|
if ($unite[$i] === 1) { |
|
1183
|
|
|
$secon[$i] = 'quatre-vingts et'; |
|
1184
|
|
|
$prim[$i] = $chif[$unite[$i] + 10]; |
|
1185
|
|
|
} else { |
|
1186
|
|
|
$secon[$i] = 'quatre-vingts'; |
|
1187
|
|
|
$prim[$i] = $chif[$unite[$i] + 10]; |
|
1188
|
|
|
} |
|
1189
|
|
|
} |
|
1190
|
|
|
|
|
1191
|
|
|
if ($cent[$i] === 1) { |
|
1192
|
|
|
$trio[$i] = 'cent'; |
|
1193
|
|
|
} elseif ($cent[$i] !== 0 || $cent[$i] !== '') { |
|
1194
|
|
|
$trio[$i] = $chif[$cent[$i]] . ' cents'; |
|
1195
|
|
|
} |
|
1196
|
|
|
} |
|
1197
|
|
|
|
|
1198
|
|
|
$chif2 = ['', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante-dix', 'quatre-vingts', 'quatre-vingts dix']; |
|
1199
|
|
|
|
|
1200
|
|
|
$secon_c = $chif2[$dix_c]; |
|
1201
|
|
|
if ($cent_c === 1) { |
|
1202
|
|
|
$trio_c = 'cent'; |
|
1203
|
|
|
} elseif ($cent_c !== 0 || $cent_c !== '') { |
|
1204
|
|
|
$trio_c = $chif[$cent_c] . ' cents'; |
|
1205
|
|
|
} |
|
1206
|
|
|
|
|
1207
|
|
|
if (($cent[3] === 0 || $cent[3] === '') && ($dix[3] === 0 || $dix[3] === '') && ($unite[3] === 1)) { |
|
1208
|
|
|
$return .= $trio[3] . ' ' . $secon[3] . ' ' . $prim[3] . ' million '; |
|
1209
|
|
|
} elseif (($cent[3] !== 0 && $cent[3] !== '') || ($dix[3] !== 0 && $dix[3] !== '') || ($unite[3] !== 0 && $unite[3] !== '')) { |
|
1210
|
|
|
$return .= $trio[3] . ' ' . $secon[3] . ' ' . $prim[3] . ' millions '; |
|
1211
|
|
|
} else { |
|
1212
|
|
|
$return .= $trio[3] . ' ' . $secon[3] . ' ' . $prim[3]; |
|
1213
|
|
|
} |
|
1214
|
|
|
|
|
1215
|
|
|
if (($cent[2] === 0 || $cent[2] === '') && ($dix[2] === 0 || $dix[2] === '') && ($unite[2] === 1)) { |
|
1216
|
|
|
$return .= ' mille '; |
|
1217
|
|
|
} elseif (($cent[2] !== 0 && $cent[2] !== '') || ($dix[2] !== 0 && $dix[2] !== '') || ($unite[2] !== 0 && $unite[2] !== '')) { |
|
1218
|
|
|
$return .= $trio[2] . ' ' . $secon[2] . ' ' . $prim[2] . ' milles '; |
|
1219
|
|
|
} else { |
|
1220
|
|
|
$return .= $trio[2] . ' ' . $secon[2] . ' ' . $prim[2]; |
|
1221
|
|
|
} |
|
1222
|
|
|
|
|
1223
|
|
|
$return .= $trio[1] . ' ' . $secon[1] . ' ' . $prim[1]; |
|
1224
|
|
|
|
|
1225
|
|
|
if (! ($cent_c === '0' || $cent_c === '') || ! ($dix_c === '0' || $dix_c === '')) { |
|
1226
|
|
|
$return .= $trio_c . ' ' . $secon_c; |
|
1227
|
|
|
} |
|
1228
|
|
|
|
|
1229
|
|
|
return trim($return); |
|
1230
|
|
|
} |
|
1231
|
|
|
|