Passed
Push — main ( 3399b6...dd4eea )
by Dimitri
11:50
created

scl_date()   F

Complexity

Conditions 30
Paths 7104

Size

Total Lines 92
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 30
eloc 64
c 1
b 0
f 0
nc 7104
nop 4
dl 0
loc 92
rs 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/***
3
 *----------- ShortCodeLib-php V3 --------------
4
 *
5
 *
6
 *    Bienenue à la bibliothèque de fonctions php "ShortCodeLib 3"
7
 *
8
 *    Cette bibliothèque a été mise sur pied pour faciliter le développement des projets php
9
 *
10
 *    ---- @Auteur : Sitchet Tomkeu Dimitric - Elève Ingénieur des travaux informatique option Génie Loiciel
11
 *    ---- @Contact : (+237) 691 88 95 87 - 673 40 66 61 / [email protected]
12
 *    ---- @Licence : Creative Commons 4.0
13
 *            Vous êtes libre d'utiliser, de modifier et de partager cette bibliothèque à
14
 *            condition expresse de respecter toutes les conditions ci-dessous
15
 *                1 - CC-BY : En utilisant, en modifiant, ou en partageant ce code, vous
16
 *                    reconnaissez qu'il a été crée par Sitchet Tomkeu Dimitric
17
 *                2 - CC-SA : Pour partager ce code, vous devez le faire suivant les mêmes
18
 *                    conditions d'utilisation sus énumerées. Le nom de son auteur doit
19
 *                    apparaitre dans toutes les copies.
20
 *
21
 *    ---- Nouveautés V3.0 :
22
 *            Par Dimitric Sitchet Tomkeu <[email protected]> le 09/05/2019
23
 *            1) Ajout de la fonction scl_cypher() qui crypte et decrypte une chaine par simple substitution (ancienne fonctionnalite de scl_hash)
24
 *            2) Modification de la fonction scl_hash() en fonction de hashage a sens unique
25
 *
26
 *    ---- Nouveautés V3.0.1 :
27
 *            Par Dimitric Sitchet Tomkeu <[email protected]> le 10/05/2019
28
 *            1) Modification de la fonction scl_include() pour gerer les inclusions faibles et fortes
29
 *
30
 *    ---- Nouveautés V3.2 :
31
 *            Par Dimitric Sitchet Tomkeu <[email protected]> le 13/08/2019
32
 *            1) Ajout de la fonction scl_byte2size() qui renvoie le nombre de kb, mo, gb en fonction du nombre de byte passé en parametre
33
 *            2) Ajout de la fonction scl_int2letter() qui transforme un chiffre en lettre
34
 *
35
 *    ---- Nouveautés V3.2.1 :
36
 *            Par Dimitric Sitchet Tomkeu <[email protected]> le 15/08/2019
37
 *            1) Modification de la fonction scl_debug() pour adopter une mise en page plus moderne
38
 *
39
 *    ---- Nouveautés V3.3 :
40
 *            Par Dimitric Sitchet Tomkeu <[email protected]> le 12/01/2020
41
 *            1) Ajout de la fonction scl_shortenStr() qui tronque une chaine en ajoutant les mots de fin
42
 ***/
43
44
45
/**
46
 * ------- FUNCTION SCL_UPLOAD()   --------
47
 * @author Dimitric Sitchet Tomkeu <[email protected]>
48
 *
49
 * @brief Cette fonction permet de récupérer un fichier envoyer par formulaire
50
 * @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
51
 * @param array $input la super globale $_FILE['nom'] qui permet de récupérer toutes les informations concernant le fichier.
52
 * @param string $path le dossier du serveur où l'on souhaite ranger le fichier
53
 * @param int [$size]  la taille maximale en Ko du fichier pouvant être téléchargé
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$size] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$size].
Loading history...
54
 * @param string [$type] représente le type de fichier pouvant être téléchargé
55
 * Cette fonction prend en charge 6 types de fichier (image, video, audio, doc, zip, et web)
56
 * mais le type par défaut est 'all' pour spécifier que les 6 types ci-dessus (24 extensions) sont pris en compte
57
 * @param string [$output]  le nom avec lequel le fichier sera enregistré.
58
 */
59
function scl_upLoad($input, $path = '', $size = 2500000, $type = '', $output = '')
60
{
61
    // taille par défaut
62
    $size = (empty($size) OR !is_numeric($size)) ? 2500000 : $size;
63
    // Le dossier par defaut est la racine
64
    $path = (!empty($path) AND !file_exists($path)) ? '' : htmlspecialchars($path);
65
66
67
    if (!is_array($input)) {
68
        return array(0, 'Entrée non valide');
69
    }
70
    if (empty($input['tmp_name']) OR empty($input['name']) OR empty($input['size'])) {
71
        return array(1, 'Informations d\'entrées incomplètes');
72
    }
73
    if ($input['size'] > $size) {
74
        return array(2, 'Fichier trop volumineux');
75
    }
76
77
78
    /* vérification du type et définition des extensions autorisées */
79
    if ($type == 'image') {
80
        $extensions = array('jpg', 'jpeg', 'png', 'gif');
81
    } else if ($type == 'audio') {
82
        $extensions = array('mp3', 'wav', 'mpeg');
83
    } else if ($type == 'video') {
84
        $extensions = array('mp4', 'avi', 'ogv', 'webm', 'flv', 'mov');
85
    } else if ($type == 'doc') {
86
        $extensions = array('txt', 'doc', 'docx', 'pdf');
87
    } else if ($type == 'web') {
88
        $extensions = array('htm', 'html', 'css', 'xml', 'js', 'json');
89
    } else if ($type == 'db') {
90
        $extensions = array('sql', 'vcf');
91
    } else if ($type == 'zip') {
92
        $extensions = array('zip', 'rar');
93
    } else {
94
        // Si on veut travailler avec une(plusieurs) extensions spécifique du même type
95
        if (preg_match('#^(image|audio|video|doc|web|db|zip){1}/(.*?)$#i', $type)) {
96
            $extensions = explode('/', $type)[1];
97
            if (empty($extensions)) {
98
                // Si il n y'a rien après le slash
99
                switch (explode('/', $type)[0]) {
100
                    case 'image' :
101
                        $extensions = array('jpg', 'jpeg', 'png', 'gif');
102
                        break;
103
                    case 'audio' :
104
                        $extensions = array('mp3', 'wav', 'mpeg');
105
                        break;
106
                    case 'video' :
107
                        $extensions = array('mp4', 'avi', 'ogv', 'webm', 'flv', 'mov');
108
                        break;
109
                    case 'doc' :
110
                        $extensions = array('txt', 'doc', 'docx', 'pdf');
111
                        break;
112
                    case 'web' :
113
                        $extensions = array('htm', 'html', 'css', 'xml', 'js', 'json');
114
                        break;
115
                    case 'db' :
116
                        $extensions = array('sql', 'vcf');
117
                        break;
118
                    case 'zip' :
119
                        $extensions = array('zip', 'rar');
120
                        break;
121
                }
122
            } else if (count(explode(',', $extensions)) < 2) {
123
                $extensions = array(explode(',', $extensions)[0]); // Si il y'a une seule extension
124
            } else {
125
                $ext = explode(',', $extensions);
126
                $extensions = array(); // Si il y'a plusieurs extensions
127
                foreach ($ext AS $ex) {
128
                    $extensions[] = $ex;
129
                }
130
            }
131
        } else {
132
            $extensions = array(
133
                'jpg', 'jpeg', 'png', 'gif', 'mp3', 'wav', 'mpeg', 'mp4', 'avi', 'ogv', 'webm', 'flv', 'mov', 'txt', 'doc', 'docx',
134
                'pdf', 'htm', 'html', 'css', 'xml', 'js', 'json', 'sql', 'vcf', 'zip', 'rar'
135
            );
136
        }
137
    }
138
139
    if (!in_array(strtolower(pathinfo($input['name'])['extension']), $extensions)) {
140
        return array(3, 'Extension non prise en charge');
141
    }
142
143
144
    /*
145
    vérification de la valeur du nom d'enregistrement ($output)
146
    --  $extension = '0.' signifie qu'on ne change pas l'extension du fichier tandis que
147
        $extension = '1.' signifie qu'on change. donc nous sommes dans le cas où le '.extension' a été spécifié
148
    --  NB: ne pas confondre $extensions et $extension. l'un représente les différents extension autorisés et
149
        l'autre vérifie si l'extension originale du fichier doit être modifié ou non
150
    */
151
    if (empty($output)) // Si on ne defini pas le nom de sortie...
152
    {
153
        // on enregistre le fichier avec la date et l'heure courante
154
        $output = 'scl_' . date('Ymd') . '-' . date('His');
155
        $extension = '0.';
156
    } else // Si on defini le nom de sortie...
157
    {
158
        if (!empty(explode('.', $output)[1]) AND in_array(strtolower(explode('.', $output)[1]), $extensions))  // Si l'extension est presente dans ce nom et est valide...
159
        {
160
            $out = explode('.', $output);
161
            $output = $out[0]; // On enregistre le fichier avec le nom specifié
162
            $extension = '1.' . $out[1]; // On enregistre le fichier avec l'extension specifié (changement d'extension)
163
        } else // Sinon...on enregistre le fichier avec le nom specifié mais en conservant son extension
164
        {
165
            $output = str_replace('.', '', $output);
166
            $output = str_replace(',', '', $output);
167
            $output = str_replace(';', '', $output);
168
            $extension = '0.';
169
        }
170
    }
171
    // si on a prévu modifier l'extension du fichier
172
    if (explode('.', $extension)[0] == 1) {
173
        $extension = explode('.', $extension)[1]; // l'extension est le celui specifié
174
    } else {
175
        $extension = strtolower(pathinfo($input['name'])['extension']); // 'extension est celui de départ
176
    }
177
178
179
    // si le fichier n'a pas été téléchargé
180
    if (!move_uploaded_file($input['tmp_name'], $path . $output . '.' . $extension)) {
181
        return array(4, 'Erreur de téléversement');
182
    }
183
    return true;
184
}
185
186
187
/**
188
 * ------- FUNCTION SCL_MINIMIZEIMG()   --------
189
 * @author Dimitric Sitchet Tomkeu <dev.dimitrisitchet@gmail>
190
 *
191
 * @brief Cette fonction permet diminuer les dimensions d'une image
192
 * @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
193
 *
194
 * @param string $src la source de l'image a redimentionner.
195
 * @param array|int [$size]  le tableau contenant les nouvelles dimensions ou la dimension unique(hauteur = largeur).
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$size] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$size].
Loading history...
196
 * @param bool [$relative]  specifie si on redimensionne la photo proportionnellement aux dimensions initiales
197
 */
