Completed
Push — master ( 323572...565410 )
by cam
04:16
created
ecrire/inc/documents.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
  * @uses _DIR_IMG
44 44
  *
45 45
  * @param string $fichier
46
- * @return bool|string
46
+ * @return string|false
47 47
  */
48 48
 function get_spip_doc($fichier) {
49 49
 	// fichier distant
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
  * @param string $orig
131 131
  * @param string $source
132 132
  * @param string $subdir
133
- * @return bool|mixed|string
133
+ * @return string|false
134 134
  */
135 135
 function copier_document($ext, $orig, $source, $subdir = null) {
136 136
 
@@ -167,7 +167,7 @@  discard block
 block discarded – undo
167 167
  * @uses sous_repertoire()
168 168
  *
169 169
  * @param string $type
170
- * @return bool|string
170
+ * @return string
171 171
  */
172 172
 function determine_upload($type = '') {
173 173
 	if (!function_exists('autoriser')) {
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
  * @param bool $move
208 208
  *     - `true` : on déplace le fichier source vers le fichier de destination
209 209
  *     - `false` : valeur par défaut. On ne fait que copier le fichier source vers la destination.
210
- * @return bool|mixed|string
210
+ * @return string|false
211 211
  */
212 212
 function deplacer_fichier_upload($source, $dest, $move = false) {
213 213
 	// Securite
Please login to merge, or discard this patch.
Indentation   +173 added lines, -173 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
  */
18 18
 
19 19
 if (!defined('_ECRIRE_INC_VERSION')) {
20
-	return;
20
+    return;
21 21
 }
22 22
 
23 23
 /**
@@ -30,11 +30,11 @@  discard block
 block discarded – undo
30 30
  * @return string
31 31
  */
32 32
 function set_spip_doc($fichier) {
33
-	if (strpos($fichier, _DIR_IMG) === 0) {
34
-		return substr($fichier, strlen(_DIR_IMG));
35
-	} else {
36
-		return $fichier;
37
-	} // ex: fichier distant
33
+    if (strpos($fichier, _DIR_IMG) === 0) {
34
+        return substr($fichier, strlen(_DIR_IMG));
35
+    } else {
36
+        return $fichier;
37
+    } // ex: fichier distant
38 38
 }
39 39
 
40 40
 /**
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
  * @return bool|string
47 47
  */
48 48
 function get_spip_doc($fichier) {
49
-	// fichier distant
50
-	if (tester_url_absolue($fichier)) {
51
-		return $fichier;
52
-	}
53
-
54
-	// gestion d'erreurs, fichier=''
55
-	if (!strlen($fichier)) {
56
-		return false;
57
-	}
58
-
59
-	$fichier = (
60
-		strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0
61
-	)
62
-		? _DIR_IMG . $fichier
63
-		: $fichier;
64
-
65
-	// fichier normal
66
-	return $fichier;
49
+    // fichier distant
50
+    if (tester_url_absolue($fichier)) {
51
+        return $fichier;
52
+    }
53
+
54
+    // gestion d'erreurs, fichier=''
55
+    if (!strlen($fichier)) {
56
+        return false;
57
+    }
58
+
59
+    $fichier = (
60
+        strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) != 0
61
+    )
62
+        ? _DIR_IMG . $fichier
63
+        : $fichier;
64
+
65
+    // fichier normal
66
+    return $fichier;
67 67
 }
68 68
 
69 69
 /**
@@ -77,24 +77,24 @@  discard block
 block discarded – undo
77 77
  * @return string
78 78
  */
79 79
 function creer_repertoire_documents($ext) {
80
-	$rep = sous_repertoire(_DIR_IMG, $ext);
81
-
82
-	if (!$ext or !$rep) {
83
-		spip_log("creer_repertoire_documents '$rep' interdit");
84
-		exit;
85
-	}
86
-
87
-	// Cette variable de configuration peut etre posee par un plugin
88
-	// par exemple acces_restreint
89
-	// sauf pour logo/ utilise pour stocker les logoon et logooff
90
-	if (isset($GLOBALS['meta']["creer_htaccess"])
91
-		and $GLOBALS['meta']["creer_htaccess"] == 'oui'
92
-	  and $ext !== 'logo') {
93
-		include_spip('inc/acces');
94
-		verifier_htaccess($rep);
95
-	}
96
-
97
-	return $rep;
80
+    $rep = sous_repertoire(_DIR_IMG, $ext);
81
+
82
+    if (!$ext or !$rep) {
83
+        spip_log("creer_repertoire_documents '$rep' interdit");
84
+        exit;
85
+    }
86
+
87
+    // Cette variable de configuration peut etre posee par un plugin
88
+    // par exemple acces_restreint
89
+    // sauf pour logo/ utilise pour stocker les logoon et logooff
90
+    if (isset($GLOBALS['meta']["creer_htaccess"])
91
+        and $GLOBALS['meta']["creer_htaccess"] == 'oui'
92
+      and $ext !== 'logo') {
93
+        include_spip('inc/acces');
94
+        verifier_htaccess($rep);
95
+    }
96
+
97
+    return $rep;
98 98
 }
99 99
 
100 100
 /**
@@ -103,21 +103,21 @@  discard block
 block discarded – undo
103 103
  * @param string $nom
104 104
  */
105 105
 function effacer_repertoire_temporaire($nom) {
106
-	if ($d = opendir($nom)) {
107
-		while (($f = readdir($d)) !== false) {
108
-			if (is_file("$nom/$f")) {
109
-				spip_unlink("$nom/$f");
110
-			} else {
111
-				if ($f <> '.' and $f <> '..'
112
-					and is_dir("$nom/$f")
113
-				) {
114
-					effacer_repertoire_temporaire("$nom/$f");
115
-				}
116
-			}
117
-		}
118
-	}
119
-	closedir($d);
120
-	@rmdir($nom);
106
+    if ($d = opendir($nom)) {
107
+        while (($f = readdir($d)) !== false) {
108
+            if (is_file("$nom/$f")) {
109
+                spip_unlink("$nom/$f");
110
+            } else {
111
+                if ($f <> '.' and $f <> '..'
112
+                    and is_dir("$nom/$f")
113
+                ) {
114
+                    effacer_repertoire_temporaire("$nom/$f");
115
+                }
116
+            }
117
+        }
118
+    }
119
+    closedir($d);
120
+    @rmdir($nom);
121 121
 }
122 122
 
123 123
 //
@@ -134,28 +134,28 @@  discard block
 block discarded – undo
134 134
  */
135 135
 function copier_document($ext, $orig, $source, $subdir = null) {
136 136
 
137
-	$orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
138
-	$dir = creer_repertoire_documents($subdir ? $subdir : $ext);
139
-	$dest = preg_replace("/[^.=\w-]+/", "_",
140
-		translitteration(preg_replace("/\.([^.]+)$/", "",
141
-			preg_replace("/<[^>]*>/", '', basename($orig)))));
137
+    $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc
138
+    $dir = creer_repertoire_documents($subdir ? $subdir : $ext);
139
+    $dest = preg_replace("/[^.=\w-]+/", "_",
140
+        translitteration(preg_replace("/\.([^.]+)$/", "",
141
+            preg_replace("/<[^>]*>/", '', basename($orig)))));
142 142
 
143
-	// ne pas accepter de noms de la forme -r90.jpg qui sont reserves
144
-	// pour les images transformees par rotation (action/documenter)
145
-	$dest = preg_replace(',-r(90|180|270)$,', '', $dest);
143
+    // ne pas accepter de noms de la forme -r90.jpg qui sont reserves
144
+    // pour les images transformees par rotation (action/documenter)
145
+    $dest = preg_replace(',-r(90|180|270)$,', '', $dest);
146 146
 
147
-	// Si le document "source" est deja au bon endroit, ne rien faire
148
-	if ($source == ($dir . $dest . '.' . $ext)) {
149
-		return $source;
150
-	}
147
+    // Si le document "source" est deja au bon endroit, ne rien faire
148
+    if ($source == ($dir . $dest . '.' . $ext)) {
149
+        return $source;
150
+    }
151 151
 
152
-	// sinon tourner jusqu'a trouver un numero correct
153
-	$n = 0;
154
-	while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
155
-		;
156
-	}
152
+    // sinon tourner jusqu'a trouver un numero correct
153
+    $n = 0;
154
+    while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) {
155
+        ;
156
+    }
157 157
 
158
-	return deplacer_fichier_upload($source, $newFile);
158
+    return deplacer_fichier_upload($source, $newFile);
159 159
 }
160 160
 
161 161
 /**
@@ -170,28 +170,28 @@  discard block
 block discarded – undo
170 170
  * @return bool|string
171 171
  */
172 172
 function determine_upload($type = '') {
173
-	if (!function_exists('autoriser')) {
174
-		include_spip('inc/autoriser');
175
-	}
176
-
177
-	if (!autoriser('chargerftp')
178
-		or $type == 'logos'
179
-	) # on ne le permet pas pour les logos
180
-	{
181
-		return false;
182
-	}
183
-
184
-	$repertoire = _DIR_TRANSFERT;
185
-	if (!@is_dir($repertoire)) {
186
-		$repertoire = str_replace(_DIR_TMP, '', $repertoire);
187
-		$repertoire = sous_repertoire(_DIR_TMP, $repertoire);
188
-	}
189
-
190
-	if (!$GLOBALS['visiteur_session']['restreint']) {
191
-		return $repertoire;
192
-	} else {
193
-		return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
194
-	}
173
+    if (!function_exists('autoriser')) {
174
+        include_spip('inc/autoriser');
175
+    }
176
+
177
+    if (!autoriser('chargerftp')
178
+        or $type == 'logos'
179
+    ) # on ne le permet pas pour les logos
180
+    {
181
+        return false;
182
+    }
183
+
184
+    $repertoire = _DIR_TRANSFERT;
185
+    if (!@is_dir($repertoire)) {
186
+        $repertoire = str_replace(_DIR_TMP, '', $repertoire);
187
+        $repertoire = sous_repertoire(_DIR_TMP, $repertoire);
188
+    }
189
+
190
+    if (!$GLOBALS['visiteur_session']['restreint']) {
191
+        return $repertoire;
192
+    } else {
193
+        return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']);
194
+    }
195 195
 }
196 196
 
197 197
 /**
@@ -210,35 +210,35 @@  discard block
 block discarded – undo
210 210
  * @return bool|mixed|string
211 211
  */
212 212
 function deplacer_fichier_upload($source, $dest, $move = false) {
213
-	// Securite
214
-	if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
215
-		$dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
216
-	} else {
217
-		$dest = preg_replace(',\.\.+,', '.', $dest);
218
-	}
219
-
220
-	if ($move) {
221
-		$ok = @rename($source, $dest);
222
-	} else {
223
-		$ok = @copy($source, $dest);
224
-	}
225
-	if (!$ok) {
226
-		$ok = @move_uploaded_file($source, $dest);
227
-	}
228
-	if ($ok) {
229
-		@chmod($dest, _SPIP_CHMOD & ~0111);
230
-	} else {
231
-		$f = @fopen($dest, 'w');
232
-		if ($f) {
233
-			fclose($f);
234
-		} else {
235
-			include_spip('inc/flock');
236
-			raler_fichier($dest);
237
-		}
238
-		spip_unlink($dest);
239
-	}
240
-
241
-	return $ok ? $dest : false;
213
+    // Securite
214
+    if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) {
215
+        $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE)));
216
+    } else {
217
+        $dest = preg_replace(',\.\.+,', '.', $dest);
218
+    }
219
+
220
+    if ($move) {
221
+        $ok = @rename($source, $dest);
222
+    } else {
223
+        $ok = @copy($source, $dest);
224
+    }
225
+    if (!$ok) {
226
+        $ok = @move_uploaded_file($source, $dest);
227
+    }
228
+    if ($ok) {
229
+        @chmod($dest, _SPIP_CHMOD & ~0111);
230
+    } else {
231
+        $f = @fopen($dest, 'w');
232
+        if ($f) {
233
+            fclose($f);
234
+        } else {
235
+            include_spip('inc/flock');
236
+            raler_fichier($dest);
237
+        }
238
+        spip_unlink($dest);
239
+    }
240
+
241
+    return $ok ? $dest : false;
242 242
 }
