Skip to content

Commit 9b4f03a

Browse files
authored
improv. remove and rewrite some code (#243)
1 parent ba96523 commit 9b4f03a

2 files changed

Lines changed: 48 additions & 136 deletions

File tree

config/function.php

Lines changed: 48 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,61 @@
11
<?php
2-
/**
3-
* Fichier contenant toutes les fonctions
4-
* Nécessaire au fonctionnement du site
5-
*
6-
* @author Eywek
7-
**/
2+
/*
3+
* File containing all functions
4+
* necessary for the operation of the site
5+
*
6+
* @author Eywek
7+
*/
88

9-
// Fonction qui supprime des entrées dans un tableau (utilisé pour les plugins)s
10-
function array_delete_value($array,$search) {
11-
$temp = array();
12-
foreach($array as $key => $value) {
13-
if($value!=$search) $temp[$key] = $value;
14-
}
15-
return $temp;
16-
}
17-
18-
function cut($data, $how) {
19-
$return = substr($data, 0, $how);
20-
return (strlen($data) > $how) ? $return.'...' : $return;
21-
}
229

23-
// Fonction qui génére une classe parmis toute celle disponible pour les news. Permet une couleur aléatoire.
24-
function rand_color_news() {
25-
$colors = array('border-top-color-dark-blue', 'border-top-color-dark-blue-2', 'border-top-color-yellow', 'border-top-color-dark-yellow', 'border-top-color-blue', 'border-top-color-magenta', 'border-top-color-green'); // toute les class disponible
26-
$color = rand(0, count($colors)-1); // génére un chiffre aléatoire entre 0 et le nombre de class
27-
return $colors[$color]; // et je retourne la class selon le chiffre aléatoire
10+
// Function that deletes entries in an array (used for plugins)
11+
function array_delete_value($array, $search)
12+
{
13+
$temp = array();
14+
foreach ($array as $key => $value) {
15+
if ($value != $search) $temp[$key] = $value;
16+
}
17+
return $temp;
2818
}
2919

30-
// Fonction qui sert a retourner un texte sécurisé avant de l'afficher (exemple: contenu d'une news).
31-
function before_display($content) {
32-
return htmlentities($content);
20+
// Function that reduces the size of a text
21+
function cut($data, $how)
22+
{
23+
$return = substr($data, 0, $how);
24+
return (strlen($data) > $how) ? $return . '...' : $return;
3325
}
3426

35-
function unzip($file, $path, $name = 'install-zip', $No_file_get_contents = false) {
36-
if ($No_file_get_contents === true OR !is_file($file)) {
37-
if(!$No_file_get_contents) {
38-
$newUpdate = file_get_contents($file);
39-
} else {
40-
$newUpdate = $file;
41-
}
42-
if ( !is_dir($path.'/zip') ) {
43-
mkdir ($path.'/zip', 0777, true);
44-
}
45-
$dlHandler = fopen($path.'/zip/'.$name.'.zip', 'w+');
46-
if ( !fwrite($dlHandler, $newUpdate) ) {
47-
return false;
48-
}
49-
fclose($dlHandler);
50-
}
51-
52-
$zip = new ZipArchive;
53-
$res = $zip->open($path.'/zip/'.$name.'.zip');
54-
if ($res === TRUE) {
55-
$zip->extractTo($path);
56-
$zip->close();
57-
unlink($path.'/zip/'.$name.'.zip');
58-
rmdir($path.'/zip');
59-
clearDir($path.'/__MACOSX');
60-
return true;
61-
} else {
62-
unlink($path.'/zip/'.$name.'.zip');
63-
rmdir($path.'/zip');
64-
return false;
65-
}
27+
// Function which generates a class among all that available for news. Allows random color.
28+
function rand_color_news()
29+
{
30+
$colors = array('border-top-color-dark-blue', 'border-top-color-dark-blue-2', 'border-top-color-yellow', 'border-top-color-dark-yellow', 'border-top-color-blue', 'border-top-color-magenta', 'border-top-color-green');
31+
$color = rand(0, count($colors) - 1);
32+
return $colors[$color];
6633
}
6734

68-
function clearDir($dossier) {
69-
if(file_exists($dossier) && is_dir($dossier)) {
70-
$ouverture=opendir($dossier);
71-
if (!$ouverture) return false;
72-
while($fichier=readdir($ouverture)) {
73-
if ($fichier == '.' || $fichier == '..') continue;
74-
if (is_dir($dossier."/".$fichier)) {
75-
$r=clearDir($dossier."/".$fichier);
76-
if (!$r) return false;
77-
}
78-
else {
79-
$r=unlink($dossier."/".$fichier);
80-
if (!$r) return false;
81-
}
82-
}
83-
closedir($ouverture);
84-
$r=rmdir($dossier);
85-
return true;
86-
}
35+
// Function which is used to return a secure text before displaying it (example: content of a news).
36+
function before_display($content)
37+
{
38+
return htmlentities($content);
8739
}
8840

89-
function clearFolder($folder)
41+
function clearDir($folder)
9042
{
91-
// 1 ouvrir le dossier
92-
@$dossier=opendir($folder);
93-
//2)Tant que le dossier est aps vide
94-
while ($fichier = readdir($dossier))
95-
{
96-
//3) Sans compter . et ..
97-
if ($fichier != "." && $fichier != "..")
98-
{
99-
//On selectionne le fichier et on le supprime
100-
unlink($folder.$fichier);
101-
}
102-
}
103-
//Fermer le dossier vide
104-
closedir($dossier);
43+
if (file_exists($folder) && is_dir($folder)) {
44+
$open = opendir($folder);
45+
if (!$open) return false;
46+
while ($file = readdir($open)) {
47+
if ($file == '.' || $file == '..') continue;
48+
if (is_dir($folder . "/" . $file)) {
49+
$r = clear_dir($folder . "/" . $file);
50+
if (!$r) return false;
51+
} else {
52+
$r = unlink($folder . "/" . $file);
53+
if (!$r) return false;
54+
}
55+
}
56+
closedir($open);
57+
rmdir($folder);
58+
return true;
59+
}
60+
return false;
10561
}
106-
107-
?>

modify.php

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)