198
function scl_minimizeImg($src, $size = array(), $relative = false)
199
{
200
    // Si le fichier n'existe pas
201
    if (!file_exists($src)) {
202
        return array(0, 'Fichier inexistant');
203
    }
204
    // Si on n'envoi pas un tableau ou un nombre comme tailles
205
    if (empty($size) OR (!is_array($size) AND !is_int($size))) {
206
        return array(1, 'Mauvaises dimensions de redimensionnement');
207
    }
208
209
    // Si on envoie un tableau comme $size
210
    if (is_array($size)) {
211
        // Si le tableau n'a pas 1 ou deux element
212
        if (count($size) < 1 OR count($size) > 2) {
213
            return array(2, 'Violation du nombre de dimension');
214
        }
215
        // Si l'un des element du tableau n'est pas un nombre
216
        if (!is_int($size[0]) OR (!empty($size[1]) AND !is_int($size[1]))) {
217
            return array(3, 'Type de dimension inconnu');
218
        }
219
    }
220
221
    // Les nouvelles dimensions
222
    $dimensions = array('x' => 0, 'y' => 0);
223
224
    if (is_int($size)) {
225
        $dimensions['x'] = $size;
226
        $dimensions['y'] = $size;
227
    } else {
228
        if (count($size) == 1) {
229
            $dimensions['x'] = $size[0];
230
            $dimensions['y'] = $size[0];
231
        } else {
232
            $dimensions['x'] = $size[0];
233
            $dimensions['y'] = $size[1];
234
        }
235
    }
236
237
    if (preg_match('#\.jpe?g$#i', $src)) {
238
        $source = imagecreatefromjpeg($src);
239
    }
240
    if (preg_match('#\.png$#i', $src)) {
241
        $source = imagecreatefrompng($src);
242
    }
243
    if (preg_match('#\.gif$#i', $src)) {
244
        $source = imagecreatefromgif($src);
245
    }
246
247
    // Les dimensions de l'image source
248
    $l_s = imagesx($source); // Largeur
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $source does not seem to be defined for all execution paths leading up to this point.
Loading history...
249
    $h_s = imagesy($source); // Hauteur
250
251
    // Les dimensions de la destination
252
    if ($relative) {
253
        $l_d = ($dimensions['x'] / 100) * $l_s;
254
        $h_d = ($dimensions['y'] / 100) * $h_s;
255
    } else {
256
        $l_d = ($dimensions['x'] <= 10) ? $l_s : $dimensions['x']; // Largeur
257
        $h_d = ($dimensions['y'] <= 10) ? $h_s : $dimensions['y']; // Hauteur
258
    }
259
260
    // On crée la miniature vide
261
    $destination = imagecreatetruecolor($l_d, $h_d);
262
263
    // On crée la miniature
264
    imagecopyresampled($destination, $source, 0, 0, 0, 0, $l_d, $h_d, $l_s, $h_s);
265
266
267
    // On enregistre la miniature
268
    if (preg_match('#\.jpe?g$#i', $src)) {
269
        $result = imagejpeg($destination, $src);
270
    }
271
    if (preg_match('#\.png$#i', $src)) {
272
        $result = imagepng($destination, $src);
273
    }
274
    if (preg_match('#\.gif$#i', $src)) {
275
        $result = imagegif($destination, $src);
276
    }
277
278
    return ($result == true) ? true : array(5, 'Erreur lors du redimensionnement');
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $result does not seem to be defined for all execution paths leading up to this point.
Loading history...
279
}
280
281
282
/**
283
 * ------- FUNCTION SCL_GENERATEKEYS()   --------
284
 * @author Dimitric Sitchet Tomkeu <[email protected]>
285
 *
286
 * @brief Cette fonction permet de une chaine aléatoirement
287
 * @return string
288
 *
289
 * @param int [$nbr]  le nombre de caractères de la clé.
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$nbr] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$nbr].
Loading history...
290
 * @param int [$type]  le type de clé à generer.
291
 */
