@@ -11,129 +11,129 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Decompilation de l'arbre de syntaxe abstraite d'un squelette SPIP |
| 18 | 18 | |
| 19 | 19 | function decompiler_boucle($struct, $fmt = '', $prof = 0) { |
| 20 | - $nom = $struct->id_boucle; |
|
| 21 | - $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | - $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | - $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | - $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | - |
|
| 28 | - $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | - $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | - |
|
| 31 | - if ($struct->jointures_explicites) { |
|
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | - } |
|
| 34 | - if ($struct->table_optionnelle) { |
|
| 35 | - $type .= '?'; |
|
| 36 | - } |
|
| 37 | - // Revoir le cas de la boucle recursive |
|
| 38 | - |
|
| 39 | - $crit = $struct->param; |
|
| 40 | - if ($crit and !is_array($crit[0])) { |
|
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 42 | - } |
|
| 43 | - $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | - |
|
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 46 | - |
|
| 47 | - return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 20 | + $nom = $struct->id_boucle; |
|
| 21 | + $preaff = decompiler_($struct->preaff, $fmt, $prof); |
|
| 22 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 23 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 24 | + $altern = decompiler_($struct->altern, $fmt, $prof); |
|
| 25 | + $milieu = decompiler_($struct->milieu, $fmt, $prof); |
|
| 26 | + $postaff = decompiler_($struct->postaff, $fmt, $prof); |
|
| 27 | + |
|
| 28 | + $type = $struct->sql_serveur ? "$struct->sql_serveur:" : ''; |
|
| 29 | + $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
|
| 30 | + |
|
| 31 | + if ($struct->jointures_explicites) { |
|
| 32 | + $type .= ' ' . $struct->jointures_explicites; |
|
| 33 | + } |
|
| 34 | + if ($struct->table_optionnelle) { |
|
| 35 | + $type .= '?'; |
|
| 36 | + } |
|
| 37 | + // Revoir le cas de la boucle recursive |
|
| 38 | + |
|
| 39 | + $crit = $struct->param; |
|
| 40 | + if ($crit and !is_array($crit[0])) { |
|
| 41 | + $type = strtolower($type) . array_shift($crit); |
|
| 42 | + } |
|
| 43 | + $crit = decompiler_criteres($struct, $fmt, $prof); |
|
| 44 | + |
|
| 45 | + $f = 'format_boucle_' . $fmt; |
|
| 46 | + |
|
| 47 | + return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | function decompiler_include($struct, $fmt = '', $prof = 0) { |
| 51 | - $res = []; |
|
| 52 | - foreach ($struct->param ?: [] as $couple) { |
|
| 53 | - array_shift($couple); |
|
| 54 | - foreach ($couple as $v) { |
|
| 55 | - $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 61 | - |
|
| 62 | - return $f($file, $res, $prof); |
|
| 51 | + $res = []; |
|
| 52 | + foreach ($struct->param ?: [] as $couple) { |
|
| 53 | + array_shift($couple); |
|
| 54 | + foreach ($couple as $v) { |
|
| 55 | + $res[] = decompiler_($v, $fmt, $prof); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | + decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | + $f = 'format_inclure_' . $fmt; |
|
| 61 | + |
|
| 62 | + return $f($file, $res, $prof); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 66 | + $f = 'format_texte_' . $fmt; |
|
| 67 | 67 | |
| 68 | - return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 68 | + return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 72 | + $f = 'format_polyglotte_' . $fmt; |
|
| 73 | 73 | |
| 74 | - return $f($struct->traductions, $prof); |
|
| 74 | + return $f($struct->traductions, $prof); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | function decompiler_idiome($struct, $fmt = '', $prof = 0) { |
| 78 | - $args = []; |
|
| 79 | - foreach ($struct->arg as $k => $v) { |
|
| 80 | - $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | - } |
|
| 78 | + $args = []; |
|
| 79 | + foreach ($struct->arg as $k => $v) { |
|
| 80 | + $args[$k] = public_decompiler($v, $fmt, $prof); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 83 | + $filtres = decompiler_liste($struct->param, $fmt, $prof); |
|
| 84 | 84 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 85 | + $f = 'format_idiome_' . $fmt; |
|
| 86 | 86 | |
| 87 | - return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 87 | + return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | function decompiler_champ($struct, $fmt = '', $prof = 0) { |
| 91 | - $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | - $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | - $args = $filtres = ''; |
|
| 94 | - if ($p = $struct->param) { |
|
| 95 | - if ($p[0][0] === '') { |
|
| 96 | - $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | - } |
|
| 98 | - $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | - } |
|
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 101 | - |
|
| 102 | - return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 91 | + $avant = decompiler_($struct->avant, $fmt, $prof); |
|
| 92 | + $apres = decompiler_($struct->apres, $fmt, $prof); |
|
| 93 | + $args = $filtres = ''; |
|
| 94 | + if ($p = $struct->param) { |
|
| 95 | + if ($p[0][0] === '') { |
|
| 96 | + $args = decompiler_liste([array_shift($p)], $fmt, $prof); |
|
| 97 | + } |
|
| 98 | + $filtres = decompiler_liste($p, $fmt, $prof); |
|
| 99 | + } |
|
| 100 | + $f = 'format_champ_' . $fmt; |
|
| 101 | + |
|
| 102 | + return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | function decompiler_liste($sources, $fmt = '', $prof = 0) { |
| 106 | - if (!is_array($sources)) { |
|
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 110 | - $res = ''; |
|
| 111 | - foreach ($sources as $arg) { |
|
| 112 | - if (!is_array($arg)) { |
|
| 113 | - continue; // ne devrait pas arriver. |
|
| 114 | - } else { |
|
| 115 | - $r = array_shift($arg); |
|
| 116 | - } |
|
| 117 | - $args = []; |
|
| 118 | - foreach ($arg as $v) { |
|
| 119 | - // cas des arguments entoures de ' ou " |
|
| 120 | - if ( |
|
| 121 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | - and $v[0]->type == 'texte' |
|
| 123 | - and (strlen($v[0]->apres) == 1) |
|
| 124 | - and $v[0]->apres == $v[0]->avant |
|
| 125 | - ) { |
|
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | - } else { |
|
| 128 | - $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (($r !== '') or $args) { |
|
| 132 | - $res .= $f($r, $args, $prof); |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - return $res; |
|
| 106 | + if (!is_array($sources)) { |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + $f = 'format_liste_' . $fmt; |
|
| 110 | + $res = ''; |
|
| 111 | + foreach ($sources as $arg) { |
|
| 112 | + if (!is_array($arg)) { |
|
| 113 | + continue; // ne devrait pas arriver. |
|
| 114 | + } else { |
|
| 115 | + $r = array_shift($arg); |
|
| 116 | + } |
|
| 117 | + $args = []; |
|
| 118 | + foreach ($arg as $v) { |
|
| 119 | + // cas des arguments entoures de ' ou " |
|
| 120 | + if ( |
|
| 121 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 122 | + and $v[0]->type == 'texte' |
|
| 123 | + and (strlen($v[0]->apres) == 1) |
|
| 124 | + and $v[0]->apres == $v[0]->avant |
|
| 125 | + ) { |
|
| 126 | + $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 127 | + } else { |
|
| 128 | + $args[] = decompiler_($v, $fmt, 0 - $prof); |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (($r !== '') or $args) { |
|
| 132 | + $res .= $f($r, $args, $prof); |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + return $res; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // Decompilation des criteres: on triche et on deroge: |
@@ -141,93 +141,93 @@ discard block |
||
| 141 | 141 | // - le champ apres signale le critere {"separateur"} ou {'separateur'} |
| 142 | 142 | // - les champs sont implicitement etendus (crochets implicites mais interdits) |
| 143 | 143 | function decompiler_criteres($boucle, $fmt = '', $prof = 0) { |
| 144 | - $sources = $boucle->param; |
|
| 145 | - if (!is_array($sources)) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 148 | - $res = ''; |
|
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 150 | - foreach ($sources as $crit) { |
|
| 151 | - if (!is_array($crit)) { |
|
| 152 | - continue; |
|
| 153 | - } // boucle recursive |
|
| 154 | - array_shift($crit); |
|
| 155 | - $args = []; |
|
| 156 | - foreach ($crit as $i => $v) { |
|
| 157 | - if ( |
|
| 158 | - ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | - and $v[0]->type == 'texte' |
|
| 160 | - and $v[0]->apres |
|
| 161 | - ) { |
|
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | - } else { |
|
| 164 | - $res2 = []; |
|
| 165 | - foreach ($v as $k => $p) { |
|
| 166 | - if ( |
|
| 167 | - isset($p->type) |
|
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | - ) { |
|
| 170 | - $r = $d($p, $fmt, (0 - $prof)); |
|
| 171 | - $res2[] = [$p->type, $r]; |
|
| 172 | - } else { |
|
| 173 | - spip_log("critere $i / $k mal forme"); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - $args[] = $res2; |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $res .= $f($args); |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return $res; |
|
| 144 | + $sources = $boucle->param; |
|
| 145 | + if (!is_array($sources)) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | + $res = ''; |
|
| 149 | + $f = 'format_critere_' . $fmt; |
|
| 150 | + foreach ($sources as $crit) { |
|
| 151 | + if (!is_array($crit)) { |
|
| 152 | + continue; |
|
| 153 | + } // boucle recursive |
|
| 154 | + array_shift($crit); |
|
| 155 | + $args = []; |
|
| 156 | + foreach ($crit as $i => $v) { |
|
| 157 | + if ( |
|
| 158 | + ((is_countable($v) ? count($v) : 0) == 1) |
|
| 159 | + and $v[0]->type == 'texte' |
|
| 160 | + and $v[0]->apres |
|
| 161 | + ) { |
|
| 162 | + $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 163 | + } else { |
|
| 164 | + $res2 = []; |
|
| 165 | + foreach ($v as $k => $p) { |
|
| 166 | + if ( |
|
| 167 | + isset($p->type) |
|
| 168 | + and function_exists($d = 'decompiler_' . $p->type) |
|
| 169 | + ) { |
|
| 170 | + $r = $d($p, $fmt, (0 - $prof)); |
|
| 171 | + $res2[] = [$p->type, $r]; |
|
| 172 | + } else { |
|
| 173 | + spip_log("critere $i / $k mal forme"); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + $args[] = $res2; |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $res .= $f($args); |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return $res; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | 186 | function decompiler_($liste, $fmt = '', $prof = 0) { |
| 187 | - if (!is_array($liste)) { |
|
| 188 | - return ''; |
|
| 189 | - } |
|
| 190 | - $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | - $contenu = []; |
|
| 192 | - foreach ($liste as $k => $p) { |
|
| 193 | - if (!isset($p->type)) { |
|
| 194 | - continue; |
|
| 195 | - } #?????? |
|
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 197 | - $next = $liste[$k + 1] ?? false; |
|
| 198 | - // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | - // contenait des args et s'il est suivi d'espaces, |
|
| 200 | - // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | - |
|
| 202 | - if ( |
|
| 203 | - $next |
|
| 204 | - and ($next->type == 'texte') |
|
| 205 | - and $p->type == 'champ' |
|
| 206 | - and !$p->apres |
|
| 207 | - and !$p->avant |
|
| 208 | - and $p->fonctions |
|
| 209 | - ) { |
|
| 210 | - $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | - if ($n) { |
|
| 212 | - $champ = new Texte(); |
|
| 213 | - $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | - $champ->ligne = $p->ligne; |
|
| 215 | - $p->apres = [$champ]; |
|
| 216 | - $next->texte = substr($next->texte, $n); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | - } |
|
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 222 | - |
|
| 223 | - return $f($contenu); |
|
| 187 | + if (!is_array($liste)) { |
|
| 188 | + return ''; |
|
| 189 | + } |
|
| 190 | + $prof2 = ($prof < 0) ? ($prof - 1) : ($prof + 1); |
|
| 191 | + $contenu = []; |
|
| 192 | + foreach ($liste as $k => $p) { |
|
| 193 | + if (!isset($p->type)) { |
|
| 194 | + continue; |
|
| 195 | + } #?????? |
|
| 196 | + $d = 'decompiler_' . $p->type; |
|
| 197 | + $next = $liste[$k + 1] ?? false; |
|
| 198 | + // Forcer le champ etendu si son source (pas les reecritures) |
|
| 199 | + // contenait des args et s'il est suivi d'espaces, |
|
| 200 | + // le champ simple les eliminant est un bug helas perenne. |
|
| 201 | + |
|
| 202 | + if ( |
|
| 203 | + $next |
|
| 204 | + and ($next->type == 'texte') |
|
| 205 | + and $p->type == 'champ' |
|
| 206 | + and !$p->apres |
|
| 207 | + and !$p->avant |
|
| 208 | + and $p->fonctions |
|
| 209 | + ) { |
|
| 210 | + $n = strlen($next->texte) - strlen(ltrim($next->texte)); |
|
| 211 | + if ($n) { |
|
| 212 | + $champ = new Texte(); |
|
| 213 | + $champ->texte = substr($next->texte, 0, $n); |
|
| 214 | + $champ->ligne = $p->ligne; |
|
| 215 | + $p->apres = [$champ]; |
|
| 216 | + $next->texte = substr($next->texte, $n); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
|
| 220 | + } |
|
| 221 | + $f = 'format_suite_' . $fmt; |
|
| 222 | + |
|
| 223 | + return $f($contenu); |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | - return "'$fmt'?"; |
|
| 229 | - } |
|
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 227 | + if (!include_spip('public/format_' . $fmt)) { |
|
| 228 | + return "'$fmt'?"; |
|
| 229 | + } |
|
| 230 | + $f = 'decompiler_' . $quoi; |
|
| 231 | 231 | |
| 232 | - return $f($liste, $fmt, $prof); |
|
| 232 | + return $f($liste, $fmt, $prof); |
|
| 233 | 233 | } |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | $type .= ($struct->type_requete ?: $struct->table_optionnelle); |
| 30 | 30 | |
| 31 | 31 | if ($struct->jointures_explicites) { |
| 32 | - $type .= ' ' . $struct->jointures_explicites; |
|
| 32 | + $type .= ' '.$struct->jointures_explicites; |
|
| 33 | 33 | } |
| 34 | 34 | if ($struct->table_optionnelle) { |
| 35 | 35 | $type .= '?'; |
@@ -38,11 +38,11 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | $crit = $struct->param; |
| 40 | 40 | if ($crit and !is_array($crit[0])) { |
| 41 | - $type = strtolower($type) . array_shift($crit); |
|
| 41 | + $type = strtolower($type).array_shift($crit); |
|
| 42 | 42 | } |
| 43 | 43 | $crit = decompiler_criteres($struct, $fmt, $prof); |
| 44 | 44 | |
| 45 | - $f = 'format_boucle_' . $fmt; |
|
| 45 | + $f = 'format_boucle_'.$fmt; |
|
| 46 | 46 | |
| 47 | 47 | return $f($preaff, $avant, $nom, $type, $crit, $milieu, $apres, $altern, $postaff, $prof); |
| 48 | 48 | } |
@@ -55,21 +55,20 @@ discard block |
||
| 55 | 55 | $res[] = decompiler_($v, $fmt, $prof); |
| 56 | 56 | } |
| 57 | 57 | } |
| 58 | - $file = is_string($struct->texte) ? $struct->texte : |
|
| 59 | - decompiler_($struct->texte, $fmt, $prof); |
|
| 60 | - $f = 'format_inclure_' . $fmt; |
|
| 58 | + $file = is_string($struct->texte) ? $struct->texte : decompiler_($struct->texte, $fmt, $prof); |
|
| 59 | + $f = 'format_inclure_'.$fmt; |
|
| 61 | 60 | |
| 62 | 61 | return $f($file, $res, $prof); |
| 63 | 62 | } |
| 64 | 63 | |
| 65 | 64 | function decompiler_texte($struct, $fmt = '', $prof = 0) { |
| 66 | - $f = 'format_texte_' . $fmt; |
|
| 65 | + $f = 'format_texte_'.$fmt; |
|
| 67 | 66 | |
| 68 | 67 | return strlen($struct->texte) ? $f($struct->texte, $prof) : ''; |
| 69 | 68 | } |
| 70 | 69 | |
| 71 | 70 | function decompiler_polyglotte($struct, $fmt = '', $prof = 0) { |
| 72 | - $f = 'format_polyglotte_' . $fmt; |
|
| 71 | + $f = 'format_polyglotte_'.$fmt; |
|
| 73 | 72 | |
| 74 | 73 | return $f($struct->traductions, $prof); |
| 75 | 74 | } |
@@ -82,7 +81,7 @@ discard block |
||
| 82 | 81 | |
| 83 | 82 | $filtres = decompiler_liste($struct->param, $fmt, $prof); |
| 84 | 83 | |
| 85 | - $f = 'format_idiome_' . $fmt; |
|
| 84 | + $f = 'format_idiome_'.$fmt; |
|
| 86 | 85 | |
| 87 | 86 | return $f($struct->nom_champ, $struct->module, $args, $filtres, $prof); |
| 88 | 87 | } |
@@ -97,7 +96,7 @@ discard block |
||
| 97 | 96 | } |
| 98 | 97 | $filtres = decompiler_liste($p, $fmt, $prof); |
| 99 | 98 | } |
| 100 | - $f = 'format_champ_' . $fmt; |
|
| 99 | + $f = 'format_champ_'.$fmt; |
|
| 101 | 100 | |
| 102 | 101 | return $f($struct->nom_champ, $struct->nom_boucle, $struct->etoile, $avant, $apres, $args, $filtres, $prof); |
| 103 | 102 | } |
@@ -106,7 +105,7 @@ discard block |
||
| 106 | 105 | if (!is_array($sources)) { |
| 107 | 106 | return ''; |
| 108 | 107 | } |
| 109 | - $f = 'format_liste_' . $fmt; |
|
| 108 | + $f = 'format_liste_'.$fmt; |
|
| 110 | 109 | $res = ''; |
| 111 | 110 | foreach ($sources as $arg) { |
| 112 | 111 | if (!is_array($arg)) { |
@@ -123,7 +122,7 @@ discard block |
||
| 123 | 122 | and (strlen($v[0]->apres) == 1) |
| 124 | 123 | and $v[0]->apres == $v[0]->avant |
| 125 | 124 | ) { |
| 126 | - $args[] = $v[0]->avant . $v[0]->texte . $v[0]->apres; |
|
| 125 | + $args[] = $v[0]->avant.$v[0]->texte.$v[0]->apres; |
|
| 127 | 126 | } else { |
| 128 | 127 | $args[] = decompiler_($v, $fmt, 0 - $prof); |
| 129 | 128 | } |
@@ -146,7 +145,7 @@ discard block |
||
| 146 | 145 | return ''; |
| 147 | 146 | } |
| 148 | 147 | $res = ''; |
| 149 | - $f = 'format_critere_' . $fmt; |
|
| 148 | + $f = 'format_critere_'.$fmt; |
|
| 150 | 149 | foreach ($sources as $crit) { |
| 151 | 150 | if (!is_array($crit)) { |
| 152 | 151 | continue; |
@@ -159,13 +158,13 @@ discard block |
||
| 159 | 158 | and $v[0]->type == 'texte' |
| 160 | 159 | and $v[0]->apres |
| 161 | 160 | ) { |
| 162 | - $args[] = [['texte', ($v[0]->apres . $v[0]->texte . $v[0]->apres)]]; |
|
| 161 | + $args[] = [['texte', ($v[0]->apres.$v[0]->texte.$v[0]->apres)]]; |
|
| 163 | 162 | } else { |
| 164 | 163 | $res2 = []; |
| 165 | 164 | foreach ($v as $k => $p) { |
| 166 | 165 | if ( |
| 167 | 166 | isset($p->type) |
| 168 | - and function_exists($d = 'decompiler_' . $p->type) |
|
| 167 | + and function_exists($d = 'decompiler_'.$p->type) |
|
| 169 | 168 | ) { |
| 170 | 169 | $r = $d($p, $fmt, (0 - $prof)); |
| 171 | 170 | $res2[] = [$p->type, $r]; |
@@ -193,7 +192,7 @@ discard block |
||
| 193 | 192 | if (!isset($p->type)) { |
| 194 | 193 | continue; |
| 195 | 194 | } #?????? |
| 196 | - $d = 'decompiler_' . $p->type; |
|
| 195 | + $d = 'decompiler_'.$p->type; |
|
| 197 | 196 | $next = $liste[$k + 1] ?? false; |
| 198 | 197 | // Forcer le champ etendu si son source (pas les reecritures) |
| 199 | 198 | // contenait des args et s'il est suivi d'espaces, |
@@ -218,16 +217,16 @@ discard block |
||
| 218 | 217 | } |
| 219 | 218 | $contenu[] = [$d($p, $fmt, $prof2), $p->type]; |
| 220 | 219 | } |
| 221 | - $f = 'format_suite_' . $fmt; |
|
| 220 | + $f = 'format_suite_'.$fmt; |
|
| 222 | 221 | |
| 223 | 222 | return $f($contenu); |
| 224 | 223 | } |
| 225 | 224 | |
| 226 | 225 | function public_decompiler($liste, $fmt = '', $prof = 0, $quoi = '') { |
| 227 | - if (!include_spip('public/format_' . $fmt)) { |
|
| 226 | + if (!include_spip('public/format_'.$fmt)) { |
|
| 228 | 227 | return "'$fmt'?"; |
| 229 | 228 | } |
| 230 | - $f = 'decompiler_' . $quoi; |
|
| 229 | + $f = 'decompiler_'.$quoi; |
|
| 231 | 230 | |
| 232 | 231 | return $f($liste, $fmt, $prof); |
| 233 | 232 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Queue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_JQ_SCHEDULED', 1); |
@@ -50,103 +50,103 @@ discard block |
||
| 50 | 50 | * id of job |
| 51 | 51 | */ |
| 52 | 52 | function queue_add_job( |
| 53 | - $function, |
|
| 54 | - $description, |
|
| 55 | - $arguments = [], |
|
| 56 | - $file = '', |
|
| 57 | - $no_duplicate = false, |
|
| 58 | - $time = 0, |
|
| 59 | - $priority = 0 |
|
| 53 | + $function, |
|
| 54 | + $description, |
|
| 55 | + $arguments = [], |
|
| 56 | + $file = '', |
|
| 57 | + $no_duplicate = false, |
|
| 58 | + $time = 0, |
|
| 59 | + $priority = 0 |
|
| 60 | 60 | ) { |
| 61 | - include_spip('base/abstract_sql'); |
|
| 62 | - |
|
| 63 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // serialiser les arguments |
|
| 69 | - $arguments = serialize($arguments); |
|
| 70 | - $md5args = md5($arguments); |
|
| 71 | - |
|
| 72 | - // si pas de date programee, des que possible |
|
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | - if (!$time) { |
|
| 75 | - $time = time(); |
|
| 76 | - $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | - } |
|
| 78 | - $date = date('Y-m-d H:i:s', $time); |
|
| 79 | - |
|
| 80 | - $set_job = [ |
|
| 81 | - 'fonction' => $function, |
|
| 82 | - 'descriptif' => $description, |
|
| 83 | - 'args' => $arguments, |
|
| 84 | - 'md5args' => $md5args, |
|
| 85 | - 'inclure' => $file, |
|
| 86 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | - 'date' => $date, |
|
| 88 | - 'status' => _JQ_SCHEDULED, |
|
| 89 | - ]; |
|
| 90 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | - // avec les memes args et file |
|
| 92 | - if ( |
|
| 93 | - $no_duplicate |
|
| 94 | - and |
|
| 95 | - $id_job = sql_getfetsel( |
|
| 96 | - 'id_job', |
|
| 97 | - 'spip_jobs', |
|
| 98 | - $duplicate_where = |
|
| 99 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | - ) |
|
| 103 | - ) { |
|
| 104 | - return $id_job; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | - // doit s'effacer |
|
| 111 | - if ( |
|
| 112 | - $no_duplicate |
|
| 113 | - and |
|
| 114 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | - ) { |
|
| 116 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | - |
|
| 118 | - return $id_prev; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | - |
|
| 124 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | - // qui coupe la valeur |
|
| 127 | - if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | - if ($args !== $arguments) { |
|
| 130 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | - $arguments, |
|
| 132 | - true |
|
| 133 | - ), 'queue'); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($id_job) { |
|
| 138 | - queue_update_next_job_time($time); |
|
| 139 | - } |
|
| 140 | - // si la mise en file d'attente du job echoue, |
|
| 141 | - // il ne faut pas perdre l'execution de la fonction |
|
| 142 | - // on la lance immediatement, c'est un fallback |
|
| 143 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | - $set_job['id_job'] = 0; |
|
| 146 | - queue_start_job($set_job); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $id_job; |
|
| 61 | + include_spip('base/abstract_sql'); |
|
| 62 | + |
|
| 63 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // serialiser les arguments |
|
| 69 | + $arguments = serialize($arguments); |
|
| 70 | + $md5args = md5($arguments); |
|
| 71 | + |
|
| 72 | + // si pas de date programee, des que possible |
|
| 73 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | + if (!$time) { |
|
| 75 | + $time = time(); |
|
| 76 | + $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | + } |
|
| 78 | + $date = date('Y-m-d H:i:s', $time); |
|
| 79 | + |
|
| 80 | + $set_job = [ |
|
| 81 | + 'fonction' => $function, |
|
| 82 | + 'descriptif' => $description, |
|
| 83 | + 'args' => $arguments, |
|
| 84 | + 'md5args' => $md5args, |
|
| 85 | + 'inclure' => $file, |
|
| 86 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | + 'date' => $date, |
|
| 88 | + 'status' => _JQ_SCHEDULED, |
|
| 89 | + ]; |
|
| 90 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | + // avec les memes args et file |
|
| 92 | + if ( |
|
| 93 | + $no_duplicate |
|
| 94 | + and |
|
| 95 | + $id_job = sql_getfetsel( |
|
| 96 | + 'id_job', |
|
| 97 | + 'spip_jobs', |
|
| 98 | + $duplicate_where = |
|
| 99 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | + ) |
|
| 103 | + ) { |
|
| 104 | + return $id_job; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | + // doit s'effacer |
|
| 111 | + if ( |
|
| 112 | + $no_duplicate |
|
| 113 | + and |
|
| 114 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | + ) { |
|
| 116 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | + |
|
| 118 | + return $id_prev; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | + |
|
| 124 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | + // qui coupe la valeur |
|
| 127 | + if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | + if ($args !== $arguments) { |
|
| 130 | + spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | + $arguments, |
|
| 132 | + true |
|
| 133 | + ), 'queue'); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($id_job) { |
|
| 138 | + queue_update_next_job_time($time); |
|
| 139 | + } |
|
| 140 | + // si la mise en file d'attente du job echoue, |
|
| 141 | + // il ne faut pas perdre l'execution de la fonction |
|
| 142 | + // on la lance immediatement, c'est un fallback |
|
| 143 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | + $set_job['id_job'] = 0; |
|
| 146 | + queue_start_job($set_job); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $id_job; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | 157 | function queue_purger() { |
| 158 | - include_spip('base/abstract_sql'); |
|
| 159 | - sql_delete('spip_jobs'); |
|
| 160 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | - include_spip('inc/genie'); |
|
| 162 | - genie_queue_watch_dist(); |
|
| 158 | + include_spip('base/abstract_sql'); |
|
| 159 | + sql_delete('spip_jobs'); |
|
| 160 | + sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | + include_spip('inc/genie'); |
|
| 162 | + genie_queue_watch_dist(); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -170,25 +170,25 @@ discard block |
||
| 170 | 170 | * @return int|bool |
| 171 | 171 | */ |
| 172 | 172 | function queue_remove_job($id_job) { |
| 173 | - include_spip('base/abstract_sql'); |
|
| 174 | - |
|
| 175 | - if ( |
|
| 176 | - $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | - ) { |
|
| 179 | - queue_unlink_job($id_job); |
|
| 180 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | - // relancer avec les nouveaux arguments de temps |
|
| 183 | - include_spip('inc/genie'); |
|
| 184 | - // relancer avec la periode prevue |
|
| 185 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | - } |
|
| 187 | - queue_update_next_job_time(); |
|
| 188 | - return $res; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 173 | + include_spip('base/abstract_sql'); |
|
| 174 | + |
|
| 175 | + if ( |
|
| 176 | + $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | + and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | + ) { |
|
| 179 | + queue_unlink_job($id_job); |
|
| 180 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | + // relancer avec les nouveaux arguments de temps |
|
| 183 | + include_spip('inc/genie'); |
|
| 184 | + // relancer avec la periode prevue |
|
| 185 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | + } |
|
| 187 | + queue_update_next_job_time(); |
|
| 188 | + return $res; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,18 +201,18 @@ discard block |
||
| 201 | 201 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 202 | 202 | */ |
| 203 | 203 | function queue_link_job($id_job, $objets) { |
| 204 | - include_spip('base/abstract_sql'); |
|
| 205 | - |
|
| 206 | - if (is_array($objets) and count($objets)) { |
|
| 207 | - if (is_array(reset($objets))) { |
|
| 208 | - foreach ($objets as $k => $o) { |
|
| 209 | - $objets[$k]['id_job'] = $id_job; |
|
| 210 | - } |
|
| 211 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | - } else { |
|
| 213 | - sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | - } |
|
| 215 | - } |
|
| 204 | + include_spip('base/abstract_sql'); |
|
| 205 | + |
|
| 206 | + if (is_array($objets) and count($objets)) { |
|
| 207 | + if (is_array(reset($objets))) { |
|
| 208 | + foreach ($objets as $k => $o) { |
|
| 209 | + $objets[$k]['id_job'] = $id_job; |
|
| 210 | + } |
|
| 211 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | + } else { |
|
| 213 | + sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * resultat du sql_delete |
| 225 | 225 | */ |
| 226 | 226 | function queue_unlink_job($id_job) { |
| 227 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 227 | + return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,36 +237,36 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function queue_start_job($row) { |
| 239 | 239 | |
| 240 | - // deserialiser les arguments |
|
| 241 | - $args = unserialize($row['args']); |
|
| 242 | - if (!is_array($args)) { |
|
| 243 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | - $args = []; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $fonction = $row['fonction']; |
|
| 248 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | - if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | - if ($f) { |
|
| 252 | - $fonction = $f; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - include_spip($inclure); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if (!function_exists($fonction)) { |
|
| 260 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | - |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | - $res = $fonction(...$args); |
|
| 267 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 268 | - |
|
| 269 | - return $res; |
|
| 240 | + // deserialiser les arguments |
|
| 241 | + $args = unserialize($row['args']); |
|
| 242 | + if (!is_array($args)) { |
|
| 243 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | + $args = []; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $fonction = $row['fonction']; |
|
| 248 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | + if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | + if ($f) { |
|
| 252 | + $fonction = $f; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + include_spip($inclure); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if (!function_exists($fonction)) { |
|
| 260 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | + |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | + $res = $fonction(...$args); |
|
| 267 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 268 | + |
|
| 269 | + return $res; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -293,89 +293,89 @@ discard block |
||
| 293 | 293 | * - true : une planification a été faite. |
| 294 | 294 | */ |
| 295 | 295 | function queue_schedule($force_jobs = null) { |
| 296 | - $time = time(); |
|
| 297 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 298 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 299 | - |
|
| 300 | - return; |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - // rien a faire si le prochain job est encore dans le futur |
|
| 304 | - if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 305 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 306 | - |
|
| 307 | - return; |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - include_spip('base/abstract_sql'); |
|
| 311 | - // on ne peut rien faire si pas de connexion SQL |
|
| 312 | - if (!spip_connect()) { |
|
| 313 | - return false; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 317 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 318 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 319 | - if (!$max_time) { |
|
| 320 | - $max_time = 5; |
|
| 321 | - } |
|
| 322 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 323 | - } |
|
| 324 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 325 | - |
|
| 326 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 327 | - |
|
| 328 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 329 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 330 | - } |
|
| 331 | - $nbj = 0; |
|
| 332 | - // attraper les jobs |
|
| 333 | - // dont la date est passee (echus en attente), |
|
| 334 | - // par ordre : |
|
| 335 | - // - de priorite |
|
| 336 | - // - de date |
|
| 337 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 338 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 339 | - if (is_array($force_jobs) and count($force_jobs)) { |
|
| 340 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 341 | - } else { |
|
| 342 | - $now = date('Y-m-d H:i:s', $time); |
|
| 343 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 347 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 348 | - do { |
|
| 349 | - if ($row = array_shift($res)) { |
|
| 350 | - $nbj++; |
|
| 351 | - // il faut un verrou, a base de sql_delete |
|
| 352 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 353 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 354 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 355 | - $row['status'] = _JQ_PENDING; |
|
| 356 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 357 | - sql_insertq('spip_jobs', $row); |
|
| 358 | - |
|
| 359 | - // on a la main sur le job : |
|
| 360 | - // l'executer |
|
| 361 | - $result = queue_start_job($row); |
|
| 362 | - |
|
| 363 | - $time = time(); |
|
| 364 | - queue_close_job($row, $time, $result); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 368 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 369 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 370 | - |
|
| 371 | - if ($row = array_shift($res)) { |
|
| 372 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 373 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 374 | - } else { |
|
| 375 | - queue_update_next_job_time(); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return true; |
|
| 296 | + $time = time(); |
|
| 297 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 298 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 299 | + |
|
| 300 | + return; |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + // rien a faire si le prochain job est encore dans le futur |
|
| 304 | + if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 305 | + spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 306 | + |
|
| 307 | + return; |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + include_spip('base/abstract_sql'); |
|
| 311 | + // on ne peut rien faire si pas de connexion SQL |
|
| 312 | + if (!spip_connect()) { |
|
| 313 | + return false; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 317 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 318 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 319 | + if (!$max_time) { |
|
| 320 | + $max_time = 5; |
|
| 321 | + } |
|
| 322 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 323 | + } |
|
| 324 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 325 | + |
|
| 326 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 327 | + |
|
| 328 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 329 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 330 | + } |
|
| 331 | + $nbj = 0; |
|
| 332 | + // attraper les jobs |
|
| 333 | + // dont la date est passee (echus en attente), |
|
| 334 | + // par ordre : |
|
| 335 | + // - de priorite |
|
| 336 | + // - de date |
|
| 337 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 338 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 339 | + if (is_array($force_jobs) and count($force_jobs)) { |
|
| 340 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 341 | + } else { |
|
| 342 | + $now = date('Y-m-d H:i:s', $time); |
|
| 343 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 347 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 348 | + do { |
|
| 349 | + if ($row = array_shift($res)) { |
|
| 350 | + $nbj++; |
|
| 351 | + // il faut un verrou, a base de sql_delete |
|
| 352 | + if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 353 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 354 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 355 | + $row['status'] = _JQ_PENDING; |
|
| 356 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 357 | + sql_insertq('spip_jobs', $row); |
|
| 358 | + |
|
| 359 | + // on a la main sur le job : |
|
| 360 | + // l'executer |
|
| 361 | + $result = queue_start_job($row); |
|
| 362 | + |
|
| 363 | + $time = time(); |
|
| 364 | + queue_close_job($row, $time, $result); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 368 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 369 | + spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 370 | + |
|
| 371 | + if ($row = array_shift($res)) { |
|
| 372 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 373 | + spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 374 | + } else { |
|
| 375 | + queue_update_next_job_time(); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return true; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -393,21 +393,21 @@ discard block |
||
| 393 | 393 | * @param int $result |
| 394 | 394 | */ |
| 395 | 395 | function queue_close_job(&$row, $time, $result = 0) { |
| 396 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 397 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 398 | - // relancer avec les nouveaux arguments de temps |
|
| 399 | - include_spip('inc/genie'); |
|
| 400 | - if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 401 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 402 | - } else // relancer avec la periode prevue |
|
| 403 | - { |
|
| 404 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - // purger ses liens eventuels avec des objets |
|
| 408 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 409 | - // supprimer le job fini |
|
| 410 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 396 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 397 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 398 | + // relancer avec les nouveaux arguments de temps |
|
| 399 | + include_spip('inc/genie'); |
|
| 400 | + if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 401 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 402 | + } else // relancer avec la periode prevue |
|
| 403 | + { |
|
| 404 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + // purger ses liens eventuels avec des objets |
|
| 408 | + sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 409 | + // supprimer le job fini |
|
| 410 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -417,10 +417,10 @@ discard block |
||
| 417 | 417 | * @uses queue_update_next_job_time() |
| 418 | 418 | */ |
| 419 | 419 | function queue_error_handler() { |
| 420 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 421 | - chdir(_ROOT_CWD); |
|
| 420 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 421 | + chdir(_ROOT_CWD); |
|
| 422 | 422 | |
| 423 | - queue_update_next_job_time(); |
|
| 423 | + queue_update_next_job_time(); |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -437,18 +437,18 @@ discard block |
||
| 437 | 437 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 438 | 438 | */ |
| 439 | 439 | function queue_is_cron_job($function, $inclure) { |
| 440 | - static $taches = null; |
|
| 441 | - if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 442 | - if (is_null($taches)) { |
|
| 443 | - include_spip('inc/genie'); |
|
| 444 | - $taches = taches_generales(); |
|
| 445 | - } |
|
| 446 | - if (isset($taches[$function])) { |
|
| 447 | - return $taches[$function]; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - return false; |
|
| 440 | + static $taches = null; |
|
| 441 | + if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 442 | + if (is_null($taches)) { |
|
| 443 | + include_spip('inc/genie'); |
|
| 444 | + $taches = taches_generales(); |
|
| 445 | + } |
|
| 446 | + if (isset($taches[$function])) { |
|
| 447 | + return $taches[$function]; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + return false; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -462,62 +462,62 @@ discard block |
||
| 462 | 462 | * temps de la tache ajoutee ou 0 pour ASAP |
| 463 | 463 | */ |
| 464 | 464 | function queue_update_next_job_time($next_time = null) { |
| 465 | - static $nb_jobs_scheduled = null; |
|
| 466 | - static $deja_la = false; |
|
| 467 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 468 | - static $next = null; |
|
| 469 | - // queue_close_job peut etre reentrant ici |
|
| 470 | - if ($deja_la) { |
|
| 471 | - return; |
|
| 472 | - } |
|
| 473 | - $deja_la = true; |
|
| 474 | - |
|
| 475 | - include_spip('base/abstract_sql'); |
|
| 476 | - $time = time(); |
|
| 477 | - |
|
| 478 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 479 | - // pour cause de timeout ou autre erreur fatale |
|
| 480 | - $res = sql_allfetsel( |
|
| 481 | - '*', |
|
| 482 | - 'spip_jobs', |
|
| 483 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 484 | - ); |
|
| 485 | - if (is_array($res)) { |
|
| 486 | - foreach ($res as $row) { |
|
| 487 | - queue_close_job($row, $time); |
|
| 488 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - // chercher la date du prochain job si pas connu |
|
| 493 | - if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 494 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 495 | - $next = strtotime($date); |
|
| 496 | - } |
|
| 497 | - if (!is_null($next_time)) { |
|
| 498 | - if (is_null($next) or $next > $next_time) { |
|
| 499 | - $next = $next_time; |
|
| 500 | - } |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - if ($next) { |
|
| 504 | - if (is_null($nb_jobs_scheduled)) { |
|
| 505 | - $nb_jobs_scheduled = sql_countsel( |
|
| 506 | - 'spip_jobs', |
|
| 507 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 508 | - ); |
|
| 509 | - } elseif ($next <= $time) { |
|
| 510 | - $nb_jobs_scheduled++; |
|
| 511 | - } |
|
| 512 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 513 | - // pour assurer le coup |
|
| 514 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 515 | - define('_DIRECT_CRON_FORCE', true); |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - queue_set_next_job_time($next); |
|
| 520 | - $deja_la = false; |
|
| 465 | + static $nb_jobs_scheduled = null; |
|
| 466 | + static $deja_la = false; |
|
| 467 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 468 | + static $next = null; |
|
| 469 | + // queue_close_job peut etre reentrant ici |
|
| 470 | + if ($deja_la) { |
|
| 471 | + return; |
|
| 472 | + } |
|
| 473 | + $deja_la = true; |
|
| 474 | + |
|
| 475 | + include_spip('base/abstract_sql'); |
|
| 476 | + $time = time(); |
|
| 477 | + |
|
| 478 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 479 | + // pour cause de timeout ou autre erreur fatale |
|
| 480 | + $res = sql_allfetsel( |
|
| 481 | + '*', |
|
| 482 | + 'spip_jobs', |
|
| 483 | + 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 484 | + ); |
|
| 485 | + if (is_array($res)) { |
|
| 486 | + foreach ($res as $row) { |
|
| 487 | + queue_close_job($row, $time); |
|
| 488 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + // chercher la date du prochain job si pas connu |
|
| 493 | + if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 494 | + $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 495 | + $next = strtotime($date); |
|
| 496 | + } |
|
| 497 | + if (!is_null($next_time)) { |
|
| 498 | + if (is_null($next) or $next > $next_time) { |
|
| 499 | + $next = $next_time; |
|
| 500 | + } |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + if ($next) { |
|
| 504 | + if (is_null($nb_jobs_scheduled)) { |
|
| 505 | + $nb_jobs_scheduled = sql_countsel( |
|
| 506 | + 'spip_jobs', |
|
| 507 | + 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 508 | + ); |
|
| 509 | + } elseif ($next <= $time) { |
|
| 510 | + $nb_jobs_scheduled++; |
|
| 511 | + } |
|
| 512 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 513 | + // pour assurer le coup |
|
| 514 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 515 | + define('_DIRECT_CRON_FORCE', true); |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + queue_set_next_job_time($next); |
|
| 520 | + $deja_la = false; |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | |
@@ -528,26 +528,26 @@ discard block |
||
| 528 | 528 | */ |
| 529 | 529 | function queue_set_next_job_time($next) { |
| 530 | 530 | |
| 531 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 532 | - $time = time(); |
|
| 533 | - |
|
| 534 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 535 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 536 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 537 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 538 | - if ( |
|
| 539 | - ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 540 | - or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 541 | - ) { |
|
| 542 | - if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 543 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 544 | - } else { |
|
| 545 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 546 | - } |
|
| 547 | - queue_sleep_time_to_next_job($next); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - return queue_sleep_time_to_next_job(); |
|
| 531 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 532 | + $time = time(); |
|
| 533 | + |
|
| 534 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 535 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 536 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 537 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 538 | + if ( |
|
| 539 | + ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 540 | + or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 541 | + ) { |
|
| 542 | + if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 543 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 544 | + } else { |
|
| 545 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 546 | + } |
|
| 547 | + queue_sleep_time_to_next_job($next); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + return queue_sleep_time_to_next_job(); |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | /** |
@@ -564,60 +564,60 @@ discard block |
||
| 564 | 564 | * @return string |
| 565 | 565 | */ |
| 566 | 566 | function queue_affichage_cron() { |
| 567 | - $texte = ''; |
|
| 568 | - |
|
| 569 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 570 | - // rien a faire si le prochain job est encore dans le futur |
|
| 571 | - if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 572 | - return $texte; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 576 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 577 | - return $texte; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - @touch($lock); |
|
| 581 | - |
|
| 582 | - // il y a des taches en attentes |
|
| 583 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 584 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 585 | - $urgent = false; |
|
| 586 | - if ($time_to_next < -300) { |
|
| 587 | - $urgent = true; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 591 | - |
|
| 592 | - if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 593 | - if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 594 | - return $texte; |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - // si deja force, on retourne sans rien |
|
| 599 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 600 | - return $texte; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - // si c'est un bot |
|
| 604 | - // inutile de faire un appel par image background, |
|
| 605 | - // on force un appel direct en fin de hit |
|
| 606 | - if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 607 | - define('_DIRECT_CRON_FORCE', true); |
|
| 608 | - |
|
| 609 | - return $texte; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 613 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 614 | - $url_cron = generer_url_action('cron'); |
|
| 615 | - $texte = '<!-- SPIP-CRON -->' |
|
| 616 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 617 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return $texte; |
|
| 567 | + $texte = ''; |
|
| 568 | + |
|
| 569 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 570 | + // rien a faire si le prochain job est encore dans le futur |
|
| 571 | + if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 572 | + return $texte; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 576 | + if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 577 | + return $texte; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + @touch($lock); |
|
| 581 | + |
|
| 582 | + // il y a des taches en attentes |
|
| 583 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 584 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 585 | + $urgent = false; |
|
| 586 | + if ($time_to_next < -300) { |
|
| 587 | + $urgent = true; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 591 | + |
|
| 592 | + if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 593 | + if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 594 | + return $texte; |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + // si deja force, on retourne sans rien |
|
| 599 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 600 | + return $texte; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + // si c'est un bot |
|
| 604 | + // inutile de faire un appel par image background, |
|
| 605 | + // on force un appel direct en fin de hit |
|
| 606 | + if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 607 | + define('_DIRECT_CRON_FORCE', true); |
|
| 608 | + |
|
| 609 | + return $texte; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 613 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 614 | + $url_cron = generer_url_action('cron'); |
|
| 615 | + $texte = '<!-- SPIP-CRON -->' |
|
| 616 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 617 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return $texte; |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | /** |
@@ -626,73 +626,73 @@ discard block |
||
| 626 | 626 | * @return bool : true si l'url a pu être appelée en asynchrone, false sinon |
| 627 | 627 | */ |
| 628 | 628 | function queue_lancer_url_http_async($url_cron) { |
| 629 | - // methode la plus rapide : |
|
| 630 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 631 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 632 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 633 | - // mais on renvoie false direct |
|
| 634 | - if (function_exists('fsockopen')) { |
|
| 635 | - $parts = parse_url($url_cron); |
|
| 636 | - |
|
| 637 | - switch ($parts['scheme']) { |
|
| 638 | - case 'https': |
|
| 639 | - $scheme = 'ssl://'; |
|
| 640 | - $port = 443; |
|
| 641 | - break; |
|
| 642 | - case 'http': |
|
| 643 | - default: |
|
| 644 | - $scheme = ''; |
|
| 645 | - $port = 80; |
|
| 646 | - } |
|
| 647 | - $fp = @fsockopen( |
|
| 648 | - $scheme . $parts['host'], |
|
| 649 | - $parts['port'] ?? $port, |
|
| 650 | - $errno, |
|
| 651 | - $errstr, |
|
| 652 | - 1 |
|
| 653 | - ); |
|
| 654 | - |
|
| 655 | - if ($fp) { |
|
| 656 | - $host_sent = $parts['host']; |
|
| 657 | - if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 658 | - $host_sent .= ':' . $parts['port']; |
|
| 659 | - } |
|
| 660 | - $timeout = 200; // ms |
|
| 661 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 662 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 663 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 664 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 665 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 666 | - fwrite($fp, $out); |
|
| 667 | - spip_timer('read'); |
|
| 668 | - $t = 0; |
|
| 669 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 670 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 671 | - while (!feof($fp) and $t < $timeout) { |
|
| 672 | - @fgets($fp, 1024); |
|
| 673 | - $t += spip_timer('read', true); |
|
| 674 | - spip_timer('read'); |
|
| 675 | - } |
|
| 676 | - fclose($fp); |
|
| 677 | - return true; |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 681 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 682 | - elseif (function_exists('curl_init')) { |
|
| 683 | - //setting the curl parameters. |
|
| 684 | - $ch = curl_init($url_cron); |
|
| 685 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 686 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 687 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 688 | - // valeur mini pour que la requete soit lancee |
|
| 689 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 690 | - // lancer |
|
| 691 | - curl_exec($ch); |
|
| 692 | - // fermer |
|
| 693 | - curl_close($ch); |
|
| 694 | - return true; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - return false; |
|
| 629 | + // methode la plus rapide : |
|
| 630 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 631 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 632 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 633 | + // mais on renvoie false direct |
|
| 634 | + if (function_exists('fsockopen')) { |
|
| 635 | + $parts = parse_url($url_cron); |
|
| 636 | + |
|
| 637 | + switch ($parts['scheme']) { |
|
| 638 | + case 'https': |
|
| 639 | + $scheme = 'ssl://'; |
|
| 640 | + $port = 443; |
|
| 641 | + break; |
|
| 642 | + case 'http': |
|
| 643 | + default: |
|
| 644 | + $scheme = ''; |
|
| 645 | + $port = 80; |
|
| 646 | + } |
|
| 647 | + $fp = @fsockopen( |
|
| 648 | + $scheme . $parts['host'], |
|
| 649 | + $parts['port'] ?? $port, |
|
| 650 | + $errno, |
|
| 651 | + $errstr, |
|
| 652 | + 1 |
|
| 653 | + ); |
|
| 654 | + |
|
| 655 | + if ($fp) { |
|
| 656 | + $host_sent = $parts['host']; |
|
| 657 | + if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 658 | + $host_sent .= ':' . $parts['port']; |
|
| 659 | + } |
|
| 660 | + $timeout = 200; // ms |
|
| 661 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 662 | + $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 663 | + $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 664 | + $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 665 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 666 | + fwrite($fp, $out); |
|
| 667 | + spip_timer('read'); |
|
| 668 | + $t = 0; |
|
| 669 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 670 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 671 | + while (!feof($fp) and $t < $timeout) { |
|
| 672 | + @fgets($fp, 1024); |
|
| 673 | + $t += spip_timer('read', true); |
|
| 674 | + spip_timer('read'); |
|
| 675 | + } |
|
| 676 | + fclose($fp); |
|
| 677 | + return true; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 681 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 682 | + elseif (function_exists('curl_init')) { |
|
| 683 | + //setting the curl parameters. |
|
| 684 | + $ch = curl_init($url_cron); |
|
| 685 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 686 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 687 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 688 | + // valeur mini pour que la requete soit lancee |
|
| 689 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 690 | + // lancer |
|
| 691 | + curl_exec($ch); |
|
| 692 | + // fermer |
|
| 693 | + curl_close($ch); |
|
| 694 | + return true; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + return false; |
|
| 698 | 698 | } |
@@ -70,7 +70,7 @@ discard block |
||
| 70 | 70 | $md5args = md5($arguments); |
| 71 | 71 | |
| 72 | 72 | // si pas de date programee, des que possible |
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 73 | + $duplicate_where = 'status='.intval(_JQ_SCHEDULED).' AND '; |
|
| 74 | 74 | if (!$time) { |
| 75 | 75 | $time = time(); |
| 76 | 76 | $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
@@ -96,9 +96,8 @@ discard block |
||
| 96 | 96 | 'id_job', |
| 97 | 97 | 'spip_jobs', |
| 98 | 98 | $duplicate_where = |
| 99 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 99 | + $duplicate_where.'fonction='.sql_quote($function) |
|
| 100 | + . (($no_duplicate === 'function_only') ? '' : ' AND md5args='.sql_quote($md5args).' AND inclure='.sql_quote($file)) |
|
| 102 | 101 | ) |
| 103 | 102 | ) { |
| 104 | 103 | return $id_job; |
@@ -111,9 +110,9 @@ discard block |
||
| 111 | 110 | if ( |
| 112 | 111 | $no_duplicate |
| 113 | 112 | and |
| 114 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 113 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<'.intval($id_job)." AND $duplicate_where") |
|
| 115 | 114 | ) { |
| 116 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 115 | + sql_delete('spip_jobs', 'id_job='.intval($id_job)); |
|
| 117 | 116 | |
| 118 | 117 | return $id_prev; |
| 119 | 118 | } |
@@ -125,9 +124,9 @@ discard block |
||
| 125 | 124 | // ie cas d'un char non acceptables sur certains type de champs |
| 126 | 125 | // qui coupe la valeur |
| 127 | 126 | if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
| 128 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 127 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job='.intval($id_job)); |
|
| 129 | 128 | if ($args !== $arguments) { |
| 130 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 129 | + spip_log('arguments job errones / longueur '.strlen($args).' vs '.strlen($arguments).' / valeur : '.var_export( |
|
| 131 | 130 | $arguments, |
| 132 | 131 | true |
| 133 | 132 | ), 'queue'); |
@@ -157,7 +156,7 @@ discard block |
||
| 157 | 156 | function queue_purger() { |
| 158 | 157 | include_spip('base/abstract_sql'); |
| 159 | 158 | sql_delete('spip_jobs'); |
| 160 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 159 | + sql_delete('spip_jobs_liens', 'id_job NOT IN ('.sql_get_select('id_job', 'spip_jobs').')'); |
|
| 161 | 160 | include_spip('inc/genie'); |
| 162 | 161 | genie_queue_watch_dist(); |
| 163 | 162 | } |
@@ -173,8 +172,8 @@ discard block |
||
| 173 | 172 | include_spip('base/abstract_sql'); |
| 174 | 173 | |
| 175 | 174 | if ( |
| 176 | - $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 175 | + $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job='.intval($id_job)) |
|
| 176 | + and $res = sql_delete('spip_jobs', 'id_job='.intval($id_job)) |
|
| 178 | 177 | ) { |
| 179 | 178 | queue_unlink_job($id_job); |
| 180 | 179 | // est-ce une tache cron qu'il faut relancer ? |
@@ -224,7 +223,7 @@ discard block |
||
| 224 | 223 | * resultat du sql_delete |
| 225 | 224 | */ |
| 226 | 225 | function queue_unlink_job($id_job) { |
| 227 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 226 | + return sql_delete('spip_jobs_liens', 'id_job='.intval($id_job)); |
|
| 228 | 227 | } |
| 229 | 228 | |
| 230 | 229 | /** |
@@ -240,7 +239,7 @@ discard block |
||
| 240 | 239 | // deserialiser les arguments |
| 241 | 240 | $args = unserialize($row['args']); |
| 242 | 241 | if (!is_array($args)) { |
| 243 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 242 | + spip_log('arguments job errones '.var_export($row, true), 'queue'); |
|
| 244 | 243 | $args = []; |
| 245 | 244 | } |
| 246 | 245 | |
@@ -257,14 +256,14 @@ discard block |
||
| 257 | 256 | } |
| 258 | 257 | |
| 259 | 258 | if (!function_exists($fonction)) { |
| 260 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 259 | + spip_log("fonction $fonction ($inclure) inexistante ".var_export($row, true), 'queue'); |
|
| 261 | 260 | |
| 262 | 261 | return false; |
| 263 | 262 | } |
| 264 | 263 | |
| 265 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 264 | + spip_log('queue ['.$row['id_job']."]: $fonction() start", 'queue'); |
|
| 266 | 265 | $res = $fonction(...$args); |
| 267 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 266 | + spip_log('queue ['.$row['id_job']."]: $fonction() end", 'queue'); |
|
| 268 | 267 | |
| 269 | 268 | return $res; |
| 270 | 269 | } |
@@ -295,14 +294,14 @@ discard block |
||
| 295 | 294 | function queue_schedule($force_jobs = null) { |
| 296 | 295 | $time = time(); |
| 297 | 296 | if (defined('_DEBUG_BLOCK_QUEUE')) { |
| 298 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 297 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq'._LOG_DEBUG); |
|
| 299 | 298 | |
| 300 | 299 | return; |
| 301 | 300 | } |
| 302 | 301 | |
| 303 | 302 | // rien a faire si le prochain job est encore dans le futur |
| 304 | 303 | if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
| 305 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 304 | + spip_log('queue_sleep_time_to_next_job', 'jq'._LOG_DEBUG); |
|
| 306 | 305 | |
| 307 | 306 | return; |
| 308 | 307 | } |
@@ -323,7 +322,7 @@ discard block |
||
| 323 | 322 | } |
| 324 | 323 | $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
| 325 | 324 | |
| 326 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 325 | + spip_log("JQ schedule $time / $end_time", 'jq'._LOG_DEBUG); |
|
| 327 | 326 | |
| 328 | 327 | if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
| 329 | 328 | define('_JQ_MAX_JOBS_EXECUTE', 200); |
@@ -337,19 +336,19 @@ discard block |
||
| 337 | 336 | // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
| 338 | 337 | // pour qu'il ne bloque pas les autres jobs en attente |
| 339 | 338 | if (is_array($force_jobs) and count($force_jobs)) { |
| 340 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 339 | + $cond = 'status='.intval(_JQ_SCHEDULED).' AND '.sql_in('id_job', $force_jobs); |
|
| 341 | 340 | } else { |
| 342 | 341 | $now = date('Y-m-d H:i:s', $time); |
| 343 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 342 | + $cond = 'status='.intval(_JQ_SCHEDULED).' AND date<='.sql_quote($now); |
|
| 344 | 343 | } |
| 345 | 344 | |
| 346 | 345 | register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
| 347 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 346 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,'.(_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 348 | 347 | do { |
| 349 | 348 | if ($row = array_shift($res)) { |
| 350 | 349 | $nbj++; |
| 351 | 350 | // il faut un verrou, a base de sql_delete |
| 352 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 351 | + if (sql_delete('spip_jobs', 'id_job='.intval($row['id_job']).' AND status='.intval(_JQ_SCHEDULED))) { |
|
| 353 | 352 | #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
| 354 | 353 | // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
| 355 | 354 | $row['status'] = _JQ_PENDING; |
@@ -364,13 +363,13 @@ discard block |
||
| 364 | 363 | queue_close_job($row, $time, $result); |
| 365 | 364 | } |
| 366 | 365 | } |
| 367 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 366 | + spip_log('JQ schedule job end time '.$time, 'jq'._LOG_DEBUG); |
|
| 368 | 367 | } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
| 369 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 368 | + spip_log('JQ schedule end time '.time(), 'jq'._LOG_DEBUG); |
|
| 370 | 369 | |
| 371 | 370 | if ($row = array_shift($res)) { |
| 372 | 371 | queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
| 373 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 372 | + spip_log('JQ encore !', 'jq'._LOG_DEBUG); |
|
| 374 | 373 | } else { |
| 375 | 374 | queue_update_next_job_time(); |
| 376 | 375 | } |
@@ -405,9 +404,9 @@ discard block |
||
| 405 | 404 | } |
| 406 | 405 | } |
| 407 | 406 | // purger ses liens eventuels avec des objets |
| 408 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 407 | + sql_delete('spip_jobs_liens', 'id_job='.intval($row['id_job'])); |
|
| 409 | 408 | // supprimer le job fini |
| 410 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 409 | + sql_delete('spip_jobs', 'id_job='.intval($row['id_job'])); |
|
| 411 | 410 | } |
| 412 | 411 | |
| 413 | 412 | /** |
@@ -480,18 +479,18 @@ discard block |
||
| 480 | 479 | $res = sql_allfetsel( |
| 481 | 480 | '*', |
| 482 | 481 | 'spip_jobs', |
| 483 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 482 | + 'status='.intval(_JQ_PENDING).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 484 | 483 | ); |
| 485 | 484 | if (is_array($res)) { |
| 486 | 485 | foreach ($res as $row) { |
| 487 | 486 | queue_close_job($row, $time); |
| 488 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 487 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : '.print_r($row, 1), 'job_mort'._LOG_ERREUR); |
|
| 489 | 488 | } |
| 490 | 489 | } |
| 491 | 490 | |
| 492 | 491 | // chercher la date du prochain job si pas connu |
| 493 | 492 | if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
| 494 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 493 | + $date = sql_getfetsel('date', 'spip_jobs', 'status='.intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 495 | 494 | $next = strtotime($date); |
| 496 | 495 | } |
| 497 | 496 | if (!is_null($next_time)) { |
@@ -504,7 +503,7 @@ discard block |
||
| 504 | 503 | if (is_null($nb_jobs_scheduled)) { |
| 505 | 504 | $nb_jobs_scheduled = sql_countsel( |
| 506 | 505 | 'spip_jobs', |
| 507 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 506 | + 'status='.intval(_JQ_SCHEDULED).' AND date<'.sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 508 | 507 | ); |
| 509 | 508 | } elseif ($next <= $time) { |
| 510 | 509 | $nb_jobs_scheduled++; |
@@ -573,7 +572,7 @@ discard block |
||
| 573 | 572 | } |
| 574 | 573 | |
| 575 | 574 | // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
| 576 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 575 | + if (file_exists($lock = _DIR_TMP.'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 577 | 576 | return $texte; |
| 578 | 577 | } |
| 579 | 578 | |
@@ -645,7 +644,7 @@ discard block |
||
| 645 | 644 | $port = 80; |
| 646 | 645 | } |
| 647 | 646 | $fp = @fsockopen( |
| 648 | - $scheme . $parts['host'], |
|
| 647 | + $scheme.$parts['host'], |
|
| 649 | 648 | $parts['port'] ?? $port, |
| 650 | 649 | $errno, |
| 651 | 650 | $errstr, |
@@ -655,13 +654,13 @@ discard block |
||
| 655 | 654 | if ($fp) { |
| 656 | 655 | $host_sent = $parts['host']; |
| 657 | 656 | if (isset($parts['port']) and $parts['port'] !== $port) { |
| 658 | - $host_sent .= ':' . $parts['port']; |
|
| 657 | + $host_sent .= ':'.$parts['port']; |
|
| 659 | 658 | } |
| 660 | 659 | $timeout = 200; // ms |
| 661 | 660 | stream_set_timeout($fp, 0, $timeout * 1000); |
| 662 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 663 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 664 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 661 | + $query = $parts['path'].($parts['query'] ? '?'.$parts['query'] : ''); |
|
| 662 | + $out = 'GET '.$query." HTTP/1.1\r\n"; |
|
| 663 | + $out .= 'Host: '.$host_sent."\r\n"; |
|
| 665 | 664 | $out .= "Connection: Close\r\n\r\n"; |
| 666 | 665 | fwrite($fp, $out); |
| 667 | 666 | spip_timer('read'); |
@@ -39,8 +39,7 @@ |
||
| 39 | 39 | } else { |
| 40 | 40 | $tls = true; |
| 41 | 41 | } |
| 42 | - } |
|
| 43 | - else { |
|
| 42 | + } else { |
|
| 44 | 43 | $tls_ldap == 'non'; |
| 45 | 44 | } |
| 46 | 45 | |
@@ -10,90 +10,90 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | function install_etape_ldap2_dist() { |
| 17 | - $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 18 | - echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 19 | - |
|
| 20 | - $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | - |
|
| 22 | - $port_ldap = _request('port_ldap'); |
|
| 23 | - |
|
| 24 | - $tls_ldap = _request('tls_ldap'); |
|
| 25 | - |
|
| 26 | - $protocole_ldap = _request('protocole_ldap'); |
|
| 27 | - |
|
| 28 | - $login_ldap = _request('login_ldap'); |
|
| 29 | - |
|
| 30 | - $pass_ldap = _request('pass_ldap'); |
|
| 31 | - |
|
| 32 | - $port_ldap = intval($port_ldap); |
|
| 33 | - |
|
| 34 | - $tls = false; |
|
| 35 | - |
|
| 36 | - if ($tls_ldap == 'oui') { |
|
| 37 | - if ($port_ldap == 636) { |
|
| 38 | - $adresse_ldap = "ldaps://$adresse_ldap"; |
|
| 39 | - } else { |
|
| 40 | - $tls = true; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - else { |
|
| 44 | - $tls_ldap == 'non'; |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // Verifions que l'adresse demandee est valide |
|
| 48 | - $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: ''; |
|
| 49 | - |
|
| 50 | - $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 51 | - $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 52 | - |
|
| 53 | - if ($ldap_link) { |
|
| 54 | - if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
|
| 55 | - $protocole_ldap = 2; |
|
| 56 | - ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap); |
|
| 57 | - } |
|
| 58 | - if ($tls === true) { |
|
| 59 | - if (!ldap_start_tls($ldap_link)) { |
|
| 60 | - $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 61 | - . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 62 | - . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 63 | - $ldap_link = false; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - if ($ldap_link) { |
|
| 67 | - $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 68 | - $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 69 | - . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 70 | - . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 71 | - . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 72 | - . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if ($ldap_link) { |
|
| 77 | - echo info_etape( |
|
| 78 | - _T('titre_connexion_ldap'), |
|
| 79 | - info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 80 | - ), _T('info_connexion_ldap_ok'); |
|
| 81 | - echo generer_form_ecrire('install', ( |
|
| 82 | - "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 83 | - . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 84 | - . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 85 | - . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 86 | - . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 87 | - . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 88 | - . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 89 | - . bouton_suivant())); |
|
| 90 | - } else { |
|
| 91 | - echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 92 | - "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 93 | - '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 94 | - "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 95 | - '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - echo $minipage->installFinPage(); |
|
| 17 | + $minipage = new Spip\Afficher\Minipage\Installation(); |
|
| 18 | + echo $minipage->installDebutPage(['onload' => 'document.getElementById(\'suivant\').focus();return false;']); |
|
| 19 | + |
|
| 20 | + $adresse_ldap = _request('adresse_ldap'); |
|
| 21 | + |
|
| 22 | + $port_ldap = _request('port_ldap'); |
|
| 23 | + |
|
| 24 | + $tls_ldap = _request('tls_ldap'); |
|
| 25 | + |
|
| 26 | + $protocole_ldap = _request('protocole_ldap'); |
|
| 27 | + |
|
| 28 | + $login_ldap = _request('login_ldap'); |
|
| 29 | + |
|
| 30 | + $pass_ldap = _request('pass_ldap'); |
|
| 31 | + |
|
| 32 | + $port_ldap = intval($port_ldap); |
|
| 33 | + |
|
| 34 | + $tls = false; |
|
| 35 | + |
|
| 36 | + if ($tls_ldap == 'oui') { |
|
| 37 | + if ($port_ldap == 636) { |
|
| 38 | + $adresse_ldap = "ldaps://$adresse_ldap"; |
|
| 39 | + } else { |
|
| 40 | + $tls = true; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + else { |
|
| 44 | + $tls_ldap == 'non'; |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // Verifions que l'adresse demandee est valide |
|
| 48 | + $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: ''; |
|
| 49 | + |
|
| 50 | + $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
|
| 51 | + $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 52 | + |
|
| 53 | + if ($ldap_link) { |
|
| 54 | + if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
|
| 55 | + $protocole_ldap = 2; |
|
| 56 | + ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap); |
|
| 57 | + } |
|
| 58 | + if ($tls === true) { |
|
| 59 | + if (!ldap_start_tls($ldap_link)) { |
|
| 60 | + $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 61 | + . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 62 | + . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 63 | + $ldap_link = false; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + if ($ldap_link) { |
|
| 67 | + $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
|
| 68 | + $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 69 | + . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 70 | + . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 71 | + . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 72 | + . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if ($ldap_link) { |
|
| 77 | + echo info_etape( |
|
| 78 | + _T('titre_connexion_ldap'), |
|
| 79 | + info_progression_etape(2, 'etape_ldap', 'install/') |
|
| 80 | + ), _T('info_connexion_ldap_ok'); |
|
| 81 | + echo generer_form_ecrire('install', ( |
|
| 82 | + "\n<input type='hidden' name='etape' value='ldap3' />" |
|
| 83 | + . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 84 | + . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 85 | + . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 86 | + . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 87 | + . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 88 | + . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 89 | + . bouton_suivant())); |
|
| 90 | + } else { |
|
| 91 | + echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
|
| 92 | + "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 93 | + '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 94 | + "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 95 | + '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + echo $minipage->installFinPage(); |
|
| 99 | 99 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | $adresse_ldap = filter_var($adresse_ldap, FILTER_SANITIZE_URL) ?: ''; |
| 49 | 49 | |
| 50 | 50 | $ldap_link = ldap_connect($adresse_ldap, $port_ldap); |
| 51 | - $erreur = 'ldap_connect(' . spip_htmlspecialchars($adresse_ldap) . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 51 | + $erreur = 'ldap_connect('.spip_htmlspecialchars($adresse_ldap).', '.spip_htmlspecialchars($port_ldap).')'; |
|
| 52 | 52 | |
| 53 | 53 | if ($ldap_link) { |
| 54 | 54 | if (!ldap_set_option($ldap_link, LDAP_OPT_PROTOCOL_VERSION, $protocole_ldap)) { |
@@ -57,19 +57,19 @@ discard block |
||
| 57 | 57 | } |
| 58 | 58 | if ($tls === true) { |
| 59 | 59 | if (!ldap_start_tls($ldap_link)) { |
| 60 | - $erreur = 'ldap_start_tls(' . spip_htmlspecialchars($ldap_link) |
|
| 61 | - . ' ' . spip_htmlspecialchars($adresse_ldap) |
|
| 62 | - . ', ' . spip_htmlspecialchars($port_ldap) . ')'; |
|
| 60 | + $erreur = 'ldap_start_tls('.spip_htmlspecialchars($ldap_link) |
|
| 61 | + . ' '.spip_htmlspecialchars($adresse_ldap) |
|
| 62 | + . ', '.spip_htmlspecialchars($port_ldap).')'; |
|
| 63 | 63 | $ldap_link = false; |
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | if ($ldap_link) { |
| 67 | 67 | $ldap_link = ldap_bind($ldap_link, $login_ldap, $pass_ldap); |
| 68 | - $erreur = "ldap_bind('" . spip_htmlspecialchars($ldap_link) |
|
| 69 | - . "', '" . spip_htmlspecialchars($login_ldap) |
|
| 70 | - . "', '" . spip_htmlspecialchars($pass_ldap) |
|
| 71 | - . "'): " . spip_htmlspecialchars($adresse_ldap) |
|
| 72 | - . ', ' . spip_htmlspecialchars($port_ldap); |
|
| 68 | + $erreur = "ldap_bind('".spip_htmlspecialchars($ldap_link) |
|
| 69 | + . "', '".spip_htmlspecialchars($login_ldap) |
|
| 70 | + . "', '".spip_htmlspecialchars($pass_ldap) |
|
| 71 | + . "'): ".spip_htmlspecialchars($adresse_ldap) |
|
| 72 | + . ', '.spip_htmlspecialchars($port_ldap); |
|
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
@@ -77,22 +77,22 @@ discard block |
||
| 77 | 77 | echo info_etape( |
| 78 | 78 | _T('titre_connexion_ldap'), |
| 79 | 79 | info_progression_etape(2, 'etape_ldap', 'install/') |
| 80 | - ), _T('info_connexion_ldap_ok'); |
|
| 80 | + ), _T('info_connexion_ldap_ok'); |
|
| 81 | 81 | echo generer_form_ecrire('install', ( |
| 82 | 82 | "\n<input type='hidden' name='etape' value='ldap3' />" |
| 83 | - . "\n<input type='hidden' name='adresse_ldap' value=\"" . spip_htmlspecialchars($adresse_ldap) . '" />' |
|
| 84 | - . "\n<input type='hidden' name='port_ldap' value=\"" . spip_htmlspecialchars($port_ldap) . '" />' |
|
| 85 | - . "\n<input type='hidden' name='login_ldap' value=\"" . spip_htmlspecialchars($login_ldap) . '" />' |
|
| 86 | - . "\n<input type='hidden' name='pass_ldap' value=\"" . spip_htmlspecialchars($pass_ldap) . '" />' |
|
| 87 | - . "\n<input type='hidden' name='protocole_ldap' value=\"" . spip_htmlspecialchars($protocole_ldap) . '" />' |
|
| 88 | - . "\n<input type='hidden' name='tls_ldap' value=\"" . spip_htmlspecialchars($tls_ldap) . '" />' |
|
| 83 | + . "\n<input type='hidden' name='adresse_ldap' value=\"".spip_htmlspecialchars($adresse_ldap).'" />' |
|
| 84 | + . "\n<input type='hidden' name='port_ldap' value=\"".spip_htmlspecialchars($port_ldap).'" />' |
|
| 85 | + . "\n<input type='hidden' name='login_ldap' value=\"".spip_htmlspecialchars($login_ldap).'" />' |
|
| 86 | + . "\n<input type='hidden' name='pass_ldap' value=\"".spip_htmlspecialchars($pass_ldap).'" />' |
|
| 87 | + . "\n<input type='hidden' name='protocole_ldap' value=\"".spip_htmlspecialchars($protocole_ldap).'" />' |
|
| 88 | + . "\n<input type='hidden' name='tls_ldap' value=\"".spip_htmlspecialchars($tls_ldap).'" />' |
|
| 89 | 89 | . bouton_suivant())); |
| 90 | 90 | } else { |
| 91 | 91 | echo info_etape(_T('titre_connexion_ldap')), info_progression_etape(1, 'etape_ldap', 'install/', true), |
| 92 | - "<div class='error'><p>" . _T('avis_connexion_ldap_echec_1') . '</p>', |
|
| 93 | - '<p>' . _T('avis_connexion_ldap_echec_2') . |
|
| 94 | - "<br />\n" . _T('avis_connexion_ldap_echec_3') . |
|
| 95 | - '<br /><br />' . $erreur . '<b> ?</b></p></div>'; |
|
| 92 | + "<div class='error'><p>"._T('avis_connexion_ldap_echec_1').'</p>', |
|
| 93 | + '<p>'._T('avis_connexion_ldap_echec_2'). |
|
| 94 | + "<br />\n"._T('avis_connexion_ldap_echec_3'). |
|
| 95 | + '<br /><br />'.$erreur.'<b> ?</b></p></div>'; |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | echo $minipage->installFinPage(); |
@@ -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 | |
@@ -52,68 +52,68 @@ discard block |
||
| 52 | 52 | * cookie sécurisé ou non ? |
| 53 | 53 | **/ |
| 54 | 54 | function spip_setcookie($name = '', $value = '', $options = []) { |
| 55 | - static $to_secure_list = ['spip_session']; |
|
| 56 | - if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | - $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (!is_array($options)) { |
|
| 61 | - // anciens paramètres : |
|
| 62 | - # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | - $opt = func_get_args(); |
|
| 64 | - $opt = array_slice($opt, 2); |
|
| 65 | - $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | - if (isset($opt[0])) { |
|
| 67 | - $options['expires'] = $opt[0]; |
|
| 68 | - } |
|
| 69 | - if (isset($opt[1])) { |
|
| 70 | - $options['path'] = $opt[1]; |
|
| 71 | - } |
|
| 72 | - if (isset($opt[2])) { |
|
| 73 | - $options['domain'] = $opt[2]; |
|
| 74 | - } |
|
| 75 | - if (isset($opt[3])) { |
|
| 76 | - $options['secure'] = $opt[3]; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // expires |
|
| 81 | - if (!isset($options['expires'])) { |
|
| 82 | - $options['expires'] = 0; |
|
| 83 | - } |
|
| 84 | - if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | - if (defined('_COOKIE_PATH')) { |
|
| 86 | - $options['path'] = _COOKIE_PATH; |
|
| 87 | - } else { |
|
| 88 | - $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | - $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | - } |
|
| 94 | - if (in_array($name, $to_secure_list)) { |
|
| 95 | - if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | - $options['secure'] = true; |
|
| 97 | - } |
|
| 98 | - if (empty($options['httponly'])) { |
|
| 99 | - $options['httponly'] = true; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - if (empty($options['samesite'])) { |
|
| 103 | - $options['samesite'] = 'Lax'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // in fine renommer le prefixe si besoin |
|
| 107 | - if (strpos($name, 'spip_') === 0) { |
|
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | - $a = @setcookie($name, $value, $options); |
|
| 113 | - |
|
| 114 | - spip_cookie_envoye(true); |
|
| 115 | - |
|
| 116 | - return $a; |
|
| 55 | + static $to_secure_list = ['spip_session']; |
|
| 56 | + if (defined('_COOKIE_SECURE_LIST') and is_array(_COOKIE_SECURE_LIST)) { |
|
| 57 | + $to_secure_list = array_merge($to_secure_list, _COOKIE_SECURE_LIST); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (!is_array($options)) { |
|
| 61 | + // anciens paramètres : |
|
| 62 | + # spip_setcookie($name = '', $value = '', $expire = 0, $path = 'AUTO', $domain = '', $secure = '') |
|
| 63 | + $opt = func_get_args(); |
|
| 64 | + $opt = array_slice($opt, 2); |
|
| 65 | + $options = []; # /!\ après le func_get_args (sinon $opt[0] référence la nouvelle valeur de $options !); |
|
| 66 | + if (isset($opt[0])) { |
|
| 67 | + $options['expires'] = $opt[0]; |
|
| 68 | + } |
|
| 69 | + if (isset($opt[1])) { |
|
| 70 | + $options['path'] = $opt[1]; |
|
| 71 | + } |
|
| 72 | + if (isset($opt[2])) { |
|
| 73 | + $options['domain'] = $opt[2]; |
|
| 74 | + } |
|
| 75 | + if (isset($opt[3])) { |
|
| 76 | + $options['secure'] = $opt[3]; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // expires |
|
| 81 | + if (!isset($options['expires'])) { |
|
| 82 | + $options['expires'] = 0; |
|
| 83 | + } |
|
| 84 | + if (!isset($options['path']) or $options['path'] === 'AUTO') { |
|
| 85 | + if (defined('_COOKIE_PATH')) { |
|
| 86 | + $options['path'] = _COOKIE_PATH; |
|
| 87 | + } else { |
|
| 88 | + $options['path'] = preg_replace(',^\w+://[^/]*,', '', url_de_base()); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + if (empty($options['domain']) and defined('_COOKIE_DOMAIN') and _COOKIE_DOMAIN) { |
|
| 92 | + $options['domain'] = _COOKIE_DOMAIN; |
|
| 93 | + } |
|
| 94 | + if (in_array($name, $to_secure_list)) { |
|
| 95 | + if (empty($options['secure']) and defined('_COOKIE_SECURE') and _COOKIE_SECURE) { |
|
| 96 | + $options['secure'] = true; |
|
| 97 | + } |
|
| 98 | + if (empty($options['httponly'])) { |
|
| 99 | + $options['httponly'] = true; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + if (empty($options['samesite'])) { |
|
| 103 | + $options['samesite'] = 'Lax'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // in fine renommer le prefixe si besoin |
|
| 107 | + if (strpos($name, 'spip_') === 0) { |
|
| 108 | + $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
|
| 112 | + $a = @setcookie($name, $value, $options); |
|
| 113 | + |
|
| 114 | + spip_cookie_envoye(true); |
|
| 115 | + |
|
| 116 | + return $a; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,12 +129,12 @@ discard block |
||
| 129 | 129 | * @return bool |
| 130 | 130 | **/ |
| 131 | 131 | function spip_cookie_envoye($set = '') { |
| 132 | - static $envoye = false; |
|
| 133 | - if ($set) { |
|
| 134 | - $envoye = true; |
|
| 135 | - } |
|
| 132 | + static $envoye = false; |
|
| 133 | + if ($set) { |
|
| 134 | + $envoye = true; |
|
| 135 | + } |
|
| 136 | 136 | |
| 137 | - return $envoye; |
|
| 137 | + return $envoye; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -153,21 +153,21 @@ discard block |
||
| 153 | 153 | * Préfixe des cookies de SPIP |
| 154 | 154 | **/ |
| 155 | 155 | function recuperer_cookies_spip($cookie_prefix) { |
| 156 | - $prefix_long = strlen($cookie_prefix); |
|
| 157 | - |
|
| 158 | - foreach ($_COOKIE as $name => $value) { |
|
| 159 | - if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | - unset($_COOKIE[$name]); |
|
| 161 | - unset($GLOBALS[$name]); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - foreach ($_COOKIE as $name => $value) { |
|
| 165 | - if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | - $_COOKIE[$spipname] = $value; |
|
| 168 | - $GLOBALS[$spipname] = $value; |
|
| 169 | - } |
|
| 170 | - } |
|
| 156 | + $prefix_long = strlen($cookie_prefix); |
|
| 157 | + |
|
| 158 | + foreach ($_COOKIE as $name => $value) { |
|
| 159 | + if (substr($name, 0, 5) == 'spip_' && substr($name, 0, $prefix_long) != $cookie_prefix) { |
|
| 160 | + unset($_COOKIE[$name]); |
|
| 161 | + unset($GLOBALS[$name]); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + foreach ($_COOKIE as $name => $value) { |
|
| 165 | + if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
|
| 166 | + $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 167 | + $_COOKIE[$spipname] = $value; |
|
| 168 | + $GLOBALS[$spipname] = $value; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -186,18 +186,18 @@ discard block |
||
| 186 | 186 | * |
| 187 | 187 | **/ |
| 188 | 188 | function exec_test_ajax_dist() { |
| 189 | - switch (_request('js')) { |
|
| 190 | - // on est appele par <noscript> |
|
| 191 | - case -1: |
|
| 192 | - spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | - include_spip('inc/headers'); |
|
| 194 | - redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | - break; |
|
| 196 | - |
|
| 197 | - // ou par ajax |
|
| 198 | - case 1: |
|
| 199 | - default: |
|
| 200 | - spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | - break; |
|
| 202 | - } |
|
| 189 | + switch (_request('js')) { |
|
| 190 | + // on est appele par <noscript> |
|
| 191 | + case -1: |
|
| 192 | + spip_setcookie('spip_accepte_ajax', -1); |
|
| 193 | + include_spip('inc/headers'); |
|
| 194 | + redirige_par_entete(chemin_image('erreur-xx.svg')); |
|
| 195 | + break; |
|
| 196 | + |
|
| 197 | + // ou par ajax |
|
| 198 | + case 1: |
|
| 199 | + default: |
|
| 200 | + spip_setcookie('spip_accepte_ajax', 1); |
|
| 201 | + break; |
|
| 202 | + } |
|
| 203 | 203 | } |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | |
| 106 | 106 | // in fine renommer le prefixe si besoin |
| 107 | 107 | if (strpos($name, 'spip_') === 0) { |
| 108 | - $name = $GLOBALS['cookie_prefix'] . '_' . substr($name, 5); |
|
| 108 | + $name = $GLOBALS['cookie_prefix'].'_'.substr($name, 5); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | #spip_log("cookie('$name', '$value', " . json_encode($options, true) . ")", "cookies"); |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | } |
| 164 | 164 | foreach ($_COOKIE as $name => $value) { |
| 165 | 165 | if (substr($name, 0, $prefix_long) == $cookie_prefix) { |
| 166 | - $spipname = preg_replace('/^' . $cookie_prefix . '_/', 'spip_', $name); |
|
| 166 | + $spipname = preg_replace('/^'.$cookie_prefix.'_/', 'spip_', $name); |
|
| 167 | 167 | $_COOKIE[$spipname] = $value; |
| 168 | 168 | $GLOBALS[$spipname] = $value; |
| 169 | 169 | } |
@@ -121,8 +121,7 @@ discard block |
||
| 121 | 121 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 122 | 122 | spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
| 123 | 123 | @unlink($localrac_tmp); |
| 124 | - } |
|
| 125 | - else { |
|
| 124 | + } else { |
|
| 126 | 125 | spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
| 127 | 126 | } |
| 128 | 127 | if (!$res or !$res['length']) { |
@@ -240,8 +239,7 @@ discard block |
||
| 240 | 239 | break; |
| 241 | 240 | } |
| 242 | 241 | } |
| 243 | - } |
|
| 244 | - else { |
|
| 242 | + } else { |
|
| 245 | 243 | $ip = false; |
| 246 | 244 | } |
| 247 | 245 | } |
@@ -17,32 +17,32 @@ discard block |
||
| 17 | 17 | * @package SPIP\Core\Distant |
| 18 | 18 | **/ |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_INC_DISTANT_VERSION_HTTP')) { |
| 24 | - define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 24 | + define('_INC_DISTANT_VERSION_HTTP', 'HTTP/1.0'); |
|
| 25 | 25 | } |
| 26 | 26 | if (!defined('_INC_DISTANT_CONTENT_ENCODING')) { |
| 27 | - define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 27 | + define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
|
| 28 | 28 | } |
| 29 | 29 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 30 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 31 | 31 | } |
| 32 | 32 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 33 | - define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 33 | + define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
|
| 34 | 34 | } |
| 35 | 35 | if (!defined('_INC_DISTANT_CONNECT_TIMEOUT')) { |
| 36 | - define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 36 | + define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | define('_REGEXP_COPIE_LOCALE', ',' . |
| 40 | - preg_replace( |
|
| 41 | - '@^https?:@', |
|
| 42 | - 'https?:', |
|
| 43 | - ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 44 | - ) |
|
| 45 | - . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 40 | + preg_replace( |
|
| 41 | + '@^https?:@', |
|
| 42 | + 'https?:', |
|
| 43 | + ($GLOBALS['meta']['adresse_site'] ?? '') |
|
| 44 | + ) |
|
| 45 | + . '/?spip.php[?]action=acceder_document.*file=(.*)$,'); |
|
| 46 | 46 | |
| 47 | 47 | //@define('_COPIE_LOCALE_MAX_SIZE',2097152); // poids (inc/utils l'a fait) |
| 48 | 48 | |
@@ -71,107 +71,107 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function copie_locale($source, $mode = 'auto', $local = null, $taille_max = null, $callback_valider_url = null) { |
| 73 | 73 | |
| 74 | - // si c'est la protection de soi-meme, retourner le path |
|
| 75 | - if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 76 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 77 | - |
|
| 78 | - return @file_exists($source) ? $source : false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if (is_null($local)) { |
|
| 82 | - $local = fichier_copie_locale($source); |
|
| 83 | - } else { |
|
| 84 | - if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 85 | - $local = substr($local, strlen(_DIR_RACINE)); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 90 | - // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 91 | - // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 92 | - if (!$local) { |
|
| 93 | - return false; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - $localrac = _DIR_RACINE . $local; |
|
| 97 | - $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 98 | - |
|
| 99 | - // test d'existence du fichier |
|
| 100 | - if ($mode === 'test') { |
|
| 101 | - return $t ? $local : ''; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // sinon voir si on doit/peut le telecharger |
|
| 105 | - if ($local === $source or !tester_url_absolue($source)) { |
|
| 106 | - return $t ? $local : ''; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($mode === 'modif' or !$t) { |
|
| 110 | - // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 111 | - // et des eventuelles recuperations concurantes |
|
| 112 | - include_spip('inc/acces'); |
|
| 113 | - if (!$taille_max) { |
|
| 114 | - $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 115 | - } |
|
| 116 | - $localrac_tmp = $localrac . '.tmp'; |
|
| 117 | - $res = recuperer_url( |
|
| 118 | - $source, |
|
| 119 | - ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 120 | - ); |
|
| 121 | - |
|
| 122 | - if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 123 | - spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 124 | - @unlink($localrac_tmp); |
|
| 125 | - } |
|
| 126 | - else { |
|
| 127 | - spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 128 | - } |
|
| 129 | - if (!$res or !$res['length']) { |
|
| 130 | - // si $t c'est sans doute juste un not-modified-since |
|
| 131 | - return $t ? $local : false; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // si option valider url, verifions que l'URL finale est acceptable |
|
| 135 | - if ( |
|
| 136 | - $callback_valider_url |
|
| 137 | - and is_callable($callback_valider_url) |
|
| 138 | - and !$callback_valider_url($res['url']) |
|
| 139 | - ) { |
|
| 140 | - spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 141 | - @unlink($localrac_tmp); |
|
| 142 | - return $t ? $local : false; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // on peut renommer le fichier tmp |
|
| 146 | - @rename($localrac_tmp, $localrac); |
|
| 147 | - |
|
| 148 | - // si on retrouve l'extension |
|
| 149 | - if ( |
|
| 150 | - !empty($res['headers']) |
|
| 151 | - and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 152 | - ) { |
|
| 153 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 154 | - $sanitizer($localrac); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // pour une eventuelle indexation |
|
| 159 | - pipeline( |
|
| 160 | - 'post_edition', |
|
| 161 | - [ |
|
| 162 | - 'args' => [ |
|
| 163 | - 'operation' => 'copie_locale', |
|
| 164 | - 'source' => $source, |
|
| 165 | - 'fichier' => $local, |
|
| 166 | - 'http_res' => $res['length'], |
|
| 167 | - 'url' => $res['url'], |
|
| 168 | - ], |
|
| 169 | - 'data' => null |
|
| 170 | - ] |
|
| 171 | - ); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return $local; |
|
| 74 | + // si c'est la protection de soi-meme, retourner le path |
|
| 75 | + if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
|
| 76 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 77 | + |
|
| 78 | + return @file_exists($source) ? $source : false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if (is_null($local)) { |
|
| 82 | + $local = fichier_copie_locale($source); |
|
| 83 | + } else { |
|
| 84 | + if (_DIR_RACINE and strncmp(_DIR_RACINE, $local, strlen(_DIR_RACINE)) == 0) { |
|
| 85 | + $local = substr($local, strlen(_DIR_RACINE)); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // si $local = '' c'est un fichier refuse par fichier_copie_locale(), |
|
| 90 | + // par exemple un fichier qui ne figure pas dans nos documents ; |
|
| 91 | + // dans ce cas on n'essaie pas de le telecharger pour ensuite echouer |
|
| 92 | + if (!$local) { |
|
| 93 | + return false; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + $localrac = _DIR_RACINE . $local; |
|
| 97 | + $t = ($mode === 'force') ? false : @file_exists($localrac); |
|
| 98 | + |
|
| 99 | + // test d'existence du fichier |
|
| 100 | + if ($mode === 'test') { |
|
| 101 | + return $t ? $local : ''; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // sinon voir si on doit/peut le telecharger |
|
| 105 | + if ($local === $source or !tester_url_absolue($source)) { |
|
| 106 | + return $t ? $local : ''; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($mode === 'modif' or !$t) { |
|
| 110 | + // passer par un fichier temporaire unique pour gerer les echecs en cours de recuperation |
|
| 111 | + // et des eventuelles recuperations concurantes |
|
| 112 | + include_spip('inc/acces'); |
|
| 113 | + if (!$taille_max) { |
|
| 114 | + $taille_max = _COPIE_LOCALE_MAX_SIZE; |
|
| 115 | + } |
|
| 116 | + $localrac_tmp = $localrac . '.tmp'; |
|
| 117 | + $res = recuperer_url( |
|
| 118 | + $source, |
|
| 119 | + ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
|
| 120 | + ); |
|
| 121 | + |
|
| 122 | + if (!$res or (!$res['length'] and $res['status'] != 304)) { |
|
| 123 | + spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 124 | + @unlink($localrac_tmp); |
|
| 125 | + } |
|
| 126 | + else { |
|
| 127 | + spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 128 | + } |
|
| 129 | + if (!$res or !$res['length']) { |
|
| 130 | + // si $t c'est sans doute juste un not-modified-since |
|
| 131 | + return $t ? $local : false; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // si option valider url, verifions que l'URL finale est acceptable |
|
| 135 | + if ( |
|
| 136 | + $callback_valider_url |
|
| 137 | + and is_callable($callback_valider_url) |
|
| 138 | + and !$callback_valider_url($res['url']) |
|
| 139 | + ) { |
|
| 140 | + spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 141 | + @unlink($localrac_tmp); |
|
| 142 | + return $t ? $local : false; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // on peut renommer le fichier tmp |
|
| 146 | + @rename($localrac_tmp, $localrac); |
|
| 147 | + |
|
| 148 | + // si on retrouve l'extension |
|
| 149 | + if ( |
|
| 150 | + !empty($res['headers']) |
|
| 151 | + and $extension = distant_trouver_extension_selon_headers($source, $res['headers']) |
|
| 152 | + ) { |
|
| 153 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 154 | + $sanitizer($localrac); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // pour une eventuelle indexation |
|
| 159 | + pipeline( |
|
| 160 | + 'post_edition', |
|
| 161 | + [ |
|
| 162 | + 'args' => [ |
|
| 163 | + 'operation' => 'copie_locale', |
|
| 164 | + 'source' => $source, |
|
| 165 | + 'fichier' => $local, |
|
| 166 | + 'http_res' => $res['length'], |
|
| 167 | + 'url' => $res['url'], |
|
| 168 | + ], |
|
| 169 | + 'data' => null |
|
| 170 | + ] |
|
| 171 | + ); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return $local; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -186,99 +186,99 @@ discard block |
||
| 186 | 186 | * url ou false en cas d'echec |
| 187 | 187 | */ |
| 188 | 188 | function valider_url_distante($url, $known_hosts = []) { |
| 189 | - if (!function_exists('protocole_verifier')) { |
|
| 190 | - include_spip('inc/filtres_mini'); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 194 | - return false; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - $parsed_url = parse_url($url); |
|
| 198 | - if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - if (!is_array($known_hosts)) { |
|
| 211 | - $known_hosts = [$known_hosts]; |
|
| 212 | - } |
|
| 213 | - $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 214 | - $known_hosts[] = url_de_base(); |
|
| 215 | - $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 216 | - |
|
| 217 | - $is_known_host = false; |
|
| 218 | - foreach ($known_hosts as $known_host) { |
|
| 219 | - $parse_known = parse_url($known_host); |
|
| 220 | - if ( |
|
| 221 | - $parse_known |
|
| 222 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 223 | - ) { |
|
| 224 | - $is_known_host = true; |
|
| 225 | - break; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - if (!$is_known_host) { |
|
| 230 | - $host = trim($parsed_url['host'], '.'); |
|
| 231 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 232 | - $ip = gethostbyname($host); |
|
| 233 | - if ($ip === $host) { |
|
| 234 | - // Error condition for gethostbyname() |
|
| 235 | - $ip = false; |
|
| 236 | - } |
|
| 237 | - if ($records = dns_get_record($host)) { |
|
| 238 | - foreach ($records as $record) { |
|
| 239 | - // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 240 | - // se fasse sur la meme IP |
|
| 241 | - if ($record['ttl'] < 10) { |
|
| 242 | - $ip = false; |
|
| 243 | - break; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - else { |
|
| 248 | - $ip = false; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - if ($ip) { |
|
| 252 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 253 | - return false; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - if (empty($parsed_url['port'])) { |
|
| 259 | - return $url; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - $port = $parsed_url['port']; |
|
| 263 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 264 | - return $url; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - if ($is_known_host) { |
|
| 268 | - foreach ($known_hosts as $known_host) { |
|
| 269 | - $parse_known = parse_url($known_host); |
|
| 270 | - if ( |
|
| 271 | - $parse_known |
|
| 272 | - and !empty($parse_known['port']) |
|
| 273 | - and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 274 | - and $parse_known['port'] == $port |
|
| 275 | - ) { |
|
| 276 | - return $url; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - return false; |
|
| 189 | + if (!function_exists('protocole_verifier')) { |
|
| 190 | + include_spip('inc/filtres_mini'); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if (!protocole_verifier($url, ['http', 'https'])) { |
|
| 194 | + return false; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + $parsed_url = parse_url($url); |
|
| 198 | + if (!$parsed_url or empty($parsed_url['host'])) { |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if (isset($parsed_url['user']) or isset($parsed_url['pass'])) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if (false !== strpbrk($parsed_url['host'], ':#?[]')) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + if (!is_array($known_hosts)) { |
|
| 211 | + $known_hosts = [$known_hosts]; |
|
| 212 | + } |
|
| 213 | + $known_hosts[] = $GLOBALS['meta']['adresse_site']; |
|
| 214 | + $known_hosts[] = url_de_base(); |
|
| 215 | + $known_hosts = pipeline('declarer_hosts_distants', $known_hosts); |
|
| 216 | + |
|
| 217 | + $is_known_host = false; |
|
| 218 | + foreach ($known_hosts as $known_host) { |
|
| 219 | + $parse_known = parse_url($known_host); |
|
| 220 | + if ( |
|
| 221 | + $parse_known |
|
| 222 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 223 | + ) { |
|
| 224 | + $is_known_host = true; |
|
| 225 | + break; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + if (!$is_known_host) { |
|
| 230 | + $host = trim($parsed_url['host'], '.'); |
|
| 231 | + if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 232 | + $ip = gethostbyname($host); |
|
| 233 | + if ($ip === $host) { |
|
| 234 | + // Error condition for gethostbyname() |
|
| 235 | + $ip = false; |
|
| 236 | + } |
|
| 237 | + if ($records = dns_get_record($host)) { |
|
| 238 | + foreach ($records as $record) { |
|
| 239 | + // il faut que le TTL soit suffisant afin d'etre certain que le copie_locale eventuel qui suit |
|
| 240 | + // se fasse sur la meme IP |
|
| 241 | + if ($record['ttl'] < 10) { |
|
| 242 | + $ip = false; |
|
| 243 | + break; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + else { |
|
| 248 | + $ip = false; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + if ($ip) { |
|
| 252 | + if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 253 | + return false; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + if (empty($parsed_url['port'])) { |
|
| 259 | + return $url; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + $port = $parsed_url['port']; |
|
| 263 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 264 | + return $url; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + if ($is_known_host) { |
|
| 268 | + foreach ($known_hosts as $known_host) { |
|
| 269 | + $parse_known = parse_url($known_host); |
|
| 270 | + if ( |
|
| 271 | + $parse_known |
|
| 272 | + and !empty($parse_known['port']) |
|
| 273 | + and strtolower($parse_known['host']) === strtolower($parsed_url['host']) |
|
| 274 | + and $parse_known['port'] == $port |
|
| 275 | + ) { |
|
| 276 | + return $url; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + return false; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -298,86 +298,86 @@ discard block |
||
| 298 | 298 | */ |
| 299 | 299 | function prepare_donnees_post($donnees, $boundary = '') { |
| 300 | 300 | |
| 301 | - // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 302 | - // pour un appel soap par exemple |
|
| 303 | - // l'entete est separe des donnees par un double retour a la ligne |
|
| 304 | - // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 305 | - if (is_string($donnees) && strlen($donnees)) { |
|
| 306 | - $entete = ''; |
|
| 307 | - // on repasse tous les \r\n et \r en simples \n |
|
| 308 | - $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 309 | - $donnees = str_replace("\r", "\n", $donnees); |
|
| 310 | - // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 311 | - $p = strpos($donnees, "\n\n"); |
|
| 312 | - if ($p !== false) { |
|
| 313 | - $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 314 | - $donnees = substr($donnees, $p + 2); |
|
| 315 | - } |
|
| 316 | - $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 317 | - } else { |
|
| 318 | - /* boundary automatique */ |
|
| 319 | - // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 320 | - if ($boundary === '') { |
|
| 321 | - $taille = 0; |
|
| 322 | - foreach ($donnees as $cle => $valeur) { |
|
| 323 | - if (is_array($valeur)) { |
|
| 324 | - foreach ($valeur as $val2) { |
|
| 325 | - $taille += strlen($val2); |
|
| 326 | - } |
|
| 327 | - } else { |
|
| 328 | - // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 329 | - $taille += strlen($valeur); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - if ($taille > 500) { |
|
| 333 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - if (is_string($boundary) and strlen($boundary)) { |
|
| 338 | - // fabrique une chaine HTTP pour un POST avec boundary |
|
| 339 | - $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 340 | - $chaine = ''; |
|
| 341 | - if (is_array($donnees)) { |
|
| 342 | - foreach ($donnees as $cle => $valeur) { |
|
| 343 | - if (is_array($valeur)) { |
|
| 344 | - foreach ($valeur as $val2) { |
|
| 345 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 346 | - $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 347 | - $chaine .= "\r\n"; |
|
| 348 | - $chaine .= $val2; |
|
| 349 | - } |
|
| 350 | - } else { |
|
| 351 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 352 | - $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 353 | - $chaine .= "\r\n"; |
|
| 354 | - $chaine .= $valeur; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $chaine .= "\r\n--$boundary\r\n"; |
|
| 358 | - } |
|
| 359 | - } else { |
|
| 360 | - // fabrique une chaine HTTP simple pour un POST |
|
| 361 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 362 | - $chaine = []; |
|
| 363 | - if (is_array($donnees)) { |
|
| 364 | - foreach ($donnees as $cle => $valeur) { |
|
| 365 | - if (is_array($valeur)) { |
|
| 366 | - foreach ($valeur as $val2) { |
|
| 367 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 368 | - } |
|
| 369 | - } else { |
|
| 370 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - $chaine = implode('&', $chaine); |
|
| 374 | - } else { |
|
| 375 | - $chaine = $donnees; |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - return [$entete, $chaine]; |
|
| 301 | + // permettre a la fonction qui a demande le post de formater elle meme ses donnees |
|
| 302 | + // pour un appel soap par exemple |
|
| 303 | + // l'entete est separe des donnees par un double retour a la ligne |
|
| 304 | + // on s'occupe ici de passer tous les retours lignes (\r\n, \r ou \n) en \r\n |
|
| 305 | + if (is_string($donnees) && strlen($donnees)) { |
|
| 306 | + $entete = ''; |
|
| 307 | + // on repasse tous les \r\n et \r en simples \n |
|
| 308 | + $donnees = str_replace("\r\n", "\n", $donnees); |
|
| 309 | + $donnees = str_replace("\r", "\n", $donnees); |
|
| 310 | + // un double retour a la ligne signifie la fin de l'entete et le debut des donnees |
|
| 311 | + $p = strpos($donnees, "\n\n"); |
|
| 312 | + if ($p !== false) { |
|
| 313 | + $entete = str_replace("\n", "\r\n", substr($donnees, 0, $p + 1)); |
|
| 314 | + $donnees = substr($donnees, $p + 2); |
|
| 315 | + } |
|
| 316 | + $chaine = str_replace("\n", "\r\n", $donnees); |
|
| 317 | + } else { |
|
| 318 | + /* boundary automatique */ |
|
| 319 | + // Si on a plus de 500 octects de donnees, on "boundarise" |
|
| 320 | + if ($boundary === '') { |
|
| 321 | + $taille = 0; |
|
| 322 | + foreach ($donnees as $cle => $valeur) { |
|
| 323 | + if (is_array($valeur)) { |
|
| 324 | + foreach ($valeur as $val2) { |
|
| 325 | + $taille += strlen($val2); |
|
| 326 | + } |
|
| 327 | + } else { |
|
| 328 | + // faut-il utiliser spip_strlen() dans inc/charsets ? |
|
| 329 | + $taille += strlen($valeur); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + if ($taille > 500) { |
|
| 333 | + $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + if (is_string($boundary) and strlen($boundary)) { |
|
| 338 | + // fabrique une chaine HTTP pour un POST avec boundary |
|
| 339 | + $entete = "Content-Type: multipart/form-data; boundary=$boundary\r\n"; |
|
| 340 | + $chaine = ''; |
|
| 341 | + if (is_array($donnees)) { |
|
| 342 | + foreach ($donnees as $cle => $valeur) { |
|
| 343 | + if (is_array($valeur)) { |
|
| 344 | + foreach ($valeur as $val2) { |
|
| 345 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 346 | + $chaine .= "Content-Disposition: form-data; name=\"{$cle}[]\"\r\n"; |
|
| 347 | + $chaine .= "\r\n"; |
|
| 348 | + $chaine .= $val2; |
|
| 349 | + } |
|
| 350 | + } else { |
|
| 351 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 352 | + $chaine .= "Content-Disposition: form-data; name=\"$cle\"\r\n"; |
|
| 353 | + $chaine .= "\r\n"; |
|
| 354 | + $chaine .= $valeur; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $chaine .= "\r\n--$boundary\r\n"; |
|
| 358 | + } |
|
| 359 | + } else { |
|
| 360 | + // fabrique une chaine HTTP simple pour un POST |
|
| 361 | + $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 362 | + $chaine = []; |
|
| 363 | + if (is_array($donnees)) { |
|
| 364 | + foreach ($donnees as $cle => $valeur) { |
|
| 365 | + if (is_array($valeur)) { |
|
| 366 | + foreach ($valeur as $val2) { |
|
| 367 | + $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 368 | + } |
|
| 369 | + } else { |
|
| 370 | + $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + $chaine = implode('&', $chaine); |
|
| 374 | + } else { |
|
| 375 | + $chaine = $donnees; |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + return [$entete, $chaine]; |
|
| 381 | 381 | } |
| 382 | 382 | |
| 383 | 383 | /** |
@@ -388,19 +388,19 @@ discard block |
||
| 388 | 388 | */ |
| 389 | 389 | function url_to_ascii($url_idn) { |
| 390 | 390 | |
| 391 | - if ($parts = parse_url($url_idn)) { |
|
| 392 | - $host = $parts['host']; |
|
| 393 | - if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 394 | - $converter = new ToIdn(); |
|
| 395 | - $host_ascii = $converter->convert($host); |
|
| 396 | - $url_idn = explode($host, $url_idn, 2); |
|
| 397 | - $url_idn = implode($host_ascii, $url_idn); |
|
| 398 | - } |
|
| 399 | - // et on urlencode les char utf si besoin dans le path |
|
| 400 | - $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return $url_idn; |
|
| 391 | + if ($parts = parse_url($url_idn)) { |
|
| 392 | + $host = $parts['host']; |
|
| 393 | + if (!preg_match(',^[a-z0-9_\.\-]+$,i', $host)) { |
|
| 394 | + $converter = new ToIdn(); |
|
| 395 | + $host_ascii = $converter->convert($host); |
|
| 396 | + $url_idn = explode($host, $url_idn, 2); |
|
| 397 | + $url_idn = implode($host_ascii, $url_idn); |
|
| 398 | + } |
|
| 399 | + // et on urlencode les char utf si besoin dans le path |
|
| 400 | + $url_idn = preg_replace_callback('/[^\x20-\x7f]/', fn($match) => urlencode($match[0]), $url_idn); |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return $url_idn; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -441,209 +441,209 @@ discard block |
||
| 441 | 441 | * string file : nom du fichier si enregistre dans un fichier |
| 442 | 442 | */ |
| 443 | 443 | function recuperer_url($url, $options = []) { |
| 444 | - // Conserve la mémoire de la méthode fournit éventuellement |
|
| 445 | - $methode_demandee = $options['methode'] ?? ''; |
|
| 446 | - $default = [ |
|
| 447 | - 'transcoder' => false, |
|
| 448 | - 'methode' => 'GET', |
|
| 449 | - 'taille_max' => null, |
|
| 450 | - 'headers' => [], |
|
| 451 | - 'datas' => '', |
|
| 452 | - 'boundary' => '', |
|
| 453 | - 'refuser_gz' => false, |
|
| 454 | - 'if_modified_since' => '', |
|
| 455 | - 'uri_referer' => '', |
|
| 456 | - 'file' => '', |
|
| 457 | - 'follow_location' => 10, |
|
| 458 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 459 | - ]; |
|
| 460 | - $options = array_merge($default, $options); |
|
| 461 | - // copier directement dans un fichier ? |
|
| 462 | - $copy = $options['file']; |
|
| 463 | - |
|
| 464 | - if ($options['methode'] == 'HEAD') { |
|
| 465 | - $options['taille_max'] = 0; |
|
| 466 | - } |
|
| 467 | - if (is_null($options['taille_max'])) { |
|
| 468 | - $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 472 | - |
|
| 473 | - // Ajout des en-têtes spécifiques si besoin |
|
| 474 | - $formatted_data = ''; |
|
| 475 | - if (!empty($options['headers'])) { |
|
| 476 | - foreach ($options['headers'] as $champ => $valeur) { |
|
| 477 | - $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - |
|
| 481 | - if (!empty($options['datas'])) { |
|
| 482 | - [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 483 | - $head .= $formatted_data; |
|
| 484 | - if (stripos($head, 'Content-Length:') === false) { |
|
| 485 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 486 | - } |
|
| 487 | - $formatted_data = $head . "\r\n" . $postdata; |
|
| 488 | - if ( |
|
| 489 | - strlen($postdata) |
|
| 490 | - and !$methode_demandee |
|
| 491 | - ) { |
|
| 492 | - $options['methode'] = 'POST'; |
|
| 493 | - } |
|
| 494 | - } elseif ($formatted_data) { |
|
| 495 | - $formatted_data .= "\r\n"; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 499 | - $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 500 | - if (!tester_url_absolue($url)) { |
|
| 501 | - $url = 'http://' . $url; |
|
| 502 | - } elseif (strncmp($url, '//', 2) == 0) { |
|
| 503 | - $url = 'http:' . $url; |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - $url = url_to_ascii($url); |
|
| 507 | - |
|
| 508 | - $result = [ |
|
| 509 | - 'status' => 0, |
|
| 510 | - 'headers' => '', |
|
| 511 | - 'page' => '', |
|
| 512 | - 'length' => 0, |
|
| 513 | - 'last_modified' => '', |
|
| 514 | - 'location' => '', |
|
| 515 | - 'url' => $url |
|
| 516 | - ]; |
|
| 517 | - |
|
| 518 | - // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 519 | - $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 520 | - |
|
| 521 | - // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 522 | - [$handle, $fopen] = init_http( |
|
| 523 | - $options['methode'], |
|
| 524 | - $url, |
|
| 525 | - $refuser_gz, |
|
| 526 | - $options['uri_referer'], |
|
| 527 | - $formatted_data, |
|
| 528 | - $options['version_http'], |
|
| 529 | - $options['if_modified_since'] |
|
| 530 | - ); |
|
| 531 | - if (!$handle) { |
|
| 532 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 533 | - |
|
| 534 | - return false; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - // Sauf en fopen, envoyer le flux d'entree |
|
| 538 | - // et recuperer les en-tetes de reponses |
|
| 539 | - if (!$fopen) { |
|
| 540 | - $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 541 | - if (!$res) { |
|
| 542 | - fclose($handle); |
|
| 543 | - $t = @parse_url($url); |
|
| 544 | - $host = $t['host']; |
|
| 545 | - // Chinoisierie inexplicable pour contrer |
|
| 546 | - // les actions liberticides de l'empire du milieu |
|
| 547 | - if ( |
|
| 548 | - !need_proxy($host) |
|
| 549 | - and $res = @file_get_contents($url) |
|
| 550 | - ) { |
|
| 551 | - $result['length'] = strlen($res); |
|
| 552 | - if ($copy) { |
|
| 553 | - ecrire_fichier($copy, $res); |
|
| 554 | - $result['file'] = $copy; |
|
| 555 | - } else { |
|
| 556 | - $result['page'] = $res; |
|
| 557 | - } |
|
| 558 | - $res = [ |
|
| 559 | - 'status' => 200, |
|
| 560 | - ]; |
|
| 561 | - } else { |
|
| 562 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 563 | - return false; |
|
| 564 | - } |
|
| 565 | - } elseif ($res['location'] and $options['follow_location']) { |
|
| 566 | - $options['follow_location']--; |
|
| 567 | - fclose($handle); |
|
| 568 | - include_spip('inc/filtres'); |
|
| 569 | - $url = suivre_lien($url, $res['location']); |
|
| 570 | - |
|
| 571 | - // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 572 | - if ($options['methode'] !== 'GET') { |
|
| 573 | - if (empty($res['status']) or !in_array($res['status'], [307, 308])) { |
|
| 574 | - $options['methode'] = 'GET'; |
|
| 575 | - $options['datas'] = ''; |
|
| 576 | - } |
|
| 577 | - } |
|
| 578 | - spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 579 | - |
|
| 580 | - return recuperer_url($url, $options); |
|
| 581 | - } elseif ($res['status'] !== 200) { |
|
| 582 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 583 | - } |
|
| 584 | - $result['status'] = $res['status']; |
|
| 585 | - if (isset($res['headers'])) { |
|
| 586 | - $result['headers'] = $res['headers']; |
|
| 587 | - } |
|
| 588 | - if (isset($res['last_modified'])) { |
|
| 589 | - $result['last_modified'] = $res['last_modified']; |
|
| 590 | - } |
|
| 591 | - if (isset($res['location'])) { |
|
| 592 | - $result['location'] = $res['location']; |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - // on ne veut que les entetes |
|
| 597 | - if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 598 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 599 | - return $result; |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - |
|
| 603 | - // s'il faut deballer, le faire via un fichier temporaire |
|
| 604 | - // sinon la memoire explose pour les gros flux |
|
| 605 | - |
|
| 606 | - $gz = false; |
|
| 607 | - if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 608 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - // si on a pas deja recuperer le contenu par une methode detournee |
|
| 612 | - if (!$result['length']) { |
|
| 613 | - $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 614 | - fclose($handle); |
|
| 615 | - if ($copy) { |
|
| 616 | - $result['length'] = $res; |
|
| 617 | - $result['file'] = $copy; |
|
| 618 | - } elseif ($res) { |
|
| 619 | - $result['page'] = &$res; |
|
| 620 | - $result['length'] = strlen($result['page']); |
|
| 621 | - } |
|
| 622 | - if (!$result['status']) { |
|
| 623 | - $result['status'] = 200; // on a reussi, donc ! |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - if (!$result['page']) { |
|
| 627 | - return $result; |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - // Decompresser au besoin |
|
| 631 | - if ($gz) { |
|
| 632 | - $result['page'] = implode('', gzfile($gz)); |
|
| 633 | - supprimer_fichier($gz); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - // Faut-il l'importer dans notre charset local ? |
|
| 637 | - if ($options['transcoder']) { |
|
| 638 | - include_spip('inc/charsets'); |
|
| 639 | - $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $trace = json_decode(json_encode($result), true); |
|
| 643 | - $trace['page'] = '...'; |
|
| 644 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 645 | - |
|
| 646 | - return $result; |
|
| 444 | + // Conserve la mémoire de la méthode fournit éventuellement |
|
| 445 | + $methode_demandee = $options['methode'] ?? ''; |
|
| 446 | + $default = [ |
|
| 447 | + 'transcoder' => false, |
|
| 448 | + 'methode' => 'GET', |
|
| 449 | + 'taille_max' => null, |
|
| 450 | + 'headers' => [], |
|
| 451 | + 'datas' => '', |
|
| 452 | + 'boundary' => '', |
|
| 453 | + 'refuser_gz' => false, |
|
| 454 | + 'if_modified_since' => '', |
|
| 455 | + 'uri_referer' => '', |
|
| 456 | + 'file' => '', |
|
| 457 | + 'follow_location' => 10, |
|
| 458 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 459 | + ]; |
|
| 460 | + $options = array_merge($default, $options); |
|
| 461 | + // copier directement dans un fichier ? |
|
| 462 | + $copy = $options['file']; |
|
| 463 | + |
|
| 464 | + if ($options['methode'] == 'HEAD') { |
|
| 465 | + $options['taille_max'] = 0; |
|
| 466 | + } |
|
| 467 | + if (is_null($options['taille_max'])) { |
|
| 468 | + $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 472 | + |
|
| 473 | + // Ajout des en-têtes spécifiques si besoin |
|
| 474 | + $formatted_data = ''; |
|
| 475 | + if (!empty($options['headers'])) { |
|
| 476 | + foreach ($options['headers'] as $champ => $valeur) { |
|
| 477 | + $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + |
|
| 481 | + if (!empty($options['datas'])) { |
|
| 482 | + [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
|
| 483 | + $head .= $formatted_data; |
|
| 484 | + if (stripos($head, 'Content-Length:') === false) { |
|
| 485 | + $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 486 | + } |
|
| 487 | + $formatted_data = $head . "\r\n" . $postdata; |
|
| 488 | + if ( |
|
| 489 | + strlen($postdata) |
|
| 490 | + and !$methode_demandee |
|
| 491 | + ) { |
|
| 492 | + $options['methode'] = 'POST'; |
|
| 493 | + } |
|
| 494 | + } elseif ($formatted_data) { |
|
| 495 | + $formatted_data .= "\r\n"; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
|
| 499 | + $url = preg_replace(',^feed://,i', 'http://', $url); |
|
| 500 | + if (!tester_url_absolue($url)) { |
|
| 501 | + $url = 'http://' . $url; |
|
| 502 | + } elseif (strncmp($url, '//', 2) == 0) { |
|
| 503 | + $url = 'http:' . $url; |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + $url = url_to_ascii($url); |
|
| 507 | + |
|
| 508 | + $result = [ |
|
| 509 | + 'status' => 0, |
|
| 510 | + 'headers' => '', |
|
| 511 | + 'page' => '', |
|
| 512 | + 'length' => 0, |
|
| 513 | + 'last_modified' => '', |
|
| 514 | + 'location' => '', |
|
| 515 | + 'url' => $url |
|
| 516 | + ]; |
|
| 517 | + |
|
| 518 | + // si on ecrit directement dans un fichier, pour ne pas manipuler en memoire refuser gz |
|
| 519 | + $refuser_gz = (($options['refuser_gz'] or $copy) ? true : false); |
|
| 520 | + |
|
| 521 | + // ouvrir la connexion et envoyer la requete et ses en-tetes |
|
| 522 | + [$handle, $fopen] = init_http( |
|
| 523 | + $options['methode'], |
|
| 524 | + $url, |
|
| 525 | + $refuser_gz, |
|
| 526 | + $options['uri_referer'], |
|
| 527 | + $formatted_data, |
|
| 528 | + $options['version_http'], |
|
| 529 | + $options['if_modified_since'] |
|
| 530 | + ); |
|
| 531 | + if (!$handle) { |
|
| 532 | + spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 533 | + |
|
| 534 | + return false; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + // Sauf en fopen, envoyer le flux d'entree |
|
| 538 | + // et recuperer les en-tetes de reponses |
|
| 539 | + if (!$fopen) { |
|
| 540 | + $res = recuperer_entetes_complets($handle, $options['if_modified_since']); |
|
| 541 | + if (!$res) { |
|
| 542 | + fclose($handle); |
|
| 543 | + $t = @parse_url($url); |
|
| 544 | + $host = $t['host']; |
|
| 545 | + // Chinoisierie inexplicable pour contrer |
|
| 546 | + // les actions liberticides de l'empire du milieu |
|
| 547 | + if ( |
|
| 548 | + !need_proxy($host) |
|
| 549 | + and $res = @file_get_contents($url) |
|
| 550 | + ) { |
|
| 551 | + $result['length'] = strlen($res); |
|
| 552 | + if ($copy) { |
|
| 553 | + ecrire_fichier($copy, $res); |
|
| 554 | + $result['file'] = $copy; |
|
| 555 | + } else { |
|
| 556 | + $result['page'] = $res; |
|
| 557 | + } |
|
| 558 | + $res = [ |
|
| 559 | + 'status' => 200, |
|
| 560 | + ]; |
|
| 561 | + } else { |
|
| 562 | + spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 563 | + return false; |
|
| 564 | + } |
|
| 565 | + } elseif ($res['location'] and $options['follow_location']) { |
|
| 566 | + $options['follow_location']--; |
|
| 567 | + fclose($handle); |
|
| 568 | + include_spip('inc/filtres'); |
|
| 569 | + $url = suivre_lien($url, $res['location']); |
|
| 570 | + |
|
| 571 | + // une redirection doit se faire en GET, sauf status explicite 307 ou 308 qui indique de garder la meme methode |
|
| 572 | + if ($options['methode'] !== 'GET') { |
|
| 573 | + if (empty($res['status']) or !in_array($res['status'], [307, 308])) { |
|
| 574 | + $options['methode'] = 'GET'; |
|
| 575 | + $options['datas'] = ''; |
|
| 576 | + } |
|
| 577 | + } |
|
| 578 | + spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 579 | + |
|
| 580 | + return recuperer_url($url, $options); |
|
| 581 | + } elseif ($res['status'] !== 200) { |
|
| 582 | + spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 583 | + } |
|
| 584 | + $result['status'] = $res['status']; |
|
| 585 | + if (isset($res['headers'])) { |
|
| 586 | + $result['headers'] = $res['headers']; |
|
| 587 | + } |
|
| 588 | + if (isset($res['last_modified'])) { |
|
| 589 | + $result['last_modified'] = $res['last_modified']; |
|
| 590 | + } |
|
| 591 | + if (isset($res['location'])) { |
|
| 592 | + $result['location'] = $res['location']; |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + // on ne veut que les entetes |
|
| 597 | + if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
|
| 598 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 599 | + return $result; |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + |
|
| 603 | + // s'il faut deballer, le faire via un fichier temporaire |
|
| 604 | + // sinon la memoire explose pour les gros flux |
|
| 605 | + |
|
| 606 | + $gz = false; |
|
| 607 | + if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
|
| 608 | + $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + // si on a pas deja recuperer le contenu par une methode detournee |
|
| 612 | + if (!$result['length']) { |
|
| 613 | + $res = recuperer_body($handle, $options['taille_max'], $gz ?: $copy); |
|
| 614 | + fclose($handle); |
|
| 615 | + if ($copy) { |
|
| 616 | + $result['length'] = $res; |
|
| 617 | + $result['file'] = $copy; |
|
| 618 | + } elseif ($res) { |
|
| 619 | + $result['page'] = &$res; |
|
| 620 | + $result['length'] = strlen($result['page']); |
|
| 621 | + } |
|
| 622 | + if (!$result['status']) { |
|
| 623 | + $result['status'] = 200; // on a reussi, donc ! |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + if (!$result['page']) { |
|
| 627 | + return $result; |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + // Decompresser au besoin |
|
| 631 | + if ($gz) { |
|
| 632 | + $result['page'] = implode('', gzfile($gz)); |
|
| 633 | + supprimer_fichier($gz); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + // Faut-il l'importer dans notre charset local ? |
|
| 637 | + if ($options['transcoder']) { |
|
| 638 | + include_spip('inc/charsets'); |
|
| 639 | + $result['page'] = transcoder_page($result['page'], $result['headers']); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $trace = json_decode(json_encode($result), true); |
|
| 643 | + $trace['page'] = '...'; |
|
| 644 | + spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 645 | + |
|
| 646 | + return $result; |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | /** |
@@ -659,73 +659,73 @@ discard block |
||
| 659 | 659 | * @return array|bool|mixed |
| 660 | 660 | */ |
| 661 | 661 | function recuperer_url_cache($url, $options = []) { |
| 662 | - if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 663 | - define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 664 | - } |
|
| 665 | - $default = [ |
|
| 666 | - 'transcoder' => false, |
|
| 667 | - 'methode' => 'GET', |
|
| 668 | - 'taille_max' => null, |
|
| 669 | - 'datas' => '', |
|
| 670 | - 'boundary' => '', |
|
| 671 | - 'refuser_gz' => false, |
|
| 672 | - 'if_modified_since' => '', |
|
| 673 | - 'uri_referer' => '', |
|
| 674 | - 'file' => '', |
|
| 675 | - 'follow_location' => 10, |
|
| 676 | - 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 677 | - 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 678 | - ]; |
|
| 679 | - $options = array_merge($default, $options); |
|
| 680 | - |
|
| 681 | - // cas ou il n'est pas possible de cacher |
|
| 682 | - if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 683 | - return recuperer_url($url, $options); |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 687 | - static $errors = []; |
|
| 688 | - if (isset($errors[$url])) { |
|
| 689 | - return $errors[$url]; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $sig = $options; |
|
| 693 | - unset($sig['if_modified_since']); |
|
| 694 | - unset($sig['delai_cache']); |
|
| 695 | - $sig['url'] = $url; |
|
| 696 | - |
|
| 697 | - $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 698 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 699 | - $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 700 | - $cache = "$sub$cache"; |
|
| 701 | - |
|
| 702 | - $res = false; |
|
| 703 | - $is_cached = file_exists($cache); |
|
| 704 | - if ( |
|
| 705 | - $is_cached |
|
| 706 | - and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 707 | - ) { |
|
| 708 | - lire_fichier($cache, $res); |
|
| 709 | - if ($res = unserialize($res)) { |
|
| 710 | - // mettre le last_modified et le status=304 ? |
|
| 711 | - } |
|
| 712 | - } |
|
| 713 | - if (!$res) { |
|
| 714 | - $res = recuperer_url($url, $options); |
|
| 715 | - // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 716 | - if (!$res) { |
|
| 717 | - if ($is_cached) { |
|
| 718 | - // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 719 | - lire_fichier($cache, $res); |
|
| 720 | - $res = unserialize($res); |
|
| 721 | - } |
|
| 722 | - |
|
| 723 | - return $errors[$url] = $res; |
|
| 724 | - } |
|
| 725 | - ecrire_fichier($cache, serialize($res)); |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - return $res; |
|
| 662 | + if (!defined('_DELAI_RECUPERER_URL_CACHE')) { |
|
| 663 | + define('_DELAI_RECUPERER_URL_CACHE', 3600); |
|
| 664 | + } |
|
| 665 | + $default = [ |
|
| 666 | + 'transcoder' => false, |
|
| 667 | + 'methode' => 'GET', |
|
| 668 | + 'taille_max' => null, |
|
| 669 | + 'datas' => '', |
|
| 670 | + 'boundary' => '', |
|
| 671 | + 'refuser_gz' => false, |
|
| 672 | + 'if_modified_since' => '', |
|
| 673 | + 'uri_referer' => '', |
|
| 674 | + 'file' => '', |
|
| 675 | + 'follow_location' => 10, |
|
| 676 | + 'version_http' => _INC_DISTANT_VERSION_HTTP, |
|
| 677 | + 'delai_cache' => in_array(_VAR_MODE, ['preview', 'recalcul']) ? 0 : _DELAI_RECUPERER_URL_CACHE, |
|
| 678 | + ]; |
|
| 679 | + $options = array_merge($default, $options); |
|
| 680 | + |
|
| 681 | + // cas ou il n'est pas possible de cacher |
|
| 682 | + if (!empty($options['data']) or $options['methode'] == 'POST') { |
|
| 683 | + return recuperer_url($url, $options); |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + // ne pas tenter plusieurs fois la meme url en erreur (non cachee donc) |
|
| 687 | + static $errors = []; |
|
| 688 | + if (isset($errors[$url])) { |
|
| 689 | + return $errors[$url]; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $sig = $options; |
|
| 693 | + unset($sig['if_modified_since']); |
|
| 694 | + unset($sig['delai_cache']); |
|
| 695 | + $sig['url'] = $url; |
|
| 696 | + |
|
| 697 | + $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
|
| 698 | + $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 699 | + $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
|
| 700 | + $cache = "$sub$cache"; |
|
| 701 | + |
|
| 702 | + $res = false; |
|
| 703 | + $is_cached = file_exists($cache); |
|
| 704 | + if ( |
|
| 705 | + $is_cached |
|
| 706 | + and (filemtime($cache) > $_SERVER['REQUEST_TIME'] - $options['delai_cache']) |
|
| 707 | + ) { |
|
| 708 | + lire_fichier($cache, $res); |
|
| 709 | + if ($res = unserialize($res)) { |
|
| 710 | + // mettre le last_modified et le status=304 ? |
|
| 711 | + } |
|
| 712 | + } |
|
| 713 | + if (!$res) { |
|
| 714 | + $res = recuperer_url($url, $options); |
|
| 715 | + // ne pas recharger cette url non cachee dans le meme hit puisque non disponible |
|
| 716 | + if (!$res) { |
|
| 717 | + if ($is_cached) { |
|
| 718 | + // on a pas reussi a recuperer mais on avait un cache : l'utiliser |
|
| 719 | + lire_fichier($cache, $res); |
|
| 720 | + $res = unserialize($res); |
|
| 721 | + } |
|
| 722 | + |
|
| 723 | + return $errors[$url] = $res; |
|
| 724 | + } |
|
| 725 | + ecrire_fichier($cache, serialize($res)); |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + return $res; |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -743,42 +743,42 @@ discard block |
||
| 743 | 743 | * string contenu de la resource |
| 744 | 744 | */ |
| 745 | 745 | function recuperer_body($handle, $taille_max = _INC_DISTANT_MAX_SIZE, $fichier = '') { |
| 746 | - $tmpfile = null; |
|
| 747 | - $taille = 0; |
|
| 748 | - $result = ''; |
|
| 749 | - $fp = false; |
|
| 750 | - if ($fichier) { |
|
| 751 | - include_spip('inc/acces'); |
|
| 752 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 753 | - $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 754 | - if (!$fp and file_exists($fichier)) { |
|
| 755 | - return filesize($fichier); |
|
| 756 | - } |
|
| 757 | - if (!$fp) { |
|
| 758 | - return false; |
|
| 759 | - } |
|
| 760 | - $result = 0; // on renvoie la taille du fichier |
|
| 761 | - } |
|
| 762 | - while (!feof($handle) and $taille < $taille_max) { |
|
| 763 | - $res = fread($handle, 16384); |
|
| 764 | - $taille += strlen($res); |
|
| 765 | - if ($fp) { |
|
| 766 | - fwrite($fp, $res); |
|
| 767 | - $result = $taille; |
|
| 768 | - } else { |
|
| 769 | - $result .= $res; |
|
| 770 | - } |
|
| 771 | - } |
|
| 772 | - if ($fp) { |
|
| 773 | - spip_fclose_unlock($fp); |
|
| 774 | - spip_unlink($fichier); |
|
| 775 | - @rename($tmpfile, $fichier); |
|
| 776 | - if (!file_exists($fichier)) { |
|
| 777 | - return false; |
|
| 778 | - } |
|
| 779 | - } |
|
| 780 | - |
|
| 781 | - return $result; |
|
| 746 | + $tmpfile = null; |
|
| 747 | + $taille = 0; |
|
| 748 | + $result = ''; |
|
| 749 | + $fp = false; |
|
| 750 | + if ($fichier) { |
|
| 751 | + include_spip('inc/acces'); |
|
| 752 | + $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 753 | + $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
|
| 754 | + if (!$fp and file_exists($fichier)) { |
|
| 755 | + return filesize($fichier); |
|
| 756 | + } |
|
| 757 | + if (!$fp) { |
|
| 758 | + return false; |
|
| 759 | + } |
|
| 760 | + $result = 0; // on renvoie la taille du fichier |
|
| 761 | + } |
|
| 762 | + while (!feof($handle) and $taille < $taille_max) { |
|
| 763 | + $res = fread($handle, 16384); |
|
| 764 | + $taille += strlen($res); |
|
| 765 | + if ($fp) { |
|
| 766 | + fwrite($fp, $res); |
|
| 767 | + $result = $taille; |
|
| 768 | + } else { |
|
| 769 | + $result .= $res; |
|
| 770 | + } |
|
| 771 | + } |
|
| 772 | + if ($fp) { |
|
| 773 | + spip_fclose_unlock($fp); |
|
| 774 | + spip_unlink($fichier); |
|
| 775 | + @rename($tmpfile, $fichier); |
|
| 776 | + if (!file_exists($fichier)) { |
|
| 777 | + return false; |
|
| 778 | + } |
|
| 779 | + } |
|
| 780 | + |
|
| 781 | + return $result; |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
@@ -800,35 +800,35 @@ discard block |
||
| 800 | 800 | * string location |
| 801 | 801 | */ |
| 802 | 802 | function recuperer_entetes_complets($handle, $if_modified_since = false) { |
| 803 | - $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 804 | - |
|
| 805 | - $s = @trim(fgets($handle, 16384)); |
|
| 806 | - if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - $result['status'] = intval($r[1]); |
|
| 810 | - while ($s = trim(fgets($handle, 16384))) { |
|
| 811 | - $result['headers'][] = $s . "\n"; |
|
| 812 | - preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 813 | - [, $d, $v] = $r; |
|
| 814 | - if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 815 | - $result['location'] = $v; |
|
| 816 | - } elseif ($d == 'Last-Modified') { |
|
| 817 | - $result['last_modified'] = strtotime($v); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - if ( |
|
| 821 | - $if_modified_since |
|
| 822 | - and $result['last_modified'] |
|
| 823 | - and $if_modified_since > $result['last_modified'] |
|
| 824 | - and $result['status'] == 200 |
|
| 825 | - ) { |
|
| 826 | - $result['status'] = 304; |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - $result['headers'] = implode('', $result['headers']); |
|
| 830 | - |
|
| 831 | - return $result; |
|
| 803 | + $result = ['status' => 0, 'headers' => [], 'last_modified' => 0, 'location' => '']; |
|
| 804 | + |
|
| 805 | + $s = @trim(fgets($handle, 16384)); |
|
| 806 | + if (!preg_match(',^HTTP/[0-9]+\.[0-9]+ ([0-9]+),', $s, $r)) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + $result['status'] = intval($r[1]); |
|
| 810 | + while ($s = trim(fgets($handle, 16384))) { |
|
| 811 | + $result['headers'][] = $s . "\n"; |
|
| 812 | + preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
|
| 813 | + [, $d, $v] = $r; |
|
| 814 | + if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
|
| 815 | + $result['location'] = $v; |
|
| 816 | + } elseif ($d == 'Last-Modified') { |
|
| 817 | + $result['last_modified'] = strtotime($v); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + if ( |
|
| 821 | + $if_modified_since |
|
| 822 | + and $result['last_modified'] |
|
| 823 | + and $if_modified_since > $result['last_modified'] |
|
| 824 | + and $result['status'] == 200 |
|
| 825 | + ) { |
|
| 826 | + $result['status'] = 304; |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + $result['headers'] = implode('', $result['headers']); |
|
| 830 | + |
|
| 831 | + return $result; |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -850,22 +850,22 @@ discard block |
||
| 850 | 850 | * Nom du fichier pour copie locale |
| 851 | 851 | **/ |
| 852 | 852 | function nom_fichier_copie_locale($source, $extension) { |
| 853 | - include_spip('inc/documents'); |
|
| 853 | + include_spip('inc/documents'); |
|
| 854 | 854 | |
| 855 | - $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 856 | - $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 855 | + $d = creer_repertoire_documents('distant'); # IMG/distant/ |
|
| 856 | + $d = sous_repertoire($d, $extension); # IMG/distant/pdf/ |
|
| 857 | 857 | |
| 858 | - // on se place tout le temps comme si on etait a la racine |
|
| 859 | - if (_DIR_RACINE) { |
|
| 860 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 861 | - } |
|
| 858 | + // on se place tout le temps comme si on etait a la racine |
|
| 859 | + if (_DIR_RACINE) { |
|
| 860 | + $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 861 | + } |
|
| 862 | 862 | |
| 863 | - $m = md5($source); |
|
| 863 | + $m = md5($source); |
|
| 864 | 864 | |
| 865 | - return $d |
|
| 866 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 867 | - . substr($m, 0, 4) |
|
| 868 | - . ".$extension"; |
|
| 865 | + return $d |
|
| 866 | + . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 867 | + . substr($m, 0, 4) |
|
| 868 | + . ".$extension"; |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -884,72 +884,72 @@ discard block |
||
| 884 | 884 | * - null: Copie locale impossible |
| 885 | 885 | **/ |
| 886 | 886 | function fichier_copie_locale($source) { |
| 887 | - // Si c'est deja local pas de souci |
|
| 888 | - if (!tester_url_absolue($source)) { |
|
| 889 | - if (_DIR_RACINE) { |
|
| 890 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 891 | - } |
|
| 892 | - |
|
| 893 | - return $source; |
|
| 894 | - } |
|
| 895 | - |
|
| 896 | - // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 897 | - // a deja ete copie en local avec cette extension |
|
| 898 | - // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 899 | - $path_parts = pathinfo($source); |
|
| 900 | - if (!isset($path_parts['extension'])) { |
|
| 901 | - $path_parts['extension'] = ''; |
|
| 902 | - } |
|
| 903 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 904 | - if ( |
|
| 905 | - $ext |
|
| 906 | - and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 907 | - and $f = nom_fichier_copie_locale($source, $ext) |
|
| 908 | - and file_exists(_DIR_RACINE . $f) |
|
| 909 | - ) { |
|
| 910 | - return $f; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - |
|
| 914 | - // Si c'est deja dans la table des documents, |
|
| 915 | - // ramener le nom de sa copie potentielle |
|
| 916 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 917 | - |
|
| 918 | - if ($ext) { |
|
| 919 | - return nom_fichier_copie_locale($source, $ext); |
|
| 920 | - } |
|
| 921 | - |
|
| 922 | - // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 923 | - // et si il n'aurait pas deja ete rapatrie |
|
| 924 | - |
|
| 925 | - $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 926 | - |
|
| 927 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 928 | - $f = nom_fichier_copie_locale($source, $ext); |
|
| 929 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 930 | - return $f; |
|
| 931 | - } |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - // Ping pour voir si son extension est connue et autorisee |
|
| 935 | - // avec mise en cache du resultat du ping |
|
| 936 | - |
|
| 937 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 938 | - if ( |
|
| 939 | - !@file_exists($cache) |
|
| 940 | - or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 941 | - or _request('var_mode') === 'recalcul' |
|
| 942 | - ) { |
|
| 943 | - $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 944 | - ecrire_fichier($cache, serialize($path_parts)); |
|
| 945 | - } |
|
| 946 | - $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 947 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 948 | - return nom_fichier_copie_locale($source, $ext); |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 952 | - return null; |
|
| 887 | + // Si c'est deja local pas de souci |
|
| 888 | + if (!tester_url_absolue($source)) { |
|
| 889 | + if (_DIR_RACINE) { |
|
| 890 | + $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 891 | + } |
|
| 892 | + |
|
| 893 | + return $source; |
|
| 894 | + } |
|
| 895 | + |
|
| 896 | + // optimisation : on regarde si on peut deviner l'extension dans l'url et si le fichier |
|
| 897 | + // a deja ete copie en local avec cette extension |
|
| 898 | + // dans ce cas elle est fiable, pas la peine de requeter en base |
|
| 899 | + $path_parts = pathinfo($source); |
|
| 900 | + if (!isset($path_parts['extension'])) { |
|
| 901 | + $path_parts['extension'] = ''; |
|
| 902 | + } |
|
| 903 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 904 | + if ( |
|
| 905 | + $ext |
|
| 906 | + and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
|
| 907 | + and $f = nom_fichier_copie_locale($source, $ext) |
|
| 908 | + and file_exists(_DIR_RACINE . $f) |
|
| 909 | + ) { |
|
| 910 | + return $f; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + |
|
| 914 | + // Si c'est deja dans la table des documents, |
|
| 915 | + // ramener le nom de sa copie potentielle |
|
| 916 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 917 | + |
|
| 918 | + if ($ext) { |
|
| 919 | + return nom_fichier_copie_locale($source, $ext); |
|
| 920 | + } |
|
| 921 | + |
|
| 922 | + // voir si l'extension indiquee dans le nom du fichier est ok |
|
| 923 | + // et si il n'aurait pas deja ete rapatrie |
|
| 924 | + |
|
| 925 | + $ext = $path_parts ? $path_parts['extension'] : ''; |
|
| 926 | + |
|
| 927 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 928 | + $f = nom_fichier_copie_locale($source, $ext); |
|
| 929 | + if (file_exists(_DIR_RACINE . $f)) { |
|
| 930 | + return $f; |
|
| 931 | + } |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + // Ping pour voir si son extension est connue et autorisee |
|
| 935 | + // avec mise en cache du resultat du ping |
|
| 936 | + |
|
| 937 | + $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 938 | + if ( |
|
| 939 | + !@file_exists($cache) |
|
| 940 | + or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
|
| 941 | + or _request('var_mode') === 'recalcul' |
|
| 942 | + ) { |
|
| 943 | + $path_parts = recuperer_infos_distantes($source, ['charger_si_petite_image' => false]); |
|
| 944 | + ecrire_fichier($cache, serialize($path_parts)); |
|
| 945 | + } |
|
| 946 | + $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
|
| 947 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 948 | + return nom_fichier_copie_locale($source, $ext); |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 952 | + return null; |
|
| 953 | 953 | } |
| 954 | 954 | |
| 955 | 955 | |
@@ -978,110 +978,110 @@ discard block |
||
| 978 | 978 | **/ |
| 979 | 979 | function recuperer_infos_distantes($source, $options = []) { |
| 980 | 980 | |
| 981 | - // pas la peine de perdre son temps |
|
| 982 | - if (!tester_url_absolue($source)) { |
|
| 983 | - return false; |
|
| 984 | - } |
|
| 985 | - |
|
| 986 | - $taille_max = $options['taille_max'] ?? 0; |
|
| 987 | - $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true); |
|
| 988 | - $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 989 | - |
|
| 990 | - # charger les alias des types mime |
|
| 991 | - include_spip('base/typedoc'); |
|
| 992 | - |
|
| 993 | - $a = []; |
|
| 994 | - $mime_type = ''; |
|
| 995 | - // On va directement charger le debut des images et des fichiers html, |
|
| 996 | - // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 997 | - // ca echoue l'utilisateur devra les entrer... |
|
| 998 | - $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 999 | - if ( |
|
| 1000 | - $callback_valider_url |
|
| 1001 | - and is_callable($callback_valider_url) |
|
| 1002 | - and !$callback_valider_url($reponse['url']) |
|
| 1003 | - ) { |
|
| 1004 | - return false; |
|
| 1005 | - } |
|
| 1006 | - $headers = $reponse['headers'] ?? ''; |
|
| 1007 | - $a['body'] = $reponse['page'] ?? ''; |
|
| 1008 | - if ($headers) { |
|
| 1009 | - if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1010 | - return false; |
|
| 1011 | - } |
|
| 1012 | - |
|
| 1013 | - $a['extension'] = $extension; |
|
| 1014 | - |
|
| 1015 | - if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1016 | - $a['taille'] = intval($regs[1]); |
|
| 1017 | - } |
|
| 1018 | - } |
|
| 1019 | - |
|
| 1020 | - // Echec avec HEAD, on tente avec GET |
|
| 1021 | - if (!$a and !$taille_max) { |
|
| 1022 | - spip_log("tenter GET $source", 'distant'); |
|
| 1023 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1024 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - // si on a rien trouve pas la peine d'insister |
|
| 1028 | - if (!$a) { |
|
| 1029 | - return false; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1033 | - // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1034 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 1035 | - if ( |
|
| 1036 | - strpos($mime_type, 'image/') === 0 |
|
| 1037 | - and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1038 | - ) { |
|
| 1039 | - if ( |
|
| 1040 | - $taille_max == 0 |
|
| 1041 | - and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1042 | - and in_array($extension, formats_image_acceptables()) |
|
| 1043 | - and $charger_si_petite_image |
|
| 1044 | - ) { |
|
| 1045 | - $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1046 | - $a = recuperer_infos_distantes($source, $options); |
|
| 1047 | - } else { |
|
| 1048 | - if ($a['body']) { |
|
| 1049 | - $a['extension'] = $extension; |
|
| 1050 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1051 | - ecrire_fichier($a['fichier'], $a['body']); |
|
| 1052 | - $size_image = @spip_getimagesize($a['fichier']); |
|
| 1053 | - $a['largeur'] = intval($size_image[0]); |
|
| 1054 | - $a['hauteur'] = intval($size_image[1]); |
|
| 1055 | - $a['type_image'] = true; |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1061 | - // ce sera mieux que 0x0 |
|
| 1062 | - // Flash is dead! |
|
| 1063 | - if ( |
|
| 1064 | - $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1065 | - and empty($a['largeur']) |
|
| 1066 | - ) { |
|
| 1067 | - $a['largeur'] = 425; |
|
| 1068 | - $a['hauteur'] = 350; |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - if ($mime_type == 'text/html') { |
|
| 1072 | - include_spip('inc/filtres'); |
|
| 1073 | - $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1074 | - $page = $page['page'] ?? ''; |
|
| 1075 | - if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1076 | - $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1077 | - } |
|
| 1078 | - if (!isset($a['taille']) or !$a['taille']) { |
|
| 1079 | - $a['taille'] = strlen($page); # a peu pres |
|
| 1080 | - } |
|
| 1081 | - } |
|
| 1082 | - $a['mime_type'] = $mime_type; |
|
| 1083 | - |
|
| 1084 | - return $a; |
|
| 981 | + // pas la peine de perdre son temps |
|
| 982 | + if (!tester_url_absolue($source)) { |
|
| 983 | + return false; |
|
| 984 | + } |
|
| 985 | + |
|
| 986 | + $taille_max = $options['taille_max'] ?? 0; |
|
| 987 | + $charger_si_petite_image = !!($options['charger_si_petite_image'] ?? true); |
|
| 988 | + $callback_valider_url = $options['callback_valider_url'] ?? null; |
|
| 989 | + |
|
| 990 | + # charger les alias des types mime |
|
| 991 | + include_spip('base/typedoc'); |
|
| 992 | + |
|
| 993 | + $a = []; |
|
| 994 | + $mime_type = ''; |
|
| 995 | + // On va directement charger le debut des images et des fichiers html, |
|
| 996 | + // de maniere a attrapper le maximum d'infos (titre, taille, etc). Si |
|
| 997 | + // ca echoue l'utilisateur devra les entrer... |
|
| 998 | + $reponse = recuperer_url($source, ['taille_max' => $taille_max, 'refuser_gz' => true]); |
|
| 999 | + if ( |
|
| 1000 | + $callback_valider_url |
|
| 1001 | + and is_callable($callback_valider_url) |
|
| 1002 | + and !$callback_valider_url($reponse['url']) |
|
| 1003 | + ) { |
|
| 1004 | + return false; |
|
| 1005 | + } |
|
| 1006 | + $headers = $reponse['headers'] ?? ''; |
|
| 1007 | + $a['body'] = $reponse['page'] ?? ''; |
|
| 1008 | + if ($headers) { |
|
| 1009 | + if (!$extension = distant_trouver_extension_selon_headers($source, $headers)) { |
|
| 1010 | + return false; |
|
| 1011 | + } |
|
| 1012 | + |
|
| 1013 | + $a['extension'] = $extension; |
|
| 1014 | + |
|
| 1015 | + if (preg_match(",\nContent-Length: *([^[:space:]]*),i", "\n$headers", $regs)) { |
|
| 1016 | + $a['taille'] = intval($regs[1]); |
|
| 1017 | + } |
|
| 1018 | + } |
|
| 1019 | + |
|
| 1020 | + // Echec avec HEAD, on tente avec GET |
|
| 1021 | + if (!$a and !$taille_max) { |
|
| 1022 | + spip_log("tenter GET $source", 'distant'); |
|
| 1023 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1024 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + // si on a rien trouve pas la peine d'insister |
|
| 1028 | + if (!$a) { |
|
| 1029 | + return false; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + // S'il s'agit d'une image pas trop grosse ou d'un fichier html, on va aller |
|
| 1033 | + // recharger le document en GET et recuperer des donnees supplementaires... |
|
| 1034 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 1035 | + if ( |
|
| 1036 | + strpos($mime_type, 'image/') === 0 |
|
| 1037 | + and $extension = _image_trouver_extension_depuis_mime($mime_type) |
|
| 1038 | + ) { |
|
| 1039 | + if ( |
|
| 1040 | + $taille_max == 0 |
|
| 1041 | + and (empty($a['taille']) or $a['taille'] < _INC_DISTANT_MAX_SIZE) |
|
| 1042 | + and in_array($extension, formats_image_acceptables()) |
|
| 1043 | + and $charger_si_petite_image |
|
| 1044 | + ) { |
|
| 1045 | + $options['taille_max'] = _INC_DISTANT_MAX_SIZE; |
|
| 1046 | + $a = recuperer_infos_distantes($source, $options); |
|
| 1047 | + } else { |
|
| 1048 | + if ($a['body']) { |
|
| 1049 | + $a['extension'] = $extension; |
|
| 1050 | + $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1051 | + ecrire_fichier($a['fichier'], $a['body']); |
|
| 1052 | + $size_image = @spip_getimagesize($a['fichier']); |
|
| 1053 | + $a['largeur'] = intval($size_image[0]); |
|
| 1054 | + $a['hauteur'] = intval($size_image[1]); |
|
| 1055 | + $a['type_image'] = true; |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + // Fichier swf, si on n'a pas la taille, on va mettre 425x350 par defaut |
|
| 1061 | + // ce sera mieux que 0x0 |
|
| 1062 | + // Flash is dead! |
|
| 1063 | + if ( |
|
| 1064 | + $a and isset($a['extension']) and $a['extension'] == 'swf' |
|
| 1065 | + and empty($a['largeur']) |
|
| 1066 | + ) { |
|
| 1067 | + $a['largeur'] = 425; |
|
| 1068 | + $a['hauteur'] = 350; |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + if ($mime_type == 'text/html') { |
|
| 1072 | + include_spip('inc/filtres'); |
|
| 1073 | + $page = recuperer_url($source, ['transcoder' => true, 'taille_max' => _INC_DISTANT_MAX_SIZE]); |
|
| 1074 | + $page = $page['page'] ?? ''; |
|
| 1075 | + if (preg_match(',<title>(.*?)</title>,ims', $page, $regs)) { |
|
| 1076 | + $a['titre'] = corriger_caracteres(trim($regs[1])); |
|
| 1077 | + } |
|
| 1078 | + if (!isset($a['taille']) or !$a['taille']) { |
|
| 1079 | + $a['taille'] = strlen($page); # a peu pres |
|
| 1080 | + } |
|
| 1081 | + } |
|
| 1082 | + $a['mime_type'] = $mime_type; |
|
| 1083 | + |
|
| 1084 | + return $a; |
|
| 1085 | 1085 | } |
| 1086 | 1086 | |
| 1087 | 1087 | /** |
@@ -1090,70 +1090,70 @@ discard block |
||
| 1090 | 1090 | * @return false|mixed |
| 1091 | 1091 | */ |
| 1092 | 1092 | function distant_trouver_extension_selon_headers($source, $headers) { |
| 1093 | - if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1094 | - $mime_type = (trim($regs[1])); |
|
| 1095 | - } else { |
|
| 1096 | - $mime_type = ''; |
|
| 1097 | - } // inconnu |
|
| 1098 | - |
|
| 1099 | - // Appliquer les alias |
|
| 1100 | - while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1101 | - $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - // pour corriger_extension() |
|
| 1105 | - include_spip('inc/documents'); |
|
| 1106 | - |
|
| 1107 | - // Si on a un mime-type insignifiant |
|
| 1108 | - // text/plain,application/octet-stream ou vide |
|
| 1109 | - // c'est peut-etre que le serveur ne sait pas |
|
| 1110 | - // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1111 | - // ou le Content-Disposition: attachment; filename=... |
|
| 1112 | - $t = null; |
|
| 1113 | - if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1114 | - if ( |
|
| 1115 | - !$t |
|
| 1116 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1117 | - ) { |
|
| 1118 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1119 | - } |
|
| 1120 | - if ( |
|
| 1121 | - !$t |
|
| 1122 | - and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1123 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1124 | - ) { |
|
| 1125 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1126 | - } |
|
| 1127 | - } |
|
| 1128 | - |
|
| 1129 | - // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1130 | - if (!$t) { |
|
| 1131 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1135 | - // On essaie de nouveau avec l'extension |
|
| 1136 | - if ( |
|
| 1137 | - !$t |
|
| 1138 | - and $mime_type != 'text/plain' |
|
| 1139 | - and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1140 | - ) { |
|
| 1141 | - # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1142 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - if ($t) { |
|
| 1146 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1147 | - return $t['extension']; |
|
| 1148 | - } else { |
|
| 1149 | - # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1150 | - spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1151 | - $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1152 | - if (!$t) { |
|
| 1153 | - return false; |
|
| 1154 | - } |
|
| 1155 | - return $t['extension']; |
|
| 1156 | - } |
|
| 1093 | + if (preg_match(",\nContent-Type: *([^[:space:];]*),i", "\n$headers", $regs)) { |
|
| 1094 | + $mime_type = (trim($regs[1])); |
|
| 1095 | + } else { |
|
| 1096 | + $mime_type = ''; |
|
| 1097 | + } // inconnu |
|
| 1098 | + |
|
| 1099 | + // Appliquer les alias |
|
| 1100 | + while (isset($GLOBALS['mime_alias'][$mime_type])) { |
|
| 1101 | + $mime_type = $GLOBALS['mime_alias'][$mime_type]; |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + // pour corriger_extension() |
|
| 1105 | + include_spip('inc/documents'); |
|
| 1106 | + |
|
| 1107 | + // Si on a un mime-type insignifiant |
|
| 1108 | + // text/plain,application/octet-stream ou vide |
|
| 1109 | + // c'est peut-etre que le serveur ne sait pas |
|
| 1110 | + // ce qu'il sert ; on va tenter de detecter via l'extension de l'url |
|
| 1111 | + // ou le Content-Disposition: attachment; filename=... |
|
| 1112 | + $t = null; |
|
| 1113 | + if (in_array($mime_type, ['text/plain', '', 'application/octet-stream'])) { |
|
| 1114 | + if ( |
|
| 1115 | + !$t |
|
| 1116 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1117 | + ) { |
|
| 1118 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1119 | + } |
|
| 1120 | + if ( |
|
| 1121 | + !$t |
|
| 1122 | + and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
|
| 1123 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
|
| 1124 | + ) { |
|
| 1125 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1126 | + } |
|
| 1127 | + } |
|
| 1128 | + |
|
| 1129 | + // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
|
| 1130 | + if (!$t) { |
|
| 1131 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
|
| 1135 | + // On essaie de nouveau avec l'extension |
|
| 1136 | + if ( |
|
| 1137 | + !$t |
|
| 1138 | + and $mime_type != 'text/plain' |
|
| 1139 | + and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
|
| 1140 | + ) { |
|
| 1141 | + # eviter xxx.3 => 3gp (> SPIP 3) |
|
| 1142 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + if ($t) { |
|
| 1146 | + spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1147 | + return $t['extension']; |
|
| 1148 | + } else { |
|
| 1149 | + # par defaut on retombe sur '.bin' si c'est autorise |
|
| 1150 | + spip_log("mime-type $mime_type inconnu", 'distant'); |
|
| 1151 | + $t = sql_fetsel('extension', 'spip_types_documents', "extension='bin'"); |
|
| 1152 | + if (!$t) { |
|
| 1153 | + return false; |
|
| 1154 | + } |
|
| 1155 | + return $t['extension']; |
|
| 1156 | + } |
|
| 1157 | 1157 | } |
| 1158 | 1158 | |
| 1159 | 1159 | /** |
@@ -1169,45 +1169,45 @@ discard block |
||
| 1169 | 1169 | */ |
| 1170 | 1170 | function need_proxy($host, $http_proxy = null, $http_noproxy = null) { |
| 1171 | 1171 | |
| 1172 | - $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1173 | - |
|
| 1174 | - // rien a faire si pas de proxy :) |
|
| 1175 | - if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1176 | - return ''; |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - if (is_null($http_noproxy)) { |
|
| 1180 | - $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1181 | - } |
|
| 1182 | - // si pas d'exception, on retourne le proxy |
|
| 1183 | - if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1184 | - return $http_proxy; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1188 | - // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1189 | - $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1190 | - $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1191 | - $http_noproxy = " $http_noproxy "; |
|
| 1192 | - $domain = $host; |
|
| 1193 | - // si le domaine exact www.example.org est dans les exceptions |
|
| 1194 | - if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1195 | - return ''; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - while (strpos($domain, '.') !== false) { |
|
| 1199 | - $domain = explode('.', $domain); |
|
| 1200 | - array_shift($domain); |
|
| 1201 | - $domain = implode('.', $domain); |
|
| 1202 | - |
|
| 1203 | - // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1204 | - if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1205 | - return ''; |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - // ok c'est pas une exception |
|
| 1210 | - return $http_proxy; |
|
| 1172 | + $http_proxy ??= $GLOBALS['meta']['http_proxy'] ?? null; |
|
| 1173 | + |
|
| 1174 | + // rien a faire si pas de proxy :) |
|
| 1175 | + if (is_null($http_proxy) or !$http_proxy = trim($http_proxy)) { |
|
| 1176 | + return ''; |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + if (is_null($http_noproxy)) { |
|
| 1180 | + $http_noproxy = $GLOBALS['meta']['http_noproxy'] ?? null; |
|
| 1181 | + } |
|
| 1182 | + // si pas d'exception, on retourne le proxy |
|
| 1183 | + if (is_null($http_noproxy) or !$http_noproxy = trim($http_noproxy)) { |
|
| 1184 | + return $http_proxy; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // si le host ou l'un des domaines parents est dans $http_noproxy on fait exception |
|
| 1188 | + // $http_noproxy peut contenir plusieurs domaines separes par des espaces ou retour ligne |
|
| 1189 | + $http_noproxy = str_replace("\n", ' ', $http_noproxy); |
|
| 1190 | + $http_noproxy = str_replace("\r", ' ', $http_noproxy); |
|
| 1191 | + $http_noproxy = " $http_noproxy "; |
|
| 1192 | + $domain = $host; |
|
| 1193 | + // si le domaine exact www.example.org est dans les exceptions |
|
| 1194 | + if (strpos($http_noproxy, (string) " $domain ") !== false) { |
|
| 1195 | + return ''; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + while (strpos($domain, '.') !== false) { |
|
| 1199 | + $domain = explode('.', $domain); |
|
| 1200 | + array_shift($domain); |
|
| 1201 | + $domain = implode('.', $domain); |
|
| 1202 | + |
|
| 1203 | + // ou si un domaine parent commencant par un . est dans les exceptions (indiquant qu'il couvre tous les sous-domaines) |
|
| 1204 | + if (strpos($http_noproxy, (string) " .$domain ") !== false) { |
|
| 1205 | + return ''; |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + // ok c'est pas une exception |
|
| 1210 | + return $http_proxy; |
|
| 1211 | 1211 | } |
| 1212 | 1212 | |
| 1213 | 1213 | |
@@ -1230,59 +1230,59 @@ discard block |
||
| 1230 | 1230 | * @return array |
| 1231 | 1231 | */ |
| 1232 | 1232 | function init_http($method, $url, $refuse_gz = false, $referer = '', $datas = '', $vers = 'HTTP/1.0', $date = '') { |
| 1233 | - $user = $via_proxy = $proxy_user = ''; |
|
| 1234 | - $fopen = false; |
|
| 1235 | - |
|
| 1236 | - $t = @parse_url($url); |
|
| 1237 | - $host = $t['host']; |
|
| 1238 | - if ($t['scheme'] == 'http') { |
|
| 1239 | - $scheme = 'http'; |
|
| 1240 | - $noproxy = ''; |
|
| 1241 | - } elseif ($t['scheme'] == 'https') { |
|
| 1242 | - $scheme = 'ssl'; |
|
| 1243 | - $noproxy = 'ssl://'; |
|
| 1244 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1245 | - $t['port'] = 443; |
|
| 1246 | - } |
|
| 1247 | - } else { |
|
| 1248 | - $scheme = $t['scheme']; |
|
| 1249 | - $noproxy = $scheme . '://'; |
|
| 1250 | - } |
|
| 1251 | - if (isset($t['user'])) { |
|
| 1252 | - $user = [$t['user'], $t['pass']]; |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1256 | - $port = 80; |
|
| 1257 | - } |
|
| 1258 | - if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1259 | - $path = '/'; |
|
| 1260 | - } |
|
| 1261 | - |
|
| 1262 | - if (!empty($t['query'])) { |
|
| 1263 | - $path .= '?' . $t['query']; |
|
| 1264 | - } |
|
| 1265 | - |
|
| 1266 | - $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1267 | - if (!$f or !is_resource($f)) { |
|
| 1268 | - // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1269 | - // ce qui correspond a $f===110 |
|
| 1270 | - if ( |
|
| 1271 | - $f !== 110 |
|
| 1272 | - and !need_proxy($host) |
|
| 1273 | - and !_request('tester_proxy') |
|
| 1274 | - and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1275 | - ) { |
|
| 1276 | - $f = @fopen($url, 'rb'); |
|
| 1277 | - spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1278 | - $fopen = true; |
|
| 1279 | - } else { |
|
| 1280 | - // echec total |
|
| 1281 | - $f = false; |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - return [$f, $fopen]; |
|
| 1233 | + $user = $via_proxy = $proxy_user = ''; |
|
| 1234 | + $fopen = false; |
|
| 1235 | + |
|
| 1236 | + $t = @parse_url($url); |
|
| 1237 | + $host = $t['host']; |
|
| 1238 | + if ($t['scheme'] == 'http') { |
|
| 1239 | + $scheme = 'http'; |
|
| 1240 | + $noproxy = ''; |
|
| 1241 | + } elseif ($t['scheme'] == 'https') { |
|
| 1242 | + $scheme = 'ssl'; |
|
| 1243 | + $noproxy = 'ssl://'; |
|
| 1244 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1245 | + $t['port'] = 443; |
|
| 1246 | + } |
|
| 1247 | + } else { |
|
| 1248 | + $scheme = $t['scheme']; |
|
| 1249 | + $noproxy = $scheme . '://'; |
|
| 1250 | + } |
|
| 1251 | + if (isset($t['user'])) { |
|
| 1252 | + $user = [$t['user'], $t['pass']]; |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + if (!isset($t['port']) || !($port = $t['port'])) { |
|
| 1256 | + $port = 80; |
|
| 1257 | + } |
|
| 1258 | + if (!isset($t['path']) || !($path = $t['path'])) { |
|
| 1259 | + $path = '/'; |
|
| 1260 | + } |
|
| 1261 | + |
|
| 1262 | + if (!empty($t['query'])) { |
|
| 1263 | + $path .= '?' . $t['query']; |
|
| 1264 | + } |
|
| 1265 | + |
|
| 1266 | + $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
|
| 1267 | + if (!$f or !is_resource($f)) { |
|
| 1268 | + // fallback : fopen si on a pas fait timeout dans lance_requete |
|
| 1269 | + // ce qui correspond a $f===110 |
|
| 1270 | + if ( |
|
| 1271 | + $f !== 110 |
|
| 1272 | + and !need_proxy($host) |
|
| 1273 | + and !_request('tester_proxy') |
|
| 1274 | + and (!isset($GLOBALS['inc_distant_allow_fopen']) or $GLOBALS['inc_distant_allow_fopen']) |
|
| 1275 | + ) { |
|
| 1276 | + $f = @fopen($url, 'rb'); |
|
| 1277 | + spip_log("connexion vers $url par simple fopen", 'distant'); |
|
| 1278 | + $fopen = true; |
|
| 1279 | + } else { |
|
| 1280 | + // echec total |
|
| 1281 | + $f = false; |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + return [$f, $fopen]; |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1317,124 +1317,124 @@ discard block |
||
| 1317 | 1317 | * resource socket vers l'url demandee |
| 1318 | 1318 | */ |
| 1319 | 1319 | function lance_requete( |
| 1320 | - $method, |
|
| 1321 | - $scheme, |
|
| 1322 | - $user, |
|
| 1323 | - $host, |
|
| 1324 | - $path, |
|
| 1325 | - $port, |
|
| 1326 | - $noproxy, |
|
| 1327 | - $refuse_gz = false, |
|
| 1328 | - $referer = '', |
|
| 1329 | - $datas = '', |
|
| 1330 | - $vers = 'HTTP/1.0', |
|
| 1331 | - $date = '' |
|
| 1320 | + $method, |
|
| 1321 | + $scheme, |
|
| 1322 | + $user, |
|
| 1323 | + $host, |
|
| 1324 | + $path, |
|
| 1325 | + $port, |
|
| 1326 | + $noproxy, |
|
| 1327 | + $refuse_gz = false, |
|
| 1328 | + $referer = '', |
|
| 1329 | + $datas = '', |
|
| 1330 | + $vers = 'HTTP/1.0', |
|
| 1331 | + $date = '' |
|
| 1332 | 1332 | ) { |
| 1333 | 1333 | |
| 1334 | - $proxy_user = ''; |
|
| 1335 | - $http_proxy = need_proxy($host); |
|
| 1336 | - if ($user) { |
|
| 1337 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1338 | - } |
|
| 1339 | - |
|
| 1340 | - $connect = ''; |
|
| 1341 | - if ($http_proxy) { |
|
| 1342 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1343 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1344 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1345 | - . "Host: $path_host\r\n" |
|
| 1346 | - . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1347 | - } else { |
|
| 1348 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1349 | - . (!$user ? '' : "$user@") |
|
| 1350 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1351 | - } |
|
| 1352 | - $t2 = @parse_url($http_proxy); |
|
| 1353 | - $first_host = $t2['host']; |
|
| 1354 | - $first_port = ($t2['port'] ?? null) ?: 80; |
|
| 1355 | - if ($t2['user'] ?? null) { |
|
| 1356 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1357 | - } |
|
| 1358 | - } else { |
|
| 1359 | - $first_host = $noproxy . $host; |
|
| 1360 | - $first_port = $port; |
|
| 1361 | - } |
|
| 1362 | - |
|
| 1363 | - if ($connect) { |
|
| 1364 | - $streamContext = stream_context_create([ |
|
| 1365 | - 'ssl' => [ |
|
| 1366 | - 'verify_peer' => false, |
|
| 1367 | - 'allow_self_signed' => true, |
|
| 1368 | - 'SNI_enabled' => true, |
|
| 1369 | - 'peer_name' => $host, |
|
| 1370 | - ] |
|
| 1371 | - ]); |
|
| 1372 | - $f = @stream_socket_client( |
|
| 1373 | - "tcp://$first_host:$first_port", |
|
| 1374 | - $errno, |
|
| 1375 | - $errstr, |
|
| 1376 | - _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1377 | - STREAM_CLIENT_CONNECT, |
|
| 1378 | - $streamContext |
|
| 1379 | - ); |
|
| 1380 | - spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect'); |
|
| 1381 | - if (!$f) { |
|
| 1382 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1383 | - return $errno; |
|
| 1384 | - } |
|
| 1385 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1386 | - |
|
| 1387 | - fputs($f, $connect); |
|
| 1388 | - fputs($f, "\r\n"); |
|
| 1389 | - $res = fread($f, 1024); |
|
| 1390 | - if ( |
|
| 1391 | - !$res |
|
| 1392 | - or !count($res = explode(' ', $res)) |
|
| 1393 | - or $res[1] !== '200' |
|
| 1394 | - ) { |
|
| 1395 | - spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1396 | - fclose($f); |
|
| 1397 | - |
|
| 1398 | - return false; |
|
| 1399 | - } |
|
| 1400 | - // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1401 | - stream_set_blocking($f, true); |
|
| 1402 | - // envoyer le handshake |
|
| 1403 | - stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1404 | - spip_log("OK CONNECT sur $first_host:$first_port", 'connect'); |
|
| 1405 | - } else { |
|
| 1406 | - $ntry = 3; |
|
| 1407 | - do { |
|
| 1408 | - $f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | - } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1410 | - spip_log("Recuperer $path sur $first_host:$first_port par $f"); |
|
| 1411 | - if (!$f) { |
|
| 1412 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1413 | - |
|
| 1414 | - return $errno; |
|
| 1415 | - } |
|
| 1416 | - stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1417 | - } |
|
| 1418 | - |
|
| 1419 | - $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1420 | - |
|
| 1421 | - $host_port = $host; |
|
| 1422 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1423 | - $host_port .= ":$port"; |
|
| 1424 | - } |
|
| 1425 | - $req = "$method $path $vers\r\n" |
|
| 1426 | - . "Host: $host_port\r\n" |
|
| 1427 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1429 | - . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1430 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1432 | - . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1433 | - . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1334 | + $proxy_user = ''; |
|
| 1335 | + $http_proxy = need_proxy($host); |
|
| 1336 | + if ($user) { |
|
| 1337 | + $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1338 | + } |
|
| 1339 | + |
|
| 1340 | + $connect = ''; |
|
| 1341 | + if ($http_proxy) { |
|
| 1342 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1343 | + $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1344 | + $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1345 | + . "Host: $path_host\r\n" |
|
| 1346 | + . "Proxy-Connection: Keep-Alive\r\n"; |
|
| 1347 | + } else { |
|
| 1348 | + $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1349 | + . (!$user ? '' : "$user@") |
|
| 1350 | + . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1351 | + } |
|
| 1352 | + $t2 = @parse_url($http_proxy); |
|
| 1353 | + $first_host = $t2['host']; |
|
| 1354 | + $first_port = ($t2['port'] ?? null) ?: 80; |
|
| 1355 | + if ($t2['user'] ?? null) { |
|
| 1356 | + $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1357 | + } |
|
| 1358 | + } else { |
|
| 1359 | + $first_host = $noproxy . $host; |
|
| 1360 | + $first_port = $port; |
|
| 1361 | + } |
|
| 1362 | + |
|
| 1363 | + if ($connect) { |
|
| 1364 | + $streamContext = stream_context_create([ |
|
| 1365 | + 'ssl' => [ |
|
| 1366 | + 'verify_peer' => false, |
|
| 1367 | + 'allow_self_signed' => true, |
|
| 1368 | + 'SNI_enabled' => true, |
|
| 1369 | + 'peer_name' => $host, |
|
| 1370 | + ] |
|
| 1371 | + ]); |
|
| 1372 | + $f = @stream_socket_client( |
|
| 1373 | + "tcp://$first_host:$first_port", |
|
| 1374 | + $errno, |
|
| 1375 | + $errstr, |
|
| 1376 | + _INC_DISTANT_CONNECT_TIMEOUT, |
|
| 1377 | + STREAM_CLIENT_CONNECT, |
|
| 1378 | + $streamContext |
|
| 1379 | + ); |
|
| 1380 | + spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect'); |
|
| 1381 | + if (!$f) { |
|
| 1382 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1383 | + return $errno; |
|
| 1384 | + } |
|
| 1385 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1386 | + |
|
| 1387 | + fputs($f, $connect); |
|
| 1388 | + fputs($f, "\r\n"); |
|
| 1389 | + $res = fread($f, 1024); |
|
| 1390 | + if ( |
|
| 1391 | + !$res |
|
| 1392 | + or !count($res = explode(' ', $res)) |
|
| 1393 | + or $res[1] !== '200' |
|
| 1394 | + ) { |
|
| 1395 | + spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1396 | + fclose($f); |
|
| 1397 | + |
|
| 1398 | + return false; |
|
| 1399 | + } |
|
| 1400 | + // important, car sinon on lit trop vite et les donnees ne sont pas encore dispo |
|
| 1401 | + stream_set_blocking($f, true); |
|
| 1402 | + // envoyer le handshake |
|
| 1403 | + stream_socket_enable_crypto($f, true, STREAM_CRYPTO_METHOD_SSLv23_CLIENT); |
|
| 1404 | + spip_log("OK CONNECT sur $first_host:$first_port", 'connect'); |
|
| 1405 | + } else { |
|
| 1406 | + $ntry = 3; |
|
| 1407 | + do { |
|
| 1408 | + $f = @fsockopen($first_host, $first_port, $errno, $errstr, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1409 | + } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
|
| 1410 | + spip_log("Recuperer $path sur $first_host:$first_port par $f"); |
|
| 1411 | + if (!$f) { |
|
| 1412 | + spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1413 | + |
|
| 1414 | + return $errno; |
|
| 1415 | + } |
|
| 1416 | + stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
|
| 1417 | + } |
|
| 1418 | + |
|
| 1419 | + $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
|
| 1420 | + |
|
| 1421 | + $host_port = $host; |
|
| 1422 | + if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1423 | + $host_port .= ":$port"; |
|
| 1424 | + } |
|
| 1425 | + $req = "$method $path $vers\r\n" |
|
| 1426 | + . "Host: $host_port\r\n" |
|
| 1427 | + . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | + . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1429 | + . (!$site ? '' : "Referer: $site/$referer\r\n") |
|
| 1430 | + . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | + . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1432 | + . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
|
| 1433 | + . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
|
| 1434 | 1434 | |
| 1435 | 1435 | # spip_log("Requete\n$req", 'distant'); |
| 1436 | - fputs($f, $req); |
|
| 1437 | - fputs($f, $datas ?: "\r\n"); |
|
| 1436 | + fputs($f, $req); |
|
| 1437 | + fputs($f, $datas ?: "\r\n"); |
|
| 1438 | 1438 | |
| 1439 | - return $f; |
|
| 1439 | + return $f; |
|
| 1440 | 1440 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | define('_INC_DISTANT_CONTENT_ENCODING', 'gzip'); |
| 28 | 28 | } |
| 29 | 29 | if (!defined('_INC_DISTANT_USER_AGENT')) { |
| 30 | - define('_INC_DISTANT_USER_AGENT', 'SPIP-' . $GLOBALS['spip_version_affichee'] . ' (' . $GLOBALS['home_server'] . ')'); |
|
| 30 | + define('_INC_DISTANT_USER_AGENT', 'SPIP-'.$GLOBALS['spip_version_affichee'].' ('.$GLOBALS['home_server'].')'); |
|
| 31 | 31 | } |
| 32 | 32 | if (!defined('_INC_DISTANT_MAX_SIZE')) { |
| 33 | 33 | define('_INC_DISTANT_MAX_SIZE', 2_097_152); |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | define('_INC_DISTANT_CONNECT_TIMEOUT', 10); |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | -define('_REGEXP_COPIE_LOCALE', ',' . |
|
| 39 | +define('_REGEXP_COPIE_LOCALE', ','. |
|
| 40 | 40 | preg_replace( |
| 41 | 41 | '@^https?:@', |
| 42 | 42 | 'https?:', |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | |
| 74 | 74 | // si c'est la protection de soi-meme, retourner le path |
| 75 | 75 | if ($mode !== 'force' and preg_match(_REGEXP_COPIE_LOCALE, $source, $match)) { |
| 76 | - $source = substr(_DIR_IMG, strlen(_DIR_RACINE)) . urldecode($match[1]); |
|
| 76 | + $source = substr(_DIR_IMG, strlen(_DIR_RACINE)).urldecode($match[1]); |
|
| 77 | 77 | |
| 78 | 78 | return @file_exists($source) ? $source : false; |
| 79 | 79 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | return false; |
| 94 | 94 | } |
| 95 | 95 | |
| 96 | - $localrac = _DIR_RACINE . $local; |
|
| 96 | + $localrac = _DIR_RACINE.$local; |
|
| 97 | 97 | $t = ($mode === 'force') ? false : @file_exists($localrac); |
| 98 | 98 | |
| 99 | 99 | // test d'existence du fichier |
@@ -113,18 +113,18 @@ discard block |
||
| 113 | 113 | if (!$taille_max) { |
| 114 | 114 | $taille_max = _COPIE_LOCALE_MAX_SIZE; |
| 115 | 115 | } |
| 116 | - $localrac_tmp = $localrac . '.tmp'; |
|
| 116 | + $localrac_tmp = $localrac.'.tmp'; |
|
| 117 | 117 | $res = recuperer_url( |
| 118 | 118 | $source, |
| 119 | 119 | ['file' => $localrac_tmp, 'taille_max' => $taille_max, 'if_modified_since' => $t ? filemtime($localrac) : ''] |
| 120 | 120 | ); |
| 121 | 121 | |
| 122 | 122 | if (!$res or (!$res['length'] and $res['status'] != 304)) { |
| 123 | - spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : " . ($res ? $res['status'] : '-'), 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 123 | + spip_log("copie_locale : Echec recuperation $source sur $localrac_tmp status : ".($res ? $res['status'] : '-'), 'distant'._LOG_INFO_IMPORTANTE); |
|
| 124 | 124 | @unlink($localrac_tmp); |
| 125 | 125 | } |
| 126 | 126 | else { |
| 127 | - spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille " . $res['length'] . ' status ' . $res['status'], 'distant'); |
|
| 127 | + spip_log("copie_locale : recuperation $source sur $localrac_tmp OK | taille ".$res['length'].' status '.$res['status'], 'distant'); |
|
| 128 | 128 | } |
| 129 | 129 | if (!$res or !$res['length']) { |
| 130 | 130 | // si $t c'est sans doute juste un not-modified-since |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | and is_callable($callback_valider_url) |
| 138 | 138 | and !$callback_valider_url($res['url']) |
| 139 | 139 | ) { |
| 140 | - spip_log('copie_locale : url finale ' . $res['url'] . " non valide, on refuse le fichier $localrac_tmp", 'distant' . _LOG_INFO_IMPORTANTE); |
|
| 140 | + spip_log('copie_locale : url finale '.$res['url']." non valide, on refuse le fichier $localrac_tmp", 'distant'._LOG_INFO_IMPORTANTE); |
|
| 141 | 141 | @unlink($localrac_tmp); |
| 142 | 142 | return $t ? $local : false; |
| 143 | 143 | } |
@@ -228,7 +228,7 @@ discard block |
||
| 228 | 228 | |
| 229 | 229 | if (!$is_known_host) { |
| 230 | 230 | $host = trim($parsed_url['host'], '.'); |
| 231 | - if (! $ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 231 | + if (!$ip = filter_var($host, FILTER_VALIDATE_IP)) { |
|
| 232 | 232 | $ip = gethostbyname($host); |
| 233 | 233 | if ($ip === $host) { |
| 234 | 234 | // Error condition for gethostbyname() |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | if ($ip) { |
| 252 | - if (! filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 252 | + if (!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) { |
|
| 253 | 253 | return false; |
| 254 | 254 | } |
| 255 | 255 | } |
@@ -260,7 +260,7 @@ discard block |
||
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | $port = $parsed_url['port']; |
| 263 | - if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 263 | + if ($port === 80 or $port === 443 or $port === 8080) { |
|
| 264 | 264 | return $url; |
| 265 | 265 | } |
| 266 | 266 | |
@@ -330,7 +330,7 @@ discard block |
||
| 330 | 330 | } |
| 331 | 331 | } |
| 332 | 332 | if ($taille > 500) { |
| 333 | - $boundary = substr(md5(random_int(0, mt_getrandmax()) . 'spip'), 0, 8); |
|
| 333 | + $boundary = substr(md5(random_int(0, mt_getrandmax()).'spip'), 0, 8); |
|
| 334 | 334 | } |
| 335 | 335 | } |
| 336 | 336 | |
@@ -358,16 +358,16 @@ discard block |
||
| 358 | 358 | } |
| 359 | 359 | } else { |
| 360 | 360 | // fabrique une chaine HTTP simple pour un POST |
| 361 | - $entete = 'Content-Type: application/x-www-form-urlencoded' . "\r\n"; |
|
| 361 | + $entete = 'Content-Type: application/x-www-form-urlencoded'."\r\n"; |
|
| 362 | 362 | $chaine = []; |
| 363 | 363 | if (is_array($donnees)) { |
| 364 | 364 | foreach ($donnees as $cle => $valeur) { |
| 365 | 365 | if (is_array($valeur)) { |
| 366 | 366 | foreach ($valeur as $val2) { |
| 367 | - $chaine[] = rawurlencode($cle) . '[]=' . rawurlencode($val2); |
|
| 367 | + $chaine[] = rawurlencode($cle).'[]='.rawurlencode($val2); |
|
| 368 | 368 | } |
| 369 | 369 | } else { |
| 370 | - $chaine[] = rawurlencode($cle) . '=' . rawurlencode($valeur); |
|
| 370 | + $chaine[] = rawurlencode($cle).'='.rawurlencode($valeur); |
|
| 371 | 371 | } |
| 372 | 372 | } |
| 373 | 373 | $chaine = implode('&', $chaine); |
@@ -468,13 +468,13 @@ discard block |
||
| 468 | 468 | $options['taille_max'] = $copy ? _COPIE_LOCALE_MAX_SIZE : _INC_DISTANT_MAX_SIZE; |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - spip_log('recuperer_url ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 471 | + spip_log('recuperer_url '.$options['methode']." sur $url", 'distant'._LOG_DEBUG); |
|
| 472 | 472 | |
| 473 | 473 | // Ajout des en-têtes spécifiques si besoin |
| 474 | 474 | $formatted_data = ''; |
| 475 | 475 | if (!empty($options['headers'])) { |
| 476 | 476 | foreach ($options['headers'] as $champ => $valeur) { |
| 477 | - $formatted_data .= $champ . ': ' . $valeur . "\r\n"; |
|
| 477 | + $formatted_data .= $champ.': '.$valeur."\r\n"; |
|
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
@@ -482,9 +482,9 @@ discard block |
||
| 482 | 482 | [$head, $postdata] = prepare_donnees_post($options['datas'], $options['boundary']); |
| 483 | 483 | $head .= $formatted_data; |
| 484 | 484 | if (stripos($head, 'Content-Length:') === false) { |
| 485 | - $head .= 'Content-Length: ' . strlen($postdata) . "\r\n"; |
|
| 485 | + $head .= 'Content-Length: '.strlen($postdata)."\r\n"; |
|
| 486 | 486 | } |
| 487 | - $formatted_data = $head . "\r\n" . $postdata; |
|
| 487 | + $formatted_data = $head."\r\n".$postdata; |
|
| 488 | 488 | if ( |
| 489 | 489 | strlen($postdata) |
| 490 | 490 | and !$methode_demandee |
@@ -498,9 +498,9 @@ discard block |
||
| 498 | 498 | // Accepter les URLs au format feed:// ou qui ont oublie le http:// ou les urls relatives au protocole |
| 499 | 499 | $url = preg_replace(',^feed://,i', 'http://', $url); |
| 500 | 500 | if (!tester_url_absolue($url)) { |
| 501 | - $url = 'http://' . $url; |
|
| 501 | + $url = 'http://'.$url; |
|
| 502 | 502 | } elseif (strncmp($url, '//', 2) == 0) { |
| 503 | - $url = 'http:' . $url; |
|
| 503 | + $url = 'http:'.$url; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | $url = url_to_ascii($url); |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | $options['if_modified_since'] |
| 530 | 530 | ); |
| 531 | 531 | if (!$handle) { |
| 532 | - spip_log("ECHEC init_http $url", 'distant' . _LOG_ERREUR); |
|
| 532 | + spip_log("ECHEC init_http $url", 'distant'._LOG_ERREUR); |
|
| 533 | 533 | |
| 534 | 534 | return false; |
| 535 | 535 | } |
@@ -559,7 +559,7 @@ discard block |
||
| 559 | 559 | 'status' => 200, |
| 560 | 560 | ]; |
| 561 | 561 | } else { |
| 562 | - spip_log("ECHEC chinoiserie $url", 'distant' . _LOG_ERREUR); |
|
| 562 | + spip_log("ECHEC chinoiserie $url", 'distant'._LOG_ERREUR); |
|
| 563 | 563 | return false; |
| 564 | 564 | } |
| 565 | 565 | } elseif ($res['location'] and $options['follow_location']) { |
@@ -575,11 +575,11 @@ discard block |
||
| 575 | 575 | $options['datas'] = ''; |
| 576 | 576 | } |
| 577 | 577 | } |
| 578 | - spip_log('recuperer_url recommence ' . $options['methode'] . " sur $url", 'distant' . _LOG_DEBUG); |
|
| 578 | + spip_log('recuperer_url recommence '.$options['methode']." sur $url", 'distant'._LOG_DEBUG); |
|
| 579 | 579 | |
| 580 | 580 | return recuperer_url($url, $options); |
| 581 | 581 | } elseif ($res['status'] !== 200) { |
| 582 | - spip_log('HTTP status ' . $res['status'] . " pour $url", 'distant'); |
|
| 582 | + spip_log('HTTP status '.$res['status']." pour $url", 'distant'); |
|
| 583 | 583 | } |
| 584 | 584 | $result['status'] = $res['status']; |
| 585 | 585 | if (isset($res['headers'])) { |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | |
| 596 | 596 | // on ne veut que les entetes |
| 597 | 597 | if (!$options['taille_max'] or $options['methode'] == 'HEAD' or $result['status'] == '304') { |
| 598 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($result), 'distant' . _LOG_DEBUG); |
|
| 598 | + spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($result), 'distant'._LOG_DEBUG); |
|
| 599 | 599 | return $result; |
| 600 | 600 | } |
| 601 | 601 | |
@@ -605,7 +605,7 @@ discard block |
||
| 605 | 605 | |
| 606 | 606 | $gz = false; |
| 607 | 607 | if (preg_match(",\bContent-Encoding: .*gzip,is", $result['headers'])) { |
| 608 | - $gz = (_DIR_TMP . md5(uniqid(random_int(0, mt_getrandmax()))) . '.tmp.gz'); |
|
| 608 | + $gz = (_DIR_TMP.md5(uniqid(random_int(0, mt_getrandmax()))).'.tmp.gz'); |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | // si on a pas deja recuperer le contenu par une methode detournee |
@@ -641,7 +641,7 @@ discard block |
||
| 641 | 641 | |
| 642 | 642 | $trace = json_decode(json_encode($result), true); |
| 643 | 643 | $trace['page'] = '...'; |
| 644 | - spip_log('RESULTAT recuperer_url ' . $options['methode'] . " sur $url : " . json_encode($trace), 'distant' . _LOG_DEBUG); |
|
| 644 | + spip_log('RESULTAT recuperer_url '.$options['methode']." sur $url : ".json_encode($trace), 'distant'._LOG_DEBUG); |
|
| 645 | 645 | |
| 646 | 646 | return $result; |
| 647 | 647 | } |
@@ -695,7 +695,7 @@ discard block |
||
| 695 | 695 | $sig['url'] = $url; |
| 696 | 696 | |
| 697 | 697 | $dir = sous_repertoire(_DIR_CACHE, 'curl'); |
| 698 | - $cache = md5(serialize($sig)) . '-' . substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 698 | + $cache = md5(serialize($sig)).'-'.substr(preg_replace(',\W+,', '_', $url), 0, 80); |
|
| 699 | 699 | $sub = sous_repertoire($dir, substr($cache, 0, 2)); |
| 700 | 700 | $cache = "$sub$cache"; |
| 701 | 701 | |
@@ -749,7 +749,7 @@ discard block |
||
| 749 | 749 | $fp = false; |
| 750 | 750 | if ($fichier) { |
| 751 | 751 | include_spip('inc/acces'); |
| 752 | - $tmpfile = "$fichier." . creer_uniqid() . '.tmp'; |
|
| 752 | + $tmpfile = "$fichier.".creer_uniqid().'.tmp'; |
|
| 753 | 753 | $fp = spip_fopen_lock($tmpfile, 'w', LOCK_EX); |
| 754 | 754 | if (!$fp and file_exists($fichier)) { |
| 755 | 755 | return filesize($fichier); |
@@ -808,7 +808,7 @@ discard block |
||
| 808 | 808 | } |
| 809 | 809 | $result['status'] = intval($r[1]); |
| 810 | 810 | while ($s = trim(fgets($handle, 16384))) { |
| 811 | - $result['headers'][] = $s . "\n"; |
|
| 811 | + $result['headers'][] = $s."\n"; |
|
| 812 | 812 | preg_match(',^([^:]*): *(.*)$,i', $s, $r); |
| 813 | 813 | [, $d, $v] = $r; |
| 814 | 814 | if (strtolower(trim($d)) == 'location' and $result['status'] >= 300 and $result['status'] < 400) { |
@@ -857,13 +857,13 @@ discard block |
||
| 857 | 857 | |
| 858 | 858 | // on se place tout le temps comme si on etait a la racine |
| 859 | 859 | if (_DIR_RACINE) { |
| 860 | - $d = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $d); |
|
| 860 | + $d = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $d); |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | $m = md5($source); |
| 864 | 864 | |
| 865 | 865 | return $d |
| 866 | - . substr(preg_replace(',[^\w-],', '', basename($source)) . '-' . $m, 0, 12) |
|
| 866 | + . substr(preg_replace(',[^\w-],', '', basename($source)).'-'.$m, 0, 12) |
|
| 867 | 867 | . substr($m, 0, 4) |
| 868 | 868 | . ".$extension"; |
| 869 | 869 | } |
@@ -887,7 +887,7 @@ discard block |
||
| 887 | 887 | // Si c'est deja local pas de souci |
| 888 | 888 | if (!tester_url_absolue($source)) { |
| 889 | 889 | if (_DIR_RACINE) { |
| 890 | - $source = preg_replace(',^' . preg_quote(_DIR_RACINE) . ',', '', $source); |
|
| 890 | + $source = preg_replace(',^'.preg_quote(_DIR_RACINE).',', '', $source); |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | return $source; |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | $ext |
| 906 | 906 | and preg_match(',^\w+$,', $ext) // pas de php?truc=1&... |
| 907 | 907 | and $f = nom_fichier_copie_locale($source, $ext) |
| 908 | - and file_exists(_DIR_RACINE . $f) |
|
| 908 | + and file_exists(_DIR_RACINE.$f) |
|
| 909 | 909 | ) { |
| 910 | 910 | return $f; |
| 911 | 911 | } |
@@ -913,7 +913,7 @@ discard block |
||
| 913 | 913 | |
| 914 | 914 | // Si c'est deja dans la table des documents, |
| 915 | 915 | // ramener le nom de sa copie potentielle |
| 916 | - $ext = sql_getfetsel('extension', 'spip_documents', 'fichier=' . sql_quote($source) . " AND distant='oui' AND extension <> ''"); |
|
| 916 | + $ext = sql_getfetsel('extension', 'spip_documents', 'fichier='.sql_quote($source)." AND distant='oui' AND extension <> ''"); |
|
| 917 | 917 | |
| 918 | 918 | if ($ext) { |
| 919 | 919 | return nom_fichier_copie_locale($source, $ext); |
@@ -924,9 +924,9 @@ discard block |
||
| 924 | 924 | |
| 925 | 925 | $ext = $path_parts ? $path_parts['extension'] : ''; |
| 926 | 926 | |
| 927 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 927 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 928 | 928 | $f = nom_fichier_copie_locale($source, $ext); |
| 929 | - if (file_exists(_DIR_RACINE . $f)) { |
|
| 929 | + if (file_exists(_DIR_RACINE.$f)) { |
|
| 930 | 930 | return $f; |
| 931 | 931 | } |
| 932 | 932 | } |
@@ -934,7 +934,7 @@ discard block |
||
| 934 | 934 | // Ping pour voir si son extension est connue et autorisee |
| 935 | 935 | // avec mise en cache du resultat du ping |
| 936 | 936 | |
| 937 | - $cache = sous_repertoire(_DIR_CACHE, 'rid') . md5($source); |
|
| 937 | + $cache = sous_repertoire(_DIR_CACHE, 'rid').md5($source); |
|
| 938 | 938 | if ( |
| 939 | 939 | !@file_exists($cache) |
| 940 | 940 | or !$path_parts = @unserialize(spip_file_get_contents($cache)) |
@@ -944,11 +944,11 @@ discard block |
||
| 944 | 944 | ecrire_fichier($cache, serialize($path_parts)); |
| 945 | 945 | } |
| 946 | 946 | $ext = !empty($path_parts['extension']) ? $path_parts['extension'] : ''; |
| 947 | - if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension=' . sql_quote($ext))) { |
|
| 947 | + if ($ext and sql_getfetsel('extension', 'spip_types_documents', 'extension='.sql_quote($ext))) { |
|
| 948 | 948 | return nom_fichier_copie_locale($source, $ext); |
| 949 | 949 | } |
| 950 | 950 | |
| 951 | - spip_log("pas de copie locale pour $source", 'distant' . _LOG_ERREUR); |
|
| 951 | + spip_log("pas de copie locale pour $source", 'distant'._LOG_ERREUR); |
|
| 952 | 952 | return null; |
| 953 | 953 | } |
| 954 | 954 | |
@@ -1047,7 +1047,7 @@ discard block |
||
| 1047 | 1047 | } else { |
| 1048 | 1048 | if ($a['body']) { |
| 1049 | 1049 | $a['extension'] = $extension; |
| 1050 | - $a['fichier'] = _DIR_RACINE . nom_fichier_copie_locale($source, $extension); |
|
| 1050 | + $a['fichier'] = _DIR_RACINE.nom_fichier_copie_locale($source, $extension); |
|
| 1051 | 1051 | ecrire_fichier($a['fichier'], $a['body']); |
| 1052 | 1052 | $size_image = @spip_getimagesize($a['fichier']); |
| 1053 | 1053 | $a['largeur'] = intval($size_image[0]); |
@@ -1115,20 +1115,20 @@ discard block |
||
| 1115 | 1115 | !$t |
| 1116 | 1116 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1117 | 1117 | ) { |
| 1118 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1118 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1119 | 1119 | } |
| 1120 | 1120 | if ( |
| 1121 | 1121 | !$t |
| 1122 | 1122 | and preg_match(',^Content-Disposition:\s*attachment;\s*filename=(.*)$,Uims', $headers, $m) |
| 1123 | 1123 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $m[1], $rext) |
| 1124 | 1124 | ) { |
| 1125 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1125 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1126 | 1126 | } |
| 1127 | 1127 | } |
| 1128 | 1128 | |
| 1129 | 1129 | // Autre mime/type (ou text/plain avec fichier d'extension inconnue) |
| 1130 | 1130 | if (!$t) { |
| 1131 | - $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type=' . sql_quote($mime_type)); |
|
| 1131 | + $t = sql_fetsel('extension', 'spip_types_documents', 'mime_type='.sql_quote($mime_type)); |
|
| 1132 | 1132 | } |
| 1133 | 1133 | |
| 1134 | 1134 | // Toujours rien ? (ex: audio/x-ogg au lieu de application/ogg) |
@@ -1139,11 +1139,11 @@ discard block |
||
| 1139 | 1139 | and preg_match(',\.([a-z0-9]+)(\?.*)?$,i', $source, $rext) |
| 1140 | 1140 | ) { |
| 1141 | 1141 | # eviter xxx.3 => 3gp (> SPIP 3) |
| 1142 | - $t = sql_fetsel('extension', 'spip_types_documents', 'extension=' . sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1142 | + $t = sql_fetsel('extension', 'spip_types_documents', 'extension='.sql_quote(corriger_extension($rext[1]), '', 'text')); |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | if ($t) { |
| 1146 | - spip_log("mime-type $mime_type ok, extension " . $t['extension'], 'distant'); |
|
| 1146 | + spip_log("mime-type $mime_type ok, extension ".$t['extension'], 'distant'); |
|
| 1147 | 1147 | return $t['extension']; |
| 1148 | 1148 | } else { |
| 1149 | 1149 | # par defaut on retombe sur '.bin' si c'est autorise |
@@ -1246,7 +1246,7 @@ discard block |
||
| 1246 | 1246 | } |
| 1247 | 1247 | } else { |
| 1248 | 1248 | $scheme = $t['scheme']; |
| 1249 | - $noproxy = $scheme . '://'; |
|
| 1249 | + $noproxy = $scheme.'://'; |
|
| 1250 | 1250 | } |
| 1251 | 1251 | if (isset($t['user'])) { |
| 1252 | 1252 | $user = [$t['user'], $t['pass']]; |
@@ -1260,7 +1260,7 @@ discard block |
||
| 1260 | 1260 | } |
| 1261 | 1261 | |
| 1262 | 1262 | if (!empty($t['query'])) { |
| 1263 | - $path .= '?' . $t['query']; |
|
| 1263 | + $path .= '?'.$t['query']; |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | $f = lance_requete($method, $scheme, $user, $host, $path, $port, $noproxy, $refuse_gz, $referer, $datas, $vers, $date); |
@@ -1334,29 +1334,29 @@ discard block |
||
| 1334 | 1334 | $proxy_user = ''; |
| 1335 | 1335 | $http_proxy = need_proxy($host); |
| 1336 | 1336 | if ($user) { |
| 1337 | - $user = urlencode($user[0]) . ':' . urlencode($user[1]); |
|
| 1337 | + $user = urlencode($user[0]).':'.urlencode($user[1]); |
|
| 1338 | 1338 | } |
| 1339 | 1339 | |
| 1340 | 1340 | $connect = ''; |
| 1341 | 1341 | if ($http_proxy) { |
| 1342 | - if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls','ssl'])) { |
|
| 1343 | - $path_host = (!$user ? '' : "$user@") . $host . (($port != 80) ? ":$port" : ''); |
|
| 1344 | - $connect = 'CONNECT ' . $path_host . " $vers\r\n" |
|
| 1342 | + if (!defined('_PROXY_HTTPS_NOT_VIA_CONNECT') and in_array($scheme, ['tls', 'ssl'])) { |
|
| 1343 | + $path_host = (!$user ? '' : "$user@").$host.(($port != 80) ? ":$port" : ''); |
|
| 1344 | + $connect = 'CONNECT '.$path_host." $vers\r\n" |
|
| 1345 | 1345 | . "Host: $path_host\r\n" |
| 1346 | 1346 | . "Proxy-Connection: Keep-Alive\r\n"; |
| 1347 | 1347 | } else { |
| 1348 | - $path = (in_array($scheme, ['tls','ssl']) ? 'https://' : "$scheme://") |
|
| 1348 | + $path = (in_array($scheme, ['tls', 'ssl']) ? 'https://' : "$scheme://") |
|
| 1349 | 1349 | . (!$user ? '' : "$user@") |
| 1350 | - . "$host" . (($port != 80) ? ":$port" : '') . $path; |
|
| 1350 | + . "$host".(($port != 80) ? ":$port" : '').$path; |
|
| 1351 | 1351 | } |
| 1352 | 1352 | $t2 = @parse_url($http_proxy); |
| 1353 | 1353 | $first_host = $t2['host']; |
| 1354 | 1354 | $first_port = ($t2['port'] ?? null) ?: 80; |
| 1355 | 1355 | if ($t2['user'] ?? null) { |
| 1356 | - $proxy_user = base64_encode($t2['user'] . ':' . $t2['pass']); |
|
| 1356 | + $proxy_user = base64_encode($t2['user'].':'.$t2['pass']); |
|
| 1357 | 1357 | } |
| 1358 | 1358 | } else { |
| 1359 | - $first_host = $noproxy . $host; |
|
| 1359 | + $first_host = $noproxy.$host; |
|
| 1360 | 1360 | $first_port = $port; |
| 1361 | 1361 | } |
| 1362 | 1362 | |
@@ -1379,7 +1379,7 @@ discard block |
||
| 1379 | 1379 | ); |
| 1380 | 1380 | spip_log("Recuperer $path sur $first_host:$first_port par $f (via CONNECT)", 'connect'); |
| 1381 | 1381 | if (!$f) { |
| 1382 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1382 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1383 | 1383 | return $errno; |
| 1384 | 1384 | } |
| 1385 | 1385 | stream_set_timeout($f, _INC_DISTANT_CONNECT_TIMEOUT); |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | or !count($res = explode(' ', $res)) |
| 1393 | 1393 | or $res[1] !== '200' |
| 1394 | 1394 | ) { |
| 1395 | - spip_log("Echec CONNECT sur $first_host:$first_port", 'connect' . _LOG_INFO_IMPORTANTE); |
|
| 1395 | + spip_log("Echec CONNECT sur $first_host:$first_port", 'connect'._LOG_INFO_IMPORTANTE); |
|
| 1396 | 1396 | fclose($f); |
| 1397 | 1397 | |
| 1398 | 1398 | return false; |
@@ -1409,7 +1409,7 @@ discard block |
||
| 1409 | 1409 | } while (!$f and $ntry-- and $errno !== 110 and sleep(1)); |
| 1410 | 1410 | spip_log("Recuperer $path sur $first_host:$first_port par $f"); |
| 1411 | 1411 | if (!$f) { |
| 1412 | - spip_log("Erreur connexion $errno $errstr", 'distant' . _LOG_ERREUR); |
|
| 1412 | + spip_log("Erreur connexion $errno $errstr", 'distant'._LOG_ERREUR); |
|
| 1413 | 1413 | |
| 1414 | 1414 | return $errno; |
| 1415 | 1415 | } |
@@ -1419,16 +1419,16 @@ discard block |
||
| 1419 | 1419 | $site = $GLOBALS['meta']['adresse_site'] ?? ''; |
| 1420 | 1420 | |
| 1421 | 1421 | $host_port = $host; |
| 1422 | - if ($port != (in_array($scheme, ['tls','ssl']) ? 443 : 80)) { |
|
| 1422 | + if ($port != (in_array($scheme, ['tls', 'ssl']) ? 443 : 80)) { |
|
| 1423 | 1423 | $host_port .= ":$port"; |
| 1424 | 1424 | } |
| 1425 | 1425 | $req = "$method $path $vers\r\n" |
| 1426 | 1426 | . "Host: $host_port\r\n" |
| 1427 | - . 'User-Agent: ' . _INC_DISTANT_USER_AGENT . "\r\n" |
|
| 1428 | - . ($refuse_gz ? '' : ('Accept-Encoding: ' . _INC_DISTANT_CONTENT_ENCODING . "\r\n")) |
|
| 1427 | + . 'User-Agent: '._INC_DISTANT_USER_AGENT."\r\n" |
|
| 1428 | + . ($refuse_gz ? '' : ('Accept-Encoding: '._INC_DISTANT_CONTENT_ENCODING."\r\n")) |
|
| 1429 | 1429 | . (!$site ? '' : "Referer: $site/$referer\r\n") |
| 1430 | - . (!$date ? '' : 'If-Modified-Since: ' . (gmdate('D, d M Y H:i:s', $date) . " GMT\r\n")) |
|
| 1431 | - . (!$user ? '' : ('Authorization: Basic ' . base64_encode($user) . "\r\n")) |
|
| 1430 | + . (!$date ? '' : 'If-Modified-Since: '.(gmdate('D, d M Y H:i:s', $date)." GMT\r\n")) |
|
| 1431 | + . (!$user ? '' : ('Authorization: Basic '.base64_encode($user)."\r\n")) |
|
| 1432 | 1432 | . (!$proxy_user ? '' : "Proxy-Authorization: Basic $proxy_user\r\n") |
| 1433 | 1433 | . (!strpos($vers, '1.1') ? '' : "Keep-Alive: 300\r\nConnection: keep-alive\r\n"); |
| 1434 | 1434 | |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $id_rubrique, |
| 151 | 151 | [ |
| 152 | 152 | 'data' => $set, |
| 153 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 153 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique').' '._T('info_numero_abbreviation').$id_rubrique] |
|
| 154 | 154 | ], |
| 155 | 155 | $c |
| 156 | 156 | ) |
@@ -254,7 +254,7 @@ discard block |
||
| 254 | 254 | ) |
| 255 | 255 | ) { |
| 256 | 256 | if ($s['statut'] != 'prepa') { |
| 257 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 257 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a ".$GLOBALS['visiteur_session']['id_auteur'].' '.$GLOBALS['visiteur_session']['statut']); |
|
| 258 | 258 | } |
| 259 | 259 | } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
| 260 | 260 | $statut_ancien = $s['statut']; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Rubriques\Edition |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rubriques'); |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | */ |
| 39 | 39 | function action_editer_rubrique_dist($arg = null) { |
| 40 | 40 | |
| 41 | - if (is_null($arg)) { |
|
| 42 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | - $arg = $securiser_action(); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (!$id_rubrique = intval($arg)) { |
|
| 47 | - if ($arg != 'oui') { |
|
| 48 | - include_spip('inc/headers'); |
|
| 49 | - redirige_url_ecrire(); |
|
| 50 | - } |
|
| 51 | - $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - $err = rubrique_modifier($id_rubrique); |
|
| 55 | - |
|
| 56 | - if (_request('redirect')) { |
|
| 57 | - $redirect = parametre_url( |
|
| 58 | - urldecode(_request('redirect')), |
|
| 59 | - 'id_rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - '&' |
|
| 62 | - ); |
|
| 63 | - |
|
| 64 | - include_spip('inc/headers'); |
|
| 65 | - redirige_par_entete($redirect); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - return [$id_rubrique, $err]; |
|
| 41 | + if (is_null($arg)) { |
|
| 42 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 43 | + $arg = $securiser_action(); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (!$id_rubrique = intval($arg)) { |
|
| 47 | + if ($arg != 'oui') { |
|
| 48 | + include_spip('inc/headers'); |
|
| 49 | + redirige_url_ecrire(); |
|
| 50 | + } |
|
| 51 | + $id_rubrique = rubrique_inserer(_request('id_parent')); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + $err = rubrique_modifier($id_rubrique); |
|
| 55 | + |
|
| 56 | + if (_request('redirect')) { |
|
| 57 | + $redirect = parametre_url( |
|
| 58 | + urldecode(_request('redirect')), |
|
| 59 | + 'id_rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + '&' |
|
| 62 | + ); |
|
| 63 | + |
|
| 64 | + include_spip('inc/headers'); |
|
| 65 | + redirige_par_entete($redirect); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + return [$id_rubrique, $err]; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -80,64 +80,64 @@ discard block |
||
| 80 | 80 | * Identifiant de la rubrique crée |
| 81 | 81 | */ |
| 82 | 82 | function rubrique_inserer($id_parent, $set = null) { |
| 83 | - $champs = [ |
|
| 84 | - 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | - 'id_parent' => intval($id_parent), |
|
| 86 | - 'statut' => 'prepa' |
|
| 87 | - ]; |
|
| 88 | - |
|
| 89 | - if ($set) { |
|
| 90 | - $champs = array_merge($champs, $set); |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - // Envoyer aux plugins |
|
| 94 | - $champs = pipeline( |
|
| 95 | - 'pre_insertion', |
|
| 96 | - [ |
|
| 97 | - 'args' => [ |
|
| 98 | - 'table' => 'spip_rubriques', |
|
| 99 | - ], |
|
| 100 | - 'data' => $champs |
|
| 101 | - ] |
|
| 102 | - ); |
|
| 103 | - |
|
| 104 | - $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | - pipeline( |
|
| 106 | - 'post_insertion', |
|
| 107 | - [ |
|
| 108 | - 'args' => [ |
|
| 109 | - 'table' => 'spip_rubriques', |
|
| 110 | - 'id_objet' => $id_rubrique |
|
| 111 | - ], |
|
| 112 | - 'data' => $champs |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - propager_les_secteurs(); |
|
| 116 | - calculer_langues_rubriques(); |
|
| 117 | - |
|
| 118 | - // Appeler une notification |
|
| 119 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 120 | - $notifications( |
|
| 121 | - 'rubrique_inserer', |
|
| 122 | - $id_rubrique, |
|
| 123 | - [ |
|
| 124 | - 'id_parent' => $id_parent, |
|
| 125 | - 'champs' => $champs, |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - $notifications( |
|
| 129 | - 'objet_inserer', |
|
| 130 | - $id_rubrique, |
|
| 131 | - [ |
|
| 132 | - 'objet' => 'rubrique', |
|
| 133 | - 'id_objet' => $id_rubrique, |
|
| 134 | - 'id_parent' => $id_parent, |
|
| 135 | - 'champs' => $champs, |
|
| 136 | - ] |
|
| 137 | - ); |
|
| 138 | - } |
|
| 83 | + $champs = [ |
|
| 84 | + 'titre' => _T('item_nouvelle_rubrique'), |
|
| 85 | + 'id_parent' => intval($id_parent), |
|
| 86 | + 'statut' => 'prepa' |
|
| 87 | + ]; |
|
| 88 | + |
|
| 89 | + if ($set) { |
|
| 90 | + $champs = array_merge($champs, $set); |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + // Envoyer aux plugins |
|
| 94 | + $champs = pipeline( |
|
| 95 | + 'pre_insertion', |
|
| 96 | + [ |
|
| 97 | + 'args' => [ |
|
| 98 | + 'table' => 'spip_rubriques', |
|
| 99 | + ], |
|
| 100 | + 'data' => $champs |
|
| 101 | + ] |
|
| 102 | + ); |
|
| 103 | + |
|
| 104 | + $id_rubrique = sql_insertq('spip_rubriques', $champs); |
|
| 105 | + pipeline( |
|
| 106 | + 'post_insertion', |
|
| 107 | + [ |
|
| 108 | + 'args' => [ |
|
| 109 | + 'table' => 'spip_rubriques', |
|
| 110 | + 'id_objet' => $id_rubrique |
|
| 111 | + ], |
|
| 112 | + 'data' => $champs |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + propager_les_secteurs(); |
|
| 116 | + calculer_langues_rubriques(); |
|
| 117 | + |
|
| 118 | + // Appeler une notification |
|
| 119 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 120 | + $notifications( |
|
| 121 | + 'rubrique_inserer', |
|
| 122 | + $id_rubrique, |
|
| 123 | + [ |
|
| 124 | + 'id_parent' => $id_parent, |
|
| 125 | + 'champs' => $champs, |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + $notifications( |
|
| 129 | + 'objet_inserer', |
|
| 130 | + $id_rubrique, |
|
| 131 | + [ |
|
| 132 | + 'objet' => 'rubrique', |
|
| 133 | + 'id_objet' => $id_rubrique, |
|
| 134 | + 'id_parent' => $id_parent, |
|
| 135 | + 'champs' => $champs, |
|
| 136 | + ] |
|
| 137 | + ); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return $id_rubrique; |
|
| 140 | + return $id_rubrique; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -153,46 +153,46 @@ discard block |
||
| 153 | 153 | * - chaîne : texte d'un message d'erreur |
| 154 | 154 | */ |
| 155 | 155 | function rubrique_modifier($id_rubrique, $set = null) { |
| 156 | - include_spip('inc/autoriser'); |
|
| 157 | - include_spip('inc/filtres'); |
|
| 158 | - |
|
| 159 | - include_spip('inc/modifier'); |
|
| 160 | - $c = collecter_requests( |
|
| 161 | - // include list |
|
| 162 | - objet_info('rubrique', 'champs_editables'), |
|
| 163 | - // exclude list |
|
| 164 | - ['id_parent', 'confirme_deplace'], |
|
| 165 | - // donnees eventuellement fournies |
|
| 166 | - $set |
|
| 167 | - ); |
|
| 168 | - |
|
| 169 | - if ( |
|
| 170 | - $err = objet_modifier_champs( |
|
| 171 | - 'rubrique', |
|
| 172 | - $id_rubrique, |
|
| 173 | - [ |
|
| 174 | - 'data' => $set, |
|
| 175 | - 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 176 | - ], |
|
| 177 | - $c |
|
| 178 | - ) |
|
| 179 | - ) { |
|
| 180 | - return $err; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 184 | - // Deplacer la rubrique |
|
| 185 | - if (isset($c['id_parent'])) { |
|
| 186 | - $err = rubrique_instituer($id_rubrique, $c); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // invalider les caches marques de cette rubrique |
|
| 190 | - include_spip('inc/invalideur'); |
|
| 191 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 192 | - // et celui de menu_rubriques |
|
| 193 | - effacer_meta('date_calcul_rubriques'); |
|
| 194 | - |
|
| 195 | - return $err; |
|
| 156 | + include_spip('inc/autoriser'); |
|
| 157 | + include_spip('inc/filtres'); |
|
| 158 | + |
|
| 159 | + include_spip('inc/modifier'); |
|
| 160 | + $c = collecter_requests( |
|
| 161 | + // include list |
|
| 162 | + objet_info('rubrique', 'champs_editables'), |
|
| 163 | + // exclude list |
|
| 164 | + ['id_parent', 'confirme_deplace'], |
|
| 165 | + // donnees eventuellement fournies |
|
| 166 | + $set |
|
| 167 | + ); |
|
| 168 | + |
|
| 169 | + if ( |
|
| 170 | + $err = objet_modifier_champs( |
|
| 171 | + 'rubrique', |
|
| 172 | + $id_rubrique, |
|
| 173 | + [ |
|
| 174 | + 'data' => $set, |
|
| 175 | + 'nonvide' => ['titre' => _T('titre_nouvelle_rubrique') . ' ' . _T('info_numero_abbreviation') . $id_rubrique] |
|
| 176 | + ], |
|
| 177 | + $c |
|
| 178 | + ) |
|
| 179 | + ) { |
|
| 180 | + return $err; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $c = collecter_requests(['id_parent', 'confirme_deplace'], [], $set); |
|
| 184 | + // Deplacer la rubrique |
|
| 185 | + if (isset($c['id_parent'])) { |
|
| 186 | + $err = rubrique_instituer($id_rubrique, $c); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // invalider les caches marques de cette rubrique |
|
| 190 | + include_spip('inc/invalideur'); |
|
| 191 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 192 | + // et celui de menu_rubriques |
|
| 193 | + effacer_meta('date_calcul_rubriques'); |
|
| 194 | + |
|
| 195 | + return $err; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | /** |
@@ -215,29 +215,29 @@ discard block |
||
| 215 | 215 | * false si la confirmation du déplacement n'est pas présente |
| 216 | 216 | */ |
| 217 | 217 | function editer_rubrique_breves($id_rubrique, $id_parent, $c = []) { |
| 218 | - if (!sql_table_exists('spip_breves')) { |
|
| 219 | - return true; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 223 | - return true; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 227 | - return false; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - if ( |
|
| 231 | - $id_secteur = sql_getfetsel( |
|
| 232 | - 'id_secteur', |
|
| 233 | - 'spip_rubriques', |
|
| 234 | - "id_rubrique=$id_parent" |
|
| 235 | - ) |
|
| 236 | - ) { |
|
| 237 | - sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - return true; |
|
| 218 | + if (!sql_table_exists('spip_breves')) { |
|
| 219 | + return true; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + if (!sql_countsel('spip_breves', "id_rubrique=$id_rubrique")) { |
|
| 223 | + return true; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + if (empty($c['confirme_deplace']) or $c['confirme_deplace'] != 'oui') { |
|
| 227 | + return false; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + if ( |
|
| 231 | + $id_secteur = sql_getfetsel( |
|
| 232 | + 'id_secteur', |
|
| 233 | + 'spip_rubriques', |
|
| 234 | + "id_rubrique=$id_parent" |
|
| 235 | + ) |
|
| 236 | + ) { |
|
| 237 | + sql_updateq('spip_breves', ['id_rubrique' => $id_secteur], "id_rubrique=$id_rubrique"); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + return true; |
|
| 241 | 241 | } |
| 242 | 242 | |
| 243 | 243 | |
@@ -259,72 +259,72 @@ discard block |
||
| 259 | 259 | * Chaîne : texte du message d'erreur |
| 260 | 260 | */ |
| 261 | 261 | function rubrique_instituer($id_rubrique, $c) { |
| 262 | - // traitement de la rubrique parente |
|
| 263 | - // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 264 | - // qu'on n'administre pas. |
|
| 265 | - |
|
| 266 | - if (null !== ($id_parent = $c['id_parent'])) { |
|
| 267 | - $id_parent = intval($id_parent); |
|
| 268 | - $filles = calcul_branche_in($id_rubrique); |
|
| 269 | - if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 270 | - spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 271 | - } else { |
|
| 272 | - $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 273 | - $old_parent = $s['id_parent']; |
|
| 274 | - |
|
| 275 | - if ( |
|
| 276 | - !($id_parent != $old_parent |
|
| 277 | - and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 278 | - and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 279 | - and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 280 | - ) |
|
| 281 | - ) { |
|
| 282 | - if ($s['statut'] != 'prepa') { |
|
| 283 | - spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 284 | - } |
|
| 285 | - } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 286 | - $statut_ancien = $s['statut']; |
|
| 287 | - sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 288 | - |
|
| 289 | - |
|
| 290 | - propager_les_secteurs(); |
|
| 291 | - |
|
| 292 | - // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 293 | - if ($statut_ancien == 'publie') { |
|
| 294 | - calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 295 | - } |
|
| 296 | - // Creation ou deplacement d'une rubrique non publiee |
|
| 297 | - // invalider le cache de leur menu |
|
| 298 | - elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 299 | - effacer_meta('date_calcul_rubriques'); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - calculer_langues_rubriques(); |
|
| 262 | + // traitement de la rubrique parente |
|
| 263 | + // interdiction de deplacer vers ou a partir d'une rubrique |
|
| 264 | + // qu'on n'administre pas. |
|
| 265 | + |
|
| 266 | + if (null !== ($id_parent = $c['id_parent'])) { |
|
| 267 | + $id_parent = intval($id_parent); |
|
| 268 | + $filles = calcul_branche_in($id_rubrique); |
|
| 269 | + if (strpos(",$id_parent,", (string) ",$filles,") !== false) { |
|
| 270 | + spip_log("La rubrique $id_rubrique ne peut etre fille de sa descendante $id_parent"); |
|
| 271 | + } else { |
|
| 272 | + $s = sql_fetsel('id_parent, statut', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 273 | + $old_parent = $s['id_parent']; |
|
| 274 | + |
|
| 275 | + if ( |
|
| 276 | + !($id_parent != $old_parent |
|
| 277 | + and autoriser('publierdans', 'rubrique', $id_parent) |
|
| 278 | + and autoriser('creerrubriquedans', 'rubrique', $id_parent) |
|
| 279 | + and autoriser('publierdans', 'rubrique', $old_parent) |
|
| 280 | + ) |
|
| 281 | + ) { |
|
| 282 | + if ($s['statut'] != 'prepa') { |
|
| 283 | + spip_log("deplacement de $id_rubrique vers $id_parent refuse a " . $GLOBALS['visiteur_session']['id_auteur'] . ' ' . $GLOBALS['visiteur_session']['statut']); |
|
| 284 | + } |
|
| 285 | + } elseif (editer_rubrique_breves($id_rubrique, $id_parent, $c)) { |
|
| 286 | + $statut_ancien = $s['statut']; |
|
| 287 | + sql_updateq('spip_rubriques', ['id_parent' => $id_parent], "id_rubrique=$id_rubrique"); |
|
| 288 | + |
|
| 289 | + |
|
| 290 | + propager_les_secteurs(); |
|
| 291 | + |
|
| 292 | + // Deplacement d'une rubrique publiee ==> chgt general de leur statut |
|
| 293 | + if ($statut_ancien == 'publie') { |
|
| 294 | + calculer_rubriques_if($old_parent, ['id_rubrique' => $id_parent], ['statut_ancien' => $statut_ancien]); |
|
| 295 | + } |
|
| 296 | + // Creation ou deplacement d'une rubrique non publiee |
|
| 297 | + // invalider le cache de leur menu |
|
| 298 | + elseif (!$statut_ancien || $old_parent != $id_parent) { |
|
| 299 | + effacer_meta('date_calcul_rubriques'); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + calculer_langues_rubriques(); |
|
| 303 | 303 | |
| 304 | - // Appeler une notification |
|
| 305 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 306 | - $notifications( |
|
| 307 | - 'rubrique_instituer', |
|
| 308 | - $id_rubrique, |
|
| 309 | - [ |
|
| 310 | - 'statut_ancien' => $statut_ancien, |
|
| 311 | - 'id_parent_ancien' => $old_parent, |
|
| 312 | - ] |
|
| 313 | - ); |
|
| 314 | - $notifications( |
|
| 315 | - 'objet_instituer', |
|
| 316 | - $id_rubrique, |
|
| 317 | - [ |
|
| 318 | - 'objet' => 'rubrique', |
|
| 319 | - 'id_objet' => $id_rubrique, |
|
| 320 | - 'statut_ancien' => $statut_ancien, |
|
| 321 | - 'id_parent_ancien' => $old_parent, |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - } |
|
| 326 | - } |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - return ''; // pas d'erreur |
|
| 304 | + // Appeler une notification |
|
| 305 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 306 | + $notifications( |
|
| 307 | + 'rubrique_instituer', |
|
| 308 | + $id_rubrique, |
|
| 309 | + [ |
|
| 310 | + 'statut_ancien' => $statut_ancien, |
|
| 311 | + 'id_parent_ancien' => $old_parent, |
|
| 312 | + ] |
|
| 313 | + ); |
|
| 314 | + $notifications( |
|
| 315 | + 'objet_instituer', |
|
| 316 | + $id_rubrique, |
|
| 317 | + [ |
|
| 318 | + 'objet' => 'rubrique', |
|
| 319 | + 'id_objet' => $id_rubrique, |
|
| 320 | + 'statut_ancien' => $statut_ancien, |
|
| 321 | + 'id_parent_ancien' => $old_parent, |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + return ''; // pas d'erreur |
|
| 330 | 330 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | function extraire_date($texte): string { |
| 40 | 40 | // format = 2001-08 |
| 41 | 41 | if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01'; |
|
| 43 | 43 | } |
| 44 | 44 | return ''; |
| 45 | 45 | } |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 72 | 72 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | + $date = $regs[1].'-00-00'.$regs[3]; |
|
| 74 | 74 | } else { |
| 75 | 75 | if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 76 | 76 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3]; |
|
| 78 | 78 | } else { |
| 79 | 79 | $date = date('Y-m-d H:i:s', strtotime($date)); |
| 80 | 80 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $letexte ??= ''; |
| 102 | 102 | if ( |
| 103 | 103 | !$verif_format_date |
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | + or (in_array(strlen($letexte), [10, 19]) and |
|
| 105 | 105 | preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
| 106 | 106 | ) { |
| 107 | 107 | if (strncmp('0000-00-00', $letexte, 10) == 0) { |
@@ -388,17 +388,17 @@ discard block |
||
| 388 | 388 | if ($decal > 3600 * 24 * 30) { |
| 389 | 389 | $mois = floor($decal / (3600 * 24 * 30)); |
| 390 | 390 | if ($mois < 2) { |
| 391 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 391 | + $delai = "$mois "._T('date_un_mois'); |
|
| 392 | 392 | } else { |
| 393 | - $delai = "$mois " . _T('date_mois'); |
|
| 393 | + $delai = "$mois "._T('date_mois'); |
|
| 394 | 394 | } |
| 395 | 395 | } else { |
| 396 | 396 | if ($decal > 3600 * 24 * 7) { |
| 397 | 397 | $semaines = floor($decal / (3600 * 24 * 7)); |
| 398 | 398 | if ($semaines < 2) { |
| 399 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 399 | + $delai = "$semaines "._T('date_une_semaine'); |
|
| 400 | 400 | } else { |
| 401 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 401 | + $delai = "$semaines "._T('date_semaines'); |
|
| 402 | 402 | } |
| 403 | 403 | } else { |
| 404 | 404 | if ($decal > 3600 * 24) { |
@@ -406,30 +406,30 @@ discard block |
||
| 406 | 406 | if ($jours < 2) { |
| 407 | 407 | return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
| 408 | 408 | } else { |
| 409 | - $delai = "$jours " . _T('date_jours'); |
|
| 409 | + $delai = "$jours "._T('date_jours'); |
|
| 410 | 410 | } |
| 411 | 411 | } else { |
| 412 | 412 | if ($decal >= 3600) { |
| 413 | 413 | $heures = floor($decal / 3600); |
| 414 | 414 | if ($heures < 2) { |
| 415 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 415 | + $delai = "$heures "._T('date_une_heure'); |
|
| 416 | 416 | } else { |
| 417 | - $delai = "$heures " . _T('date_heures'); |
|
| 417 | + $delai = "$heures "._T('date_heures'); |
|
| 418 | 418 | } |
| 419 | 419 | } else { |
| 420 | 420 | if ($decal >= 60) { |
| 421 | 421 | $minutes = floor($decal / 60); |
| 422 | 422 | if ($minutes < 2) { |
| 423 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 423 | + $delai = "$minutes "._T('date_une_minute'); |
|
| 424 | 424 | } else { |
| 425 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 425 | + $delai = "$minutes "._T('date_minutes'); |
|
| 426 | 426 | } |
| 427 | 427 | } else { |
| 428 | 428 | $secondes = ceil($decal); |
| 429 | 429 | if ($secondes < 2) { |
| 430 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 430 | + $delai = "$secondes "._T('date_une_seconde'); |
|
| 431 | 431 | } else { |
| 432 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 432 | + $delai = "$secondes "._T('date_secondes'); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | $njour = 0; |
| 523 | 523 | } else { |
| 524 | 524 | $njour = intval($jour); |
| 525 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 525 | + if ($jourth = _T('date_jnum'.$jour)) { |
|
| 526 | 526 | $jour = $jourth; |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -530,10 +530,10 @@ discard block |
||
| 530 | 530 | $mois = intval($mois); |
| 531 | 531 | if ($mois > 0 and $mois < 13) { |
| 532 | 532 | /* Traiter le cas "abbr" pour les noms de mois */ |
| 533 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 534 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : ''); |
|
| 534 | + $nommois = _T('date_mois_'.$mois.$param); |
|
| 535 | 535 | if ($jour) { |
| 536 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 536 | + $jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 537 | 537 | } else { |
| 538 | 538 | $jourmois = $nommois; |
| 539 | 539 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | if ($annee < 0) { |
| 546 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 546 | + $annee = -$annee.' '._T('date_avant_jc'); |
|
| 547 | 547 | $avjc = true; |
| 548 | 548 | } else { |
| 549 | 549 | $avjc = false; |
@@ -569,11 +569,11 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | if ($vue == 'saison') { |
| 572 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 572 | + return $saison ? _T('date_saison_'.$saison) : ''; |
|
| 573 | 573 | } else { |
| 574 | 574 | return $saison ? trim(_T( |
| 575 | 575 | 'date_fmt_saison_annee', |
| 576 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 576 | + ['saison' => _T('date_saison_'.$saison), 'annee' => $annee] |
|
| 577 | 577 | )) : ''; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | } |
| 651 | 651 | $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
| 652 | 652 | $nom = 1 + (int) date('w', $nom); |
| 653 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 653 | + $param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : ''); |
|
| 654 | 654 | |
| 655 | - return _T('date_jour_' . $nom . $param); |
|
| 655 | + return _T('date_jour_'.$nom.$param); |
|
| 656 | 656 | |
| 657 | 657 | case 'mois_annee': |
| 658 | 658 | if ($avjc) { |
@@ -1047,8 +1047,8 @@ discard block |
||
| 1047 | 1047 | |
| 1048 | 1048 | $dtstart = $dtend = $dtabbr = ''; |
| 1049 | 1049 | if (strpos($forme, 'hcal') !== false) { |
| 1050 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1051 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | + $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
|
| 1051 | + $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
|
| 1052 | 1052 | $dtabbr = '</abbr>'; |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1096,7 +1096,7 @@ discard block |
||
| 1096 | 1096 | } |
| 1097 | 1097 | } else { |
| 1098 | 1098 | if ($dtabbr && $dtstart) { |
| 1099 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1099 | + $s = $dtstart.spip_ucfirst($s).$dtabbr; |
|
| 1100 | 1100 | } else { |
| 1101 | 1101 | $s = spip_ucfirst($s); |
| 1102 | 1102 | } |
@@ -1119,8 +1119,8 @@ discard block |
||
| 1119 | 1119 | $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
| 1120 | 1120 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1121 | 1121 | } |
| 1122 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1123 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1123 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1124 | 1124 | |
| 1125 | 1125 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1126 | 1126 | } else { |
@@ -1137,8 +1137,8 @@ discard block |
||
| 1137 | 1137 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1141 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1141 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1142 | 1142 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1143 | 1143 | } |
| 1144 | 1144 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | $d = date('Y-m-d'); |
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1245 | + return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2); |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | /** |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | $d = date('Y-m-d'); |
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1265 | + return substr($d, 0, 4).substr($d, 5, 2); |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | /** |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 37 | 37 | **/ |
| 38 | 38 | function extraire_date($texte): string { |
| 39 | - // format = 2001-08 |
|
| 40 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | - } |
|
| 43 | - return ''; |
|
| 39 | + // format = 2001-08 |
|
| 40 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + } |
|
| 43 | + return ''; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -62,29 +62,29 @@ discard block |
||
| 62 | 62 | * - une chaîne vide si la date est considérée nulle |
| 63 | 63 | **/ |
| 64 | 64 | function normaliser_date($date, $forcer_jour = false): string { |
| 65 | - $date = vider_date($date); |
|
| 66 | - if ($date) { |
|
| 67 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 68 | - $date = date('Y-m-d H:i:s', $date); |
|
| 69 | - } |
|
| 70 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 71 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 72 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | - } else { |
|
| 74 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 75 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 76 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | - } else { |
|
| 78 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ($forcer_jour) { |
|
| 83 | - $date = str_replace('-00', '-01', $date); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $date; |
|
| 65 | + $date = vider_date($date); |
|
| 66 | + if ($date) { |
|
| 67 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 68 | + $date = date('Y-m-d H:i:s', $date); |
|
| 69 | + } |
|
| 70 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 71 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 72 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | + } else { |
|
| 74 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 75 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 76 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | + } else { |
|
| 78 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ($forcer_jour) { |
|
| 83 | + $date = str_replace('-00', '-01', $date); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $date; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,23 +97,23 @@ discard block |
||
| 97 | 97 | * - Une chaine vide |
| 98 | 98 | **/ |
| 99 | 99 | function vider_date($letexte, $verif_format_date = false): string { |
| 100 | - $letexte ??= ''; |
|
| 101 | - if ( |
|
| 102 | - !$verif_format_date |
|
| 103 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 105 | - ) { |
|
| 106 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 110 | - return ''; |
|
| 111 | - } |
|
| 112 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 113 | - return ''; |
|
| 114 | - } // eviter le bug GMT-1 |
|
| 115 | - } |
|
| 116 | - return $letexte; |
|
| 100 | + $letexte ??= ''; |
|
| 101 | + if ( |
|
| 102 | + !$verif_format_date |
|
| 103 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 105 | + ) { |
|
| 106 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 110 | + return ''; |
|
| 111 | + } |
|
| 112 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 113 | + return ''; |
|
| 114 | + } // eviter le bug GMT-1 |
|
| 115 | + } |
|
| 116 | + return $letexte; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | **/ |
| 130 | 130 | function recup_heure($date): array { |
| 131 | 131 | |
| 132 | - if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 133 | - array_shift($elements); |
|
| 134 | - if (!isset($elements[2])) { |
|
| 135 | - $elements[2] = 0; |
|
| 136 | - } |
|
| 137 | - $heure = $elements; |
|
| 138 | - } else { |
|
| 139 | - $heure = [0, 0, 0]; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $heure; |
|
| 132 | + if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 133 | + array_shift($elements); |
|
| 134 | + if (!isset($elements[2])) { |
|
| 135 | + $elements[2] = 0; |
|
| 136 | + } |
|
| 137 | + $heure = $elements; |
|
| 138 | + } else { |
|
| 139 | + $heure = [0, 0, 0]; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $heure; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -153,13 +153,13 @@ discard block |
||
| 153 | 153 | * @return string heures, sinon 0 |
| 154 | 154 | **/ |
| 155 | 155 | function heures($numdate): string { |
| 156 | - $heures = null; |
|
| 157 | - $date_array = recup_heure($numdate); |
|
| 158 | - if ($date_array) { |
|
| 159 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 160 | - } |
|
| 156 | + $heures = null; |
|
| 157 | + $date_array = recup_heure($numdate); |
|
| 158 | + if ($date_array) { |
|
| 159 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $heures; |
|
| 162 | + return $heures; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | * @return string minutes, sinon 0 |
| 174 | 174 | **/ |
| 175 | 175 | function minutes($numdate): string { |
| 176 | - $minutes = null; |
|
| 177 | - $date_array = recup_heure($numdate); |
|
| 178 | - if ($date_array) { |
|
| 179 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 180 | - } |
|
| 176 | + $minutes = null; |
|
| 177 | + $date_array = recup_heure($numdate); |
|
| 178 | + if ($date_array) { |
|
| 179 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - return $minutes; |
|
| 182 | + return $minutes; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | * @return string secondes, sinon 0 |
| 194 | 194 | **/ |
| 195 | 195 | function secondes($numdate): string { |
| 196 | - $secondes = null; |
|
| 197 | - $date_array = recup_heure($numdate); |
|
| 198 | - if ($date_array) { |
|
| 199 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 200 | - } |
|
| 196 | + $secondes = null; |
|
| 197 | + $date_array = recup_heure($numdate); |
|
| 198 | + if ($date_array) { |
|
| 199 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return $secondes; |
|
| 202 | + return $secondes; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | * @return string L'heure formatée dans la langue en cours. |
| 219 | 219 | **/ |
| 220 | 220 | function heures_minutes($numdate, $forme = ''): string { |
| 221 | - if ($forme !== 'abbr') { |
|
| 222 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 223 | - } else { |
|
| 224 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 225 | - } |
|
| 221 | + if ($forme !== 'abbr') { |
|
| 222 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 223 | + } else { |
|
| 224 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -247,57 +247,57 @@ discard block |
||
| 247 | 247 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 248 | 248 | **/ |
| 249 | 249 | function recup_date($numdate, $forcer_jour = true): array { |
| 250 | - if (!$numdate) { |
|
| 251 | - return []; |
|
| 252 | - } |
|
| 253 | - $heures = $minutes = $secondes = 0; |
|
| 254 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 255 | - $jour = $regs[1]; |
|
| 256 | - $mois = $regs[2]; |
|
| 257 | - $annee = $regs[3]; |
|
| 258 | - if ($annee < 90) { |
|
| 259 | - $annee = 2000 + $annee; |
|
| 260 | - } elseif ($annee < 100) { |
|
| 261 | - $annee = 1900 + $annee; |
|
| 262 | - } |
|
| 263 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 264 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 265 | - $annee = $regs[1]; |
|
| 266 | - $mois = $regs[2]; |
|
| 267 | - $jour = $regs[3]; |
|
| 268 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 269 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 270 | - $annee = $regs[1]; |
|
| 271 | - $mois = $regs[2]; |
|
| 272 | - $jour = ''; |
|
| 273 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 274 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 275 | - $annee = $regs[1]; |
|
| 276 | - $mois = $regs[2]; |
|
| 277 | - $jour = $regs[3]; |
|
| 278 | - $heures = $regs[4]; |
|
| 279 | - $minutes = $regs[5]; |
|
| 280 | - $secondes = $regs[6]; |
|
| 281 | - } else { |
|
| 282 | - $annee = $mois = $jour = ''; |
|
| 283 | - } |
|
| 284 | - if ($annee > 4000) { |
|
| 285 | - $annee -= 9000; |
|
| 286 | - } |
|
| 287 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 288 | - $jour = substr($jour, 1); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if ($forcer_jour and $jour == '0') { |
|
| 292 | - $jour = '1'; |
|
| 293 | - } |
|
| 294 | - if ($forcer_jour and $mois == '0') { |
|
| 295 | - $mois = '1'; |
|
| 296 | - } |
|
| 297 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 298 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 299 | - } |
|
| 300 | - return []; |
|
| 250 | + if (!$numdate) { |
|
| 251 | + return []; |
|
| 252 | + } |
|
| 253 | + $heures = $minutes = $secondes = 0; |
|
| 254 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 255 | + $jour = $regs[1]; |
|
| 256 | + $mois = $regs[2]; |
|
| 257 | + $annee = $regs[3]; |
|
| 258 | + if ($annee < 90) { |
|
| 259 | + $annee = 2000 + $annee; |
|
| 260 | + } elseif ($annee < 100) { |
|
| 261 | + $annee = 1900 + $annee; |
|
| 262 | + } |
|
| 263 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 264 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 265 | + $annee = $regs[1]; |
|
| 266 | + $mois = $regs[2]; |
|
| 267 | + $jour = $regs[3]; |
|
| 268 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 269 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 270 | + $annee = $regs[1]; |
|
| 271 | + $mois = $regs[2]; |
|
| 272 | + $jour = ''; |
|
| 273 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 274 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 275 | + $annee = $regs[1]; |
|
| 276 | + $mois = $regs[2]; |
|
| 277 | + $jour = $regs[3]; |
|
| 278 | + $heures = $regs[4]; |
|
| 279 | + $minutes = $regs[5]; |
|
| 280 | + $secondes = $regs[6]; |
|
| 281 | + } else { |
|
| 282 | + $annee = $mois = $jour = ''; |
|
| 283 | + } |
|
| 284 | + if ($annee > 4000) { |
|
| 285 | + $annee -= 9000; |
|
| 286 | + } |
|
| 287 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 288 | + $jour = substr($jour, 1); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if ($forcer_jour and $jour == '0') { |
|
| 292 | + $jour = '1'; |
|
| 293 | + } |
|
| 294 | + if ($forcer_jour and $mois == '0') { |
|
| 295 | + $mois = '1'; |
|
| 296 | + } |
|
| 297 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 298 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 299 | + } |
|
| 300 | + return []; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | * La date relative ou complète |
| 325 | 325 | **/ |
| 326 | 326 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 327 | - return sinon( |
|
| 328 | - date_relative($date, $decalage_maxi), |
|
| 329 | - affdate_heure($date) |
|
| 330 | - ); |
|
| 327 | + return sinon( |
|
| 328 | + date_relative($date, $decalage_maxi), |
|
| 329 | + affdate_heure($date) |
|
| 330 | + ); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -360,86 +360,86 @@ discard block |
||
| 360 | 360 | **/ |
| 361 | 361 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 362 | 362 | |
| 363 | - if (!$date) { |
|
| 364 | - return ''; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - if (is_null($ref_date)) { |
|
| 368 | - $ref_time = time(); |
|
| 369 | - } else { |
|
| 370 | - $ref_time = strtotime($ref_date); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 374 | - |
|
| 375 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 376 | - return ''; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if ($decal < 0) { |
|
| 380 | - $il_y_a = 'date_dans'; |
|
| 381 | - $decal = -1 * $decal; |
|
| 382 | - } else { |
|
| 383 | - $il_y_a = 'date_il_y_a'; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 387 | - return affdate_court($date); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if ($decal > 3600 * 24 * 30) { |
|
| 391 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 392 | - if ($mois < 2) { |
|
| 393 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 394 | - } else { |
|
| 395 | - $delai = "$mois " . _T('date_mois'); |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - if ($decal > 3600 * 24 * 7) { |
|
| 399 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 400 | - if ($semaines < 2) { |
|
| 401 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 402 | - } else { |
|
| 403 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 404 | - } |
|
| 405 | - } else { |
|
| 406 | - if ($decal > 3600 * 24) { |
|
| 407 | - $jours = floor($decal / (3600 * 24)); |
|
| 408 | - if ($jours < 2) { |
|
| 409 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 410 | - } else { |
|
| 411 | - $delai = "$jours " . _T('date_jours'); |
|
| 412 | - } |
|
| 413 | - } else { |
|
| 414 | - if ($decal >= 3600) { |
|
| 415 | - $heures = floor($decal / 3600); |
|
| 416 | - if ($heures < 2) { |
|
| 417 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 418 | - } else { |
|
| 419 | - $delai = "$heures " . _T('date_heures'); |
|
| 420 | - } |
|
| 421 | - } else { |
|
| 422 | - if ($decal >= 60) { |
|
| 423 | - $minutes = floor($decal / 60); |
|
| 424 | - if ($minutes < 2) { |
|
| 425 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 426 | - } else { |
|
| 427 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 428 | - } |
|
| 429 | - } else { |
|
| 430 | - $secondes = ceil($decal); |
|
| 431 | - if ($secondes < 2) { |
|
| 432 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 433 | - } else { |
|
| 434 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 363 | + if (!$date) { |
|
| 364 | + return ''; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + if (is_null($ref_date)) { |
|
| 368 | + $ref_time = time(); |
|
| 369 | + } else { |
|
| 370 | + $ref_time = strtotime($ref_date); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 374 | + |
|
| 375 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 376 | + return ''; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if ($decal < 0) { |
|
| 380 | + $il_y_a = 'date_dans'; |
|
| 381 | + $decal = -1 * $decal; |
|
| 382 | + } else { |
|
| 383 | + $il_y_a = 'date_il_y_a'; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 387 | + return affdate_court($date); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if ($decal > 3600 * 24 * 30) { |
|
| 391 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 392 | + if ($mois < 2) { |
|
| 393 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 394 | + } else { |
|
| 395 | + $delai = "$mois " . _T('date_mois'); |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + if ($decal > 3600 * 24 * 7) { |
|
| 399 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 400 | + if ($semaines < 2) { |
|
| 401 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 402 | + } else { |
|
| 403 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 404 | + } |
|
| 405 | + } else { |
|
| 406 | + if ($decal > 3600 * 24) { |
|
| 407 | + $jours = floor($decal / (3600 * 24)); |
|
| 408 | + if ($jours < 2) { |
|
| 409 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 410 | + } else { |
|
| 411 | + $delai = "$jours " . _T('date_jours'); |
|
| 412 | + } |
|
| 413 | + } else { |
|
| 414 | + if ($decal >= 3600) { |
|
| 415 | + $heures = floor($decal / 3600); |
|
| 416 | + if ($heures < 2) { |
|
| 417 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 418 | + } else { |
|
| 419 | + $delai = "$heures " . _T('date_heures'); |
|
| 420 | + } |
|
| 421 | + } else { |
|
| 422 | + if ($decal >= 60) { |
|
| 423 | + $minutes = floor($decal / 60); |
|
| 424 | + if ($minutes < 2) { |
|
| 425 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 426 | + } else { |
|
| 427 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 428 | + } |
|
| 429 | + } else { |
|
| 430 | + $secondes = ceil($decal); |
|
| 431 | + if ($secondes < 2) { |
|
| 432 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 433 | + } else { |
|
| 434 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -465,32 +465,32 @@ discard block |
||
| 465 | 465 | **/ |
| 466 | 466 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 467 | 467 | |
| 468 | - if (!$date) { |
|
| 469 | - return ''; |
|
| 470 | - } |
|
| 471 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 472 | - |
|
| 473 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 474 | - return ''; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - if ($decal < -24 * 3600) { |
|
| 478 | - $retour = date_relative($date, $decalage_maxi); |
|
| 479 | - } elseif ($decal < 0) { |
|
| 480 | - $retour = _T('date_demain'); |
|
| 481 | - } else { |
|
| 482 | - if ($decal < (3600 * 24)) { |
|
| 483 | - $retour = _T('date_aujourdhui'); |
|
| 484 | - } else { |
|
| 485 | - if ($decal < (3600 * 24 * 2)) { |
|
| 486 | - $retour = _T('date_hier'); |
|
| 487 | - } else { |
|
| 488 | - $retour = date_relative($date, $decalage_maxi); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - return $retour; |
|
| 468 | + if (!$date) { |
|
| 469 | + return ''; |
|
| 470 | + } |
|
| 471 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 472 | + |
|
| 473 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 474 | + return ''; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + if ($decal < -24 * 3600) { |
|
| 478 | + $retour = date_relative($date, $decalage_maxi); |
|
| 479 | + } elseif ($decal < 0) { |
|
| 480 | + $retour = _T('date_demain'); |
|
| 481 | + } else { |
|
| 482 | + if ($decal < (3600 * 24)) { |
|
| 483 | + $retour = _T('date_aujourdhui'); |
|
| 484 | + } else { |
|
| 485 | + if ($decal < (3600 * 24 * 2)) { |
|
| 486 | + $retour = _T('date_hier'); |
|
| 487 | + } else { |
|
| 488 | + $retour = date_relative($date, $decalage_maxi); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + return $retour; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -507,174 +507,174 @@ discard block |
||
| 507 | 507 | * @return string |
| 508 | 508 | */ |
| 509 | 509 | function affdate_base($numdate, $vue, $options = []): string { |
| 510 | - if (is_string($options)) { |
|
| 511 | - $options = ['param' => $options]; |
|
| 512 | - } |
|
| 513 | - $date_array = recup_date($numdate, false); |
|
| 514 | - if (!$date_array) { |
|
| 515 | - return ''; |
|
| 516 | - } |
|
| 517 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 518 | - |
|
| 519 | - // 1er, 21st, etc. |
|
| 520 | - $journum = $jour; |
|
| 521 | - |
|
| 522 | - if ($jour == 0) { |
|
| 523 | - $jour = ''; |
|
| 524 | - $njour = 0; |
|
| 525 | - } else { |
|
| 526 | - $njour = intval($jour); |
|
| 527 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 528 | - $jour = $jourth; |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $mois = intval($mois); |
|
| 533 | - if ($mois > 0 and $mois < 13) { |
|
| 534 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 535 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 536 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 537 | - if ($jour) { |
|
| 538 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 539 | - } else { |
|
| 540 | - $jourmois = $nommois; |
|
| 541 | - } |
|
| 542 | - } else { |
|
| 543 | - $nommois = ''; |
|
| 544 | - $jourmois = ''; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if ($annee < 0) { |
|
| 548 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 549 | - $avjc = true; |
|
| 550 | - } else { |
|
| 551 | - $avjc = false; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - switch ($vue) { |
|
| 555 | - case 'saison': |
|
| 556 | - case 'saison_annee': |
|
| 557 | - $saison = ''; |
|
| 558 | - if ($mois > 0) { |
|
| 559 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 560 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 561 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 562 | - } |
|
| 563 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 564 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 565 | - } |
|
| 566 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 567 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 568 | - } |
|
| 569 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 570 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - if ($vue == 'saison') { |
|
| 574 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 575 | - } else { |
|
| 576 | - return $saison ? trim(_T( |
|
| 577 | - 'date_fmt_saison_annee', |
|
| 578 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 579 | - )) : ''; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - case 'court': |
|
| 583 | - if ($avjc) { |
|
| 584 | - return $annee; |
|
| 585 | - } |
|
| 586 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 587 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 588 | - return $annee; |
|
| 589 | - } |
|
| 590 | - if ($annee != $a) { |
|
| 591 | - return _T( |
|
| 592 | - 'date_fmt_mois_annee', |
|
| 593 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return _T( |
|
| 598 | - 'date_fmt_jour_mois', |
|
| 599 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 600 | - ); |
|
| 601 | - |
|
| 602 | - case 'jourcourt': |
|
| 603 | - if ($avjc) { |
|
| 604 | - return $annee; |
|
| 605 | - } |
|
| 606 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 607 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 608 | - return $annee; |
|
| 609 | - } |
|
| 610 | - if ($annee != $a) { |
|
| 611 | - return _T( |
|
| 612 | - 'date_fmt_jour_mois_annee', |
|
| 613 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 614 | - ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return _T( |
|
| 618 | - 'date_fmt_jour_mois', |
|
| 619 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 620 | - ); |
|
| 621 | - |
|
| 622 | - case 'entier': |
|
| 623 | - if ($avjc) { |
|
| 624 | - return $annee; |
|
| 625 | - } |
|
| 626 | - if ($jour) { |
|
| 627 | - return _T( |
|
| 628 | - 'date_fmt_jour_mois_annee', |
|
| 629 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 630 | - ); |
|
| 631 | - } elseif ($mois) { |
|
| 632 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 633 | - } else { |
|
| 634 | - return $annee; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - case 'nom_mois': |
|
| 638 | - return $nommois; |
|
| 639 | - |
|
| 640 | - case 'mois': |
|
| 641 | - return sprintf('%02s', $mois); |
|
| 642 | - |
|
| 643 | - case 'jour': |
|
| 644 | - return $jour; |
|
| 645 | - |
|
| 646 | - case 'journum': |
|
| 647 | - return $journum; |
|
| 648 | - |
|
| 649 | - case 'nom_jour': |
|
| 650 | - if (!$mois or !$njour) { |
|
| 651 | - return ''; |
|
| 652 | - } |
|
| 653 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 654 | - $nom = 1 + (int) date('w', $nom); |
|
| 655 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 656 | - |
|
| 657 | - return _T('date_jour_' . $nom . $param); |
|
| 658 | - |
|
| 659 | - case 'mois_annee': |
|
| 660 | - if ($avjc) { |
|
| 661 | - return $annee; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 665 | - |
|
| 666 | - case 'annee': |
|
| 667 | - return $annee; |
|
| 668 | - |
|
| 669 | - // Cas d'une vue non definie : retomber sur le format |
|
| 670 | - // de date propose par http://www.php.net/date |
|
| 671 | - default: |
|
| 672 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 673 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 674 | - $time = strtotime($numdate); |
|
| 675 | - } |
|
| 676 | - return date($vue, $time); |
|
| 677 | - } |
|
| 510 | + if (is_string($options)) { |
|
| 511 | + $options = ['param' => $options]; |
|
| 512 | + } |
|
| 513 | + $date_array = recup_date($numdate, false); |
|
| 514 | + if (!$date_array) { |
|
| 515 | + return ''; |
|
| 516 | + } |
|
| 517 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 518 | + |
|
| 519 | + // 1er, 21st, etc. |
|
| 520 | + $journum = $jour; |
|
| 521 | + |
|
| 522 | + if ($jour == 0) { |
|
| 523 | + $jour = ''; |
|
| 524 | + $njour = 0; |
|
| 525 | + } else { |
|
| 526 | + $njour = intval($jour); |
|
| 527 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 528 | + $jour = $jourth; |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $mois = intval($mois); |
|
| 533 | + if ($mois > 0 and $mois < 13) { |
|
| 534 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 535 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 536 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 537 | + if ($jour) { |
|
| 538 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 539 | + } else { |
|
| 540 | + $jourmois = $nommois; |
|
| 541 | + } |
|
| 542 | + } else { |
|
| 543 | + $nommois = ''; |
|
| 544 | + $jourmois = ''; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($annee < 0) { |
|
| 548 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 549 | + $avjc = true; |
|
| 550 | + } else { |
|
| 551 | + $avjc = false; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + switch ($vue) { |
|
| 555 | + case 'saison': |
|
| 556 | + case 'saison_annee': |
|
| 557 | + $saison = ''; |
|
| 558 | + if ($mois > 0) { |
|
| 559 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 560 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 561 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 562 | + } |
|
| 563 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 564 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 565 | + } |
|
| 566 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 567 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 568 | + } |
|
| 569 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 570 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + if ($vue == 'saison') { |
|
| 574 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 575 | + } else { |
|
| 576 | + return $saison ? trim(_T( |
|
| 577 | + 'date_fmt_saison_annee', |
|
| 578 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 579 | + )) : ''; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + case 'court': |
|
| 583 | + if ($avjc) { |
|
| 584 | + return $annee; |
|
| 585 | + } |
|
| 586 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 587 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 588 | + return $annee; |
|
| 589 | + } |
|
| 590 | + if ($annee != $a) { |
|
| 591 | + return _T( |
|
| 592 | + 'date_fmt_mois_annee', |
|
| 593 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return _T( |
|
| 598 | + 'date_fmt_jour_mois', |
|
| 599 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 600 | + ); |
|
| 601 | + |
|
| 602 | + case 'jourcourt': |
|
| 603 | + if ($avjc) { |
|
| 604 | + return $annee; |
|
| 605 | + } |
|
| 606 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 607 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 608 | + return $annee; |
|
| 609 | + } |
|
| 610 | + if ($annee != $a) { |
|
| 611 | + return _T( |
|
| 612 | + 'date_fmt_jour_mois_annee', |
|
| 613 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 614 | + ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return _T( |
|
| 618 | + 'date_fmt_jour_mois', |
|
| 619 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 620 | + ); |
|
| 621 | + |
|
| 622 | + case 'entier': |
|
| 623 | + if ($avjc) { |
|
| 624 | + return $annee; |
|
| 625 | + } |
|
| 626 | + if ($jour) { |
|
| 627 | + return _T( |
|
| 628 | + 'date_fmt_jour_mois_annee', |
|
| 629 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 630 | + ); |
|
| 631 | + } elseif ($mois) { |
|
| 632 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 633 | + } else { |
|
| 634 | + return $annee; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + case 'nom_mois': |
|
| 638 | + return $nommois; |
|
| 639 | + |
|
| 640 | + case 'mois': |
|
| 641 | + return sprintf('%02s', $mois); |
|
| 642 | + |
|
| 643 | + case 'jour': |
|
| 644 | + return $jour; |
|
| 645 | + |
|
| 646 | + case 'journum': |
|
| 647 | + return $journum; |
|
| 648 | + |
|
| 649 | + case 'nom_jour': |
|
| 650 | + if (!$mois or !$njour) { |
|
| 651 | + return ''; |
|
| 652 | + } |
|
| 653 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 654 | + $nom = 1 + (int) date('w', $nom); |
|
| 655 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 656 | + |
|
| 657 | + return _T('date_jour_' . $nom . $param); |
|
| 658 | + |
|
| 659 | + case 'mois_annee': |
|
| 660 | + if ($avjc) { |
|
| 661 | + return $annee; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 665 | + |
|
| 666 | + case 'annee': |
|
| 667 | + return $annee; |
|
| 668 | + |
|
| 669 | + // Cas d'une vue non definie : retomber sur le format |
|
| 670 | + // de date propose par http://www.php.net/date |
|
| 671 | + default: |
|
| 672 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 673 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 674 | + $time = strtotime($numdate); |
|
| 675 | + } |
|
| 676 | + return date($vue, $time); |
|
| 677 | + } |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | |
@@ -701,11 +701,11 @@ discard block |
||
| 701 | 701 | * Nom du jour |
| 702 | 702 | **/ |
| 703 | 703 | function nom_jour($numdate, $forme = ''): string { |
| 704 | - if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 705 | - $forme = ''; |
|
| 706 | - } |
|
| 704 | + if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 705 | + $forme = ''; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 708 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | * Numéro du jour |
| 728 | 728 | **/ |
| 729 | 729 | function jour($numdate): string { |
| 730 | - return affdate_base($numdate, 'jour'); |
|
| 730 | + return affdate_base($numdate, 'jour'); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | * Numéro du jour |
| 746 | 746 | **/ |
| 747 | 747 | function journum($numdate): string { |
| 748 | - return affdate_base($numdate, 'journum'); |
|
| 748 | + return affdate_base($numdate, 'journum'); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | * Numéro du mois (sur 2 chiffres) |
| 764 | 764 | **/ |
| 765 | 765 | function mois($numdate): string { |
| 766 | - return affdate_base($numdate, 'mois'); |
|
| 766 | + return affdate_base($numdate, 'mois'); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /** |
@@ -787,11 +787,11 @@ discard block |
||
| 787 | 787 | * Nom du mois |
| 788 | 788 | **/ |
| 789 | 789 | function nom_mois($numdate, $forme = ''): string { |
| 790 | - if (!($forme === 'abbr')) { |
|
| 791 | - $forme = ''; |
|
| 792 | - } |
|
| 790 | + if (!($forme === 'abbr')) { |
|
| 791 | + $forme = ''; |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 794 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | /** |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * Année (sur 4 chiffres) |
| 810 | 810 | **/ |
| 811 | 811 | function annee($numdate): string { |
| 812 | - return affdate_base($numdate, 'annee'); |
|
| 812 | + return affdate_base($numdate, 'annee'); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -839,11 +839,11 @@ discard block |
||
| 839 | 839 | * La date formatée |
| 840 | 840 | **/ |
| 841 | 841 | function saison($numdate, $hemisphere = 'nord'): string { |
| 842 | - if ($hemisphere !== 'sud') { |
|
| 843 | - $hemisphere = 'nord'; |
|
| 844 | - } |
|
| 842 | + if ($hemisphere !== 'sud') { |
|
| 843 | + $hemisphere = 'nord'; |
|
| 844 | + } |
|
| 845 | 845 | |
| 846 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 846 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | |
@@ -872,11 +872,11 @@ discard block |
||
| 872 | 872 | * La date formatée |
| 873 | 873 | **/ |
| 874 | 874 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 875 | - if ($hemisphere !== 'sud') { |
|
| 876 | - $hemisphere = 'nord'; |
|
| 877 | - } |
|
| 875 | + if ($hemisphere !== 'sud') { |
|
| 876 | + $hemisphere = 'nord'; |
|
| 877 | + } |
|
| 878 | 878 | |
| 879 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 879 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | * La date formatée |
| 905 | 905 | **/ |
| 906 | 906 | function affdate($numdate, $format = 'entier'): string { |
| 907 | - return affdate_base($numdate, $format); |
|
| 907 | + return affdate_base($numdate, $format); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | * La date formatée |
| 932 | 932 | **/ |
| 933 | 933 | function affdate_court($numdate, $annee_courante = null): string { |
| 934 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 934 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | * La date formatée |
| 959 | 959 | **/ |
| 960 | 960 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 961 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 961 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | * La date formatée |
| 977 | 977 | **/ |
| 978 | 978 | function affdate_mois_annee($numdate): string { |
| 979 | - return affdate_base($numdate, 'mois_annee'); |
|
| 979 | + return affdate_base($numdate, 'mois_annee'); |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | /** |
@@ -994,16 +994,16 @@ discard block |
||
| 994 | 994 | * La date formatée, sinon '' |
| 995 | 995 | **/ |
| 996 | 996 | function affdate_heure($numdate): string { |
| 997 | - $date_array = recup_date($numdate); |
|
| 998 | - if (!$date_array) { |
|
| 999 | - return ''; |
|
| 1000 | - } |
|
| 1001 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1002 | - |
|
| 1003 | - return _T('date_fmt_jour_heure', [ |
|
| 1004 | - 'jour' => affdate($numdate), |
|
| 1005 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1006 | - ]); |
|
| 997 | + $date_array = recup_date($numdate); |
|
| 998 | + if (!$date_array) { |
|
| 999 | + return ''; |
|
| 1000 | + } |
|
| 1001 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1002 | + |
|
| 1003 | + return _T('date_fmt_jour_heure', [ |
|
| 1004 | + 'jour' => affdate($numdate), |
|
| 1005 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1006 | + ]); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1035,117 +1035,117 @@ discard block |
||
| 1035 | 1035 | * texte de la date |
| 1036 | 1036 | */ |
| 1037 | 1037 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1038 | - $abbr = $jour = ''; |
|
| 1039 | - $affdate = 'affdate_jourcourt'; |
|
| 1040 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1041 | - $abbr = 'abbr'; |
|
| 1042 | - } |
|
| 1043 | - if (strpos($forme, 'annee') !== false) { |
|
| 1044 | - $affdate = 'affdate'; |
|
| 1045 | - } |
|
| 1046 | - if (strpos($forme, 'jour') !== false) { |
|
| 1047 | - $jour = 'jour'; |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1051 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1052 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1053 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1054 | - $dtabbr = '</abbr>'; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - $date_debut = strtotime($date_debut); |
|
| 1058 | - $date_fin = strtotime($date_fin); |
|
| 1059 | - $d = date('Y-m-d', $date_debut); |
|
| 1060 | - $f = date('Y-m-d', $date_fin); |
|
| 1061 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1062 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1063 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1064 | - |
|
| 1065 | - if ($d == $f) { // meme jour |
|
| 1066 | - $nomjour = nom_jour($d, $abbr); |
|
| 1067 | - $s = $affdate($d); |
|
| 1068 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1069 | - if ($h) { |
|
| 1070 | - if ($hd == $hf) { |
|
| 1071 | - // Lundi 20 fevrier a 18h25 |
|
| 1072 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1073 | - $s = "$dtstart$s$dtabbr"; |
|
| 1074 | - } else { |
|
| 1075 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1076 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1077 | - $s = _T( |
|
| 1078 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1079 | - [ |
|
| 1080 | - 'jour' => spip_ucfirst($s), |
|
| 1081 | - 'heure_debut' => $hd, |
|
| 1082 | - 'heure_fin' => $hf, |
|
| 1083 | - 'dtstart' => $dtstart, |
|
| 1084 | - 'dtend' => $dtend, |
|
| 1085 | - 'dtabbr' => $dtabbr |
|
| 1086 | - ], |
|
| 1087 | - [ |
|
| 1088 | - 'sanitize' => false |
|
| 1089 | - ] |
|
| 1090 | - ); |
|
| 1091 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1092 | - else { |
|
| 1093 | - $s = spip_ucfirst(_T( |
|
| 1094 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1095 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1096 | - )); |
|
| 1097 | - } |
|
| 1098 | - } |
|
| 1099 | - } else { |
|
| 1100 | - if ($dtabbr && $dtstart) { |
|
| 1101 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1102 | - } else { |
|
| 1103 | - $s = spip_ucfirst($s); |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1106 | - } else { |
|
| 1107 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1108 | - if (!$h) { |
|
| 1109 | - $date_debut = jour($d); |
|
| 1110 | - } else { |
|
| 1111 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1112 | - } |
|
| 1113 | - $date_fin = $affdate($f); |
|
| 1114 | - if ($jour) { |
|
| 1115 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1116 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1117 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1118 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1119 | - } |
|
| 1120 | - if ($h) { |
|
| 1121 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1122 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1123 | - } |
|
| 1124 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1125 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1126 | - |
|
| 1127 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1128 | - } else { |
|
| 1129 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1130 | - $date_fin = $affdate($f); |
|
| 1131 | - if ($jour) { |
|
| 1132 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1133 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1134 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1135 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1136 | - } |
|
| 1137 | - if ($h) { |
|
| 1138 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1139 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1143 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1144 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - return $s; |
|
| 1038 | + $abbr = $jour = ''; |
|
| 1039 | + $affdate = 'affdate_jourcourt'; |
|
| 1040 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1041 | + $abbr = 'abbr'; |
|
| 1042 | + } |
|
| 1043 | + if (strpos($forme, 'annee') !== false) { |
|
| 1044 | + $affdate = 'affdate'; |
|
| 1045 | + } |
|
| 1046 | + if (strpos($forme, 'jour') !== false) { |
|
| 1047 | + $jour = 'jour'; |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1051 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1052 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1053 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1054 | + $dtabbr = '</abbr>'; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + $date_debut = strtotime($date_debut); |
|
| 1058 | + $date_fin = strtotime($date_fin); |
|
| 1059 | + $d = date('Y-m-d', $date_debut); |
|
| 1060 | + $f = date('Y-m-d', $date_fin); |
|
| 1061 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1062 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1063 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1064 | + |
|
| 1065 | + if ($d == $f) { // meme jour |
|
| 1066 | + $nomjour = nom_jour($d, $abbr); |
|
| 1067 | + $s = $affdate($d); |
|
| 1068 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1069 | + if ($h) { |
|
| 1070 | + if ($hd == $hf) { |
|
| 1071 | + // Lundi 20 fevrier a 18h25 |
|
| 1072 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1073 | + $s = "$dtstart$s$dtabbr"; |
|
| 1074 | + } else { |
|
| 1075 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1076 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1077 | + $s = _T( |
|
| 1078 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1079 | + [ |
|
| 1080 | + 'jour' => spip_ucfirst($s), |
|
| 1081 | + 'heure_debut' => $hd, |
|
| 1082 | + 'heure_fin' => $hf, |
|
| 1083 | + 'dtstart' => $dtstart, |
|
| 1084 | + 'dtend' => $dtend, |
|
| 1085 | + 'dtabbr' => $dtabbr |
|
| 1086 | + ], |
|
| 1087 | + [ |
|
| 1088 | + 'sanitize' => false |
|
| 1089 | + ] |
|
| 1090 | + ); |
|
| 1091 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1092 | + else { |
|
| 1093 | + $s = spip_ucfirst(_T( |
|
| 1094 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1095 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1096 | + )); |
|
| 1097 | + } |
|
| 1098 | + } |
|
| 1099 | + } else { |
|
| 1100 | + if ($dtabbr && $dtstart) { |
|
| 1101 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1102 | + } else { |
|
| 1103 | + $s = spip_ucfirst($s); |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | + } else { |
|
| 1107 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1108 | + if (!$h) { |
|
| 1109 | + $date_debut = jour($d); |
|
| 1110 | + } else { |
|
| 1111 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1112 | + } |
|
| 1113 | + $date_fin = $affdate($f); |
|
| 1114 | + if ($jour) { |
|
| 1115 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1116 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1117 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1118 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1119 | + } |
|
| 1120 | + if ($h) { |
|
| 1121 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1122 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1123 | + } |
|
| 1124 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1125 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1126 | + |
|
| 1127 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1128 | + } else { |
|
| 1129 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1130 | + $date_fin = $affdate($f); |
|
| 1131 | + if ($jour) { |
|
| 1132 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1133 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1134 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1135 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1136 | + } |
|
| 1137 | + if ($h) { |
|
| 1138 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1139 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1143 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1144 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + return $s; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1166,10 +1166,10 @@ discard block |
||
| 1166 | 1166 | * Date au format ical |
| 1167 | 1167 | **/ |
| 1168 | 1168 | function date_ical($date, $addminutes = 0): string { |
| 1169 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1170 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1169 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1170 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1171 | 1171 | |
| 1172 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1172 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | |
@@ -1193,14 +1193,14 @@ discard block |
||
| 1193 | 1193 | * La date formatée |
| 1194 | 1194 | **/ |
| 1195 | 1195 | function date_iso($date_heure): string { |
| 1196 | - $date = recup_date($date_heure); |
|
| 1197 | - $annee = $date[0] ?? null; |
|
| 1198 | - $mois = $date[1] ?? null; |
|
| 1199 | - $jour = $date[2] ?? null; |
|
| 1200 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1201 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1202 | - |
|
| 1203 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1196 | + $date = recup_date($date_heure); |
|
| 1197 | + $annee = $date[0] ?? null; |
|
| 1198 | + $mois = $date[1] ?? null; |
|
| 1199 | + $jour = $date[2] ?? null; |
|
| 1200 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1201 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1202 | + |
|
| 1203 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | /** |
@@ -1223,11 +1223,11 @@ discard block |
||
| 1223 | 1223 | * La date formatée |
| 1224 | 1224 | **/ |
| 1225 | 1225 | function date_822($date_heure): string { |
| 1226 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1227 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1228 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1226 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1227 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1228 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1229 | 1229 | |
| 1230 | - return date('r', $time); |
|
| 1230 | + return date('r', $time); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | /** |
@@ -1243,11 +1243,11 @@ discard block |
||
| 1243 | 1243 | * Date au format `Ymd` |
| 1244 | 1244 | **/ |
| 1245 | 1245 | function date_anneemoisjour($d): string { |
| 1246 | - if (!$d) { |
|
| 1247 | - $d = date('Y-m-d'); |
|
| 1248 | - } |
|
| 1246 | + if (!$d) { |
|
| 1247 | + $d = date('Y-m-d'); |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1250 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | /** |
@@ -1263,11 +1263,11 @@ discard block |
||
| 1263 | 1263 | * Date au format `Ym` |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function date_anneemois($d): string { |
| 1266 | - if (!$d) { |
|
| 1267 | - $d = date('Y-m-d'); |
|
| 1268 | - } |
|
| 1266 | + if (!$d) { |
|
| 1267 | + $d = date('Y-m-d'); |
|
| 1268 | + } |
|
| 1269 | 1269 | |
| 1270 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1270 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | /** |
@@ -1283,13 +1283,13 @@ discard block |
||
| 1283 | 1283 | * Date au lundi de la même semaine au format `Ymd` |
| 1284 | 1284 | **/ |
| 1285 | 1285 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1286 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1287 | - if ($w_day == 0) { |
|
| 1288 | - $w_day = 7; |
|
| 1289 | - } // Gaffe: le dimanche est zero |
|
| 1290 | - $debut = $jour - $w_day + 1; |
|
| 1286 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1287 | + if ($w_day == 0) { |
|
| 1288 | + $w_day = 7; |
|
| 1289 | + } // Gaffe: le dimanche est zero |
|
| 1290 | + $debut = $jour - $w_day + 1; |
|
| 1291 | 1291 | |
| 1292 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1292 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | /** |
@@ -1305,11 +1305,11 @@ discard block |
||
| 1305 | 1305 | * Date au dimanche de la même semaine au format `Ymd` |
| 1306 | 1306 | **/ |
| 1307 | 1307 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1308 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1309 | - if ($w_day == 0) { |
|
| 1310 | - $w_day = 7; |
|
| 1311 | - } // Gaffe: le dimanche est zero |
|
| 1312 | - $debut = $jour - $w_day + 1; |
|
| 1308 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1309 | + if ($w_day == 0) { |
|
| 1310 | + $w_day = 7; |
|
| 1311 | + } // Gaffe: le dimanche est zero |
|
| 1312 | + $debut = $jour - $w_day + 1; |
|
| 1313 | 1313 | |
| 1314 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1314 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1315 | 1315 | } |
@@ -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'); |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | * Environnement du formulaire |
| 48 | 48 | **/ |
| 49 | 49 | function formulaires_editer_rubrique_charger_dist( |
| 50 | - $id_rubrique = 'new', |
|
| 51 | - $id_parent = 0, |
|
| 52 | - $retour = '', |
|
| 53 | - $lier_trad = 0, |
|
| 54 | - $config_fonc = 'rubriques_edit_config', |
|
| 55 | - $row = [], |
|
| 56 | - $hidden = '' |
|
| 50 | + $id_rubrique = 'new', |
|
| 51 | + $id_parent = 0, |
|
| 52 | + $retour = '', |
|
| 53 | + $lier_trad = 0, |
|
| 54 | + $config_fonc = 'rubriques_edit_config', |
|
| 55 | + $row = [], |
|
| 56 | + $hidden = '' |
|
| 57 | 57 | ) { |
| 58 | - $valeurs = formulaires_editer_objet_charger( |
|
| 59 | - 'rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - $id_parent, |
|
| 62 | - $lier_trad, |
|
| 63 | - $retour, |
|
| 64 | - $config_fonc, |
|
| 65 | - $row, |
|
| 66 | - $hidden |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | - $valeurs['editable'] = ''; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $valeurs; |
|
| 58 | + $valeurs = formulaires_editer_objet_charger( |
|
| 59 | + 'rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + $id_parent, |
|
| 62 | + $lier_trad, |
|
| 63 | + $retour, |
|
| 64 | + $config_fonc, |
|
| 65 | + $row, |
|
| 66 | + $hidden |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | + $valeurs['editable'] = ''; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $valeurs; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | function rubriques_edit_config(array $row): array { |
| 85 | 85 | |
| 86 | - $config = []; |
|
| 87 | - $config['lignes'] = 8; |
|
| 88 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | - $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 86 | + $config = []; |
|
| 87 | + $config['lignes'] = 8; |
|
| 88 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | + $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 90 | 90 | |
| 91 | - return $config; |
|
| 91 | + return $config; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | * Hash du formulaire |
| 114 | 114 | */ |
| 115 | 115 | function formulaires_editer_rubrique_identifier_dist( |
| 116 | - $id_rubrique = 'new', |
|
| 117 | - $id_parent = 0, |
|
| 118 | - $retour = '', |
|
| 119 | - $lier_trad = 0, |
|
| 120 | - $config_fonc = 'rubriques_edit_config', |
|
| 121 | - $row = [], |
|
| 122 | - $hidden = '' |
|
| 116 | + $id_rubrique = 'new', |
|
| 117 | + $id_parent = 0, |
|
| 118 | + $retour = '', |
|
| 119 | + $lier_trad = 0, |
|
| 120 | + $config_fonc = 'rubriques_edit_config', |
|
| 121 | + $row = [], |
|
| 122 | + $hidden = '' |
|
| 123 | 123 | ) { |
| 124 | - return serialize([intval($id_rubrique), $lier_trad]); |
|
| 124 | + return serialize([intval($id_rubrique), $lier_trad]); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -147,34 +147,34 @@ discard block |
||
| 147 | 147 | * Erreurs du formulaire |
| 148 | 148 | **/ |
| 149 | 149 | function formulaires_editer_rubrique_verifier_dist( |
| 150 | - $id_rubrique = 'new', |
|
| 151 | - $id_parent = 0, |
|
| 152 | - $retour = '', |
|
| 153 | - $lier_trad = 0, |
|
| 154 | - $config_fonc = 'rubriques_edit_config', |
|
| 155 | - $row = [], |
|
| 156 | - $hidden = '' |
|
| 150 | + $id_rubrique = 'new', |
|
| 151 | + $id_parent = 0, |
|
| 152 | + $retour = '', |
|
| 153 | + $lier_trad = 0, |
|
| 154 | + $config_fonc = 'rubriques_edit_config', |
|
| 155 | + $row = [], |
|
| 156 | + $hidden = '' |
|
| 157 | 157 | ) { |
| 158 | - // auto-renseigner le titre si il n'existe pas |
|
| 159 | - titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | - $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | - |
|
| 163 | - // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | - if ( |
|
| 165 | - intval($id_rubrique) |
|
| 166 | - and empty($erreurs['id_parent']) |
|
| 167 | - and $id_parent = _request('id_parent') |
|
| 168 | - ) { |
|
| 169 | - include_spip('inc/rubriques'); |
|
| 170 | - $branche = calcul_branche_in($id_rubrique); |
|
| 171 | - $branche = explode(',', $branche); |
|
| 172 | - if (in_array($id_parent, $branche)) { |
|
| 173 | - $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $erreurs; |
|
| 158 | + // auto-renseigner le titre si il n'existe pas |
|
| 159 | + titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | + $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | + |
|
| 163 | + // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | + if ( |
|
| 165 | + intval($id_rubrique) |
|
| 166 | + and empty($erreurs['id_parent']) |
|
| 167 | + and $id_parent = _request('id_parent') |
|
| 168 | + ) { |
|
| 169 | + include_spip('inc/rubriques'); |
|
| 170 | + $branche = calcul_branche_in($id_rubrique); |
|
| 171 | + $branche = explode(',', $branche); |
|
| 172 | + if (in_array($id_parent, $branche)) { |
|
| 173 | + $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $erreurs; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -200,22 +200,22 @@ discard block |
||
| 200 | 200 | * Retour des traitements |
| 201 | 201 | **/ |
| 202 | 202 | function formulaires_editer_rubrique_traiter_dist( |
| 203 | - $id_rubrique = 'new', |
|
| 204 | - $id_parent = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $lier_trad = 0, |
|
| 207 | - $config_fonc = 'rubriques_edit_config', |
|
| 208 | - $row = [], |
|
| 209 | - $hidden = '' |
|
| 203 | + $id_rubrique = 'new', |
|
| 204 | + $id_parent = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $lier_trad = 0, |
|
| 207 | + $config_fonc = 'rubriques_edit_config', |
|
| 208 | + $row = [], |
|
| 209 | + $hidden = '' |
|
| 210 | 210 | ) { |
| 211 | - return formulaires_editer_objet_traiter( |
|
| 212 | - 'rubrique', |
|
| 213 | - $id_rubrique, |
|
| 214 | - $id_parent, |
|
| 215 | - $lier_trad, |
|
| 216 | - $retour, |
|
| 217 | - $config_fonc, |
|
| 218 | - $row, |
|
| 219 | - $hidden |
|
| 220 | - ); |
|
| 211 | + return formulaires_editer_objet_traiter( |
|
| 212 | + 'rubrique', |
|
| 213 | + $id_rubrique, |
|
| 214 | + $id_parent, |
|
| 215 | + $lier_trad, |
|
| 216 | + $retour, |
|
| 217 | + $config_fonc, |
|
| 218 | + $row, |
|
| 219 | + $hidden |
|
| 220 | + ); |
|
| 221 | 221 | } |
@@ -31,7 +31,7 @@ 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()); |
|
| 34 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 35 | 35 | |
| 36 | 36 | mt_srand($seed); |
| 37 | 37 | $s = ''; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | if (!$s) { |
| 43 | 43 | $s = random_int(0, mt_getrandmax()); |
| 44 | 44 | } |
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 46 | 46 | } |
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 48 | 48 | $x = $r['r'] & 63; |
| 49 | 49 | if ($x < 10) { |
| 50 | 50 | $x = chr($x + 48); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | static $seeded; |
| 83 | 83 | |
| 84 | 84 | if (!$seeded) { |
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 86 | 86 | mt_srand($seed); |
| 87 | 87 | $seeded = true; |
| 88 | 88 | } |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
| 169 | 169 | } |
| 170 | 170 | } else { |
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 172 | 172 | if (!$low_sec) { |
| 173 | 173 | $low_sec = creer_pass_aleatoire(); |
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.intval($id_auteur)); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | 230 | $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
| 231 | 231 | $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | 234 | return generer_url_api($script, $path, $args, $no_entities = false, $public); |
| 235 | 235 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | foreach ($args as $val => $var) { |
| 254 | 254 | if ($var) { |
| 255 | 255 | if ($val <> 'statut') { |
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 256 | + $a .= ':'.$val.'-'.$var; |
|
| 257 | 257 | } |
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 258 | + $b .= $val.'='.$var.'&'; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | $a = substr($a, 1); |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | if (!$id_auteur = intval($id_auteur)) { |
| 317 | 317 | return; |
| 318 | 318 | } // jamais trop prudent ;) |
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 337 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 339 | 339 | |
| 340 | 340 | // Cette variable de configuration peut etre posee par un plugin |
| 341 | 341 | // par exemple acces_restreint ; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | and !@file_exists($htaccess) |
| 347 | 347 | ) { |
| 348 | 348 | spip_unlink($htpasswd); |
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 349 | + spip_unlink($htpasswd.'-admin'); |
|
| 350 | 350 | return; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | $pwd_all = ''; // login:htpass pour tous |
| 375 | 375 | $pwd_admin = ''; // login:htpass pour les admins |
| 376 | 376 | |
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | 378 | while ($row = sql_fetch($res)) { |
| 379 | 379 | if (strlen($row['login']) and strlen($row['htpass'])) { |
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | + $ligne = $row['login'].':'.$row['htpass']."\n"; |
|
| 381 | 381 | $pwd_all .= $ligne; |
| 382 | 382 | if ($row['statut'] == '0minirezo') { |
| 383 | 383 | $pwd_admin .= $ligne; |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 424 | 424 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 425 | 425 | return true; |
| 426 | 426 | } |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | fputs($ht, $deny); |
| 450 | 450 | fclose($ht); |
| 451 | 451 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 453 | 453 | if ($ht = @fopen($t, 'w')) { |
| 454 | 454 | @fclose($ht); |
| 455 | 455 | include_spip('inc/distant'); |
| 456 | 456 | $t = substr($t, strlen(_DIR_RACINE)); |
| 457 | - $t = url_de_base() . $t; |
|
| 457 | + $t = url_de_base().$t; |
|
| 458 | 458 | $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
| 459 | 459 | $ht = ($ht['status'] ?? null) === 403; |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 463 | 463 | |
| 464 | 464 | return $ht; |
| 465 | 465 | } |
@@ -485,11 +485,11 @@ discard block |
||
| 485 | 485 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 486 | 486 | $dirs[] = ['extension' => 'distant']; |
| 487 | 487 | foreach ($dirs as $e) { |
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 489 | 489 | if ($f) { |
| 490 | 490 | verifier_htaccess($dir); |
| 491 | 491 | } else { |
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -30,46 +30,46 @@ discard block |
||
| 30 | 30 | * Mot de passe |
| 31 | 31 | **/ |
| 32 | 32 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 33 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | - |
|
| 35 | - mt_srand($seed); |
|
| 36 | - $s = ''; |
|
| 37 | - $pass = ''; |
|
| 38 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 39 | - if (!$s) { |
|
| 40 | - $s = random_int(0, mt_getrandmax()); |
|
| 41 | - if (!$s) { |
|
| 42 | - $s = random_int(0, mt_getrandmax()); |
|
| 43 | - } |
|
| 44 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | - } |
|
| 46 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | - $x = $r['r'] & 63; |
|
| 48 | - if ($x < 10) { |
|
| 49 | - $x = chr($x + 48); |
|
| 50 | - } else { |
|
| 51 | - if ($x < 36) { |
|
| 52 | - $x = chr($x + 55); |
|
| 53 | - } else { |
|
| 54 | - if ($x < 62) { |
|
| 55 | - $x = chr($x + 61); |
|
| 56 | - } else { |
|
| 57 | - if ($x == 63) { |
|
| 58 | - $x = '/'; |
|
| 59 | - } else { |
|
| 60 | - $x = '.'; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - $pass .= $x; |
|
| 66 | - $s = substr($s, 2); |
|
| 67 | - } |
|
| 68 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 69 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 70 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 71 | - |
|
| 72 | - return $pass; |
|
| 33 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + |
|
| 35 | + mt_srand($seed); |
|
| 36 | + $s = ''; |
|
| 37 | + $pass = ''; |
|
| 38 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 39 | + if (!$s) { |
|
| 40 | + $s = random_int(0, mt_getrandmax()); |
|
| 41 | + if (!$s) { |
|
| 42 | + $s = random_int(0, mt_getrandmax()); |
|
| 43 | + } |
|
| 44 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + } |
|
| 46 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $x = $r['r'] & 63; |
|
| 48 | + if ($x < 10) { |
|
| 49 | + $x = chr($x + 48); |
|
| 50 | + } else { |
|
| 51 | + if ($x < 36) { |
|
| 52 | + $x = chr($x + 55); |
|
| 53 | + } else { |
|
| 54 | + if ($x < 62) { |
|
| 55 | + $x = chr($x + 61); |
|
| 56 | + } else { |
|
| 57 | + if ($x == 63) { |
|
| 58 | + $x = '/'; |
|
| 59 | + } else { |
|
| 60 | + $x = '.'; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + $pass .= $x; |
|
| 66 | + $s = substr($s, 2); |
|
| 67 | + } |
|
| 68 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 69 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 70 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 71 | + |
|
| 72 | + return $pass; |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | * @return string Identifiant |
| 79 | 79 | */ |
| 80 | 80 | function creer_uniqid() { |
| 81 | - static $seeded; |
|
| 81 | + static $seeded; |
|
| 82 | 82 | |
| 83 | - if (!$seeded) { |
|
| 84 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | - mt_srand($seed); |
|
| 86 | - $seeded = true; |
|
| 87 | - } |
|
| 83 | + if (!$seeded) { |
|
| 84 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | + mt_srand($seed); |
|
| 86 | + $seeded = true; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - $s = random_int(0, mt_getrandmax()); |
|
| 90 | - if (!$s) { |
|
| 91 | - $s = random_int(0, mt_getrandmax()); |
|
| 92 | - } |
|
| 89 | + $s = random_int(0, mt_getrandmax()); |
|
| 90 | + if (!$s) { |
|
| 91 | + $s = random_int(0, mt_getrandmax()); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - return uniqid($s, 1); |
|
| 94 | + return uniqid($s, 1); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -105,42 +105,42 @@ discard block |
||
| 105 | 105 | * @return string Retourne l'alea éphemère actuel au passage |
| 106 | 106 | */ |
| 107 | 107 | function charger_aleas() { |
| 108 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 109 | - include_spip('base/abstract_sql'); |
|
| 110 | - $aleas = sql_allfetsel( |
|
| 111 | - ['nom', 'valeur'], |
|
| 112 | - 'spip_meta', |
|
| 113 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 114 | - '', |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - 'continue' |
|
| 120 | - ); |
|
| 121 | - if ($aleas) { |
|
| 122 | - foreach ($aleas as $a) { |
|
| 123 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 124 | - } |
|
| 125 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 126 | - } else { |
|
| 127 | - spip_log('aleas indisponibles', 'session'); |
|
| 128 | - return ''; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 108 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 109 | + include_spip('base/abstract_sql'); |
|
| 110 | + $aleas = sql_allfetsel( |
|
| 111 | + ['nom', 'valeur'], |
|
| 112 | + 'spip_meta', |
|
| 113 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 114 | + '', |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + 'continue' |
|
| 120 | + ); |
|
| 121 | + if ($aleas) { |
|
| 122 | + foreach ($aleas as $a) { |
|
| 123 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 124 | + } |
|
| 125 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 126 | + } else { |
|
| 127 | + spip_log('aleas indisponibles', 'session'); |
|
| 128 | + return ''; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 132 | 132 | } |
| 133 | 133 | |
| 134 | 134 | /** |
| 135 | 135 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 136 | 136 | **/ |
| 137 | 137 | function renouvelle_alea() { |
| 138 | - charger_aleas(); |
|
| 139 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 140 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 141 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 142 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 143 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 138 | + charger_aleas(); |
|
| 139 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 140 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 141 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 142 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 143 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | |
@@ -160,21 +160,21 @@ discard block |
||
| 160 | 160 | * Clé de sécurité. |
| 161 | 161 | **/ |
| 162 | 162 | function low_sec($id_auteur) { |
| 163 | - // Pas d'id_auteur : low_sec |
|
| 164 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 165 | - include_spip('inc/config'); |
|
| 166 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 167 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 168 | - } |
|
| 169 | - } else { |
|
| 170 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | - if (!$low_sec) { |
|
| 172 | - $low_sec = creer_pass_aleatoire(); |
|
| 173 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $low_sec; |
|
| 163 | + // Pas d'id_auteur : low_sec |
|
| 164 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 165 | + include_spip('inc/config'); |
|
| 166 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 167 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 168 | + } |
|
| 169 | + } else { |
|
| 170 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | + if (!$low_sec) { |
|
| 172 | + $low_sec = creer_pass_aleatoire(); |
|
| 173 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $low_sec; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @filtre |
| 208 | 208 | */ |
| 209 | 209 | function securiser_acces_low_sec($id_auteur, #[\SensitiveParameter] $cle, $dir, $op = '', $args = '') { |
| 210 | - if ($op) { |
|
| 211 | - $dir .= " $op $args"; |
|
| 212 | - } |
|
| 210 | + if ($op) { |
|
| 211 | + $dir .= " $op $args"; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 214 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -226,11 +226,11 @@ discard block |
||
| 226 | 226 | * @return string |
| 227 | 227 | */ |
| 228 | 228 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 229 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 230 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 231 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 229 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 230 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 231 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 232 | 232 | |
| 233 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 233 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | |
@@ -248,27 +248,27 @@ discard block |
||
| 248 | 248 | * @deprecated 4.1 |
| 249 | 249 | */ |
| 250 | 250 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 251 | - $a = $b = ''; |
|
| 252 | - foreach ($args as $val => $var) { |
|
| 253 | - if ($var) { |
|
| 254 | - if ($val <> 'statut') { |
|
| 255 | - $a .= ':' . $val . '-' . $var; |
|
| 256 | - } |
|
| 257 | - $b .= $val . '=' . $var . '&'; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - $a = substr($a, 1); |
|
| 261 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 262 | - |
|
| 263 | - return $b |
|
| 264 | - . 'op=' |
|
| 265 | - . $op |
|
| 266 | - . '&id=' |
|
| 267 | - . $id |
|
| 268 | - . '&cle=' |
|
| 269 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 270 | - . (!$a ? '' : "&args=$a") |
|
| 271 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 251 | + $a = $b = ''; |
|
| 252 | + foreach ($args as $val => $var) { |
|
| 253 | + if ($var) { |
|
| 254 | + if ($val <> 'statut') { |
|
| 255 | + $a .= ':' . $val . '-' . $var; |
|
| 256 | + } |
|
| 257 | + $b .= $val . '=' . $var . '&'; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + $a = substr($a, 1); |
|
| 261 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 262 | + |
|
| 263 | + return $b |
|
| 264 | + . 'op=' |
|
| 265 | + . $op |
|
| 266 | + . '&id=' |
|
| 267 | + . $id |
|
| 268 | + . '&cle=' |
|
| 269 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 270 | + . (!$a ? '' : "&args=$a") |
|
| 271 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | /** |
@@ -284,7 +284,7 @@ discard block |
||
| 284 | 284 | * Clé |
| 285 | 285 | **/ |
| 286 | 286 | function afficher_low_sec($id_auteur, $action = '') { |
| 287 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 287 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -302,7 +302,7 @@ discard block |
||
| 302 | 302 | * true si les clés corresponde, false sinon |
| 303 | 303 | **/ |
| 304 | 304 | function verifier_low_sec($id_auteur, #[\SensitiveParameter] $cle, $action = '') { |
| 305 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 305 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | /** |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | * Identifiant de l'auteur |
| 313 | 313 | **/ |
| 314 | 314 | function effacer_low_sec($id_auteur) { |
| 315 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 316 | - return; |
|
| 317 | - } // jamais trop prudent ;) |
|
| 318 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 315 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 316 | + return; |
|
| 317 | + } // jamais trop prudent ;) |
|
| 318 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | |
@@ -333,31 +333,31 @@ discard block |
||
| 333 | 333 | * - void sinon. |
| 334 | 334 | **/ |
| 335 | 335 | function ecrire_acces() { |
| 336 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 337 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 338 | - |
|
| 339 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 340 | - // par exemple acces_restreint ; |
|
| 341 | - // si .htaccess existe, outrepasser spip_meta |
|
| 342 | - if ( |
|
| 343 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 344 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 345 | - and !@file_exists($htaccess) |
|
| 346 | - ) { |
|
| 347 | - spip_unlink($htpasswd); |
|
| 348 | - spip_unlink($htpasswd . '-admin'); |
|
| 349 | - return; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 353 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 354 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 355 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 356 | - if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 357 | - return; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 336 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 337 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 338 | + |
|
| 339 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 340 | + // par exemple acces_restreint ; |
|
| 341 | + // si .htaccess existe, outrepasser spip_meta |
|
| 342 | + if ( |
|
| 343 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 344 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 345 | + and !@file_exists($htaccess) |
|
| 346 | + ) { |
|
| 347 | + spip_unlink($htpasswd); |
|
| 348 | + spip_unlink($htpasswd . '-admin'); |
|
| 349 | + return; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 353 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 354 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 355 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 356 | + if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 357 | + return; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -366,29 +366,29 @@ discard block |
||
| 366 | 366 | * @param $htpasswd_admin |
| 367 | 367 | */ |
| 368 | 368 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 369 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 370 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $pwd_all = ''; // login:htpass pour tous |
|
| 374 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 375 | - |
|
| 376 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | - while ($row = sql_fetch($res)) { |
|
| 378 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 379 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | - $pwd_all .= $ligne; |
|
| 381 | - if ($row['statut'] == '0minirezo') { |
|
| 382 | - $pwd_admin .= $ligne; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ($pwd_all) { |
|
| 388 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 389 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 390 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 391 | - } |
|
| 369 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 370 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $pwd_all = ''; // login:htpass pour tous |
|
| 374 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 375 | + |
|
| 376 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | + while ($row = sql_fetch($res)) { |
|
| 378 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 379 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | + $pwd_all .= $ligne; |
|
| 381 | + if ($row['statut'] == '0minirezo') { |
|
| 382 | + $pwd_admin .= $ligne; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ($pwd_all) { |
|
| 388 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 389 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 390 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | /** |
@@ -402,11 +402,11 @@ discard block |
||
| 402 | 402 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 403 | 403 | */ |
| 404 | 404 | function generer_htpass(#[\SensitiveParameter] $pass) { |
| 405 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 406 | - return $generer_htpass($pass); |
|
| 407 | - } |
|
| 405 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 406 | + return $generer_htpass($pass); |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | - return ''; |
|
| 409 | + return ''; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -419,14 +419,14 @@ discard block |
||
| 419 | 419 | * @return boolean |
| 420 | 420 | */ |
| 421 | 421 | function verifier_htaccess($rep, $force = false) { |
| 422 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 424 | - return true; |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - // directive deny compatible Apache 2.0+ |
|
| 428 | - $deny = |
|
| 429 | - '# Deny all requests from Apache 2.4+. |
|
| 422 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 424 | + return true; |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + // directive deny compatible Apache 2.0+ |
|
| 428 | + $deny = |
|
| 429 | + '# Deny all requests from Apache 2.4+. |
|
| 430 | 430 | <IfModule mod_authz_core.c> |
| 431 | 431 | Require all denied |
| 432 | 432 | </IfModule> |
@@ -435,32 +435,32 @@ discard block |
||
| 435 | 435 | Deny from all |
| 436 | 436 | </IfModule> |
| 437 | 437 | '; |
| 438 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 439 | - if ( |
|
| 440 | - function_exists('apache_get_version') |
|
| 441 | - and $v = apache_get_version() |
|
| 442 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 443 | - ) { |
|
| 444 | - $deny = "deny from all\n"; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 448 | - fputs($ht, $deny); |
|
| 449 | - fclose($ht); |
|
| 450 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 451 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | - if ($ht = @fopen($t, 'w')) { |
|
| 453 | - @fclose($ht); |
|
| 454 | - include_spip('inc/distant'); |
|
| 455 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 456 | - $t = url_de_base() . $t; |
|
| 457 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 458 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | - |
|
| 463 | - return $ht; |
|
| 438 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 439 | + if ( |
|
| 440 | + function_exists('apache_get_version') |
|
| 441 | + and $v = apache_get_version() |
|
| 442 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 443 | + ) { |
|
| 444 | + $deny = "deny from all\n"; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 448 | + fputs($ht, $deny); |
|
| 449 | + fclose($ht); |
|
| 450 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 451 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | + if ($ht = @fopen($t, 'w')) { |
|
| 453 | + @fclose($ht); |
|
| 454 | + include_spip('inc/distant'); |
|
| 455 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 456 | + $t = url_de_base() . $t; |
|
| 457 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 458 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | + |
|
| 463 | + return $ht; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | /** |
@@ -478,20 +478,20 @@ discard block |
||
| 478 | 478 | * Valeur de la configuration `creer_htaccess` |
| 479 | 479 | */ |
| 480 | 480 | function gerer_htaccess() { |
| 481 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 482 | - // par exemple acces_restreint |
|
| 483 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 484 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 485 | - $dirs[] = ['extension' => 'distant']; |
|
| 486 | - foreach ($dirs as $e) { |
|
| 487 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | - if ($f) { |
|
| 489 | - verifier_htaccess($dir); |
|
| 490 | - } else { |
|
| 491 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 481 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 482 | + // par exemple acces_restreint |
|
| 483 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 484 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 485 | + $dirs[] = ['extension' => 'distant']; |
|
| 486 | + foreach ($dirs as $e) { |
|
| 487 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | + if ($f) { |
|
| 489 | + verifier_htaccess($dir); |
|
| 490 | + } else { |
|
| 491 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 497 | 497 | } |