243 243
 
244 244
 
@@ -262,51 +262,51 @@  discard block
 block discarded – undo
262 262
  */
263 263
 function check_upload_error($error, $msg = '', $return = false) {
264 264
 
265
-	if (!$error) {
266
-		return false;
267
-	}
268
-
269
-	spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
270
-
271
-	switch ($error) {
272
-
273
-		case 4: /* UPLOAD_ERR_NO_FILE */
274
-			return true;
275
-
276
-		# on peut affiner les differents messages d'erreur
277
-		case 1: /* UPLOAD_ERR_INI_SIZE */
278
-			$msg = _T('upload_limit',
279
-				array('max' => ini_get('upload_max_filesize')));
280
-			break;
281
-		case 2: /* UPLOAD_ERR_FORM_SIZE */
282
-			$msg = _T('upload_limit',
283
-				array('max' => ini_get('upload_max_filesize')));
284
-			break;
285
-		case 3: /* UPLOAD_ERR_PARTIAL  */
286
-			$msg = _T('upload_limit',
287
-				array('max' => ini_get('upload_max_filesize')));
288
-			break;
289
-
290
-		default: /* autre */
291
-			if (!$msg) {
292
-				$msg = _T('pass_erreur') . ' ' . $error
293
-					. '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
294
-			}
295
-			break;
296
-	}
297
-
298
-	spip_log("erreur upload $error");
299
-	if ($return) {
300
-		return $msg;
301
-	}
302
-
303
-	if (_request("iframe") == "iframe") {
304
-		echo "<div class='upload_answer upload_error'>$msg</div>";
305
-		exit;
306
-	}
307
-
308
-	include_spip('inc/minipres');
309
-	echo minipres($msg,
310
-		"<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>");
311
-	exit;
265
+    if (!$error) {
266
+        return false;
267
+    }
268
+
269
+    spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php");
270
+
271
+    switch ($error) {
272
+
273
+        case 4: /* UPLOAD_ERR_NO_FILE */
274
+            return true;
275
+
276
+        # on peut affiner les differents messages d'erreur
277
+        case 1: /* UPLOAD_ERR_INI_SIZE */
278
+            $msg = _T('upload_limit',
279
+                array('max' => ini_get('upload_max_filesize')));
280
+            break;
281
+        case 2: /* UPLOAD_ERR_FORM_SIZE */
282
+            $msg = _T('upload_limit',
283
+                array('max' => ini_get('upload_max_filesize')));
284
+            break;
285
+        case 3: /* UPLOAD_ERR_PARTIAL  */
286
+            $msg = _T('upload_limit',
287
+                array('max' => ini_get('upload_max_filesize')));
288
+            break;
289
+
290
+        default: /* autre */
291
+            if (!$msg) {
292
+                $msg = _T('pass_erreur') . ' ' . $error
293
+                    . '<br />' . propre("[->http://php.net/manual/fr/features.file-upload.errors.php]");
294
+            }
295
+            break;
296
+    }
297
+
298
+    spip_log("erreur upload $error");
299
+    if ($return) {
300
+        return $msg;
301
+    }
302
+
303
+    if (_request("iframe") == "iframe") {
304
+        echo "<div class='upload_answer upload_error'>$msg</div>";
305
+        exit;
306
+    }
307
+
308
+    include_spip('inc/minipres');
309
+    echo minipres($msg,
310
+        "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . "</button></a></div>");
311
+    exit;
312 312
 }
Please login to merge, or discard this patch.