292
function scl_generateKeys($nbr = 8, $type = 0)
293
{
294
    /* Valeurs par défaut */
295
    $nbr = (empty($nbr)) ? 8 : (int)$nbr;
296
    $nbr = (!is_int($nbr)) ? 8 : (int)$nbr;
0 ignored issues
show
introduced by
The condition is_int($nbr) is always true.
Loading history...
297
    $nbr = ($nbr < 3 OR $nbr > 64) ? 8 : (int)$nbr;
298
299
    switch ($type) {
300
        case 1 :
301
            $chars = range('a', 'z');
302
            break; // Caractères alphabetique minuscules
303
        case 2 :
304
            $chars = range('A', 'Z');
305
            break; // Caractères alphabetique majuscules
306
        case 3 :
307
            $chars = range(0, 9);
308
            break; // Caractères numerique
309
        case 4 :
310
            $chars = array_merge(range('a', 'z'), range('A', 'Z'));
311
            break; // Caractères alphabetique
312
        case 5 :
313
            $chars = array_merge(range(0, 9), range('a', 'z'));
314
            break; // Caractères numerique et alphabetique minuscules
315
        case 6 :
316
            $chars = array_merge(range(0, 9), range('A', 'Z'));
317
            break; // Caractères numerique et alphabetique majuscules
318
        default :
319
            $chars = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
320
            break; // Tous les caractères
321
    }
322
    $return = ''; // Valeur de retour
323
    $nb_char = count($chars); // On compte le nombre de caractères disponible
324
325
    for ($i = 0; $i < $nbr; $i++) {
326
        // On tire un nombre au hasard parmi toutes les indexes de caracteres et on affiche le caracteres corespondant
327
        $return .= $chars[rand(0, ($nb_char - 1))];
328
    }
329
    return $return;
330
}
331
332
333
/**
334
 * ------- FUNCTION SCL_DATE()   --------
335
 * @author Dimitric Sitchet Tomkeu <[email protected]>
336
 * @brief Cette fonction permet de formater une date
337
 * @return string
338
 *
339
 * @param string $date la date à formater
340
 * @param string [$format]  le format de sortie
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$format] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$format].
Loading history...
341
 * @param bool [$interval] specifie si l'interval va etre donné (true) ou pas (false)
342
 * @param string [$fuseau]  le fuseau horaire
343
 */
344
function scl_date($date, $format = 'D, d M Y', $interval = true, $fuseau = 'Europe/Paris')
345
{
346
    /* Valeurs par défaut */
347
    $format = (empty($format) OR !is_string($format)) ? 'D, d M Y' : htmlspecialchars(trim($format)); // Le format de sortie, par défaut = D, d M Y
348
    $fuseau = (empty($fuseau) OR !is_string($fuseau)) ? 'Europe/Paris' : htmlspecialchars(trim($fuseau)); // fuseau horaire
349
    $interval = (!is_bool($interval)) ? true : $interval; // Specifie si on gere les intervales ou pas
350
    $interval = ($interval == false) ? false : true; // Specifie si on gere les intervales ou pas
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
351
352
    $date = new DateTime($date);  // On contruit la date
353
354
    // Si on ne gere pas les intervales
355
    if ($interval == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
356
        //On renvoie la date formatée et dans le fuseau correspondant
357
        return $date/* ->setTimezone(new DateTimeZone($fuseau)) */->format($format);
358
    }
359
360
    // Si on gere les intervales
361
    $maintenant = new DateTime(date('Y-m-d H:i:s')); // recupere la date actuelle
362
363
    // On place les date dans le fuseau horaire souhaité
364
    $maintenant->setTimezone(new DateTimeZone($fuseau));
365
    $date->setTimezone(new DateTimeZone($fuseau));
366
367
    $dif = $maintenant->diff($date)->format('%d');
368
    if ($dif < 0 OR $dif > 3) {
369
        // Si sa fait plus de 3 jours ou la date n'est pas encore arriver
370
        $return = $date->setTimezone(new DateTimeZone($fuseau))->format($format);
371
    } else if ($dif > 1) {
372
        $return = $maintenant->diff($date)->format('There is %d days');
373
    } else if ($dif == 1) {
374
        $return = 'Yesterday at ' . $date->format('H') . 'h';
375
    } else {
376
        // Si c'est aujourd'hui
377
        $dif = $maintenant->diff($date)->format('%h');
378
        if ($dif < 0) {
379
            // Si l'heure est par hasard negatif, on renvoie la data normalement
380
            $return = $date->setTimezone(new DateTimeZone($fuseau))->format($format);
381
        } else if ($dif > 1) {
382
            $return = $maintenant->diff($date)->format('There is %h hours');
383
        } else {
384
            $dif = $maintenant->diff($date)->format('%i');
385
            if ($dif < 0) {
386
                $return = $date->setTimezone(new DateTimeZone($fuseau))->format($format);
387
            } else if ($dif > 1) {
388
                $return = $maintenant->diff($date)->format('There is a %i minutes');
389
            } else {
390
                $dif = $maintenant->diff($date)->format('%s');
391
                if ($dif < 0) {
392
                    $return = $date->setTimezone(new DateTimeZone($fuseau))->format($format);
393
                } else if ($dif >= 10) {
394
                    $return = $maintenant->diff($date)->format('There is %s seconds');
395
                } else {
396
                    $return = 'Now';
397
                }
398
            }
399
        }
400
    }
401
    if ($maintenant->diff($date)->format('%y') >= 1 OR $maintenant->diff($date)->format('%m') >= 1) {
402
        return $date->setTimezone(new DateTimeZone($fuseau))->format($format);
403
    }
404
    if ($maintenant->format('d') < $date->format('d') AND $maintenant->format('y-m') <= $date->format('y-m')) {
405
        return $date->setTimezone(new DateTimeZone($fuseau))->format($format);
406
    }
407
    if ($maintenant < $date) {
408
        $dif = $date->diff($maintenant)->format('%y');
409
        if ($dif > 1) {
410
            return $date->diff($maintenant)->format('In %y years');
411
        }
412
        $dif = $date->diff($maintenant)->format('%m');
413
        if ($dif > 1) {
414
            return $date->diff($maintenant)->format('In %m months');
415
        }
416
        $dif = $date->diff($maintenant)->format('%d');
417
        if ($dif > 1) {
418
            return $date->diff($maintenant)->format('In %d days');
419
        }
420
        $dif = $date->diff($maintenant)->format('%h');
421
        if ($dif < 0) {
422
            return $date->setTimezone(new DateTimeZone($fuseau))->format($format);
423
        } else if ($dif >= 1) {
424
            return $date->diff($maintenant)->format('In %h hours');
425
        }
426
        $dif = $date->diff($maintenant)->format('%i');
427
        if ($dif < 0) {
428
            return $date->setTimezone(new DateTimeZone($fuseau))->format($format);
429
        } else if ($dif >= 1) {
430
            return $date->diff($maintenant)->format('In %i minutes');
431
        } else {
432
            return $date->setTimezone(new DateTimeZone($fuseau))->format($format);
433
        }
434
    }
435
    return $return;
436
}
437
438
439
/**
440
 * ------- FUNCTION SCL_TRANSLATE_DATE()   --------
441
 * @author Dimitric Sitchet Tomkeu <dev.dimitrisitchet@gmail>
442
 * @brief Cette fonction permet de traduire une date en une autre langue formater une date
443
 * @return string
444
 *
445
 * @param string $date la date à traduire
446
 * @param string [$lang] la langue de sortie
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$lang] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$lang].
Loading history...
447
 */
