@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -24,11 +24,11 @@ discard block |
||
| 24 | 24 | * @param array $opt |
| 25 | 25 | */ |
| 26 | 26 | function inc_journal_dist($phrase, $opt = []) { |
| 27 | - if (!strlen($phrase)) { |
|
| 28 | - return; |
|
| 29 | - } |
|
| 30 | - if ($opt) { |
|
| 31 | - $phrase .= ' :: ' . str_replace("\n", ' ', join(', ', $opt)); |
|
| 32 | - } |
|
| 33 | - spip_log($phrase, 'journal'); |
|
| 27 | + if (!strlen($phrase)) { |
|
| 28 | + return; |
|
| 29 | + } |
|
| 30 | + if ($opt) { |
|
| 31 | + $phrase .= ' :: ' . str_replace("\n", ' ', join(', ', $opt)); |
|
| 32 | + } |
|
| 33 | + spip_log($phrase, 'journal'); |
|
| 34 | 34 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 44 | 44 | */ |
| 45 | 45 | function generer_action_auteur($action, $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 46 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | 47 | |
| 48 | - return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 48 | + return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * Code HTML du formulaire |
| 79 | 79 | */ |
| 80 | 80 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 81 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 81 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 82 | 82 | |
| 83 | - return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 83 | + return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 106 | 106 | */ |
| 107 | 107 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') { |
| 108 | - $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 108 | + $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 109 | 109 | |
| 110 | - return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 110 | + return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -122,26 +122,26 @@ discard block |
||
| 122 | 122 | * passer "text/html" comme $content_type |
| 123 | 123 | */ |
| 124 | 124 | function ajax_retour($corps, $content_type = null) { |
| 125 | - $xml = false; |
|
| 126 | - if (is_null($content_type) or $content_type === true) { |
|
| 127 | - $xml = true; |
|
| 128 | - $content_type = 'text/html'; |
|
| 129 | - } elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) { |
|
| 130 | - $content_type = 'text/html'; |
|
| 131 | - } |
|
| 125 | + $xml = false; |
|
| 126 | + if (is_null($content_type) or $content_type === true) { |
|
| 127 | + $xml = true; |
|
| 128 | + $content_type = 'text/html'; |
|
| 129 | + } elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) { |
|
| 130 | + $content_type = 'text/html'; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - $e = ''; |
|
| 134 | - if ( |
|
| 135 | - isset($_COOKIE['spip_admin']) |
|
| 136 | - and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps'])) |
|
| 137 | - ) { |
|
| 138 | - $e = erreur_squelette(); |
|
| 139 | - } |
|
| 133 | + $e = ''; |
|
| 134 | + if ( |
|
| 135 | + isset($_COOKIE['spip_admin']) |
|
| 136 | + and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps'])) |
|
| 137 | + ) { |
|
| 138 | + $e = erreur_squelette(); |
|
| 139 | + } |
|
| 140 | 140 | |
| 141 | - $c = $GLOBALS['meta']['charset']; |
|
| 142 | - header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 143 | - $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 144 | - $fin = ''; |
|
| 141 | + $c = $GLOBALS['meta']['charset']; |
|
| 142 | + header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 143 | + $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 144 | + $fin = ''; |
|
| 145 | 145 | |
| 146 | - echo $debut, $corps, $fin, $e; |
|
| 146 | + echo $debut, $corps, $fin, $e; |
|
| 147 | 147 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ? $_texte : "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ? $_texte : "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,55 +198,55 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $role = $role ?? 'alert'; // fallback uniquement si null |
|
| 205 | - $class = $class ?? 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $role = $role ?? 'alert'; // fallback uniquement si null |
|
| 205 | + $class = $class ?? 'notice'; // fallback uniquement si null |
|
| 206 | 206 | |
| 207 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | - $types = [ |
|
| 209 | - 'notice', |
|
| 210 | - 'error', |
|
| 211 | - 'success', |
|
| 212 | - 'info', |
|
| 213 | - ]; |
|
| 214 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | - $type = reset($type); |
|
| 216 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 207 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | + $types = [ |
|
| 209 | + 'notice', |
|
| 210 | + 'error', |
|
| 211 | + 'success', |
|
| 212 | + 'info', |
|
| 213 | + ]; |
|
| 214 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | + $type = reset($type); |
|
| 216 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 217 | 217 | |
| 218 | - // Classes |
|
| 219 | - $class_racine = 'msg-alert'; |
|
| 220 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | - $class_alerte = "$class_racine $class"; |
|
| 222 | - $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | - $class_titre = "${class_racine}__heading"; |
|
| 218 | + // Classes |
|
| 219 | + $class_racine = 'msg-alert'; |
|
| 220 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | + $class_alerte = "$class_racine $class"; |
|
| 222 | + $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | + $class_titre = "${class_racine}__heading"; |
|
| 224 | 224 | |
| 225 | - // Titre : markup |
|
| 226 | - $titre = trim($titre); |
|
| 227 | - if (strlen($titre)) { |
|
| 228 | - include_spip('inc/filtres'); |
|
| 229 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | - $titre = wrap($titre, $wrap_tag); |
|
| 234 | - } |
|
| 235 | - // puis on ajoute la classe |
|
| 236 | - $titre = ajouter_class($titre, $class_titre); |
|
| 237 | - } |
|
| 225 | + // Titre : markup |
|
| 226 | + $titre = trim($titre); |
|
| 227 | + if (strlen($titre)) { |
|
| 228 | + include_spip('inc/filtres'); |
|
| 229 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | + $titre = wrap($titre, $wrap_tag); |
|
| 234 | + } |
|
| 235 | + // puis on ajoute la classe |
|
| 236 | + $titre = ajouter_class($titre, $class_titre); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - // Attributs |
|
| 240 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 239 | + // Attributs |
|
| 240 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 243 | 243 | |
| 244 | - $message = |
|
| 245 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | - . $titre |
|
| 247 | - . "<div class=\"$class_texte\">"; |
|
| 244 | + $message = |
|
| 245 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | + . $titre |
|
| 247 | + . "<div class=\"$class_texte\">"; |
|
| 248 | 248 | |
| 249 | - return $message; |
|
| 249 | + return $message; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -260,5 +260,5 @@ discard block |
||
| 260 | 260 | * HTML de fin de l'alerte |
| 261 | 261 | */ |
| 262 | 262 | function message_alerte_fermer(): string { |
| 263 | - return '</div></div>'; |
|
| 263 | + return '</div></div>'; |
|
| 264 | 264 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', isset($_ENV['HTTP_HOST']) ? $_ENV['HTTP_HOST'] : '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,22 +388,22 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - include_spip('inc/minipres'); |
|
| 392 | - $dir = dirname($fichier); |
|
| 393 | - http_status(401); |
|
| 394 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 395 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 396 | - . " <a href='" |
|
| 397 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 398 | - . "'>" |
|
| 399 | - . _T('texte_inc_meta_2') |
|
| 400 | - . '</a> ' |
|
| 401 | - . _T( |
|
| 402 | - 'texte_inc_meta_3', |
|
| 403 | - ['repertoire' => joli_repertoire($dir)] |
|
| 404 | - ) |
|
| 405 | - . "</h4>\n"); |
|
| 406 | - exit; |
|
| 391 | + include_spip('inc/minipres'); |
|
| 392 | + $dir = dirname($fichier); |
|
| 393 | + http_status(401); |
|
| 394 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 395 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 396 | + . " <a href='" |
|
| 397 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 398 | + . "'>" |
|
| 399 | + . _T('texte_inc_meta_2') |
|
| 400 | + . '</a> ' |
|
| 401 | + . _T( |
|
| 402 | + 'texte_inc_meta_3', |
|
| 403 | + ['repertoire' => joli_repertoire($dir)] |
|
| 404 | + ) |
|
| 405 | + . "</h4>\n"); |
|
| 406 | + exit; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -418,14 +418,14 @@ discard block |
||
| 418 | 418 | * - true si récent, false sinon |
| 419 | 419 | */ |
| 420 | 420 | function jeune_fichier($fichier, $n) { |
| 421 | - if (!file_exists($fichier)) { |
|
| 422 | - return false; |
|
| 423 | - } |
|
| 424 | - if (!$c = @filemtime($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - return (time() - $n <= $c); |
|
| 421 | + if (!file_exists($fichier)) { |
|
| 422 | + return false; |
|
| 423 | + } |
|
| 424 | + if (!$c = @filemtime($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + return (time() - $n <= $c); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -440,22 +440,22 @@ discard block |
||
| 440 | 440 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 441 | 441 | */ |
| 442 | 442 | function supprimer_fichier($fichier, $lock = true) { |
| 443 | - if (!@file_exists($fichier)) { |
|
| 444 | - return true; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if ($lock) { |
|
| 448 | - // verrouiller le fichier destination |
|
| 449 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 450 | - return false; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // liberer le verrou |
|
| 454 | - spip_fclose_unlock($fp); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - // supprimer |
|
| 458 | - return @unlink($fichier); |
|
| 443 | + if (!@file_exists($fichier)) { |
|
| 444 | + return true; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if ($lock) { |
|
| 448 | + // verrouiller le fichier destination |
|
| 449 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // liberer le verrou |
|
| 454 | + spip_fclose_unlock($fp); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + // supprimer |
|
| 458 | + return @unlink($fichier); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | * Chemin du fichier |
| 466 | 466 | */ |
| 467 | 467 | function spip_unlink($f) { |
| 468 | - if (!is_dir($f)) { |
|
| 469 | - supprimer_fichier($f, false); |
|
| 470 | - } else { |
|
| 471 | - @unlink("$f/.ok"); |
|
| 472 | - @rmdir($f); |
|
| 473 | - } |
|
| 468 | + if (!is_dir($f)) { |
|
| 469 | + supprimer_fichier($f, false); |
|
| 470 | + } else { |
|
| 471 | + @unlink("$f/.ok"); |
|
| 472 | + @rmdir($f); |
|
| 473 | + } |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -484,26 +484,26 @@ discard block |
||
| 484 | 484 | * The absolute path of the PHP file to invalidate. |
| 485 | 485 | */ |
| 486 | 486 | function spip_clear_opcode_cache($filepath) { |
| 487 | - clearstatcache(true, $filepath); |
|
| 488 | - |
|
| 489 | - // Zend OPcache |
|
| 490 | - if (function_exists('opcache_invalidate')) { |
|
| 491 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 492 | - // si l'invalidation a echoue lever un flag |
|
| 493 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 494 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 495 | - } |
|
| 496 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 498 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 499 | - } |
|
| 500 | - // APC. |
|
| 501 | - if (function_exists('apc_delete_file')) { |
|
| 502 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 503 | - // not compiled yet. |
|
| 504 | - // @see http://php.net/apc-delete-file |
|
| 505 | - @apc_delete_file($filepath); |
|
| 506 | - } |
|
| 487 | + clearstatcache(true, $filepath); |
|
| 488 | + |
|
| 489 | + // Zend OPcache |
|
| 490 | + if (function_exists('opcache_invalidate')) { |
|
| 491 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 492 | + // si l'invalidation a echoue lever un flag |
|
| 493 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 494 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 495 | + } |
|
| 496 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 498 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 499 | + } |
|
| 500 | + // APC. |
|
| 501 | + if (function_exists('apc_delete_file')) { |
|
| 502 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 503 | + // not compiled yet. |
|
| 504 | + // @see http://php.net/apc-delete-file |
|
| 505 | + @apc_delete_file($filepath); |
|
| 506 | + } |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /** |
@@ -526,25 +526,25 @@ discard block |
||
| 526 | 526 | * |
| 527 | 527 | */ |
| 528 | 528 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 529 | - if ( |
|
| 530 | - function_exists('opcache_get_configuration') |
|
| 531 | - and @ini_get('opcache.enable') |
|
| 532 | - and @ini_get('opcache.validate_timestamps') |
|
| 533 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 534 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 535 | - ) { |
|
| 536 | - $wait = $duree + 1; |
|
| 537 | - if ($timestamp) { |
|
| 538 | - $wait -= (time() - $timestamp); |
|
| 539 | - if ($wait < 0) { |
|
| 540 | - $wait = 0; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 544 | - if ($wait) { |
|
| 545 | - sleep($duree + 1); |
|
| 546 | - } |
|
| 547 | - } |
|
| 529 | + if ( |
|
| 530 | + function_exists('opcache_get_configuration') |
|
| 531 | + and @ini_get('opcache.enable') |
|
| 532 | + and @ini_get('opcache.validate_timestamps') |
|
| 533 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 534 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 535 | + ) { |
|
| 536 | + $wait = $duree + 1; |
|
| 537 | + if ($timestamp) { |
|
| 538 | + $wait -= (time() - $timestamp); |
|
| 539 | + if ($wait < 0) { |
|
| 540 | + $wait = 0; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 544 | + if ($wait) { |
|
| 545 | + sleep($duree + 1); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -557,26 +557,26 @@ discard block |
||
| 557 | 557 | * @return bool Suppression reussie. |
| 558 | 558 | */ |
| 559 | 559 | function supprimer_repertoire($dir) { |
| 560 | - if (!file_exists($dir)) { |
|
| 561 | - return true; |
|
| 562 | - } |
|
| 563 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 564 | - return @unlink($dir); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - foreach (scandir($dir) as $item) { |
|
| 568 | - if ($item == '.' || $item == '..') { |
|
| 569 | - continue; |
|
| 570 | - } |
|
| 571 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 572 | - @chmod($dir . '/' . $item, 0777); |
|
| 573 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 574 | - return false; |
|
| 575 | - } |
|
| 576 | - }; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return @rmdir($dir); |
|
| 560 | + if (!file_exists($dir)) { |
|
| 561 | + return true; |
|
| 562 | + } |
|
| 563 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 564 | + return @unlink($dir); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + foreach (scandir($dir) as $item) { |
|
| 568 | + if ($item == '.' || $item == '..') { |
|
| 569 | + continue; |
|
| 570 | + } |
|
| 571 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 572 | + @chmod($dir . '/' . $item, 0777); |
|
| 573 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 574 | + return false; |
|
| 575 | + } |
|
| 576 | + }; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return @rmdir($dir); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | |
@@ -605,57 +605,57 @@ discard block |
||
| 605 | 605 | * Chemin du répertoire créé. |
| 606 | 606 | **/ |
| 607 | 607 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 608 | - static $dirs = []; |
|
| 609 | - |
|
| 610 | - $base = str_replace('//', '/', $base); |
|
| 611 | - |
|
| 612 | - # suppr le dernier caractere si c'est un / |
|
| 613 | - $base = rtrim($base, '/'); |
|
| 614 | - |
|
| 615 | - if (!strlen($subdir)) { |
|
| 616 | - $n = strrpos($base, '/'); |
|
| 617 | - if ($n === false) { |
|
| 618 | - return $nobase ? '' : ($base . '/'); |
|
| 619 | - } |
|
| 620 | - $subdir = substr($base, $n + 1); |
|
| 621 | - $base = substr($base, 0, $n + 1); |
|
| 622 | - } else { |
|
| 623 | - $base .= '/'; |
|
| 624 | - $subdir = str_replace('/', '', $subdir); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $baseaff = $nobase ? '' : $base; |
|
| 628 | - if (isset($dirs[$base . $subdir])) { |
|
| 629 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 633 | - |
|
| 634 | - if (file_exists("$path/.ok")) { |
|
| 635 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - @mkdir($path, _SPIP_CHMOD); |
|
| 639 | - @chmod($path, _SPIP_CHMOD); |
|
| 640 | - |
|
| 641 | - if (is_dir($path) && is_writable($path)) { |
|
| 642 | - @touch("$path/.ok"); |
|
| 643 | - spip_log("creation $base$subdir/"); |
|
| 644 | - |
|
| 645 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 649 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 650 | - spip_log("echec creation $base${subdir}"); |
|
| 651 | - if ($tantpis) { |
|
| 652 | - return ''; |
|
| 653 | - } |
|
| 654 | - if (!_DIR_RESTREINT) { |
|
| 655 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 656 | - } |
|
| 657 | - $base .= $subdir; |
|
| 658 | - raler_fichier($base . '/.ok'); |
|
| 608 | + static $dirs = []; |
|
| 609 | + |
|
| 610 | + $base = str_replace('//', '/', $base); |
|
| 611 | + |
|
| 612 | + # suppr le dernier caractere si c'est un / |
|
| 613 | + $base = rtrim($base, '/'); |
|
| 614 | + |
|
| 615 | + if (!strlen($subdir)) { |
|
| 616 | + $n = strrpos($base, '/'); |
|
| 617 | + if ($n === false) { |
|
| 618 | + return $nobase ? '' : ($base . '/'); |
|
| 619 | + } |
|
| 620 | + $subdir = substr($base, $n + 1); |
|
| 621 | + $base = substr($base, 0, $n + 1); |
|
| 622 | + } else { |
|
| 623 | + $base .= '/'; |
|
| 624 | + $subdir = str_replace('/', '', $subdir); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $baseaff = $nobase ? '' : $base; |
|
| 628 | + if (isset($dirs[$base . $subdir])) { |
|
| 629 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 633 | + |
|
| 634 | + if (file_exists("$path/.ok")) { |
|
| 635 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + @mkdir($path, _SPIP_CHMOD); |
|
| 639 | + @chmod($path, _SPIP_CHMOD); |
|
| 640 | + |
|
| 641 | + if (is_dir($path) && is_writable($path)) { |
|
| 642 | + @touch("$path/.ok"); |
|
| 643 | + spip_log("creation $base$subdir/"); |
|
| 644 | + |
|
| 645 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 649 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 650 | + spip_log("echec creation $base${subdir}"); |
|
| 651 | + if ($tantpis) { |
|
| 652 | + return ''; |
|
| 653 | + } |
|
| 654 | + if (!_DIR_RESTREINT) { |
|
| 655 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 656 | + } |
|
| 657 | + $base .= $subdir; |
|
| 658 | + raler_fichier($base . '/.ok'); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -688,56 +688,56 @@ discard block |
||
| 688 | 688 | * Chemins des fichiers trouvés. |
| 689 | 689 | **/ |
| 690 | 690 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 691 | - $nbfiles = 0; |
|
| 692 | - if ($pattern == -1) { |
|
| 693 | - $pattern = "^$dir"; |
|
| 694 | - } |
|
| 695 | - $fichiers = []; |
|
| 696 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 697 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 698 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 699 | - if ($dir == '') { |
|
| 700 | - $dir = '.'; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 704 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 705 | - if ( |
|
| 706 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 707 | - and $f != 'CVS' |
|
| 708 | - and $f != 'remove.txt' |
|
| 709 | - and is_readable($f = "$dir/$f") |
|
| 710 | - ) { |
|
| 711 | - if (is_file($f)) { |
|
| 712 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 713 | - $fichiers[] = $f; |
|
| 714 | - $nbfiles++; |
|
| 715 | - } |
|
| 716 | - } else { |
|
| 717 | - if (is_dir($f) and is_array($recurs)) { |
|
| 718 | - $rp = @realpath($f); |
|
| 719 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 720 | - $rp = $f; |
|
| 721 | - } # realpath n'est peut etre pas autorise |
|
| 722 | - if (!isset($recurs[$rp])) { |
|
| 723 | - $recurs[$rp] = true; |
|
| 724 | - $beginning = $fichiers; |
|
| 725 | - $end = preg_files( |
|
| 726 | - "$f/", |
|
| 727 | - $pattern, |
|
| 728 | - $maxfiles - $nbfiles, |
|
| 729 | - $recurs |
|
| 730 | - ); |
|
| 731 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 732 | - $nbfiles = count($fichiers); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - closedir($d); |
|
| 739 | - } |
|
| 740 | - sort($fichiers); |
|
| 741 | - |
|
| 742 | - return $fichiers; |
|
| 691 | + $nbfiles = 0; |
|
| 692 | + if ($pattern == -1) { |
|
| 693 | + $pattern = "^$dir"; |
|
| 694 | + } |
|
| 695 | + $fichiers = []; |
|
| 696 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 697 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 698 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 699 | + if ($dir == '') { |
|
| 700 | + $dir = '.'; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 704 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 705 | + if ( |
|
| 706 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 707 | + and $f != 'CVS' |
|
| 708 | + and $f != 'remove.txt' |
|
| 709 | + and is_readable($f = "$dir/$f") |
|
| 710 | + ) { |
|
| 711 | + if (is_file($f)) { |
|
| 712 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 713 | + $fichiers[] = $f; |
|
| 714 | + $nbfiles++; |
|
| 715 | + } |
|
| 716 | + } else { |
|
| 717 | + if (is_dir($f) and is_array($recurs)) { |
|
| 718 | + $rp = @realpath($f); |
|
| 719 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 720 | + $rp = $f; |
|
| 721 | + } # realpath n'est peut etre pas autorise |
|
| 722 | + if (!isset($recurs[$rp])) { |
|
| 723 | + $recurs[$rp] = true; |
|
| 724 | + $beginning = $fichiers; |
|
| 725 | + $end = preg_files( |
|
| 726 | + "$f/", |
|
| 727 | + $pattern, |
|
| 728 | + $maxfiles - $nbfiles, |
|
| 729 | + $recurs |
|
| 730 | + ); |
|
| 731 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 732 | + $nbfiles = count($fichiers); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + closedir($d); |
|
| 739 | + } |
|
| 740 | + sort($fichiers); |
|
| 741 | + |
|
| 742 | + return $fichiers; |
|
| 743 | 743 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Surligne |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -35,43 +35,43 @@ discard block |
||
| 35 | 35 | * Page HTML |
| 36 | 36 | **/ |
| 37 | 37 | function surligner_mots($page, $surcharge_surligne = '') { |
| 38 | - $surlignejs_engines = [ |
|
| 39 | - [ |
|
| 40 | - ',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i', |
|
| 41 | - ',recherche=([^&]+),i' |
|
| 42 | - ], //SPIP |
|
| 43 | - [',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google |
|
| 44 | - [',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo |
|
| 45 | - [',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN |
|
| 46 | - [',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live |
|
| 47 | - [',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL |
|
| 48 | - [',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com |
|
| 49 | - [',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista |
|
| 50 | - [',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster |
|
| 51 | - [',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos |
|
| 52 | - [',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb |
|
| 53 | - [',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati |
|
| 54 | - ]; |
|
| 38 | + $surlignejs_engines = [ |
|
| 39 | + [ |
|
| 40 | + ',' . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . ',i', |
|
| 41 | + ',recherche=([^&]+),i' |
|
| 42 | + ], //SPIP |
|
| 43 | + [',^http://(www\.)?google\.,i', ',q=([^&]+),i'], // Google |
|
| 44 | + [',^http://(www\.)?search\.yahoo\.,i', ',p=([^&]+),i'], // Yahoo |
|
| 45 | + [',^http://(www\.)?search\.msn\.,i', ',q=([^&]+),i'], // MSN |
|
| 46 | + [',^http://(www\.)?search\.live\.,i', ',query=([^&]+),i'], // MSN Live |
|
| 47 | + [',^http://(www\.)?search\.aol\.,i', ',userQuery=([^&]+),i'], // AOL |
|
| 48 | + [',^http://(www\.)?ask\.com,i', ',q=([^&]+),i'], // Ask.com |
|
| 49 | + [',^http://(www\.)?altavista\.,i', ',q=([^&]+),i'], // AltaVista |
|
| 50 | + [',^http://(www\.)?feedster\.,i', ',q=([^&]+),i'], // Feedster |
|
| 51 | + [',^http://(www\.)?search\.lycos\.,i', ',q=([^&]+),i'], // Lycos |
|
| 52 | + [',^http://(www\.)?alltheweb\.,i', ',q=([^&]+),i'], // AllTheWeb |
|
| 53 | + [',^http://(www\.)?technorati\.com,i', ',([^\?\/]+)(?:\?.*)$,i'], // Technorati |
|
| 54 | + ]; |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 58 | - //avoid a js injection |
|
| 59 | - if ($surcharge_surligne) { |
|
| 60 | - $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne); |
|
| 61 | - $surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne); |
|
| 62 | - if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 63 | - include_spip('inc/charsets'); |
|
| 64 | - if (!is_utf8($surcharge_surligne)) { |
|
| 65 | - $surcharge_surligne = utf8_encode($surcharge_surligne); |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final |
|
| 69 | - } |
|
| 70 | - foreach ($surlignejs_engines as $engine) { |
|
| 71 | - if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) { |
|
| 72 | - //good referrer found or var_recherche is not null |
|
| 73 | - include_spip('inc/filtres'); |
|
| 74 | - $script = " |
|
| 57 | + $ref = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : null; |
|
| 58 | + //avoid a js injection |
|
| 59 | + if ($surcharge_surligne) { |
|
| 60 | + $surcharge_surligne = preg_replace(",(?<!\\\\)((?:(?>\\\\){2})*)('),", '$1\\\$2', $surcharge_surligne); |
|
| 61 | + $surcharge_surligne = str_replace('\\', '\\\\', $surcharge_surligne); |
|
| 62 | + if ($GLOBALS['meta']['charset'] == 'utf-8') { |
|
| 63 | + include_spip('inc/charsets'); |
|
| 64 | + if (!is_utf8($surcharge_surligne)) { |
|
| 65 | + $surcharge_surligne = utf8_encode($surcharge_surligne); |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + $surcharge_surligne = preg_replace(',\*$,', '', trim($surcharge_surligne)); # supprimer un * final |
|
| 69 | + } |
|
| 70 | + foreach ($surlignejs_engines as $engine) { |
|
| 71 | + if ($surcharge_surligne || (preg_match($engine[0], $ref) && preg_match($engine[1], $ref))) { |
|
| 72 | + //good referrer found or var_recherche is not null |
|
| 73 | + include_spip('inc/filtres'); |
|
| 74 | + $script = " |
|
| 75 | 75 | <script type='text/javascript' src='" . url_absolue(find_in_path('javascript/SearchHighlight.js')) . "'></script> |
| 76 | 76 | <script type='text/javascript'>/*<![CDATA[*/ |
| 77 | 77 | if (window.jQuery) |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | engines:[/^" . str_replace(['/', '.'], ['\/', '\.'], $GLOBALS['meta']['adresse_site']) . "/i,/recherche=([^&]+)/i], |
| 85 | 85 | highlight:'.surlignable', |
| 86 | 86 | nohighlight:'.pas_surlignable'" . |
| 87 | - ($surcharge_surligne ? ", |
|
| 87 | + ($surcharge_surligne ? ", |
|
| 88 | 88 | keys:'$surcharge_surligne'" : '') . ', |
| 89 | 89 | min_length: 3 |
| 90 | 90 | }) |
@@ -92,14 +92,14 @@ discard block |
||
| 92 | 92 | })(jQuery); |
| 93 | 93 | /*]]>*/</script> |
| 94 | 94 | '; |
| 95 | - // on l'insere juste avant </head>, sinon tout en bas |
|
| 96 | - if (is_null($l = strpos($page, '</head>'))) { |
|
| 97 | - $l = strlen($page); |
|
| 98 | - } |
|
| 99 | - $page = substr_replace($page, $script, $l, 0); |
|
| 100 | - break; |
|
| 101 | - } |
|
| 102 | - } |
|
| 95 | + // on l'insere juste avant </head>, sinon tout en bas |
|
| 96 | + if (is_null($l = strpos($page, '</head>'))) { |
|
| 97 | + $l = strlen($page); |
|
| 98 | + } |
|
| 99 | + $page = substr_replace($page, $script, $l, 0); |
|
| 100 | + break; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - return $page; |
|
| 104 | + return $page; |
|
| 105 | 105 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,47 +31,47 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - srand($seed); |
|
| 38 | - $s = ''; |
|
| 39 | - $pass = ''; |
|
| 40 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 41 | - if (!$s) { |
|
| 42 | - $s = mt_rand(); |
|
| 43 | - if (!$s) { |
|
| 44 | - $s = rand(); |
|
| 45 | - } |
|
| 46 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 47 | - } |
|
| 48 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 49 | - $x = $r['r'] & 63; |
|
| 50 | - if ($x < 10) { |
|
| 51 | - $x = chr($x + 48); |
|
| 52 | - } else { |
|
| 53 | - if ($x < 36) { |
|
| 54 | - $x = chr($x + 55); |
|
| 55 | - } else { |
|
| 56 | - if ($x < 62) { |
|
| 57 | - $x = chr($x + 61); |
|
| 58 | - } else { |
|
| 59 | - if ($x == 63) { |
|
| 60 | - $x = '/'; |
|
| 61 | - } else { |
|
| 62 | - $x = '.'; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - $pass .= $x; |
|
| 68 | - $s = substr($s, 2); |
|
| 69 | - } |
|
| 70 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 71 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 72 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 73 | - |
|
| 74 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + srand($seed); |
|
| 38 | + $s = ''; |
|
| 39 | + $pass = ''; |
|
| 40 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 41 | + if (!$s) { |
|
| 42 | + $s = mt_rand(); |
|
| 43 | + if (!$s) { |
|
| 44 | + $s = rand(); |
|
| 45 | + } |
|
| 46 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 47 | + } |
|
| 48 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 49 | + $x = $r['r'] & 63; |
|
| 50 | + if ($x < 10) { |
|
| 51 | + $x = chr($x + 48); |
|
| 52 | + } else { |
|
| 53 | + if ($x < 36) { |
|
| 54 | + $x = chr($x + 55); |
|
| 55 | + } else { |
|
| 56 | + if ($x < 62) { |
|
| 57 | + $x = chr($x + 61); |
|
| 58 | + } else { |
|
| 59 | + if ($x == 63) { |
|
| 60 | + $x = '/'; |
|
| 61 | + } else { |
|
| 62 | + $x = '.'; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + $pass .= $x; |
|
| 68 | + $s = substr($s, 2); |
|
| 69 | + } |
|
| 70 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 71 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 72 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 73 | + |
|
| 74 | + return $pass; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,21 +80,21 @@ discard block |
||
| 80 | 80 | * @return string Identifiant |
| 81 | 81 | */ |
| 82 | 82 | function creer_uniqid() { |
| 83 | - static $seeded; |
|
| 83 | + static $seeded; |
|
| 84 | 84 | |
| 85 | - if (!$seeded) { |
|
| 86 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 87 | - mt_srand($seed); |
|
| 88 | - srand($seed); |
|
| 89 | - $seeded = true; |
|
| 90 | - } |
|
| 85 | + if (!$seeded) { |
|
| 86 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 87 | + mt_srand($seed); |
|
| 88 | + srand($seed); |
|
| 89 | + $seeded = true; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $s = mt_rand(); |
|
| 93 | - if (!$s) { |
|
| 94 | - $s = rand(); |
|
| 95 | - } |
|
| 92 | + $s = mt_rand(); |
|
| 93 | + if (!$s) { |
|
| 94 | + $s = rand(); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - return uniqid($s, 1); |
|
| 97 | + return uniqid($s, 1); |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | /** |
@@ -108,42 +108,42 @@ discard block |
||
| 108 | 108 | * @return string Retourne l'alea éphemère actuel au passage |
| 109 | 109 | */ |
| 110 | 110 | function charger_aleas() { |
| 111 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 112 | - include_spip('base/abstract_sql'); |
|
| 113 | - $aleas = sql_allfetsel( |
|
| 114 | - ['nom', 'valeur'], |
|
| 115 | - 'spip_meta', |
|
| 116 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - '', |
|
| 121 | - '', |
|
| 122 | - 'continue' |
|
| 123 | - ); |
|
| 124 | - if ($aleas) { |
|
| 125 | - foreach ($aleas as $a) { |
|
| 126 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 127 | - } |
|
| 128 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 129 | - } else { |
|
| 130 | - spip_log('aleas indisponibles', 'session'); |
|
| 131 | - return ''; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 111 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 112 | + include_spip('base/abstract_sql'); |
|
| 113 | + $aleas = sql_allfetsel( |
|
| 114 | + ['nom', 'valeur'], |
|
| 115 | + 'spip_meta', |
|
| 116 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + '', |
|
| 121 | + '', |
|
| 122 | + 'continue' |
|
| 123 | + ); |
|
| 124 | + if ($aleas) { |
|
| 125 | + foreach ($aleas as $a) { |
|
| 126 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 127 | + } |
|
| 128 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 129 | + } else { |
|
| 130 | + spip_log('aleas indisponibles', 'session'); |
|
| 131 | + return ''; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | 138 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 139 | 139 | **/ |
| 140 | 140 | function renouvelle_alea() { |
| 141 | - charger_aleas(); |
|
| 142 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 144 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 145 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 146 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 141 | + charger_aleas(); |
|
| 142 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 144 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 145 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 146 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | |
@@ -163,21 +163,21 @@ discard block |
||
| 163 | 163 | * Clé de sécurité. |
| 164 | 164 | **/ |
| 165 | 165 | function low_sec($id_auteur) { |
| 166 | - // Pas d'id_auteur : low_sec |
|
| 167 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 168 | - include_spip('inc/config'); |
|
| 169 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 170 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 171 | - } |
|
| 172 | - } else { |
|
| 173 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | - if (!$low_sec) { |
|
| 175 | - $low_sec = creer_pass_aleatoire(); |
|
| 176 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return $low_sec; |
|
| 166 | + // Pas d'id_auteur : low_sec |
|
| 167 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 168 | + include_spip('inc/config'); |
|
| 169 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 170 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 171 | + } |
|
| 172 | + } else { |
|
| 173 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + if (!$low_sec) { |
|
| 175 | + $low_sec = creer_pass_aleatoire(); |
|
| 176 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return $low_sec; |
|
| 181 | 181 | } |
| 182 | 182 | |
| 183 | 183 | /** |
@@ -193,27 +193,27 @@ discard block |
||
| 193 | 193 | * @return string |
| 194 | 194 | */ |
| 195 | 195 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 196 | - $a = $b = ''; |
|
| 197 | - foreach ($args as $val => $var) { |
|
| 198 | - if ($var) { |
|
| 199 | - if ($val <> 'statut') { |
|
| 200 | - $a .= ':' . $val . '-' . $var; |
|
| 201 | - } |
|
| 202 | - $b .= $val . '=' . $var . '&'; |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - $a = substr($a, 1); |
|
| 206 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 207 | - |
|
| 208 | - return $b |
|
| 209 | - . 'op=' |
|
| 210 | - . $op |
|
| 211 | - . '&id=' |
|
| 212 | - . $id |
|
| 213 | - . '&cle=' |
|
| 214 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 215 | - . (!$a ? '' : "&args=$a") |
|
| 216 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 196 | + $a = $b = ''; |
|
| 197 | + foreach ($args as $val => $var) { |
|
| 198 | + if ($var) { |
|
| 199 | + if ($val <> 'statut') { |
|
| 200 | + $a .= ':' . $val . '-' . $var; |
|
| 201 | + } |
|
| 202 | + $b .= $val . '=' . $var . '&'; |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + $a = substr($a, 1); |
|
| 206 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 207 | + |
|
| 208 | + return $b |
|
| 209 | + . 'op=' |
|
| 210 | + . $op |
|
| 211 | + . '&id=' |
|
| 212 | + . $id |
|
| 213 | + . '&cle=' |
|
| 214 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 215 | + . (!$a ? '' : "&args=$a") |
|
| 216 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | * Clé |
| 230 | 230 | **/ |
| 231 | 231 | function afficher_low_sec($id_auteur, $action = '') { |
| 232 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 232 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | * true si les clés corresponde, false sinon |
| 248 | 248 | **/ |
| 249 | 249 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 250 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 250 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -257,10 +257,10 @@ discard block |
||
| 257 | 257 | * Identifiant de l'auteur |
| 258 | 258 | **/ |
| 259 | 259 | function effacer_low_sec($id_auteur) { |
| 260 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 261 | - return; |
|
| 262 | - } // jamais trop prudent ;) |
|
| 263 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 260 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 261 | + return; |
|
| 262 | + } // jamais trop prudent ;) |
|
| 263 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | * @return void|bool |
| 270 | 270 | */ |
| 271 | 271 | function initialiser_sel() { |
| 272 | - if (!isset($GLOBALS['htsalt'])) { |
|
| 273 | - if (CRYPT_MD5) { |
|
| 274 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 275 | - } else { |
|
| 276 | - $GLOBALS['htsalt'] = ''; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - return $GLOBALS['htsalt']; |
|
| 272 | + if (!isset($GLOBALS['htsalt'])) { |
|
| 273 | + if (CRYPT_MD5) { |
|
| 274 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 275 | + } else { |
|
| 276 | + $GLOBALS['htsalt'] = ''; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + return $GLOBALS['htsalt']; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -293,32 +293,32 @@ discard block |
||
| 293 | 293 | * - void sinon. |
| 294 | 294 | **/ |
| 295 | 295 | function ecrire_acces() { |
| 296 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 297 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 298 | - |
|
| 299 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 300 | - // par exemple acces_restreint ; |
|
| 301 | - // si .htaccess existe, outrepasser spip_meta |
|
| 302 | - if ( |
|
| 303 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 304 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 305 | - and !@file_exists($htaccess) |
|
| 306 | - ) { |
|
| 307 | - spip_unlink($htpasswd); |
|
| 308 | - spip_unlink($htpasswd . '-admin'); |
|
| 309 | - return; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 313 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 314 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 315 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 316 | - |
|
| 317 | - if (spip_connect_ldap()) { |
|
| 318 | - return; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 296 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 297 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 298 | + |
|
| 299 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 300 | + // par exemple acces_restreint ; |
|
| 301 | + // si .htaccess existe, outrepasser spip_meta |
|
| 302 | + if ( |
|
| 303 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 304 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 305 | + and !@file_exists($htaccess) |
|
| 306 | + ) { |
|
| 307 | + spip_unlink($htpasswd); |
|
| 308 | + spip_unlink($htpasswd . '-admin'); |
|
| 309 | + return; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 313 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 314 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 315 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test spip_connect_ldap() |
|
| 316 | + |
|
| 317 | + if (spip_connect_ldap()) { |
|
| 318 | + return; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -327,29 +327,29 @@ discard block |
||
| 327 | 327 | * @param $htpasswd_admin |
| 328 | 328 | */ |
| 329 | 329 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 330 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 331 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - $pwd_all = ''; // login:htpass pour tous |
|
| 335 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 336 | - |
|
| 337 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 338 | - while ($row = sql_fetch($res)) { |
|
| 339 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 340 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 341 | - $pwd_all .= $ligne; |
|
| 342 | - if ($row['statut'] == '0minirezo') { |
|
| 343 | - $pwd_admin .= $ligne; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - if ($pwd_all) { |
|
| 349 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 350 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 351 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 352 | - } |
|
| 330 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 331 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + $pwd_all = ''; // login:htpass pour tous |
|
| 335 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 336 | + |
|
| 337 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 338 | + while ($row = sql_fetch($res)) { |
|
| 339 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 340 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 341 | + $pwd_all .= $ligne; |
|
| 342 | + if ($row['statut'] == '0minirezo') { |
|
| 343 | + $pwd_admin .= $ligne; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + if ($pwd_all) { |
|
| 349 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 350 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 351 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 352 | + } |
|
| 353 | 353 | } |
| 354 | 354 | |
| 355 | 355 | /** |
@@ -363,13 +363,13 @@ discard block |
||
| 363 | 363 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 364 | 364 | */ |
| 365 | 365 | function generer_htpass($pass) { |
| 366 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 367 | - return $generer_htpass($pass); |
|
| 368 | - } |
|
| 369 | - elseif (function_exists('crypt')) { |
|
| 370 | - return crypt($pass, initialiser_sel()); |
|
| 371 | - } |
|
| 372 | - return ''; |
|
| 366 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 367 | + return $generer_htpass($pass); |
|
| 368 | + } |
|
| 369 | + elseif (function_exists('crypt')) { |
|
| 370 | + return crypt($pass, initialiser_sel()); |
|
| 371 | + } |
|
| 372 | + return ''; |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -382,14 +382,14 @@ discard block |
||
| 382 | 382 | * @return boolean |
| 383 | 383 | */ |
| 384 | 384 | function verifier_htaccess($rep, $force = false) { |
| 385 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 386 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 387 | - return true; |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - // directive deny compatible Apache 2.0+ |
|
| 391 | - $deny = |
|
| 392 | - '# Deny all requests from Apache 2.4+. |
|
| 385 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 386 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 387 | + return true; |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + // directive deny compatible Apache 2.0+ |
|
| 391 | + $deny = |
|
| 392 | + '# Deny all requests from Apache 2.4+. |
|
| 393 | 393 | <IfModule mod_authz_core.c> |
| 394 | 394 | Require all denied |
| 395 | 395 | </IfModule> |
@@ -398,32 +398,32 @@ discard block |
||
| 398 | 398 | Deny from all |
| 399 | 399 | </IfModule> |
| 400 | 400 | '; |
| 401 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 402 | - if ( |
|
| 403 | - function_exists('apache_get_version') |
|
| 404 | - and $v = apache_get_version() |
|
| 405 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 406 | - ) { |
|
| 407 | - $deny = "deny from all\n"; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 411 | - fputs($ht, $deny); |
|
| 412 | - fclose($ht); |
|
| 413 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 414 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 415 | - if ($ht = @fopen($t, 'w')) { |
|
| 416 | - @fclose($ht); |
|
| 417 | - include_spip('inc/distant'); |
|
| 418 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 419 | - $t = url_de_base() . $t; |
|
| 420 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 421 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 425 | - |
|
| 426 | - return $ht; |
|
| 401 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 402 | + if ( |
|
| 403 | + function_exists('apache_get_version') |
|
| 404 | + and $v = apache_get_version() |
|
| 405 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 406 | + ) { |
|
| 407 | + $deny = "deny from all\n"; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 411 | + fputs($ht, $deny); |
|
| 412 | + fclose($ht); |
|
| 413 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 414 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 415 | + if ($ht = @fopen($t, 'w')) { |
|
| 416 | + @fclose($ht); |
|
| 417 | + include_spip('inc/distant'); |
|
| 418 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 419 | + $t = url_de_base() . $t; |
|
| 420 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 421 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 425 | + |
|
| 426 | + return $ht; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -441,20 +441,20 @@ discard block |
||
| 441 | 441 | * Valeur de la configuration `creer_htaccess` |
| 442 | 442 | */ |
| 443 | 443 | function gerer_htaccess() { |
| 444 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 445 | - // par exemple acces_restreint |
|
| 446 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 447 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 448 | - $dirs[] = ['extension' => 'distant']; |
|
| 449 | - foreach ($dirs as $e) { |
|
| 450 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 451 | - if ($f) { |
|
| 452 | - verifier_htaccess($dir); |
|
| 453 | - } else { |
|
| 454 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 444 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 445 | + // par exemple acces_restreint |
|
| 446 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 447 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 448 | + $dirs[] = ['extension' => 'distant']; |
|
| 449 | + foreach ($dirs as $e) { |
|
| 450 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 451 | + if ($f) { |
|
| 452 | + verifier_htaccess($dir); |
|
| 453 | + } else { |
|
| 454 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + return isset($GLOBALS['meta']['creer_htaccess']) ? $GLOBALS['meta']['creer_htaccess'] : ''; |
|
| 460 | 460 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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,26 +77,26 @@ discard block |
||
| 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 ( |
|
| 91 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 92 | - and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 93 | - and $ext !== 'logo' |
|
| 94 | - ) { |
|
| 95 | - include_spip('inc/acces'); |
|
| 96 | - verifier_htaccess($rep); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - 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 ( |
|
| 91 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 92 | + and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 93 | + and $ext !== 'logo' |
|
| 94 | + ) { |
|
| 95 | + include_spip('inc/acces'); |
|
| 96 | + verifier_htaccess($rep); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return $rep; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -105,22 +105,22 @@ discard block |
||
| 105 | 105 | * @param string $nom |
| 106 | 106 | */ |
| 107 | 107 | function effacer_repertoire_temporaire($nom) { |
| 108 | - if ($d = opendir($nom)) { |
|
| 109 | - while (($f = readdir($d)) !== false) { |
|
| 110 | - if (is_file("$nom/$f")) { |
|
| 111 | - spip_unlink("$nom/$f"); |
|
| 112 | - } else { |
|
| 113 | - if ( |
|
| 114 | - $f <> '.' and $f <> '..' |
|
| 115 | - and is_dir("$nom/$f") |
|
| 116 | - ) { |
|
| 117 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - closedir($d); |
|
| 123 | - @rmdir($nom); |
|
| 108 | + if ($d = opendir($nom)) { |
|
| 109 | + while (($f = readdir($d)) !== false) { |
|
| 110 | + if (is_file("$nom/$f")) { |
|
| 111 | + spip_unlink("$nom/$f"); |
|
| 112 | + } else { |
|
| 113 | + if ( |
|
| 114 | + $f <> '.' and $f <> '..' |
|
| 115 | + and is_dir("$nom/$f") |
|
| 116 | + ) { |
|
| 117 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + closedir($d); |
|
| 123 | + @rmdir($nom); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // |
@@ -137,34 +137,34 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 139 | 139 | |
| 140 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 141 | - $dir = creer_repertoire_documents($subdir ? $subdir : $ext); |
|
| 142 | - $dest = preg_replace( |
|
| 143 | - '/[^.=\w-]+/', |
|
| 144 | - '_', |
|
| 145 | - translitteration(preg_replace( |
|
| 146 | - '/\.([^.]+)$/', |
|
| 147 | - '', |
|
| 148 | - preg_replace('/<[^>]*>/', '', basename($orig)) |
|
| 149 | - )) |
|
| 150 | - ); |
|
| 151 | - |
|
| 152 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 153 | - // pour les images transformees par rotation (action/documenter) |
|
| 154 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 155 | - |
|
| 156 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 157 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 158 | - return $source; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 162 | - $n = 0; |
|
| 163 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 164 | - ; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return deplacer_fichier_upload($source, $newFile); |
|
| 140 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 141 | + $dir = creer_repertoire_documents($subdir ? $subdir : $ext); |
|
| 142 | + $dest = preg_replace( |
|
| 143 | + '/[^.=\w-]+/', |
|
| 144 | + '_', |
|
| 145 | + translitteration(preg_replace( |
|
| 146 | + '/\.([^.]+)$/', |
|
| 147 | + '', |
|
| 148 | + preg_replace('/<[^>]*>/', '', basename($orig)) |
|
| 149 | + )) |
|
| 150 | + ); |
|
| 151 | + |
|
| 152 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 153 | + // pour les images transformees par rotation (action/documenter) |
|
| 154 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 155 | + |
|
| 156 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 157 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 158 | + return $source; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 162 | + $n = 0; |
|
| 163 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 164 | + ; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return deplacer_fichier_upload($source, $newFile); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -179,28 +179,28 @@ discard block |
||
| 179 | 179 | * @return bool|string |
| 180 | 180 | */ |
| 181 | 181 | function determine_upload($type = '') { |
| 182 | - if (!function_exists('autoriser')) { |
|
| 183 | - include_spip('inc/autoriser'); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - if ( |
|
| 187 | - !autoriser('chargerftp') |
|
| 188 | - or $type == 'logos' |
|
| 189 | - ) { # on ne le permet pas pour les logos |
|
| 190 | - return false; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - $repertoire = _DIR_TRANSFERT; |
|
| 194 | - if (!@is_dir($repertoire)) { |
|
| 195 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 196 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 200 | - return $repertoire; |
|
| 201 | - } else { |
|
| 202 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 203 | - } |
|
| 182 | + if (!function_exists('autoriser')) { |
|
| 183 | + include_spip('inc/autoriser'); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + if ( |
|
| 187 | + !autoriser('chargerftp') |
|
| 188 | + or $type == 'logos' |
|
| 189 | + ) { # on ne le permet pas pour les logos |
|
| 190 | + return false; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + $repertoire = _DIR_TRANSFERT; |
|
| 194 | + if (!@is_dir($repertoire)) { |
|
| 195 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 196 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 200 | + return $repertoire; |
|
| 201 | + } else { |
|
| 202 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 203 | + } |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -219,35 +219,35 @@ discard block |
||
| 219 | 219 | * @return bool|mixed|string |
| 220 | 220 | */ |
| 221 | 221 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 222 | - // Securite |
|
| 223 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 224 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 225 | - } else { |
|
| 226 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if ($move) { |
|
| 230 | - $ok = @rename($source, $dest); |
|
| 231 | - } else { |
|
| 232 | - $ok = @copy($source, $dest); |
|
| 233 | - } |
|
| 234 | - if (!$ok) { |
|
| 235 | - $ok = @move_uploaded_file($source, $dest); |
|
| 236 | - } |
|
| 237 | - if ($ok) { |
|
| 238 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 239 | - } else { |
|
| 240 | - $f = @fopen($dest, 'w'); |
|
| 241 | - if ($f) { |
|
| 242 | - fclose($f); |
|
| 243 | - } else { |
|
| 244 | - include_spip('inc/flock'); |
|
| 245 | - raler_fichier($dest); |
|
| 246 | - } |
|
| 247 | - spip_unlink($dest); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $ok ? $dest : false; |
|
| 222 | + // Securite |
|
| 223 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 224 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 225 | + } else { |
|
| 226 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if ($move) { |
|
| 230 | + $ok = @rename($source, $dest); |
|
| 231 | + } else { |
|
| 232 | + $ok = @copy($source, $dest); |
|
| 233 | + } |
|
| 234 | + if (!$ok) { |
|
| 235 | + $ok = @move_uploaded_file($source, $dest); |
|
| 236 | + } |
|
| 237 | + if ($ok) { |
|
| 238 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 239 | + } else { |
|
| 240 | + $f = @fopen($dest, 'w'); |
|
| 241 | + if ($f) { |
|
| 242 | + fclose($f); |
|
| 243 | + } else { |
|
| 244 | + include_spip('inc/flock'); |
|
| 245 | + raler_fichier($dest); |
|
| 246 | + } |
|
| 247 | + spip_unlink($dest); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $ok ? $dest : false; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -271,58 +271,58 @@ discard block |
||
| 271 | 271 | */ |
| 272 | 272 | function check_upload_error($error, $msg = '', $return = false) { |
| 273 | 273 | |
| 274 | - if (!$error) { |
|
| 275 | - return false; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 279 | - |
|
| 280 | - switch ($error) { |
|
| 281 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 282 | - return true; |
|
| 283 | - |
|
| 284 | - # on peut affiner les differents messages d'erreur |
|
| 285 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 286 | - $msg = _T( |
|
| 287 | - 'upload_limit', |
|
| 288 | - ['max' => ini_get('upload_max_filesize')] |
|
| 289 | - ); |
|
| 290 | - break; |
|
| 291 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 292 | - $msg = _T( |
|
| 293 | - 'upload_limit', |
|
| 294 | - ['max' => ini_get('upload_max_filesize')] |
|
| 295 | - ); |
|
| 296 | - break; |
|
| 297 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 298 | - $msg = _T( |
|
| 299 | - 'upload_limit', |
|
| 300 | - ['max' => ini_get('upload_max_filesize')] |
|
| 301 | - ); |
|
| 302 | - break; |
|
| 303 | - |
|
| 304 | - default: /* autre */ |
|
| 305 | - if (!$msg) { |
|
| 306 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 307 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 308 | - } |
|
| 309 | - break; |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - spip_log("erreur upload $error"); |
|
| 313 | - if ($return) { |
|
| 314 | - return $msg; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - if (_request('iframe') == 'iframe') { |
|
| 318 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 319 | - exit; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - include_spip('inc/minipres'); |
|
| 323 | - echo minipres( |
|
| 324 | - $msg, |
|
| 325 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 326 | - ); |
|
| 327 | - exit; |
|
| 274 | + if (!$error) { |
|
| 275 | + return false; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 279 | + |
|
| 280 | + switch ($error) { |
|
| 281 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 282 | + return true; |
|
| 283 | + |
|
| 284 | + # on peut affiner les differents messages d'erreur |
|
| 285 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 286 | + $msg = _T( |
|
| 287 | + 'upload_limit', |
|
| 288 | + ['max' => ini_get('upload_max_filesize')] |
|
| 289 | + ); |
|
| 290 | + break; |
|
| 291 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 292 | + $msg = _T( |
|
| 293 | + 'upload_limit', |
|
| 294 | + ['max' => ini_get('upload_max_filesize')] |
|
| 295 | + ); |
|
| 296 | + break; |
|
| 297 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 298 | + $msg = _T( |
|
| 299 | + 'upload_limit', |
|
| 300 | + ['max' => ini_get('upload_max_filesize')] |
|
| 301 | + ); |
|
| 302 | + break; |
|
| 303 | + |
|
| 304 | + default: /* autre */ |
|
| 305 | + if (!$msg) { |
|
| 306 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 307 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 308 | + } |
|
| 309 | + break; |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + spip_log("erreur upload $error"); |
|
| 313 | + if ($return) { |
|
| 314 | + return $msg; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + if (_request('iframe') == 'iframe') { |
|
| 318 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 319 | + exit; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + include_spip('inc/minipres'); |
|
| 323 | + echo minipres( |
|
| 324 | + $msg, |
|
| 325 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 326 | + ); |
|
| 327 | + exit; |
|
| 328 | 328 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -38,70 +38,70 @@ discard block |
||
| 38 | 38 | * @return array|string |
| 39 | 39 | */ |
| 40 | 40 | function inc_couleurs_dist($choix = null, $ajouter = false) { |
| 41 | - static $couleurs_spip = [ |
|
| 42 | - // Violet soutenu |
|
| 43 | - 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 44 | - // Violet rosé |
|
| 45 | - 4 => ['couleur_theme' => '#c464cb'], |
|
| 46 | - // Rose interface SPIP |
|
| 47 | - 2 => ['couleur_theme' => '#F02364'], |
|
| 48 | - // Rouge |
|
| 49 | - 8 => ['couleur_theme' => '#ff4524'], |
|
| 50 | - // Orange |
|
| 51 | - 3 => ['couleur_theme' => '#c97500'], |
|
| 52 | - // Vert SPIP |
|
| 53 | - 1 => ['couleur_theme' => '#9dba00'], |
|
| 54 | - // Vert Troglo |
|
| 55 | - 7 => ['couleur_theme' => '#419a2c'], |
|
| 56 | - // Bleu-vert |
|
| 57 | - 12 => ['couleur_theme' => '#269681'], |
|
| 58 | - // Bleu pastel |
|
| 59 | - 5 => ['couleur_theme' => '#3190ae'], |
|
| 60 | - // Bleu Kermesse |
|
| 61 | - 11 => ['couleur_theme' => '#288bdd'], |
|
| 62 | - // Gris bleuté |
|
| 63 | - 6 => ['couleur_theme' => '#7d90a2'], |
|
| 64 | - // Gris |
|
| 65 | - 10 => ['couleur_theme' => '#909090'], |
|
| 66 | - ]; |
|
| 41 | + static $couleurs_spip = [ |
|
| 42 | + // Violet soutenu |
|
| 43 | + 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 44 | + // Violet rosé |
|
| 45 | + 4 => ['couleur_theme' => '#c464cb'], |
|
| 46 | + // Rose interface SPIP |
|
| 47 | + 2 => ['couleur_theme' => '#F02364'], |
|
| 48 | + // Rouge |
|
| 49 | + 8 => ['couleur_theme' => '#ff4524'], |
|
| 50 | + // Orange |
|
| 51 | + 3 => ['couleur_theme' => '#c97500'], |
|
| 52 | + // Vert SPIP |
|
| 53 | + 1 => ['couleur_theme' => '#9dba00'], |
|
| 54 | + // Vert Troglo |
|
| 55 | + 7 => ['couleur_theme' => '#419a2c'], |
|
| 56 | + // Bleu-vert |
|
| 57 | + 12 => ['couleur_theme' => '#269681'], |
|
| 58 | + // Bleu pastel |
|
| 59 | + 5 => ['couleur_theme' => '#3190ae'], |
|
| 60 | + // Bleu Kermesse |
|
| 61 | + 11 => ['couleur_theme' => '#288bdd'], |
|
| 62 | + // Gris bleuté |
|
| 63 | + 6 => ['couleur_theme' => '#7d90a2'], |
|
| 64 | + // Gris |
|
| 65 | + 10 => ['couleur_theme' => '#909090'], |
|
| 66 | + ]; |
|
| 67 | 67 | |
| 68 | - if (is_numeric($choix)) { |
|
| 69 | - $c = $couleurs_spip[$choix]; |
|
| 70 | - // compat < SPIP 3.3 |
|
| 71 | - include_spip('inc/filtres_images_mini'); |
|
| 72 | - $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 73 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 68 | + if (is_numeric($choix)) { |
|
| 69 | + $c = $couleurs_spip[$choix]; |
|
| 70 | + // compat < SPIP 3.3 |
|
| 71 | + include_spip('inc/filtres_images_mini'); |
|
| 72 | + $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 73 | + $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 74 | 74 | |
| 75 | - return |
|
| 76 | - 'couleur_theme=' . substr($c['couleur_theme'], 1) |
|
| 77 | - // compat < SPIP 3.3 |
|
| 78 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 79 | - . '&couleur_foncee=' . substr($c['couleur_foncee'], 1); |
|
| 80 | - } else { |
|
| 81 | - if (is_array($choix)) { |
|
| 82 | - // compat < SPIP 3.3 |
|
| 83 | - $compat_spip_33 = function ($c) { |
|
| 84 | - if (!isset($c['couleur_theme'])) { |
|
| 85 | - $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 86 | - unset($c['couleur_foncee']); |
|
| 87 | - unset($c['couleur_claire']); |
|
| 88 | - unset($c['couleur_lien']); |
|
| 89 | - unset($c['couleur_lien_off']); |
|
| 90 | - } |
|
| 91 | - return $c; |
|
| 92 | - }; |
|
| 93 | - if ($ajouter) { |
|
| 94 | - foreach ($choix as $c) { |
|
| 95 | - $couleurs_spip[] = $compat_spip_33($c); |
|
| 96 | - } |
|
| 75 | + return |
|
| 76 | + 'couleur_theme=' . substr($c['couleur_theme'], 1) |
|
| 77 | + // compat < SPIP 3.3 |
|
| 78 | + . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 79 | + . '&couleur_foncee=' . substr($c['couleur_foncee'], 1); |
|
| 80 | + } else { |
|
| 81 | + if (is_array($choix)) { |
|
| 82 | + // compat < SPIP 3.3 |
|
| 83 | + $compat_spip_33 = function ($c) { |
|
| 84 | + if (!isset($c['couleur_theme'])) { |
|
| 85 | + $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 86 | + unset($c['couleur_foncee']); |
|
| 87 | + unset($c['couleur_claire']); |
|
| 88 | + unset($c['couleur_lien']); |
|
| 89 | + unset($c['couleur_lien_off']); |
|
| 90 | + } |
|
| 91 | + return $c; |
|
| 92 | + }; |
|
| 93 | + if ($ajouter) { |
|
| 94 | + foreach ($choix as $c) { |
|
| 95 | + $couleurs_spip[] = $compat_spip_33($c); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - return $couleurs_spip; |
|
| 99 | - } else { |
|
| 100 | - $choix = array_map($compat_spip_33, $choix); |
|
| 101 | - return $couleurs_spip = $choix; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 98 | + return $couleurs_spip; |
|
| 99 | + } else { |
|
| 100 | + $choix = array_map($compat_spip_33, $choix); |
|
| 101 | + return $couleurs_spip = $choix; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - return $couleurs_spip; |
|
| 106 | + return $couleurs_spip; |
|
| 107 | 107 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | * - ou tableau d'information sur le squelette. |
| 37 | 37 | */ |
| 38 | 38 | function inc_iconifier_dist($objet, $id, $script, $visible = false, $flag_modif = true) { |
| 39 | - // compat avec anciens appels |
|
| 40 | - $objet = objet_type($objet); |
|
| 39 | + // compat avec anciens appels |
|
| 40 | + $objet = objet_type($objet); |
|
| 41 | 41 | |
| 42 | - return recuperer_fond( |
|
| 43 | - 'prive/objets/editer/logo', |
|
| 44 | - ['objet' => $objet, 'id_objet' => $id, 'editable' => $flag_modif] |
|
| 45 | - ); |
|
| 42 | + return recuperer_fond( |
|
| 43 | + 'prive/objets/editer/logo', |
|
| 44 | + ['objet' => $objet, 'id_objet' => $id, 'editable' => $flag_modif] |
|
| 45 | + ); |
|
| 46 | 46 | } |