Passed
Push — master ( f418e9...b58333 )
by Anthony
04:11
created
core/admin/Admin.class.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,6 @@
 block discarded – undo
2 2
 	namespace core\admin;
3 3
 
4 4
 	use core\App;
5
-	use core\auth\Connexion;
6 5
 	use core\auth\Encrypt;
7 6
 	use core\auth\Membre;
8 7
 	use core\Configuration;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		 * Pour récupérer la liste de tous les users afin d'activer un compte ou modifier des trucs dessus
45 45
 		 * si archiver == null on récupère les utilisateurs actifs sur le site sinon on récupere les utilisateurs archives
46 46
 		 */
47
-		public function getAllUser($archiver=null) {
47
+		public function getAllUser($archiver = null) {
48 48
 			$dbc = \core\App::getDb();
49 49
 			$this->setAllUser(null, null, null, null, null, null, null);
50 50
 
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
 
230 230
 			if ($oldimg_profil != "") {
231 231
 				$oldimg_profil = explode("/", $oldimg_profil);
232
-				if($oldimg_profil[7] != "defaut.png") {
232
+				if ($oldimg_profil[7] != "defaut.png") {
233 233
 					unlink("../../images/profil/".$oldimg_profil[7]);
234 234
 				}
235 235
 			}
Please login to merge, or discard this patch.
Braces   +5 added lines, -10 removed lines patch added patch discarded remove patch
@@ -50,8 +50,7 @@  discard block
 block discarded – undo
50 50
 
51 51
 			if ($archiver == null) {
52 52
 				$query = $dbc->query("SELECT * FROM identite WHERE archiver IS NULL AND ID_identite > 1");
53
-			}
54
-			else {
53
+			} else {
55 54
 				$query = $dbc->query("SELECT * FROM identite WHERE archiver IS NOT NULL AND ID_identite > 1");
56 55
 			}
57 56
 
@@ -67,20 +66,17 @@  discard block
 block discarded – undo
67 66
 
68 67
 					if ($obj->img_profil == "") {
69 68
 						$img_profil[] = "profil/defaut.png";
70
-					}
71
-					else {
69
+					} else {
72 70
 						$img_profil[] = $obj->img_profil;
73 71
 					}
74 72
 
75 73
 					if ($config->getValiderInscription() == 1) {
76 74
 						if ($obj->valide == 0) {
77 75
 							$valide[] = "<a href=".ADMWEBROOT."controller/core/admin/comptes/valider_compte?id_identite=$obj->ID_identite>Valider cet utilisateur</a>";
78
-						}
79
-						else {
76
+						} else {
80 77
 							$valide[] = "Utilisateur validé";
81 78
 						}
82
-					}
83
-					else {
79
+					} else {
84 80
 						$valide = "";
85 81
 					}
86 82
 				}
@@ -177,8 +173,7 @@  discard block
 block discarded – undo
177 173
 
178 174
 				$mail = new Mail($this->mail);
179 175
 				$mail->setEnvoyerMail("Réinitialisation de votre E-mail effectuée", "Votre mot de passe a été réinitialisé");
180
-			}
181
-			else {
176
+			} else {
182 177
 				FlashMessage::setFlash("le mot de passe de $this->pseudo ne peu pas être réinitialisé car il ne possède pas d'E-mail");
183 178
 				$this->erreur = true;
184 179
 			}
Please login to merge, or discard this patch.
core/Configuration.class.php 4 patches
Doc Comments   +4 added lines patch added patch discarded remove patch
@@ -59,6 +59,10 @@
 block discarded – undo
59 59
         public function getNomSite(){
60 60
             return $this->nom_site;
61 61
         }
62
+
63
+        /**
64
+         * @return string|null
65
+         */
62 66
         public function getMailSite(){
63 67
             return $this->mail_site;
64 68
         }
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -2,8 +2,6 @@
 block discarded – undo
2 2
     namespace core;
3 3
 
4 4
 
5
-    use core\HTML\flashmessage\FlashMessage;
6
-
7 5
 	class Configuration {
8 6
 		//pour la configuration générale du site
9 7
         private $nom_site; //-> nom du site
Please login to merge, or discard this patch.
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -1,16 +1,16 @@  discard block
 block discarded – undo
1 1
 <?php
2
-    namespace core;
2
+	namespace core;
3 3
 
4 4
 
5
-    use core\HTML\flashmessage\FlashMessage;
5
+	use core\HTML\flashmessage\FlashMessage;
6 6
 
7 7
 	class Configuration {
8 8
 		//pour la configuration générale du site
9
-        private $nom_site; //-> nom du site
10
-        private $mail_site; //-> pour le gérant du site contact@nomdedomaine;com
11
-        private $gerant_site; //->nom du gérant du site
12
-        private $url_site; //-> url de site
13
-        private $mail_administrateur; //-> mail de l'administrateur [email protected]
9
+		private $nom_site; //-> nom du site
10
+		private $mail_site; //-> pour le gérant du site contact@nomdedomaine;com
11
+		private $gerant_site; //->nom du gérant du site
12
+		private $url_site; //-> url de site
13
+		private $mail_administrateur; //-> mail de l'administrateur [email protected]
14 14
 		private $last_save; //-> derniere sauvegarde de la bdd
15 15
 		private $acces_admin; //-> si == 1 on a acces à l'admin
16 16
 		private $contenu_dynamique; //->savoir si es contenus sont dynamique (stockés in DB)
@@ -23,24 +23,24 @@  discard block
 block discarded – undo
23 23
 		private $activer_connexion;
24 24
 
25 25
 
26
-        //-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
27
-        public function __construct() {
28
-            $dbc = \core\App::getDb();
26
+		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
27
+		public function __construct() {
28
+			$dbc = \core\App::getDb();
29 29
 
30 30
 			//pour la configuration générale du site
31
-            $query = $dbc->query("SELECT * FROM configuration WHERE ID_configuration=1");
32
-            foreach ($query as $obj) {
33
-                $this->nom_site = $obj->nom_site;
34
-                $this->mail_site = $obj->mail_site;
35
-                $this->gerant_site = $obj->gerant_site;
36
-                $this->url_site = $obj->url_site;
37
-                $this->mail_administrateur = $obj->mail_administrateur;
38
-                $this->last_save = $obj->last_save;
31
+			$query = $dbc->query("SELECT * FROM configuration WHERE ID_configuration=1");
32
+			foreach ($query as $obj) {
33
+				$this->nom_site = $obj->nom_site;
34
+				$this->mail_site = $obj->mail_site;
35
+				$this->gerant_site = $obj->gerant_site;
36
+				$this->url_site = $obj->url_site;
37
+				$this->mail_administrateur = $obj->mail_administrateur;
38
+				$this->last_save = $obj->last_save;
39 39
 				$this->acces_admin = $obj->acces_admin;
40 40
 				$this->contenu_dynamique = $obj->contenu_dynamique;
41 41
 				$this->responsive = $obj->responsive;
42 42
 				$this->cache = $obj->cache;
43
-            }
43
+			}
44 44
 
45 45
 			//pour la configuration des comptes
46 46
 			$query = $dbc->query("SELECT * FROM configuration_compte WHERE ID_configuration_compte=1");
@@ -49,31 +49,31 @@  discard block
 block discarded – undo
49 49
 				$this->activer_inscription = $obj->activer_inscription;
50 50
 				$this->activer_connexion = $obj->activer_connexion;
51 51
 			}
52
-        }
53
-        //-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
52
+		}
53
+		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
54 54
 
55 55
 
56 56
 
57
-        //-------------------------- GETTER ----------------------------------------------------------------------------//
57
+		//-------------------------- GETTER ----------------------------------------------------------------------------//
58 58
 		//pour la configuration générale du site
59
-        public function getNomSite(){
60
-            return $this->nom_site;
61
-        }
62
-        public function getMailSite(){
63
-            return $this->mail_site;
64
-        }
65
-        public function getGerantSite(){
66
-            return $this->gerant_site;
67
-        }
68
-        public function getUrlSite(){
69
-            return $this->url_site;
70
-        }
71
-        public function getMailAdministrateur(){
72
-            return $this->mail_administrateur;
73
-        }
74
-        public function getLastSave(){
75
-            return $this->last_save;
76
-        }
59
+		public function getNomSite(){
60
+			return $this->nom_site;
61
+		}
62
+		public function getMailSite(){
63
+			return $this->mail_site;
64
+		}
65
+		public function getGerantSite(){
66
+			return $this->gerant_site;
67
+		}
68
+		public function getUrlSite(){
69
+			return $this->url_site;
70
+		}
71
+		public function getMailAdministrateur(){
72
+			return $this->mail_administrateur;
73
+		}
74
+		public function getLastSave(){
75
+			return $this->last_save;
76
+		}
77 77
 		public function getAccesAdmin() {
78 78
 			return $this->acces_admin;
79 79
 		}
@@ -97,11 +97,11 @@  discard block
 block discarded – undo
97 97
 		public function getActiverConnexion() {
98 98
 			return $this->activer_connexion;
99 99
 		}
100
-        //-------------------------- FIN GETTER ----------------------------------------------------------------------------//
100
+		//-------------------------- FIN GETTER ----------------------------------------------------------------------------//
101 101
 
102 102
 
103 103
 
104
-        //-------------------------- SETTER ----------------------------------------------------------------------------//
104
+		//-------------------------- SETTER ----------------------------------------------------------------------------//
105 105
 		/**
106 106
 		 * fonction qui permet de mettre à jour la date de la derniere save de la bdd
107 107
 		 * + supprimer la sauverde ancienne d'il y a 1 mois
@@ -125,5 +125,5 @@  discard block
 block discarded – undo
125 125
 				unlink(ROOT."bdd_backup/".$nom_save);
126 126
 			}
127 127
 		}
128
-        //-------------------------- FIN SETTER ----------------------------------------------------------------------------//
129
-    }
130 128
\ No newline at end of file
129
+		//-------------------------- FIN SETTER ----------------------------------------------------------------------------//
130
+	}
131 131
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -56,22 +56,22 @@
 block discarded – undo
56 56
 
57 57
         //-------------------------- GETTER ----------------------------------------------------------------------------//
58 58
 		//pour la configuration générale du site
59
-        public function getNomSite(){
59
+        public function getNomSite() {
60 60
             return $this->nom_site;
61 61
         }
62
-        public function getMailSite(){
62
+        public function getMailSite() {
63 63
             return $this->mail_site;
64 64
         }
65
-        public function getGerantSite(){
65
+        public function getGerantSite() {
66 66
             return $this->gerant_site;
67 67
         }
68
-        public function getUrlSite(){
68
+        public function getUrlSite() {
69 69
             return $this->url_site;
70 70
         }
71
-        public function getMailAdministrateur(){
71
+        public function getMailAdministrateur() {
72 72
             return $this->mail_administrateur;
73 73
         }
74
-        public function getLastSave(){
74
+        public function getLastSave() {
75 75
             return $this->last_save;
76 76
         }
77 77
 		public function getAccesAdmin() {
Please login to merge, or discard this patch.
core/contenus/Contenus.class.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -1,7 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 	namespace core\contenus;
3 3
 
4
-	use core\functions\ChaineCaractere;
5 4
 	use core\RedirectError;
6 5
 
7 6
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 
19 19
 
20 20
 		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
21
-		public function __construct($init_all=0) {
21
+		public function __construct($init_all = 0) {
22 22
 			$dbc = \core\App::getDb();
23 23
 
24 24
 			if ($init_all == 1) {
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
 		 * pour récupérer l'en tete d'une page (balise title ++ meta description)
72 72
 		 * @param $id_page
73 73
 		 */
74
-		public function getHeadPage($id_page, $url=null) {
74
+		public function getHeadPage($id_page, $url = null) {
75 75
 			$dbc = \core\App::getDb();
76 76
 
77 77
 			if ($id_page != 0) {
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
 		 * pour récupérer une page en particulier
95 95
 		 * @param $id_page
96 96
 		 */
97
-		public function getContenuPage($id_page=null) {
97
+		public function getContenuPage($id_page = null) {
98 98
 			$dbc = \core\App::getDb();
99 99
 
100 100
 			if ($id_page == null) {
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
 
121 121
 
122 122
 		//-------------------------- SETTER ----------------------------------------------------------------------------//
123
-		protected function setMenu($id_page, $titre, $balise_title, $url, $parent ){
123
+		protected function setMenu($id_page, $titre, $balise_title, $url, $parent) {
124 124
 			$this->id_page = $id_page;
125 125
 			$this->titre = $titre;
126 126
 			$this->balise_title = $balise_title;
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -76,8 +76,7 @@
 block discarded – undo
76 76
 
77 77
 			if ($id_page != 0) {
78 78
 				$query = $dbc->query("SELECT balise_title, meta_description, ID_page FROM page WHERE ID_page=".$id_page);
79
-			}
80
-			else {
79
+			} else {
81 80
 				$query = $dbc->query("SELECT balise_title, meta_description, ID_page FROM page WHERE url LIKE '$url'");
82 81
 			}
83 82
 
Please login to merge, or discard this patch.
core/functions/DateHeure.class.php 3 patches
Doc Comments   +2 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 		 * Fonction pour passer du format H:m en seconde
21 21
 		 * @param int $heure recoit l'heure a passer en minute
22 22
 		 * @param int $minute recoit les minutes a passer en minute
23
-		 * @return int
23
+		 * @return double|null
24 24
 		 **/
25 25
 		public static function Heureenseconde($heure, $minute) {
26 26
 			if ((is_numeric($heure)) && (is_numeric($minute))) {
@@ -38,7 +38,6 @@  discard block
 block discarded – undo
38 38
 
39 39
 		/**
40 40
 		 * passe des secondes au format H:m
41
-		 * @param int $temps correspond aux format seconde à repasser en H:m
42 41
 		 * @return string
43 42
 		 */
44 43
 		public static function Secondeenheure($seconde) {
@@ -77,7 +76,7 @@  discard block
 block discarded – undo
77 76
 
78 77
 		/**
79 78
 		 * affiche la date du jour au format jeudi 12 janvier
80
-		 * @param string $date si NULL on prend la date du jour sinon on prend la date qui est mise
79
+		 * @param integer $date si NULL on prend la date du jour sinon on prend la date qui est mise
81 80
 		 * @param int $abreger si NOT NULL, on abrege la date, on enleve la semaine et on coupe le mois à 3 lettres
82 81
 		 * @return string
83 82
 		 */
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -24,9 +24,9 @@  discard block
 block discarded – undo
24 24
 		 **/
25 25
 		public static function Heureenseconde($heure, $minute) {
26 26
 			if ((is_numeric($heure)) && (is_numeric($minute))) {
27
-				$heuresec = $heure*3600;
28
-				$minutesec = $minute*60;
29
-				$heureseconde = $heuresec+$minutesec;
27
+				$heuresec = $heure * 3600;
28
+				$minutesec = $minute * 60;
29
+				$heureseconde = $heuresec + $minutesec;
30 30
 				return $heureseconde;
31 31
 			}
32 32
 			else {
@@ -81,12 +81,12 @@  discard block
 block discarded – undo
81 81
 		 * @param int $abreger si NOT NULL, on abrege la date, on enleve la semaine et on coupe le mois à 3 lettres
82 82
 		 * @return string
83 83
 		 */
84
-		public static function date_fr_texte($date=0, $abreger=null) {
85
-			$mois = array("Janvier", "Fevrier", "Mars", "Avril","Mai", "Juin", "Juillet", "Août","Septembre", "Octobre", "Novembre", "Decembre");
86
-			$jours= array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
84
+		public static function date_fr_texte($date = 0, $abreger = null) {
85
+			$mois = array("Janvier", "Fevrier", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Decembre");
86
+			$jours = array("Dimanche", "Lundi", "Mardi", "Mercredi", "Jeudi", "Vendredi", "Samedi");
87 87
 
88 88
 			if ($date == 0) {
89
-				return $jours[date("w")]." ".date("j").(date("j")==1 ? "er":" ").$mois[date("n")-1]." ".date("Y");
89
+				return $jours[date("w")]." ".date("j").(date("j") == 1 ? "er" : " ").$mois[date("n") - 1]." ".date("Y");
90 90
 			}
91 91
 			else if ((strpos($date, "-") > 0) || (strpos($date, "/") > 0)) {
92 92
 				$pos = strpos($date, "-");
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 					return $jour_d." ".mb_substr($explode[2], 0, 3, "UTF-8")." ".$annee_d;
112 112
 				}
113 113
 				else {
114
-					return $jour_semaine." ".$jour_d." ".$mois[$mois_d-1]." ".$annee_d;
114
+					return $jour_semaine." ".$jour_d." ".$mois[$mois_d - 1]." ".$annee_d;
115 115
 				}
116 116
 			}
117 117
 			else {
Please login to merge, or discard this patch.
Braces   +9 added lines, -18 removed lines patch added patch discarded remove patch
@@ -28,8 +28,7 @@  discard block
 block discarded – undo
28 28
 				$minutesec = $minute*60;
29 29
 				$heureseconde = $heuresec+$minutesec;
30 30
 				return $heureseconde;
31
-			}
32
-			else {
31
+			} else {
33 32
 				FlashMessage::setFlash("La/les valeurs entrée n'est/ne sont pas de type int");
34 33
 				FlashMessage::getFlash();
35 34
 				die();
@@ -49,8 +48,7 @@  discard block
 block discarded – undo
49 48
 
50 49
 				$temps = $heure."h".$minute."m".$seconde;
51 50
 				return $temps;
52
-			}
53
-			else {
51
+			} else {
54 52
 				FlashMessage::setFlash("La valeur entrée n'est pas de type int");
55 53
 				FlashMessage::getFlash();
56 54
 				die();
@@ -67,8 +65,7 @@  discard block
 block discarded – undo
67 65
 				$chaine = str_replace(":", "h", $temps);
68 66
 
69 67
 				return $chaine;
70
-			}
71
-			else {
68
+			} else {
72 69
 				FlashMessage::setFlash("La valeur entrée n'est pas de type h:m");
73 70
 				FlashMessage::getFlash();
74 71
 				die();
@@ -87,8 +84,7 @@  discard block
 block discarded – undo
87 84
 
88 85
 			if ($date == 0) {
89 86
 				return $jours[date("w")]." ".date("j").(date("j")==1 ? "er":" ").$mois[date("n")-1]." ".date("Y");
90
-			}
91
-			else if ((strpos($date, "-") > 0) || (strpos($date, "/") > 0)) {
87
+			} else if ((strpos($date, "-") > 0) || (strpos($date, "/") > 0)) {
92 88
 				$pos = strpos($date, "-");
93 89
 
94 90
 				//si $pos > 0 cela veut dire qu'on est en YYYY-mm-jj
@@ -97,8 +93,7 @@  discard block
 block discarded – undo
97 93
 					$jour_d = $explode[2];
98 94
 					$mois_d = $explode[1];
99 95
 					$annee_d = $explode[0];
100
-				}
101
-				else {
96
+				} else {
102 97
 					$explode = explode("/", $date);
103 98
 					$jour_d = $explode[0];
104 99
 					$mois_d = $explode[1];
@@ -109,12 +104,10 @@  discard block
 block discarded – undo
109 104
 
110 105
 				if ($abreger != NULL) {
111 106
 					return $jour_d." ".mb_substr($explode[2], 0, 3, "UTF-8")." ".$annee_d;
112
-				}
113
-				else {
107
+				} else {
114 108
 					return $jour_semaine." ".$jour_d." ".$mois[$mois_d-1]." ".$annee_d;
115 109
 				}
116
-			}
117
-			else {
110
+			} else {
118 111
 				FlashMessage::setFlash("Format de date passé en paramètre ne correspond pas à YYYY-mm-jj ou jj/mm/YYYY");
119 112
 				FlashMessage::getFlash();
120 113
 				die();
@@ -140,8 +133,7 @@  discard block
 block discarded – undo
140 133
 				self::$annee = $annee;
141 134
 
142 135
 				return $jour."/".$mois."/".$annee;
143
-			}
144
-			else {
136
+			} else {
145 137
 				FlashMessage::setFlash("format de date passé en paramètre ne correspond pas à YYYY-mm-jj");
146 138
 				FlashMessage::getFlash();
147 139
 				die();
@@ -163,8 +155,7 @@  discard block
 block discarded – undo
163 155
 				$annee = $explode[2];
164 156
 
165 157
 				return $annee."-".$mois."-".$jour;
166
-			}
167
-			else {
158
+			} else {
168 159
 				FlashMessage::setFlash("Format de date passé en paramètre ne correspond pas à jj/mm/aaaa");
169 160
 				FlashMessage::getFlash();
170 161
 				die();
Please login to merge, or discard this patch.
core/modules/GestionModule.class.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 
134 134
 		/**
135 135
 		 * @param $nom_module
136
-		 * @return bool
136
+		 * @return boolean|null
137 137
 		 * return true si le module est activer sinon false
138 138
 		 */
139 139
 		public static function getModuleActiver($nom_module) {
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
 
154 154
 		/**
155 155
 		 * @param $nom_module
156
-		 * @return bool
156
+		 * @return boolean|null
157 157
 		 * fonction qui permet de savoir si un module est à jour ou non
158 158
 		 * si a jour renvoi true sinon renvoi false
159 159
 		 */
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -203,12 +203,12 @@  discard block
 block discarded – undo
203 203
 						$this->nom_fichier = end($explode);
204 204
 
205 205
 						//on recupere le nom du dossier + extention
206
-						$explode  = explode(".", $obj->url_telechargement);
206
+						$explode = explode(".", $obj->url_telechargement);
207 207
 						array_pop($explode);
208 208
 
209 209
 						$version_txt = implode(".", $explode)."_version.txt";
210 210
 
211
-						if(file_get_contents($version_txt) == true) {
211
+						if (file_get_contents($version_txt) == true) {
212 212
 
213 213
 							//online pour bdd
214 214
 							$version_online_txt = file_get_contents($version_txt);
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
 		
276 276
 		
277 277
 		//-------------------------- SETTER ----------------------------------------------------------------------------//
278
-		private function setListeModuleActiver($id_module, $url, $version, $nom, $icone=null, $url_telechargement=null) {
278
+		private function setListeModuleActiver($id_module, $url, $version, $nom, $icone = null, $url_telechargement = null) {
279 279
 			$this->id_module = $id_module;
280 280
 			$this->url = $url;
281 281
 			$this->nom = $nom;
Please login to merge, or discard this patch.
Braces   +7 added lines, -14 removed lines patch added patch discarded remove patch
@@ -121,12 +121,10 @@  discard block
 block discarded – undo
121 121
 
122 122
 				if ($installer == 1) {
123 123
 					return true;
124
-				}
125
-				else {
124
+				} else {
126 125
 					return false;
127 126
 				}
128
-			}
129
-			else {
127
+			} else {
130 128
 				return false;
131 129
 			}
132 130
 		}
@@ -144,8 +142,7 @@  discard block
 block discarded – undo
144 142
 			foreach ($query as $obj) {
145 143
 				if ($obj->activer == 1) {
146 144
 					return true;
147
-				}
148
-				else {
145
+				} else {
149 146
 					return false;
150 147
 				}
151 148
 			}
@@ -165,8 +162,7 @@  discard block
 block discarded – undo
165 162
 			foreach ($query as $obj) {
166 163
 				if ($obj->mettre_jour == 1) {
167 164
 					return false;
168
-				}
169
-				else {
165
+				} else {
170 166
 					return true;
171 167
 				}
172 168
 			}
@@ -189,8 +185,7 @@  discard block
 block discarded – undo
189 185
 						//si pas de version a checker, cela veut dire qu'on vient d'installer le module
190 186
 						//du coup on met le next_check aa la semaine pro
191 187
 						$set_next = true;
192
-					}
193
-					else if (($obj->next_check_version <= $today) && ($obj->mettre_jour != 1)) {
188
+					} else if (($obj->next_check_version <= $today) && ($obj->mettre_jour != 1)) {
194 189
 						//avant tout on regarde si on doit delete une vieille version
195 190
 						if ($obj->delete_old_version == 1) {
196 191
 							$import = new ImportModule();
@@ -232,8 +227,7 @@  discard block
 block discarded – undo
232 227
 								$dbc->prepare("UPDATE module SET mettre_jour=:update, online_version=:online_version WHERE ID_module=:id_module", $value);
233 228
 
234 229
 								$set_next = true;
235
-							}
236
-							else {
230
+							} else {
237 231
 								$set_next = true;
238 232
 							}
239 233
 						}
@@ -266,8 +260,7 @@  discard block
 block discarded – undo
266 260
 				$this->setListeModuleMettreJour($nom_module, $version, $online_version);
267 261
 
268 262
 				return true;
269
-			}
270
-			else {
263
+			} else {
271 264
 				return false;
272 265
 			}
273 266
 		}
Please login to merge, or discard this patch.
core/modules/ImportModule.class.php 3 patches
Doc Comments   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -50,6 +50,7 @@  discard block
 block discarded – undo
50 50
 		/**
51 51
 		 * @param $url_module
52 52
 		 * fonction qui permets d'importer un module dans notre site internet
53
+		 * @param boolean $update
53 54
 		 */
54 55
 		public function setImportModule($url_module, $update=null) {
55 56
 			$dbc= App::getDb();
@@ -226,7 +227,7 @@  discard block
 block discarded – undo
226 227
 		}
227 228
 
228 229
 		/**
229
-		 * @param $url
230
+		 * @param string $url
230 231
 		 * fonction qui permet de supprmer un dossier avec toute son abrorescence en fonction d'une URL
231 232
 		 */
232 233
 		private function supprimerDossier($url) {
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,15 +51,15 @@
 block discarded – undo
51 51
 		 * @param $url_module
52 52
 		 * fonction qui permets d'importer un module dans notre site internet
53 53
 		 */
54
-		public function setImportModule($url_module, $update=null) {
55
-			$dbc= App::getDb();
54
+		public function setImportModule($url_module, $update = null) {
55
+			$dbc = App::getDb();
56 56
 
57 57
 			//avant tout on récupère le nom du fichier pour le mettre dans le dossier temporaire
58 58
 			$explode = explode("/", $url_module);
59 59
 			$this->nom_fichier = end($explode);
60 60
 
61 61
 			//on recupere le nom du dossier + extention
62
-			$explode  = explode(".", $this->nom_fichier);
62
+			$explode = explode(".", $this->nom_fichier);
63 63
 			$this->nom_dossier = $explode[0];
64 64
 			$this->extension = $explode[1];
65 65
 
Please login to merge, or discard this patch.
Braces   +20 added lines, -21 removed lines patch added patch discarded remove patch
@@ -20,8 +20,12 @@  discard block
 block discarded – undo
20 20
 		//-------------------------- CONSTRUCTEUR ----------------------------------------------------------------------------//
21 21
 		public function __construct() {
22 22
 			//On test si dossier temporaire + modules a la racines existes bien sinon on les crées
23
-			if (!file_exists(ROOT."temp")) mkdir(ROOT."temp");
24
-			if (!file_exists(ROOT."modules")) mkdir(ROOT."modules");
23
+			if (!file_exists(ROOT."temp")) {
24
+				mkdir(ROOT."temp");
25
+			}
26
+			if (!file_exists(ROOT."modules")) {
27
+				mkdir(ROOT."modules");
28
+			}
25 29
 		}
26 30
 		//-------------------------- FIN CONSTRUCTEUR ----------------------------------------------------------------------------//
27 31
 		
@@ -81,19 +85,16 @@  discard block
 block discarded – undo
81 85
 
82 86
 
83 87
 									FlashMessage::setFlash("Votre module a bien été ajouté au site.", "success");
84
-								}
85
-								else {
88
+								} else {
86 89
 									\core\HTML\flashmessage\FlashMessage::setFlash("Erreur lors du téléchargement du module, veuillez réessayer dans un instant.");
87 90
 									$this->erreur = true;
88 91
 								}
89
-							}
90
-							else {
92
+							} else {
91 93
 								\core\HTML\flashmessage\FlashMessage::setFlash("Erreur lors du téléchargement du module, veuillez réessayer dans un instant.");
92 94
 								$this->setSupprimerArchiveTemp();
93 95
 								$this->erreur = true;
94 96
 							}
95
-						}
96
-						else {
97
+						} else {
97 98
 							\core\HTML\flashmessage\FlashMessage::setFlash("Erreur lors du téléchargement du module, veuillez réessayer dans un instant.");
98 99
 							$this->setSupprimerArchiveTemp();
99 100
 							$this->erreur = true;
@@ -101,18 +102,15 @@  discard block
 block discarded – undo
101 102
 
102 103
 						$zip->close();
103 104
 						$this->setSupprimerArchiveTemp();
104
-					}
105
-					else {
105
+					} else {
106 106
 						FlashMessage::setFlash("Le module n'a pas pu être correctement téléchargé, veuillez réesseyer dans un instant");
107 107
 						$this->erreur = true;
108 108
 					}
109
-				}
110
-				else {
109
+				} else {
111 110
 					FlashMessage::setFlash("Ce module est déjà présent sur ce site, merci de renommer votre module");
112 111
 					$this->erreur = true;
113 112
 				}
114
-			}
115
-			else {
113
+			} else {
116 114
 				FlashMessage::setFlash("Le format de votre archive doit obligatoirement être un .zip");
117 115
 				$this->erreur = true;
118 116
 			}
@@ -150,8 +148,7 @@  discard block
 block discarded – undo
150 148
 
151 149
 					FlashMessage::setFlash("Votre module a bien été mis à jour", "success");
152 150
 				}
153
-			}
154
-			else {
151
+			} else {
155 152
 				FlashMessage::setFlash("Impossible de télécharger la mise à jour, veuillez réesseyer dans un instant");
156 153
 			}
157 154
 		}
@@ -163,8 +160,7 @@  discard block
 block discarded – undo
163 160
 		private function setSupprimerArchiveTemp() {
164 161
 			if (unlink(TEMPROOT.$this->nom_fichier) == true) {
165 162
 				return true;
166
-			}
167
-			else {
163
+			} else {
168 164
 				return false;
169 165
 			}
170 166
 		}
@@ -191,8 +187,7 @@  discard block
 block discarded – undo
191 187
 				);
192 188
 
193 189
 				$dbc->prepare("UPDATE module SET activer=:activer, installer=:installer WHERE ID_module=:id_module", $value);
194
-			}
195
-			else {
190
+			} else {
196 191
 				$value = array(
197 192
 					"id_module" => $id_module,
198 193
 				);
@@ -234,7 +229,11 @@  discard block
 block discarded – undo
234 229
 				$objects = scandir($url);
235 230
 				foreach ($objects as $object) {
236 231
 					if ($object != "." && $object != "..") {
237
-						if (filetype($url."/".$object) == "dir") $this->supprimerDossier($url."/".$object); else unlink($url."/".$object);
232
+						if (filetype($url."/".$object) == "dir") {
233
+							$this->supprimerDossier($url."/".$object);
234
+						} else {
235
+							unlink($url."/".$object);
236
+						}
238 237
 					}
239 238
 				}
240 239
 				reset($objects);
Please login to merge, or discard this patch.
core/modules/RouterModule.class.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 	use core\App;
6 6
 	use core\functions\ChaineCaractere;
7
-	use core\HTML\flashmessage\FlashMessage;
8 7
 
9 8
 	class RouterModule {
10 9
 		//varaibles de base de config
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -48,10 +48,10 @@  discard block
 block discarded – undo
48 48
 		 * @param $url
49 49
 		 * @return string
50 50
 		 */
51
-		public function getUrl($url){
51
+		public function getUrl($url) {
52 52
 			$explode = explode("/", $url);
53 53
 
54
-			for ($i=0 ; $i<count($explode) ; $i++) {
54
+			for ($i = 0; $i < count($explode); $i++) {
55 55
 				if (in_array($explode[$i], $this->getAllModules())) {
56 56
 					$this->module = $explode[$i];
57 57
 					$debut_url = $explode[$i];
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
 
86 86
 			$query = $dbc->query("SELECT * FROM module");
87 87
 
88
-			foreach($query as $obj) {
88
+			foreach ($query as $obj) {
89 89
 				$test_module = ChaineCaractere::FindInString($url, $obj->url);
90 90
 				$test_module1 = ChaineCaractere::FindInString($url, str_replace("/", "", $obj->url));
91 91
 				$module_activer = \core\modules\GestionModule::getModuleActiver($obj->nom_module);
Please login to merge, or discard this patch.
Braces   +4 added lines, -8 removed lines patch added patch discarded remove patch
@@ -55,12 +55,10 @@  discard block
 block discarded – undo
55 55
 				if (in_array($explode[$i], $this->getAllModules())) {
56 56
 					$this->module = $explode[$i];
57 57
 					$debut_url = $explode[$i];
58
-				}
59
-				else if ($i == 1) {
58
+				} else if ($i == 1) {
60 59
 					$centre_url = $explode[$i];
61 60
 					$this->page = $explode[$i];
62
-				}
63
-				else {
61
+				} else {
64 62
 					$this->parametre = $explode[$i];
65 63
 				}
66 64
 			}
@@ -93,16 +91,14 @@  discard block
 block discarded – undo
93 91
 				if ((($test_module == true) || ($test_module1 == true)) && ($module_activer == true)) {
94 92
 					$error = false;
95 93
 					break;
96
-				}
97
-				else {
94
+				} else {
98 95
 					$error = true;
99 96
 				}
100 97
 			}
101 98
 
102 99
 			if ($error == true) {
103 100
 				return false;
104
-			}
105
-			else {
101
+			} else {
106 102
 				return true;
107 103
 			}
108 104
 		}
Please login to merge, or discard this patch.
core/RedirectError.class.php 4 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -7,6 +7,9 @@
 block discarded – undo
7 7
 
8 8
 	class RedirectError {
9 9
 
10
+		/**
11
+		 * @param integer $type
12
+		 */
10 13
 		public static function Redirect($type) {
11 14
 			if ($type == 404) {
12 15
 				header("HTTP/1.0 404 Not Found");
Please login to merge, or discard this patch.
Unused Use Statements   -2 removed lines patch added patch discarded remove patch
@@ -1,8 +1,6 @@
 block discarded – undo
1 1
 <?php
2 2
 	namespace core;
3 3
 
4
-	use core\functions\ChaineCaractere;
5
-	use core\HTML\flashmessage\FlashMessage;
6 4
 	use core\modules\RouterModule;
7 5
 
8 6
 	class RedirectError {
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@
 block discarded – undo
32 32
 			}
33 33
 
34 34
 
35
-			$find   = 'controller/';
35
+			$find = 'controller/';
36 36
 			$pos = strpos($url, $find);
37 37
 
38 38
 			if ($pos !== false) {
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,8 +26,7 @@  discard block
 block discarded – undo
26 26
 		public static function testRedirect404($query, $url) {
27 27
 			if (is_array($query)) {
28 28
 				$count_query = count($query);
29
-			}
30
-			else {
29
+			} else {
31 30
 				$count_query = 0;
32 31
 			}
33 32
 
@@ -37,15 +36,13 @@  discard block
 block discarded – undo
37 36
 
38 37
 			if ($pos !== false) {
39 38
 				$controller = true;
40
-			}
41
-			else {
39
+			} else {
42 40
 				$controller = false;
43 41
 			}
44 42
 
45 43
 			if (($count_query > 0) || ((!is_array($query)) && ($query > 0)) || ($controller == true)) {
46 44
 				return true;
47
-			}
48
-			else {
45
+			} else {
49 46
 				$router = new RouterModule();
50 47
 
51 48
 				if ($router->getRouteModuleExist($url) == false) {
Please login to merge, or discard this patch.
libs/ckfinder/core/connector/php/php4/Utils/FileSystem.php 4 patches
Doc Comments   +3 added lines, -5 removed lines patch added patch discarded remove patch
@@ -135,7 +135,7 @@  discard block
 block discarded – undo
135 135
      * PHP4 Scandir
136 136
      * @static
137 137
      * @access public
138
-     * @param $directory directory name
138
+     * @param string $directory directory name
139 139
     */
140 140
     function php4_scandir($directory)
141 141
     {
@@ -404,7 +404,6 @@  discard block
 block discarded – undo
404 404
      * @static
405 405
      * @access public
406 406
      * @param string $dir
407
-     * @param int $mode
408 407
      * @return boolean
409 408
      */
410 409
     function createDirectoryRecursively($dir)
@@ -454,7 +453,7 @@  discard block
 block discarded – undo
454 453
      * @static
455 454
      * @access public
456 455
      * @param string $filePath absolute path to file
457
-     * @return boolean
456
+     * @return string
458 457
     */
459 458
     function detectHtml($filePath)
460 459
     {
@@ -515,8 +514,7 @@  discard block
 block discarded – undo
515 514
      * @access public
516 515
      * @param string $filePath absolute path to file
517 516
      * @param string $extension file extension
518
-     * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
519
-     * @return boolean
517
+     * @return string
520 518
     */
521 519
     function isImageValid($filePath, $extension)
522 520
     {
Please login to merge, or discard this patch.
Indentation   +523 added lines, -523 removed lines patch added patch discarded remove patch
@@ -26,220 +26,220 @@  discard block
 block discarded – undo
26 26
 class CKFinder_Connector_Utils_FileSystem
27 27
 {
28 28
 
29
-    /**
30
-     * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string
31
-     *
32
-     * @static
33
-     * @access public
34
-     * @param string $path1 first path
35
-     * @param string $path2 scecond path
36
-     * @return string
37
-     */
38
-    function combinePaths($path1, $path2)
39
-    {
40
-        if (is_null($path1))  {
41
-            $path1 = "";
42
-        }
43
-        if (is_null($path2))  {
44
-            $path2 = "";
45
-        }
46
-        if (!strlen($path2)) {
47
-            if (strlen($path1)) {
48
-                $_lastCharP1 = substr($path1, -1, 1);
49
-                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
50
-                    $path1 .= DIRECTORY_SEPARATOR;
51
-                }
52
-            }
53
-        }
54
-        else {
55
-            $_firstCharP2 = substr($path2, 0, 1);
56
-            if (strlen($path1)) {
57
-                if (strpos($path2, $path1)===0) {
58
-                    return $path2;
59
-                }
60
-                $_lastCharP1 = substr($path1, -1, 1);
61
-                if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
62
-                    $path1 .= DIRECTORY_SEPARATOR;
63
-                }
64
-            }
65
-            else {
66
-                return $path2;
67
-            }
68
-        }
69
-        return $path1 . $path2;
70
-    }
71
-
72
-    /**
73
-     * Check whether $fileName is a valid file name, return true on success
74
-     *
75
-     * @static
76
-     * @access public
77
-     * @param string $fileName
78
-     * @return boolean
79
-     */
80
-    function checkFileName($fileName)
81
-    {
82
-        if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
83
-            return false;
84
-        }
85
-
86
-        if (preg_match(CKFINDER_REGEX_INVALID_FILE, $fileName)) {
87
-            return false;
88
-        }
89
-
90
-        return true;
91
-    }
92
-
93
-    /**
94
-     * Unlink file/folder
95
-     *
96
-     * @static
97
-     * @access public
98
-     * @param string $path
99
-     * @return boolean
100
-     */
101
-    function unlink($path)
102
-    {
103
-        /*    make sure the path exists    */
104
-        if(!file_exists($path)) {
105
-            return false;
106
-        }
107
-
108
-        /*    If it is a file or link, just delete it    */
109
-        if(is_file($path) || is_link($path)) {
110
-            return @unlink($path);
111
-        }
112
-
113
-        /*    Scan the dir and recursively unlink    */
114
-        $files = CKFinder_Connector_Utils_FileSystem::php4_scandir($path);
115
-        if ($files) {
116
-            foreach($files as $filename)
117
-            {
118
-                if ($filename == '.' || $filename == '..') {
119
-                    continue;
120
-                }
121
-                $file = str_replace('//','/',$path.'/'.$filename);
122
-                CKFinder_Connector_Utils_FileSystem::unlink($file);
123
-            }
124
-        }
125
-
126
-        /*    Remove the parent dir    */
127
-        if(!@rmdir($path)) {
128
-            return false;
129
-        }
130
-
131
-        return true;
132
-    }
133
-
134
-    /**
135
-     * PHP4 Scandir
136
-     * @static
137
-     * @access public
138
-     * @param $directory directory name
139
-    */
140
-    function php4_scandir($directory)
141
-    {
142
-        if (!is_dir($directory) || (false === $fh = @opendir($directory))) {
143
-            return false;
144
-        }
145
-
146
-        $files = array ();
147
-        while (false !== ($filename = readdir($fh))) {
148
-            $files[] = $filename;
149
-        }
150
-
151
-        closedir($fh);
152
-
153
-        return $files;
154
-    }
155
-
156
-    /**
157
-     * Return file name without extension (without dot & last part after dot)
158
-     *
159
-     * @static
160
-     * @access public
161
-     * @param string $fileName
162
-     * @return string
163
-     */
164
-    function getFileNameWithoutExtension($fileName)
165
-    {
166
-        $dotPos = strrpos( $fileName, '.' );
167
-        if (false === $dotPos) {
168
-            return $fileName;
169
-        }
170
-
171
-        return substr($fileName, 0, $dotPos);
172
-    }
173
-
174
-    /**
175
-     * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg)
176
-     *
177
-     * @static
178
-     * @access public
179
-     * @param string $fileName
180
-     * @return string
181
-     */
182
-    function getExtension( $fileName )
183
-    {
184
-        $dotPos = strrpos( $fileName, '.' );
185
-        if (false === $dotPos) {
186
-            return "";
187
-        }
188
-
189
-        return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
190
-    }
191
-
192
-    /**
29
+	/**
30
+	 * This function behaves similar to System.IO.Path.Combine in C#, the only diffrenece is that it also accepts null values and treat them as empty string
31
+	 *
32
+	 * @static
33
+	 * @access public
34
+	 * @param string $path1 first path
35
+	 * @param string $path2 scecond path
36
+	 * @return string
37
+	 */
38
+	function combinePaths($path1, $path2)
39
+	{
40
+		if (is_null($path1))  {
41
+			$path1 = "";
42
+		}
43
+		if (is_null($path2))  {
44
+			$path2 = "";
45
+		}
46
+		if (!strlen($path2)) {
47
+			if (strlen($path1)) {
48
+				$_lastCharP1 = substr($path1, -1, 1);
49
+				if ($_lastCharP1 != "/" && $_lastCharP1 != "\\") {
50
+					$path1 .= DIRECTORY_SEPARATOR;
51
+				}
52
+			}
53
+		}
54
+		else {
55
+			$_firstCharP2 = substr($path2, 0, 1);
56
+			if (strlen($path1)) {
57
+				if (strpos($path2, $path1)===0) {
58
+					return $path2;
59
+				}
60
+				$_lastCharP1 = substr($path1, -1, 1);
61
+				if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
62
+					$path1 .= DIRECTORY_SEPARATOR;
63
+				}
64
+			}
65
+			else {
66
+				return $path2;
67
+			}
68
+		}
69
+		return $path1 . $path2;
70
+	}
71
+
72
+	/**
73
+	 * Check whether $fileName is a valid file name, return true on success
74
+	 *
75
+	 * @static
76
+	 * @access public
77
+	 * @param string $fileName
78
+	 * @return boolean
79
+	 */
80
+	function checkFileName($fileName)
81
+	{
82
+		if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
83
+			return false;
84
+		}
85
+
86
+		if (preg_match(CKFINDER_REGEX_INVALID_FILE, $fileName)) {
87
+			return false;
88
+		}
89
+
90
+		return true;
91
+	}
92
+
93
+	/**
94
+	 * Unlink file/folder
95
+	 *
96
+	 * @static
97
+	 * @access public
98
+	 * @param string $path
99
+	 * @return boolean
100
+	 */
101
+	function unlink($path)
102
+	{
103
+		/*    make sure the path exists    */
104
+		if(!file_exists($path)) {
105
+			return false;
106
+		}
107
+
108
+		/*    If it is a file or link, just delete it    */
109
+		if(is_file($path) || is_link($path)) {
110
+			return @unlink($path);
111
+		}
112
+
113
+		/*    Scan the dir and recursively unlink    */
114
+		$files = CKFinder_Connector_Utils_FileSystem::php4_scandir($path);
115
+		if ($files) {
116
+			foreach($files as $filename)
117
+			{
118
+				if ($filename == '.' || $filename == '..') {
119
+					continue;
120
+				}
121
+				$file = str_replace('//','/',$path.'/'.$filename);
122
+				CKFinder_Connector_Utils_FileSystem::unlink($file);
123
+			}
124
+		}
125
+
126
+		/*    Remove the parent dir    */
127
+		if(!@rmdir($path)) {
128
+			return false;
129
+		}
130
+
131
+		return true;
132
+	}
133
+
134
+	/**
135
+	 * PHP4 Scandir
136
+	 * @static
137
+	 * @access public
138
+	 * @param $directory directory name
139
+	 */
140
+	function php4_scandir($directory)
141
+	{
142
+		if (!is_dir($directory) || (false === $fh = @opendir($directory))) {
143
+			return false;
144
+		}
145
+
146
+		$files = array ();
147
+		while (false !== ($filename = readdir($fh))) {
148
+			$files[] = $filename;
149
+		}
150
+
151
+		closedir($fh);
152
+
153
+		return $files;
154
+	}
155
+
156
+	/**
157
+	 * Return file name without extension (without dot & last part after dot)
158
+	 *
159
+	 * @static
160
+	 * @access public
161
+	 * @param string $fileName
162
+	 * @return string
163
+	 */
164
+	function getFileNameWithoutExtension($fileName)
165
+	{
166
+		$dotPos = strrpos( $fileName, '.' );
167
+		if (false === $dotPos) {
168
+			return $fileName;
169
+		}
170
+
171
+		return substr($fileName, 0, $dotPos);
172
+	}
173
+
174
+	/**
175
+	 * Get file extension (only last part - e.g. extension of file.foo.bar.jpg = jpg)
176
+	 *
177
+	 * @static
178
+	 * @access public
179
+	 * @param string $fileName
180
+	 * @return string
181
+	 */
182
+	function getExtension( $fileName )
183
+	{
184
+		$dotPos = strrpos( $fileName, '.' );
185
+		if (false === $dotPos) {
186
+			return "";
187
+		}
188
+
189
+		return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
190
+	}
191
+
192
+	/**
193 193
 	 * Read file, split it into small chunks and send it to the browser
194 194
 	 *
195
-     * @static
196
-     * @access public
195
+	 * @static
196
+	 * @access public
197 197
 	 * @param string $filename
198 198
 	 * @return boolean
199 199
 	 */
200
-    function readfileChunked($filename)
201
-    {
202
-        $chunksize = 1024 * 10; // how many bytes per chunk
203
-
204
-        $handle = fopen($filename, 'rb');
205
-        if ($handle === false) {
206
-            return false;
207
-        }
208
-        while (!feof($handle)) {
209
-            echo fread($handle, $chunksize);
210
-            @ob_flush();
211
-            flush();
212
-            @set_time_limit(8);
213
-        }
214
-        fclose($handle);
215
-        return true;
216
-    }
217
-
218
-    /**
219
-    * Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents".
220
-    * The purpose of this function is to replace characters commonly found in Latin
221
-    * alphabets with something more or less equivalent from the ASCII range. This can
222
-    * be useful for converting a UTF-8 to something ready for a filename, for example.
223
-    * Following the use of this function, you would probably also pass the string
224
-    * through utf8_strip_non_ascii to clean out any other non-ASCII chars
225
-    *
226
-    * For a more complete implementation of transliteration, see the utf8_to_ascii package
227
-    * available from the phputf8 project downloads:
228
-    * http://prdownloads.sourceforge.net/phputf8
229
-    *
230
-    * @param string UTF-8 string
231
-    * @param string UTF-8 with accented characters replaced by ASCII chars
232
-    * @return string accented chars replaced with ascii equivalents
233
-    * @author Andreas Gohr <[email protected]>
234
-    * @see http://sourceforge.net/projects/phputf8/
235
-    */
236
-    function convertToAscii($str)
237
-    {
238
-        static $UTF8_LOWER_ACCENTS = NULL;
239
-        static $UTF8_UPPER_ACCENTS = NULL;
240
-
241
-        if ( is_null($UTF8_LOWER_ACCENTS) ) {
242
-            $UTF8_LOWER_ACCENTS = array(
200
+	function readfileChunked($filename)
201
+	{
202
+		$chunksize = 1024 * 10; // how many bytes per chunk
203
+
204
+		$handle = fopen($filename, 'rb');
205
+		if ($handle === false) {
206
+			return false;
207
+		}
208
+		while (!feof($handle)) {
209
+			echo fread($handle, $chunksize);
210
+			@ob_flush();
211
+			flush();
212
+			@set_time_limit(8);
213
+		}
214
+		fclose($handle);
215
+		return true;
216
+	}
217
+
218
+	/**
219
+	 * Replace accented UTF-8 characters by unaccented ASCII-7 "equivalents".
220
+	 * The purpose of this function is to replace characters commonly found in Latin
221
+	 * alphabets with something more or less equivalent from the ASCII range. This can
222
+	 * be useful for converting a UTF-8 to something ready for a filename, for example.
223
+	 * Following the use of this function, you would probably also pass the string
224
+	 * through utf8_strip_non_ascii to clean out any other non-ASCII chars
225
+	 *
226
+	 * For a more complete implementation of transliteration, see the utf8_to_ascii package
227
+	 * available from the phputf8 project downloads:
228
+	 * http://prdownloads.sourceforge.net/phputf8
229
+	 *
230
+	 * @param string UTF-8 string
231
+	 * @param string UTF-8 with accented characters replaced by ASCII chars
232
+	 * @return string accented chars replaced with ascii equivalents
233
+	 * @author Andreas Gohr <[email protected]>
234
+	 * @see http://sourceforge.net/projects/phputf8/
235
+	 */
236
+	function convertToAscii($str)
237
+	{
238
+		static $UTF8_LOWER_ACCENTS = NULL;
239
+		static $UTF8_UPPER_ACCENTS = NULL;
240
+
241
+		if ( is_null($UTF8_LOWER_ACCENTS) ) {
242
+			$UTF8_LOWER_ACCENTS = array(
243 243
   'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o',
244 244
   'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k',
245 245
   'ŝ' => 's', 'ỳ' => 'y', 'ņ' => 'n', 'ĺ' => 'l', 'ħ' => 'h', 'ṗ' => 'p', 'ó' => 'o',
@@ -255,17 +255,17 @@  discard block
 block discarded – undo
255 255
   'â' => 'a', 'ľ' => 'l', 'ẅ' => 'w', 'ż' => 'z', 'ī' => 'i', 'ã' => 'a', 'ġ' => 'g',
256 256
   'ṁ' => 'm', 'ō' => 'o', 'ĩ' => 'i', 'ù' => 'u', 'į' => 'i', 'ź' => 'z', 'á' => 'a',
257 257
   'û' => 'u', 'þ' => 'th', 'ð' => 'dh', 'æ' => 'ae', 'µ' => 'u', 'ĕ' => 'e',
258
-            );
259
-        }
258
+			);
259
+		}
260 260
 
261
-        $str = str_replace(
262
-                array_keys($UTF8_LOWER_ACCENTS),
263
-                array_values($UTF8_LOWER_ACCENTS),
264
-                $str
265
-            );
261
+		$str = str_replace(
262
+				array_keys($UTF8_LOWER_ACCENTS),
263
+				array_values($UTF8_LOWER_ACCENTS),
264
+				$str
265
+			);
266 266
 
267
-        if ( is_null($UTF8_UPPER_ACCENTS) ) {
268
-            $UTF8_UPPER_ACCENTS = array(
267
+		if ( is_null($UTF8_UPPER_ACCENTS) ) {
268
+			$UTF8_UPPER_ACCENTS = array(
269 269
   'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O',
270 270
   'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K',
271 271
   'Ŝ' => 'S', 'Ỳ' => 'Y', 'Ņ' => 'N', 'Ĺ' => 'L', 'Ħ' => 'H', 'Ṗ' => 'P', 'Ó' => 'O',
@@ -281,309 +281,309 @@  discard block
 block discarded – undo
281 281
   'Â' => 'A', 'Ľ' => 'L', 'Ẅ' => 'W', 'Ż' => 'Z', 'Ī' => 'I', 'Ã' => 'A', 'Ġ' => 'G',
282 282
   'Ṁ' => 'M', 'Ō' => 'O', 'Ĩ' => 'I', 'Ù' => 'U', 'Į' => 'I', 'Ź' => 'Z', 'Á' => 'A',
283 283
   'Û' => 'U', 'Þ' => 'Th', 'Ð' => 'Dh', 'Æ' => 'Ae', 'Ĕ' => 'E',
284
-            );
285
-        }
286
-        $str = str_replace(
287
-                array_keys($UTF8_UPPER_ACCENTS),
288
-                array_values($UTF8_UPPER_ACCENTS),
289
-                $str
290
-            );
291
-        return $str;
292
-    }
293
-
294
-    /**
295
-     * Convert file name from UTF-8 to system encoding
296
-     *
297
-     * @static
298
-     * @access public
299
-     * @param string $fileName
300
-     * @return string
301
-     */
302
-    function convertToFilesystemEncoding($fileName)
303
-    {
304
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
305
-        $encoding = $_config->getFilesystemEncoding();
306
-        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
307
-            return $fileName;
308
-        }
309
-
310
-        if (!function_exists("iconv")) {
311
-            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
312
-                return str_replace("\0", "_", utf8_decode($fileName));
313
-            } else if (function_exists('mb_convert_encoding')) {
314
-
315
-                $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316
-                if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317
-                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
318
-                }
319
-                else {
320
-                    return str_replace("\0", "_", $encoded);
321
-                }
322
-            } else {
323
-                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
324
-            }
325
-        }
326
-
327
-        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
328
-        if ($converted === false) {
329
-            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
330
-        }
331
-
332
-        return $converted;
333
-    }
334
-
335
-    /**
336
-     * Convert file name from system encoding into UTF-8
337
-     *
338
-     * @static
339
-     * @access public
340
-     * @param string $fileName
341
-     * @return string
342
-     */
343
-    function convertToConnectorEncoding($fileName)
344
-    {
345
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
346
-        $encoding = $_config->getFilesystemEncoding();
347
-        if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
348
-            return $fileName;
349
-        }
350
-
351
-        if (!function_exists("iconv")) {
352
-            if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
353
-                return utf8_encode($fileName);
354
-            } else {
355
-                return $fileName;
356
-            }
357
-        }
358
-
359
-        $converted = @iconv($encoding, "UTF-8", $fileName);
360
-
361
-        if ($converted === false) {
362
-            return $fileName;
363
-        }
364
-
365
-        return $converted;
366
-    }
367
-
368
-    /**
369
-     * Find document root
370
-     *
371
-     * @return string
372
-     * @access public
373
-     */
374
-    function getDocumentRootPath()
375
-    {
376
-        /**
377
-         * The absolute pathname of the currently executing script.
378
-         * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
379
-         * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
380
-         */
381
-        if (isset($_SERVER['SCRIPT_FILENAME'])) {
382
-            $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
383
-        }
384
-        else {
385
-            /**
386
-             * realpath — Returns canonicalized absolute pathname
387
-             */
388
-            $sRealPath = realpath( './' ) ;
389
-        }
390
-
391
-        /**
392
-         * The filename of the currently executing script, relative to the document root.
393
-         * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
394
-         * would be /test.php/foo.bar.
395
-         */
396
-        $sSelfPath = dirname($_SERVER['PHP_SELF']);
397
-
398
-        return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
399
-    }
400
-
401
-    /**
402
-     * Create directory recursively
403
-     *
404
-     * @static
405
-     * @access public
406
-     * @param string $dir
407
-     * @param int $mode
408
-     * @return boolean
409
-     */
410
-    function createDirectoryRecursively($dir)
411
-    {
412
-        if (is_dir($dir)) {
413
-            return true;
414
-        }
415
-
416
-        //attempt to create directory
417
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
418
-        if ($perms = $_config->getChmodFolders()) {
419
-            $oldUmask = umask(0);
420
-            $bCreated = @mkdir($dir, $perms);
421
-            umask($oldUmask);
422
-        }
423
-        else {
424
-            $bCreated = @mkdir($dir);
425
-        }
426
-
427
-        if ($bCreated) {
428
-            return true;
429
-        }
430
-
431
-        //failed to create directory, perhaps we need to create parent directories first
432
-        if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively(dirname($dir))) {
433
-            return false;
434
-        }
435
-
436
-        //parent directories created successfully, let's try to create directory once again
437
-        if ($perms) {
438
-            $old_umask = umask(0);
439
-            $result = @mkdir($dir, $perms);
440
-            umask($old_umask);
441
-        }
442
-        else {
443
-            $result = @mkdir($dir);
444
-        }
445
-
446
-        return $result;
447
-    }
448
-
449
-    /**
450
-     * Detect HTML in the first KB to prevent against potential security issue with
451
-     * IE/Safari/Opera file type auto detection bug.
452
-     * Returns true if file contain insecure HTML code at the beginning.
453
-     *
454
-     * @static
455
-     * @access public
456
-     * @param string $filePath absolute path to file
457
-     * @return boolean
458
-    */
459
-    function detectHtml($filePath)
460
-    {
461
-        $fp = @fopen($filePath, 'rb');
462
-        if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
463
-            return -1 ;
464
-        }
465
-        $chunk = fread($fp, 1024);
466
-        flock( $fp, LOCK_UN ) ;
467
-        fclose($fp);
468
-
469
-        $chunk = strtolower($chunk);
470
-
471
-        if (!$chunk) {
472
-            return false;
473
-        }
474
-
475
-        $chunk = trim($chunk);
476
-
477
-        if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) {
478
-            return true;
479
-        }
480
-
481
-        $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
482
-
483
-        foreach( $tags as $tag ) {
484
-            if(false !== strpos($chunk, $tag)) {
485
-                return true ;
486
-            }
487
-        }
488
-
489
-        //type = javascript
490
-        if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
491
-            return true ;
492
-        }
493
-
494
-        //href = javascript
495
-        //src = javascript
496
-        //data = javascript
497
-        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
498
-            return true ;
499
-        }
500
-
501
-        //url(javascript
502
-        if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
503
-            return true ;
504
-        }
505
-
506
-        return false ;
507
-    }
508
-
509
-    /**
510
-     * Check file content.
511
-     * Currently this function validates only image files.
512
-     * Returns false if file is invalid.
513
-     *
514
-     * @static
515
-     * @access public
516
-     * @param string $filePath absolute path to file
517
-     * @param string $extension file extension
518
-     * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
519
-     * @return boolean
520
-    */
521
-    function isImageValid($filePath, $extension)
522
-    {
523
-        if (!@is_readable($filePath)) {
524
-            return -1;
525
-        }
526
-
527
-        $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
528
-
529
-        // version_compare is available since PHP4 >= 4.0.7
530
-        if ( function_exists( 'version_compare' ) ) {
531
-            $sCurrentVersion = phpversion();
532
-            if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
533
-                $imageCheckExtensions[] = "tiff";
534
-                $imageCheckExtensions[] = "tif";
535
-            }
536
-            if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
537
-                $imageCheckExtensions[] = "swc";
538
-            }
539
-            if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
540
-                $imageCheckExtensions[] = "jpc";
541
-                $imageCheckExtensions[] = "jp2";
542
-                $imageCheckExtensions[] = "jpx";
543
-                $imageCheckExtensions[] = "jb2";
544
-                $imageCheckExtensions[] = "xbm";
545
-                $imageCheckExtensions[] = "wbmp";
546
-            }
547
-        }
548
-
549
-        if ( !in_array( $extension, $imageCheckExtensions ) ) {
550
-            return true;
551
-        }
552
-
553
-        if ( @getimagesize( $filePath ) === false ) {
554
-            return false ;
555
-        }
556
-
557
-        return true;
558
-    }
559
-
560
-    /**
561
-     * Returns true if directory is not empty
562
-     *
563
-     * @access public
564
-     * @static
565
-     * @param string $serverPath
566
-     * @return boolean
567
-     */
568
-    function hasChildren($serverPath)
569
-    {
570
-        if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) {
571
-            return false;
572
-        }
573
-
574
-        $hasChildren = false;
575
-        while (false !== ($filename = readdir($fh))) {
576
-            if ($filename == '.' || $filename == '..') {
577
-                continue;
578
-            } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) {
579
-                //we have found valid directory
580
-                $hasChildren = true;
581
-                break;
582
-            }
583
-        }
584
-
585
-        closedir($fh);
586
-
587
-        return $hasChildren;
588
-    }
284
+			);
285
+		}
286
+		$str = str_replace(
287
+				array_keys($UTF8_UPPER_ACCENTS),
288
+				array_values($UTF8_UPPER_ACCENTS),
289
+				$str
290
+			);
291
+		return $str;
292
+	}
293
+
294
+	/**
295
+	 * Convert file name from UTF-8 to system encoding
296
+	 *
297
+	 * @static
298
+	 * @access public
299
+	 * @param string $fileName
300
+	 * @return string
301
+	 */
302
+	function convertToFilesystemEncoding($fileName)
303
+	{
304
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
305
+		$encoding = $_config->getFilesystemEncoding();
306
+		if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
307
+			return $fileName;
308
+		}
309
+
310
+		if (!function_exists("iconv")) {
311
+			if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
312
+				return str_replace("\0", "_", utf8_decode($fileName));
313
+			} else if (function_exists('mb_convert_encoding')) {
314
+
315
+				$encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316
+				if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317
+					return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
318
+				}
319
+				else {
320
+					return str_replace("\0", "_", $encoded);
321
+				}
322
+			} else {
323
+				return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
324
+			}
325
+		}
326
+
327
+		$converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
328
+		if ($converted === false) {
329
+			return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
330
+		}
331
+
332
+		return $converted;
333
+	}
334
+
335
+	/**
336
+	 * Convert file name from system encoding into UTF-8
337
+	 *
338
+	 * @static
339
+	 * @access public
340
+	 * @param string $fileName
341
+	 * @return string
342
+	 */
343
+	function convertToConnectorEncoding($fileName)
344
+	{
345
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
346
+		$encoding = $_config->getFilesystemEncoding();
347
+		if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
348
+			return $fileName;
349
+		}
350
+
351
+		if (!function_exists("iconv")) {
352
+			if (strcasecmp($encoding, "ISO-8859-1") == 0 || strcasecmp($encoding, "ISO8859-1") == 0 || strcasecmp($encoding, "Latin1") == 0) {
353
+				return utf8_encode($fileName);
354
+			} else {
355
+				return $fileName;
356
+			}
357
+		}
358
+
359
+		$converted = @iconv($encoding, "UTF-8", $fileName);
360
+
361
+		if ($converted === false) {
362
+			return $fileName;
363
+		}
364
+
365
+		return $converted;
366
+	}
367
+
368
+	/**
369
+	 * Find document root
370
+	 *
371
+	 * @return string
372
+	 * @access public
373
+	 */
374
+	function getDocumentRootPath()
375
+	{
376
+		/**
377
+		 * The absolute pathname of the currently executing script.
378
+		 * Notatka: If a script is executed with the CLI, as a relative path, such as file.php or ../file.php,
379
+		 * $_SERVER['SCRIPT_FILENAME'] will contain the relative path specified by the user.
380
+		 */
381
+		if (isset($_SERVER['SCRIPT_FILENAME'])) {
382
+			$sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
383
+		}
384
+		else {
385
+			/**
386
+			 * realpath — Returns canonicalized absolute pathname
387
+			 */
388
+			$sRealPath = realpath( './' ) ;
389
+		}
390
+
391
+		/**
392
+		 * The filename of the currently executing script, relative to the document root.
393
+		 * For instance, $_SERVER['PHP_SELF'] in a script at the address http://example.com/test.php/foo.bar
394
+		 * would be /test.php/foo.bar.
395
+		 */
396
+		$sSelfPath = dirname($_SERVER['PHP_SELF']);
397
+
398
+		return substr($sRealPath, 0, strlen($sRealPath) - strlen($sSelfPath));
399
+	}
400
+
401
+	/**
402
+	 * Create directory recursively
403
+	 *
404
+	 * @static
405
+	 * @access public
406
+	 * @param string $dir
407
+	 * @param int $mode
408
+	 * @return boolean
409
+	 */
410
+	function createDirectoryRecursively($dir)
411
+	{
412
+		if (is_dir($dir)) {
413
+			return true;
414
+		}
415
+
416
+		//attempt to create directory
417
+		$_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
418
+		if ($perms = $_config->getChmodFolders()) {
419
+			$oldUmask = umask(0);
420
+			$bCreated = @mkdir($dir, $perms);
421
+			umask($oldUmask);
422
+		}
423
+		else {
424
+			$bCreated = @mkdir($dir);
425
+		}
426
+
427
+		if ($bCreated) {
428
+			return true;
429
+		}
430
+
431
+		//failed to create directory, perhaps we need to create parent directories first
432
+		if (!CKFinder_Connector_Utils_FileSystem::createDirectoryRecursively(dirname($dir))) {
433
+			return false;
434
+		}
435
+
436
+		//parent directories created successfully, let's try to create directory once again
437
+		if ($perms) {
438
+			$old_umask = umask(0);
439
+			$result = @mkdir($dir, $perms);
440
+			umask($old_umask);
441
+		}
442
+		else {
443
+			$result = @mkdir($dir);
444
+		}
445
+
446
+		return $result;
447
+	}
448
+
449
+	/**
450
+	 * Detect HTML in the first KB to prevent against potential security issue with
451
+	 * IE/Safari/Opera file type auto detection bug.
452
+	 * Returns true if file contain insecure HTML code at the beginning.
453
+	 *
454
+	 * @static
455
+	 * @access public
456
+	 * @param string $filePath absolute path to file
457
+	 * @return boolean
458
+	 */
459
+	function detectHtml($filePath)
460
+	{
461
+		$fp = @fopen($filePath, 'rb');
462
+		if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
463
+			return -1 ;
464
+		}
465
+		$chunk = fread($fp, 1024);
466
+		flock( $fp, LOCK_UN ) ;
467
+		fclose($fp);
468
+
469
+		$chunk = strtolower($chunk);
470
+
471
+		if (!$chunk) {
472
+			return false;
473
+		}
474
+
475
+		$chunk = trim($chunk);
476
+
477
+		if (preg_match("/<!DOCTYPE\W*X?HTML/sim", $chunk)) {
478
+			return true;
479
+		}
480
+
481
+		$tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
482
+
483
+		foreach( $tags as $tag ) {
484
+			if(false !== strpos($chunk, $tag)) {
485
+				return true ;
486
+			}
487
+		}
488
+
489
+		//type = javascript
490
+		if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
491
+			return true ;
492
+		}
493
+
494
+		//href = javascript
495
+		//src = javascript
496
+		//data = javascript
497
+		if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
498
+			return true ;
499
+		}
500
+
501
+		//url(javascript
502
+		if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
503
+			return true ;
504
+		}
505
+
506
+		return false ;
507
+	}
508
+
509
+	/**
510
+	 * Check file content.
511
+	 * Currently this function validates only image files.
512
+	 * Returns false if file is invalid.
513
+	 *
514
+	 * @static
515
+	 * @access public
516
+	 * @param string $filePath absolute path to file
517
+	 * @param string $extension file extension
518
+	 * @param integer $detectionLevel 0 = none, 1 = use getimagesize for images, 2 = use DetectHtml for images
519
+	 * @return boolean
520
+	 */
521
+	function isImageValid($filePath, $extension)
522
+	{
523
+		if (!@is_readable($filePath)) {
524
+			return -1;
525
+		}
526
+
527
+		$imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
528
+
529
+		// version_compare is available since PHP4 >= 4.0.7
530
+		if ( function_exists( 'version_compare' ) ) {
531
+			$sCurrentVersion = phpversion();
532
+			if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
533
+				$imageCheckExtensions[] = "tiff";
534
+				$imageCheckExtensions[] = "tif";
535
+			}
536
+			if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
537
+				$imageCheckExtensions[] = "swc";
538
+			}
539
+			if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
540
+				$imageCheckExtensions[] = "jpc";
541
+				$imageCheckExtensions[] = "jp2";
542
+				$imageCheckExtensions[] = "jpx";
543
+				$imageCheckExtensions[] = "jb2";
544
+				$imageCheckExtensions[] = "xbm";
545
+				$imageCheckExtensions[] = "wbmp";
546
+			}
547
+		}
548
+
549
+		if ( !in_array( $extension, $imageCheckExtensions ) ) {
550
+			return true;
551
+		}
552
+
553
+		if ( @getimagesize( $filePath ) === false ) {
554
+			return false ;
555
+		}
556
+
557
+		return true;
558
+	}
559
+
560
+	/**
561
+	 * Returns true if directory is not empty
562
+	 *
563
+	 * @access public
564
+	 * @static
565
+	 * @param string $serverPath
566
+	 * @return boolean
567
+	 */
568
+	function hasChildren($serverPath)
569
+	{
570
+		if (!is_dir($serverPath) || (false === $fh = @opendir($serverPath))) {
571
+			return false;
572
+		}
573
+
574
+		$hasChildren = false;
575
+		while (false !== ($filename = readdir($fh))) {
576
+			if ($filename == '.' || $filename == '..') {
577
+				continue;
578
+			} else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) {
579
+				//we have found valid directory
580
+				$hasChildren = true;
581
+				break;
582
+			}
583
+		}
584
+
585
+		closedir($fh);
586
+
587
+		return $hasChildren;
588
+	}
589 589
 }