448
function scl_translate_date($date, $lang = 'en')
449
{
450
    $lang = strtolower($lang);
451
452
    if ($lang == 'fr') {
453
        $date = preg_replace('#^Now?#iSu', 'Maintenant', $date);
454
        $date = preg_replace('#^There is(\s?a)?#iSu', 'Il y a', $date);
455
        $date = preg_replace('#^Yesterday at#iSu', 'Hier à', $date);
456
        $date = preg_replace('#^In#iSu', 'Dans', $date);
457
458
        $date = preg_replace('#years#iSu', 'ans', $date);
459
        $date = preg_replace('#months#iSu', 'mois', $date);
460
        $date = preg_replace('#days#iSu', 'jours', $date);
461
        $date = preg_replace('#hours#iSu', 'heures', $date);
462
        $date = preg_replace('#seconds#iSu', 'secondes', $date);
463
464
        $date = preg_replace('#Monday#iSu', 'Lundi', $date);
465
        $date = preg_replace('#Mon#iSu', 'Lun', $date);
466
        $date = preg_replace('#Tuesday#iSu', 'Mardi', $date);
467
        $date = preg_replace('#Tue#iSu', 'Mar', $date);
468
        $date = preg_replace('#Wednesday#iSu', 'Mercredi', $date);
469
        $date = preg_replace('#Wed#iSu', 'Mer', $date);
470
        $date = preg_replace('#Thursday#iSu', 'Jeudi', $date);
471
        $date = preg_replace('#Thu#iSu', 'Jeu', $date);
472
        $date = preg_replace('#Friday#iSu', 'Vendredi', $date);
473
        $date = preg_replace('#Fri#iSu', 'Ven', $date);
474
        $date = preg_replace('#Saturday#iSu', 'Samedi', $date);
475
        $date = preg_replace('#Sat#iSu', 'Sam', $date);
476
        $date = preg_replace('#Sunday#iSu', 'Dimanche', $date);
477
        $date = preg_replace('#Sun#iSu', 'Dim', $date);
478
479
        $date = preg_replace('#January#iSu', 'Janvier', $date);
480
        $date = preg_replace('#Jan#iSu', 'Jan', $date);
481
        $date = preg_replace('#February#iSu', 'Févier', $date);
482
        $date = preg_replace('#Feb#iSu', 'Fev', $date);
483
        $date = preg_replace('#March#iSu', 'Mars', $date);
484
        $date = preg_replace('#Mar#iSu', 'Mar', $date);
485
        $date = preg_replace('#April#iSu', 'Avril', $date);
486
        $date = preg_replace('#Apr#iSu', 'Avr', $date);
487
        $date = preg_replace('#May#iSu', 'Mai', $date);
488
        $date = preg_replace('#June#iSu', 'Juin', $date);
489
        $date = preg_replace('#Jun#iSu', 'Juin', $date);
490
        $date = preg_replace('#July#iSu', 'Juillet', $date);
491
        $date = preg_replace('#July?#iSu', 'Jui', $date);
492
        $date = preg_replace('#August#iSu', 'Août', $date);
493
        $date = preg_replace('#Aug#iSu', 'Août', $date);
494
        $date = preg_replace('#September#iSu', 'Septembre', $date);
495
        $date = preg_replace('#Sept?#iSu', 'Sept', $date);
496
        $date = preg_replace('#October#iSu', 'Octobre', $date);
497
        $date = preg_replace('#Oct#iSu', 'Oct', $date);
498
        $date = preg_replace('#November#iSu', 'Novembre', $date);
499
        $date = preg_replace('#Nov#iSu', 'Nov', $date);
500
        $date = preg_replace('#December#iSu', 'Décembre', $date);
501
        $date = preg_replace('#Dec#iSu', 'Déc', $date);
502
    }
503
    return $date;
504
}
505
506
507
/**
508
 * ------- FUNCTION SCL_HASH()   --------
509
 * @author Dimitric Sitchet Tomkeu <[email protected]>
510
 * @brief Cette fonction permet d'hasher une chaine
511
 * @return string
512
 *
513
 * @param string $str la chaine caractères qu'on veut hasher
514
 * @param int [$lenght] la longueur de la chaine a sortir
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$lenght] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$lenght].
Loading history...
515
 */
516
function scl_hash($str, $lenght = 128, $key = '')
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

516
function scl_hash($str, $lenght = 128, /** @scrutinizer ignore-unused */ $key = '')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
517
{
518
// Valeur par defaut
519
    $lenght = (empty($lenght) OR !is_int($lenght)) ? 128 : $lenght;
520
//    Valeurs minimale et maximale pour le haché
521
    $lenght = ($lenght < 50) ? 50 : $lenght;
522
    $lenght = ($lenght > 200) ? 200 : $lenght;
523
524
    $str = trim(htmlspecialchars($str)); // On echappe la chaine et on supprime les espaces de debut et de fin
525
526
    $code = strlen($str); // On recupere la logueur de la chaine
527
    $code = ($code * 200) * ($code / 50); // afin de creer un code
528
529
//    Le sel
530
    $sel1 = strlen($str);
531
    $sel2 = strlen($code);
532
    $sel = strlen($str . $code);
533
534
//    Le hashage commence ici
535
    $texte_hash_1 = hash('sha256', 'scl_' . $sel1 . $str . $sel2); // Premier hash avec le sha256
536
    $texte_hash_2 = hash('sha512', $texte_hash_1 . $sel . '_hash'); // Deuxieme hash avec le sha512
537
538
//    On divise les deux hash en 2 parties egales
539
    $texte_hash_1_1 = substr($texte_hash_1, 0, 32);
540
    $texte_hash_1_2 = substr($texte_hash_1, -32); // Les parties du premier hashé
541
    $texte_hash_2_1 = substr($texte_hash_2, 0, 64);
542
    $texte_hash_2_2 = substr($texte_hash_2, -64); // Les parties du deuxieme hashé
543
544
    $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
545
546
//    On renvoi le hash avec la longueur souhaité
547
    return substr($final, 0, $lenght);
548
}
549
550
551
/**
552
 * ------- FUNCTION SCL_CYPHER()   --------
553
 * @author Dimitric Sitchet Tomkeu <[email protected]>
554
 * @brief Cette fonction permet d'encrypter et de decrypter une chaine de caracteres
555
 * @return string
556
 *
557
 * @param string $str la chaine caractères qu'on veut encrypter ou decrypter
558
 * @param string [$action] l'action qu'on veut effectuer (encrypter/decrypter).
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$action] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$action].
Loading history...
559
 * @param int [$repeat] le nombre de fois qu'on repete l'action
560
 */
561
function scl_cypher($str, $action = 'encrypt', $repeat = 0)
562
{
563
    /*Valeur par defaut */
564
    $action = strtolower($action);
565
    $action = ($action != 'decrypt') ? 'encrypt' : 'decrypt';
566
    $repeat = (!is_int($repeat) OR $repeat < 1) ? 0 : $repeat;
567
568
    $chars = ''; //Les differents caractères entrés
569
    $size = strlen($str);
570
571
    for ($i = $size; $i > 1; $i--) {
572
        // On separes chaque caracteres du mot independament
573
        $chars .= substr($str, 0, 1) . ' ';
574
        $str = substr($str, 1);
575
    }
576
    if (strlen($str) <> 0) {
577
        $chars .= $str;
578
    } else {
579
        $chars = substr($chars, 0, strlen($chars) - 1);
580
    }
581
582
    //Les entrées / sorties
583
    $inputs = array(
584
        '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',
585
        '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',
586
        '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'
587
    );
588
    $outputs = array(
589
        '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',
590
        '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',
591
        'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
592
    );
593
    $chars = explode(' ', $chars);  // On transforme la chaine précédement créée en tableau
594
    $return = '';
595
596
    // On parcours tout le dit tableau (ie. on recupere les caracteres un a un)
597
    foreach ($chars As $val) {
598
        // Si le caractère est encryptable ou decryptable
599
        if (in_array($val, $inputs) AND in_array($val, $outputs)) {
600
            // Si on veut encrypter
601
            if ($action == 'encrypt') {
602
                $num = array_search($val, $inputs); // On recupere l'index de la lettre
603
                $return .= $outputs[$num]; // et on ajoute le caractère d'encryptage correspondant
604
            } // sinon, on veut decrypter
605
            else {
606
                $num = array_search($val, $outputs); // On recupere l'index de la lettre
607
                $return .= $inputs[$num]; // et on ajoute le caractère de décryptage correspondant
608
            }
609
        } //Sinon
610
        else {
611
            $return .= $val; // On le laisse comme il est
612
        }
613
    }
614
615
    for ($i = 0; $i < $repeat; $i++) {
616
        $return = scl_cypher($return, $action);
617
    }
618
619
    return $return; // On renvoie la chaine encrypter ou decrypter
620
}
621
622
623
/**
624
 * ------- FUNCTION SCL_CRYPT()   --------
625
 * @author Dimitric Sitchet Tomkeu <[email protected]>
626
 * @param string $str la chaine caractères qu'on veut e
627
 * @brief Cette fonction permet d'encrypter et de decrypter une chaine de caracteres
628
 * @return string
629
 *ncrypter ou decrypter
630
 * @param string $key la clé de chiffrement
631
 * @param string [$action] l'action qu'on veut effectuer (encrypter/decrypter).
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$action] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$action].
Loading history...
632
 */
633
function scl_crypt($str, $key, $action = 'encrypt')
634
{
635
    /*Valeur par defaut */
636
    $action = strtolower($action);
637
    $action = ($action != 'decrypt') ? 'encrypt' : 'decrypt';
638
639
    $return = ''; // La valeur retournée
640
641
    /* On protège la clé pour eviter les failles */
642
    $code = strlen($key);
643
    $code = ($code * 4) * ($code / 3);
644
    $key = sha1(strlen($key) . $key . strlen($key . $code));
645
    $key .= md5($code . $key . $code);
646
647
    $letter = -1;
648
    $str = ($action == 'encrypt') ? $str : base64_decode($str);
649
    $strlen = strlen($str); // Nombre de caractère de la chaine à traiter
650
651
    for ($i = 0; $i < $strlen; $i++) {
652
        $letter++;
653
        if ($letter > 31) {
654
            $letter = 0;
655
        }
656
        if ($action == 'encrypt') {
657
            $neword = ord($str[$i]) + ord($key[$letter]);
658
            if ($neword > 255) {
659
                $neword -= 256;
660
            }
661
        } else {
662
            $neword = ord($str[$i]) - ord($key[$letter]);
663
            if ($neword < 1) {
664
                $neword += 256;
665
            }
666
        }
667
        $return .= chr($neword);
668
    }
669
    $return = ($action == 'encrypt') ? base64_encode($return) : $return;
670
    return $return; // On renvoie la chaine encrypter ou decrypter
671
}
672
673
674
/**
675
 * ------- FUNCTION SCL_TRUNCATE()   --------
676
 * @author Dimitric Sitchet Tomkeu <[email protected]>
677
 * @brief Cette fonction permet de couper une chaine de caractere
678
 * @return string
679
 *
680
 * @param  string $str la chaine caractères qu'on veut couper
681
 * @param int $size est la longueur finale de la chaine apres la coupure
682
 * @param bool [$suspension] specifie si on ajoute les points de suspension à la fin (true) ou pas (false).
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$suspension] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$suspension].
Loading history...
683
 */
684
function scl_truncate($str, $size, $suspension = false)
685
{
686
    /*Valeur par defaut */
687
    $str = htmlspecialchars($str); // On protege la chaine
688
    $size = (!is_numeric($size)) ? strlen($str) : $size; // Taille à couper
689
690
    $lenght = strlen($str); // longueur de la chaine
691
    if ($lenght > $size) {
692
        // Si la longueur initiale de la chaine est superieur à la taille qu'on veut
693
        $str = substr($str, 0, $size); // On coupe la chaine
694
        if ($suspension === true) {
695
            $str .= '...'; // On ajoute les suspension
696
        }
697
    }
698
    return $str; // On renvoie la chaine couper
699
}
700
701
702
/**
703
 * ------- FUNCTION SCL_SHORTENSTR()   --------
704
 * @author Dimitric Sitchet Tomkeu <[email protected]>
705
 * @brief Cette fonction permet de couper une chaine de caractere
706
 * @return string
707
 *
708
 * @param  string $str la chaine caractères qu'on veut couper
709
 * @param int $max est la longueur finale de la chaine apres la coupure
710
 * @param string [$sep] Le separateur entre le debut et la fin de la chaine
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$sep] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$sep].
Loading history...
711
 * @param int [$width] Le nombre de fois qu'on doit repeter le separateur
712
 *
713
 * @example
714
 *  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
715
 */