Please login to merge, or discard this patch.
Spacing   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -37,10 +37,10 @@  discard block
 block discarded – undo
37 37
      */
38 38
     function combinePaths($path1, $path2)
39 39
     {
40
-        if (is_null($path1))  {
40
+        if (is_null($path1)) {
41 41
             $path1 = "";
42 42
         }
43
-        if (is_null($path2))  {
43
+        if (is_null($path2)) {
44 44
             $path2 = "";
45 45
         }
46 46
         if (!strlen($path2)) {
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         else {
55 55
             $_firstCharP2 = substr($path2, 0, 1);
56 56
             if (strlen($path1)) {
57
-                if (strpos($path2, $path1)===0) {
57
+                if (strpos($path2, $path1) === 0) {
58 58
                     return $path2;
59 59
                 }
60 60
                 $_lastCharP1 = substr($path1, -1, 1);
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
                 return $path2;
67 67
             }
68 68
         }
69
-        return $path1 . $path2;
69
+        return $path1.$path2;
70 70
     }
71 71
 
72 72
     /**
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
      */
80 80
     function checkFileName($fileName)
81 81
     {
82
-        if (is_null($fileName) || !strlen($fileName) || substr($fileName,-1,1)=="." || false!==strpos($fileName, "..")) {
82
+        if (is_null($fileName) || !strlen($fileName) || substr($fileName, -1, 1) == "." || false !== strpos($fileName, "..")) {
83 83
             return false;
84 84
         }
85 85
 
@@ -101,30 +101,30 @@  discard block
 block discarded – undo
101 101
     function unlink($path)
102 102
     {
103 103
         /*    make sure the path exists    */
104
-        if(!file_exists($path)) {
104
+        if (!file_exists($path)) {
105 105
             return false;
106 106
         }
107 107
 
108 108
         /*    If it is a file or link, just delete it    */
109
-        if(is_file($path) || is_link($path)) {
109
+        if (is_file($path) || is_link($path)) {
110 110
             return @unlink($path);
111 111
         }
112 112
 
113 113
         /*    Scan the dir and recursively unlink    */
114 114
         $files = CKFinder_Connector_Utils_FileSystem::php4_scandir($path);
115 115
         if ($files) {
116
-            foreach($files as $filename)
116
+            foreach ($files as $filename)
117 117
             {
118 118
                 if ($filename == '.' || $filename == '..') {
119 119
                     continue;
120 120
                 }
121
-                $file = str_replace('//','/',$path.'/'.$filename);
121
+                $file = str_replace('//', '/', $path.'/'.$filename);
122 122
                 CKFinder_Connector_Utils_FileSystem::unlink($file);
123 123
             }
124 124
         }
125 125
 
126 126
         /*    Remove the parent dir    */
127
-        if(!@rmdir($path)) {
127
+        if (!@rmdir($path)) {
128 128
             return false;
129 129
         }
130 130
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
             return false;
144 144
         }
145 145
 
146
-        $files = array ();
146
+        $files = array();
147 147
         while (false !== ($filename = readdir($fh))) {
148 148
             $files[] = $filename;
149 149
         }
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      */
164 164
     function getFileNameWithoutExtension($fileName)
165 165
     {
166
-        $dotPos = strrpos( $fileName, '.' );
166
+        $dotPos = strrpos($fileName, '.');
167 167
         if (false === $dotPos) {
168 168
             return $fileName;
169 169
         }
@@ -179,14 +179,14 @@  discard block
 block discarded – undo
179 179
      * @param string $fileName
180 180
      * @return string
181 181
      */
182
-    function getExtension( $fileName )
182
+    function getExtension($fileName)
183 183
     {
184
-        $dotPos = strrpos( $fileName, '.' );
184
+        $dotPos = strrpos($fileName, '.');
185 185
         if (false === $dotPos) {
186 186
             return "";
187 187
         }
188 188
 
189
-        return substr( $fileName, strrpos( $fileName, '.' ) +1 ) ;
189
+        return substr($fileName, strrpos($fileName, '.') + 1);
190 190
     }
191 191
 
192 192
     /**
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
         static $UTF8_LOWER_ACCENTS = NULL;
239 239
         static $UTF8_UPPER_ACCENTS = NULL;
240 240
 
241
-        if ( is_null($UTF8_LOWER_ACCENTS) ) {
241
+        if (is_null($UTF8_LOWER_ACCENTS)) {
242 242
             $UTF8_LOWER_ACCENTS = array(
243 243
   'à' => 'a', 'ô' => 'o', 'ď' => 'd', 'ḟ' => 'f', 'ë' => 'e', 'š' => 's', 'ơ' => 'o',
244 244
   'ß' => 'ss', 'ă' => 'a', 'ř' => 'r', 'ț' => 't', 'ň' => 'n', 'ā' => 'a', 'ķ' => 'k',
@@ -264,7 +264,7 @@  discard block
 block discarded – undo
264 264
                 $str
265 265
             );
266 266
 
267
-        if ( is_null($UTF8_UPPER_ACCENTS) ) {
267
+        if (is_null($UTF8_UPPER_ACCENTS)) {
268 268
             $UTF8_UPPER_ACCENTS = array(
269 269
   'À' => 'A', 'Ô' => 'O', 'Ď' => 'D', 'Ḟ' => 'F', 'Ë' => 'E', 'Š' => 'S', 'Ơ' => 'O',
270 270
   'Ă' => 'A', 'Ř' => 'R', 'Ț' => 'T', 'Ň' => 'N', 'Ā' => 'A', 'Ķ' => 'K',
@@ -301,7 +301,7 @@  discard block
 block discarded – undo
301 301
      */
302 302
     function convertToFilesystemEncoding($fileName)
303 303
     {
304
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
304
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
305 305
         $encoding = $_config->getFilesystemEncoding();
306 306
         if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
307 307
             return $fileName;
@@ -314,19 +314,19 @@  discard block
 block discarded – undo
314 314
 
315 315
                 $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316 316
                 if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317
-                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
317
+                    return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName));
318 318
                 }
319 319
                 else {
320 320
                     return str_replace("\0", "_", $encoded);
321 321
                 }
322 322
             } else {
323
-                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
323
+                return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName));
324 324
             }
325 325
         }
326 326
 
327
-        $converted = @iconv("UTF-8", $encoding . "//IGNORE//TRANSLIT", $fileName);
327
+        $converted = @iconv("UTF-8", $encoding."//IGNORE//TRANSLIT", $fileName);
328 328
         if ($converted === false) {
329
-            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
329
+            return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u", "_", $fileName));
330 330
         }
331 331
 
332 332
         return $converted;
@@ -342,7 +342,7 @@  discard block
 block discarded – undo
342 342
      */
343 343
     function convertToConnectorEncoding($fileName)
344 344
     {
345
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
345
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
346 346
         $encoding = $_config->getFilesystemEncoding();
347 347
         if (is_null($encoding) || strcasecmp($encoding, "UTF-8") == 0 || strcasecmp($encoding, "UTF8") == 0) {
348 348
             return $fileName;
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
             /**
386 386
              * realpath — Returns canonicalized absolute pathname
387 387
              */
388
-            $sRealPath = realpath( './' ) ;
388
+            $sRealPath = realpath('./');
389 389
         }
390 390
 
391 391
         /**
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
         }
415 415
 
416 416
         //attempt to create directory
417
-        $_config =& CKFinder_Connector_Core_Factory::getInstance("Core_Config");
417
+        $_config = & CKFinder_Connector_Core_Factory::getInstance("Core_Config");
418 418
         if ($perms = $_config->getChmodFolders()) {
419 419
             $oldUmask = umask(0);
420 420
             $bCreated = @mkdir($dir, $perms);
@@ -459,11 +459,11 @@  discard block
 block discarded – undo
459 459
     function detectHtml($filePath)
460 460
     {
461 461
         $fp = @fopen($filePath, 'rb');
462
-        if ( $fp === false || !flock( $fp, LOCK_SH ) ) {
463
-            return -1 ;
462
+        if ($fp === false || !flock($fp, LOCK_SH)) {
463
+            return -1;
464 464
         }
465 465
         $chunk = fread($fp, 1024);
466
-        flock( $fp, LOCK_UN ) ;
466
+        flock($fp, LOCK_UN);
467 467
         fclose($fp);
468 468
 
469 469
         $chunk = strtolower($chunk);
@@ -480,30 +480,30 @@  discard block
 block discarded – undo
480 480
 
481 481
         $tags = array('<body', '<head', '<html', '<img', '<pre', '<script', '<table', '<title');
482 482
 
483
-        foreach( $tags as $tag ) {
484
-            if(false !== strpos($chunk, $tag)) {
485
-                return true ;
483
+        foreach ($tags as $tag) {
484
+            if (false !== strpos($chunk, $tag)) {
485
+                return true;
486 486
             }
487 487
         }
488 488
 
489 489
         //type = javascript
490 490
         if (preg_match('!type\s*=\s*[\'"]?\s*(?:\w*/)?(?:ecma|java)!sim', $chunk)) {
491
-            return true ;
491
+            return true;
492 492
         }
493 493
 
494 494
         //href = javascript
495 495
         //src = javascript
496 496
         //data = javascript
497
-        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim',$chunk)) {
498
-            return true ;
497
+        if (preg_match('!(?:href|src|data)\s*=\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
498
+            return true;
499 499
         }
500 500
 
501 501
         //url(javascript
502 502
         if (preg_match('!url\s*\(\s*[\'"]?\s*(?:ecma|java)script:!sim', $chunk)) {
503
-            return true ;
503
+            return true;
504 504
         }
505 505
 
506
-        return false ;
506
+        return false;
507 507
     }
508 508
 
509 509
     /**
@@ -527,16 +527,16 @@  discard block
 block discarded – undo
527 527
         $imageCheckExtensions = array('gif', 'jpeg', 'jpg', 'png', 'psd', 'bmp', 'tiff');
528 528
 
529 529
         // version_compare is available since PHP4 >= 4.0.7
530
-        if ( function_exists( 'version_compare' ) ) {
530
+        if (function_exists('version_compare')) {
531 531
             $sCurrentVersion = phpversion();
532
-            if ( version_compare( $sCurrentVersion, "4.2.0" ) >= 0 ) {
532
+            if (version_compare($sCurrentVersion, "4.2.0") >= 0) {
533 533
                 $imageCheckExtensions[] = "tiff";
534 534
                 $imageCheckExtensions[] = "tif";
535 535
             }
536
-            if ( version_compare( $sCurrentVersion, "4.3.0" ) >= 0 ) {
536
+            if (version_compare($sCurrentVersion, "4.3.0") >= 0) {
537 537
                 $imageCheckExtensions[] = "swc";
538 538
             }
539
-            if ( version_compare( $sCurrentVersion, "4.3.2" ) >= 0 ) {
539
+            if (version_compare($sCurrentVersion, "4.3.2") >= 0) {
540 540
                 $imageCheckExtensions[] = "jpc";
541 541
                 $imageCheckExtensions[] = "jp2";
542 542
                 $imageCheckExtensions[] = "jpx";
@@ -546,12 +546,12 @@  discard block
 block discarded – undo
546 546
             }
547 547
         }
548 548
 
549
-        if ( !in_array( $extension, $imageCheckExtensions ) ) {
549
+        if (!in_array($extension, $imageCheckExtensions)) {
550 550
             return true;
551 551
         }
552 552
 
553
-        if ( @getimagesize( $filePath ) === false ) {
554
-            return false ;
553
+        if (@getimagesize($filePath) === false) {
554
+            return false;
555 555
         }
556 556
 
557 557
         return true;
@@ -575,7 +575,7 @@  discard block
 block discarded – undo
575 575
         while (false !== ($filename = readdir($fh))) {
576 576
             if ($filename == '.' || $filename == '..') {
577 577
                 continue;
578
-            } else if (is_dir($serverPath . DIRECTORY_SEPARATOR . $filename)) {
578
+            } else if (is_dir($serverPath.DIRECTORY_SEPARATOR.$filename)) {
579 579
                 //we have found valid directory
580 580
                 $hasChildren = true;
581 581
                 break;
Please login to merge, or discard this patch.
Braces   +9 added lines, -13 removed lines patch added patch discarded remove patch
@@ -10,7 +10,9 @@  discard block
 block discarded – undo
10 10
 * modifying or distribute this file or part of its contents. The contents of
11 11
 * this file is part of the Source Code of CKFinder.
12 12
 */
13
-if (!defined('IN_CKFINDER')) exit;
13
+if (!defined('IN_CKFINDER')) {
14
+	exit;
15
+}
14 16
 
15 17
 /**
16 18
  * @package CKFinder
@@ -50,8 +52,7 @@  discard block
 block discarded – undo
50 52
                     $path1 .= DIRECTORY_SEPARATOR;
51 53
                 }
52 54
             }
53
-        }
54
-        else {
55
+        } else {
55 56
             $_firstCharP2 = substr($path2, 0, 1);
56 57
             if (strlen($path1)) {
57 58
                 if (strpos($path2, $path1)===0) {
@@ -61,8 +62,7 @@  discard block
 block discarded – undo
61 62
                 if ($_lastCharP1 != "/" && $_lastCharP1 != "\\" && $_firstCharP2 != "/" && $_firstCharP2 != "\\") {
62 63
                     $path1 .= DIRECTORY_SEPARATOR;
63 64
                 }
64
-            }
65
-            else {
65
+            } else {
66 66
                 return $path2;
67 67
             }
68 68
         }
@@ -315,8 +315,7 @@  discard block
 block discarded – undo
315 315
                 $encoded = @mb_convert_encoding($fileName, $encoding, 'UTF-8');
316 316
                 if (@mb_strlen($fileName, "UTF-8") != @mb_strlen($encoded, $encoding)) {
317 317
                     return str_replace("\0", "_", preg_replace("/[^[:ascii:]]/u","_",$fileName));
318
-                }
319
-                else {
318
+                } else {
320 319
                     return str_replace("\0", "_", $encoded);
321 320
                 }
322 321
             } else {
@@ -380,8 +379,7 @@  discard block
 block discarded – undo
380 379
          */
381 380
         if (isset($_SERVER['SCRIPT_FILENAME'])) {
382 381
             $sRealPath = dirname($_SERVER['SCRIPT_FILENAME']);
383
-        }
384
-        else {
382
+        } else {
385 383
             /**
386 384
              * realpath — Returns canonicalized absolute pathname
387 385
              */
@@ -419,8 +417,7 @@  discard block
 block discarded – undo
419 417
             $oldUmask = umask(0);
420 418
             $bCreated = @mkdir($dir, $perms);
421 419
             umask($oldUmask);
422
-        }
423
-        else {
420
+        } else {
424 421
             $bCreated = @mkdir($dir);
425 422
         }
426 423
 
@@ -438,8 +435,7 @@  discard block
 block discarded – undo
438 435
             $old_umask = umask(0);
439 436
             $result = @mkdir($dir, $perms);
440 437
             umask($old_umask);
441
-        }
442
-        else {
438
+        } else {
443 439
             $result = @mkdir($dir);
444 440
         }
445 441
 
Please login to merge, or discard this patch.