716
function scl_shortenStr($str, $max, $sep = '.', $width = 3)
717
{
718
    /*Valeur par defaut */
719
    $str = htmlspecialchars($str); // On protege la chaine
720
    $max = (!is_numeric($max)) ? strlen($str) : $max; // Taille à couper
721
722
    $length = strlen($str); // Nombre de caractères
723
724
    if ($length > $max) {
725
        $too_much_length = $length - $max + $width; // Nombre de caractères en trop
726
        if ($max < $width) {
727
            // Dans le cas où la largeur max est inférieur à la largeur du séparateur
728
            $width = $max;
729
        }
730
        $start = ceil($length / 2 - $too_much_length / 2);
731
        $str = substr($str, 0, $start) . str_repeat($sep, $width) . substr($str, floor($start + $too_much_length));
0 ignored issues
show
Bug introduced by
$start of type double is incompatible with the type integer|null expected by parameter $length of substr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

731
        $str = substr($str, 0, /** @scrutinizer ignore-type */ $start) . str_repeat($sep, $width) . substr($str, floor($start + $too_much_length));
Loading history...
Bug introduced by
floor($start + $too_much_length) of type double is incompatible with the type integer expected by parameter $offset of substr(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

731
        $str = substr($str, 0, $start) . str_repeat($sep, $width) . substr($str, /** @scrutinizer ignore-type */ floor($start + $too_much_length));
Loading history...
732
    }
733
    return $str;
734
}
735
736
737
/**
738
 * ------- FUNCTION SCL_CLEANER()   --------
739
 * @author Dimitric Sitchet Tomkeu <[email protected]>
740
 *
741
 * @brief Cette fonction permet de suprimer les espace en debut et fin d'une chaine tout en echappant les entités html
742
 * @return string
743
 *
744
 * @param string $str la chaine caractères qu'on veut netoyer
745
 */
746
function scl_cleaner(&$str)
747
{
748
    if (is_array($str)) {
0 ignored issues
show
introduced by
The condition is_array($str) is always false.
Loading history...
749
        foreach ($str As $key => $value) {
750
            if (is_string($value)) {
751
                $str[$key] = trim(htmlspecialchars($value));
752
            }
753
            if (is_array($value)) {
754
                foreach ($value As $cle => $valeur) {
755
                    $str[$key][$cle] = scl_cleaner($valeur);
756
                }
757
            }
758
        }
759
    }
760
    if (is_string($str)) {
0 ignored issues
show
introduced by
The condition is_string($str) is always true.
Loading history...
761
        $str = trim(htmlspecialchars($str));
762
    }
763
    return $str; // On renvoie la chaine netoyer
764
}
765
766
767
/**
768
 * ------- FUNCTION SCL_INCLUDE()   --------
769
 * @author Dimitric Sitchet Tomkeu <[email protected]>
770
 *
771
 * @brief Cette fonction permet inclure un fichier de maniere securiser dans une page web
772
 * @return void
773
 *
774
 * @param string $file le fichier a inclure
775
 * @param array|null $data
776
 * @param bool $exception
777
 *
778
 */
779
function scl_include($file, $data = array(), $exception = false)
780
{
781
    $file = trim(htmlspecialchars($file));
782
    if (is_file($file) AND file_exists($file)) {
783
        extract((array)$data);
784
        include_once($file);
785
    }
786
    else if ($exception) {
787
        die('SCL EXCEPTION : The file &laquo; <b>' . $file . '</b> &raquo; don\'t exist !');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
788
    }
789
    return;
790
}
791
792
793
/**
794
 * ------- FUNCTION SCL_DEBUG()   --------
795
 * @author Dimitric Sitchet Tomkeu <[email protected]>
796
 *
797
 * @brief Cette fonction permet de debuger une ou plusieurs variable
798
 * @return void
799
 *
800
 * @param mixed $var
801
 * @param bool $style specifie si on veut styliser le resultat ou pas (affichage classique de var_dump())
802
 */
803
function scl_debug($var, $style = false)
804
{
805
    $vars = (array) $var;
806
807
    if(true !== (bool) $style)
808
    {
809
        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";
810
        foreach ($vars As $var) {
0 ignored issues
show
introduced by
$var is overwriting one of the parameters of this function.
Loading history...
811
            var_dump($var);
0 ignored issues
show
Security Debugging Code introduced by
var_dump($var) looks like debug code. Are you sure you do not want to remove it?
Loading history...
812
        }
813
        echo "</pre>\n";
814
        return;
815
    }
816
817
    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";
818
    $i = 0;
819
820
    foreach ($vars As $var)
0 ignored issues
show
introduced by
$var is overwriting one of the parameters of this function.
Loading history...
821
    {
822
        if($i != 0) {
823
            echo '<hr style="height:1;margin:0;margin-top:1em;" color="#ddd" size="1">';
824
        }
825
        $i++;
826
827
        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">';
828
        echo ucfirst(gettype($var));
829
        if(is_object($var)) {
830
            echo ' | '.get_class($var);
831
        }
832
833
        if(is_string($var)) {
834
            echo '<span style="width:auto;font-weight:lighter !important; display:inline-block; padding-left:.5em; color:crimson">(lenght : '.strlen($var).')</span>';
835
        }
836
        if(is_array($var)) {
837
            echo '<span style="width:auto;font-weight:lighter !important; display:inline-block; padding-left:.5em; color:crimson">(lenght : '.count($var).')</span>';
838
        }
839
        echo "</span>";
840
841
        if(is_null($var)) {
842
            echo "\n\tNULL";
843
        }
844
        else if(is_string($var) OR is_numeric($var))
845
        {
846
            echo "\n\t".$var;
847
        }
848
        else if(is_bool($var)) {
849
            echo (true === $var) ? "\n\ttrue" : "\n\tfalse";
850
        }
851
        else if(is_array($var) OR is_object($var))
852
        {
853
            if(empty($var)) {
854
                echo "\n\tempty";
855
            }
856
            else
857
            {
858
                foreach($var As $key => $value)
859
                {
860
                    echo "\n\t<span style=\"width:auto;display:inline-block; margin: .25em; 0\">";
861
                    echo "<b>".$key."</b> => ";
862
                    if(is_array($value) OR is_object($value)) {
863
                        scl_debug($value);
864
                    }
865
                    else {
866
                        if(is_bool($value)) {
867
                            echo (true === $value) ? 'true' : 'false';
868
                        }
869
                        else {
870
                            echo $value;
871
                        }
872
                        echo '<span style="auto;font-weight:lighter !important; display:inline-block; padding-left:.5em; color:#eb7c55">['.ucfirst(gettype($value));
873
                        if(is_string($value)) {
874
                            echo '('.strlen($value).')';
875
                        }
876
                        echo ']</span>';
877
                    }
878
                    echo "</span>";
879
                }
880
            }
881
        }
882
    }
883
    echo "</pre>";
884
    return;
885
}
886
887
888
889
890
/* ------------------------------------------------------------------------- */
891
892
893
/**
894
 * ------- FUNCTION SCL_BYTE2SIZE()   --------
895
 *
896
 * @brief Cette fonction donne le poids en byte, kb, mb en fonction du nombre de byte passé en parametre
897
 * @return string
898
 *
899
 * @param int $bytes
900
 * @param int $format
901
 * @param int $precision
902
 */
903
function scl_byte2size($bytes, $format = 1024, $precision = 2)
904
{
905
    $unit = array('B','KB','MB', 'GB', 'TB');
906
    return @round($bytes / pow($format, ($i = floor(log($bytes, $format)))), $precision).' '.$unit[$i];
907
}
908
909
910
911
/**
912
 * ------- FUNCTION SCL_MOVESPECIALCHAR()   --------
913
 *
914
 * @brief Cette fonction permet d'enlever tous les caractères spéciaux (accents, points...) dans une chaine
915
 * @return string
916
 *
917
 * @param string $str est chaine à traiter.
918
 * @param bool [$leaveSpecialChar] specifie si on veut laisser les ponctuations (.,?/:) (true) ou les remplacer par les tirets (false)
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$leaveSpecialChar] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$leaveSpecialChar].
Loading history...
919
 * @param bool [$UpperToLower] specifie si on veut laisser les majuscules (false) ou les transformer en minuscules (true)
920
 * @param array [$specialChars] La liste des caracteres speciaux a gerer
921
 */
922
function scl_moveSpecialChar($str, $leaveSpecialChar = false, $UpperToLower = true, $specialChars = array())
923
{
924
    /* Valeurs par défaut */
925
    $leaveSpecialChar = ($leaveSpecialChar != false) ? true : false;
926
    $UpperToLower = ($UpperToLower != false) ? true : false;
927
928
    // transformer les caractères accentués en entités HTML
929
    $str = htmlentities($str, ENT_NOQUOTES);
930
    // remplacer les entités HTML pour avoir juste le premier caractères non accentués. Exemple : "&ecute;" => "e", "&Ecute;" => "E", "à" => "a" ...
931
    $str = preg_replace('#&([A-za-z])(?:acute|grave|cedil|circ|orn|ring|slash|th|tilde|uml);#', '\1', $str);
932
    // Remplacer les ligatures tel que : ?, Æ ... . Exemple "œ" => "oe"
933
    $str = preg_replace('#&([A-za-z]{2})(?:lig);#', '\1', $str);
934
    // Supprimer tout le reste
935
    $str = preg_replace('#&[^;]+;#', '', $str);
936
937
    // Si on ne veut pas avoir les caractères spéciaux
938
    if ($leaveSpecialChar == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
939
        // Caractères spéciaux à modifier en tirets
940
        $specialChars = array_merge(array(
941
            ' ', '?', '!', '.', ',', ':', ';', "'", '"', '/', '\\', '*', '+', '=', '%',
942
            '[', ']', '(', ')', '{', '}', '<', '>', '&', '$', '^', '@', 'µ', '£', '§',
943
        ), $specialChars);
944
        $str = str_replace($specialChars, '-', $str);
945
    }
946
    $modifStr = true;
947
    while ($modifStr == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
948
        $modifStr = false;
949
        // On modifie tous les << -- >> par un seul << - >>
950
        if (preg_match('#--#iSu', $str)) {
951
            $str = str_replace('--', '-', $str);
952
            $modifStr = true;
953
        }
954
        // Si le dernier caractère est un tiret, on le supprime
955
        if (preg_match('#(-)+$#iSu', $str)) {
956
            $str = substr($str, 0, (strlen($str) - 1));
957
            $modifStr = true;
958
        }
959
    }
960
    if ($UpperToLower == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
961
        // Si on veut transformer les majuscules en minuscules
962
        $str = strtolower($str);
963
    }
964
    return $str;
965
}
966
967
968
/**
969
 * ------- FUNCTION SCL_MOVEDUPLICATECHAR()   --------
970
 *
971
 * @brief Cette fonction permet d'enlever tous les caractères doublées dans une chaine
972
 * @return string
973
 *
974
 * @param string $str est la chaine à traiter.
975
 */
976
function scl_moveDuplicateChar($str)
977
{
978
    for ($ascii = 95; $ascii <= 123; $ascii++) {
979
        // le chiffre 3 permet de controler qu'il y a 3 fois de suite le meme caractère
980
        $str = preg_replace('#' . chr($ascii) . '{3,}#', chr($ascii), $str);
981
    }
982
    return $str;
983
}
984
985
986
/**
987
 * ------- FUNCTION SCL_SPLITINT()   --------
988
 *
989
 * @brief Cette fonction permet de segmenter un nombre
990
 * @return string|void
991
 *
992
 * @param float|int $nbr le nombre qu'on veut segmenter.
993
 * @param int [$pas] le pas de segmentation.
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$pas] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$pas].
Loading history...
994
 * @param string [$separateur] le separateur des segments.
995
 */
996
function scl_splitInt($nbr, $pas = 3, $separateur = ' ')
997
{
998
    /* Valeurs par défaut */
999
    if (!is_numeric($nbr)) {
1000
        return;
1001
    }
1002
    $pas = (!empty($pas) AND is_int($pas)) ? $pas : 3;
1003
    $separateur = (in_array($separateur, array('.', ' ', ',', '-', '/'))) ? $separateur : ' ';
1004
1005
    $return = ''; // Valeur renvoyée
1006
1007
    $nombre = explode('.', $nbr);
1008
    $nbr = $nombre[0];
1009
    $virgule = (!empty($nombre[1])) ? '.' . $nombre[1] : '';
1010
1011
    $lenght = strlen($nbr); // nombre de chiffre
1012
    $nbr = strrev($nbr); // on inverse le nombre
1013
1014
    while ($lenght > $pas) {
1015
        // On coupe le nombre après 3 ($pas) chiffres à partir de debut et on le stocke dans $return
1016
        $return .= substr($nbr, 0, $pas) . $separateur;
1017
        $nbr = substr($nbr, $pas); // On enleve les 3 ($pas) premier chiffres du nombre
1018
        $lenght = $lenght - $pas; // Le nombre de chiffr du nombre diminue donc de 3 ($pas)
1019
    }
1020
    if (strlen($nbr) <> 0) {
1021
        $return .= $nbr;
1022
    } else {
1023
        $return = substr($return, 0, strlen($return) - 1);
1024
    }
1025
    // On inverse encore le nombre pour revenir à la valeur initiale et on le retourne
1026
    return strrev($return) . '' . $virgule;
1027
}
1028
1029
1030
/**
1031
 * ------- FUNCTION SCL_GETTAGS()   --------
1032
 *
1033
 * @brief Cette fonction permet de generer les mots clés d'un contenu
1034
 * @return string
1035
 *
1036
 * @param string $content le contenu à partir duquel on va generer les mots clés.
1037
 * @param int [$nb_tags]  le nombre de mots clés à generer.
0 ignored issues
show
Documentation Bug introduced by
The doc comment [$nb_tags] at position 0 could not be parsed: Unknown type name '[' at position 0 in [$nb_tags].
Loading history...
1038
 * @param bool [$relief] specifie si les mots clés renvoyés doivent avoir une taille proportionnelle à leur frequence d'apparition (true) ou pas (false).
1039
 * @param null|string|array [$mots_a_banir] specifie une liste de mot a banir dans la recherche
1040
 */
1041
function scl_getTags($content, $nb_tags = 10, $relief = false, $mots_a_bannir = null)
1042
{
1043
    /* Valeurs par défaut */
1044
    $nb_tags = (empty($nb_tags)) ? 10 : (int)$nb_tags;
1045
    $relief = ($relief != true) ? false : true;
1046
1047
    if (is_file($mots_a_bannir) AND file_exists($mots_a_bannir)) {
1048
        $mots_a_bannir = file_get_contents($mots_a_bannir);
1049
        $mots_a_bannir = explode("\n", $mots_a_bannir);
1050
    }
1051
    $mots_a_bannir = array_merge(array(
1052
        #---------------Pronoms---------------
1053
        'ELLE', 'ELLES', 'CETTE', 'IL', 'ILS', 'LUI', 'NOUS', 'VOUS', 'EUX', 'MOI', 'JE', 'TU',
1054
1055
        #---------------Verbes etre et avoir---------------
1056
        'SOMMES', 'ETES', 'SONT', 'ETAIS', 'ETAIS', 'ETAIT', 'ETIONS', 'ETIEZ', 'ETAIENT', 'FUMES', 'FUTES',
1057
        'FURENT', 'SERAI', 'SERAS', 'SERA', 'SERONS', 'SEREZ', 'SERONT', 'SOIS', 'SOIT', 'SOYONS', 'SOYEZ',
1058
        'SOIENT', 'FUSSE', 'FUSSES', 'FUT', 'FUSSIONS', 'FUSSIEZ', 'FUSSENT', 'AVONS', 'AVEZ', 'AVAIS',
1059
        'AVAIT', 'AVIONS', 'AVIEZ', 'AVAIENT', 'AURAI', 'AURAS', 'AURA', 'AURONS', 'AUREZ', 'AURONT',
1060
        'AURAIS', 'AURAIS', 'AURAIT', 'AURIONS', 'AURIEZ', 'AURAIENT',
1061
1062
        #---------------Mot de liaison---------------
1063
        'DANS', 'AVEC', 'AFIN', 'POUR', 'DONT', 'COMME', 'SELON', 'APRES', 'ENSUITE', 'QUAND', 'QUANT',
1064
        'PUIS', 'ENFIN', 'MAIS', 'CEPENDANT', 'TOUTEFOIS', 'NEANMOINS', 'POURTANT', 'SINON', 'SEULEMENT',
1065
        'MALGRE', 'QUOIQUE', 'TANDIS', 'ALORS', 'CERTES', 'EVIDEMMENT', 'EVIDENT', 'AINSI', 'SOIT', 'DONC',
1066
        'TOUT', 'TOUS',
1067
1068
        #---------------Caracteres HTML---------------
1069
        'AGRAVE', 'EACUTE', 'NBSP',
1070
    ), (array)$mots_a_bannir);
1071
1072
    foreach ($mots_a_bannir As $banni) {
1073
        $content = preg_replace('#' . $banni . '#iSu', '', $content); //Supprime les mots à bannir
1074
    }
1075
    $content = preg_replace("#[^[:alpha:]]#", ' ', $content); //On ne garde que les chaines contenant des caractères
1076
    $content = preg_replace('#(\s|\b)[\w]{1,3}\s#i', ' ', $content); //On supprime les chaines inférieurs à 3 caractrèes
1077
    $content = preg_replace('/\s\s+/', ' ', $content); //Supprime les doubles espaces
1078
1079
    $content = explode(" ", $content); // On recupere chaque mot (separer de l'autre mot par un espace)
1080
    $nb_words = count($content); // On compte le nombre de mots du contenu
1081
1082
    $content = array_count_values($content); //Construit un tableau avec le nombre d'occurences de chaques mots
1083
    arsort($content); //Tri le tableau par valeur décroissante en gardant les index
1084
    $tags = array_slice($content, 0, $nb_tags, true); //Coupe le tableau pour n'obtenir que le nombre de mots souhaité
1085
1086
    foreach ($tags as &$value) { //Utilisation de & pour modifier la valeur
1087
        $value = round((($value / $nb_words) * 100), 2);
1088
    }
1089
    $render_array = array();
1090
    foreach ($tags as $key => $value) {
1091
        // Si on veut voir en relief c'est-a-dire avec des taille qui dependent du nombre d'apparition des tags
1092
        if ($relief == true) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
1093
            $size = 6;
1094
            $size = $size + $size * $value; //Calcul de la taille du tag en fonction de sa fréquence d'apparition
1095
            $render_array[] = "<span style='font-size:" . $size . "px' class='tag'>" . strtoupper($key) . "</span> ";
1096
        } else {
1097
            $render_array[] = $key . " ";
1098
        }
1099
    }
1100
    srand((float)microtime() * 1000000);
0 ignored issues
show
Bug introduced by
(double)microtime() * 1000000 of type double is incompatible with the type integer expected by parameter $seed of srand(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1100
    srand(/** @scrutinizer ignore-type */ (float)microtime() * 1000000);
Loading history...
1101
    shuffle($render_array); //On mélange aléatoirement le tableau
1102
    $return = ''; // La variable de retour
1103
    foreach ($render_array as $value) {
1104
        $return .= $value;
1105
    }
1106
    return $return;
1107
}
1108
1109
1110
/**
1111
 * ------- FUNCTION SCL_INT2LETTER()   --------
1112
 *
1113
 * @brief Cette fonction convertie un entier en lettre (ex: 12 => douze)
1114
 * @credit { Author: zied9b | Url: http://codes-sources.commentcamarche.net/source/51285-chiffres-en-lettres}
1115
 * @return string
1116
 *
1117
 * @param int $int
1118
 */
1119
function scl_int2letter($int)
1120
{
1121
    $int_val= intval($int);
1122
    $real_val = intval(round($int - intval($int), 2) * 1000);
1123
1124
    if($int_val == 0) {
1125
        return 'Zero';
1126
    }
1127
    $return = '';
1128
1129
    $dix_c = intval($real_val%100/10);
1130
    $cent_c = intval($real_val%1000/100);
1131
    $unite[1] = $int_val%10;
0 ignored issues
show
Comprehensibility Best Practice introduced by
$unite was never initialized. Although not strictly required by PHP, it is generally a good practice to add $unite = array(); before regardless.
Loading history...
1132
    $dix[1] = intval($int_val%100/10);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$dix was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dix = array(); before regardless.
Loading history...
1133
    $cent[1] =intval($int_val%1000/100);
0 ignored issues
show
Comprehensibility Best Practice introduced by
$cent was never initialized. Although not strictly required by PHP, it is generally a good practice to add $cent = array(); before regardless.
Loading history...
1134
    $unite[2]=intval($int_val%10000/1000);
1135
    $dix[2] = intval($int_val%100000/10000);
1136
    $cent[2] = intval($int_val%1000000/100000);
1137
    $unite[3] = intval($int_val%10000000/1000000);
1138
    $dix[3] = intval($int_val%100000000/10000000);
1139
    $cent[3] = intval($int_val%1000000000/100000000);
1140
1141
    $chif = array('', 'un', 'deux', 'trois', 'quatre', 'cinq', 'six', 'sept', 'huit', 'neuf', 'dix', 'onze', 'douze', 'treize', 'quatorze', 'quinze', 'seize', 'dix sept', 'dix huit', 'dix neuf');
1142
1143
    $trio_c='';
1144
    for($i=1; $i<=3; $i++)
1145
    {
1146
        $prim[$i]='';
1147
        $secon[$i]='';
1148
        $trio[$i]='';
1149
1150
        if($dix[$i]==0) {
1151
            $secon[$i]=''; $prim[$i]=$chif[$unite[$i]];
1152
        }
1153
        else if($dix[$i]==1) {
1154
            $secon[$i]=''; $prim[$i]=$chif[($unite[$i]+10)];
1155
        }
1156
        else if($dix[$i]==2)
1157
        {
1158
            if($unite[$i]==1) {
1159
                $secon[$i]='vingt et'; $prim[$i]=$chif[$unite[$i]];
1160
            }
1161
            else {
1162
                $secon[$i]='vingt'; $prim[$i]=$chif[$unite[$i]];
1163
            }
1164
        }
1165
        else if($dix[$i]==3)
1166
        {
1167
            if($unite[$i]==1) {
1168
                $secon[$i]='trente et'; $prim[$i]=$chif[$unite[$i]];
1169
            }
1170
            else {
1171
                $secon[$i]='trente'; $prim[$i]=$chif[$unite[$i]];
1172
            }
1173
        }
1174
        else if($dix[$i]==4)
1175
        {
1176
            if($unite[$i]==1) {
1177
                $secon[$i]='quarante et'; $prim[$i]=$chif[$unite[$i]];
1178
            }
1179
            else {
1180
                $secon[$i]='quarante'; $prim[$i]=$chif[$unite[$i]];
1181
            }
1182
        }
1183
        else if($dix[$i]==5)
1184
        {
1185
            if($unite[$i]==1) {
1186
                $secon[$i]='cinquante et'; $prim[$i]=$chif[$unite[$i]];
1187
            }
1188
            else {
1189
                $secon[$i]='cinquante'; $prim[$i]=$chif[$unite[$i]];
1190
            }
1191
        }
1192
        else if($dix[$i]==6)
1193
        {
1194
            if($unite[$i]==1) {
1195
                $secon[$i]='soixante et'; $prim[$i]=$chif[$unite[$i]];
1196
            }
1197
            else {
1198
                $secon[$i]='soixante'; $prim[$i]=$chif[$unite[$i]];
1199
            }
1200
        }
1201
        else if($dix[$i]==7)
1202
        {
1203
            if($unite[$i]==1) {
1204
                $secon[$i]='soixante et'; $prim[$i]=$chif[$unite[$i]+10];
1205
            }
1206
            else {
1207
                $secon[$i]='soixante'; $prim[$i]=$chif[$unite[$i]+10];
1208
            }
1209
        }
1210
        else if($dix[$i]==8)
1211
        {
1212
            if($unite[$i]==1)
1213
            {
1214
                $secon[$i]='quatre-vingts et'; $prim[$i]=$chif[$unite[$i]];
1215
            }
1216
            else {
1217
                $secon[$i]='quatre-vingt'; $prim[$i]=$chif[$unite[$i]];
1218
            }
1219
        }
1220
        else if($dix[$i]==9)
1221
        {
1222
            if($unite[$i]==1) {
1223
                $secon[$i]='quatre-vingts et'; $prim[$i]=$chif[$unite[$i]+10];
1224
            }
1225
            else {
1226
                $secon[$i]='quatre-vingts'; $prim[$i]=$chif[$unite[$i]+10];
1227
            }
1228
        }
1229
1230
        if($cent[$i]==1) {
1231
            $trio[$i]='cent';
1232
        }
1233
        else if($cent[$i]!=0 || $cent[$i]!='') {
1234
            $trio[$i] = $chif[$cent[$i]] .' cents';
1235
        }
1236
    }
1237
1238
1239
    $chif2=array('', 'dix', 'vingt', 'trente', 'quarante', 'cinquante', 'soixante', 'soixante-dix', 'quatre-vingts', 'quatre-vingts dix');
1240
1241
    $secon_c=$chif2[$dix_c];
1242
    if($cent_c==1) {
1243
        $trio_c='cent';
1244
    }
1245
    else if($cent_c!=0 || $cent_c!='') {
1246
        $trio_c = $chif[$cent_c] .' cents';
1247
    }
1248
1249
1250
    if(($cent[3]==0 || $cent[3]=='') && ($dix[3]==0 || $dix[3]=='') && ($unite[3]==1)) {
1251
        $return .= $trio[3]. '  ' .$secon[3]. ' ' . $prim[3]. ' million ';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $secon does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $trio does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $prim does not seem to be defined for all execution paths leading up to this point.
Loading history...
1252
    }
1253
    else if(($cent[3]!=0 && $cent[3]!='') || ($dix[3]!=0 && $dix[3]!='') || ($unite[3]!=0 && $unite[3]!='')) {
1254
        $return .= $trio[3]. ' ' .$secon[3]. ' ' . $prim[3]. ' millions ';
1255
    }
1256
    else {
1257
        $return .= $trio[3]. ' ' .$secon[3]. ' ' . $prim[3];
1258
    }
1259
1260
    if(($cent[2]==0 || $cent[2]=='') && ($dix[2]==0 || $dix[2]=='') && ($unite[2]==1)) {
1261
        $return .= ' mille ';
1262
    }
1263
    else if(($cent[2]!=0 && $cent[2]!='') || ($dix[2]!=0 && $dix[2]!='') || ($unite[2]!=0 && $unite[2]!='')) {
1264
        $return .= $trio[2]. ' ' .$secon[2]. ' ' . $prim[2]. ' milles ';
1265
    }
1266
    else {
1267
        $return .= $trio[2]. ' ' .$secon[2]. ' ' . $prim[2];
1268
    }
1269
1270
    $return .= $trio[1]. ' ' .$secon[1]. ' ' . $prim[1];
1271
1272
1273
    if(!($cent_c=='0' || $cent_c=='') || !($dix_c=='0' || $dix_c=='')) {
1274
        $return .= $trio_c. ' ' .$secon_c;
1275
    }
1276
1277
    return trim($return);
1278
}