@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = [ |
|
| 47 | - 'field' => [ |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = [ |
|
| 47 | + 'field' => [ |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,522 +62,522 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** |
|
| 66 | - * tableau de donnees |
|
| 67 | - * |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - protected $tableau = []; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Conditions de filtrage |
|
| 74 | - * ie criteres de selection |
|
| 75 | - * |
|
| 76 | - * @var array |
|
| 77 | - */ |
|
| 78 | - protected $filtre = []; |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Cle courante |
|
| 83 | - * |
|
| 84 | - * @var null |
|
| 85 | - */ |
|
| 86 | - protected $cle = null; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * Valeur courante |
|
| 90 | - * |
|
| 91 | - * @var null |
|
| 92 | - */ |
|
| 93 | - protected $valeur = null; |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Erreur presente ? |
|
| 97 | - * |
|
| 98 | - * @var bool |
|
| 99 | - **/ |
|
| 100 | - public $err = false; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Calcul du total des elements |
|
| 104 | - * |
|
| 105 | - * @var int|null |
|
| 106 | - **/ |
|
| 107 | - public $total = null; |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Constructeur |
|
| 111 | - * |
|
| 112 | - * @param $command |
|
| 113 | - * @param array $info |
|
| 114 | - */ |
|
| 115 | - public function __construct($command, $info = []) { |
|
| 116 | - $this->type = 'DATA'; |
|
| 117 | - $this->command = $command; |
|
| 118 | - $this->info = $info; |
|
| 119 | - |
|
| 120 | - $this->select($command); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Revenir au depart |
|
| 125 | - * |
|
| 126 | - * @return void |
|
| 127 | - */ |
|
| 128 | - public function rewind(): void { |
|
| 129 | - reset($this->tableau); |
|
| 130 | - $this->cle = array_key_first($this->tableau); |
|
| 131 | - $this->valeur = current($this->tableau); |
|
| 132 | - next($this->tableau); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Déclarer les critères exceptions |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function exception_des_criteres() { |
|
| 141 | - return ['tableau']; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Récupérer depuis le cache si possible |
|
| 146 | - * |
|
| 147 | - * @param string $cle |
|
| 148 | - * @return mixed |
|
| 149 | - */ |
|
| 150 | - protected function cache_get($cle) { |
|
| 151 | - if (!$cle) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - # utiliser memoization si dispo |
|
| 155 | - if (!function_exists('cache_get')) { |
|
| 156 | - return; |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return cache_get($cle); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * Stocker en cache si possible |
|
| 164 | - * |
|
| 165 | - * @param string $cle |
|
| 166 | - * @param int $ttl |
|
| 167 | - * @param null|mixed $valeur |
|
| 168 | - * @return bool |
|
| 169 | - */ |
|
| 170 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | - if (!$cle) { |
|
| 172 | - return; |
|
| 173 | - } |
|
| 174 | - if (is_null($valeur)) { |
|
| 175 | - $valeur = $this->tableau; |
|
| 176 | - } |
|
| 177 | - # utiliser memoization si dispo |
|
| 178 | - if (!function_exists('cache_set')) { |
|
| 179 | - return; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - return cache_set( |
|
| 183 | - $cle, |
|
| 184 | - [ |
|
| 185 | - 'data' => $valeur, |
|
| 186 | - 'time' => time(), |
|
| 187 | - 'ttl' => $ttl |
|
| 188 | - ], |
|
| 189 | - 3600 + $ttl |
|
| 190 | - ); |
|
| 191 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - /** |
|
| 196 | - * Aller chercher les données de la boucle DATA |
|
| 197 | - * |
|
| 198 | - * @throws Exception |
|
| 199 | - * @param array $command |
|
| 200 | - * @return void |
|
| 201 | - */ |
|
| 202 | - protected function select($command) { |
|
| 203 | - |
|
| 204 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | - // le type se retrouve dans la commande 'from' |
|
| 206 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | - if (isset($this->command['from'][0])) { |
|
| 208 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | - } |
|
| 211 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | - // les commandes connues pour l'iterateur DATA |
|
| 216 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | - |
|
| 218 | - // {source format, [URL], [arg2]...} |
|
| 219 | - if ( |
|
| 220 | - isset($this->command['source']) |
|
| 221 | - and isset($this->command['sourcemode']) |
|
| 222 | - ) { |
|
| 223 | - $this->select_source(); |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - // Critere {liste X1, X2, X3} |
|
| 227 | - if (isset($this->command['liste'])) { |
|
| 228 | - $this->select_liste(); |
|
| 229 | - } |
|
| 230 | - if (isset($this->command['enum'])) { |
|
| 231 | - $this->select_enum(); |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | - if (!is_array($this->tableau)) { |
|
| 236 | - $this->err = true; |
|
| 237 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // {datapath query.results} |
|
| 241 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | - if ( |
|
| 243 | - !$this->err |
|
| 244 | - and isset($this->command['datapath']) |
|
| 245 | - and is_array($this->command['datapath']) |
|
| 246 | - ) { |
|
| 247 | - $this->select_datapath(); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - // tri {par x} |
|
| 251 | - if ($this->command['orderby']) { |
|
| 252 | - $this->select_orderby(); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | - if ($this->command['groupby']) { |
|
| 257 | - $this->select_groupby(); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - $this->rewind(); |
|
| 261 | - #var_dump($this->tableau); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Aller chercher les donnees de la boucle DATA |
|
| 267 | - * depuis une source |
|
| 268 | - * {source format, [URL], [arg2]...} |
|
| 269 | - */ |
|
| 270 | - protected function select_source() { |
|
| 271 | - # un peu crado : avant de charger le cache il faut charger |
|
| 272 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | - # l'objet en cache ; cf plugins/icalendar |
|
| 274 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | - if ( |
|
| 276 | - isset($this->command['sourcemode']) |
|
| 277 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | - ) { |
|
| 279 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - # le premier argument peut etre un array, une URL etc. |
|
| 283 | - $src = $this->command['source'][0]; |
|
| 284 | - |
|
| 285 | - # avons-nous un cache dispo ? |
|
| 286 | - $cle = null; |
|
| 287 | - if (is_string($src)) { |
|
| 288 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - $cache = $this->cache_get($cle); |
|
| 292 | - if (isset($this->command['datacache'])) { |
|
| 293 | - $ttl = intval($this->command['datacache']); |
|
| 294 | - } |
|
| 295 | - if ( |
|
| 296 | - $cache |
|
| 297 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 298 | - > time()) |
|
| 299 | - and !(_request('var_mode') === 'recalcul' |
|
| 300 | - and include_spip('inc/autoriser') |
|
| 301 | - and autoriser('recalcul') |
|
| 302 | - ) |
|
| 303 | - ) { |
|
| 304 | - $this->tableau = $cache['data']; |
|
| 305 | - } else { |
|
| 306 | - try { |
|
| 307 | - if ( |
|
| 308 | - isset($this->command['sourcemode']) |
|
| 309 | - and in_array( |
|
| 310 | - $this->command['sourcemode'], |
|
| 311 | - ['table', 'array', 'tableau'] |
|
| 312 | - ) |
|
| 313 | - ) { |
|
| 314 | - if ( |
|
| 315 | - is_array($a = $src) |
|
| 316 | - or (is_string($a) |
|
| 317 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | - and is_array($a = @unserialize($a))) |
|
| 319 | - ) { |
|
| 320 | - $this->tableau = $a; |
|
| 321 | - } |
|
| 322 | - } else { |
|
| 323 | - $data = $src; |
|
| 324 | - if (is_string($src)) { |
|
| 325 | - if (tester_url_absolue($src)) { |
|
| 326 | - include_spip('inc/distant'); |
|
| 327 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | - $data = $data['page'] ?? ''; |
|
| 329 | - if (!$data) { |
|
| 330 | - throw new Exception('404'); |
|
| 331 | - } |
|
| 332 | - if (!isset($ttl)) { |
|
| 333 | - $ttl = 24 * 3600; |
|
| 334 | - } |
|
| 335 | - } elseif (@is_dir($src)) { |
|
| 336 | - $data = $src; |
|
| 337 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | - $data = spip_file_get_contents($src); |
|
| 339 | - } |
|
| 340 | - if (!isset($ttl)) { |
|
| 341 | - $ttl = 10; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - if ( |
|
| 346 | - !$this->err |
|
| 347 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | - ) { |
|
| 349 | - $args = $this->command['source']; |
|
| 350 | - $args[0] = $data; |
|
| 351 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | - $this->tableau = $a; |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!is_array($this->tableau)) { |
|
| 358 | - $this->err = true; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | - $this->cache_set($cle, $ttl); |
|
| 363 | - } |
|
| 364 | - } catch (Exception $e) { |
|
| 365 | - $e = $e->getMessage(); |
|
| 366 | - $err = sprintf( |
|
| 367 | - "[%s, %s] $e", |
|
| 368 | - $src, |
|
| 369 | - $this->command['sourcemode'] |
|
| 370 | - ); |
|
| 371 | - erreur_squelette([$err, []]); |
|
| 372 | - $this->err = true; |
|
| 373 | - } |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | - if ( |
|
| 378 | - $this->err |
|
| 379 | - and $cache |
|
| 380 | - ) { |
|
| 381 | - $this->tableau = $cache['data']; |
|
| 382 | - $this->err = false; |
|
| 383 | - } |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - |
|
| 387 | - /** |
|
| 388 | - * Retourne un tableau donne depuis un critère liste |
|
| 389 | - * |
|
| 390 | - * Critère `{liste X1, X2, X3}` |
|
| 391 | - * |
|
| 392 | - * @see critere_DATA_liste_dist() |
|
| 393 | - * |
|
| 394 | - **/ |
|
| 395 | - protected function select_liste() { |
|
| 396 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | - if (!isset($this->command['liste'][1])) { |
|
| 398 | - if (!is_array($this->command['liste'][0])) { |
|
| 399 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | - } else { |
|
| 401 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - $this->tableau = $this->command['liste']; |
|
| 405 | - } |
|
| 406 | - |
|
| 407 | - /** |
|
| 408 | - * Retourne un tableau donne depuis un critere liste |
|
| 409 | - * Critere {enum Xmin, Xmax} |
|
| 410 | - * |
|
| 411 | - **/ |
|
| 412 | - protected function select_enum() { |
|
| 413 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | - if (!isset($this->command['enum'][1])) { |
|
| 415 | - if (!is_array($this->command['enum'][0])) { |
|
| 416 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | - } else { |
|
| 418 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 422 | - $enum = range( |
|
| 423 | - array_shift($this->command['enum']), |
|
| 424 | - array_shift($this->command['enum']), |
|
| 425 | - array_shift($this->command['enum']) |
|
| 426 | - ); |
|
| 427 | - } else { |
|
| 428 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | - } |
|
| 430 | - $this->tableau = $enum; |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | - * {datapath query.results} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_datapath() { |
|
| 440 | - $base = reset($this->command['datapath']); |
|
| 441 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | - if (!is_array($this->tableau)) { |
|
| 444 | - $this->tableau = []; |
|
| 445 | - $this->err = true; |
|
| 446 | - spip_log("datapath '$base' absent"); |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - /** |
|
| 452 | - * Ordonner les resultats |
|
| 453 | - * {par x} |
|
| 454 | - * |
|
| 455 | - **/ |
|
| 456 | - protected function select_orderby() { |
|
| 457 | - $sortfunc = ''; |
|
| 458 | - $aleas = 0; |
|
| 459 | - foreach ($this->command['orderby'] as $tri) { |
|
| 460 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | - $r = array_pad($r, 3, null); |
|
| 463 | - |
|
| 464 | - // tri par cle |
|
| 465 | - if ($r[1] == 'cle') { |
|
| 466 | - if (isset($r[2]) and $r[2]) { |
|
| 467 | - krsort($this->tableau); |
|
| 468 | - } else { |
|
| 469 | - ksort($this->tableau); |
|
| 470 | - } |
|
| 471 | - } # {par hasard} |
|
| 472 | - else { |
|
| 473 | - if ($r[1] == 'hasard') { |
|
| 474 | - $k = array_keys($this->tableau); |
|
| 475 | - shuffle($k); |
|
| 476 | - $v = []; |
|
| 477 | - foreach ($k as $cle) { |
|
| 478 | - $v[$cle] = $this->tableau[$cle]; |
|
| 479 | - } |
|
| 480 | - $this->tableau = $v; |
|
| 481 | - } else { |
|
| 482 | - # {par valeur} |
|
| 483 | - if ($r[1] == 'valeur') { |
|
| 484 | - $tv = '%s'; |
|
| 485 | - } # {par valeur/xx/yy} ?? |
|
| 486 | - else { |
|
| 487 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | - } |
|
| 489 | - $sortfunc .= ' |
|
| 65 | + /** |
|
| 66 | + * tableau de donnees |
|
| 67 | + * |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + protected $tableau = []; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Conditions de filtrage |
|
| 74 | + * ie criteres de selection |
|
| 75 | + * |
|
| 76 | + * @var array |
|
| 77 | + */ |
|
| 78 | + protected $filtre = []; |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Cle courante |
|
| 83 | + * |
|
| 84 | + * @var null |
|
| 85 | + */ |
|
| 86 | + protected $cle = null; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * Valeur courante |
|
| 90 | + * |
|
| 91 | + * @var null |
|
| 92 | + */ |
|
| 93 | + protected $valeur = null; |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Erreur presente ? |
|
| 97 | + * |
|
| 98 | + * @var bool |
|
| 99 | + **/ |
|
| 100 | + public $err = false; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Calcul du total des elements |
|
| 104 | + * |
|
| 105 | + * @var int|null |
|
| 106 | + **/ |
|
| 107 | + public $total = null; |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Constructeur |
|
| 111 | + * |
|
| 112 | + * @param $command |
|
| 113 | + * @param array $info |
|
| 114 | + */ |
|
| 115 | + public function __construct($command, $info = []) { |
|
| 116 | + $this->type = 'DATA'; |
|
| 117 | + $this->command = $command; |
|
| 118 | + $this->info = $info; |
|
| 119 | + |
|
| 120 | + $this->select($command); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Revenir au depart |
|
| 125 | + * |
|
| 126 | + * @return void |
|
| 127 | + */ |
|
| 128 | + public function rewind(): void { |
|
| 129 | + reset($this->tableau); |
|
| 130 | + $this->cle = array_key_first($this->tableau); |
|
| 131 | + $this->valeur = current($this->tableau); |
|
| 132 | + next($this->tableau); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Déclarer les critères exceptions |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function exception_des_criteres() { |
|
| 141 | + return ['tableau']; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Récupérer depuis le cache si possible |
|
| 146 | + * |
|
| 147 | + * @param string $cle |
|
| 148 | + * @return mixed |
|
| 149 | + */ |
|
| 150 | + protected function cache_get($cle) { |
|
| 151 | + if (!$cle) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + # utiliser memoization si dispo |
|
| 155 | + if (!function_exists('cache_get')) { |
|
| 156 | + return; |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return cache_get($cle); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * Stocker en cache si possible |
|
| 164 | + * |
|
| 165 | + * @param string $cle |
|
| 166 | + * @param int $ttl |
|
| 167 | + * @param null|mixed $valeur |
|
| 168 | + * @return bool |
|
| 169 | + */ |
|
| 170 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 171 | + if (!$cle) { |
|
| 172 | + return; |
|
| 173 | + } |
|
| 174 | + if (is_null($valeur)) { |
|
| 175 | + $valeur = $this->tableau; |
|
| 176 | + } |
|
| 177 | + # utiliser memoization si dispo |
|
| 178 | + if (!function_exists('cache_set')) { |
|
| 179 | + return; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + return cache_set( |
|
| 183 | + $cle, |
|
| 184 | + [ |
|
| 185 | + 'data' => $valeur, |
|
| 186 | + 'time' => time(), |
|
| 187 | + 'ttl' => $ttl |
|
| 188 | + ], |
|
| 189 | + 3600 + $ttl |
|
| 190 | + ); |
|
| 191 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 192 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + /** |
|
| 196 | + * Aller chercher les données de la boucle DATA |
|
| 197 | + * |
|
| 198 | + * @throws Exception |
|
| 199 | + * @param array $command |
|
| 200 | + * @return void |
|
| 201 | + */ |
|
| 202 | + protected function select($command) { |
|
| 203 | + |
|
| 204 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 205 | + // le type se retrouve dans la commande 'from' |
|
| 206 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 207 | + if (isset($this->command['from'][0])) { |
|
| 208 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 209 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 210 | + } |
|
| 211 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 215 | + // les commandes connues pour l'iterateur DATA |
|
| 216 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 217 | + |
|
| 218 | + // {source format, [URL], [arg2]...} |
|
| 219 | + if ( |
|
| 220 | + isset($this->command['source']) |
|
| 221 | + and isset($this->command['sourcemode']) |
|
| 222 | + ) { |
|
| 223 | + $this->select_source(); |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + // Critere {liste X1, X2, X3} |
|
| 227 | + if (isset($this->command['liste'])) { |
|
| 228 | + $this->select_liste(); |
|
| 229 | + } |
|
| 230 | + if (isset($this->command['enum'])) { |
|
| 231 | + $this->select_enum(); |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 235 | + if (!is_array($this->tableau)) { |
|
| 236 | + $this->err = true; |
|
| 237 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // {datapath query.results} |
|
| 241 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 242 | + if ( |
|
| 243 | + !$this->err |
|
| 244 | + and isset($this->command['datapath']) |
|
| 245 | + and is_array($this->command['datapath']) |
|
| 246 | + ) { |
|
| 247 | + $this->select_datapath(); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + // tri {par x} |
|
| 251 | + if ($this->command['orderby']) { |
|
| 252 | + $this->select_orderby(); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 256 | + if ($this->command['groupby']) { |
|
| 257 | + $this->select_groupby(); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + $this->rewind(); |
|
| 261 | + #var_dump($this->tableau); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Aller chercher les donnees de la boucle DATA |
|
| 267 | + * depuis une source |
|
| 268 | + * {source format, [URL], [arg2]...} |
|
| 269 | + */ |
|
| 270 | + protected function select_source() { |
|
| 271 | + # un peu crado : avant de charger le cache il faut charger |
|
| 272 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 273 | + # l'objet en cache ; cf plugins/icalendar |
|
| 274 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 275 | + if ( |
|
| 276 | + isset($this->command['sourcemode']) |
|
| 277 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 278 | + ) { |
|
| 279 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + # le premier argument peut etre un array, une URL etc. |
|
| 283 | + $src = $this->command['source'][0]; |
|
| 284 | + |
|
| 285 | + # avons-nous un cache dispo ? |
|
| 286 | + $cle = null; |
|
| 287 | + if (is_string($src)) { |
|
| 288 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + $cache = $this->cache_get($cle); |
|
| 292 | + if (isset($this->command['datacache'])) { |
|
| 293 | + $ttl = intval($this->command['datacache']); |
|
| 294 | + } |
|
| 295 | + if ( |
|
| 296 | + $cache |
|
| 297 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 298 | + > time()) |
|
| 299 | + and !(_request('var_mode') === 'recalcul' |
|
| 300 | + and include_spip('inc/autoriser') |
|
| 301 | + and autoriser('recalcul') |
|
| 302 | + ) |
|
| 303 | + ) { |
|
| 304 | + $this->tableau = $cache['data']; |
|
| 305 | + } else { |
|
| 306 | + try { |
|
| 307 | + if ( |
|
| 308 | + isset($this->command['sourcemode']) |
|
| 309 | + and in_array( |
|
| 310 | + $this->command['sourcemode'], |
|
| 311 | + ['table', 'array', 'tableau'] |
|
| 312 | + ) |
|
| 313 | + ) { |
|
| 314 | + if ( |
|
| 315 | + is_array($a = $src) |
|
| 316 | + or (is_string($a) |
|
| 317 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 318 | + and is_array($a = @unserialize($a))) |
|
| 319 | + ) { |
|
| 320 | + $this->tableau = $a; |
|
| 321 | + } |
|
| 322 | + } else { |
|
| 323 | + $data = $src; |
|
| 324 | + if (is_string($src)) { |
|
| 325 | + if (tester_url_absolue($src)) { |
|
| 326 | + include_spip('inc/distant'); |
|
| 327 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 328 | + $data = $data['page'] ?? ''; |
|
| 329 | + if (!$data) { |
|
| 330 | + throw new Exception('404'); |
|
| 331 | + } |
|
| 332 | + if (!isset($ttl)) { |
|
| 333 | + $ttl = 24 * 3600; |
|
| 334 | + } |
|
| 335 | + } elseif (@is_dir($src)) { |
|
| 336 | + $data = $src; |
|
| 337 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 338 | + $data = spip_file_get_contents($src); |
|
| 339 | + } |
|
| 340 | + if (!isset($ttl)) { |
|
| 341 | + $ttl = 10; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + if ( |
|
| 346 | + !$this->err |
|
| 347 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 348 | + ) { |
|
| 349 | + $args = $this->command['source']; |
|
| 350 | + $args[0] = $data; |
|
| 351 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 352 | + $this->tableau = $a; |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!is_array($this->tableau)) { |
|
| 358 | + $this->err = true; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 362 | + $this->cache_set($cle, $ttl); |
|
| 363 | + } |
|
| 364 | + } catch (Exception $e) { |
|
| 365 | + $e = $e->getMessage(); |
|
| 366 | + $err = sprintf( |
|
| 367 | + "[%s, %s] $e", |
|
| 368 | + $src, |
|
| 369 | + $this->command['sourcemode'] |
|
| 370 | + ); |
|
| 371 | + erreur_squelette([$err, []]); |
|
| 372 | + $this->err = true; |
|
| 373 | + } |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 377 | + if ( |
|
| 378 | + $this->err |
|
| 379 | + and $cache |
|
| 380 | + ) { |
|
| 381 | + $this->tableau = $cache['data']; |
|
| 382 | + $this->err = false; |
|
| 383 | + } |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + |
|
| 387 | + /** |
|
| 388 | + * Retourne un tableau donne depuis un critère liste |
|
| 389 | + * |
|
| 390 | + * Critère `{liste X1, X2, X3}` |
|
| 391 | + * |
|
| 392 | + * @see critere_DATA_liste_dist() |
|
| 393 | + * |
|
| 394 | + **/ |
|
| 395 | + protected function select_liste() { |
|
| 396 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 397 | + if (!isset($this->command['liste'][1])) { |
|
| 398 | + if (!is_array($this->command['liste'][0])) { |
|
| 399 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 400 | + } else { |
|
| 401 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + $this->tableau = $this->command['liste']; |
|
| 405 | + } |
|
| 406 | + |
|
| 407 | + /** |
|
| 408 | + * Retourne un tableau donne depuis un critere liste |
|
| 409 | + * Critere {enum Xmin, Xmax} |
|
| 410 | + * |
|
| 411 | + **/ |
|
| 412 | + protected function select_enum() { |
|
| 413 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 414 | + if (!isset($this->command['enum'][1])) { |
|
| 415 | + if (!is_array($this->command['enum'][0])) { |
|
| 416 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 417 | + } else { |
|
| 418 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 422 | + $enum = range( |
|
| 423 | + array_shift($this->command['enum']), |
|
| 424 | + array_shift($this->command['enum']), |
|
| 425 | + array_shift($this->command['enum']) |
|
| 426 | + ); |
|
| 427 | + } else { |
|
| 428 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 429 | + } |
|
| 430 | + $this->tableau = $enum; |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 436 | + * {datapath query.results} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_datapath() { |
|
| 440 | + $base = reset($this->command['datapath']); |
|
| 441 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 442 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 443 | + if (!is_array($this->tableau)) { |
|
| 444 | + $this->tableau = []; |
|
| 445 | + $this->err = true; |
|
| 446 | + spip_log("datapath '$base' absent"); |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + /** |
|
| 452 | + * Ordonner les resultats |
|
| 453 | + * {par x} |
|
| 454 | + * |
|
| 455 | + **/ |
|
| 456 | + protected function select_orderby() { |
|
| 457 | + $sortfunc = ''; |
|
| 458 | + $aleas = 0; |
|
| 459 | + foreach ($this->command['orderby'] as $tri) { |
|
| 460 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 461 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 462 | + $r = array_pad($r, 3, null); |
|
| 463 | + |
|
| 464 | + // tri par cle |
|
| 465 | + if ($r[1] == 'cle') { |
|
| 466 | + if (isset($r[2]) and $r[2]) { |
|
| 467 | + krsort($this->tableau); |
|
| 468 | + } else { |
|
| 469 | + ksort($this->tableau); |
|
| 470 | + } |
|
| 471 | + } # {par hasard} |
|
| 472 | + else { |
|
| 473 | + if ($r[1] == 'hasard') { |
|
| 474 | + $k = array_keys($this->tableau); |
|
| 475 | + shuffle($k); |
|
| 476 | + $v = []; |
|
| 477 | + foreach ($k as $cle) { |
|
| 478 | + $v[$cle] = $this->tableau[$cle]; |
|
| 479 | + } |
|
| 480 | + $this->tableau = $v; |
|
| 481 | + } else { |
|
| 482 | + # {par valeur} |
|
| 483 | + if ($r[1] == 'valeur') { |
|
| 484 | + $tv = '%s'; |
|
| 485 | + } # {par valeur/xx/yy} ?? |
|
| 486 | + else { |
|
| 487 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 488 | + } |
|
| 489 | + $sortfunc .= ' |
|
| 490 | 490 | $a = ' . sprintf($tv, '$aa') . '; |
| 491 | 491 | $b = ' . sprintf($tv, '$bb') . '; |
| 492 | 492 | if ($a <> $b) |
| 493 | 493 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 494 | - } |
|
| 495 | - } |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - if ($sortfunc) { |
|
| 500 | - $sortfunc .= "\n return 0;"; |
|
| 501 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 502 | - } |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - |
|
| 506 | - /** |
|
| 507 | - * Grouper les resultats |
|
| 508 | - * {fusion /x/y/z} |
|
| 509 | - * |
|
| 510 | - **/ |
|
| 511 | - protected function select_groupby() { |
|
| 512 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | - $vu = []; |
|
| 515 | - foreach ($this->tableau as $k => $v) { |
|
| 516 | - $val = table_valeur($v, $fusion); |
|
| 517 | - if (isset($vu[$val])) { |
|
| 518 | - unset($this->tableau[$k]); |
|
| 519 | - } else { |
|
| 520 | - $vu[$val] = true; |
|
| 521 | - } |
|
| 522 | - } |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * L'iterateur est-il encore valide ? |
|
| 529 | - * |
|
| 530 | - * @return bool |
|
| 531 | - */ |
|
| 532 | - public function valid(): bool { |
|
| 533 | - return !is_null($this->cle); |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * Retourner la valeur |
|
| 538 | - * |
|
| 539 | - * @return mixed |
|
| 540 | - */ |
|
| 541 | - #[\ReturnTypeWillChange] |
|
| 542 | - public function current() { |
|
| 543 | - return $this->valeur; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Retourner la cle |
|
| 548 | - * |
|
| 549 | - * @return mixed |
|
| 550 | - */ |
|
| 551 | - #[\ReturnTypeWillChange] |
|
| 552 | - public function key() { |
|
| 553 | - return $this->cle; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Passer a la valeur suivante |
|
| 558 | - * |
|
| 559 | - * @return void |
|
| 560 | - */ |
|
| 561 | - public function next(): void { |
|
| 562 | - if ($this->valid()) { |
|
| 563 | - $this->cle = key($this->tableau); |
|
| 564 | - $this->valeur = current($this->tableau); |
|
| 565 | - next($this->tableau); |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - /** |
|
| 570 | - * Compter le nombre total de resultats |
|
| 571 | - * |
|
| 572 | - * @return int |
|
| 573 | - */ |
|
| 574 | - public function count() { |
|
| 575 | - if (is_null($this->total)) { |
|
| 576 | - $this->total = count($this->tableau); |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return $this->total; |
|
| 580 | - } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + if ($sortfunc) { |
|
| 500 | + $sortfunc .= "\n return 0;"; |
|
| 501 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 502 | + } |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + |
|
| 506 | + /** |
|
| 507 | + * Grouper les resultats |
|
| 508 | + * {fusion /x/y/z} |
|
| 509 | + * |
|
| 510 | + **/ |
|
| 511 | + protected function select_groupby() { |
|
| 512 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 513 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 514 | + $vu = []; |
|
| 515 | + foreach ($this->tableau as $k => $v) { |
|
| 516 | + $val = table_valeur($v, $fusion); |
|
| 517 | + if (isset($vu[$val])) { |
|
| 518 | + unset($this->tableau[$k]); |
|
| 519 | + } else { |
|
| 520 | + $vu[$val] = true; |
|
| 521 | + } |
|
| 522 | + } |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * L'iterateur est-il encore valide ? |
|
| 529 | + * |
|
| 530 | + * @return bool |
|
| 531 | + */ |
|
| 532 | + public function valid(): bool { |
|
| 533 | + return !is_null($this->cle); |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * Retourner la valeur |
|
| 538 | + * |
|
| 539 | + * @return mixed |
|
| 540 | + */ |
|
| 541 | + #[\ReturnTypeWillChange] |
|
| 542 | + public function current() { |
|
| 543 | + return $this->valeur; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Retourner la cle |
|
| 548 | + * |
|
| 549 | + * @return mixed |
|
| 550 | + */ |
|
| 551 | + #[\ReturnTypeWillChange] |
|
| 552 | + public function key() { |
|
| 553 | + return $this->cle; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Passer a la valeur suivante |
|
| 558 | + * |
|
| 559 | + * @return void |
|
| 560 | + */ |
|
| 561 | + public function next(): void { |
|
| 562 | + if ($this->valid()) { |
|
| 563 | + $this->cle = key($this->tableau); |
|
| 564 | + $this->valeur = current($this->tableau); |
|
| 565 | + next($this->tableau); |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + /** |
|
| 570 | + * Compter le nombre total de resultats |
|
| 571 | + * |
|
| 572 | + * @return int |
|
| 573 | + */ |
|
| 574 | + public function count() { |
|
| 575 | + if (is_null($this->total)) { |
|
| 576 | + $this->total = count($this->tableau); |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return $this->total; |
|
| 580 | + } |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | /* |
@@ -591,7 +591,7 @@ discard block |
||
| 591 | 591 | * @return array |
| 592 | 592 | */ |
| 593 | 593 | function inc_file_to_array_dist($data) { |
| 594 | - return preg_split('/\r?\n/', $data); |
|
| 594 | + return preg_split('/\r?\n/', $data); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -600,9 +600,9 @@ discard block |
||
| 600 | 600 | * @return array |
| 601 | 601 | */ |
| 602 | 602 | function inc_plugins_to_array_dist() { |
| 603 | - include_spip('inc/plugin'); |
|
| 603 | + include_spip('inc/plugin'); |
|
| 604 | 604 | |
| 605 | - return liste_chemin_plugin_actifs(); |
|
| 605 | + return liste_chemin_plugin_actifs(); |
|
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | /** |
@@ -612,7 +612,7 @@ discard block |
||
| 612 | 612 | * @return array |
| 613 | 613 | */ |
| 614 | 614 | function inc_xml_to_array_dist($data) { |
| 615 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 615 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 616 | 616 | } |
| 617 | 617 | |
| 618 | 618 | /** |
@@ -624,14 +624,14 @@ discard block |
||
| 624 | 624 | * |
| 625 | 625 | */ |
| 626 | 626 | function inc_object_to_array($object) { |
| 627 | - if (!is_object($object) && !is_array($object)) { |
|
| 628 | - return $object; |
|
| 629 | - } |
|
| 630 | - if (is_object($object)) { |
|
| 631 | - $object = get_object_vars($object); |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - return array_map('inc_object_to_array', $object); |
|
| 627 | + if (!is_object($object) && !is_array($object)) { |
|
| 628 | + return $object; |
|
| 629 | + } |
|
| 630 | + if (is_object($object)) { |
|
| 631 | + $object = get_object_vars($object); |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + return array_map('inc_object_to_array', $object); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -641,20 +641,20 @@ discard block |
||
| 641 | 641 | * @return array|bool |
| 642 | 642 | */ |
| 643 | 643 | function inc_sql_to_array_dist($data) { |
| 644 | - # sortir le connecteur de $data |
|
| 645 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 646 | - $serveur = (string)$v[1]; |
|
| 647 | - $req = trim($v[2]); |
|
| 648 | - if ($s = sql_query($req, $serveur)) { |
|
| 649 | - $r = []; |
|
| 650 | - while ($t = sql_fetch($s)) { |
|
| 651 | - $r[] = $t; |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $r; |
|
| 655 | - } |
|
| 656 | - |
|
| 657 | - return false; |
|
| 644 | + # sortir le connecteur de $data |
|
| 645 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 646 | + $serveur = (string)$v[1]; |
|
| 647 | + $req = trim($v[2]); |
|
| 648 | + if ($s = sql_query($req, $serveur)) { |
|
| 649 | + $r = []; |
|
| 650 | + while ($t = sql_fetch($s)) { |
|
| 651 | + $r[] = $t; |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $r; |
|
| 655 | + } |
|
| 656 | + |
|
| 657 | + return false; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -664,13 +664,13 @@ discard block |
||
| 664 | 664 | * @return array|bool |
| 665 | 665 | */ |
| 666 | 666 | function inc_json_to_array_dist($data) { |
| 667 | - try { |
|
| 668 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 669 | - } catch (JsonException $e) { |
|
| 670 | - $json = null; |
|
| 671 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 672 | - } |
|
| 673 | - return is_array($json) ? (array) $json : []; |
|
| 667 | + try { |
|
| 668 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 669 | + } catch (JsonException $e) { |
|
| 670 | + $json = null; |
|
| 671 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 672 | + } |
|
| 673 | + return is_array($json) ? (array) $json : []; |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | /** |
@@ -680,30 +680,30 @@ discard block |
||
| 680 | 680 | * @return array|bool |
| 681 | 681 | */ |
| 682 | 682 | function inc_csv_to_array_dist($data) { |
| 683 | - include_spip('inc/csv'); |
|
| 684 | - [$entete, $csv] = analyse_csv($data); |
|
| 685 | - array_unshift($csv, $entete); |
|
| 686 | - |
|
| 687 | - include_spip('inc/charsets'); |
|
| 688 | - $i = 1; |
|
| 689 | - foreach ($entete as $k => $v) { |
|
| 690 | - if (trim($v) == '') { |
|
| 691 | - $v = 'col' . $i; |
|
| 692 | - } // reperer des eventuelles cases vides |
|
| 693 | - if (is_numeric($v) and $v < 0) { |
|
| 694 | - $v = '__' . $v; |
|
| 695 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 696 | - if (is_numeric($v)) { |
|
| 697 | - $v = '_' . $v; |
|
| 698 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 699 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 700 | - foreach ($csv as &$item) { |
|
| 701 | - $item[$v] = &$item[$k]; |
|
| 702 | - } |
|
| 703 | - $i++; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - return $csv; |
|
| 683 | + include_spip('inc/csv'); |
|
| 684 | + [$entete, $csv] = analyse_csv($data); |
|
| 685 | + array_unshift($csv, $entete); |
|
| 686 | + |
|
| 687 | + include_spip('inc/charsets'); |
|
| 688 | + $i = 1; |
|
| 689 | + foreach ($entete as $k => $v) { |
|
| 690 | + if (trim($v) == '') { |
|
| 691 | + $v = 'col' . $i; |
|
| 692 | + } // reperer des eventuelles cases vides |
|
| 693 | + if (is_numeric($v) and $v < 0) { |
|
| 694 | + $v = '__' . $v; |
|
| 695 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 696 | + if (is_numeric($v)) { |
|
| 697 | + $v = '_' . $v; |
|
| 698 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 699 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 700 | + foreach ($csv as &$item) { |
|
| 701 | + $item[$v] = &$item[$k]; |
|
| 702 | + } |
|
| 703 | + $i++; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + return $csv; |
|
| 707 | 707 | } |
| 708 | 708 | |
| 709 | 709 | /** |
@@ -713,13 +713,13 @@ discard block |
||
| 713 | 713 | * @return array|bool |
| 714 | 714 | */ |
| 715 | 715 | function inc_rss_to_array_dist($data) { |
| 716 | - $tableau = null; |
|
| 717 | - include_spip('inc/syndic'); |
|
| 718 | - if (is_array($rss = analyser_backend($data))) { |
|
| 719 | - $tableau = $rss; |
|
| 720 | - } |
|
| 716 | + $tableau = null; |
|
| 717 | + include_spip('inc/syndic'); |
|
| 718 | + if (is_array($rss = analyser_backend($data))) { |
|
| 719 | + $tableau = $rss; |
|
| 720 | + } |
|
| 721 | 721 | |
| 722 | - return $tableau; |
|
| 722 | + return $tableau; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -729,9 +729,9 @@ discard block |
||
| 729 | 729 | * @return array|bool |
| 730 | 730 | */ |
| 731 | 731 | function inc_atom_to_array_dist($data) { |
| 732 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 732 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 733 | 733 | |
| 734 | - return $rss_to_array($data); |
|
| 734 | + return $rss_to_array($data); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | /** |
@@ -742,12 +742,12 @@ discard block |
||
| 742 | 742 | * @return array|bool |
| 743 | 743 | */ |
| 744 | 744 | function inc_glob_to_array_dist($data) { |
| 745 | - $a = glob( |
|
| 746 | - $data, |
|
| 747 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 748 | - ); |
|
| 745 | + $a = glob( |
|
| 746 | + $data, |
|
| 747 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 748 | + ); |
|
| 749 | 749 | |
| 750 | - return $a ?: []; |
|
| 750 | + return $a ?: []; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | /** |
@@ -758,14 +758,14 @@ discard block |
||
| 758 | 758 | * @throws Exception |
| 759 | 759 | */ |
| 760 | 760 | function inc_yaml_to_array_dist($data) { |
| 761 | - include_spip('inc/yaml-mini'); |
|
| 762 | - if (!function_exists('yaml_decode')) { |
|
| 763 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 761 | + include_spip('inc/yaml-mini'); |
|
| 762 | + if (!function_exists('yaml_decode')) { |
|
| 763 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 764 | 764 | |
| 765 | - return false; |
|
| 766 | - } |
|
| 765 | + return false; |
|
| 766 | + } |
|
| 767 | 767 | |
| 768 | - return yaml_decode($data); |
|
| 768 | + return yaml_decode($data); |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * @return array|bool |
| 781 | 781 | */ |
| 782 | 782 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 783 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 783 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -792,23 +792,23 @@ discard block |
||
| 792 | 792 | * @return array|bool |
| 793 | 793 | */ |
| 794 | 794 | function inc_ls_to_array_dist($data) { |
| 795 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 796 | - $a = $glob_to_array($data); |
|
| 797 | - foreach ($a as &$v) { |
|
| 798 | - $b = (array)@stat($v); |
|
| 799 | - foreach ($b as $k => $ignore) { |
|
| 800 | - if (is_numeric($k)) { |
|
| 801 | - unset($b[$k]); |
|
| 802 | - } |
|
| 803 | - } |
|
| 804 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 805 | - $v = array_merge( |
|
| 806 | - pathinfo($v), |
|
| 807 | - $b |
|
| 808 | - ); |
|
| 809 | - } |
|
| 810 | - |
|
| 811 | - return $a; |
|
| 795 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 796 | + $a = $glob_to_array($data); |
|
| 797 | + foreach ($a as &$v) { |
|
| 798 | + $b = (array)@stat($v); |
|
| 799 | + foreach ($b as $k => $ignore) { |
|
| 800 | + if (is_numeric($k)) { |
|
| 801 | + unset($b[$k]); |
|
| 802 | + } |
|
| 803 | + } |
|
| 804 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 805 | + $v = array_merge( |
|
| 806 | + pathinfo($v), |
|
| 807 | + $b |
|
| 808 | + ); |
|
| 809 | + } |
|
| 810 | + |
|
| 811 | + return $a; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | /** |
@@ -818,25 +818,25 @@ discard block |
||
| 818 | 818 | * @return array|bool |
| 819 | 819 | */ |
| 820 | 820 | function XMLObjectToArray($object) { |
| 821 | - $xml_array = []; |
|
| 822 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 823 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 824 | - $key .= '-' . uniqid(); |
|
| 825 | - } |
|
| 826 | - $vars = get_object_vars($object->current()); |
|
| 827 | - if (isset($vars['@attributes'])) { |
|
| 828 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 829 | - $xml_array[$key][$k] = $v; |
|
| 830 | - } |
|
| 831 | - } |
|
| 832 | - if ($object->hasChildren()) { |
|
| 833 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 834 | - $object->current() |
|
| 835 | - ); |
|
| 836 | - } else { |
|
| 837 | - $xml_array[$key][] = strval($object->current()); |
|
| 838 | - } |
|
| 839 | - } |
|
| 840 | - |
|
| 841 | - return $xml_array; |
|
| 821 | + $xml_array = []; |
|
| 822 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 823 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 824 | + $key .= '-' . uniqid(); |
|
| 825 | + } |
|
| 826 | + $vars = get_object_vars($object->current()); |
|
| 827 | + if (isset($vars['@attributes'])) { |
|
| 828 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 829 | + $xml_array[$key][$k] = $v; |
|
| 830 | + } |
|
| 831 | + } |
|
| 832 | + if ($object->hasChildren()) { |
|
| 833 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 834 | + $object->current() |
|
| 835 | + ); |
|
| 836 | + } else { |
|
| 837 | + $xml_array[$key][] = strval($object->current()); |
|
| 838 | + } |
|
| 839 | + } |
|
| 840 | + |
|
| 841 | + return $xml_array; |
|
| 842 | 842 | } |
@@ -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 | |
@@ -27,210 +27,210 @@ discard block |
||
| 27 | 27 | * Permet d'itérer sur des données en base de données |
| 28 | 28 | */ |
| 29 | 29 | class IterateurSQL implements Iterator { |
| 30 | - /** |
|
| 31 | - * Ressource sql |
|
| 32 | - * |
|
| 33 | - * @var Object|bool |
|
| 34 | - */ |
|
| 35 | - protected $sqlresult = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * row sql courante |
|
| 39 | - * |
|
| 40 | - * @var array|null |
|
| 41 | - */ |
|
| 42 | - protected $row = null; |
|
| 43 | - |
|
| 44 | - protected $firstseek = false; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Erreur presente ? |
|
| 48 | - * |
|
| 49 | - * @var bool |
|
| 50 | - **/ |
|
| 51 | - public $err = false; |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Calcul du total des elements |
|
| 55 | - * |
|
| 56 | - * @var int|null |
|
| 57 | - **/ |
|
| 58 | - public $total = null; |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * selectionner les donnees, ie faire la requete SQL |
|
| 62 | - * |
|
| 63 | - * @return void |
|
| 64 | - */ |
|
| 65 | - protected function select() { |
|
| 66 | - $this->row = null; |
|
| 67 | - $v = &$this->command; |
|
| 68 | - $this->sqlresult = calculer_select( |
|
| 69 | - $v['select'], |
|
| 70 | - $v['from'], |
|
| 71 | - $v['type'], |
|
| 72 | - $v['where'], |
|
| 73 | - $v['join'], |
|
| 74 | - $v['groupby'], |
|
| 75 | - $v['orderby'], |
|
| 76 | - $v['limit'], |
|
| 77 | - $v['having'], |
|
| 78 | - $v['table'], |
|
| 79 | - $v['id'], |
|
| 80 | - $v['connect'], |
|
| 81 | - $this->info |
|
| 82 | - ); |
|
| 83 | - $this->err = !$this->sqlresult; |
|
| 84 | - $this->firstseek = false; |
|
| 85 | - $this->pos = -1; |
|
| 86 | - |
|
| 87 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 88 | - //$this->total = $this->count(); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /* |
|
| 30 | + /** |
|
| 31 | + * Ressource sql |
|
| 32 | + * |
|
| 33 | + * @var Object|bool |
|
| 34 | + */ |
|
| 35 | + protected $sqlresult = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * row sql courante |
|
| 39 | + * |
|
| 40 | + * @var array|null |
|
| 41 | + */ |
|
| 42 | + protected $row = null; |
|
| 43 | + |
|
| 44 | + protected $firstseek = false; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Erreur presente ? |
|
| 48 | + * |
|
| 49 | + * @var bool |
|
| 50 | + **/ |
|
| 51 | + public $err = false; |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Calcul du total des elements |
|
| 55 | + * |
|
| 56 | + * @var int|null |
|
| 57 | + **/ |
|
| 58 | + public $total = null; |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * selectionner les donnees, ie faire la requete SQL |
|
| 62 | + * |
|
| 63 | + * @return void |
|
| 64 | + */ |
|
| 65 | + protected function select() { |
|
| 66 | + $this->row = null; |
|
| 67 | + $v = &$this->command; |
|
| 68 | + $this->sqlresult = calculer_select( |
|
| 69 | + $v['select'], |
|
| 70 | + $v['from'], |
|
| 71 | + $v['type'], |
|
| 72 | + $v['where'], |
|
| 73 | + $v['join'], |
|
| 74 | + $v['groupby'], |
|
| 75 | + $v['orderby'], |
|
| 76 | + $v['limit'], |
|
| 77 | + $v['having'], |
|
| 78 | + $v['table'], |
|
| 79 | + $v['id'], |
|
| 80 | + $v['connect'], |
|
| 81 | + $this->info |
|
| 82 | + ); |
|
| 83 | + $this->err = !$this->sqlresult; |
|
| 84 | + $this->firstseek = false; |
|
| 85 | + $this->pos = -1; |
|
| 86 | + |
|
| 87 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 88 | + //$this->total = $this->count(); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /* |
|
| 92 | 92 | * array command: les commandes d'initialisation |
| 93 | 93 | * array info: les infos sur le squelette |
| 94 | 94 | */ |
| 95 | - public function __construct($command, $info = []) { |
|
| 96 | - $this->type = 'SQL'; |
|
| 97 | - $this->command = $command; |
|
| 98 | - $this->info = $info; |
|
| 99 | - $this->select(); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Rembobiner |
|
| 104 | - * |
|
| 105 | - * @return bool |
|
| 106 | - */ |
|
| 107 | - public function rewind(): void { |
|
| 108 | - if ($this->pos > 0) { |
|
| 109 | - $this->seek(0); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Verifier l'etat de l'iterateur |
|
| 115 | - * |
|
| 116 | - * @return bool |
|
| 117 | - */ |
|
| 118 | - public function valid(): bool { |
|
| 119 | - if ($this->err) { |
|
| 120 | - return false; |
|
| 121 | - } |
|
| 122 | - if (!$this->firstseek) { |
|
| 123 | - $this->next(); |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - return is_array($this->row); |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Valeurs sur la position courante |
|
| 131 | - * |
|
| 132 | - * @return array |
|
| 133 | - */ |
|
| 134 | - #[\ReturnTypeWillChange] |
|
| 135 | - public function current() { |
|
| 136 | - return $this->row; |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - #[\ReturnTypeWillChange] |
|
| 140 | - public function key() { |
|
| 141 | - return $this->pos; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * Sauter a une position absolue |
|
| 146 | - * |
|
| 147 | - * @param int $n |
|
| 148 | - * @param null|string $continue |
|
| 149 | - * @return bool |
|
| 150 | - */ |
|
| 151 | - public function seek($n = 0, $continue = null) { |
|
| 152 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 153 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 154 | - // si la position courante est apres la position visee |
|
| 155 | - // il faut relancer la requete |
|
| 156 | - if ($this->pos > $n) { |
|
| 157 | - $this->free(); |
|
| 158 | - $this->select(); |
|
| 159 | - $this->valid(); |
|
| 160 | - } |
|
| 161 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 162 | - // (sera fait en cas d'echec de cette fonction) |
|
| 163 | - return false; |
|
| 164 | - } |
|
| 165 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 166 | - $this->pos = min($n, $this->count()); |
|
| 167 | - |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Avancer d'un cran |
|
| 173 | - * |
|
| 174 | - * @return void |
|
| 175 | - */ |
|
| 176 | - public function next(): void { |
|
| 177 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 178 | - $this->pos++; |
|
| 179 | - $this->firstseek |= true; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Avancer et retourner les donnees pour le nouvel element |
|
| 184 | - * |
|
| 185 | - * @return array|bool|null |
|
| 186 | - */ |
|
| 187 | - public function fetch() { |
|
| 188 | - if ($this->valid()) { |
|
| 189 | - $r = $this->current(); |
|
| 190 | - $this->next(); |
|
| 191 | - } else { |
|
| 192 | - $r = false; |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - return $r; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * liberer les ressources |
|
| 200 | - * |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 203 | - public function free() { |
|
| 204 | - if (!$this->sqlresult) { |
|
| 205 | - return true; |
|
| 206 | - } |
|
| 207 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 208 | - $this->sqlresult = null; |
|
| 209 | - |
|
| 210 | - return $a; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Compter le nombre de resultats |
|
| 215 | - * |
|
| 216 | - * @return int |
|
| 217 | - */ |
|
| 218 | - public function count() { |
|
| 219 | - if (is_null($this->total)) { |
|
| 220 | - if (!$this->sqlresult) { |
|
| 221 | - $this->total = 0; |
|
| 222 | - } else { |
|
| 223 | - # cas count(*) |
|
| 224 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 225 | - $this->valid(); |
|
| 226 | - $s = $this->current(); |
|
| 227 | - $this->total = $s['count(*)']; |
|
| 228 | - } else { |
|
| 229 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - } |
|
| 233 | - |
|
| 234 | - return $this->total; |
|
| 235 | - } |
|
| 95 | + public function __construct($command, $info = []) { |
|
| 96 | + $this->type = 'SQL'; |
|
| 97 | + $this->command = $command; |
|
| 98 | + $this->info = $info; |
|
| 99 | + $this->select(); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Rembobiner |
|
| 104 | + * |
|
| 105 | + * @return bool |
|
| 106 | + */ |
|
| 107 | + public function rewind(): void { |
|
| 108 | + if ($this->pos > 0) { |
|
| 109 | + $this->seek(0); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Verifier l'etat de l'iterateur |
|
| 115 | + * |
|
| 116 | + * @return bool |
|
| 117 | + */ |
|
| 118 | + public function valid(): bool { |
|
| 119 | + if ($this->err) { |
|
| 120 | + return false; |
|
| 121 | + } |
|
| 122 | + if (!$this->firstseek) { |
|
| 123 | + $this->next(); |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + return is_array($this->row); |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Valeurs sur la position courante |
|
| 131 | + * |
|
| 132 | + * @return array |
|
| 133 | + */ |
|
| 134 | + #[\ReturnTypeWillChange] |
|
| 135 | + public function current() { |
|
| 136 | + return $this->row; |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + #[\ReturnTypeWillChange] |
|
| 140 | + public function key() { |
|
| 141 | + return $this->pos; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * Sauter a une position absolue |
|
| 146 | + * |
|
| 147 | + * @param int $n |
|
| 148 | + * @param null|string $continue |
|
| 149 | + * @return bool |
|
| 150 | + */ |
|
| 151 | + public function seek($n = 0, $continue = null) { |
|
| 152 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 153 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 154 | + // si la position courante est apres la position visee |
|
| 155 | + // il faut relancer la requete |
|
| 156 | + if ($this->pos > $n) { |
|
| 157 | + $this->free(); |
|
| 158 | + $this->select(); |
|
| 159 | + $this->valid(); |
|
| 160 | + } |
|
| 161 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 162 | + // (sera fait en cas d'echec de cette fonction) |
|
| 163 | + return false; |
|
| 164 | + } |
|
| 165 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 166 | + $this->pos = min($n, $this->count()); |
|
| 167 | + |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Avancer d'un cran |
|
| 173 | + * |
|
| 174 | + * @return void |
|
| 175 | + */ |
|
| 176 | + public function next(): void { |
|
| 177 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 178 | + $this->pos++; |
|
| 179 | + $this->firstseek |= true; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Avancer et retourner les donnees pour le nouvel element |
|
| 184 | + * |
|
| 185 | + * @return array|bool|null |
|
| 186 | + */ |
|
| 187 | + public function fetch() { |
|
| 188 | + if ($this->valid()) { |
|
| 189 | + $r = $this->current(); |
|
| 190 | + $this->next(); |
|
| 191 | + } else { |
|
| 192 | + $r = false; |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + return $r; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * liberer les ressources |
|
| 200 | + * |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | + public function free() { |
|
| 204 | + if (!$this->sqlresult) { |
|
| 205 | + return true; |
|
| 206 | + } |
|
| 207 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 208 | + $this->sqlresult = null; |
|
| 209 | + |
|
| 210 | + return $a; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Compter le nombre de resultats |
|
| 215 | + * |
|
| 216 | + * @return int |
|
| 217 | + */ |
|
| 218 | + public function count() { |
|
| 219 | + if (is_null($this->total)) { |
|
| 220 | + if (!$this->sqlresult) { |
|
| 221 | + $this->total = 0; |
|
| 222 | + } else { |
|
| 223 | + # cas count(*) |
|
| 224 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 225 | + $this->valid(); |
|
| 226 | + $s = $this->current(); |
|
| 227 | + $this->total = $s['count(*)']; |
|
| 228 | + } else { |
|
| 229 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + } |
|
| 233 | + |
|
| 234 | + return $this->total; |
|
| 235 | + } |
|
| 236 | 236 | } |
@@ -17,91 +17,91 @@ |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
| 24 | 24 | function action_api_transmettre_dist($arg = null) { |
| 25 | 25 | |
| 26 | - // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 27 | - if (is_null($arg)) { |
|
| 28 | - $arg = _request('arg'); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - $args = explode('/', $arg); |
|
| 32 | - |
|
| 33 | - if (count($args) !== 4) { |
|
| 34 | - action_api_transmettre_fail($arg); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - [$id_auteur, $cle, $format, $fond] = $args; |
|
| 38 | - $id_auteur = intval($id_auteur); |
|
| 39 | - |
|
| 40 | - if (preg_match(',[^\w\\.-],', $format)) { |
|
| 41 | - action_api_transmettre_fail("format $format ??"); |
|
| 42 | - } |
|
| 43 | - if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 44 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - // verifier la cle |
|
| 48 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | - //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 50 | - |
|
| 51 | - $qs = $_SERVER['QUERY_STRING']; |
|
| 52 | - // retirer action et arg de la qs |
|
| 53 | - $contexte = []; |
|
| 54 | - parse_str($qs, $contexte); |
|
| 55 | - foreach ($contexte as $k => $v) { |
|
| 56 | - if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 57 | - unset($contexte[$k]); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - $qs = http_build_query($contexte); |
|
| 61 | - if (!securiser_acces_low_sec(intval($id_auteur), $cle, "transmettre/$format", $fond, $qs)) { |
|
| 62 | - // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 63 | - include_spip('inc/autoriser'); |
|
| 64 | - $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 65 | - if ( |
|
| 66 | - !$id_auteur |
|
| 67 | - or empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 68 | - or $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 69 | - or !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 70 | - ) { |
|
| 71 | - action_api_transmettre_fail("auth QS $qs ??"); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $contexte['id_auteur'] = $id_auteur; |
|
| 76 | - |
|
| 77 | - $fond = "transmettre/$format/$fond"; |
|
| 78 | - |
|
| 79 | - if (!trouver_fond($fond)) { |
|
| 80 | - $fond = "prive/$fond"; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - if (!trouver_fond($fond)) { |
|
| 84 | - action_api_transmettre_fail("fond $fond ??"); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 88 | - if (!empty($res['entetes'])) { |
|
| 89 | - foreach ($res['entetes'] as $h => $v) { |
|
| 90 | - header("$h: $v"); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - $res = ltrim($res['texte']); |
|
| 95 | - if (empty($res)) { |
|
| 96 | - spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - echo $res; |
|
| 100 | - exit(); |
|
| 26 | + // Obtenir l'argument 'id_auteur/cle/format/fond' |
|
| 27 | + if (is_null($arg)) { |
|
| 28 | + $arg = _request('arg'); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + $args = explode('/', $arg); |
|
| 32 | + |
|
| 33 | + if (count($args) !== 4) { |
|
| 34 | + action_api_transmettre_fail($arg); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + [$id_auteur, $cle, $format, $fond] = $args; |
|
| 38 | + $id_auteur = intval($id_auteur); |
|
| 39 | + |
|
| 40 | + if (preg_match(',[^\w\\.-],', $format)) { |
|
| 41 | + action_api_transmettre_fail("format $format ??"); |
|
| 42 | + } |
|
| 43 | + if (preg_match(',[^\w\\.-],', $fond)) { |
|
| 44 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + // verifier la cle |
|
| 48 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 49 | + //[(#ENV{id,0}|securiser_acces{#ENV{cle}, voirstats, #ENV{op}, #ENV{args}}|?{1,0})] |
|
| 50 | + |
|
| 51 | + $qs = $_SERVER['QUERY_STRING']; |
|
| 52 | + // retirer action et arg de la qs |
|
| 53 | + $contexte = []; |
|
| 54 | + parse_str($qs, $contexte); |
|
| 55 | + foreach ($contexte as $k => $v) { |
|
| 56 | + if (in_array($k, ['action', 'arg', 'var_mode'])) { |
|
| 57 | + unset($contexte[$k]); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + $qs = http_build_query($contexte); |
|
| 61 | + if (!securiser_acces_low_sec(intval($id_auteur), $cle, "transmettre/$format", $fond, $qs)) { |
|
| 62 | + // si le autoriser low_sec n'est pas bon, on peut valider l'appel si l'auteur est identifie |
|
| 63 | + include_spip('inc/autoriser'); |
|
| 64 | + $autoriser_type = preg_replace(',\W+,', '', "_{$format}{$fond}"); |
|
| 65 | + if ( |
|
| 66 | + !$id_auteur |
|
| 67 | + or empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 68 | + or $GLOBALS['visiteur_session']['id_auteur'] != $id_auteur |
|
| 69 | + or !autoriser('transmettre', $autoriser_type, $id_auteur) |
|
| 70 | + ) { |
|
| 71 | + action_api_transmettre_fail("auth QS $qs ??"); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $contexte['id_auteur'] = $id_auteur; |
|
| 76 | + |
|
| 77 | + $fond = "transmettre/$format/$fond"; |
|
| 78 | + |
|
| 79 | + if (!trouver_fond($fond)) { |
|
| 80 | + $fond = "prive/$fond"; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + if (!trouver_fond($fond)) { |
|
| 84 | + action_api_transmettre_fail("fond $fond ??"); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $res = recuperer_fond($fond, $contexte, ['raw' => true]); |
|
| 88 | + if (!empty($res['entetes'])) { |
|
| 89 | + foreach ($res['entetes'] as $h => $v) { |
|
| 90 | + header("$h: $v"); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + $res = ltrim($res['texte']); |
|
| 95 | + if (empty($res)) { |
|
| 96 | + spip_log("$arg $qs resultat vide", 'transmettre' . _LOG_INFO_IMPORTANTE); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + echo $res; |
|
| 100 | + exit(); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function action_api_transmettre_fail($arg) { |
| 104 | - include_spip('inc/minipres'); |
|
| 105 | - echo minipres(_T('info_acces_interdit'), $arg); |
|
| 106 | - exit; |
|
| 104 | + include_spip('inc/minipres'); |
|
| 105 | + echo minipres(_T('info_acces_interdit'), $arg); |
|
| 106 | + exit; |
|
| 107 | 107 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,667 +21,667 @@ discard block |
||
| 21 | 21 | * |
| 22 | 22 | */ |
| 23 | 23 | class IterFactory { |
| 24 | - public static function create($iterateur, $command, $info = null) { |
|
| 25 | - |
|
| 26 | - $iter = null; |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = $command['args'] ?? []; |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = 'Iterateur' . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if ( |
|
| 85 | - !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | - or !class_exists($class) |
|
| 87 | - ) { |
|
| 88 | - die("Iterateur $iterateur non trouvé"); |
|
| 89 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | - # $iter = new EmptyIterator(); |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - $iter = new $class($command, $info); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - return new IterDecorator($iter, $command, $info); |
|
| 97 | - } |
|
| 24 | + public static function create($iterateur, $command, $info = null) { |
|
| 25 | + |
|
| 26 | + $iter = null; |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), [], $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = $command['args'] ?? []; |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if ((is_countable($a) ? count($a) : 0) == 1 and is_object($a[0]) and is_subclass_of($a[0], \Iterator::class)) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (is_countable($a) ? count($a) : 0) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = 'Iterateur' . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if ( |
|
| 85 | + !include_spip('iterateur/' . strtolower($iterateur)) |
|
| 86 | + or !class_exists($class) |
|
| 87 | + ) { |
|
| 88 | + die("Iterateur $iterateur non trouvé"); |
|
| 89 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 90 | + # $iter = new EmptyIterator(); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + $iter = new $class($command, $info); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + return new IterDecorator($iter, $command, $info); |
|
| 97 | + } |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | |
| 101 | 101 | class IterDecorator extends FilterIterator { |
| 102 | - private $iter; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Conditions de filtrage |
|
| 106 | - * ie criteres de selection |
|
| 107 | - * |
|
| 108 | - * @var array |
|
| 109 | - */ |
|
| 110 | - protected $filtre = []; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | - * |
|
| 115 | - * @var string |
|
| 116 | - */ |
|
| 117 | - protected $func_filtre = null; |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Critere {offset, limit} |
|
| 121 | - * |
|
| 122 | - * @var int |
|
| 123 | - * @var int |
|
| 124 | - */ |
|
| 125 | - protected $offset = null; |
|
| 126 | - protected $limit = null; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * nombre d'elements recuperes depuis la position 0, |
|
| 130 | - * en tenant compte des filtres |
|
| 131 | - * |
|
| 132 | - * @var int |
|
| 133 | - */ |
|
| 134 | - protected $fetched = 0; |
|
| 135 | - |
|
| 136 | - /** |
|
| 137 | - * Y a t'il une erreur ? |
|
| 138 | - * |
|
| 139 | - * @var bool |
|
| 140 | - **/ |
|
| 141 | - protected $err = false; |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * Drapeau a activer en cas d'echec |
|
| 145 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | - */ |
|
| 147 | - public function err() { |
|
| 148 | - if (method_exists($this->iter, 'err')) { |
|
| 149 | - return $this->iter->err(); |
|
| 150 | - } |
|
| 151 | - if (property_exists($this->iter, 'err')) { |
|
| 152 | - return $this->iter->err; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | - parent::__construct($iter); |
|
| 160 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | - |
|
| 162 | - // recuperer l'iterateur transmis |
|
| 163 | - $this->iter = $this->getInnerIterator(); |
|
| 164 | - $this->command = $command; |
|
| 165 | - $this->info = $info; |
|
| 166 | - $this->pos = 0; |
|
| 167 | - $this->fetched = 0; |
|
| 168 | - |
|
| 169 | - // chercher la liste des champs a retourner par |
|
| 170 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | - $this->calculer_select(); |
|
| 173 | - $this->calculer_filtres(); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | - if (isset($this->iter->err)) { |
|
| 178 | - $this->err = $this->iter->err; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | - //$this->total = $this->count(); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - |
|
| 186 | - // calcule les elements a retournes par fetch() |
|
| 187 | - // enleve les elements inutiles du select() |
|
| 188 | - // |
|
| 189 | - private function calculer_select() { |
|
| 190 | - if ($select = &$this->command['select']) { |
|
| 191 | - foreach ($select as $s) { |
|
| 192 | - // /!\ $s = '.nom' |
|
| 193 | - if ($s[0] == '.') { |
|
| 194 | - $s = substr($s, 1); |
|
| 195 | - } |
|
| 196 | - $this->select[] = $s; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // recuperer la valeur d'une balise #X |
|
| 202 | - // en fonction des methodes |
|
| 203 | - // et proprietes disponibles |
|
| 204 | - public function get_select($nom) { |
|
| 205 | - if ( |
|
| 206 | - is_object($this->iter) |
|
| 207 | - and method_exists($this->iter, $nom) |
|
| 208 | - ) { |
|
| 209 | - try { |
|
| 210 | - return $this->iter->$nom(); |
|
| 211 | - } catch (Exception $e) { |
|
| 212 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | - |
|
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - /* |
|
| 102 | + private $iter; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Conditions de filtrage |
|
| 106 | + * ie criteres de selection |
|
| 107 | + * |
|
| 108 | + * @var array |
|
| 109 | + */ |
|
| 110 | + protected $filtre = []; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 114 | + * |
|
| 115 | + * @var string |
|
| 116 | + */ |
|
| 117 | + protected $func_filtre = null; |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Critere {offset, limit} |
|
| 121 | + * |
|
| 122 | + * @var int |
|
| 123 | + * @var int |
|
| 124 | + */ |
|
| 125 | + protected $offset = null; |
|
| 126 | + protected $limit = null; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * nombre d'elements recuperes depuis la position 0, |
|
| 130 | + * en tenant compte des filtres |
|
| 131 | + * |
|
| 132 | + * @var int |
|
| 133 | + */ |
|
| 134 | + protected $fetched = 0; |
|
| 135 | + |
|
| 136 | + /** |
|
| 137 | + * Y a t'il une erreur ? |
|
| 138 | + * |
|
| 139 | + * @var bool |
|
| 140 | + **/ |
|
| 141 | + protected $err = false; |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * Drapeau a activer en cas d'echec |
|
| 145 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 146 | + */ |
|
| 147 | + public function err() { |
|
| 148 | + if (method_exists($this->iter, 'err')) { |
|
| 149 | + return $this->iter->err(); |
|
| 150 | + } |
|
| 151 | + if (property_exists($this->iter, 'err')) { |
|
| 152 | + return $this->iter->err; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 159 | + parent::__construct($iter); |
|
| 160 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 161 | + |
|
| 162 | + // recuperer l'iterateur transmis |
|
| 163 | + $this->iter = $this->getInnerIterator(); |
|
| 164 | + $this->command = $command; |
|
| 165 | + $this->info = $info; |
|
| 166 | + $this->pos = 0; |
|
| 167 | + $this->fetched = 0; |
|
| 168 | + |
|
| 169 | + // chercher la liste des champs a retourner par |
|
| 170 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 171 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 172 | + $this->calculer_select(); |
|
| 173 | + $this->calculer_filtres(); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 177 | + if (isset($this->iter->err)) { |
|
| 178 | + $this->err = $this->iter->err; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 182 | + //$this->total = $this->count(); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + |
|
| 186 | + // calcule les elements a retournes par fetch() |
|
| 187 | + // enleve les elements inutiles du select() |
|
| 188 | + // |
|
| 189 | + private function calculer_select() { |
|
| 190 | + if ($select = &$this->command['select']) { |
|
| 191 | + foreach ($select as $s) { |
|
| 192 | + // /!\ $s = '.nom' |
|
| 193 | + if ($s[0] == '.') { |
|
| 194 | + $s = substr($s, 1); |
|
| 195 | + } |
|
| 196 | + $this->select[] = $s; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // recuperer la valeur d'une balise #X |
|
| 202 | + // en fonction des methodes |
|
| 203 | + // et proprietes disponibles |
|
| 204 | + public function get_select($nom) { |
|
| 205 | + if ( |
|
| 206 | + is_object($this->iter) |
|
| 207 | + and method_exists($this->iter, $nom) |
|
| 208 | + ) { |
|
| 209 | + try { |
|
| 210 | + return $this->iter->$nom(); |
|
| 211 | + } catch (Exception $e) { |
|
| 212 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 213 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 214 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 215 | + |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + /* |
|
| 220 | 220 | if (property_exists($this->iter, $nom)) { |
| 221 | 221 | return $this->iter->$nom; |
| 222 | 222 | }*/ |
| 223 | - // cle et valeur par defaut |
|
| 224 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | - if ( |
|
| 226 | - in_array($nom, ['cle', 'valeur']) |
|
| 227 | - and method_exists($this, $nom) |
|
| 228 | - ) { |
|
| 229 | - return $this->$nom(); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - // Par defaut chercher en xpath dans la valeur() |
|
| 233 | - return table_valeur($this->valeur(), $nom, null); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - |
|
| 237 | - private function calculer_filtres() { |
|
| 238 | - |
|
| 239 | - // Issu de calculer_select() de public/composer L.519 |
|
| 240 | - // TODO: externaliser... |
|
| 241 | - // |
|
| 242 | - // retirer les criteres vides: |
|
| 243 | - // {X ?} avec X absent de l'URL |
|
| 244 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | - if ($where = &$this->command['where']) { |
|
| 247 | - foreach ($where as $k => $v) { |
|
| 248 | - $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // critere {2,7} |
|
| 253 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | - $limit = explode(',', $this->command['limit']); |
|
| 255 | - $this->offset = $limit[0]; |
|
| 256 | - $this->limit = $limit[1]; |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - // Creer la fonction de filtrage sur $this |
|
| 260 | - if ($this->filtre) { |
|
| 261 | - if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | - $filtres = 'return ' . $filtres . ';'; |
|
| 263 | - $this->func_filtre = fn() => eval($filtres); |
|
| 264 | - } |
|
| 265 | - else { |
|
| 266 | - $this->func_filtre = null; |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - /** |
|
| 272 | - * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | - * les filtres vides ou null sont ignores |
|
| 274 | - * @param $filtres |
|
| 275 | - * @param string $operateur |
|
| 276 | - * @return string|null |
|
| 277 | - */ |
|
| 278 | - protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | - |
|
| 280 | - $filtres_string = []; |
|
| 281 | - foreach ($filtres as $k => $v) { |
|
| 282 | - // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | - if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | - $op = array_shift($v); |
|
| 285 | - $v = $this->assembler_filtres($v, $op); |
|
| 286 | - } |
|
| 287 | - if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | - continue; |
|
| 289 | - } |
|
| 290 | - $filtres_string[] = $v; |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - if (!count($filtres_string)) { |
|
| 294 | - return null; |
|
| 295 | - } |
|
| 296 | - |
|
| 297 | - return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * Traduire un element du tableau where SQL en un filtre |
|
| 302 | - * @param $v |
|
| 303 | - * @return string|array|null |
|
| 304 | - */ |
|
| 305 | - protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | - if (is_array($v)) { |
|
| 307 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | - return 'true'; |
|
| 309 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | - return 'true'; |
|
| 311 | - } else { |
|
| 312 | - $op = $v[0] ?: $v; |
|
| 313 | - } |
|
| 314 | - } else { |
|
| 315 | - $op = $v; |
|
| 316 | - } |
|
| 317 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | - return 'true'; |
|
| 319 | - } |
|
| 320 | - if ($op === '0=1') { |
|
| 321 | - return 'false'; |
|
| 322 | - } |
|
| 323 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | - if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | - return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | - } |
|
| 327 | - |
|
| 328 | - // 3 possibilites : count($v) = |
|
| 329 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | - |
|
| 333 | - // 1 : forcement traite par un critere, on passe |
|
| 334 | - if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | - return null; // sera ignore |
|
| 336 | - } |
|
| 337 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | - return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | - } |
|
| 340 | - if (count($v) == 3) { |
|
| 341 | - // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | - if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | - array_shift($v); |
|
| 344 | - foreach (array_keys($v) as $k) { |
|
| 345 | - $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | - if ($v[$k] === null) { |
|
| 347 | - unset($v[$k]); |
|
| 348 | - } |
|
| 349 | - elseif ($v[$k] === 'true') { |
|
| 350 | - if ($op === 'OR') { |
|
| 351 | - return 'true'; |
|
| 352 | - } |
|
| 353 | - if ($op === 'AND') { |
|
| 354 | - unset($v[$k]); |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - elseif ($v[$k] === 'false') { |
|
| 358 | - if ($op === 'OR') { |
|
| 359 | - unset($v[$k]); |
|
| 360 | - } |
|
| 361 | - if ($op === 'AND') { |
|
| 362 | - return 'false'; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - } |
|
| 366 | - if (!count($v)) { |
|
| 367 | - return null; |
|
| 368 | - } |
|
| 369 | - if (count($v) === 1) { |
|
| 370 | - return reset($v); |
|
| 371 | - } |
|
| 372 | - array_unshift($v, $op); |
|
| 373 | - return $v; |
|
| 374 | - } |
|
| 375 | - return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return null; // sera ignore |
|
| 379 | - } |
|
| 380 | - |
|
| 381 | - /** |
|
| 382 | - * Calculer un filtre sur un champ du tableau |
|
| 383 | - * @param $cle |
|
| 384 | - * @param $op |
|
| 385 | - * @param $valeur |
|
| 386 | - * @param false $not |
|
| 387 | - * @return string|null |
|
| 388 | - */ |
|
| 389 | - protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | - return null; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | - |
|
| 401 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | - # return; |
|
| 403 | - |
|
| 404 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | - |
|
| 406 | - $filtre = ''; |
|
| 407 | - |
|
| 408 | - if ($op == 'REGEXP') { |
|
| 409 | - $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | - $op = ''; |
|
| 411 | - } else { |
|
| 412 | - if ($op == 'LIKE') { |
|
| 413 | - $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | - $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | - $op = ''; |
|
| 416 | - } else { |
|
| 417 | - if ($op == '=') { |
|
| 418 | - $op = '=='; |
|
| 419 | - } else { |
|
| 420 | - if ($op == 'IN') { |
|
| 421 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | - $op = ''; |
|
| 423 | - } else { |
|
| 424 | - if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | - $op = ''; |
|
| 427 | - } |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($op) { |
|
| 434 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - if ($not) { |
|
| 438 | - $filtre = "!($filtre)"; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - return $filtre; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - |
|
| 445 | - public function next(): void { |
|
| 446 | - $this->pos++; |
|
| 447 | - parent::next(); |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * revient au depart |
|
| 452 | - * |
|
| 453 | - * @return void |
|
| 454 | - */ |
|
| 455 | - public function rewind(): void { |
|
| 456 | - $this->pos = 0; |
|
| 457 | - $this->fetched = 0; |
|
| 458 | - parent::rewind(); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - # Extension SPIP des iterateurs PHP |
|
| 463 | - /** |
|
| 464 | - * type de l'iterateur |
|
| 465 | - * |
|
| 466 | - * @var string |
|
| 467 | - */ |
|
| 468 | - protected $type; |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * parametres de l'iterateur |
|
| 472 | - * |
|
| 473 | - * @var array |
|
| 474 | - */ |
|
| 475 | - protected $command; |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * infos de compilateur |
|
| 479 | - * |
|
| 480 | - * @var array |
|
| 481 | - */ |
|
| 482 | - protected $info; |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * position courante de l'iterateur |
|
| 486 | - * |
|
| 487 | - * @var int |
|
| 488 | - */ |
|
| 489 | - protected $pos = null; |
|
| 490 | - |
|
| 491 | - /** |
|
| 492 | - * nombre total resultats dans l'iterateur |
|
| 493 | - * |
|
| 494 | - * @var int |
|
| 495 | - */ |
|
| 496 | - protected $total = null; |
|
| 497 | - |
|
| 498 | - /** |
|
| 499 | - * nombre maximal de recherche pour $total |
|
| 500 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | - */ |
|
| 502 | - protected $max = 100000; |
|
| 503 | - |
|
| 504 | - |
|
| 505 | - /** |
|
| 506 | - * Liste des champs a inserer dans les $row |
|
| 507 | - * retournes par ->fetch() |
|
| 508 | - */ |
|
| 509 | - protected $select = []; |
|
| 510 | - |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * aller a la position absolue n, |
|
| 514 | - * comptee depuis le debut |
|
| 515 | - * |
|
| 516 | - * @param int $n |
|
| 517 | - * absolute pos |
|
| 518 | - * @param string $continue |
|
| 519 | - * param for sql_ api |
|
| 520 | - * @return bool |
|
| 521 | - * success or fail if not implemented |
|
| 522 | - */ |
|
| 523 | - public function seek($n = 0, $continue = null) { |
|
| 524 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | - $this->seek_loop($n); |
|
| 526 | - } |
|
| 527 | - $this->pos = $n; |
|
| 528 | - $this->fetched = $n; |
|
| 529 | - |
|
| 530 | - return true; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - /* |
|
| 223 | + // cle et valeur par defaut |
|
| 224 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 225 | + if ( |
|
| 226 | + in_array($nom, ['cle', 'valeur']) |
|
| 227 | + and method_exists($this, $nom) |
|
| 228 | + ) { |
|
| 229 | + return $this->$nom(); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + // Par defaut chercher en xpath dans la valeur() |
|
| 233 | + return table_valeur($this->valeur(), $nom, null); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + |
|
| 237 | + private function calculer_filtres() { |
|
| 238 | + |
|
| 239 | + // Issu de calculer_select() de public/composer L.519 |
|
| 240 | + // TODO: externaliser... |
|
| 241 | + // |
|
| 242 | + // retirer les criteres vides: |
|
| 243 | + // {X ?} avec X absent de l'URL |
|
| 244 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 245 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 246 | + if ($where = &$this->command['where']) { |
|
| 247 | + foreach ($where as $k => $v) { |
|
| 248 | + $this->filtre[] = $this->traduire_condition_sql_en_filtre($v); |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // critere {2,7} |
|
| 253 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 254 | + $limit = explode(',', $this->command['limit']); |
|
| 255 | + $this->offset = $limit[0]; |
|
| 256 | + $this->limit = $limit[1]; |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + // Creer la fonction de filtrage sur $this |
|
| 260 | + if ($this->filtre) { |
|
| 261 | + if ($filtres = $this->assembler_filtres($this->filtre)) { |
|
| 262 | + $filtres = 'return ' . $filtres . ';'; |
|
| 263 | + $this->func_filtre = fn() => eval($filtres); |
|
| 264 | + } |
|
| 265 | + else { |
|
| 266 | + $this->func_filtre = null; |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + /** |
|
| 272 | + * Assembler le tableau de filtres traduits depuis les conditions SQL |
|
| 273 | + * les filtres vides ou null sont ignores |
|
| 274 | + * @param $filtres |
|
| 275 | + * @param string $operateur |
|
| 276 | + * @return string|null |
|
| 277 | + */ |
|
| 278 | + protected function assembler_filtres($filtres, $operateur = 'AND') { |
|
| 279 | + |
|
| 280 | + $filtres_string = []; |
|
| 281 | + foreach ($filtres as $k => $v) { |
|
| 282 | + // si c'est un tableau de OR/AND + 2 sous-filtres, on recurse pour transformer en chaine |
|
| 283 | + if (is_array($v) and in_array(reset($v), ['OR', 'AND'])) { |
|
| 284 | + $op = array_shift($v); |
|
| 285 | + $v = $this->assembler_filtres($v, $op); |
|
| 286 | + } |
|
| 287 | + if (is_null($v) or !is_string($v) or empty($v)) { |
|
| 288 | + continue; |
|
| 289 | + } |
|
| 290 | + $filtres_string[] = $v; |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + if (!count($filtres_string)) { |
|
| 294 | + return null; |
|
| 295 | + } |
|
| 296 | + |
|
| 297 | + return '(' . implode(") $operateur (", $filtres_string) . ')'; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * Traduire un element du tableau where SQL en un filtre |
|
| 302 | + * @param $v |
|
| 303 | + * @return string|array|null |
|
| 304 | + */ |
|
| 305 | + protected function traduire_condition_sql_en_filtre($v) { |
|
| 306 | + if (is_array($v)) { |
|
| 307 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 308 | + return 'true'; |
|
| 309 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 310 | + return 'true'; |
|
| 311 | + } else { |
|
| 312 | + $op = $v[0] ?: $v; |
|
| 313 | + } |
|
| 314 | + } else { |
|
| 315 | + $op = $v; |
|
| 316 | + } |
|
| 317 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 318 | + return 'true'; |
|
| 319 | + } |
|
| 320 | + if ($op === '0=1') { |
|
| 321 | + return 'false'; |
|
| 322 | + } |
|
| 323 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 324 | + if (preg_match(',^\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)$,', $op, $regs)) { |
|
| 325 | + return $this->composer_filtre($regs[1], 'IN', $regs[3], $regs[2]); |
|
| 326 | + } |
|
| 327 | + |
|
| 328 | + // 3 possibilites : count($v) = |
|
| 329 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 330 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 331 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 332 | + |
|
| 333 | + // 1 : forcement traite par un critere, on passe |
|
| 334 | + if (!$v or !is_array($v) or count($v) == 1) { |
|
| 335 | + return null; // sera ignore |
|
| 336 | + } |
|
| 337 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 338 | + return $this->composer_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 339 | + } |
|
| 340 | + if (count($v) == 3) { |
|
| 341 | + // traiter le OR/AND suivi de 2 valeurs |
|
| 342 | + if (in_array($op, ['OR', 'AND'])) { |
|
| 343 | + array_shift($v); |
|
| 344 | + foreach (array_keys($v) as $k) { |
|
| 345 | + $v[$k] = $this->traduire_condition_sql_en_filtre($v[$k]); |
|
| 346 | + if ($v[$k] === null) { |
|
| 347 | + unset($v[$k]); |
|
| 348 | + } |
|
| 349 | + elseif ($v[$k] === 'true') { |
|
| 350 | + if ($op === 'OR') { |
|
| 351 | + return 'true'; |
|
| 352 | + } |
|
| 353 | + if ($op === 'AND') { |
|
| 354 | + unset($v[$k]); |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + elseif ($v[$k] === 'false') { |
|
| 358 | + if ($op === 'OR') { |
|
| 359 | + unset($v[$k]); |
|
| 360 | + } |
|
| 361 | + if ($op === 'AND') { |
|
| 362 | + return 'false'; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + } |
|
| 366 | + if (!count($v)) { |
|
| 367 | + return null; |
|
| 368 | + } |
|
| 369 | + if (count($v) === 1) { |
|
| 370 | + return reset($v); |
|
| 371 | + } |
|
| 372 | + array_unshift($v, $op); |
|
| 373 | + return $v; |
|
| 374 | + } |
|
| 375 | + return $this->composer_filtre($v[1], $v[0], $v[2]); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return null; // sera ignore |
|
| 379 | + } |
|
| 380 | + |
|
| 381 | + /** |
|
| 382 | + * Calculer un filtre sur un champ du tableau |
|
| 383 | + * @param $cle |
|
| 384 | + * @param $op |
|
| 385 | + * @param $valeur |
|
| 386 | + * @param false $not |
|
| 387 | + * @return string|null |
|
| 388 | + */ |
|
| 389 | + protected function composer_filtre($cle, $op, $valeur, $not = false) { |
|
| 390 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 391 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 392 | + return null; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 396 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 397 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 398 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 399 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 400 | + |
|
| 401 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 402 | + # return; |
|
| 403 | + |
|
| 404 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 405 | + |
|
| 406 | + $filtre = ''; |
|
| 407 | + |
|
| 408 | + if ($op == 'REGEXP') { |
|
| 409 | + $filtre = 'filtrer("match", ' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 410 | + $op = ''; |
|
| 411 | + } else { |
|
| 412 | + if ($op == 'LIKE') { |
|
| 413 | + $valeur = str_replace(['\"', '_', '%'], ['"', '.', '.*'], preg_quote($valeur)); |
|
| 414 | + $filtre = 'filtrer("match", ' . $a . ', ' . $valeur . ')'; |
|
| 415 | + $op = ''; |
|
| 416 | + } else { |
|
| 417 | + if ($op == '=') { |
|
| 418 | + $op = '=='; |
|
| 419 | + } else { |
|
| 420 | + if ($op == 'IN') { |
|
| 421 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 422 | + $op = ''; |
|
| 423 | + } else { |
|
| 424 | + if (!in_array($op, ['<', '<=', '>', '>='])) { |
|
| 425 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 426 | + $op = ''; |
|
| 427 | + } |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($op) { |
|
| 434 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + if ($not) { |
|
| 438 | + $filtre = "!($filtre)"; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + return $filtre; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + |
|
| 445 | + public function next(): void { |
|
| 446 | + $this->pos++; |
|
| 447 | + parent::next(); |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * revient au depart |
|
| 452 | + * |
|
| 453 | + * @return void |
|
| 454 | + */ |
|
| 455 | + public function rewind(): void { |
|
| 456 | + $this->pos = 0; |
|
| 457 | + $this->fetched = 0; |
|
| 458 | + parent::rewind(); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + # Extension SPIP des iterateurs PHP |
|
| 463 | + /** |
|
| 464 | + * type de l'iterateur |
|
| 465 | + * |
|
| 466 | + * @var string |
|
| 467 | + */ |
|
| 468 | + protected $type; |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * parametres de l'iterateur |
|
| 472 | + * |
|
| 473 | + * @var array |
|
| 474 | + */ |
|
| 475 | + protected $command; |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * infos de compilateur |
|
| 479 | + * |
|
| 480 | + * @var array |
|
| 481 | + */ |
|
| 482 | + protected $info; |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * position courante de l'iterateur |
|
| 486 | + * |
|
| 487 | + * @var int |
|
| 488 | + */ |
|
| 489 | + protected $pos = null; |
|
| 490 | + |
|
| 491 | + /** |
|
| 492 | + * nombre total resultats dans l'iterateur |
|
| 493 | + * |
|
| 494 | + * @var int |
|
| 495 | + */ |
|
| 496 | + protected $total = null; |
|
| 497 | + |
|
| 498 | + /** |
|
| 499 | + * nombre maximal de recherche pour $total |
|
| 500 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 501 | + */ |
|
| 502 | + protected $max = 100000; |
|
| 503 | + |
|
| 504 | + |
|
| 505 | + /** |
|
| 506 | + * Liste des champs a inserer dans les $row |
|
| 507 | + * retournes par ->fetch() |
|
| 508 | + */ |
|
| 509 | + protected $select = []; |
|
| 510 | + |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * aller a la position absolue n, |
|
| 514 | + * comptee depuis le debut |
|
| 515 | + * |
|
| 516 | + * @param int $n |
|
| 517 | + * absolute pos |
|
| 518 | + * @param string $continue |
|
| 519 | + * param for sql_ api |
|
| 520 | + * @return bool |
|
| 521 | + * success or fail if not implemented |
|
| 522 | + */ |
|
| 523 | + public function seek($n = 0, $continue = null) { |
|
| 524 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 525 | + $this->seek_loop($n); |
|
| 526 | + } |
|
| 527 | + $this->pos = $n; |
|
| 528 | + $this->fetched = $n; |
|
| 529 | + |
|
| 530 | + return true; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + /* |
|
| 534 | 534 | * aller a la position $n en parcourant |
| 535 | 535 | * un par un tous les elements |
| 536 | 536 | */ |
| 537 | - private function seek_loop($n) { |
|
| 538 | - if ($this->pos > $n) { |
|
| 539 | - $this->rewind(); |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - while ($this->pos < $n and $this->valid()) { |
|
| 543 | - $this->next(); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return true; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Avancer de $saut pas |
|
| 551 | - * |
|
| 552 | - * @param $saut |
|
| 553 | - * @param $max |
|
| 554 | - * @return int |
|
| 555 | - */ |
|
| 556 | - public function skip($saut, $max = null) { |
|
| 557 | - // pas de saut en arriere autorise pour cette fonction |
|
| 558 | - if (($saut = intval($saut)) <= 0) { |
|
| 559 | - return $this->pos; |
|
| 560 | - } |
|
| 561 | - $seek = $this->pos + $saut; |
|
| 562 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | - // et on sort |
|
| 564 | - if (is_null($max)) { |
|
| 565 | - $max = $this->count(); |
|
| 566 | - } |
|
| 567 | - |
|
| 568 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | - $this->free(); |
|
| 571 | - |
|
| 572 | - return $max; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - $this->seek($seek); |
|
| 576 | - |
|
| 577 | - return $this->pos; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Renvoyer un tableau des donnees correspondantes |
|
| 582 | - * a la position courante de l'iterateur |
|
| 583 | - * en controlant si on respecte le filtre |
|
| 584 | - * Appliquer aussi le critere {offset,limit} |
|
| 585 | - * |
|
| 586 | - * @return array|bool |
|
| 587 | - */ |
|
| 588 | - public function fetch() { |
|
| 589 | - if (method_exists($this->iter, 'fetch')) { |
|
| 590 | - return $this->iter->fetch(); |
|
| 591 | - } else { |
|
| 592 | - while ( |
|
| 593 | - $this->valid() |
|
| 594 | - and ( |
|
| 595 | - !$this->accept() |
|
| 596 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | - ) |
|
| 598 | - ) { |
|
| 599 | - $this->next(); |
|
| 600 | - } |
|
| 601 | - |
|
| 602 | - if (!$this->valid()) { |
|
| 603 | - return false; |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - if ( |
|
| 607 | - isset($this->limit) |
|
| 608 | - and $this->fetched > $this->offset + $this->limit |
|
| 609 | - ) { |
|
| 610 | - return false; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $r = []; |
|
| 614 | - foreach ($this->select as $nom) { |
|
| 615 | - $r[$nom] = $this->get_select($nom); |
|
| 616 | - } |
|
| 617 | - $this->next(); |
|
| 618 | - |
|
| 619 | - return $r; |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // retourner la cle pour #CLE |
|
| 624 | - public function cle() { |
|
| 625 | - return $this->key(); |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - // retourner la valeur pour #VALEUR |
|
| 629 | - public function valeur() { |
|
| 630 | - return $this->current(); |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - /** |
|
| 634 | - * Accepte-t-on l'entree courante lue ? |
|
| 635 | - * On execute les filtres pour le savoir. |
|
| 636 | - **/ |
|
| 637 | - public function accept(): bool { |
|
| 638 | - if ($f = $this->func_filtre) { |
|
| 639 | - return $f(); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - return true; |
|
| 643 | - } |
|
| 644 | - |
|
| 645 | - /** |
|
| 646 | - * liberer la ressource |
|
| 647 | - * |
|
| 648 | - * @return bool |
|
| 649 | - */ |
|
| 650 | - public function free() { |
|
| 651 | - if (method_exists($this->iter, 'free')) { |
|
| 652 | - $this->iter->free(); |
|
| 653 | - } |
|
| 654 | - $this->pos = $this->total = 0; |
|
| 655 | - |
|
| 656 | - return true; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * Compter le nombre total de resultats |
|
| 661 | - * pour #TOTAL_BOUCLE |
|
| 662 | - * |
|
| 663 | - * @return int |
|
| 664 | - */ |
|
| 665 | - public function count() { |
|
| 666 | - if (is_null($this->total)) { |
|
| 667 | - if ( |
|
| 668 | - method_exists($this->iter, 'count') |
|
| 669 | - and !$this->func_filtre |
|
| 670 | - ) { |
|
| 671 | - return $this->total = $this->iter->count(); |
|
| 672 | - } else { |
|
| 673 | - // compter les lignes et rembobiner |
|
| 674 | - $total = 0; |
|
| 675 | - $pos = $this->pos; // sauver la position |
|
| 676 | - $this->rewind(); |
|
| 677 | - while ($this->fetch() and $total < $this->max) { |
|
| 678 | - $total++; |
|
| 679 | - } |
|
| 680 | - $this->seek($pos); |
|
| 681 | - $this->total = $total; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return $this->total; |
|
| 686 | - } |
|
| 537 | + private function seek_loop($n) { |
|
| 538 | + if ($this->pos > $n) { |
|
| 539 | + $this->rewind(); |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + while ($this->pos < $n and $this->valid()) { |
|
| 543 | + $this->next(); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return true; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Avancer de $saut pas |
|
| 551 | + * |
|
| 552 | + * @param $saut |
|
| 553 | + * @param $max |
|
| 554 | + * @return int |
|
| 555 | + */ |
|
| 556 | + public function skip($saut, $max = null) { |
|
| 557 | + // pas de saut en arriere autorise pour cette fonction |
|
| 558 | + if (($saut = intval($saut)) <= 0) { |
|
| 559 | + return $this->pos; |
|
| 560 | + } |
|
| 561 | + $seek = $this->pos + $saut; |
|
| 562 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 563 | + // et on sort |
|
| 564 | + if (is_null($max)) { |
|
| 565 | + $max = $this->count(); |
|
| 566 | + } |
|
| 567 | + |
|
| 568 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 569 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 570 | + $this->free(); |
|
| 571 | + |
|
| 572 | + return $max; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + $this->seek($seek); |
|
| 576 | + |
|
| 577 | + return $this->pos; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Renvoyer un tableau des donnees correspondantes |
|
| 582 | + * a la position courante de l'iterateur |
|
| 583 | + * en controlant si on respecte le filtre |
|
| 584 | + * Appliquer aussi le critere {offset,limit} |
|
| 585 | + * |
|
| 586 | + * @return array|bool |
|
| 587 | + */ |
|
| 588 | + public function fetch() { |
|
| 589 | + if (method_exists($this->iter, 'fetch')) { |
|
| 590 | + return $this->iter->fetch(); |
|
| 591 | + } else { |
|
| 592 | + while ( |
|
| 593 | + $this->valid() |
|
| 594 | + and ( |
|
| 595 | + !$this->accept() |
|
| 596 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 597 | + ) |
|
| 598 | + ) { |
|
| 599 | + $this->next(); |
|
| 600 | + } |
|
| 601 | + |
|
| 602 | + if (!$this->valid()) { |
|
| 603 | + return false; |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + if ( |
|
| 607 | + isset($this->limit) |
|
| 608 | + and $this->fetched > $this->offset + $this->limit |
|
| 609 | + ) { |
|
| 610 | + return false; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $r = []; |
|
| 614 | + foreach ($this->select as $nom) { |
|
| 615 | + $r[$nom] = $this->get_select($nom); |
|
| 616 | + } |
|
| 617 | + $this->next(); |
|
| 618 | + |
|
| 619 | + return $r; |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // retourner la cle pour #CLE |
|
| 624 | + public function cle() { |
|
| 625 | + return $this->key(); |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + // retourner la valeur pour #VALEUR |
|
| 629 | + public function valeur() { |
|
| 630 | + return $this->current(); |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + /** |
|
| 634 | + * Accepte-t-on l'entree courante lue ? |
|
| 635 | + * On execute les filtres pour le savoir. |
|
| 636 | + **/ |
|
| 637 | + public function accept(): bool { |
|
| 638 | + if ($f = $this->func_filtre) { |
|
| 639 | + return $f(); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + return true; |
|
| 643 | + } |
|
| 644 | + |
|
| 645 | + /** |
|
| 646 | + * liberer la ressource |
|
| 647 | + * |
|
| 648 | + * @return bool |
|
| 649 | + */ |
|
| 650 | + public function free() { |
|
| 651 | + if (method_exists($this->iter, 'free')) { |
|
| 652 | + $this->iter->free(); |
|
| 653 | + } |
|
| 654 | + $this->pos = $this->total = 0; |
|
| 655 | + |
|
| 656 | + return true; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * Compter le nombre total de resultats |
|
| 661 | + * pour #TOTAL_BOUCLE |
|
| 662 | + * |
|
| 663 | + * @return int |
|
| 664 | + */ |
|
| 665 | + public function count() { |
|
| 666 | + if (is_null($this->total)) { |
|
| 667 | + if ( |
|
| 668 | + method_exists($this->iter, 'count') |
|
| 669 | + and !$this->func_filtre |
|
| 670 | + ) { |
|
| 671 | + return $this->total = $this->iter->count(); |
|
| 672 | + } else { |
|
| 673 | + // compter les lignes et rembobiner |
|
| 674 | + $total = 0; |
|
| 675 | + $pos = $this->pos; // sauver la position |
|
| 676 | + $this->rewind(); |
|
| 677 | + while ($this->fetch() and $total < $this->max) { |
|
| 678 | + $total++; |
|
| 679 | + } |
|
| 680 | + $this->seek($pos); |
|
| 681 | + $this->total = $total; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return $this->total; |
|
| 686 | + } |
|
| 687 | 687 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 50 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @return void |
| 66 | 66 | **/ |
| 67 | 67 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 68 | - $not = $crit->not; |
|
| 69 | - $boucle = &$boucles[$idb]; |
|
| 70 | - $id = $boucle->primary; |
|
| 71 | - |
|
| 72 | - if ($not or !$id) { |
|
| 73 | - return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 74 | - } |
|
| 75 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 68 | + $not = $crit->not; |
|
| 69 | + $boucle = &$boucles[$idb]; |
|
| 70 | + $id = $boucle->primary; |
|
| 71 | + |
|
| 72 | + if ($not or !$id) { |
|
| 73 | + return (['zbug_critere_inconnu', ['critere' => $not . $crit->op]]); |
|
| 74 | + } |
|
| 75 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -93,73 +93,73 @@ discard block |
||
| 93 | 93 | * @return void |
| 94 | 94 | **/ |
| 95 | 95 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 96 | - $boucle = &$boucles[$idb]; |
|
| 97 | - $primary = $boucle->primary; |
|
| 98 | - |
|
| 99 | - // la table nécessite une clé primaire, non composée |
|
| 100 | - if (!$primary or strpos($primary, ',')) { |
|
| 101 | - return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | - |
|
| 106 | - // le doublon s'applique sur un type de boucle (article) |
|
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | - |
|
| 109 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | - // on obtient $nom = "'article' . 'nom'" |
|
| 111 | - if (isset($crit->param[0])) { |
|
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | - |
|
| 119 | - // on crée un sql_in avec la clé primaire de la table |
|
| 120 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | - // $doublons et son index, ici $nom |
|
| 122 | - |
|
| 123 | - // debut du code "sql_in('articles.id_article', " |
|
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | - |
|
| 129 | - // le debut complet du code des doublons |
|
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | - |
|
| 132 | - // nom du doublon "('article' . 'nom')]" |
|
| 133 | - $fin_doub = "($nom)]"; |
|
| 134 | - |
|
| 135 | - // si on trouve un autre critère doublon, |
|
| 136 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | - foreach ($boucle->where as $k => $w) { |
|
| 138 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | - // fusionner le sql_in (du where) |
|
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | - $x = strpos($boucle->hash, $init_comment); |
|
| 143 | - $len = strlen($init_comment); |
|
| 144 | - $boucle->hash = |
|
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | - |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | - |
|
| 154 | - // déclarer le doublon s'il n'existe pas encore |
|
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | - # {!doublons A}{doublons B} |
|
| 161 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 96 | + $boucle = &$boucles[$idb]; |
|
| 97 | + $primary = $boucle->primary; |
|
| 98 | + |
|
| 99 | + // la table nécessite une clé primaire, non composée |
|
| 100 | + if (!$primary or strpos($primary, ',')) { |
|
| 101 | + return (['zbug_doublon_sur_table_sans_cle_primaire']); |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | + |
|
| 106 | + // le doublon s'applique sur un type de boucle (article) |
|
| 107 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + |
|
| 109 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | + // on obtient $nom = "'article' . 'nom'" |
|
| 111 | + if (isset($crit->param[0])) { |
|
| 112 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | + |
|
| 119 | + // on crée un sql_in avec la clé primaire de la table |
|
| 120 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | + // $doublons et son index, ici $nom |
|
| 122 | + |
|
| 123 | + // debut du code "sql_in('articles.id_article', " |
|
| 124 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + |
|
| 129 | + // le debut complet du code des doublons |
|
| 130 | + $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + |
|
| 132 | + // nom du doublon "('article' . 'nom')]" |
|
| 133 | + $fin_doub = "($nom)]"; |
|
| 134 | + |
|
| 135 | + // si on trouve un autre critère doublon, |
|
| 136 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | + foreach ($boucle->where as $k => $w) { |
|
| 138 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | + // fusionner le sql_in (du where) |
|
| 140 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | + $x = strpos($boucle->hash, $init_comment); |
|
| 143 | + $len = strlen($init_comment); |
|
| 144 | + $boucle->hash = |
|
| 145 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + |
|
| 154 | + // déclarer le doublon s'il n'existe pas encore |
|
| 155 | + $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | + # {!doublons A}{doublons B} |
|
| 161 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | **/ |
| 182 | 182 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 183 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | - $param = 'oui'; |
|
| 185 | - } |
|
| 186 | - if ($crit->not) { |
|
| 187 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | - } |
|
| 189 | - $boucle = &$boucles[$idb]; |
|
| 190 | - $boucle->lang_select = $param; |
|
| 183 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | + $param = 'oui'; |
|
| 185 | + } |
|
| 186 | + if ($crit->not) { |
|
| 187 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | + } |
|
| 189 | + $boucle = &$boucles[$idb]; |
|
| 190 | + $boucle->lang_select = $param; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * @return void |
| 210 | 210 | **/ |
| 211 | 211 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 212 | - [$un, $deux] = $crit->param; |
|
| 213 | - $un = $un[0]->texte; |
|
| 214 | - $deux = $deux[0]->texte; |
|
| 215 | - if ($deux) { |
|
| 216 | - $boucles[$idb]->limit = |
|
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | - } else { |
|
| 219 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | - } |
|
| 212 | + [$un, $deux] = $crit->param; |
|
| 213 | + $un = $un[0]->texte; |
|
| 214 | + $deux = $deux[0]->texte; |
|
| 215 | + if ($deux) { |
|
| 216 | + $boucles[$idb]->limit = |
|
| 217 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + } else { |
|
| 219 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -251,58 +251,58 @@ discard block |
||
| 251 | 251 | **/ |
| 252 | 252 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 253 | 253 | |
| 254 | - $boucle = &$boucles[$idb]; |
|
| 255 | - // definition de la taille de la page |
|
| 256 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | - |
|
| 259 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | - } else { |
|
| 262 | - $r = intval($r[2]); |
|
| 263 | - $pas = strval($r ?: 10); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Calcul du nommage de la pagination si il existe. |
|
| 267 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | - $type = "'$idb'"; |
|
| 270 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | - // Syntaxe {pagination 20, nom} |
|
| 272 | - if (isset($crit->param[0][1])) { |
|
| 273 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | - elseif (isset($crit->param[1][0])) { |
|
| 276 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | - $partie = |
|
| 282 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | - . "\t}\n" |
|
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | - |
|
| 290 | - $boucle->hash .= ' |
|
| 254 | + $boucle = &$boucles[$idb]; |
|
| 255 | + // definition de la taille de la page |
|
| 256 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | + |
|
| 259 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | + } else { |
|
| 262 | + $r = intval($r[2]); |
|
| 263 | + $pas = strval($r ?: 10); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Calcul du nommage de la pagination si il existe. |
|
| 267 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | + $type = "'$idb'"; |
|
| 270 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | + // Syntaxe {pagination 20, nom} |
|
| 272 | + if (isset($crit->param[0][1])) { |
|
| 273 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | + elseif (isset($crit->param[1][0])) { |
|
| 276 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | + $partie = |
|
| 282 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | + . "\t}\n" |
|
| 288 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + |
|
| 290 | + $boucle->hash .= ' |
|
| 291 | 291 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 292 | 292 | |
| 293 | - $boucle->total_parties = $pas; |
|
| 294 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | - // sauf si pas de primaire, ou si primaire composee |
|
| 297 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | - if ( |
|
| 300 | - $boucle->primary |
|
| 301 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | - and !in_array($t, $boucle->select) |
|
| 303 | - ) { |
|
| 304 | - $boucle->select[] = $t; |
|
| 305 | - } |
|
| 293 | + $boucle->total_parties = $pas; |
|
| 294 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | + // sauf si pas de primaire, ou si primaire composee |
|
| 297 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + if ( |
|
| 300 | + $boucle->primary |
|
| 301 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | + and !in_array($t, $boucle->select) |
|
| 303 | + ) { |
|
| 304 | + $boucle->select[] = $t; |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | **/ |
| 325 | 325 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 326 | 326 | |
| 327 | - $boucle = &$boucles[$idb]; |
|
| 327 | + $boucle = &$boucles[$idb]; |
|
| 328 | 328 | |
| 329 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 329 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | 331 | |
| 332 | - return; |
|
| 333 | - } |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if (isset($crit->param[0])) { |
|
| 336 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | - } else { |
|
| 338 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | - } |
|
| 335 | + if (isset($crit->param[0])) { |
|
| 336 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | + } else { |
|
| 338 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | - $boucle->hash .= ' |
|
| 341 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | + $boucle->hash .= ' |
|
| 343 | 343 | // RECHERCHE' |
| 344 | - . ($crit->cond ? ' |
|
| 344 | + . ($crit->cond ? ' |
|
| 345 | 345 | if (!strlen(' . $quoi . ')){ |
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | 347 | } else' : '') . ' |
@@ -352,21 +352,21 @@ discard block |
||
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | - $boucle->select[] = $t; |
|
| 358 | - } # pour postgres, neuneu ici |
|
| 359 | - // jointure uniquement sur le serveur principal |
|
| 360 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | - if (!$boucle->sql_serveur) { |
|
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | - } |
|
| 365 | - $boucle->select[] = '$rech_select'; |
|
| 366 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | - |
|
| 368 | - // et la recherche trouve |
|
| 369 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 355 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | + $boucle->select[] = $t; |
|
| 358 | + } # pour postgres, neuneu ici |
|
| 359 | + // jointure uniquement sur le serveur principal |
|
| 360 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | + if (!$boucle->sql_serveur) { |
|
| 362 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | + } |
|
| 365 | + $boucle->select[] = '$rech_select'; |
|
| 366 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | + |
|
| 368 | + // et la recherche trouve |
|
| 369 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * @return void |
| 384 | 384 | **/ |
| 385 | 385 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 386 | - $boucle = &$boucles[$idb]; |
|
| 387 | - $prim = $boucle->primary; |
|
| 388 | - $table = $boucle->id_table; |
|
| 389 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | - $boucle->where[] = |
|
| 392 | - [ |
|
| 393 | - "'OR'", |
|
| 394 | - [ |
|
| 395 | - "'AND'", |
|
| 396 | - ["'='", "'$table.id_trad'", 0], |
|
| 397 | - ["'='", "'$table.$prim'", $dprim] |
|
| 398 | - ], |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'>'", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.id_trad'", $arg] |
|
| 403 | - ] |
|
| 404 | - ]; |
|
| 386 | + $boucle = &$boucles[$idb]; |
|
| 387 | + $prim = $boucle->primary; |
|
| 388 | + $table = $boucle->id_table; |
|
| 389 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | + $boucle->where[] = |
|
| 392 | + [ |
|
| 393 | + "'OR'", |
|
| 394 | + [ |
|
| 395 | + "'AND'", |
|
| 396 | + ["'='", "'$table.id_trad'", 0], |
|
| 397 | + ["'='", "'$table.$prim'", $dprim] |
|
| 398 | + ], |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'>'", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.id_trad'", $arg] |
|
| 403 | + ] |
|
| 404 | + ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @return void |
| 420 | 420 | **/ |
| 421 | 421 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 422 | - $boucle = &$boucles[$idb]; |
|
| 423 | - $prim = $boucle->primary; |
|
| 424 | - $table = $boucle->id_table; |
|
| 425 | - |
|
| 426 | - $c = |
|
| 427 | - [ |
|
| 428 | - "'OR'", |
|
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | - ]; |
|
| 432 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 422 | + $boucle = &$boucles[$idb]; |
|
| 423 | + $prim = $boucle->primary; |
|
| 424 | + $table = $boucle->id_table; |
|
| 425 | + |
|
| 426 | + $c = |
|
| 427 | + [ |
|
| 428 | + "'OR'", |
|
| 429 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | + ]; |
|
| 432 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | **/ |
| 447 | 447 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 448 | 448 | |
| 449 | - $boucle = &$boucles[$idb]; |
|
| 450 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | - |
|
| 454 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | - else { |
|
| 458 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 459 | - } |
|
| 449 | + $boucle = &$boucles[$idb]; |
|
| 450 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + |
|
| 454 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | + else { |
|
| 458 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]); |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -487,37 +487,37 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 489 | 489 | |
| 490 | - $not = $crit->not; |
|
| 491 | - $boucle = &$boucles[$idb]; |
|
| 492 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | - if (isset($crit->param[0])) { |
|
| 494 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | - // sinon on le prend chez une boucle parente |
|
| 496 | - } else { |
|
| 497 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - //Trouver une jointure |
|
| 501 | - $champ = 'id_rubrique'; |
|
| 502 | - $desc = $boucle->show; |
|
| 503 | - //Seulement si necessaire |
|
| 504 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | - $decompose = decompose_champ_id_objet($champ); |
|
| 510 | - $champ = array_shift($decompose); |
|
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - $cle = $boucle->id_table; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 490 | + $not = $crit->not; |
|
| 491 | + $boucle = &$boucles[$idb]; |
|
| 492 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | + if (isset($crit->param[0])) { |
|
| 494 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | + // sinon on le prend chez une boucle parente |
|
| 496 | + } else { |
|
| 497 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + //Trouver une jointure |
|
| 501 | + $champ = 'id_rubrique'; |
|
| 502 | + $desc = $boucle->show; |
|
| 503 | + //Seulement si necessaire |
|
| 504 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | + $decompose = decompose_champ_id_objet($champ); |
|
| 510 | + $champ = array_shift($decompose); |
|
| 511 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $cle = $boucle->id_table; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 535 | 535 | |
| 536 | - $boucle = &$boucles[$idb]; |
|
| 537 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | - $serveur = $boucle->sql_serveur; |
|
| 536 | + $boucle = &$boucles[$idb]; |
|
| 537 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | + $serveur = $boucle->sql_serveur; |
|
| 539 | 539 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 540 | + $c = "sql_in('" . |
|
| 541 | + $boucle->id_table . '.' . $boucle->primary |
|
| 542 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | 543 | |
| 544 | - $boucle->where[] = $c; |
|
| 544 | + $boucle->where[] = $c; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -563,31 +563,31 @@ discard block |
||
| 563 | 563 | * @return void |
| 564 | 564 | **/ |
| 565 | 565 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 566 | - if ($t = isset($crit->param[0])) { |
|
| 567 | - $t = $crit->param[0]; |
|
| 568 | - if ($t[0]->type == 'texte') { |
|
| 569 | - $t = $t[0]->texte; |
|
| 570 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | - $t = table_objet_sql($r[1]); |
|
| 572 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | - if ($t) { |
|
| 574 | - $t .= '.' . $r[2]; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $t = '".' |
|
| 579 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | - . '."'; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - if ($t) { |
|
| 584 | - $boucles[$idb]->group[] = $t; |
|
| 585 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | - $boucles[$idb]->select[] = $t; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 590 | - } |
|
| 566 | + if ($t = isset($crit->param[0])) { |
|
| 567 | + $t = $crit->param[0]; |
|
| 568 | + if ($t[0]->type == 'texte') { |
|
| 569 | + $t = $t[0]->texte; |
|
| 570 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | + $t = table_objet_sql($r[1]); |
|
| 572 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | + if ($t) { |
|
| 574 | + $t .= '.' . $r[2]; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } else { |
|
| 578 | + $t = '".' |
|
| 579 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | + . '."'; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + if ($t) { |
|
| 584 | + $boucles[$idb]->group[] = $t; |
|
| 585 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | + $boucles[$idb]->select[] = $t; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @return void |
| 608 | 608 | **/ |
| 609 | 609 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 610 | - $boucles[$idb]->group = []; |
|
| 610 | + $boucles[$idb]->group = []; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -644,44 +644,44 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 647 | - if (isset($crit->param[0])) { |
|
| 648 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | - $boucle = $boucles[$idb]; |
|
| 650 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | - if ( |
|
| 656 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | - ) { |
|
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | - } else { |
|
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | - } |
|
| 647 | + if (isset($crit->param[0])) { |
|
| 648 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | + $boucle = $boucles[$idb]; |
|
| 650 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | + if ( |
|
| 656 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | + ) { |
|
| 659 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + } else { |
|
| 661 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | + } |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | - $boucle = $boucles[$idb]; |
|
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 673 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | - if (!$desc) { |
|
| 675 | - $desc = $boucle->show['field']; |
|
| 676 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | - } |
|
| 679 | - if ($desc) { |
|
| 680 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | - } |
|
| 682 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | - |
|
| 684 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 670 | + $boucle = $boucles[$idb]; |
|
| 671 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | + $var = '$champs_' . $idb; |
|
| 673 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | + if (!$desc) { |
|
| 675 | + $desc = $boucle->show['field']; |
|
| 676 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | + } |
|
| 679 | + if ($desc) { |
|
| 680 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | + } |
|
| 682 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | + |
|
| 684 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 721 | 721 | */ |
| 722 | 722 | function critere_par_dist($idb, &$boucles, $crit) { |
| 723 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 723 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -742,93 +742,93 @@ discard block |
||
| 742 | 742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 743 | 743 | */ |
| 744 | 744 | function critere_parinverse($idb, &$boucles, $crit) { |
| 745 | - $boucle = &$boucles[$idb]; |
|
| 746 | - |
|
| 747 | - $sens = $collecte = ''; |
|
| 748 | - if ($crit->not) { |
|
| 749 | - $sens = " . ' DESC'"; |
|
| 750 | - } |
|
| 751 | - if (isset($boucle->modificateur['collate'])) { |
|
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // Pour chaque paramètre du critère |
|
| 756 | - foreach ($crit->param as $tri) { |
|
| 757 | - $order = $fct = ''; |
|
| 758 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | - if ($tri[0]->type != 'texte') { |
|
| 760 | - // calculer le order dynamique qui verifie les champs |
|
| 761 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | - } |
|
| 765 | - // tris textuels {par titre} |
|
| 766 | - else { |
|
| 767 | - $par = array_shift($tri); |
|
| 768 | - $par = $par->texte; |
|
| 769 | - |
|
| 770 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | - $expression = trim($m[1]); |
|
| 773 | - $champ = trim($m[2]); |
|
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | - } else { |
|
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | - // {par FONCTION(champ)} |
|
| 783 | - if (isset($match) and count($match) > 2) { |
|
| 784 | - $par = substr($match[2], 1, -1); |
|
| 785 | - $fct = $match[1]; |
|
| 786 | - } |
|
| 787 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | - if ($par == 'hasard') { |
|
| 789 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | - } else { |
|
| 793 | - // cas général {par champ}, {par table.champ}, ... |
|
| 794 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // on ne sait pas traiter… |
|
| 799 | - else { |
|
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | - if (is_array($order)) { |
|
| 805 | - return $order; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | - $t = $m[1]; |
|
| 811 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | - $boucle->select[] = $t; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - $sens = ''; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($fct) { |
|
| 819 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | - } else { |
|
| 822 | - $order = "'$fct(' . $order . ')'"; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $t = $order . $collecte . $sens; |
|
| 826 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | - $t = $r[1] . $r[2]; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $boucle->order[] = $t; |
|
| 831 | - } |
|
| 745 | + $boucle = &$boucles[$idb]; |
|
| 746 | + |
|
| 747 | + $sens = $collecte = ''; |
|
| 748 | + if ($crit->not) { |
|
| 749 | + $sens = " . ' DESC'"; |
|
| 750 | + } |
|
| 751 | + if (isset($boucle->modificateur['collate'])) { |
|
| 752 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // Pour chaque paramètre du critère |
|
| 756 | + foreach ($crit->param as $tri) { |
|
| 757 | + $order = $fct = ''; |
|
| 758 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | + if ($tri[0]->type != 'texte') { |
|
| 760 | + // calculer le order dynamique qui verifie les champs |
|
| 761 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | + } |
|
| 765 | + // tris textuels {par titre} |
|
| 766 | + else { |
|
| 767 | + $par = array_shift($tri); |
|
| 768 | + $par = $par->texte; |
|
| 769 | + |
|
| 770 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | + $expression = trim($m[1]); |
|
| 773 | + $champ = trim($m[2]); |
|
| 774 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | + } else { |
|
| 777 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | + // {par FONCTION(champ)} |
|
| 783 | + if (isset($match) and count($match) > 2) { |
|
| 784 | + $par = substr($match[2], 1, -1); |
|
| 785 | + $fct = $match[1]; |
|
| 786 | + } |
|
| 787 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | + if ($par == 'hasard') { |
|
| 789 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | + } else { |
|
| 793 | + // cas général {par champ}, {par table.champ}, ... |
|
| 794 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // on ne sait pas traiter… |
|
| 799 | + else { |
|
| 800 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | + if (is_array($order)) { |
|
| 805 | + return $order; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | + $t = $m[1]; |
|
| 811 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | + $boucle->select[] = $t; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + $sens = ''; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($fct) { |
|
| 819 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | + } else { |
|
| 822 | + $order = "'$fct(' . $order . ')'"; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $t = $order . $collecte . $sens; |
|
| 826 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | + $t = $r[1] . $r[2]; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $boucle->order[] = $t; |
|
| 831 | + } |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -842,13 +842,13 @@ discard block |
||
| 842 | 842 | * @return string Clause pour le Order by |
| 843 | 843 | */ |
| 844 | 844 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 845 | - $boucle = &$boucles[$idb]; |
|
| 846 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | - $parha = 'rand() AS hasard'; |
|
| 848 | - if (!in_array($parha, $boucle->select)) { |
|
| 849 | - $boucle->select[] = $parha; |
|
| 850 | - } |
|
| 851 | - return "'hasard'"; |
|
| 845 | + $boucle = &$boucles[$idb]; |
|
| 846 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | + $parha = 'rand() AS hasard'; |
|
| 848 | + if (!in_array($parha, $boucle->select)) { |
|
| 849 | + $boucle->select[] = $parha; |
|
| 850 | + } |
|
| 851 | + return "'hasard'"; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -872,24 +872,24 @@ discard block |
||
| 872 | 872 | * @return string Clause pour le Order by |
| 873 | 873 | */ |
| 874 | 874 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | - if (is_array($_champ)) { |
|
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | - } |
|
| 879 | - $boucle = &$boucles[$idb]; |
|
| 880 | - $texte = '0+' . $_champ; |
|
| 881 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | - if ($suite !== "''") { |
|
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | - } |
|
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | - |
|
| 888 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | - $orderassinum = trim($orderassinum, "'"); |
|
| 890 | - |
|
| 891 | - $order = "'$orderassinum, $asnum'"; |
|
| 892 | - return $order; |
|
| 875 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | + if (is_array($_champ)) { |
|
| 877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | + } |
|
| 879 | + $boucle = &$boucles[$idb]; |
|
| 880 | + $texte = '0+' . $_champ; |
|
| 881 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | + if ($suite !== "''") { |
|
| 883 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | + } |
|
| 885 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + |
|
| 888 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | + $orderassinum = trim($orderassinum, "'"); |
|
| 890 | + |
|
| 891 | + $order = "'$orderassinum, $asnum'"; |
|
| 892 | + return $order; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -910,35 +910,35 @@ discard block |
||
| 910 | 910 | * @return string Clause pour le Order by |
| 911 | 911 | */ |
| 912 | 912 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | - if (is_array($_champ)) { |
|
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | - } |
|
| 917 | - $boucle = &$boucles[$idb]; |
|
| 918 | - $texte = '0+' . $_champ; |
|
| 919 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | - if ($suite !== "''") { |
|
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $as = false; |
|
| 925 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | - foreach ($boucle->select as $s) { |
|
| 927 | - if (strpos($s, $select) === 0) { |
|
| 928 | - $as = trim(substr($s, strlen($select))); |
|
| 929 | - if (!preg_match(',\W,', $as)) { |
|
| 930 | - break; |
|
| 931 | - } |
|
| 932 | - $as = false; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if (!$as) { |
|
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 939 | - } |
|
| 940 | - $order = "'$as'"; |
|
| 941 | - return $order; |
|
| 913 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | + if (is_array($_champ)) { |
|
| 915 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + } |
|
| 917 | + $boucle = &$boucles[$idb]; |
|
| 918 | + $texte = '0+' . $_champ; |
|
| 919 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | + if ($suite !== "''") { |
|
| 921 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $as = false; |
|
| 925 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | + foreach ($boucle->select as $s) { |
|
| 927 | + if (strpos($s, $select) === 0) { |
|
| 928 | + $as = trim(substr($s, strlen($select))); |
|
| 929 | + if (!preg_match(',\W,', $as)) { |
|
| 930 | + break; |
|
| 931 | + } |
|
| 932 | + $as = false; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + if (!$as) { |
|
| 937 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | + $boucle->select[] = $select . $as; |
|
| 939 | + } |
|
| 940 | + $order = "'$as'"; |
|
| 941 | + return $order; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @return string Clause pour le Order by |
| 959 | 959 | */ |
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | - if (is_array($_champ)) { |
|
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | - } |
|
| 965 | - $boucle = &$boucles[$idb]; |
|
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | - $order = "'multi'"; |
|
| 968 | - return $order; |
|
| 961 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | + if (is_array($_champ)) { |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | + } |
|
| 965 | + $boucle = &$boucles[$idb]; |
|
| 966 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | + $order = "'multi'"; |
|
| 968 | + return $order; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,56 +984,56 @@ discard block |
||
| 984 | 984 | * @return array|string |
| 985 | 985 | */ |
| 986 | 986 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 987 | - $boucle = &$boucles[$idb]; |
|
| 988 | - $desc = $boucle->show; |
|
| 989 | - |
|
| 990 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | - if (isset($desc['field'][$par])) { |
|
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 993 | - } |
|
| 994 | - // le champ est peut être une jointure |
|
| 995 | - else { |
|
| 996 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | - $champ = $par; |
|
| 998 | - |
|
| 999 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | - [, $table, $champ] = $r; |
|
| 1005 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | - $table = table_objet_sql($table); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | - } elseif ( |
|
| 1015 | - $boucle->jointures_explicites |
|
| 1016 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | - ) { |
|
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1019 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1021 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | - } elseif ( |
|
| 1023 | - $table_alias |
|
| 1024 | - and isset($boucle->from[$table_alias]) |
|
| 1025 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | - ) { |
|
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | - } elseif ($table) { |
|
| 1029 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | - } else { |
|
| 1032 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $raw ? $par : "'$par'"; |
|
| 987 | + $boucle = &$boucles[$idb]; |
|
| 988 | + $desc = $boucle->show; |
|
| 989 | + |
|
| 990 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | + if (isset($desc['field'][$par])) { |
|
| 992 | + $par = $boucle->id_table . '.' . $par; |
|
| 993 | + } |
|
| 994 | + // le champ est peut être une jointure |
|
| 995 | + else { |
|
| 996 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | + $champ = $par; |
|
| 998 | + |
|
| 999 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | + [, $table, $champ] = $r; |
|
| 1005 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | + $table = table_objet_sql($table); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | + } elseif ( |
|
| 1015 | + $boucle->jointures_explicites |
|
| 1016 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | + ) { |
|
| 1018 | + $par = $alias . '.' . $champ; |
|
| 1019 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | + $par = $alias . '.' . $champ; |
|
| 1021 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | + } elseif ( |
|
| 1023 | + $table_alias |
|
| 1024 | + and isset($boucle->from[$table_alias]) |
|
| 1025 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | + ) { |
|
| 1027 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | + } elseif ($table) { |
|
| 1029 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | + } else { |
|
| 1032 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $raw ? $par : "'$par'"; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1047,11 +1047,11 @@ discard block |
||
| 1047 | 1047 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1048 | 1048 | */ |
| 1049 | 1049 | function critere_par_joint($table, $champ, &$boucle) { |
| 1050 | - $t = array_search($table, $boucle->from); |
|
| 1051 | - if (!$t) { |
|
| 1052 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | - } |
|
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1050 | + $t = array_search($table, $boucle->from); |
|
| 1051 | + if (!$t) { |
|
| 1052 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | + } |
|
| 1054 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1076,33 +1076,33 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1078 | 1078 | |
| 1079 | - $boucle = &$boucles[$idb]; |
|
| 1080 | - // Classement par ordre inverse |
|
| 1081 | - if ($crit->not) { |
|
| 1082 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | - } else { |
|
| 1084 | - $order = "' DESC'"; |
|
| 1085 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | - if (isset($crit->param[0])) { |
|
| 1087 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | - $order = "(($critere)?' DESC':'')"; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | - if (!$n) { |
|
| 1093 | - if (isset($boucle->default_order[0])) { |
|
| 1094 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | - } else { |
|
| 1096 | - $boucle->default_order[] = ' DESC'; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1102 | - } |
|
| 1103 | - $boucle->order[$n - 1] = $t; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1079 | + $boucle = &$boucles[$idb]; |
|
| 1080 | + // Classement par ordre inverse |
|
| 1081 | + if ($crit->not) { |
|
| 1082 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | + } else { |
|
| 1084 | + $order = "' DESC'"; |
|
| 1085 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | + if (isset($crit->param[0])) { |
|
| 1087 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | + $order = "(($critere)?' DESC':'')"; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | + if (!$n) { |
|
| 1093 | + if (isset($boucle->default_order[0])) { |
|
| 1094 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | + } else { |
|
| 1096 | + $boucle->default_order[] = ' DESC'; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | + $t = $r[1] . $r[2]; |
|
| 1102 | + } |
|
| 1103 | + $boucle->order[$n - 1] = $t; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1113,137 +1113,137 @@ discard block |
||
| 1113 | 1113 | * @return array|string |
| 1114 | 1114 | */ |
| 1115 | 1115 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1116 | - $boucle = &$boucles[$idb]; |
|
| 1116 | + $boucle = &$boucles[$idb]; |
|
| 1117 | 1117 | |
| 1118 | - $sens = $collecte = ''; |
|
| 1119 | - if ($crit->not) { |
|
| 1120 | - $sens = " . ' DESC'"; |
|
| 1121 | - } |
|
| 1118 | + $sens = $collecte = ''; |
|
| 1119 | + if ($crit->not) { |
|
| 1120 | + $sens = " . ' DESC'"; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - $crit2 = clone $crit; |
|
| 1124 | - $crit2->not = false; |
|
| 1125 | - $crit2->param = [reset($crit->param)]; |
|
| 1126 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1123 | + $crit2 = clone $crit; |
|
| 1124 | + $crit2->not = false; |
|
| 1125 | + $crit2->param = [reset($crit->param)]; |
|
| 1126 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1127 | 1127 | |
| 1128 | - // erreur ? |
|
| 1129 | - if (is_array($res)) { |
|
| 1130 | - return $res; |
|
| 1131 | - } |
|
| 1128 | + // erreur ? |
|
| 1129 | + if (is_array($res)) { |
|
| 1130 | + return $res; |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - $_order = array_pop($boucle->order); |
|
| 1133 | + $_order = array_pop($boucle->order); |
|
| 1134 | 1134 | |
| 1135 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1135 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | 1140 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1141 | - $params = $crit->param; |
|
| 1142 | - |
|
| 1143 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - $boucle = &$boucles[$idb]; |
|
| 1148 | - $parent = $boucle->id_parent; |
|
| 1149 | - $fields = $boucle->show['field']; |
|
| 1150 | - |
|
| 1151 | - $date = array_shift($params); |
|
| 1152 | - $type = array_shift($params); |
|
| 1153 | - |
|
| 1154 | - // la valeur $type doit etre connue a la compilation |
|
| 1155 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | - |
|
| 1158 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | - $date = $date[0]->texte; |
|
| 1164 | - if (!isset($fields[$date])) { |
|
| 1165 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | - } |
|
| 1167 | - } else { |
|
| 1168 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | - $noms = array_keys($fields); |
|
| 1170 | - $defaut = $noms[0]; |
|
| 1171 | - $noms = join(' ', $noms); |
|
| 1172 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | - } |
|
| 1176 | - $annee = $params ? array_shift($params) : ''; |
|
| 1177 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | - ') ? $x : date("Y"))'; |
|
| 1180 | - |
|
| 1181 | - $mois = $params ? array_shift($params) : ''; |
|
| 1182 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | - ') ? $x : date("m"))'; |
|
| 1185 | - |
|
| 1186 | - $jour = $params ? array_shift($params) : ''; |
|
| 1187 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | - ') ? $x : date("d"))'; |
|
| 1190 | - |
|
| 1191 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | - ') ? $x : date("Y"))'; |
|
| 1195 | - |
|
| 1196 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | - ') ? $x : date("m"))'; |
|
| 1200 | - |
|
| 1201 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | - ') ? $x : date("d"))'; |
|
| 1205 | - |
|
| 1206 | - $date = $boucle->id_table . ".$date"; |
|
| 1207 | - |
|
| 1208 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | - if ($type == 'jour') { |
|
| 1210 | - $boucle->where[] = [ |
|
| 1211 | - "'='", |
|
| 1212 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | - ]; |
|
| 1215 | - } elseif ($type == 'mois') { |
|
| 1216 | - $boucle->where[] = [ |
|
| 1217 | - "'='", |
|
| 1218 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | - ]; |
|
| 1221 | - } elseif ($type == 'semaine') { |
|
| 1222 | - $boucle->where[] = [ |
|
| 1223 | - "'AND'", |
|
| 1224 | - [ |
|
| 1225 | - "'>='", |
|
| 1226 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | - ], |
|
| 1229 | - [ |
|
| 1230 | - "'<='", |
|
| 1231 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | - ] |
|
| 1234 | - ]; |
|
| 1235 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | - $boucle->where[] = [ |
|
| 1237 | - "'AND'", |
|
| 1238 | - [ |
|
| 1239 | - "'>='", |
|
| 1240 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | - ], |
|
| 1243 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | - ]; |
|
| 1245 | - } |
|
| 1246 | - // sinon on prend tout |
|
| 1141 | + $params = $crit->param; |
|
| 1142 | + |
|
| 1143 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + $boucle = &$boucles[$idb]; |
|
| 1148 | + $parent = $boucle->id_parent; |
|
| 1149 | + $fields = $boucle->show['field']; |
|
| 1150 | + |
|
| 1151 | + $date = array_shift($params); |
|
| 1152 | + $type = array_shift($params); |
|
| 1153 | + |
|
| 1154 | + // la valeur $type doit etre connue a la compilation |
|
| 1155 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | + |
|
| 1158 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | + $date = $date[0]->texte; |
|
| 1164 | + if (!isset($fields[$date])) { |
|
| 1165 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | + } |
|
| 1167 | + } else { |
|
| 1168 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | + $noms = array_keys($fields); |
|
| 1170 | + $defaut = $noms[0]; |
|
| 1171 | + $noms = join(' ', $noms); |
|
| 1172 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | + } |
|
| 1176 | + $annee = $params ? array_shift($params) : ''; |
|
| 1177 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + ') ? $x : date("Y"))'; |
|
| 1180 | + |
|
| 1181 | + $mois = $params ? array_shift($params) : ''; |
|
| 1182 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + ') ? $x : date("m"))'; |
|
| 1185 | + |
|
| 1186 | + $jour = $params ? array_shift($params) : ''; |
|
| 1187 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + ') ? $x : date("d"))'; |
|
| 1190 | + |
|
| 1191 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + ') ? $x : date("Y"))'; |
|
| 1195 | + |
|
| 1196 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + ') ? $x : date("m"))'; |
|
| 1200 | + |
|
| 1201 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + ') ? $x : date("d"))'; |
|
| 1205 | + |
|
| 1206 | + $date = $boucle->id_table . ".$date"; |
|
| 1207 | + |
|
| 1208 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | + if ($type == 'jour') { |
|
| 1210 | + $boucle->where[] = [ |
|
| 1211 | + "'='", |
|
| 1212 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | + ]; |
|
| 1215 | + } elseif ($type == 'mois') { |
|
| 1216 | + $boucle->where[] = [ |
|
| 1217 | + "'='", |
|
| 1218 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | + ]; |
|
| 1221 | + } elseif ($type == 'semaine') { |
|
| 1222 | + $boucle->where[] = [ |
|
| 1223 | + "'AND'", |
|
| 1224 | + [ |
|
| 1225 | + "'>='", |
|
| 1226 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | + ], |
|
| 1229 | + [ |
|
| 1230 | + "'<='", |
|
| 1231 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | + ] |
|
| 1234 | + ]; |
|
| 1235 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | + $boucle->where[] = [ |
|
| 1237 | + "'AND'", |
|
| 1238 | + [ |
|
| 1239 | + "'>='", |
|
| 1240 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | + ], |
|
| 1243 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | + ]; |
|
| 1245 | + } |
|
| 1246 | + // sinon on prend tout |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | |
@@ -1268,33 +1268,33 @@ discard block |
||
| 1268 | 1268 | * @return void |
| 1269 | 1269 | **/ |
| 1270 | 1270 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1271 | - $boucle = &$boucles[$idb]; |
|
| 1272 | - $a1 = $crit->param[0]; |
|
| 1273 | - $a2 = $crit->param[1]; |
|
| 1274 | - $op = $crit->op; |
|
| 1275 | - |
|
| 1276 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | - |
|
| 1279 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | - } else { |
|
| 1282 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | - $mode = (($op == '/') ? '/' : |
|
| 1287 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | - $boucle->limit = |
|
| 1291 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | - . ".','." |
|
| 1293 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | - } else { |
|
| 1295 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | - } |
|
| 1297 | - } |
|
| 1271 | + $boucle = &$boucles[$idb]; |
|
| 1272 | + $a1 = $crit->param[0]; |
|
| 1273 | + $a2 = $crit->param[1]; |
|
| 1274 | + $op = $crit->op; |
|
| 1275 | + |
|
| 1276 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | + |
|
| 1279 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | + } else { |
|
| 1282 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | + $mode = (($op == '/') ? '/' : |
|
| 1287 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | + $boucle->limit = |
|
| 1291 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | + . ".','." |
|
| 1293 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | + } else { |
|
| 1295 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | + } |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1322,63 +1322,63 @@ discard block |
||
| 1322 | 1322 | * @return void |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1325 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | - |
|
| 1327 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | - // {1/3} |
|
| 1331 | - if ($op1 == '/') { |
|
| 1332 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | - "($total_parties ? $total_parties : 1)"; |
|
| 1335 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | - } else { |
|
| 1338 | - // cas {n-1,x} |
|
| 1339 | - if ($op1 == '-') { |
|
| 1340 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - // cas {x,n-1} |
|
| 1344 | - if ($op2 == '-') { |
|
| 1345 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | - ($total_parties . ' - 1')); |
|
| 1348 | - } else { |
|
| 1349 | - // {x,1} ou {pagination} |
|
| 1350 | - $fin = '$debut_boucle' |
|
| 1351 | - . (is_numeric($total_parties) ? |
|
| 1352 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | - ('+' . $total_parties . ' - 1')); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | - if ($op1 == 'p') { |
|
| 1358 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - // Notes : |
|
| 1365 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | - |
|
| 1370 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | - . "\n\tif (\$debut_boucle>0" |
|
| 1377 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | - |
|
| 1381 | - $boucles[$id_boucle]->partie = " |
|
| 1325 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | + |
|
| 1327 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | + // {1/3} |
|
| 1331 | + if ($op1 == '/') { |
|
| 1332 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | + "($total_parties ? $total_parties : 1)"; |
|
| 1335 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | + } else { |
|
| 1338 | + // cas {n-1,x} |
|
| 1339 | + if ($op1 == '-') { |
|
| 1340 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + // cas {x,n-1} |
|
| 1344 | + if ($op2 == '-') { |
|
| 1345 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | + ($total_parties . ' - 1')); |
|
| 1348 | + } else { |
|
| 1349 | + // {x,1} ou {pagination} |
|
| 1350 | + $fin = '$debut_boucle' |
|
| 1351 | + . (is_numeric($total_parties) ? |
|
| 1352 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | + ('+' . $total_parties . ' - 1')); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | + if ($op1 == 'p') { |
|
| 1358 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + // Notes : |
|
| 1365 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | + |
|
| 1370 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | + . "\n\tif (\$debut_boucle>0" |
|
| 1377 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | + |
|
| 1381 | + $boucles[$id_boucle]->partie = " |
|
| 1382 | 1382 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1383 | 1383 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1384 | 1384 | } |
@@ -1395,26 +1395,26 @@ discard block |
||
| 1395 | 1395 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1396 | 1396 | **/ |
| 1397 | 1397 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1398 | - if ($param[0]->type != 'texte') { |
|
| 1399 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | - if (isset($param[1]->texte)) { |
|
| 1401 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | - |
|
| 1403 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | - } else { |
|
| 1405 | - return ["intval($a1)", 0]; |
|
| 1406 | - } |
|
| 1407 | - } else { |
|
| 1408 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | - $a1 = $m[1]; |
|
| 1410 | - if (empty($m[3])) { |
|
| 1411 | - return [$a1, 0]; |
|
| 1412 | - } elseif (!empty($m[4])) { |
|
| 1413 | - return [$a1, $m[4]]; |
|
| 1414 | - } else { |
|
| 1415 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | - } |
|
| 1417 | - } |
|
| 1398 | + if ($param[0]->type != 'texte') { |
|
| 1399 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | + if (isset($param[1]->texte)) { |
|
| 1401 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | + |
|
| 1403 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | + } else { |
|
| 1405 | + return ["intval($a1)", 0]; |
|
| 1406 | + } |
|
| 1407 | + } else { |
|
| 1408 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | + $a1 = $m[1]; |
|
| 1410 | + if (empty($m[3])) { |
|
| 1411 | + return [$a1, 0]; |
|
| 1412 | + } elseif (!empty($m[4])) { |
|
| 1413 | + return [$a1, $m[4]]; |
|
| 1414 | + } else { |
|
| 1415 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | + } |
|
| 1417 | + } |
|
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | |
@@ -1441,47 +1441,47 @@ discard block |
||
| 1441 | 1441 | * array : Erreur sur un des critères |
| 1442 | 1442 | **/ |
| 1443 | 1443 | function calculer_criteres($idb, &$boucles) { |
| 1444 | - $msg = ''; |
|
| 1445 | - $boucle = $boucles[$idb]; |
|
| 1446 | - $table = strtoupper($boucle->type_requete); |
|
| 1447 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | - |
|
| 1449 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | - if (!is_array($boucle->criteres)) { |
|
| 1452 | - return []; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - foreach ($boucle->criteres as $crit) { |
|
| 1456 | - $critere = $crit->op; |
|
| 1457 | - // critere personnalise ? |
|
| 1458 | - if ( |
|
| 1459 | - (!$serveur or |
|
| 1460 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | - and (!function_exists($f = $f . '_dist')) |
|
| 1462 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | - ) |
|
| 1465 | - ) |
|
| 1466 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1470 | - ) { |
|
| 1471 | - // fonction critere standard |
|
| 1472 | - $f = $defaut; |
|
| 1473 | - } |
|
| 1474 | - // compile le critere |
|
| 1475 | - $res = $f($idb, $boucles, $crit); |
|
| 1476 | - |
|
| 1477 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | - if (is_array($res)) { |
|
| 1479 | - $msg = $res; |
|
| 1480 | - erreur_squelette($msg, $boucle); |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - return $msg; |
|
| 1444 | + $msg = ''; |
|
| 1445 | + $boucle = $boucles[$idb]; |
|
| 1446 | + $table = strtoupper($boucle->type_requete); |
|
| 1447 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | + |
|
| 1449 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | + if (!is_array($boucle->criteres)) { |
|
| 1452 | + return []; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + foreach ($boucle->criteres as $crit) { |
|
| 1456 | + $critere = $crit->op; |
|
| 1457 | + // critere personnalise ? |
|
| 1458 | + if ( |
|
| 1459 | + (!$serveur or |
|
| 1460 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | + and (!function_exists($f = $f . '_dist')) |
|
| 1462 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | + and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + ) |
|
| 1465 | + ) |
|
| 1466 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | + and (!function_exists($f = $f . '_dist')) |
|
| 1468 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | + and (!function_exists($f = $f . '_dist')) |
|
| 1470 | + ) { |
|
| 1471 | + // fonction critere standard |
|
| 1472 | + $f = $defaut; |
|
| 1473 | + } |
|
| 1474 | + // compile le critere |
|
| 1475 | + $res = $f($idb, $boucles, $crit); |
|
| 1476 | + |
|
| 1477 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | + if (is_array($res)) { |
|
| 1479 | + $msg = $res; |
|
| 1480 | + erreur_squelette($msg, $boucle); |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + return $msg; |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
@@ -1496,11 +1496,11 @@ discard block |
||
| 1496 | 1496 | * @return string Code compilé rééchappé |
| 1497 | 1497 | */ |
| 1498 | 1498 | function kwote($lisp, $serveur = '', $type = '') { |
| 1499 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | - } else { |
|
| 1502 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | - } |
|
| 1499 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | + } else { |
|
| 1502 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | + } |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | |
@@ -1519,81 +1519,81 @@ discard block |
||
| 1519 | 1519 | * @return void |
| 1520 | 1520 | **/ |
| 1521 | 1521 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1522 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | - if (!$r) { |
|
| 1524 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1525 | - } |
|
| 1526 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | - |
|
| 1528 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | - |
|
| 1530 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | - $where = $in; |
|
| 1532 | - if ($crit->cond) { |
|
| 1533 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - if ($crit->exclus) { |
|
| 1540 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | - $where = ["'NOT'", $where]; |
|
| 1542 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | - { |
|
| 1545 | - $where = [ |
|
| 1546 | - "'NOT'", |
|
| 1547 | - [ |
|
| 1548 | - "'IN'", |
|
| 1549 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | - ] |
|
| 1552 | - ]; |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - $boucles[$idb]->where[] = $where; |
|
| 1557 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | - } |
|
| 1522 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | + if (!$r) { |
|
| 1524 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]); |
|
| 1525 | + } |
|
| 1526 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | + |
|
| 1528 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | + |
|
| 1530 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | + $where = $in; |
|
| 1532 | + if ($crit->cond) { |
|
| 1533 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + if ($crit->exclus) { |
|
| 1540 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | + $where = ["'NOT'", $where]; |
|
| 1542 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | + { |
|
| 1545 | + $where = [ |
|
| 1546 | + "'NOT'", |
|
| 1547 | + [ |
|
| 1548 | + "'IN'", |
|
| 1549 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | + ] |
|
| 1552 | + ]; |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + $boucles[$idb]->where[] = $where; |
|
| 1557 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | + } |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1563 | - static $num = []; |
|
| 1564 | - $descr = $boucles[$idb]->descr; |
|
| 1565 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | - |
|
| 1567 | - $var = '$in' . $cpt++; |
|
| 1568 | - $x = "\n\t$var = array();"; |
|
| 1569 | - foreach ($val as $k => $v) { |
|
| 1570 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | - // optimiser le traitement des constantes |
|
| 1572 | - if (is_numeric($r[2])) { |
|
| 1573 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | - } else { |
|
| 1575 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | - } |
|
| 1577 | - } else { |
|
| 1578 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - $boucles[$idb]->in .= $x; |
|
| 1587 | - |
|
| 1588 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | - if (!$crit2) { |
|
| 1593 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1563 | + static $num = []; |
|
| 1564 | + $descr = $boucles[$idb]->descr; |
|
| 1565 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | + |
|
| 1567 | + $var = '$in' . $cpt++; |
|
| 1568 | + $x = "\n\t$var = array();"; |
|
| 1569 | + foreach ($val as $k => $v) { |
|
| 1570 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | + // optimiser le traitement des constantes |
|
| 1572 | + if (is_numeric($r[2])) { |
|
| 1573 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | + } else { |
|
| 1575 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | + } |
|
| 1577 | + } else { |
|
| 1578 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + $boucles[$idb]->in .= $x; |
|
| 1587 | + |
|
| 1588 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | + if (!$crit2) { |
|
| 1593 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | /** |
@@ -1609,22 +1609,22 @@ discard block |
||
| 1609 | 1609 | * @return void |
| 1610 | 1610 | */ |
| 1611 | 1611 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1612 | - $boucle = &$boucles[$idb]; |
|
| 1613 | - if (isset($crit->param[0])) { |
|
| 1614 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | - } else { |
|
| 1616 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - if ($crit->cond) { |
|
| 1620 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - if ($crit->not) { |
|
| 1624 | - $_where = "array('NOT',$_where)"; |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - $boucle->where[] = $_where; |
|
| 1612 | + $boucle = &$boucles[$idb]; |
|
| 1613 | + if (isset($crit->param[0])) { |
|
| 1614 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | + } else { |
|
| 1616 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + if ($crit->cond) { |
|
| 1620 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + if ($crit->not) { |
|
| 1624 | + $_where = "array('NOT',$_where)"; |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + $boucle->where[] = $_where; |
|
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | /** |
@@ -1652,31 +1652,31 @@ discard block |
||
| 1652 | 1652 | * @return void |
| 1653 | 1653 | */ |
| 1654 | 1654 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1655 | - /** @var Boucle $boucle */ |
|
| 1656 | - $boucle = $boucles[$idb]; |
|
| 1657 | - |
|
| 1658 | - $champs = lister_champs_id_conditionnel( |
|
| 1659 | - $boucle->show['table'], |
|
| 1660 | - $boucle->show, |
|
| 1661 | - $boucle->sql_serveur |
|
| 1662 | - ); |
|
| 1663 | - |
|
| 1664 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | - } |
|
| 1668 | - // nous aider en mode debug. |
|
| 1669 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | - $boucle->modificateur['id_'] = $champs; |
|
| 1671 | - |
|
| 1672 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | - foreach ($champs as $champ) { |
|
| 1674 | - $critere_id_table = new Critere(); |
|
| 1675 | - $critere_id_table->op = $champ; |
|
| 1676 | - $critere_id_table->cond = '?'; |
|
| 1677 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | - } |
|
| 1655 | + /** @var Boucle $boucle */ |
|
| 1656 | + $boucle = $boucles[$idb]; |
|
| 1657 | + |
|
| 1658 | + $champs = lister_champs_id_conditionnel( |
|
| 1659 | + $boucle->show['table'], |
|
| 1660 | + $boucle->show, |
|
| 1661 | + $boucle->sql_serveur |
|
| 1662 | + ); |
|
| 1663 | + |
|
| 1664 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | + } |
|
| 1668 | + // nous aider en mode debug. |
|
| 1669 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | + $boucle->modificateur['id_'] = $champs; |
|
| 1671 | + |
|
| 1672 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | + foreach ($champs as $champ) { |
|
| 1674 | + $critere_id_table = new Critere(); |
|
| 1675 | + $critere_id_table->op = $champ; |
|
| 1676 | + $critere_id_table->cond = '?'; |
|
| 1677 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | + } |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | /** |
@@ -1696,75 +1696,75 @@ discard block |
||
| 1696 | 1696 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1697 | 1697 | */ |
| 1698 | 1698 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1699 | - // calculer la description de la table |
|
| 1700 | - if (!is_array($desc)) { |
|
| 1701 | - $desc = description_table($table, $serveur); |
|
| 1702 | - } |
|
| 1703 | - if (!$desc) { |
|
| 1704 | - return []; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - // Les champs id_xx de la table demandée |
|
| 1708 | - $champs = array_filter( |
|
| 1709 | - array_keys($desc['field']), |
|
| 1710 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | - ); |
|
| 1712 | - |
|
| 1713 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | - if ( |
|
| 1715 | - in_array('id_rubrique', $champs) |
|
| 1716 | - and !in_array('id_secteur', $champs) |
|
| 1717 | - ) { |
|
| 1718 | - $champs[] = 'id_secteur'; |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | - if ($serveur) { |
|
| 1723 | - return $champs; |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - $primary = false; |
|
| 1727 | - $associable = false; |
|
| 1728 | - include_spip('action/editer_liens'); |
|
| 1729 | - |
|
| 1730 | - if (isset($desc['type'])) { |
|
| 1731 | - $primary = id_table_objet($desc['type']); |
|
| 1732 | - $associable = objet_associable($desc['type']); |
|
| 1733 | - } |
|
| 1734 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | - $associable = true; |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - // liste de toutes les tables principales, sauf la notre |
|
| 1739 | - $tables = lister_tables_objets_sql(); |
|
| 1740 | - unset($tables[$table]); |
|
| 1741 | - |
|
| 1742 | - foreach ($tables as $_table => $_desc) { |
|
| 1743 | - if ( |
|
| 1744 | - $associable |
|
| 1745 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | - or objet_associable($_desc['type']) |
|
| 1747 | - ) { |
|
| 1748 | - $champs[] = id_table_objet($_table); |
|
| 1749 | - } |
|
| 1750 | - } |
|
| 1751 | - $champs = array_values(array_unique($champs)); |
|
| 1752 | - |
|
| 1753 | - // Exclusions de certains id |
|
| 1754 | - $exclusions = pipeline( |
|
| 1755 | - 'exclure_id_conditionnel', |
|
| 1756 | - [ |
|
| 1757 | - 'args' => [ |
|
| 1758 | - 'table' => $table, |
|
| 1759 | - 'id_table_objet' => $primary, |
|
| 1760 | - 'associable' => $associable, |
|
| 1761 | - ], |
|
| 1762 | - 'data' => [], |
|
| 1763 | - ] |
|
| 1764 | - ); |
|
| 1765 | - $champs = array_diff($champs, $exclusions); |
|
| 1766 | - |
|
| 1767 | - return $champs; |
|
| 1699 | + // calculer la description de la table |
|
| 1700 | + if (!is_array($desc)) { |
|
| 1701 | + $desc = description_table($table, $serveur); |
|
| 1702 | + } |
|
| 1703 | + if (!$desc) { |
|
| 1704 | + return []; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + // Les champs id_xx de la table demandée |
|
| 1708 | + $champs = array_filter( |
|
| 1709 | + array_keys($desc['field']), |
|
| 1710 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | + ); |
|
| 1712 | + |
|
| 1713 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | + if ( |
|
| 1715 | + in_array('id_rubrique', $champs) |
|
| 1716 | + and !in_array('id_secteur', $champs) |
|
| 1717 | + ) { |
|
| 1718 | + $champs[] = 'id_secteur'; |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | + if ($serveur) { |
|
| 1723 | + return $champs; |
|
| 1724 | + } |
|
| 1725 | + |
|
| 1726 | + $primary = false; |
|
| 1727 | + $associable = false; |
|
| 1728 | + include_spip('action/editer_liens'); |
|
| 1729 | + |
|
| 1730 | + if (isset($desc['type'])) { |
|
| 1731 | + $primary = id_table_objet($desc['type']); |
|
| 1732 | + $associable = objet_associable($desc['type']); |
|
| 1733 | + } |
|
| 1734 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | + $associable = true; |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + // liste de toutes les tables principales, sauf la notre |
|
| 1739 | + $tables = lister_tables_objets_sql(); |
|
| 1740 | + unset($tables[$table]); |
|
| 1741 | + |
|
| 1742 | + foreach ($tables as $_table => $_desc) { |
|
| 1743 | + if ( |
|
| 1744 | + $associable |
|
| 1745 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | + or objet_associable($_desc['type']) |
|
| 1747 | + ) { |
|
| 1748 | + $champs[] = id_table_objet($_table); |
|
| 1749 | + } |
|
| 1750 | + } |
|
| 1751 | + $champs = array_values(array_unique($champs)); |
|
| 1752 | + |
|
| 1753 | + // Exclusions de certains id |
|
| 1754 | + $exclusions = pipeline( |
|
| 1755 | + 'exclure_id_conditionnel', |
|
| 1756 | + [ |
|
| 1757 | + 'args' => [ |
|
| 1758 | + 'table' => $table, |
|
| 1759 | + 'id_table_objet' => $primary, |
|
| 1760 | + 'associable' => $associable, |
|
| 1761 | + ], |
|
| 1762 | + 'data' => [], |
|
| 1763 | + ] |
|
| 1764 | + ); |
|
| 1765 | + $champs = array_diff($champs, $exclusions); |
|
| 1766 | + |
|
| 1767 | + return $champs; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1819,27 +1819,27 @@ discard block |
||
| 1819 | 1819 | * @return void |
| 1820 | 1820 | */ |
| 1821 | 1821 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1822 | - $boucle = &$boucles[$idb]; |
|
| 1823 | - |
|
| 1824 | - // definition du champ par defaut |
|
| 1825 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | - $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | - |
|
| 1832 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | - |
|
| 1834 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | - |
|
| 1837 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1840 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1841 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1842 | - $boucle->hash .= " |
|
| 1822 | + $boucle = &$boucles[$idb]; |
|
| 1823 | + |
|
| 1824 | + // definition du champ par defaut |
|
| 1825 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | + $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | + |
|
| 1832 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | + |
|
| 1834 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | + |
|
| 1837 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1840 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1841 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1842 | + $boucle->hash .= " |
|
| 1843 | 1843 | \$senstri = ''; |
| 1844 | 1844 | \$tri = $_tri; |
| 1845 | 1845 | if (\$tri){ |
@@ -1847,8 +1847,8 @@ discard block |
||
| 1847 | 1847 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1848 | 1848 | }; |
| 1849 | 1849 | "; |
| 1850 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1851 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1850 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1851 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | # Criteres de comparaison |
@@ -1865,20 +1865,20 @@ discard block |
||
| 1865 | 1865 | * @return void |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1868 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1869 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1870 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1874 | - if (!$r) { |
|
| 1875 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1876 | - # if (!$crit->cond) { |
|
| 1877 | - return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1878 | - # } |
|
| 1879 | - } else { |
|
| 1880 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1881 | - } |
|
| 1868 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1869 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1870 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1874 | + if (!$r) { |
|
| 1875 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1876 | + # if (!$crit->cond) { |
|
| 1877 | + return (['zbug_critere_inconnu', ['critere' => $crit->op]]); |
|
| 1878 | + # } |
|
| 1879 | + } else { |
|
| 1880 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1881 | + } |
|
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | 1884 | |
@@ -1898,62 +1898,62 @@ discard block |
||
| 1898 | 1898 | * @return void |
| 1899 | 1899 | **/ |
| 1900 | 1900 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1901 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1902 | - |
|
| 1903 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1904 | - |
|
| 1905 | - // inserer la negation (cf !...) |
|
| 1906 | - |
|
| 1907 | - if ($crit->not) { |
|
| 1908 | - $where = ["'NOT'", $where]; |
|
| 1909 | - } |
|
| 1910 | - if ($crit->exclus) { |
|
| 1911 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1912 | - $where = ["'NOT'", $where]; |
|
| 1913 | - } else { |
|
| 1914 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1915 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1916 | - $where = [ |
|
| 1917 | - "'NOT'", |
|
| 1918 | - [ |
|
| 1919 | - "'IN'", |
|
| 1920 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1922 | - ] |
|
| 1923 | - ]; |
|
| 1924 | - } |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - // inserer la condition (cf {lang?}) |
|
| 1928 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1929 | - if ($crit->cond) { |
|
| 1930 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1931 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1932 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1933 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - |
|
| 1937 | - if ($op === '=' and !$crit->not) { |
|
| 1938 | - $where = [ |
|
| 1939 | - "'?'", |
|
| 1940 | - "(is_array($pred))", |
|
| 1941 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1942 | - $where |
|
| 1943 | - ]; |
|
| 1944 | - } |
|
| 1945 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1946 | - if ($where_complement) { |
|
| 1947 | - // condition annexe du type "AND (objet='article')" |
|
| 1948 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - $boucles[$idb]->where[] = $where; |
|
| 1953 | - if ($where_complement) { |
|
| 1954 | - // condition annexe du type "AND (objet='article')" |
|
| 1955 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1956 | - } |
|
| 1901 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1902 | + |
|
| 1903 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1904 | + |
|
| 1905 | + // inserer la negation (cf !...) |
|
| 1906 | + |
|
| 1907 | + if ($crit->not) { |
|
| 1908 | + $where = ["'NOT'", $where]; |
|
| 1909 | + } |
|
| 1910 | + if ($crit->exclus) { |
|
| 1911 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1912 | + $where = ["'NOT'", $where]; |
|
| 1913 | + } else { |
|
| 1914 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1915 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1916 | + $where = [ |
|
| 1917 | + "'NOT'", |
|
| 1918 | + [ |
|
| 1919 | + "'IN'", |
|
| 1920 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1922 | + ] |
|
| 1923 | + ]; |
|
| 1924 | + } |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + // inserer la condition (cf {lang?}) |
|
| 1928 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1929 | + if ($crit->cond) { |
|
| 1930 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1931 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1932 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1933 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + if ($op === '=' and !$crit->not) { |
|
| 1938 | + $where = [ |
|
| 1939 | + "'?'", |
|
| 1940 | + "(is_array($pred))", |
|
| 1941 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1942 | + $where |
|
| 1943 | + ]; |
|
| 1944 | + } |
|
| 1945 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1946 | + if ($where_complement) { |
|
| 1947 | + // condition annexe du type "AND (objet='article')" |
|
| 1948 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + $boucles[$idb]->where[] = $where; |
|
| 1953 | + if ($where_complement) { |
|
| 1954 | + // condition annexe du type "AND (objet='article')" |
|
| 1955 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1956 | + } |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | 1959 | |
@@ -1994,165 +1994,165 @@ discard block |
||
| 1994 | 1994 | **/ |
| 1995 | 1995 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1996 | 1996 | |
| 1997 | - $boucle = &$boucles[$idb]; |
|
| 1998 | - $type = $boucle->type_requete; |
|
| 1999 | - $table = $boucle->id_table ?? ''; |
|
| 2000 | - $desc = $boucle->show; |
|
| 2001 | - $col_vraie = null; |
|
| 2002 | - |
|
| 2003 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2004 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2005 | - |
|
| 2006 | - $col_alias = $col; |
|
| 2007 | - $where_complement = false; |
|
| 2008 | - |
|
| 2009 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2010 | - if ($col == 'id_enfant') { |
|
| 2011 | - $col = $boucle->primary; |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2015 | - if ( |
|
| 2016 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2017 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | - ) { |
|
| 2019 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2020 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2021 | - else { |
|
| 2022 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2023 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2027 | - // sauf si exception declaree : sauter cette etape |
|
| 2028 | - else { |
|
| 2029 | - if ( |
|
| 2030 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2031 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2032 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2033 | - ) { |
|
| 2034 | - $e = decompose_champ_id_objet($col); |
|
| 2035 | - $col = array_shift($e); |
|
| 2036 | - $where_complement = primary_doublee($e, $table); |
|
| 2037 | - } // Cas particulier : expressions de date |
|
| 2038 | - else { |
|
| 2039 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2040 | - [$col, $col_vraie] = $c; |
|
| 2041 | - $table = ''; |
|
| 2042 | - } // table explicitée {mots.titre} |
|
| 2043 | - else { |
|
| 2044 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2045 | - [, $table, $col] = $r; |
|
| 2046 | - $col_alias = $col; |
|
| 2047 | - |
|
| 2048 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2049 | - if ( |
|
| 2050 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2051 | - and isset($desc['field'][$col]) |
|
| 2052 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2053 | - ) { |
|
| 2054 | - $table = $cle; |
|
| 2055 | - } else { |
|
| 2056 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2057 | - } |
|
| 2058 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2059 | - if (!$table) { |
|
| 2060 | - return ''; |
|
| 2061 | - } |
|
| 2062 | - } |
|
| 2063 | - // si le champ n'est pas trouvé dans la table, |
|
| 2064 | - // on cherche si une jointure peut l'obtenir |
|
| 2065 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2066 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2067 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2068 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2069 | - } |
|
| 2070 | - else { |
|
| 2071 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2072 | - if (!$r) { |
|
| 2073 | - return ''; |
|
| 2074 | - } |
|
| 2075 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2076 | - } |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - } |
|
| 2081 | - } |
|
| 2082 | - |
|
| 2083 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2084 | - // Dans tous les cas, |
|
| 2085 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2086 | - // et passer dans sql_quote avec le type si connu |
|
| 2087 | - // et int sinon si la valeur est numerique |
|
| 2088 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2089 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2090 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2091 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2092 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2093 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2094 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2095 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2096 | - } |
|
| 2097 | - // sinon expliciter les |
|
| 2098 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2099 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2100 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2101 | - // sans toucher aux |
|
| 2102 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2103 | - // sql_quote(truc,'','varchar') |
|
| 2104 | - elseif ( |
|
| 2105 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2106 | - // si pas deja un type |
|
| 2107 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2108 | - ) { |
|
| 2109 | - $r = $r[1] |
|
| 2110 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2111 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2112 | - $val[0] = "sql_quote($r)"; |
|
| 2113 | - } |
|
| 2114 | - elseif ( |
|
| 2115 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2116 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2117 | - ) { |
|
| 2118 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - if ( |
|
| 2123 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2124 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2125 | - ) { |
|
| 2126 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2127 | - } |
|
| 2128 | - |
|
| 2129 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2130 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2131 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2132 | - if ($table === $boucle->id_table) { |
|
| 2133 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2134 | - if ($col_alias != $col_vraie) { |
|
| 2135 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2136 | - } |
|
| 2137 | - } |
|
| 2138 | - |
|
| 2139 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2140 | - if ($table) { |
|
| 2141 | - if ($col[0] == '`') { |
|
| 2142 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2143 | - } else { |
|
| 2144 | - $arg = "$table.$col"; |
|
| 2145 | - } |
|
| 2146 | - } else { |
|
| 2147 | - $arg = $col; |
|
| 2148 | - } |
|
| 2149 | - |
|
| 2150 | - // inserer la fonction SQL |
|
| 2151 | - if ($fct) { |
|
| 2152 | - $arg = "$fct($arg$args_sql)"; |
|
| 2153 | - } |
|
| 2154 | - |
|
| 2155 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 1997 | + $boucle = &$boucles[$idb]; |
|
| 1998 | + $type = $boucle->type_requete; |
|
| 1999 | + $table = $boucle->id_table ?? ''; |
|
| 2000 | + $desc = $boucle->show; |
|
| 2001 | + $col_vraie = null; |
|
| 2002 | + |
|
| 2003 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2004 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2005 | + |
|
| 2006 | + $col_alias = $col; |
|
| 2007 | + $where_complement = false; |
|
| 2008 | + |
|
| 2009 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2010 | + if ($col == 'id_enfant') { |
|
| 2011 | + $col = $boucle->primary; |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2015 | + if ( |
|
| 2016 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2017 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | + ) { |
|
| 2019 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2020 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2021 | + else { |
|
| 2022 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2023 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2027 | + // sauf si exception declaree : sauter cette etape |
|
| 2028 | + else { |
|
| 2029 | + if ( |
|
| 2030 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2031 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2032 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2033 | + ) { |
|
| 2034 | + $e = decompose_champ_id_objet($col); |
|
| 2035 | + $col = array_shift($e); |
|
| 2036 | + $where_complement = primary_doublee($e, $table); |
|
| 2037 | + } // Cas particulier : expressions de date |
|
| 2038 | + else { |
|
| 2039 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2040 | + [$col, $col_vraie] = $c; |
|
| 2041 | + $table = ''; |
|
| 2042 | + } // table explicitée {mots.titre} |
|
| 2043 | + else { |
|
| 2044 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2045 | + [, $table, $col] = $r; |
|
| 2046 | + $col_alias = $col; |
|
| 2047 | + |
|
| 2048 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2049 | + if ( |
|
| 2050 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2051 | + and isset($desc['field'][$col]) |
|
| 2052 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2053 | + ) { |
|
| 2054 | + $table = $cle; |
|
| 2055 | + } else { |
|
| 2056 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2057 | + } |
|
| 2058 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2059 | + if (!$table) { |
|
| 2060 | + return ''; |
|
| 2061 | + } |
|
| 2062 | + } |
|
| 2063 | + // si le champ n'est pas trouvé dans la table, |
|
| 2064 | + // on cherche si une jointure peut l'obtenir |
|
| 2065 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2066 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2067 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2068 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2069 | + } |
|
| 2070 | + else { |
|
| 2071 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2072 | + if (!$r) { |
|
| 2073 | + return ''; |
|
| 2074 | + } |
|
| 2075 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2076 | + } |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + } |
|
| 2081 | + } |
|
| 2082 | + |
|
| 2083 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2084 | + // Dans tous les cas, |
|
| 2085 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2086 | + // et passer dans sql_quote avec le type si connu |
|
| 2087 | + // et int sinon si la valeur est numerique |
|
| 2088 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2089 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2090 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2091 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2092 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2093 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2094 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2095 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2096 | + } |
|
| 2097 | + // sinon expliciter les |
|
| 2098 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2099 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2100 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2101 | + // sans toucher aux |
|
| 2102 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2103 | + // sql_quote(truc,'','varchar') |
|
| 2104 | + elseif ( |
|
| 2105 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2106 | + // si pas deja un type |
|
| 2107 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2108 | + ) { |
|
| 2109 | + $r = $r[1] |
|
| 2110 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2111 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2112 | + $val[0] = "sql_quote($r)"; |
|
| 2113 | + } |
|
| 2114 | + elseif ( |
|
| 2115 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2116 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2117 | + ) { |
|
| 2118 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + if ( |
|
| 2123 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2124 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2125 | + ) { |
|
| 2126 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2127 | + } |
|
| 2128 | + |
|
| 2129 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2130 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2131 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2132 | + if ($table === $boucle->id_table) { |
|
| 2133 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2134 | + if ($col_alias != $col_vraie) { |
|
| 2135 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2136 | + } |
|
| 2137 | + } |
|
| 2138 | + |
|
| 2139 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2140 | + if ($table) { |
|
| 2141 | + if ($col[0] == '`') { |
|
| 2142 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2143 | + } else { |
|
| 2144 | + $arg = "$table.$col"; |
|
| 2145 | + } |
|
| 2146 | + } else { |
|
| 2147 | + $arg = $col; |
|
| 2148 | + } |
|
| 2149 | + |
|
| 2150 | + // inserer la fonction SQL |
|
| 2151 | + if ($fct) { |
|
| 2152 | + $arg = "$fct($arg$args_sql)"; |
|
| 2153 | + } |
|
| 2154 | + |
|
| 2155 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | |
@@ -2181,77 +2181,77 @@ discard block |
||
| 2181 | 2181 | **/ |
| 2182 | 2182 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2183 | 2183 | |
| 2184 | - $where = ''; |
|
| 2185 | - |
|
| 2186 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2187 | - // gestion par les plugins des jointures tordues |
|
| 2188 | - // pas automatiques mais necessaires |
|
| 2189 | - $table_sql = table_objet_sql($table); |
|
| 2190 | - if ( |
|
| 2191 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2192 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | - and |
|
| 2194 | - ( |
|
| 2195 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2196 | - or |
|
| 2197 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2198 | - ) |
|
| 2199 | - ) { |
|
| 2200 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2201 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2202 | - |
|
| 2203 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2204 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2205 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2206 | - [$t, $col] = $t[$col]; |
|
| 2207 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2208 | - [$calculer_critere_externe] = $index; |
|
| 2209 | - $t = $table; |
|
| 2210 | - } else { |
|
| 2211 | - $t = ''; |
|
| 2212 | - } // jointure non declaree. La trouver. |
|
| 2213 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2214 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2215 | - } else { |
|
| 2216 | - $t = ''; |
|
| 2217 | - } // jointure non declaree. La trouver. |
|
| 2218 | - |
|
| 2219 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2220 | - |
|
| 2221 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2222 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2223 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2224 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2225 | - $table = ''; |
|
| 2226 | - if ($boucle->jointures_explicites) { |
|
| 2227 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2228 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2232 | - if (!$table) { |
|
| 2233 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2234 | - } |
|
| 2235 | - |
|
| 2236 | - if (!$table) { |
|
| 2237 | - return ''; |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2241 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2242 | - |
|
| 2243 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2244 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2245 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2246 | - $e = decompose_champ_id_objet($col); |
|
| 2247 | - $col = array_shift($e); |
|
| 2248 | - $where = primary_doublee($e, $table); |
|
| 2249 | - } else { |
|
| 2250 | - $col = reset($cle); |
|
| 2251 | - } |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2184 | + $where = ''; |
|
| 2185 | + |
|
| 2186 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2187 | + // gestion par les plugins des jointures tordues |
|
| 2188 | + // pas automatiques mais necessaires |
|
| 2189 | + $table_sql = table_objet_sql($table); |
|
| 2190 | + if ( |
|
| 2191 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2192 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | + and |
|
| 2194 | + ( |
|
| 2195 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2196 | + or |
|
| 2197 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2198 | + ) |
|
| 2199 | + ) { |
|
| 2200 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2201 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2202 | + |
|
| 2203 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2204 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2205 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2206 | + [$t, $col] = $t[$col]; |
|
| 2207 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2208 | + [$calculer_critere_externe] = $index; |
|
| 2209 | + $t = $table; |
|
| 2210 | + } else { |
|
| 2211 | + $t = ''; |
|
| 2212 | + } // jointure non declaree. La trouver. |
|
| 2213 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2214 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2215 | + } else { |
|
| 2216 | + $t = ''; |
|
| 2217 | + } // jointure non declaree. La trouver. |
|
| 2218 | + |
|
| 2219 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2220 | + |
|
| 2221 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2222 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2223 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2224 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2225 | + $table = ''; |
|
| 2226 | + if ($boucle->jointures_explicites) { |
|
| 2227 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2228 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2232 | + if (!$table) { |
|
| 2233 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2234 | + } |
|
| 2235 | + |
|
| 2236 | + if (!$table) { |
|
| 2237 | + return ''; |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2241 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2242 | + |
|
| 2243 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2244 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2245 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2246 | + $e = decompose_champ_id_objet($col); |
|
| 2247 | + $col = array_shift($e); |
|
| 2248 | + $where = primary_doublee($e, $table); |
|
| 2249 | + } else { |
|
| 2250 | + $col = reset($cle); |
|
| 2251 | + } |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | |
@@ -2272,10 +2272,10 @@ discard block |
||
| 2272 | 2272 | * - valeur |
| 2273 | 2273 | **/ |
| 2274 | 2274 | function primary_doublee($decompose, $table) { |
| 2275 | - $e1 = reset($decompose); |
|
| 2276 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2275 | + $e1 = reset($decompose); |
|
| 2276 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2277 | 2277 | |
| 2278 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2278 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2279 | 2279 | } |
| 2280 | 2280 | |
| 2281 | 2281 | /** |
@@ -2306,57 +2306,57 @@ discard block |
||
| 2306 | 2306 | * Vide sinon. |
| 2307 | 2307 | */ |
| 2308 | 2308 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2309 | - // si on demande un truc du genre spip_mots |
|
| 2310 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2311 | - // et qu'on est la |
|
| 2312 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2313 | - if ( |
|
| 2314 | - $checkarrivee |
|
| 2315 | - and is_string($checkarrivee) |
|
| 2316 | - and $a = table_objet($checkarrivee) |
|
| 2317 | - and in_array($a . '_liens', $joints) |
|
| 2318 | - ) { |
|
| 2319 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2320 | - return $res; |
|
| 2321 | - } |
|
| 2322 | - } |
|
| 2323 | - foreach ($joints as $joint) { |
|
| 2324 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2325 | - // alias de table dans le from |
|
| 2326 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2327 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2328 | - $cols = $arrivee[2]; |
|
| 2329 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2330 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2331 | - array_pop($cols); |
|
| 2332 | - } |
|
| 2333 | - if ($t) { |
|
| 2334 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2335 | - $joindre = false; |
|
| 2336 | - foreach ($cols as $col) { |
|
| 2337 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2338 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2339 | - $joindre = true; |
|
| 2340 | - } else { |
|
| 2341 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2342 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2343 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2344 | - $joindre = true; |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - } |
|
| 2348 | - if (!$joindre) { |
|
| 2349 | - return $t; |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - array_pop($arrivee); |
|
| 2353 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2354 | - return $res; |
|
| 2355 | - } |
|
| 2356 | - } |
|
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - return ''; |
|
| 2309 | + // si on demande un truc du genre spip_mots |
|
| 2310 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2311 | + // et qu'on est la |
|
| 2312 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2313 | + if ( |
|
| 2314 | + $checkarrivee |
|
| 2315 | + and is_string($checkarrivee) |
|
| 2316 | + and $a = table_objet($checkarrivee) |
|
| 2317 | + and in_array($a . '_liens', $joints) |
|
| 2318 | + ) { |
|
| 2319 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2320 | + return $res; |
|
| 2321 | + } |
|
| 2322 | + } |
|
| 2323 | + foreach ($joints as $joint) { |
|
| 2324 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2325 | + // alias de table dans le from |
|
| 2326 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2327 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2328 | + $cols = $arrivee[2]; |
|
| 2329 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2330 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2331 | + array_pop($cols); |
|
| 2332 | + } |
|
| 2333 | + if ($t) { |
|
| 2334 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2335 | + $joindre = false; |
|
| 2336 | + foreach ($cols as $col) { |
|
| 2337 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2338 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2339 | + $joindre = true; |
|
| 2340 | + } else { |
|
| 2341 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2342 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2343 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2344 | + $joindre = true; |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + } |
|
| 2348 | + if (!$joindre) { |
|
| 2349 | + return $t; |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + array_pop($arrivee); |
|
| 2353 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2354 | + return $res; |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + } |
|
| 2358 | + |
|
| 2359 | + return ''; |
|
| 2360 | 2360 | } |
| 2361 | 2361 | |
| 2362 | 2362 | /** |
@@ -2382,35 +2382,35 @@ discard block |
||
| 2382 | 2382 | * Alias de la table de jointure (Lx) |
| 2383 | 2383 | */ |
| 2384 | 2384 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2385 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2386 | - |
|
| 2387 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2388 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2389 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2390 | - |
|
| 2391 | - if (!$intermediaire or !$arrivee) { |
|
| 2392 | - return ''; |
|
| 2393 | - } |
|
| 2394 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2395 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2396 | - |
|
| 2397 | - $res = fabrique_jointures( |
|
| 2398 | - $boucle, |
|
| 2399 | - [ |
|
| 2400 | - [ |
|
| 2401 | - $boucle->id_table, |
|
| 2402 | - $intermediaire, |
|
| 2403 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2404 | - ], |
|
| 2405 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2406 | - ], |
|
| 2407 | - $cond, |
|
| 2408 | - $desc, |
|
| 2409 | - $boucle->id_table, |
|
| 2410 | - [$col] |
|
| 2411 | - ); |
|
| 2412 | - |
|
| 2413 | - return $res; |
|
| 2385 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2386 | + |
|
| 2387 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2388 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2389 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2390 | + |
|
| 2391 | + if (!$intermediaire or !$arrivee) { |
|
| 2392 | + return ''; |
|
| 2393 | + } |
|
| 2394 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2395 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2396 | + |
|
| 2397 | + $res = fabrique_jointures( |
|
| 2398 | + $boucle, |
|
| 2399 | + [ |
|
| 2400 | + [ |
|
| 2401 | + $boucle->id_table, |
|
| 2402 | + $intermediaire, |
|
| 2403 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2404 | + ], |
|
| 2405 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2406 | + ], |
|
| 2407 | + $cond, |
|
| 2408 | + $desc, |
|
| 2409 | + $boucle->id_table, |
|
| 2410 | + [$col] |
|
| 2411 | + ); |
|
| 2412 | + |
|
| 2413 | + return $res; |
|
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | |
@@ -2427,17 +2427,17 @@ discard block |
||
| 2427 | 2427 | * false sinon. |
| 2428 | 2428 | **/ |
| 2429 | 2429 | function trouver_champ($champ, $where) { |
| 2430 | - if (!is_array($where)) { |
|
| 2431 | - return preg_match($champ, $where); |
|
| 2432 | - } else { |
|
| 2433 | - foreach ($where as $clause) { |
|
| 2434 | - if (trouver_champ($champ, $clause)) { |
|
| 2435 | - return true; |
|
| 2436 | - } |
|
| 2437 | - } |
|
| 2438 | - |
|
| 2439 | - return false; |
|
| 2440 | - } |
|
| 2430 | + if (!is_array($where)) { |
|
| 2431 | + return preg_match($champ, $where); |
|
| 2432 | + } else { |
|
| 2433 | + foreach ($where as $clause) { |
|
| 2434 | + if (trouver_champ($champ, $clause)) { |
|
| 2435 | + return true; |
|
| 2436 | + } |
|
| 2437 | + } |
|
| 2438 | + |
|
| 2439 | + return false; |
|
| 2440 | + } |
|
| 2441 | 2441 | } |
| 2442 | 2442 | |
| 2443 | 2443 | |
@@ -2463,129 +2463,129 @@ discard block |
||
| 2463 | 2463 | * - string $args_sql Suite des arguments du critère. ? |
| 2464 | 2464 | **/ |
| 2465 | 2465 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2466 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2467 | - if (count($crit->param) == 0) { |
|
| 2468 | - $op = '='; |
|
| 2469 | - $col = $val = $crit->op; |
|
| 2470 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2471 | - $val = $r[2]; |
|
| 2472 | - } |
|
| 2473 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2474 | - if ($val == 'lang') { |
|
| 2475 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2476 | - } else { |
|
| 2477 | - $defaut = null; |
|
| 2478 | - if ($val == 'id_parent') { |
|
| 2479 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2480 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2481 | - // pour eviter l'erreur SQL |
|
| 2482 | - $val = $boucles[$idb]->primary; |
|
| 2483 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2484 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2485 | - } elseif ($val == 'id_enfant') { |
|
| 2486 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2487 | - // de la boucle superieure |
|
| 2488 | - $val = 'id_parent'; |
|
| 2489 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2490 | - // un critere conditionnel sur date est traite a part |
|
| 2491 | - // car la date est mise d'office par SPIP, |
|
| 2492 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2496 | - $val = [kwote($val)]; |
|
| 2497 | - } |
|
| 2498 | - } else { |
|
| 2499 | - // comparaison explicite |
|
| 2500 | - // le phraseur impose que le premier param soit du texte |
|
| 2501 | - $params = $crit->param; |
|
| 2502 | - $op = $crit->op; |
|
| 2503 | - if ($op == '==') { |
|
| 2504 | - $op = 'REGEXP'; |
|
| 2505 | - } |
|
| 2506 | - $col = array_shift($params); |
|
| 2507 | - $col = $col[0]->texte; |
|
| 2508 | - |
|
| 2509 | - $val = []; |
|
| 2510 | - $parent = $boucles[$idb]->id_parent; |
|
| 2511 | - |
|
| 2512 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2513 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2514 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2515 | - if ( |
|
| 2516 | - count($params) == 1 |
|
| 2517 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2518 | - and $params[0][0]->type == 'texte' |
|
| 2519 | - and $params[0][2]->type == 'texte' |
|
| 2520 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2521 | - and (($p == "'") or ($p == '"')) |
|
| 2522 | - and $params[0][1]->type == 'champ' |
|
| 2523 | - ) { |
|
| 2524 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2525 | - } else { |
|
| 2526 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2527 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2528 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2529 | - $val[] = $a; |
|
| 2530 | - } else { |
|
| 2531 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2532 | - } // toujours quoter en char ici |
|
| 2533 | - } |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - $fct = $args_sql = ''; |
|
| 2538 | - // fonction SQL ? |
|
| 2539 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2540 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2541 | - $fct = $m[1]; |
|
| 2542 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2543 | - $col = $a[1]; |
|
| 2544 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2545 | - $col = $m[1]; |
|
| 2546 | - $args_sql = $m[2]; |
|
| 2547 | - } |
|
| 2548 | - $args_sql .= $a[2]; |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2466 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2467 | + if (count($crit->param) == 0) { |
|
| 2468 | + $op = '='; |
|
| 2469 | + $col = $val = $crit->op; |
|
| 2470 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2471 | + $val = $r[2]; |
|
| 2472 | + } |
|
| 2473 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2474 | + if ($val == 'lang') { |
|
| 2475 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2476 | + } else { |
|
| 2477 | + $defaut = null; |
|
| 2478 | + if ($val == 'id_parent') { |
|
| 2479 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2480 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2481 | + // pour eviter l'erreur SQL |
|
| 2482 | + $val = $boucles[$idb]->primary; |
|
| 2483 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2484 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2485 | + } elseif ($val == 'id_enfant') { |
|
| 2486 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2487 | + // de la boucle superieure |
|
| 2488 | + $val = 'id_parent'; |
|
| 2489 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2490 | + // un critere conditionnel sur date est traite a part |
|
| 2491 | + // car la date est mise d'office par SPIP, |
|
| 2492 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2496 | + $val = [kwote($val)]; |
|
| 2497 | + } |
|
| 2498 | + } else { |
|
| 2499 | + // comparaison explicite |
|
| 2500 | + // le phraseur impose que le premier param soit du texte |
|
| 2501 | + $params = $crit->param; |
|
| 2502 | + $op = $crit->op; |
|
| 2503 | + if ($op == '==') { |
|
| 2504 | + $op = 'REGEXP'; |
|
| 2505 | + } |
|
| 2506 | + $col = array_shift($params); |
|
| 2507 | + $col = $col[0]->texte; |
|
| 2508 | + |
|
| 2509 | + $val = []; |
|
| 2510 | + $parent = $boucles[$idb]->id_parent; |
|
| 2511 | + |
|
| 2512 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2513 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2514 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2515 | + if ( |
|
| 2516 | + count($params) == 1 |
|
| 2517 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2518 | + and $params[0][0]->type == 'texte' |
|
| 2519 | + and $params[0][2]->type == 'texte' |
|
| 2520 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2521 | + and (($p == "'") or ($p == '"')) |
|
| 2522 | + and $params[0][1]->type == 'champ' |
|
| 2523 | + ) { |
|
| 2524 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2525 | + } else { |
|
| 2526 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2527 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2528 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2529 | + $val[] = $a; |
|
| 2530 | + } else { |
|
| 2531 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2532 | + } // toujours quoter en char ici |
|
| 2533 | + } |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + $fct = $args_sql = ''; |
|
| 2538 | + // fonction SQL ? |
|
| 2539 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2540 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2541 | + $fct = $m[1]; |
|
| 2542 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2543 | + $col = $a[1]; |
|
| 2544 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2545 | + $col = $m[1]; |
|
| 2546 | + $args_sql = $m[2]; |
|
| 2547 | + } |
|
| 2548 | + $args_sql .= $a[2]; |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2552 | 2552 | } |
| 2553 | 2553 | |
| 2554 | 2554 | // compatibilite ancienne version |
| 2555 | 2555 | |
| 2556 | 2556 | function calculer_vieux_in($params) { |
| 2557 | - $deb = $params[0][0]; |
|
| 2558 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2559 | - $last = $params[$k]; |
|
| 2560 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2561 | - $last = $last[$j]; |
|
| 2562 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2563 | - |
|
| 2564 | - if ( |
|
| 2565 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2566 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2567 | - ) { |
|
| 2568 | - return $params; |
|
| 2569 | - } |
|
| 2570 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2571 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2572 | - $last = $params[$k][$j]; |
|
| 2573 | - $n = strlen($last->texte); |
|
| 2574 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2575 | - $newp = []; |
|
| 2576 | - foreach ($params as $v) { |
|
| 2577 | - if ($v[0]->type != 'texte') { |
|
| 2578 | - $newp[] = $v; |
|
| 2579 | - } else { |
|
| 2580 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2581 | - $t = new Texte(); |
|
| 2582 | - $t->texte = $x; |
|
| 2583 | - $newp[] = [$t]; |
|
| 2584 | - } |
|
| 2585 | - } |
|
| 2586 | - } |
|
| 2587 | - |
|
| 2588 | - return $newp; |
|
| 2557 | + $deb = $params[0][0]; |
|
| 2558 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2559 | + $last = $params[$k]; |
|
| 2560 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2561 | + $last = $last[$j]; |
|
| 2562 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2563 | + |
|
| 2564 | + if ( |
|
| 2565 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2566 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2567 | + ) { |
|
| 2568 | + return $params; |
|
| 2569 | + } |
|
| 2570 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2571 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2572 | + $last = $params[$k][$j]; |
|
| 2573 | + $n = strlen($last->texte); |
|
| 2574 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2575 | + $newp = []; |
|
| 2576 | + foreach ($params as $v) { |
|
| 2577 | + if ($v[0]->type != 'texte') { |
|
| 2578 | + $newp[] = $v; |
|
| 2579 | + } else { |
|
| 2580 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2581 | + $t = new Texte(); |
|
| 2582 | + $t->texte = $x; |
|
| 2583 | + $newp[] = [$t]; |
|
| 2584 | + } |
|
| 2585 | + } |
|
| 2586 | + } |
|
| 2587 | + |
|
| 2588 | + return $newp; |
|
| 2589 | 2589 | } |
| 2590 | 2590 | |
| 2591 | 2591 | /** |
@@ -2604,89 +2604,89 @@ discard block |
||
| 2604 | 2604 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2605 | 2605 | **/ |
| 2606 | 2606 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2607 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2608 | - return ''; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - $boucle = $boucles[$idb]; |
|
| 2612 | - $table = $boucle->show; |
|
| 2613 | - |
|
| 2614 | - // si c'est une colonne de la table, ne rien faire |
|
| 2615 | - if (isset($table['field'][$col])) { |
|
| 2616 | - return ''; |
|
| 2617 | - } |
|
| 2618 | - |
|
| 2619 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2620 | - return ''; |
|
| 2621 | - } |
|
| 2622 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2623 | - |
|
| 2624 | - $col = $regs[1]; |
|
| 2625 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2626 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2627 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2628 | - |
|
| 2629 | - if (isset($table['field']["date$suite"])) { |
|
| 2630 | - $date_orig = 'date' . $suite; |
|
| 2631 | - } else { |
|
| 2632 | - $date_orig = substr($suite, 1); |
|
| 2633 | - } |
|
| 2634 | - $pred = $date_orig; |
|
| 2635 | - } else { |
|
| 2636 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2637 | - $pred = 'date'; |
|
| 2638 | - } |
|
| 2639 | - } |
|
| 2640 | - |
|
| 2641 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2643 | - ") . '\""; |
|
| 2644 | - |
|
| 2645 | - $col_vraie = $date_orig; |
|
| 2646 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2647 | - |
|
| 2648 | - switch ($col) { |
|
| 2649 | - case 'date': |
|
| 2650 | - $col = $date_orig; |
|
| 2651 | - break; |
|
| 2652 | - case 'jour': |
|
| 2653 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2654 | - break; |
|
| 2655 | - case 'mois': |
|
| 2656 | - $col = "MONTH($date_orig)"; |
|
| 2657 | - break; |
|
| 2658 | - case 'annee': |
|
| 2659 | - $col = "YEAR($date_orig)"; |
|
| 2660 | - break; |
|
| 2661 | - case 'heure': |
|
| 2662 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2663 | - break; |
|
| 2664 | - case 'age': |
|
| 2665 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2666 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2667 | - break; |
|
| 2668 | - case 'age_relatif': |
|
| 2669 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2670 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | - break; |
|
| 2672 | - case 'jour_relatif': |
|
| 2673 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | - break; |
|
| 2676 | - case 'mois_relatif': |
|
| 2677 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | - break; |
|
| 2682 | - case 'annee_relatif': |
|
| 2683 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | - $date_orig . ')'; |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | - break; |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - return [$col, $col_vraie]; |
|
| 2607 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2608 | + return ''; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + $boucle = $boucles[$idb]; |
|
| 2612 | + $table = $boucle->show; |
|
| 2613 | + |
|
| 2614 | + // si c'est une colonne de la table, ne rien faire |
|
| 2615 | + if (isset($table['field'][$col])) { |
|
| 2616 | + return ''; |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2620 | + return ''; |
|
| 2621 | + } |
|
| 2622 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2623 | + |
|
| 2624 | + $col = $regs[1]; |
|
| 2625 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2626 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2627 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2628 | + |
|
| 2629 | + if (isset($table['field']["date$suite"])) { |
|
| 2630 | + $date_orig = 'date' . $suite; |
|
| 2631 | + } else { |
|
| 2632 | + $date_orig = substr($suite, 1); |
|
| 2633 | + } |
|
| 2634 | + $pred = $date_orig; |
|
| 2635 | + } else { |
|
| 2636 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2637 | + $pred = 'date'; |
|
| 2638 | + } |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2643 | + ") . '\""; |
|
| 2644 | + |
|
| 2645 | + $col_vraie = $date_orig; |
|
| 2646 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2647 | + |
|
| 2648 | + switch ($col) { |
|
| 2649 | + case 'date': |
|
| 2650 | + $col = $date_orig; |
|
| 2651 | + break; |
|
| 2652 | + case 'jour': |
|
| 2653 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2654 | + break; |
|
| 2655 | + case 'mois': |
|
| 2656 | + $col = "MONTH($date_orig)"; |
|
| 2657 | + break; |
|
| 2658 | + case 'annee': |
|
| 2659 | + $col = "YEAR($date_orig)"; |
|
| 2660 | + break; |
|
| 2661 | + case 'heure': |
|
| 2662 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2663 | + break; |
|
| 2664 | + case 'age': |
|
| 2665 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2666 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2667 | + break; |
|
| 2668 | + case 'age_relatif': |
|
| 2669 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2670 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | + break; |
|
| 2672 | + case 'jour_relatif': |
|
| 2673 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + break; |
|
| 2676 | + case 'mois_relatif': |
|
| 2677 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + break; |
|
| 2682 | + case 'annee_relatif': |
|
| 2683 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | + $date_orig . ')'; |
|
| 2685 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + break; |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + return [$col, $col_vraie]; |
|
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | /** |
@@ -2705,16 +2705,16 @@ discard block |
||
| 2705 | 2705 | * de colonne SQL et une date. |
| 2706 | 2706 | **/ |
| 2707 | 2707 | function calculer_param_date($date_compare, $date_orig) { |
| 2708 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2709 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2710 | - $date_compare = '\'$x\''; |
|
| 2711 | - } else { |
|
| 2712 | - $init = $date_compare; |
|
| 2713 | - } |
|
| 2714 | - |
|
| 2715 | - return |
|
| 2716 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2717 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2708 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2709 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2710 | + $date_compare = '\'$x\''; |
|
| 2711 | + } else { |
|
| 2712 | + $init = $date_compare; |
|
| 2713 | + } |
|
| 2714 | + |
|
| 2715 | + return |
|
| 2716 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2717 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2718 | 2718 | } |
| 2719 | 2719 | |
| 2720 | 2720 | /** |
@@ -2732,20 +2732,20 @@ discard block |
||
| 2732 | 2732 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2733 | 2733 | */ |
| 2734 | 2734 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2735 | - $boucle = &$boucles[$idb]; |
|
| 2736 | - |
|
| 2737 | - $args = []; |
|
| 2738 | - foreach ($crit->param as &$param) { |
|
| 2739 | - array_push( |
|
| 2740 | - $args, |
|
| 2741 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2742 | - ); |
|
| 2743 | - } |
|
| 2735 | + $boucle = &$boucles[$idb]; |
|
| 2744 | 2736 | |
| 2745 | - $boucle->hash .= ' |
|
| 2737 | + $args = []; |
|
| 2738 | + foreach ($crit->param as &$param) { |
|
| 2739 | + array_push( |
|
| 2740 | + $args, |
|
| 2741 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2742 | + ); |
|
| 2743 | + } |
|
| 2744 | + |
|
| 2745 | + $boucle->hash .= ' |
|
| 2746 | 2746 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2747 | 2747 | |
| 2748 | - $boucle->hash .= ' |
|
| 2748 | + $boucle->hash .= ' |
|
| 2749 | 2749 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2750 | 2750 | } |
| 2751 | 2751 | |
@@ -2763,8 +2763,8 @@ discard block |
||
| 2763 | 2763 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2764 | 2764 | */ |
| 2765 | 2765 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2766 | - $boucle = &$boucles[$idb]; |
|
| 2767 | - $boucle->hash .= ' |
|
| 2766 | + $boucle = &$boucles[$idb]; |
|
| 2767 | + $boucle->hash .= ' |
|
| 2768 | 2768 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2769 | 2769 | } |
| 2770 | 2770 | |
@@ -2780,12 +2780,12 @@ discard block |
||
| 2780 | 2780 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2781 | 2781 | */ |
| 2782 | 2782 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2783 | - $boucle = &$boucles[$idb]; |
|
| 2784 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2785 | - foreach ($crit->param as $param) { |
|
| 2786 | - $boucle->hash .= ' |
|
| 2783 | + $boucle = &$boucles[$idb]; |
|
| 2784 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2785 | + foreach ($crit->param as $param) { |
|
| 2786 | + $boucle->hash .= ' |
|
| 2787 | 2787 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2788 | - } |
|
| 2788 | + } |
|
| 2789 | 2789 | } |
| 2790 | 2790 | |
| 2791 | 2791 | /** |
@@ -2802,16 +2802,16 @@ discard block |
||
| 2802 | 2802 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2803 | 2803 | */ |
| 2804 | 2804 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2805 | - $boucle = &$boucles[$idb]; |
|
| 2806 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2807 | - foreach ($crit->param as $param) { |
|
| 2808 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2809 | - $param, |
|
| 2810 | - $idb, |
|
| 2811 | - $boucles, |
|
| 2812 | - $boucles[$idb]->id_parent |
|
| 2813 | - ) . ";\n"; |
|
| 2814 | - } |
|
| 2805 | + $boucle = &$boucles[$idb]; |
|
| 2806 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2807 | + foreach ($crit->param as $param) { |
|
| 2808 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2809 | + $param, |
|
| 2810 | + $idb, |
|
| 2811 | + $boucles, |
|
| 2812 | + $boucles[$idb]->id_parent |
|
| 2813 | + ) . ";\n"; |
|
| 2814 | + } |
|
| 2815 | 2815 | } |
| 2816 | 2816 | |
| 2817 | 2817 | /** |
@@ -2836,16 +2836,16 @@ discard block |
||
| 2836 | 2836 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2837 | 2837 | */ |
| 2838 | 2838 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2839 | - $boucle = &$boucles[$idb]; |
|
| 2840 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2841 | - foreach ($crit->param as $param) { |
|
| 2842 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2843 | - $param, |
|
| 2844 | - $idb, |
|
| 2845 | - $boucles, |
|
| 2846 | - $boucles[$idb]->id_parent |
|
| 2847 | - ) . ";\n"; |
|
| 2848 | - } |
|
| 2839 | + $boucle = &$boucles[$idb]; |
|
| 2840 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2841 | + foreach ($crit->param as $param) { |
|
| 2842 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2843 | + $param, |
|
| 2844 | + $idb, |
|
| 2845 | + $boucles, |
|
| 2846 | + $boucles[$idb]->id_parent |
|
| 2847 | + ) . ";\n"; |
|
| 2848 | + } |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | /** |
@@ -2860,11 +2860,11 @@ discard block |
||
| 2860 | 2860 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2861 | 2861 | */ |
| 2862 | 2862 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2863 | - $boucle = &$boucles[$idb]; |
|
| 2864 | - foreach ($crit->param as $param) { |
|
| 2865 | - $boucle->hash .= ' |
|
| 2863 | + $boucle = &$boucles[$idb]; |
|
| 2864 | + foreach ($crit->param as $param) { |
|
| 2865 | + $boucle->hash .= ' |
|
| 2866 | 2866 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2867 | - } |
|
| 2867 | + } |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | |
@@ -2896,20 +2896,20 @@ discard block |
||
| 2896 | 2896 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2897 | 2897 | */ |
| 2898 | 2898 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2899 | - $boucle = &$boucles[$idb]; |
|
| 2900 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2901 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2902 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2903 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2904 | - if ($crit->param) { |
|
| 2905 | - foreach ($crit->param as $param) { |
|
| 2906 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2907 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2908 | - } |
|
| 2909 | - // interdire {si 0} aussi ! |
|
| 2910 | - } else { |
|
| 2911 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2912 | - } |
|
| 2899 | + $boucle = &$boucles[$idb]; |
|
| 2900 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2901 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2902 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2903 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2904 | + if ($crit->param) { |
|
| 2905 | + foreach ($crit->param as $param) { |
|
| 2906 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2907 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2908 | + } |
|
| 2909 | + // interdire {si 0} aussi ! |
|
| 2910 | + } else { |
|
| 2911 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2912 | + } |
|
| 2913 | 2913 | } |
| 2914 | 2914 | |
| 2915 | 2915 | /** |
@@ -2926,8 +2926,8 @@ discard block |
||
| 2926 | 2926 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2927 | 2927 | */ |
| 2928 | 2928 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2929 | - $boucle = &$boucles[$idb]; |
|
| 2930 | - $boucle->hash .= ' |
|
| 2929 | + $boucle = &$boucles[$idb]; |
|
| 2930 | + $boucle->hash .= ' |
|
| 2931 | 2931 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2932 | 2932 | $command[\'sourcemode\'] = \'table\';'; |
| 2933 | 2933 | } |
@@ -2948,27 +2948,27 @@ discard block |
||
| 2948 | 2948 | */ |
| 2949 | 2949 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2950 | 2950 | |
| 2951 | - $not = $crit->not; |
|
| 2952 | - $boucle = &$boucles[$idb]; |
|
| 2953 | - $primary = $boucle->primary; |
|
| 2951 | + $not = $crit->not; |
|
| 2952 | + $boucle = &$boucles[$idb]; |
|
| 2953 | + $primary = $boucle->primary; |
|
| 2954 | 2954 | |
| 2955 | - if (!$primary or strpos($primary, ',')) { |
|
| 2956 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2955 | + if (!$primary or strpos($primary, ',')) { |
|
| 2956 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2957 | 2957 | |
| 2958 | - return; |
|
| 2959 | - } |
|
| 2960 | - $table = $boucle->type_requete; |
|
| 2961 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2958 | + return; |
|
| 2959 | + } |
|
| 2960 | + $table = $boucle->type_requete; |
|
| 2961 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2962 | 2962 | |
| 2963 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2963 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2964 | 2964 | |
| 2965 | - $in = 'IN'; |
|
| 2966 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | - if ($not) { |
|
| 2968 | - $where = ["'NOT'", $where]; |
|
| 2969 | - } |
|
| 2965 | + $in = 'IN'; |
|
| 2966 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | + if ($not) { |
|
| 2968 | + $where = ["'NOT'", $where]; |
|
| 2969 | + } |
|
| 2970 | 2970 | |
| 2971 | - $boucle->where[] = $where; |
|
| 2971 | + $boucle->where[] = $where; |
|
| 2972 | 2972 | } |
| 2973 | 2973 | |
| 2974 | 2974 | /** |
@@ -2984,8 +2984,8 @@ discard block |
||
| 2984 | 2984 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2985 | 2985 | */ |
| 2986 | 2986 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2987 | - $not = $crit->not; |
|
| 2988 | - $crit->not = $not ? false : true; |
|
| 2989 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2990 | - $crit->not = $not; |
|
| 2987 | + $not = $crit->not; |
|
| 2988 | + $crit->not = $not ? false : true; |
|
| 2989 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2990 | + $crit->not = $not; |
|
| 2991 | 2991 | } |
@@ -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 | /** |
@@ -32,116 +32,116 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 34 | 34 | |
| 35 | - // retrouver le login |
|
| 36 | - $login = auth_spip_retrouver_login($login); |
|
| 37 | - // login inconnu, n'allons pas plus loin |
|
| 38 | - if (!$login) { |
|
| 39 | - return []; |
|
| 40 | - } |
|
| 41 | - |
|
| 42 | - $md5pass = ''; |
|
| 43 | - $shapass = $shanext = ''; |
|
| 44 | - |
|
| 45 | - if (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i', $pass, $regs)) { |
|
| 46 | - $shapass = $regs[1]; |
|
| 47 | - $shanext = $regs[2]; |
|
| 48 | - } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash |
|
| 49 | - elseif (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i', $pass, $regs)) { |
|
| 50 | - $shapass = $regs[1]; |
|
| 51 | - $shanext = $regs[2]; |
|
| 52 | - $md5pass = $regs[3]; |
|
| 53 | - //$md5next = $regs[4]; |
|
| 54 | - } // si envoi non crypte, crypter maintenant |
|
| 55 | - elseif ($pass) { |
|
| 56 | - $row = sql_fetsel( |
|
| 57 | - 'alea_actuel, alea_futur', |
|
| 58 | - 'spip_auteurs', |
|
| 59 | - 'login=' . sql_quote($login, $serveur, 'text'), |
|
| 60 | - '', |
|
| 61 | - '', |
|
| 62 | - '', |
|
| 63 | - '', |
|
| 64 | - $serveur |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - if ($row) { |
|
| 68 | - include_spip('auth/sha256.inc'); |
|
| 69 | - $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 70 | - $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 71 | - $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // login inexistant ou mot de passe vide |
|
| 76 | - if (!$shapass and !$md5pass) { |
|
| 77 | - return []; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $row = sql_fetsel( |
|
| 81 | - '*', |
|
| 82 | - 'spip_auteurs', |
|
| 83 | - 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 84 | - $shapass, |
|
| 85 | - $serveur, |
|
| 86 | - 'text' |
|
| 87 | - ) . " AND statut<>'5poubelle'", |
|
| 88 | - '', |
|
| 89 | - '', |
|
| 90 | - '', |
|
| 91 | - '', |
|
| 92 | - $serveur |
|
| 93 | - ); |
|
| 94 | - |
|
| 95 | - // compat avec les anciennes bases en md5 |
|
| 96 | - if (!$row and $md5pass) { |
|
| 97 | - $row = sql_fetsel( |
|
| 98 | - '*', |
|
| 99 | - 'spip_auteurs', |
|
| 100 | - 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 101 | - $md5pass, |
|
| 102 | - $serveur, |
|
| 103 | - 'text' |
|
| 104 | - ) . " AND statut<>'5poubelle'", |
|
| 105 | - '', |
|
| 106 | - '', |
|
| 107 | - '', |
|
| 108 | - '', |
|
| 109 | - $serveur |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - // login/mot de passe incorrect |
|
| 114 | - if (!$row) { |
|
| 115 | - return []; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - // fait tourner le codage du pass dans la base |
|
| 119 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 120 | - if ($shanext and !$phpauth) { |
|
| 121 | - include_spip('inc/acces'); // pour creer_uniqid |
|
| 122 | - @sql_update( |
|
| 123 | - 'spip_auteurs', |
|
| 124 | - [ |
|
| 125 | - 'alea_actuel' => 'alea_futur', |
|
| 126 | - 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 127 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 128 | - ], |
|
| 129 | - 'id_auteur=' . $row['id_auteur'] . ' AND pass IN (' . sql_quote( |
|
| 130 | - $shapass, |
|
| 131 | - $serveur, |
|
| 132 | - 'text' |
|
| 133 | - ) . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', |
|
| 134 | - [], |
|
| 135 | - $serveur |
|
| 136 | - ); |
|
| 137 | - // En profiter pour verifier la securite de tmp/ |
|
| 138 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 139 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 140 | - return false; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $row; |
|
| 35 | + // retrouver le login |
|
| 36 | + $login = auth_spip_retrouver_login($login); |
|
| 37 | + // login inconnu, n'allons pas plus loin |
|
| 38 | + if (!$login) { |
|
| 39 | + return []; |
|
| 40 | + } |
|
| 41 | + |
|
| 42 | + $md5pass = ''; |
|
| 43 | + $shapass = $shanext = ''; |
|
| 44 | + |
|
| 45 | + if (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64})\}$,i', $pass, $regs)) { |
|
| 46 | + $shapass = $regs[1]; |
|
| 47 | + $shanext = $regs[2]; |
|
| 48 | + } // compat avec une base mixte md5/sha256 : le js a envoye les 2 hash |
|
| 49 | + elseif (preg_match(',^\{([0-9a-f]{64});([0-9a-f]{64});([0-9a-f]{32});([0-9a-f]{32})\}$,i', $pass, $regs)) { |
|
| 50 | + $shapass = $regs[1]; |
|
| 51 | + $shanext = $regs[2]; |
|
| 52 | + $md5pass = $regs[3]; |
|
| 53 | + //$md5next = $regs[4]; |
|
| 54 | + } // si envoi non crypte, crypter maintenant |
|
| 55 | + elseif ($pass) { |
|
| 56 | + $row = sql_fetsel( |
|
| 57 | + 'alea_actuel, alea_futur', |
|
| 58 | + 'spip_auteurs', |
|
| 59 | + 'login=' . sql_quote($login, $serveur, 'text'), |
|
| 60 | + '', |
|
| 61 | + '', |
|
| 62 | + '', |
|
| 63 | + '', |
|
| 64 | + $serveur |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + if ($row) { |
|
| 68 | + include_spip('auth/sha256.inc'); |
|
| 69 | + $shapass = spip_sha256($row['alea_actuel'] . $pass); |
|
| 70 | + $shanext = spip_sha256($row['alea_futur'] . $pass); |
|
| 71 | + $md5pass = md5($row['alea_actuel'] . $pass); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // login inexistant ou mot de passe vide |
|
| 76 | + if (!$shapass and !$md5pass) { |
|
| 77 | + return []; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $row = sql_fetsel( |
|
| 81 | + '*', |
|
| 82 | + 'spip_auteurs', |
|
| 83 | + 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 84 | + $shapass, |
|
| 85 | + $serveur, |
|
| 86 | + 'text' |
|
| 87 | + ) . " AND statut<>'5poubelle'", |
|
| 88 | + '', |
|
| 89 | + '', |
|
| 90 | + '', |
|
| 91 | + '', |
|
| 92 | + $serveur |
|
| 93 | + ); |
|
| 94 | + |
|
| 95 | + // compat avec les anciennes bases en md5 |
|
| 96 | + if (!$row and $md5pass) { |
|
| 97 | + $row = sql_fetsel( |
|
| 98 | + '*', |
|
| 99 | + 'spip_auteurs', |
|
| 100 | + 'login=' . sql_quote($login, $serveur, 'text') . ' AND pass=' . sql_quote( |
|
| 101 | + $md5pass, |
|
| 102 | + $serveur, |
|
| 103 | + 'text' |
|
| 104 | + ) . " AND statut<>'5poubelle'", |
|
| 105 | + '', |
|
| 106 | + '', |
|
| 107 | + '', |
|
| 108 | + '', |
|
| 109 | + $serveur |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + // login/mot de passe incorrect |
|
| 114 | + if (!$row) { |
|
| 115 | + return []; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + // fait tourner le codage du pass dans la base |
|
| 119 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 120 | + if ($shanext and !$phpauth) { |
|
| 121 | + include_spip('inc/acces'); // pour creer_uniqid |
|
| 122 | + @sql_update( |
|
| 123 | + 'spip_auteurs', |
|
| 124 | + [ |
|
| 125 | + 'alea_actuel' => 'alea_futur', |
|
| 126 | + 'pass' => sql_quote($shanext, $serveur, 'text'), |
|
| 127 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text') |
|
| 128 | + ], |
|
| 129 | + 'id_auteur=' . $row['id_auteur'] . ' AND pass IN (' . sql_quote( |
|
| 130 | + $shapass, |
|
| 131 | + $serveur, |
|
| 132 | + 'text' |
|
| 133 | + ) . ', ' . sql_quote($md5pass, $serveur, 'text') . ')', |
|
| 134 | + [], |
|
| 135 | + $serveur |
|
| 136 | + ); |
|
| 137 | + // En profiter pour verifier la securite de tmp/ |
|
| 138 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 139 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 140 | + return false; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $row; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -151,41 +151,41 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function auth_spip_formulaire_login($flux) { |
| 154 | - // faut il encore envoyer md5 ? |
|
| 155 | - // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 156 | - // les hash md5 ont une longueur 32, les sha 64 |
|
| 157 | - // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 158 | - // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 159 | - $compat_md5 = false; |
|
| 160 | - if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 161 | - $compat_md5 = sql_countsel('spip_auteurs', "length(pass)=32 AND statut<>'poubelle'"); |
|
| 162 | - if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 163 | - effacer_meta('sha_256_only'); |
|
| 164 | - } |
|
| 165 | - if (!$compat_md5) { |
|
| 166 | - ecrire_meta('sha_256_only', 'oui'); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 171 | - $flux['data'] .= |
|
| 172 | - ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 173 | - . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 174 | - . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 175 | - . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 176 | - . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 177 | - . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 178 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 179 | - . "'informe_auteur_en_cours':false," |
|
| 180 | - . "'attente_informe':0," |
|
| 181 | - . "'compat_md5':" . ($compat_md5 ? 'true' : 'false') . '};' |
|
| 182 | - . "jQuery(function(){ |
|
| 154 | + // faut il encore envoyer md5 ? |
|
| 155 | + // on regarde si il reste des pass md5 en base pour des auteurs en statut pas poubelle |
|
| 156 | + // les hash md5 ont une longueur 32, les sha 64 |
|
| 157 | + // en evitant une requete sql a chaque affichage du formulaire login sans session |
|
| 158 | + // (perf issue pour les sites qui mettent le formulaire de login sur la home) |
|
| 159 | + $compat_md5 = false; |
|
| 160 | + if (!isset($GLOBALS['meta']['sha_256_only']) or _request('var_mode')) { |
|
| 161 | + $compat_md5 = sql_countsel('spip_auteurs', "length(pass)=32 AND statut<>'poubelle'"); |
|
| 162 | + if ($compat_md5 and isset($GLOBALS['meta']['sha_256_only'])) { |
|
| 163 | + effacer_meta('sha_256_only'); |
|
| 164 | + } |
|
| 165 | + if (!$compat_md5) { |
|
| 166 | + ecrire_meta('sha_256_only', 'oui'); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 171 | + $flux['data'] .= |
|
| 172 | + ($compat_md5 ? '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'md5.js"></script>' : '') |
|
| 173 | + . '<script type="text/javascript" src="' . _DIR_JAVASCRIPT . 'login-sha-min.js"></script>' |
|
| 174 | + . '<script type="text/javascript">/*<![CDATA[*/' |
|
| 175 | + . "var login_info={'alea_actuel':'" . $flux['args']['contexte']['_alea_actuel'] . "'," |
|
| 176 | + . "'alea_futur':'" . $flux['args']['contexte']['_alea_futur'] . "'," |
|
| 177 | + . "'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 178 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 179 | + . "'informe_auteur_en_cours':false," |
|
| 180 | + . "'attente_informe':0," |
|
| 181 | + . "'compat_md5':" . ($compat_md5 ? 'true' : 'false') . '};' |
|
| 182 | + . "jQuery(function(){ |
|
| 183 | 183 | jQuery('#var_login').change(actualise_auteur); |
| 184 | 184 | jQuery('form#formulaire_login').submit(login_submit); |
| 185 | 185 | });" |
| 186 | - . '/*]]>*/</script>'; |
|
| 186 | + . '/*]]>*/</script>'; |
|
| 187 | 187 | |
| 188 | - return $flux; |
|
| 188 | + return $flux; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -197,11 +197,11 @@ discard block |
||
| 197 | 197 | * toujours true pour un auteur cree dans SPIP |
| 198 | 198 | */ |
| 199 | 199 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 200 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 201 | - if (strlen($serveur)) { |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - return true; |
|
| 200 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 201 | + if (strlen($serveur)) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + return true; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -215,25 +215,25 @@ discard block |
||
| 215 | 215 | * message d'erreur si login non valide, chaine vide sinon |
| 216 | 216 | */ |
| 217 | 217 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 218 | - // login et mot de passe |
|
| 219 | - if (strlen($new_login)) { |
|
| 220 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 221 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 222 | - } else { |
|
| 223 | - $n = sql_countsel( |
|
| 224 | - 'spip_auteurs', |
|
| 225 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 226 | - '', |
|
| 227 | - '', |
|
| 228 | - $serveur |
|
| 229 | - ); |
|
| 230 | - if ($n) { |
|
| 231 | - return _T('info_login_existant'); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return ''; |
|
| 218 | + // login et mot de passe |
|
| 219 | + if (strlen($new_login)) { |
|
| 220 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 221 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 222 | + } else { |
|
| 223 | + $n = sql_countsel( |
|
| 224 | + 'spip_auteurs', |
|
| 225 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 226 | + '', |
|
| 227 | + '', |
|
| 228 | + $serveur |
|
| 229 | + ); |
|
| 230 | + if ($n) { |
|
| 231 | + return _T('info_login_existant'); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return ''; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -245,41 +245,41 @@ discard block |
||
| 245 | 245 | * @return bool |
| 246 | 246 | */ |
| 247 | 247 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 248 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 249 | - return false; |
|
| 250 | - } |
|
| 251 | - if ( |
|
| 252 | - !$id_auteur = intval($id_auteur) |
|
| 253 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 254 | - ) { |
|
| 255 | - return false; |
|
| 256 | - } |
|
| 257 | - if ($new_login == $auteur['login']) { |
|
| 258 | - return true; |
|
| 259 | - } // on a rien fait mais c'est bon ! |
|
| 260 | - |
|
| 261 | - include_spip('action/editer_auteur'); |
|
| 262 | - |
|
| 263 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 264 | - if (strlen($new_login)) { |
|
| 265 | - $anciens = sql_allfetsel( |
|
| 266 | - 'id_auteur', |
|
| 267 | - 'spip_auteurs', |
|
| 268 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 269 | - '', |
|
| 270 | - '', |
|
| 271 | - '', |
|
| 272 | - '', |
|
| 273 | - $serveur |
|
| 274 | - ); |
|
| 275 | - while ($row = array_pop($anciens)) { |
|
| 276 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 281 | - |
|
| 282 | - return true; |
|
| 248 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 249 | + return false; |
|
| 250 | + } |
|
| 251 | + if ( |
|
| 252 | + !$id_auteur = intval($id_auteur) |
|
| 253 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 254 | + ) { |
|
| 255 | + return false; |
|
| 256 | + } |
|
| 257 | + if ($new_login == $auteur['login']) { |
|
| 258 | + return true; |
|
| 259 | + } // on a rien fait mais c'est bon ! |
|
| 260 | + |
|
| 261 | + include_spip('action/editer_auteur'); |
|
| 262 | + |
|
| 263 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 264 | + if (strlen($new_login)) { |
|
| 265 | + $anciens = sql_allfetsel( |
|
| 266 | + 'id_auteur', |
|
| 267 | + 'spip_auteurs', |
|
| 268 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 269 | + '', |
|
| 270 | + '', |
|
| 271 | + '', |
|
| 272 | + '', |
|
| 273 | + $serveur |
|
| 274 | + ); |
|
| 275 | + while ($row = array_pop($anciens)) { |
|
| 276 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 281 | + |
|
| 282 | + return true; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -291,44 +291,44 @@ discard block |
||
| 291 | 291 | * @return string |
| 292 | 292 | */ |
| 293 | 293 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 294 | - if (!strlen($login)) { |
|
| 295 | - return null; |
|
| 296 | - } // pas la peine de requeter |
|
| 297 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 298 | - if ( |
|
| 299 | - $r = sql_getfetsel( |
|
| 300 | - 'login', |
|
| 301 | - 'spip_auteurs', |
|
| 302 | - "statut<>'5poubelle'" . |
|
| 303 | - ' AND (length(pass)>0)' . |
|
| 304 | - " AND (login=$l)", |
|
| 305 | - '', |
|
| 306 | - '', |
|
| 307 | - '', |
|
| 308 | - '', |
|
| 309 | - $serveur |
|
| 310 | - ) |
|
| 311 | - ) { |
|
| 312 | - return $r; |
|
| 313 | - } |
|
| 314 | - // Si pas d'auteur avec ce login |
|
| 315 | - // regarder s'il a saisi son nom ou son mail. |
|
| 316 | - // Ne pas fusionner avec la requete precedente |
|
| 317 | - // car un nom peut etre homonyme d'un autre login |
|
| 318 | - else { |
|
| 319 | - return sql_getfetsel( |
|
| 320 | - 'login', |
|
| 321 | - 'spip_auteurs', |
|
| 322 | - "statut<>'5poubelle'" . |
|
| 323 | - ' AND (length(pass)>0)' . |
|
| 324 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 325 | - '', |
|
| 326 | - '', |
|
| 327 | - '', |
|
| 328 | - '', |
|
| 329 | - $serveur |
|
| 330 | - ); |
|
| 331 | - } |
|
| 294 | + if (!strlen($login)) { |
|
| 295 | + return null; |
|
| 296 | + } // pas la peine de requeter |
|
| 297 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 298 | + if ( |
|
| 299 | + $r = sql_getfetsel( |
|
| 300 | + 'login', |
|
| 301 | + 'spip_auteurs', |
|
| 302 | + "statut<>'5poubelle'" . |
|
| 303 | + ' AND (length(pass)>0)' . |
|
| 304 | + " AND (login=$l)", |
|
| 305 | + '', |
|
| 306 | + '', |
|
| 307 | + '', |
|
| 308 | + '', |
|
| 309 | + $serveur |
|
| 310 | + ) |
|
| 311 | + ) { |
|
| 312 | + return $r; |
|
| 313 | + } |
|
| 314 | + // Si pas d'auteur avec ce login |
|
| 315 | + // regarder s'il a saisi son nom ou son mail. |
|
| 316 | + // Ne pas fusionner avec la requete precedente |
|
| 317 | + // car un nom peut etre homonyme d'un autre login |
|
| 318 | + else { |
|
| 319 | + return sql_getfetsel( |
|
| 320 | + 'login', |
|
| 321 | + 'spip_auteurs', |
|
| 322 | + "statut<>'5poubelle'" . |
|
| 323 | + ' AND (length(pass)>0)' . |
|
| 324 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 325 | + '', |
|
| 326 | + '', |
|
| 327 | + '', |
|
| 328 | + '', |
|
| 329 | + $serveur |
|
| 330 | + ); |
|
| 331 | + } |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | |
@@ -346,11 +346,11 @@ discard block |
||
| 346 | 346 | */ |
| 347 | 347 | function auth_spip_informer_login($infos, $row, $serveur = '') { |
| 348 | 348 | |
| 349 | - // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 350 | - $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 351 | - $infos['alea_futur'] = $row['alea_futur']; |
|
| 349 | + // pour la methode SPIP on a besoin des alea en plus pour encoder le pass avec |
|
| 350 | + $infos['alea_actuel'] = $row['alea_actuel']; |
|
| 351 | + $infos['alea_futur'] = $row['alea_futur']; |
|
| 352 | 352 | |
| 353 | - return $infos; |
|
| 353 | + return $infos; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -361,11 +361,11 @@ discard block |
||
| 361 | 361 | * toujours true pour un auteur cree dans SPIP |
| 362 | 362 | */ |
| 363 | 363 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 364 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 365 | - if (strlen($serveur)) { |
|
| 366 | - return false; |
|
| 367 | - } |
|
| 368 | - return true; |
|
| 364 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 365 | + if (strlen($serveur)) { |
|
| 366 | + return false; |
|
| 367 | + } |
|
| 368 | + return true; |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -386,12 +386,12 @@ discard block |
||
| 386 | 386 | * message d'erreur si login non valide, chaine vide sinon |
| 387 | 387 | */ |
| 388 | 388 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 389 | - // login et mot de passe |
|
| 390 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 391 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 392 | - } |
|
| 389 | + // login et mot de passe |
|
| 390 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 391 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 392 | + } |
|
| 393 | 393 | |
| 394 | - return ''; |
|
| 394 | + return ''; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -405,34 +405,34 @@ discard block |
||
| 405 | 405 | * @return bool |
| 406 | 406 | */ |
| 407 | 407 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 408 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - if ( |
|
| 413 | - !$id_auteur = intval($id_auteur) |
|
| 414 | - or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 415 | - ) { |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - $c = []; |
|
| 420 | - include_spip('inc/acces'); |
|
| 421 | - include_spip('auth/sha256.inc'); |
|
| 422 | - $htpass = generer_htpass($new_pass); |
|
| 423 | - $alea_actuel = creer_uniqid(); |
|
| 424 | - $alea_futur = creer_uniqid(); |
|
| 425 | - $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 426 | - $c['pass'] = $pass; |
|
| 427 | - $c['htpass'] = $htpass; |
|
| 428 | - $c['alea_actuel'] = $alea_actuel; |
|
| 429 | - $c['alea_futur'] = $alea_futur; |
|
| 430 | - $c['low_sec'] = ''; |
|
| 431 | - |
|
| 432 | - include_spip('action/editer_auteur'); |
|
| 433 | - auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 434 | - |
|
| 435 | - return true; // on a bien modifie le pass |
|
| 408 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + if ( |
|
| 413 | + !$id_auteur = intval($id_auteur) |
|
| 414 | + or !sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 415 | + ) { |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + $c = []; |
|
| 420 | + include_spip('inc/acces'); |
|
| 421 | + include_spip('auth/sha256.inc'); |
|
| 422 | + $htpass = generer_htpass($new_pass); |
|
| 423 | + $alea_actuel = creer_uniqid(); |
|
| 424 | + $alea_futur = creer_uniqid(); |
|
| 425 | + $pass = spip_sha256($alea_actuel . $new_pass); |
|
| 426 | + $c['pass'] = $pass; |
|
| 427 | + $c['htpass'] = $htpass; |
|
| 428 | + $c['alea_actuel'] = $alea_actuel; |
|
| 429 | + $c['alea_futur'] = $alea_futur; |
|
| 430 | + $c['low_sec'] = ''; |
|
| 431 | + |
|
| 432 | + include_spip('action/editer_auteur'); |
|
| 433 | + auteur_modifier($id_auteur, $c, true); // manque la gestion de $serveur |
|
| 434 | + |
|
| 435 | + return true; // on a bien modifie le pass |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -446,58 +446,58 @@ discard block |
||
| 446 | 446 | * @return void |
| 447 | 447 | */ |
| 448 | 448 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 449 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 450 | - if (strlen($serveur)) { |
|
| 451 | - return; |
|
| 452 | - } |
|
| 453 | - // si un login, pass ou statut a ete modifie |
|
| 454 | - // regenerer les fichier htpass |
|
| 455 | - if ( |
|
| 456 | - isset($champs['login']) |
|
| 457 | - or isset($champs['pass']) |
|
| 458 | - or isset($champs['statut']) |
|
| 459 | - or (isset($options['all']) and $options['all']) |
|
| 460 | - ) { |
|
| 461 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 462 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 463 | - |
|
| 464 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 465 | - // par exemple acces_restreint ; |
|
| 466 | - // si .htaccess existe, outrepasser spip_meta |
|
| 467 | - if ( |
|
| 468 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 469 | - and !@file_exists($htaccess) |
|
| 470 | - ) { |
|
| 471 | - spip_unlink($htpasswd); |
|
| 472 | - spip_unlink($htpasswd . '-admin'); |
|
| 473 | - |
|
| 474 | - return; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 478 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 479 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 480 | - |
|
| 481 | - $p1 = ''; // login:htpass pour tous |
|
| 482 | - $p2 = ''; // login:htpass pour les admins |
|
| 483 | - $s = sql_select( |
|
| 484 | - 'login, htpass, statut', |
|
| 485 | - 'spip_auteurs', |
|
| 486 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 487 | - ); |
|
| 488 | - while ($t = sql_fetch($s)) { |
|
| 489 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 490 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 491 | - if ($t['statut'] == '0minirezo') { |
|
| 492 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - sql_free($s); |
|
| 497 | - if ($p1) { |
|
| 498 | - ecrire_fichier($htpasswd, $p1); |
|
| 499 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 500 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 501 | - } |
|
| 502 | - } |
|
| 449 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 450 | + if (strlen($serveur)) { |
|
| 451 | + return; |
|
| 452 | + } |
|
| 453 | + // si un login, pass ou statut a ete modifie |
|
| 454 | + // regenerer les fichier htpass |
|
| 455 | + if ( |
|
| 456 | + isset($champs['login']) |
|
| 457 | + or isset($champs['pass']) |
|
| 458 | + or isset($champs['statut']) |
|
| 459 | + or (isset($options['all']) and $options['all']) |
|
| 460 | + ) { |
|
| 461 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 462 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 463 | + |
|
| 464 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 465 | + // par exemple acces_restreint ; |
|
| 466 | + // si .htaccess existe, outrepasser spip_meta |
|
| 467 | + if ( |
|
| 468 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 469 | + and !@file_exists($htaccess) |
|
| 470 | + ) { |
|
| 471 | + spip_unlink($htpasswd); |
|
| 472 | + spip_unlink($htpasswd . '-admin'); |
|
| 473 | + |
|
| 474 | + return; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 478 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 479 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 480 | + |
|
| 481 | + $p1 = ''; // login:htpass pour tous |
|
| 482 | + $p2 = ''; // login:htpass pour les admins |
|
| 483 | + $s = sql_select( |
|
| 484 | + 'login, htpass, statut', |
|
| 485 | + 'spip_auteurs', |
|
| 486 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 487 | + ); |
|
| 488 | + while ($t = sql_fetch($s)) { |
|
| 489 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 490 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 491 | + if ($t['statut'] == '0minirezo') { |
|
| 492 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + sql_free($s); |
|
| 497 | + if ($p1) { |
|
| 498 | + ecrire_fichier($htpasswd, $p1); |
|
| 499 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 500 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | 503 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Minipres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/headers'); |
@@ -46,61 +46,61 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 48 | 48 | |
| 49 | - utiliser_langue_visiteur(); |
|
| 50 | - |
|
| 51 | - http_no_cache(); |
|
| 52 | - |
|
| 53 | - if ($titre == 'AUTO') { |
|
| 54 | - $titre = _T('info_installation_systeme_publication'); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | - # lors de l'installation |
|
| 59 | - if (!headers_sent()) { |
|
| 60 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $css = ''; |
|
| 64 | - $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | - if ($all_inline) { |
|
| 66 | - // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | - foreach ($files as $name) { |
|
| 68 | - $file = direction_css(find_in_theme($name)); |
|
| 69 | - if (function_exists('minifier')) { |
|
| 70 | - $file = minifier($file); |
|
| 71 | - } else { |
|
| 72 | - $file = url_absolue_css($file); // precaution |
|
| 73 | - } |
|
| 74 | - lire_fichier($file, $c); |
|
| 75 | - $css .= $c; |
|
| 76 | - } |
|
| 77 | - $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | - } else { |
|
| 79 | - foreach ($files as $name) { |
|
| 80 | - $file = direction_css(find_in_theme($name)); |
|
| 81 | - $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | - define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return _DOCTYPE_ECRIRE . |
|
| 91 | - html_lang_attributes() . |
|
| 92 | - "<head>\n" . |
|
| 93 | - '<title>' . |
|
| 94 | - textebrut($titre) . |
|
| 95 | - "</title>\n" . |
|
| 96 | - "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | - $css . |
|
| 98 | - '</head> |
|
| 49 | + utiliser_langue_visiteur(); |
|
| 50 | + |
|
| 51 | + http_no_cache(); |
|
| 52 | + |
|
| 53 | + if ($titre == 'AUTO') { |
|
| 54 | + $titre = _T('info_installation_systeme_publication'); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | + # lors de l'installation |
|
| 59 | + if (!headers_sent()) { |
|
| 60 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $css = ''; |
|
| 64 | + $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | + if ($all_inline) { |
|
| 66 | + // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | + foreach ($files as $name) { |
|
| 68 | + $file = direction_css(find_in_theme($name)); |
|
| 69 | + if (function_exists('minifier')) { |
|
| 70 | + $file = minifier($file); |
|
| 71 | + } else { |
|
| 72 | + $file = url_absolue_css($file); // precaution |
|
| 73 | + } |
|
| 74 | + lire_fichier($file, $c); |
|
| 75 | + $css .= $c; |
|
| 76 | + } |
|
| 77 | + $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | + } else { |
|
| 79 | + foreach ($files as $name) { |
|
| 80 | + $file = direction_css(find_in_theme($name)); |
|
| 81 | + $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | + define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return _DOCTYPE_ECRIRE . |
|
| 91 | + html_lang_attributes() . |
|
| 92 | + "<head>\n" . |
|
| 93 | + '<title>' . |
|
| 94 | + textebrut($titre) . |
|
| 95 | + "</title>\n" . |
|
| 96 | + "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | + $css . |
|
| 98 | + '</head> |
|
| 99 | 99 | <body' . $onLoad . " class='minipres'> |
| 100 | 100 | <div id='minipres'> |
| 101 | 101 | <h1>" . |
| 102 | - $titre . |
|
| 103 | - "</h1> |
|
| 102 | + $titre . |
|
| 103 | + "</h1> |
|
| 104 | 104 | <div>\n"; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string Code HTML |
| 111 | 111 | */ |
| 112 | 112 | function install_fin_html() { |
| 113 | - return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 113 | + return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -148,88 +148,88 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function minipres($titre = '', $corps = '', $options = []) { |
| 150 | 150 | |
| 151 | - // compat signature old |
|
| 152 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | - $args = func_get_args(); |
|
| 154 | - if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | - $options = ['onload' => $args[2]]; |
|
| 156 | - } |
|
| 157 | - if (isset($args[3])) { |
|
| 158 | - $options['all_inline'] = $args[3]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $options = array_merge([ |
|
| 162 | - 'onload' => '', |
|
| 163 | - 'all_inline' => false, |
|
| 164 | - ], $options); |
|
| 165 | - |
|
| 166 | - if (!defined('_AJAX')) { |
|
| 167 | - define('_AJAX', false); |
|
| 168 | - } // par securite |
|
| 169 | - if (!$titre) { |
|
| 170 | - if (!isset($options['status'])) { |
|
| 171 | - $options['status'] = 403; |
|
| 172 | - } |
|
| 173 | - if ( |
|
| 174 | - !$titre = _request('action') |
|
| 175 | - and !$titre = _request('exec') |
|
| 176 | - and !$titre = _request('page') |
|
| 177 | - ) { |
|
| 178 | - $titre = '?'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $titre = spip_htmlspecialchars($titre); |
|
| 182 | - |
|
| 183 | - $titre = ($titre == 'install') |
|
| 184 | - ? _T('avis_espace_interdit') |
|
| 185 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | - |
|
| 187 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | - |
|
| 190 | - if ($statut != '0minirezo') { |
|
| 191 | - $titre = _T('info_acces_interdit'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($statut and test_espace_prive()) { |
|
| 195 | - $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | - } |
|
| 197 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | - $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | - } |
|
| 200 | - else { |
|
| 201 | - $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | - } |
|
| 203 | - $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (!_AJAX) { |
|
| 208 | - if (isset($options['status'])) { |
|
| 209 | - http_response_code($options['status']); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | - . $corps |
|
| 214 | - . install_fin_html(); |
|
| 215 | - |
|
| 216 | - if ( |
|
| 217 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 218 | - and empty($options['all_inline']) |
|
| 219 | - ) { |
|
| 220 | - define('_SET_HTML_BASE', true); |
|
| 221 | - include_spip('public/assembler'); |
|
| 222 | - $GLOBALS['html'] = true; |
|
| 223 | - page_base_href($html); |
|
| 224 | - } |
|
| 225 | - return $html; |
|
| 226 | - } else { |
|
| 227 | - include_spip('inc/headers'); |
|
| 228 | - include_spip('inc/actions'); |
|
| 229 | - $url = self('&', true); |
|
| 230 | - foreach ($_POST as $v => $c) { |
|
| 231 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 232 | - } |
|
| 233 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 234 | - } |
|
| 151 | + // compat signature old |
|
| 152 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | + $args = func_get_args(); |
|
| 154 | + if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | + $options = ['onload' => $args[2]]; |
|
| 156 | + } |
|
| 157 | + if (isset($args[3])) { |
|
| 158 | + $options['all_inline'] = $args[3]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $options = array_merge([ |
|
| 162 | + 'onload' => '', |
|
| 163 | + 'all_inline' => false, |
|
| 164 | + ], $options); |
|
| 165 | + |
|
| 166 | + if (!defined('_AJAX')) { |
|
| 167 | + define('_AJAX', false); |
|
| 168 | + } // par securite |
|
| 169 | + if (!$titre) { |
|
| 170 | + if (!isset($options['status'])) { |
|
| 171 | + $options['status'] = 403; |
|
| 172 | + } |
|
| 173 | + if ( |
|
| 174 | + !$titre = _request('action') |
|
| 175 | + and !$titre = _request('exec') |
|
| 176 | + and !$titre = _request('page') |
|
| 177 | + ) { |
|
| 178 | + $titre = '?'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $titre = spip_htmlspecialchars($titre); |
|
| 182 | + |
|
| 183 | + $titre = ($titre == 'install') |
|
| 184 | + ? _T('avis_espace_interdit') |
|
| 185 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | + |
|
| 187 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | + |
|
| 190 | + if ($statut != '0minirezo') { |
|
| 191 | + $titre = _T('info_acces_interdit'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($statut and test_espace_prive()) { |
|
| 195 | + $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | + } |
|
| 197 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | + $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | + } |
|
| 200 | + else { |
|
| 201 | + $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | + } |
|
| 203 | + $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | + spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (!_AJAX) { |
|
| 208 | + if (isset($options['status'])) { |
|
| 209 | + http_response_code($options['status']); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | + . $corps |
|
| 214 | + . install_fin_html(); |
|
| 215 | + |
|
| 216 | + if ( |
|
| 217 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 218 | + and empty($options['all_inline']) |
|
| 219 | + ) { |
|
| 220 | + define('_SET_HTML_BASE', true); |
|
| 221 | + include_spip('public/assembler'); |
|
| 222 | + $GLOBALS['html'] = true; |
|
| 223 | + page_base_href($html); |
|
| 224 | + } |
|
| 225 | + return $html; |
|
| 226 | + } else { |
|
| 227 | + include_spip('inc/headers'); |
|
| 228 | + include_spip('inc/actions'); |
|
| 229 | + $url = self('&', true); |
|
| 230 | + foreach ($_POST as $v => $c) { |
|
| 231 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 232 | + } |
|
| 233 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres'); // par precaution |
| 24 | 24 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | * Le code de la couleur en hexadécimal. |
| 39 | 39 | */ |
| 40 | 40 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 41 | - $red = dechex($red); |
|
| 42 | - $green = dechex($green); |
|
| 43 | - $blue = dechex($blue); |
|
| 44 | - |
|
| 45 | - if (strlen($red) == 1) { |
|
| 46 | - $red = '0' . $red; |
|
| 47 | - } |
|
| 48 | - if (strlen($green) == 1) { |
|
| 49 | - $green = '0' . $green; |
|
| 50 | - } |
|
| 51 | - if (strlen($blue) == 1) { |
|
| 52 | - $blue = '0' . $blue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return "$red$green$blue"; |
|
| 41 | + $red = dechex($red); |
|
| 42 | + $green = dechex($green); |
|
| 43 | + $blue = dechex($blue); |
|
| 44 | + |
|
| 45 | + if (strlen($red) == 1) { |
|
| 46 | + $red = '0' . $red; |
|
| 47 | + } |
|
| 48 | + if (strlen($green) == 1) { |
|
| 49 | + $green = '0' . $green; |
|
| 50 | + } |
|
| 51 | + if (strlen($blue) == 1) { |
|
| 52 | + $blue = '0' . $blue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return "$red$green$blue"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 65 | 65 | */ |
| 66 | 66 | function _couleur_hex_to_dec($couleur) { |
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,59 +120,59 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $H = null; |
|
| 124 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | - $var_G = ($G / 255); |
|
| 126 | - $var_B = ($B / 255); |
|
| 127 | - |
|
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | - |
|
| 132 | - $L = ($var_Max + $var_Min) / 2; |
|
| 133 | - |
|
| 134 | - if ($del_Max == 0) { |
|
| 135 | - //This is a gray, no chroma... |
|
| 136 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | - $S = 0; |
|
| 138 | - } else { |
|
| 139 | - // Chromatic data... |
|
| 140 | - if ($L < 0.5) { |
|
| 141 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | - } else { |
|
| 143 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - |
|
| 150 | - if ($var_R == $var_Max) { |
|
| 151 | - $H = $del_B - $del_G; |
|
| 152 | - } else { |
|
| 153 | - if ($var_G == $var_Max) { |
|
| 154 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | - } else { |
|
| 156 | - if ($var_B == $var_Max) { |
|
| 157 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if ($H < 0) { |
|
| 163 | - $H += 1; |
|
| 164 | - } |
|
| 165 | - if ($H > 1) { |
|
| 166 | - $H -= 1; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ret = []; |
|
| 171 | - $ret['h'] = $H; |
|
| 172 | - $ret['s'] = $S; |
|
| 173 | - $ret['l'] = $L; |
|
| 174 | - |
|
| 175 | - return $ret; |
|
| 123 | + $H = null; |
|
| 124 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | + $var_G = ($G / 255); |
|
| 126 | + $var_B = ($B / 255); |
|
| 127 | + |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | + |
|
| 132 | + $L = ($var_Max + $var_Min) / 2; |
|
| 133 | + |
|
| 134 | + if ($del_Max == 0) { |
|
| 135 | + //This is a gray, no chroma... |
|
| 136 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | + $S = 0; |
|
| 138 | + } else { |
|
| 139 | + // Chromatic data... |
|
| 140 | + if ($L < 0.5) { |
|
| 141 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | + } else { |
|
| 143 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + |
|
| 150 | + if ($var_R == $var_Max) { |
|
| 151 | + $H = $del_B - $del_G; |
|
| 152 | + } else { |
|
| 153 | + if ($var_G == $var_Max) { |
|
| 154 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | + } else { |
|
| 156 | + if ($var_B == $var_Max) { |
|
| 157 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if ($H < 0) { |
|
| 163 | + $H += 1; |
|
| 164 | + } |
|
| 165 | + if ($H > 1) { |
|
| 166 | + $H -= 1; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ret = []; |
|
| 171 | + $ret['h'] = $H; |
|
| 172 | + $ret['s'] = $S; |
|
| 173 | + $ret['l'] = $L; |
|
| 174 | + |
|
| 175 | + return $ret; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -188,52 +188,52 @@ discard block |
||
| 188 | 188 | * @return array |
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | - // helper |
|
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | - if ($vH < 0) { |
|
| 194 | - $vH += 1; |
|
| 195 | - } |
|
| 196 | - if ($vH > 1) { |
|
| 197 | - $vH -= 1; |
|
| 198 | - } |
|
| 199 | - if ((6 * $vH) < 1) { |
|
| 200 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | - } |
|
| 202 | - if ((2 * $vH) < 1) { |
|
| 203 | - return ($v2); |
|
| 204 | - } |
|
| 205 | - if ((3 * $vH) < 2) { |
|
| 206 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return ($v1); |
|
| 210 | - }; |
|
| 211 | - |
|
| 212 | - if ($S == 0) { |
|
| 213 | - // HSV values = 0 -> 1 |
|
| 214 | - $R = $L * 255; |
|
| 215 | - $G = $L * 255; |
|
| 216 | - $B = $L * 255; |
|
| 217 | - } else { |
|
| 218 | - if ($L < 0.5) { |
|
| 219 | - $var_2 = $L * (1 + $S); |
|
| 220 | - } else { |
|
| 221 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $var_1 = 2 * $L - $var_2; |
|
| 225 | - |
|
| 226 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $ret = []; |
|
| 232 | - $ret['r'] = floor($R); |
|
| 233 | - $ret['g'] = floor($G); |
|
| 234 | - $ret['b'] = floor($B); |
|
| 235 | - |
|
| 236 | - return $ret; |
|
| 191 | + // helper |
|
| 192 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | + if ($vH < 0) { |
|
| 194 | + $vH += 1; |
|
| 195 | + } |
|
| 196 | + if ($vH > 1) { |
|
| 197 | + $vH -= 1; |
|
| 198 | + } |
|
| 199 | + if ((6 * $vH) < 1) { |
|
| 200 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | + } |
|
| 202 | + if ((2 * $vH) < 1) { |
|
| 203 | + return ($v2); |
|
| 204 | + } |
|
| 205 | + if ((3 * $vH) < 2) { |
|
| 206 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return ($v1); |
|
| 210 | + }; |
|
| 211 | + |
|
| 212 | + if ($S == 0) { |
|
| 213 | + // HSV values = 0 -> 1 |
|
| 214 | + $R = $L * 255; |
|
| 215 | + $G = $L * 255; |
|
| 216 | + $B = $L * 255; |
|
| 217 | + } else { |
|
| 218 | + if ($L < 0.5) { |
|
| 219 | + $var_2 = $L * (1 + $S); |
|
| 220 | + } else { |
|
| 221 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $var_1 = 2 * $L - $var_2; |
|
| 225 | + |
|
| 226 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $ret = []; |
|
| 232 | + $ret['r'] = floor($R); |
|
| 233 | + $ret['g'] = floor($G); |
|
| 234 | + $ret['b'] = floor($B); |
|
| 235 | + |
|
| 236 | + return $ret; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 251 | 251 | */ |
| 252 | 252 | function statut_effacer_images_temporaires($stat) { |
| 253 | - static $statut = false; // par defaut on grave toute les images |
|
| 254 | - if ($stat === 'get') { |
|
| 255 | - return $statut; |
|
| 256 | - } |
|
| 257 | - $statut = $stat ? true : false; |
|
| 253 | + static $statut = false; // par defaut on grave toute les images |
|
| 254 | + if ($stat === 'get') { |
|
| 255 | + return $statut; |
|
| 256 | + } |
|
| 257 | + $statut = $stat ? true : false; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -307,243 +307,243 @@ discard block |
||
| 307 | 307 | * - array : tableau décrivant de l'image |
| 308 | 308 | */ |
| 309 | 309 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 310 | - $ret = []; |
|
| 311 | - $f = null; |
|
| 312 | - static $images_recalcul = []; |
|
| 313 | - if (strlen($img) == 0) { |
|
| 314 | - return false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 318 | - if (strlen($source) < 1) { |
|
| 319 | - $source = $img; |
|
| 320 | - $img = "<img src='$source' />"; |
|
| 321 | - } elseif ( |
|
| 322 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 323 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 325 | - ) { |
|
| 326 | - # gerer img src="data:....base64" |
|
| 327 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | - if (!file_exists($local)) { |
|
| 329 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 330 | - } |
|
| 331 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 332 | - $sanitizer($local); |
|
| 333 | - } |
|
| 334 | - $source = $local; |
|
| 335 | - $img = inserer_attribut($img, 'src', $source); |
|
| 336 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 337 | - $img = inserer_attribut($img, 'width', ''); |
|
| 338 | - $img = inserer_attribut($img, 'height', ''); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // les protocoles web prennent au moins 3 lettres |
|
| 342 | - if (tester_url_absolue($source)) { |
|
| 343 | - include_spip('inc/distant'); |
|
| 344 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | - if (!$fichier) { |
|
| 346 | - return ''; |
|
| 347 | - } |
|
| 348 | - if ( |
|
| 349 | - $extension = _image_trouver_extension($fichier) |
|
| 350 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 351 | - ) { |
|
| 352 | - $sanitizer($fichier); |
|
| 353 | - } |
|
| 354 | - } else { |
|
| 355 | - // enlever le timestamp eventuel |
|
| 356 | - if (strpos($source, '?') !== false) { |
|
| 357 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 358 | - } |
|
| 359 | - if ( |
|
| 360 | - strpos($source, '?') !== false |
|
| 361 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 362 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 363 | - ) { |
|
| 364 | - $source = $f; |
|
| 365 | - } |
|
| 366 | - $fichier = $source; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $terminaison_dest = ''; |
|
| 370 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 371 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ( |
|
| 375 | - $forcer_format !== false |
|
| 376 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 377 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 378 | - ) { |
|
| 379 | - $terminaison_dest = $forcer_format; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - if (!$terminaison_dest) { |
|
| 383 | - return false; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 387 | - $fichier_dest = $nom_fichier; |
|
| 388 | - if ( |
|
| 389 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 390 | - or @file_exists($f = $fichier) |
|
| 391 | - ) { |
|
| 392 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 393 | - // au lieu de faire un acces disque sur le fichier |
|
| 394 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 395 | - $date_src = @filemtime($f); |
|
| 396 | - } elseif ( |
|
| 397 | - @file_exists($f = "$fichier.src") |
|
| 398 | - and lire_fichier($f, $valeurs) |
|
| 399 | - and $valeurs = unserialize($valeurs) |
|
| 400 | - and isset($valeurs['hauteur_dest']) |
|
| 401 | - and isset($valeurs['largeur_dest']) |
|
| 402 | - ) { |
|
| 403 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 404 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 405 | - $date_src = $valeurs['date']; |
|
| 406 | - } // pas de fichier source par la |
|
| 407 | - else { |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // pas de taille mesurable |
|
| 412 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 413 | - return false; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - // les images calculees dependent du chemin du fichier source |
|
| 417 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 418 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 419 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 420 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 421 | - // alors que ca concerne peu de site au final |
|
| 422 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 423 | - $identifiant = $fichier; |
|
| 424 | - |
|
| 425 | - // cas general : |
|
| 426 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 427 | - // cas particulier de reduire : |
|
| 428 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 429 | - $cache = 'cache-gd2'; |
|
| 430 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 431 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 432 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 433 | - $ret['largeur_dest'] = $destWidth; |
|
| 434 | - $ret['hauteur_dest'] = $destHeight; |
|
| 435 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 436 | - $cache = 'cache-vignettes'; |
|
| 437 | - $fichier_dest = basename($fichier_dest); |
|
| 438 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 439 | - // on garde la terminaison initiale car image simplement copiee |
|
| 440 | - // et on postfixe son nom avec un md5 du path |
|
| 441 | - $terminaison_dest = $terminaison; |
|
| 442 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 443 | - } else { |
|
| 444 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 445 | - } |
|
| 446 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 447 | - $cache = sous_repertoire($cache, $effet); |
|
| 448 | - } else { |
|
| 449 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 450 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 451 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 452 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 456 | - |
|
| 457 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 458 | - |
|
| 459 | - $creer = true; |
|
| 460 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 461 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 462 | - $images_recalcul[$fichier_dest] = true; |
|
| 463 | - } else { |
|
| 464 | - if (@file_exists($f = $fichier_dest)) { |
|
| 465 | - if (filemtime($f) >= $date_src) { |
|
| 466 | - $creer = false; |
|
| 467 | - } |
|
| 468 | - } else { |
|
| 469 | - if ( |
|
| 470 | - @file_exists($f = "$fichier_dest.src") |
|
| 471 | - and lire_fichier($f, $valeurs) |
|
| 472 | - and $valeurs = unserialize($valeurs) |
|
| 473 | - and $valeurs['date'] >= $date_src |
|
| 474 | - ) { |
|
| 475 | - $creer = false; |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - if ($creer) { |
|
| 480 | - if (!@file_exists($fichier)) { |
|
| 481 | - if (!@file_exists("$fichier.src")) { |
|
| 482 | - spip_log("Image absente : $fichier"); |
|
| 483 | - |
|
| 484 | - return false; |
|
| 485 | - } |
|
| 486 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 487 | - reconstruire_image_intermediaire($fichier); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - if ($creer) { |
|
| 492 | - spip_log( |
|
| 493 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 494 | - 'images' . _LOG_DEBUG |
|
| 495 | - ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 499 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | - $ret['fichier'] = $fichier; |
|
| 501 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 503 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 504 | - $ret['format_dest'] = $terminaison_dest; |
|
| 505 | - $ret['date_src'] = $date_src; |
|
| 506 | - $ret['creer'] = $creer; |
|
| 507 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 508 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 509 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 510 | - $ret['tag'] = $img; |
|
| 511 | - if ($fonction_creation) { |
|
| 512 | - $ret['reconstruction'] = $fonction_creation; |
|
| 513 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 514 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 515 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 516 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 520 | - 'args' => [ |
|
| 521 | - 'img' => $img, |
|
| 522 | - 'effet' => $effet, |
|
| 523 | - 'forcer_format' => $forcer_format, |
|
| 524 | - 'fonction_creation' => $fonction_creation, |
|
| 525 | - 'find_in_path' => $find_in_path, |
|
| 526 | - ], |
|
| 527 | - 'data' => $ret |
|
| 528 | - ]); |
|
| 529 | - |
|
| 530 | - // une globale pour le debug en cas de crash memoire |
|
| 531 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 532 | - |
|
| 533 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 534 | - if ($term_fonction === 'svg') { |
|
| 535 | - if ($creer and !$support_svg) { |
|
| 536 | - process_image_svg_identite($ret); |
|
| 537 | - $ret['creer'] = false; |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - else { |
|
| 541 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return $ret; |
|
| 310 | + $ret = []; |
|
| 311 | + $f = null; |
|
| 312 | + static $images_recalcul = []; |
|
| 313 | + if (strlen($img) == 0) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 318 | + if (strlen($source) < 1) { |
|
| 319 | + $source = $img; |
|
| 320 | + $img = "<img src='$source' />"; |
|
| 321 | + } elseif ( |
|
| 322 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 323 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 325 | + ) { |
|
| 326 | + # gerer img src="data:....base64" |
|
| 327 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | + if (!file_exists($local)) { |
|
| 329 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 330 | + } |
|
| 331 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 332 | + $sanitizer($local); |
|
| 333 | + } |
|
| 334 | + $source = $local; |
|
| 335 | + $img = inserer_attribut($img, 'src', $source); |
|
| 336 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 337 | + $img = inserer_attribut($img, 'width', ''); |
|
| 338 | + $img = inserer_attribut($img, 'height', ''); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // les protocoles web prennent au moins 3 lettres |
|
| 342 | + if (tester_url_absolue($source)) { |
|
| 343 | + include_spip('inc/distant'); |
|
| 344 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | + if (!$fichier) { |
|
| 346 | + return ''; |
|
| 347 | + } |
|
| 348 | + if ( |
|
| 349 | + $extension = _image_trouver_extension($fichier) |
|
| 350 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 351 | + ) { |
|
| 352 | + $sanitizer($fichier); |
|
| 353 | + } |
|
| 354 | + } else { |
|
| 355 | + // enlever le timestamp eventuel |
|
| 356 | + if (strpos($source, '?') !== false) { |
|
| 357 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 358 | + } |
|
| 359 | + if ( |
|
| 360 | + strpos($source, '?') !== false |
|
| 361 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 362 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 363 | + ) { |
|
| 364 | + $source = $f; |
|
| 365 | + } |
|
| 366 | + $fichier = $source; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $terminaison_dest = ''; |
|
| 370 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 371 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ( |
|
| 375 | + $forcer_format !== false |
|
| 376 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 377 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 378 | + ) { |
|
| 379 | + $terminaison_dest = $forcer_format; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + if (!$terminaison_dest) { |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 387 | + $fichier_dest = $nom_fichier; |
|
| 388 | + if ( |
|
| 389 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 390 | + or @file_exists($f = $fichier) |
|
| 391 | + ) { |
|
| 392 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 393 | + // au lieu de faire un acces disque sur le fichier |
|
| 394 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 395 | + $date_src = @filemtime($f); |
|
| 396 | + } elseif ( |
|
| 397 | + @file_exists($f = "$fichier.src") |
|
| 398 | + and lire_fichier($f, $valeurs) |
|
| 399 | + and $valeurs = unserialize($valeurs) |
|
| 400 | + and isset($valeurs['hauteur_dest']) |
|
| 401 | + and isset($valeurs['largeur_dest']) |
|
| 402 | + ) { |
|
| 403 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 404 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 405 | + $date_src = $valeurs['date']; |
|
| 406 | + } // pas de fichier source par la |
|
| 407 | + else { |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // pas de taille mesurable |
|
| 412 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + // les images calculees dependent du chemin du fichier source |
|
| 417 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 418 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 419 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 420 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 421 | + // alors que ca concerne peu de site au final |
|
| 422 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 423 | + $identifiant = $fichier; |
|
| 424 | + |
|
| 425 | + // cas general : |
|
| 426 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 427 | + // cas particulier de reduire : |
|
| 428 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 429 | + $cache = 'cache-gd2'; |
|
| 430 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 431 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 432 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 433 | + $ret['largeur_dest'] = $destWidth; |
|
| 434 | + $ret['hauteur_dest'] = $destHeight; |
|
| 435 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 436 | + $cache = 'cache-vignettes'; |
|
| 437 | + $fichier_dest = basename($fichier_dest); |
|
| 438 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 439 | + // on garde la terminaison initiale car image simplement copiee |
|
| 440 | + // et on postfixe son nom avec un md5 du path |
|
| 441 | + $terminaison_dest = $terminaison; |
|
| 442 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 443 | + } else { |
|
| 444 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 445 | + } |
|
| 446 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 447 | + $cache = sous_repertoire($cache, $effet); |
|
| 448 | + } else { |
|
| 449 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 450 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 451 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 452 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 456 | + |
|
| 457 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 458 | + |
|
| 459 | + $creer = true; |
|
| 460 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 461 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 462 | + $images_recalcul[$fichier_dest] = true; |
|
| 463 | + } else { |
|
| 464 | + if (@file_exists($f = $fichier_dest)) { |
|
| 465 | + if (filemtime($f) >= $date_src) { |
|
| 466 | + $creer = false; |
|
| 467 | + } |
|
| 468 | + } else { |
|
| 469 | + if ( |
|
| 470 | + @file_exists($f = "$fichier_dest.src") |
|
| 471 | + and lire_fichier($f, $valeurs) |
|
| 472 | + and $valeurs = unserialize($valeurs) |
|
| 473 | + and $valeurs['date'] >= $date_src |
|
| 474 | + ) { |
|
| 475 | + $creer = false; |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + if ($creer) { |
|
| 480 | + if (!@file_exists($fichier)) { |
|
| 481 | + if (!@file_exists("$fichier.src")) { |
|
| 482 | + spip_log("Image absente : $fichier"); |
|
| 483 | + |
|
| 484 | + return false; |
|
| 485 | + } |
|
| 486 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 487 | + reconstruire_image_intermediaire($fichier); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($creer) { |
|
| 492 | + spip_log( |
|
| 493 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 494 | + 'images' . _LOG_DEBUG |
|
| 495 | + ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 499 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | + $ret['fichier'] = $fichier; |
|
| 501 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 503 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 504 | + $ret['format_dest'] = $terminaison_dest; |
|
| 505 | + $ret['date_src'] = $date_src; |
|
| 506 | + $ret['creer'] = $creer; |
|
| 507 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 508 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 509 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 510 | + $ret['tag'] = $img; |
|
| 511 | + if ($fonction_creation) { |
|
| 512 | + $ret['reconstruction'] = $fonction_creation; |
|
| 513 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 514 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 515 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 516 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 520 | + 'args' => [ |
|
| 521 | + 'img' => $img, |
|
| 522 | + 'effet' => $effet, |
|
| 523 | + 'forcer_format' => $forcer_format, |
|
| 524 | + 'fonction_creation' => $fonction_creation, |
|
| 525 | + 'find_in_path' => $find_in_path, |
|
| 526 | + ], |
|
| 527 | + 'data' => $ret |
|
| 528 | + ]); |
|
| 529 | + |
|
| 530 | + // une globale pour le debug en cas de crash memoire |
|
| 531 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 532 | + |
|
| 533 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 534 | + if ($term_fonction === 'svg') { |
|
| 535 | + if ($creer and !$support_svg) { |
|
| 536 | + process_image_svg_identite($ret); |
|
| 537 | + $ret['creer'] = false; |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + else { |
|
| 541 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 542 | + return false; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return $ret; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | |
@@ -552,53 +552,53 @@ discard block |
||
| 552 | 552 | * @return array |
| 553 | 553 | */ |
| 554 | 554 | function _image_extensions_acceptees_en_entree() { |
| 555 | - static $extensions = null; |
|
| 556 | - if (empty($extensions)) { |
|
| 557 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 558 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 559 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 560 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 561 | - $extensions = array_map('trim', $extensions); |
|
| 562 | - $extensions = array_filter($extensions); |
|
| 563 | - $extensions = array_unique($extensions); |
|
| 564 | - if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - return $extensions; |
|
| 555 | + static $extensions = null; |
|
| 556 | + if (empty($extensions)) { |
|
| 557 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 558 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 559 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 560 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 561 | + $extensions = array_map('trim', $extensions); |
|
| 562 | + $extensions = array_filter($extensions); |
|
| 563 | + $extensions = array_unique($extensions); |
|
| 564 | + if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + return $extensions; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
| 574 | 574 | * @return array|string[]|null |
| 575 | 575 | */ |
| 576 | 576 | function _image_extensions_acceptees_en_sortie() { |
| 577 | - static $extensions = null; |
|
| 578 | - if (empty($extensions)) { |
|
| 579 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 580 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 581 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 582 | - $extensions = array_diff($extensions, ['gif']); |
|
| 583 | - } |
|
| 584 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 585 | - $extensions = array_diff($extensions, ['webp']); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $extensions; |
|
| 577 | + static $extensions = null; |
|
| 578 | + if (empty($extensions)) { |
|
| 579 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 580 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 581 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 582 | + $extensions = array_diff($extensions, ['gif']); |
|
| 583 | + } |
|
| 584 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 585 | + $extensions = array_diff($extensions, ['webp']); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $extensions; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | function _image_extension_normalisee($extension) { |
| 593 | - $extension = strtolower($extension); |
|
| 594 | - if ($extension === 'jpeg') { |
|
| 595 | - $extension = 'jpg'; |
|
| 596 | - } |
|
| 597 | - return $extension; |
|
| 593 | + $extension = strtolower($extension); |
|
| 594 | + if ($extension === 'jpeg') { |
|
| 595 | + $extension = 'jpg'; |
|
| 596 | + } |
|
| 597 | + return $extension; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | function _image_extensions_conservent_transparence() { |
| 601 | - return ['png', 'webp']; |
|
| 601 | + return ['png', 'webp']; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | |
@@ -608,12 +608,12 @@ discard block |
||
| 608 | 608 | * @return string |
| 609 | 609 | */ |
| 610 | 610 | function _image_trouver_extension($path) { |
| 611 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 612 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 613 | - $terminaison = strtolower($regs[1]); |
|
| 614 | - return $terminaison; |
|
| 615 | - } |
|
| 616 | - return ''; |
|
| 611 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 612 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 613 | + $terminaison = strtolower($regs[1]); |
|
| 614 | + return $terminaison; |
|
| 615 | + } |
|
| 616 | + return ''; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -624,33 +624,33 @@ discard block |
||
| 624 | 624 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 625 | 625 | */ |
| 626 | 626 | function _image_trouver_extension_pertinente($path) { |
| 627 | - $path = supprimer_timestamp($path); |
|
| 628 | - $terminaison = _image_trouver_extension($path); |
|
| 629 | - if ($terminaison == 'jpg') { |
|
| 630 | - $terminaison = 'jpeg'; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - if (!file_exists($path)) { |
|
| 634 | - return $terminaison; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - if (!$info = @spip_getimagesize($path)) { |
|
| 638 | - return $terminaison; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - if (isset($info['mime'])) { |
|
| 642 | - $mime = $info['mime']; |
|
| 643 | - } |
|
| 644 | - else { |
|
| 645 | - $mime = image_type_to_mime_type($info[2]); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 649 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 650 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 651 | - $terminaison = $_terminaison; |
|
| 652 | - } |
|
| 653 | - return $terminaison; |
|
| 627 | + $path = supprimer_timestamp($path); |
|
| 628 | + $terminaison = _image_trouver_extension($path); |
|
| 629 | + if ($terminaison == 'jpg') { |
|
| 630 | + $terminaison = 'jpeg'; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + if (!file_exists($path)) { |
|
| 634 | + return $terminaison; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + if (!$info = @spip_getimagesize($path)) { |
|
| 638 | + return $terminaison; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + if (isset($info['mime'])) { |
|
| 642 | + $mime = $info['mime']; |
|
| 643 | + } |
|
| 644 | + else { |
|
| 645 | + $mime = image_type_to_mime_type($info[2]); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 649 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 650 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 651 | + $terminaison = $_terminaison; |
|
| 652 | + } |
|
| 653 | + return $terminaison; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -658,36 +658,36 @@ discard block |
||
| 658 | 658 | * @return string |
| 659 | 659 | */ |
| 660 | 660 | function _image_trouver_extension_depuis_mime($mime) { |
| 661 | - switch (strtolower($mime)) { |
|
| 662 | - case 'image/png': |
|
| 663 | - case 'image/x-png': |
|
| 664 | - $terminaison = 'png'; |
|
| 665 | - break; |
|
| 666 | - |
|
| 667 | - case 'image/jpg': |
|
| 668 | - case 'image/jpeg': |
|
| 669 | - case 'image/pjpeg': |
|
| 670 | - $terminaison = 'jpeg'; |
|
| 671 | - break; |
|
| 672 | - |
|
| 673 | - case 'image/gif': |
|
| 674 | - $terminaison = 'gif'; |
|
| 675 | - break; |
|
| 676 | - |
|
| 677 | - case 'image/webp': |
|
| 678 | - case 'image/x-webp': |
|
| 679 | - $terminaison = 'webp'; |
|
| 680 | - break; |
|
| 681 | - |
|
| 682 | - case 'image/svg+xml': |
|
| 683 | - $terminaison = 'svg'; |
|
| 684 | - break; |
|
| 685 | - |
|
| 686 | - default: |
|
| 687 | - $terminaison = ''; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - return $terminaison; |
|
| 661 | + switch (strtolower($mime)) { |
|
| 662 | + case 'image/png': |
|
| 663 | + case 'image/x-png': |
|
| 664 | + $terminaison = 'png'; |
|
| 665 | + break; |
|
| 666 | + |
|
| 667 | + case 'image/jpg': |
|
| 668 | + case 'image/jpeg': |
|
| 669 | + case 'image/pjpeg': |
|
| 670 | + $terminaison = 'jpeg'; |
|
| 671 | + break; |
|
| 672 | + |
|
| 673 | + case 'image/gif': |
|
| 674 | + $terminaison = 'gif'; |
|
| 675 | + break; |
|
| 676 | + |
|
| 677 | + case 'image/webp': |
|
| 678 | + case 'image/x-webp': |
|
| 679 | + $terminaison = 'webp'; |
|
| 680 | + break; |
|
| 681 | + |
|
| 682 | + case 'image/svg+xml': |
|
| 683 | + $terminaison = 'svg'; |
|
| 684 | + break; |
|
| 685 | + |
|
| 686 | + default: |
|
| 687 | + $terminaison = ''; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + return $terminaison; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | |
@@ -707,18 +707,18 @@ discard block |
||
| 707 | 707 | * Une ressource de type Image GD. |
| 708 | 708 | */ |
| 709 | 709 | function _imagecreatefrom_func(string $func, string $filename) { |
| 710 | - if (!function_exists($func)) { |
|
| 711 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 712 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 713 | - return null; |
|
| 714 | - } |
|
| 715 | - $img = @$func($filename); |
|
| 716 | - if (!$img) { |
|
| 717 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 718 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 719 | - $img = imagecreate(10, 10); |
|
| 720 | - } |
|
| 721 | - return $img; |
|
| 710 | + if (!function_exists($func)) { |
|
| 711 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 712 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 713 | + return null; |
|
| 714 | + } |
|
| 715 | + $img = @$func($filename); |
|
| 716 | + if (!$img) { |
|
| 717 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 718 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 719 | + $img = imagecreate(10, 10); |
|
| 720 | + } |
|
| 721 | + return $img; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * Une ressource de type Image GD. |
| 735 | 735 | */ |
| 736 | 736 | function _imagecreatefromjpeg($filename) { |
| 737 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 737 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | /** |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * Une ressource de type Image GD. |
| 751 | 751 | */ |
| 752 | 752 | function _imagecreatefrompng($filename) { |
| 753 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 753 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | * Une ressource de type Image GD. |
| 767 | 767 | */ |
| 768 | 768 | function _imagecreatefromgif($filename) { |
| 769 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 769 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | * Une ressource de type Image GD. |
| 784 | 784 | */ |
| 785 | 785 | function _imagecreatefromwebp($filename) { |
| 786 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 786 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | /** |
@@ -801,24 +801,24 @@ discard block |
||
| 801 | 801 | * - true si une image est bien retournée. |
| 802 | 802 | */ |
| 803 | 803 | function _image_imagepng($img, $fichier) { |
| 804 | - if (!function_exists('imagepng')) { |
|
| 805 | - return false; |
|
| 806 | - } |
|
| 807 | - $tmp = $fichier . '.tmp'; |
|
| 808 | - $ret = imagepng($img, $tmp); |
|
| 809 | - if (file_exists($tmp)) { |
|
| 810 | - $taille_test = getimagesize($tmp); |
|
| 811 | - if ($taille_test[0] < 1) { |
|
| 812 | - return false; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 816 | - @rename($tmp, $fichier); |
|
| 817 | - |
|
| 818 | - return $ret; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - return false; |
|
| 804 | + if (!function_exists('imagepng')) { |
|
| 805 | + return false; |
|
| 806 | + } |
|
| 807 | + $tmp = $fichier . '.tmp'; |
|
| 808 | + $ret = imagepng($img, $tmp); |
|
| 809 | + if (file_exists($tmp)) { |
|
| 810 | + $taille_test = getimagesize($tmp); |
|
| 811 | + if ($taille_test[0] < 1) { |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 816 | + @rename($tmp, $fichier); |
|
| 817 | + |
|
| 818 | + return $ret; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + return false; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -836,24 +836,24 @@ discard block |
||
| 836 | 836 | * - true si une image est bien retournée. |
| 837 | 837 | */ |
| 838 | 838 | function _image_imagegif($img, $fichier) { |
| 839 | - if (!function_exists('imagegif')) { |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - $tmp = $fichier . '.tmp'; |
|
| 843 | - $ret = imagegif($img, $tmp); |
|
| 844 | - if (file_exists($tmp)) { |
|
| 845 | - $taille_test = getimagesize($tmp); |
|
| 846 | - if ($taille_test[0] < 1) { |
|
| 847 | - return false; |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 851 | - @rename($tmp, $fichier); |
|
| 852 | - |
|
| 853 | - return $ret; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return false; |
|
| 839 | + if (!function_exists('imagegif')) { |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + $tmp = $fichier . '.tmp'; |
|
| 843 | + $ret = imagegif($img, $tmp); |
|
| 844 | + if (file_exists($tmp)) { |
|
| 845 | + $taille_test = getimagesize($tmp); |
|
| 846 | + if ($taille_test[0] < 1) { |
|
| 847 | + return false; |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 851 | + @rename($tmp, $fichier); |
|
| 852 | + |
|
| 853 | + return $ret; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return false; |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -876,29 +876,29 @@ discard block |
||
| 876 | 876 | * - true si une image est bien retournée. |
| 877 | 877 | */ |
| 878 | 878 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 879 | - if (!function_exists('imagejpeg')) { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 882 | - $tmp = $fichier . '.tmp'; |
|
| 879 | + if (!function_exists('imagejpeg')) { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | + $tmp = $fichier . '.tmp'; |
|
| 883 | 883 | |
| 884 | - // Enable interlancing |
|
| 885 | - imageinterlace($img, true); |
|
| 884 | + // Enable interlancing |
|
| 885 | + imageinterlace($img, true); |
|
| 886 | 886 | |
| 887 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 887 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 888 | 888 | |
| 889 | - if (file_exists($tmp)) { |
|
| 890 | - $taille_test = getimagesize($tmp); |
|
| 891 | - if ($taille_test[0] < 1) { |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 889 | + if (file_exists($tmp)) { |
|
| 890 | + $taille_test = getimagesize($tmp); |
|
| 891 | + if ($taille_test[0] < 1) { |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 896 | - @rename($tmp, $fichier); |
|
| 895 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 896 | + @rename($tmp, $fichier); |
|
| 897 | 897 | |
| 898 | - return $ret; |
|
| 899 | - } |
|
| 898 | + return $ret; |
|
| 899 | + } |
|
| 900 | 900 | |
| 901 | - return false; |
|
| 901 | + return false; |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -916,9 +916,9 @@ discard block |
||
| 916 | 916 | * true si le fichier a bien été créé ; false sinon. |
| 917 | 917 | */ |
| 918 | 918 | function _image_imageico($img, $fichier) { |
| 919 | - $gd_image_array = [$img]; |
|
| 919 | + $gd_image_array = [$img]; |
|
| 920 | 920 | |
| 921 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 921 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | |
@@ -937,24 +937,24 @@ discard block |
||
| 937 | 937 | * - true si une image est bien retournée. |
| 938 | 938 | */ |
| 939 | 939 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 940 | - if (!function_exists('imagewebp')) { |
|
| 941 | - return false; |
|
| 942 | - } |
|
| 943 | - $tmp = $fichier . '.tmp'; |
|
| 944 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 945 | - if (file_exists($tmp)) { |
|
| 946 | - $taille_test = getimagesize($tmp); |
|
| 947 | - if ($taille_test[0] < 1) { |
|
| 948 | - return false; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 952 | - @rename($tmp, $fichier); |
|
| 953 | - |
|
| 954 | - return $ret; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - return false; |
|
| 940 | + if (!function_exists('imagewebp')) { |
|
| 941 | + return false; |
|
| 942 | + } |
|
| 943 | + $tmp = $fichier . '.tmp'; |
|
| 944 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 945 | + if (file_exists($tmp)) { |
|
| 946 | + $taille_test = getimagesize($tmp); |
|
| 947 | + if ($taille_test[0] < 1) { |
|
| 948 | + return false; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 952 | + @rename($tmp, $fichier); |
|
| 953 | + |
|
| 954 | + return $ret; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + return false; |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -974,35 +974,35 @@ discard block |
||
| 974 | 974 | */ |
| 975 | 975 | function _image_imagesvg($img, $fichier) { |
| 976 | 976 | |
| 977 | - $tmp = $fichier . '.tmp'; |
|
| 978 | - if (strpos($img, '<') === false) { |
|
| 979 | - $img = supprimer_timestamp($img); |
|
| 980 | - if (!file_exists($img)) { |
|
| 981 | - return false; |
|
| 982 | - } |
|
| 983 | - @copy($img, $tmp); |
|
| 984 | - if (filesize($tmp) == filesize($img)) { |
|
| 985 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 986 | - @rename($tmp, $fichier); |
|
| 987 | - return true; |
|
| 988 | - } |
|
| 989 | - return false; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - file_put_contents($tmp, $img); |
|
| 993 | - if (file_exists($tmp)) { |
|
| 994 | - $taille_test = spip_getimagesize($tmp); |
|
| 995 | - if ($taille_test[0] < 1) { |
|
| 996 | - return false; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1000 | - @rename($tmp, $fichier); |
|
| 1001 | - |
|
| 1002 | - return true; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return false; |
|
| 977 | + $tmp = $fichier . '.tmp'; |
|
| 978 | + if (strpos($img, '<') === false) { |
|
| 979 | + $img = supprimer_timestamp($img); |
|
| 980 | + if (!file_exists($img)) { |
|
| 981 | + return false; |
|
| 982 | + } |
|
| 983 | + @copy($img, $tmp); |
|
| 984 | + if (filesize($tmp) == filesize($img)) { |
|
| 985 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 986 | + @rename($tmp, $fichier); |
|
| 987 | + return true; |
|
| 988 | + } |
|
| 989 | + return false; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + file_put_contents($tmp, $img); |
|
| 993 | + if (file_exists($tmp)) { |
|
| 994 | + $taille_test = spip_getimagesize($tmp); |
|
| 995 | + if ($taille_test[0] < 1) { |
|
| 996 | + return false; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1000 | + @rename($tmp, $fichier); |
|
| 1001 | + |
|
| 1002 | + return true; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return false; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | |
@@ -1030,29 +1030,29 @@ discard block |
||
| 1030 | 1030 | * - false sinon. |
| 1031 | 1031 | */ |
| 1032 | 1032 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1033 | - if (is_null($fonction)) { |
|
| 1034 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1035 | - } |
|
| 1036 | - $ret = false; |
|
| 1037 | - #un flag pour reperer les images gravees |
|
| 1038 | - $lock = |
|
| 1039 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1040 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1041 | - if ( |
|
| 1042 | - function_exists($fonction) |
|
| 1043 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1044 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1045 | - && !$lock |
|
| 1046 | - ) { |
|
| 1047 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1048 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1049 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1050 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1051 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - return $ret; |
|
| 1033 | + if (is_null($fonction)) { |
|
| 1034 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1035 | + } |
|
| 1036 | + $ret = false; |
|
| 1037 | + #un flag pour reperer les images gravees |
|
| 1038 | + $lock = |
|
| 1039 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1040 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1041 | + if ( |
|
| 1042 | + function_exists($fonction) |
|
| 1043 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1044 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1045 | + && !$lock |
|
| 1046 | + ) { |
|
| 1047 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1048 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1049 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1050 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1051 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + return $ret; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
@@ -1065,27 +1065,27 @@ discard block |
||
| 1065 | 1065 | * Chemin vers le fichier manquant |
| 1066 | 1066 | **/ |
| 1067 | 1067 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1068 | - $reconstruire = []; |
|
| 1069 | - $fichier = $fichier_manquant; |
|
| 1070 | - while ( |
|
| 1071 | - strpos($fichier, '://') === false |
|
| 1072 | - and !@file_exists($fichier) |
|
| 1073 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1074 | - and $valeurs = unserialize($source) |
|
| 1075 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1076 | - ) { |
|
| 1077 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1078 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1079 | - } |
|
| 1080 | - while (count($reconstruire)) { |
|
| 1081 | - $r = array_pop($reconstruire); |
|
| 1082 | - $fonction = $r[0]; |
|
| 1083 | - $args = $r[1]; |
|
| 1084 | - $fonction(...$args); |
|
| 1085 | - } |
|
| 1086 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1087 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1088 | - ramasse_miettes($fichier_manquant); |
|
| 1068 | + $reconstruire = []; |
|
| 1069 | + $fichier = $fichier_manquant; |
|
| 1070 | + while ( |
|
| 1071 | + strpos($fichier, '://') === false |
|
| 1072 | + and !@file_exists($fichier) |
|
| 1073 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1074 | + and $valeurs = unserialize($source) |
|
| 1075 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1076 | + ) { |
|
| 1077 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1078 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1079 | + } |
|
| 1080 | + while (count($reconstruire)) { |
|
| 1081 | + $r = array_pop($reconstruire); |
|
| 1082 | + $fonction = $r[0]; |
|
| 1083 | + $args = $r[1]; |
|
| 1084 | + $fonction(...$args); |
|
| 1085 | + } |
|
| 1086 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1087 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1088 | + ramasse_miettes($fichier_manquant); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | /** |
@@ -1105,28 +1105,28 @@ discard block |
||
| 1105 | 1105 | * Chemin du fichier d'image calculé |
| 1106 | 1106 | **/ |
| 1107 | 1107 | function ramasse_miettes($fichier) { |
| 1108 | - if ( |
|
| 1109 | - strpos($fichier, '://') !== false |
|
| 1110 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1111 | - or !$valeurs = unserialize($source) |
|
| 1112 | - ) { |
|
| 1113 | - return; |
|
| 1114 | - } |
|
| 1115 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1116 | - while ( |
|
| 1117 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1118 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1119 | - and (lire_fichier( |
|
| 1120 | - $src = "$fichier.src", |
|
| 1121 | - $source |
|
| 1122 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1123 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1124 | - ) { |
|
| 1125 | - # on efface le fichier |
|
| 1126 | - spip_unlink($fichier); |
|
| 1127 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1128 | - #spip_unlink($src); |
|
| 1129 | - } |
|
| 1108 | + if ( |
|
| 1109 | + strpos($fichier, '://') !== false |
|
| 1110 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1111 | + or !$valeurs = unserialize($source) |
|
| 1112 | + ) { |
|
| 1113 | + return; |
|
| 1114 | + } |
|
| 1115 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1116 | + while ( |
|
| 1117 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1118 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1119 | + and (lire_fichier( |
|
| 1120 | + $src = "$fichier.src", |
|
| 1121 | + $source |
|
| 1122 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1123 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1124 | + ) { |
|
| 1125 | + # on efface le fichier |
|
| 1126 | + spip_unlink($fichier); |
|
| 1127 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1128 | + #spip_unlink($src); |
|
| 1129 | + } |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
@@ -1151,71 +1151,71 @@ discard block |
||
| 1151 | 1151 | * Code HTML de l'image |
| 1152 | 1152 | **/ |
| 1153 | 1153 | function image_graver($img) { |
| 1154 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1155 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1156 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1157 | - |
|
| 1158 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1159 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1160 | - $fichier = substr($fichier, 0, $p); |
|
| 1161 | - } |
|
| 1162 | - if (strlen($fichier) < 1) { |
|
| 1163 | - $fichier = $img; |
|
| 1164 | - } |
|
| 1165 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1166 | - # et qu'il ne s'agit pas d'une URL |
|
| 1167 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1168 | - reconstruire_image_intermediaire($fichier); |
|
| 1169 | - } |
|
| 1170 | - ramasse_miettes($fichier); |
|
| 1171 | - |
|
| 1172 | - // ajouter le timestamp si besoin |
|
| 1173 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1174 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1175 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - return $img; |
|
| 1154 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1155 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1156 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1157 | + |
|
| 1158 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1159 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1160 | + $fichier = substr($fichier, 0, $p); |
|
| 1161 | + } |
|
| 1162 | + if (strlen($fichier) < 1) { |
|
| 1163 | + $fichier = $img; |
|
| 1164 | + } |
|
| 1165 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1166 | + # et qu'il ne s'agit pas d'une URL |
|
| 1167 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1168 | + reconstruire_image_intermediaire($fichier); |
|
| 1169 | + } |
|
| 1170 | + ramasse_miettes($fichier); |
|
| 1171 | + |
|
| 1172 | + // ajouter le timestamp si besoin |
|
| 1173 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1174 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1175 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + return $img; |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | |
| 1182 | 1182 | if (!function_exists('imagepalettetotruecolor')) { |
| 1183 | - /** |
|
| 1184 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1185 | - * |
|
| 1186 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 1187 | - * |
|
| 1188 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1189 | - * |
|
| 1190 | - * @param ressource $img |
|
| 1191 | - * @return bool |
|
| 1192 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1193 | - * - false si la transformation ne peut être faite. |
|
| 1194 | - **/ |
|
| 1195 | - function imagepalettetotruecolor(&$img) { |
|
| 1196 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1197 | - return false; |
|
| 1198 | - } elseif (!imageistruecolor($img)) { |
|
| 1199 | - $w = imagesx($img); |
|
| 1200 | - $h = imagesy($img); |
|
| 1201 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 1202 | - //Conserver la transparence si possible |
|
| 1203 | - if (function_exists('ImageCopyResampled')) { |
|
| 1204 | - if (function_exists('imageAntiAlias')) { |
|
| 1205 | - imageAntiAlias($img1, true); |
|
| 1206 | - } |
|
| 1207 | - @imagealphablending($img1, false); |
|
| 1208 | - @imagesavealpha($img1, true); |
|
| 1209 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1210 | - } else { |
|
| 1211 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - $img = $img1; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - return true; |
|
| 1218 | - } |
|
| 1183 | + /** |
|
| 1184 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1185 | + * |
|
| 1186 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 1187 | + * |
|
| 1188 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1189 | + * |
|
| 1190 | + * @param ressource $img |
|
| 1191 | + * @return bool |
|
| 1192 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1193 | + * - false si la transformation ne peut être faite. |
|
| 1194 | + **/ |
|
| 1195 | + function imagepalettetotruecolor(&$img) { |
|
| 1196 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1197 | + return false; |
|
| 1198 | + } elseif (!imageistruecolor($img)) { |
|
| 1199 | + $w = imagesx($img); |
|
| 1200 | + $h = imagesy($img); |
|
| 1201 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 1202 | + //Conserver la transparence si possible |
|
| 1203 | + if (function_exists('ImageCopyResampled')) { |
|
| 1204 | + if (function_exists('imageAntiAlias')) { |
|
| 1205 | + imageAntiAlias($img1, true); |
|
| 1206 | + } |
|
| 1207 | + @imagealphablending($img1, false); |
|
| 1208 | + @imagesavealpha($img1, true); |
|
| 1209 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1210 | + } else { |
|
| 1211 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + $img = $img1; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return true; |
|
| 1218 | + } |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | /** |
@@ -1242,34 +1242,34 @@ discard block |
||
| 1242 | 1242 | * Code html modifié de la balise. |
| 1243 | 1243 | **/ |
| 1244 | 1244 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1245 | - if ($style === false) { |
|
| 1246 | - $style = extraire_attribut($tag, 'style'); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - // enlever le width et height du style |
|
| 1250 | - if ($style) { |
|
| 1251 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1252 | - } |
|
| 1253 | - if ($style and $style[0] === ';') { |
|
| 1254 | - $style = substr($style, 1); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - // mettre des attributs de width et height sur les images, |
|
| 1258 | - // ca accelere le rendu du navigateur |
|
| 1259 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1260 | - // quand on a desactive l'affichage des images. |
|
| 1261 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1262 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1263 | - |
|
| 1264 | - // attributs deprecies. Transformer en CSS |
|
| 1265 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1266 | - $style = "margin:${espace}px;" . $style; |
|
| 1267 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1271 | - |
|
| 1272 | - return $tag; |
|
| 1245 | + if ($style === false) { |
|
| 1246 | + $style = extraire_attribut($tag, 'style'); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + // enlever le width et height du style |
|
| 1250 | + if ($style) { |
|
| 1251 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1252 | + } |
|
| 1253 | + if ($style and $style[0] === ';') { |
|
| 1254 | + $style = substr($style, 1); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + // mettre des attributs de width et height sur les images, |
|
| 1258 | + // ca accelere le rendu du navigateur |
|
| 1259 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1260 | + // quand on a desactive l'affichage des images. |
|
| 1261 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1262 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1263 | + |
|
| 1264 | + // attributs deprecies. Transformer en CSS |
|
| 1265 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1266 | + $style = "margin:${espace}px;" . $style; |
|
| 1267 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1271 | + |
|
| 1272 | + return $tag; |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | |
@@ -1295,72 +1295,72 @@ discard block |
||
| 1295 | 1295 | * Retourne le code HTML de l'image |
| 1296 | 1296 | **/ |
| 1297 | 1297 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1298 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1299 | - |
|
| 1300 | - // fermer les tags img pas bien fermes; |
|
| 1301 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1302 | - |
|
| 1303 | - // le style |
|
| 1304 | - $style = $valeurs['style']; |
|
| 1305 | - if (isset($surcharge['style'])) { |
|
| 1306 | - $style = $surcharge['style']; |
|
| 1307 | - unset($surcharge['style']); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - // traiter specifiquement la largeur et la hauteur |
|
| 1311 | - $width = $valeurs['largeur']; |
|
| 1312 | - if (isset($surcharge['width'])) { |
|
| 1313 | - $width = $surcharge['width']; |
|
| 1314 | - unset($surcharge['width']); |
|
| 1315 | - } |
|
| 1316 | - $height = $valeurs['hauteur']; |
|
| 1317 | - if (isset($surcharge['height'])) { |
|
| 1318 | - $height = $surcharge['height']; |
|
| 1319 | - unset($surcharge['height']); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1323 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1324 | - // on remplace toute les ref a src dans le tag |
|
| 1325 | - $src = extraire_attribut($tag, 'src'); |
|
| 1326 | - if (isset($surcharge['src'])) { |
|
| 1327 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1328 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1329 | - // pas garanti comme methode, mais mieux que rien |
|
| 1330 | - if (strpos($src, '&') !== false) { |
|
| 1331 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1332 | - } |
|
| 1333 | - $src = $surcharge['src']; |
|
| 1334 | - unset($surcharge['src']); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - $class = $valeurs['class']; |
|
| 1338 | - if (isset($surcharge['class'])) { |
|
| 1339 | - $class = $surcharge['class']; |
|
| 1340 | - unset($surcharge['class']); |
|
| 1341 | - } |
|
| 1342 | - if (is_scalar($class) && strlen($class)) { |
|
| 1343 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - if (count($surcharge)) { |
|
| 1347 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1348 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1349 | - } |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - $tag = pipeline( |
|
| 1353 | - 'image_ecrire_tag_finir', |
|
| 1354 | - [ |
|
| 1355 | - 'args' => [ |
|
| 1356 | - 'valeurs' => $valeurs, |
|
| 1357 | - 'surcharge' => $surcharge, |
|
| 1358 | - ], |
|
| 1359 | - 'data' => $tag |
|
| 1360 | - ] |
|
| 1361 | - ); |
|
| 1362 | - |
|
| 1363 | - return $tag; |
|
| 1298 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1299 | + |
|
| 1300 | + // fermer les tags img pas bien fermes; |
|
| 1301 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1302 | + |
|
| 1303 | + // le style |
|
| 1304 | + $style = $valeurs['style']; |
|
| 1305 | + if (isset($surcharge['style'])) { |
|
| 1306 | + $style = $surcharge['style']; |
|
| 1307 | + unset($surcharge['style']); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + // traiter specifiquement la largeur et la hauteur |
|
| 1311 | + $width = $valeurs['largeur']; |
|
| 1312 | + if (isset($surcharge['width'])) { |
|
| 1313 | + $width = $surcharge['width']; |
|
| 1314 | + unset($surcharge['width']); |
|
| 1315 | + } |
|
| 1316 | + $height = $valeurs['hauteur']; |
|
| 1317 | + if (isset($surcharge['height'])) { |
|
| 1318 | + $height = $surcharge['height']; |
|
| 1319 | + unset($surcharge['height']); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1323 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1324 | + // on remplace toute les ref a src dans le tag |
|
| 1325 | + $src = extraire_attribut($tag, 'src'); |
|
| 1326 | + if (isset($surcharge['src'])) { |
|
| 1327 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1328 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1329 | + // pas garanti comme methode, mais mieux que rien |
|
| 1330 | + if (strpos($src, '&') !== false) { |
|
| 1331 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1332 | + } |
|
| 1333 | + $src = $surcharge['src']; |
|
| 1334 | + unset($surcharge['src']); |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + $class = $valeurs['class']; |
|
| 1338 | + if (isset($surcharge['class'])) { |
|
| 1339 | + $class = $surcharge['class']; |
|
| 1340 | + unset($surcharge['class']); |
|
| 1341 | + } |
|
| 1342 | + if (is_scalar($class) && strlen($class)) { |
|
| 1343 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + if (count($surcharge)) { |
|
| 1347 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1348 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + $tag = pipeline( |
|
| 1353 | + 'image_ecrire_tag_finir', |
|
| 1354 | + [ |
|
| 1355 | + 'args' => [ |
|
| 1356 | + 'valeurs' => $valeurs, |
|
| 1357 | + 'surcharge' => $surcharge, |
|
| 1358 | + ], |
|
| 1359 | + 'data' => $tag |
|
| 1360 | + ] |
|
| 1361 | + ); |
|
| 1362 | + |
|
| 1363 | + return $tag; |
|
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | 1366 | /** |
@@ -1383,259 +1383,259 @@ discard block |
||
| 1383 | 1383 | * Description de l'image, sinon null. |
| 1384 | 1384 | **/ |
| 1385 | 1385 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1386 | - $srcHeight = null; |
|
| 1387 | - $retour = []; |
|
| 1388 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1389 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1390 | - $image = $valeurs['fichier']; |
|
| 1391 | - $format = $valeurs['format_source']; |
|
| 1392 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1393 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1394 | - |
|
| 1395 | - $format_sortie = $valeurs['format_dest']; |
|
| 1396 | - |
|
| 1397 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1398 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1402 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1403 | - return; |
|
| 1404 | - } |
|
| 1405 | - $destination = "$destdir/$destfile"; |
|
| 1406 | - |
|
| 1407 | - // calculer la taille |
|
| 1408 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1409 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1410 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1411 | - } |
|
| 1412 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1413 | - $destWidth = $maxWidth; |
|
| 1414 | - $destHeight = $maxHeight; |
|
| 1415 | - } else { |
|
| 1416 | - spip_log("echec $process sur $image"); |
|
| 1417 | - |
|
| 1418 | - return; |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - $vignette = ''; |
|
| 1422 | - |
|
| 1423 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1424 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1425 | - $vignette = $destination . '.' . $format; |
|
| 1426 | - @copy($image, $vignette); |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1430 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1431 | - $format_sortie = 'svg'; |
|
| 1432 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1433 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1434 | - _image_gd_output($svg, $valeurs); |
|
| 1435 | - } |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - // imagemagick en ligne de commande |
|
| 1439 | - elseif ($process == 'convert') { |
|
| 1440 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1441 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1442 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1443 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1444 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1445 | - } |
|
| 1446 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1447 | - $commande = str_replace( |
|
| 1448 | - ['%x', '%y', '%src', '%dest'], |
|
| 1449 | - [ |
|
| 1450 | - $destWidth, |
|
| 1451 | - $destHeight, |
|
| 1452 | - escapeshellcmd($image), |
|
| 1453 | - escapeshellcmd($vignette) |
|
| 1454 | - ], |
|
| 1455 | - _RESIZE_COMMAND |
|
| 1456 | - ); |
|
| 1457 | - spip_log($commande); |
|
| 1458 | - exec($commande); |
|
| 1459 | - if (!@file_exists($vignette)) { |
|
| 1460 | - spip_log("echec convert sur $vignette"); |
|
| 1461 | - |
|
| 1462 | - return; // echec commande |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - // php5 imagemagick |
|
| 1467 | - elseif ($process == 'imagick') { |
|
| 1468 | - $vignette = "$destination." . $format_sortie; |
|
| 1469 | - |
|
| 1470 | - if (!class_exists(\Imagick::class)) { |
|
| 1471 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1472 | - |
|
| 1473 | - return; |
|
| 1474 | - } |
|
| 1475 | - $imagick = new Imagick(); |
|
| 1476 | - $imagick->readImage($image); |
|
| 1477 | - $imagick->resizeImage( |
|
| 1478 | - $destWidth, |
|
| 1479 | - $destHeight, |
|
| 1480 | - Imagick::FILTER_LANCZOS, |
|
| 1481 | - 1 |
|
| 1482 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1483 | - $imagick->writeImage($vignette); |
|
| 1484 | - |
|
| 1485 | - if (!@file_exists($vignette)) { |
|
| 1486 | - spip_log("echec imagick sur $vignette"); |
|
| 1487 | - |
|
| 1488 | - return; |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - // netpbm |
|
| 1493 | - elseif ($process == 'netpbm') { |
|
| 1494 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1495 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1496 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1497 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1498 | - return; |
|
| 1499 | - } |
|
| 1500 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1501 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1502 | - if ($format == 'jpg') { |
|
| 1503 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | - if (!($s = @filesize($vignette))) { |
|
| 1506 | - spip_unlink($vignette); |
|
| 1507 | - } |
|
| 1508 | - if (!@file_exists($vignette)) { |
|
| 1509 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1510 | - |
|
| 1511 | - return; |
|
| 1512 | - } |
|
| 1513 | - } else { |
|
| 1514 | - if ($format == 'gif') { |
|
| 1515 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1516 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1517 | - if (!($s = @filesize($vignette))) { |
|
| 1518 | - spip_unlink($vignette); |
|
| 1519 | - } |
|
| 1520 | - if (!@file_exists($vignette)) { |
|
| 1521 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1522 | - |
|
| 1523 | - return; |
|
| 1524 | - } |
|
| 1525 | - } else { |
|
| 1526 | - if ($format == 'png') { |
|
| 1527 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1528 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1529 | - if (!($s = @filesize($vignette))) { |
|
| 1530 | - spip_unlink($vignette); |
|
| 1531 | - } |
|
| 1532 | - if (!@file_exists($vignette)) { |
|
| 1533 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1534 | - |
|
| 1535 | - return; |
|
| 1536 | - } |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - // gd ou gd2 |
|
| 1543 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1544 | - if (!function_exists('gd_info')) { |
|
| 1545 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1546 | - |
|
| 1547 | - return; |
|
| 1548 | - } |
|
| 1549 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1550 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1551 | - |
|
| 1552 | - return; |
|
| 1553 | - } |
|
| 1554 | - $destFormat = $format_sortie; |
|
| 1555 | - if (!$destFormat) { |
|
| 1556 | - spip_log("pas de format pour $image"); |
|
| 1557 | - |
|
| 1558 | - return; |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1562 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1563 | - return ''; |
|
| 1564 | - } |
|
| 1565 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1566 | - if (!$srcImage) { |
|
| 1567 | - spip_log('echec gd1/gd2'); |
|
| 1568 | - |
|
| 1569 | - return; |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - // Initialisation de l'image destination |
|
| 1573 | - $destImage = null; |
|
| 1574 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1575 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1576 | - } |
|
| 1577 | - if (!$destImage) { |
|
| 1578 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1582 | - $ok = false; |
|
| 1583 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1584 | - if ($format == 'gif') { |
|
| 1585 | - // Si un GIF est transparent, |
|
| 1586 | - // fabriquer un PNG transparent |
|
| 1587 | - $transp = imagecolortransparent($srcImage); |
|
| 1588 | - if ($transp > 0) { |
|
| 1589 | - $destFormat = 'png'; |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1593 | - // Conserver la transparence |
|
| 1594 | - if (function_exists('imageAntiAlias')) { |
|
| 1595 | - imageAntiAlias($destImage, true); |
|
| 1596 | - } |
|
| 1597 | - @imagealphablending($destImage, false); |
|
| 1598 | - @imagesavealpha($destImage, true); |
|
| 1599 | - } |
|
| 1600 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1601 | - } |
|
| 1602 | - if (!$ok) { |
|
| 1603 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - // Sauvegarde de l'image destination |
|
| 1607 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1608 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1609 | - _image_gd_output($destImage, $valeurs); |
|
| 1610 | - |
|
| 1611 | - if ($srcImage) { |
|
| 1612 | - ImageDestroy($srcImage); |
|
| 1613 | - } |
|
| 1614 | - ImageDestroy($destImage); |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1618 | - $size = [$destWidth, $destHeight]; |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1622 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1623 | - if ($size[0] < 1) { |
|
| 1624 | - $size[0] = $destWidth; |
|
| 1625 | - } |
|
| 1626 | - if ($size[1] < 1) { |
|
| 1627 | - $size[1] = $destHeight; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - $retour['width'] = $largeur = $size[0]; |
|
| 1631 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1632 | - |
|
| 1633 | - $retour['fichier'] = $vignette; |
|
| 1634 | - $retour['format'] = $format; |
|
| 1635 | - $retour['date'] = @filemtime($vignette); |
|
| 1636 | - |
|
| 1637 | - // renvoyer l'image |
|
| 1638 | - return $retour; |
|
| 1386 | + $srcHeight = null; |
|
| 1387 | + $retour = []; |
|
| 1388 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1389 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1390 | + $image = $valeurs['fichier']; |
|
| 1391 | + $format = $valeurs['format_source']; |
|
| 1392 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1393 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1394 | + |
|
| 1395 | + $format_sortie = $valeurs['format_dest']; |
|
| 1396 | + |
|
| 1397 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1398 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1402 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1403 | + return; |
|
| 1404 | + } |
|
| 1405 | + $destination = "$destdir/$destfile"; |
|
| 1406 | + |
|
| 1407 | + // calculer la taille |
|
| 1408 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1409 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1410 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1411 | + } |
|
| 1412 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1413 | + $destWidth = $maxWidth; |
|
| 1414 | + $destHeight = $maxHeight; |
|
| 1415 | + } else { |
|
| 1416 | + spip_log("echec $process sur $image"); |
|
| 1417 | + |
|
| 1418 | + return; |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + $vignette = ''; |
|
| 1422 | + |
|
| 1423 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1424 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1425 | + $vignette = $destination . '.' . $format; |
|
| 1426 | + @copy($image, $vignette); |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1430 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1431 | + $format_sortie = 'svg'; |
|
| 1432 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1433 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1434 | + _image_gd_output($svg, $valeurs); |
|
| 1435 | + } |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + // imagemagick en ligne de commande |
|
| 1439 | + elseif ($process == 'convert') { |
|
| 1440 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1441 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1442 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1443 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1444 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1445 | + } |
|
| 1446 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1447 | + $commande = str_replace( |
|
| 1448 | + ['%x', '%y', '%src', '%dest'], |
|
| 1449 | + [ |
|
| 1450 | + $destWidth, |
|
| 1451 | + $destHeight, |
|
| 1452 | + escapeshellcmd($image), |
|
| 1453 | + escapeshellcmd($vignette) |
|
| 1454 | + ], |
|
| 1455 | + _RESIZE_COMMAND |
|
| 1456 | + ); |
|
| 1457 | + spip_log($commande); |
|
| 1458 | + exec($commande); |
|
| 1459 | + if (!@file_exists($vignette)) { |
|
| 1460 | + spip_log("echec convert sur $vignette"); |
|
| 1461 | + |
|
| 1462 | + return; // echec commande |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + // php5 imagemagick |
|
| 1467 | + elseif ($process == 'imagick') { |
|
| 1468 | + $vignette = "$destination." . $format_sortie; |
|
| 1469 | + |
|
| 1470 | + if (!class_exists(\Imagick::class)) { |
|
| 1471 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1472 | + |
|
| 1473 | + return; |
|
| 1474 | + } |
|
| 1475 | + $imagick = new Imagick(); |
|
| 1476 | + $imagick->readImage($image); |
|
| 1477 | + $imagick->resizeImage( |
|
| 1478 | + $destWidth, |
|
| 1479 | + $destHeight, |
|
| 1480 | + Imagick::FILTER_LANCZOS, |
|
| 1481 | + 1 |
|
| 1482 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1483 | + $imagick->writeImage($vignette); |
|
| 1484 | + |
|
| 1485 | + if (!@file_exists($vignette)) { |
|
| 1486 | + spip_log("echec imagick sur $vignette"); |
|
| 1487 | + |
|
| 1488 | + return; |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + // netpbm |
|
| 1493 | + elseif ($process == 'netpbm') { |
|
| 1494 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1495 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1496 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1497 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1498 | + return; |
|
| 1499 | + } |
|
| 1500 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1501 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1502 | + if ($format == 'jpg') { |
|
| 1503 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | + if (!($s = @filesize($vignette))) { |
|
| 1506 | + spip_unlink($vignette); |
|
| 1507 | + } |
|
| 1508 | + if (!@file_exists($vignette)) { |
|
| 1509 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1510 | + |
|
| 1511 | + return; |
|
| 1512 | + } |
|
| 1513 | + } else { |
|
| 1514 | + if ($format == 'gif') { |
|
| 1515 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1516 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1517 | + if (!($s = @filesize($vignette))) { |
|
| 1518 | + spip_unlink($vignette); |
|
| 1519 | + } |
|
| 1520 | + if (!@file_exists($vignette)) { |
|
| 1521 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1522 | + |
|
| 1523 | + return; |
|
| 1524 | + } |
|
| 1525 | + } else { |
|
| 1526 | + if ($format == 'png') { |
|
| 1527 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1528 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1529 | + if (!($s = @filesize($vignette))) { |
|
| 1530 | + spip_unlink($vignette); |
|
| 1531 | + } |
|
| 1532 | + if (!@file_exists($vignette)) { |
|
| 1533 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1534 | + |
|
| 1535 | + return; |
|
| 1536 | + } |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + // gd ou gd2 |
|
| 1543 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1544 | + if (!function_exists('gd_info')) { |
|
| 1545 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1546 | + |
|
| 1547 | + return; |
|
| 1548 | + } |
|
| 1549 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1550 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1551 | + |
|
| 1552 | + return; |
|
| 1553 | + } |
|
| 1554 | + $destFormat = $format_sortie; |
|
| 1555 | + if (!$destFormat) { |
|
| 1556 | + spip_log("pas de format pour $image"); |
|
| 1557 | + |
|
| 1558 | + return; |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1562 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1563 | + return ''; |
|
| 1564 | + } |
|
| 1565 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1566 | + if (!$srcImage) { |
|
| 1567 | + spip_log('echec gd1/gd2'); |
|
| 1568 | + |
|
| 1569 | + return; |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + // Initialisation de l'image destination |
|
| 1573 | + $destImage = null; |
|
| 1574 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1575 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1576 | + } |
|
| 1577 | + if (!$destImage) { |
|
| 1578 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1582 | + $ok = false; |
|
| 1583 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1584 | + if ($format == 'gif') { |
|
| 1585 | + // Si un GIF est transparent, |
|
| 1586 | + // fabriquer un PNG transparent |
|
| 1587 | + $transp = imagecolortransparent($srcImage); |
|
| 1588 | + if ($transp > 0) { |
|
| 1589 | + $destFormat = 'png'; |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1593 | + // Conserver la transparence |
|
| 1594 | + if (function_exists('imageAntiAlias')) { |
|
| 1595 | + imageAntiAlias($destImage, true); |
|
| 1596 | + } |
|
| 1597 | + @imagealphablending($destImage, false); |
|
| 1598 | + @imagesavealpha($destImage, true); |
|
| 1599 | + } |
|
| 1600 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1601 | + } |
|
| 1602 | + if (!$ok) { |
|
| 1603 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + // Sauvegarde de l'image destination |
|
| 1607 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1608 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1609 | + _image_gd_output($destImage, $valeurs); |
|
| 1610 | + |
|
| 1611 | + if ($srcImage) { |
|
| 1612 | + ImageDestroy($srcImage); |
|
| 1613 | + } |
|
| 1614 | + ImageDestroy($destImage); |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1618 | + $size = [$destWidth, $destHeight]; |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1622 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1623 | + if ($size[0] < 1) { |
|
| 1624 | + $size[0] = $destWidth; |
|
| 1625 | + } |
|
| 1626 | + if ($size[1] < 1) { |
|
| 1627 | + $size[1] = $destHeight; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + $retour['width'] = $largeur = $size[0]; |
|
| 1631 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1632 | + |
|
| 1633 | + $retour['fichier'] = $vignette; |
|
| 1634 | + $retour['format'] = $format; |
|
| 1635 | + $retour['date'] = @filemtime($vignette); |
|
| 1636 | + |
|
| 1637 | + // renvoyer l'image |
|
| 1638 | + return $retour; |
|
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
@@ -1655,25 +1655,25 @@ discard block |
||
| 1655 | 1655 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1656 | 1656 | **/ |
| 1657 | 1657 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1658 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1659 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1660 | - |
|
| 1661 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1662 | - $destWidth = $srcWidth; |
|
| 1663 | - $destHeight = $srcHeight; |
|
| 1664 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1665 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1666 | - $destHeight = $maxHeight; |
|
| 1667 | - } else { |
|
| 1668 | - $destWidth = $maxWidth; |
|
| 1669 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - return [ |
|
| 1673 | - intval(round($destWidth)), |
|
| 1674 | - intval(round($destHeight)), |
|
| 1675 | - max($ratioWidth, $ratioHeight) |
|
| 1676 | - ]; |
|
| 1658 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1659 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1660 | + |
|
| 1661 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1662 | + $destWidth = $srcWidth; |
|
| 1663 | + $destHeight = $srcHeight; |
|
| 1664 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1665 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1666 | + $destHeight = $maxHeight; |
|
| 1667 | + } else { |
|
| 1668 | + $destWidth = $maxWidth; |
|
| 1669 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + return [ |
|
| 1673 | + intval(round($destWidth)), |
|
| 1674 | + intval(round($destHeight)), |
|
| 1675 | + max($ratioWidth, $ratioHeight) |
|
| 1676 | + ]; |
|
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | 1679 | /** |
@@ -1693,25 +1693,25 @@ discard block |
||
| 1693 | 1693 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1694 | 1694 | **/ |
| 1695 | 1695 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1696 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1697 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1698 | - |
|
| 1699 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1700 | - $destWidth = $srcWidth; |
|
| 1701 | - $destHeight = $srcHeight; |
|
| 1702 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1703 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1704 | - $destHeight = $maxHeight; |
|
| 1705 | - } else { |
|
| 1706 | - $destWidth = $maxWidth; |
|
| 1707 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - return [ |
|
| 1711 | - intval(round($destWidth)), |
|
| 1712 | - intval(round($destHeight)), |
|
| 1713 | - min($ratioWidth, $ratioHeight) |
|
| 1714 | - ]; |
|
| 1696 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1697 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1698 | + |
|
| 1699 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1700 | + $destWidth = $srcWidth; |
|
| 1701 | + $destHeight = $srcHeight; |
|
| 1702 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1703 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1704 | + $destHeight = $maxHeight; |
|
| 1705 | + } else { |
|
| 1706 | + $destWidth = $maxWidth; |
|
| 1707 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + return [ |
|
| 1711 | + intval(round($destWidth)), |
|
| 1712 | + intval(round($destHeight)), |
|
| 1713 | + min($ratioWidth, $ratioHeight) |
|
| 1714 | + ]; |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | |
@@ -1724,12 +1724,12 @@ discard block |
||
| 1724 | 1724 | * @return string |
| 1725 | 1725 | */ |
| 1726 | 1726 | function process_image_svg_identite($image) { |
| 1727 | - if ($image['creer']) { |
|
| 1728 | - $source = $image['fichier']; |
|
| 1729 | - _image_gd_output($source, $image); |
|
| 1730 | - } |
|
| 1727 | + if ($image['creer']) { |
|
| 1728 | + $source = $image['fichier']; |
|
| 1729 | + _image_gd_output($source, $image); |
|
| 1730 | + } |
|
| 1731 | 1731 | |
| 1732 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1732 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | 1735 | |
@@ -1762,111 +1762,111 @@ discard block |
||
| 1762 | 1762 | * Code HTML de la balise img produite |
| 1763 | 1763 | **/ |
| 1764 | 1764 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1765 | - $image = false; |
|
| 1766 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1767 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1768 | - } |
|
| 1769 | - # determiner le format de sortie |
|
| 1770 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1771 | - if ($process == 'netpbm') { |
|
| 1772 | - $format_sortie = 'jpg'; |
|
| 1773 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1774 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1775 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1776 | - $gd_formats = formats_image_acceptables(true); |
|
| 1777 | - if ( |
|
| 1778 | - is_array($image) |
|
| 1779 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1780 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1781 | - ) |
|
| 1782 | - ) { |
|
| 1783 | - if ($image['format_source'] == 'jpg') { |
|
| 1784 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1785 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1786 | - { |
|
| 1787 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1788 | - } |
|
| 1789 | - // Choisir le format destination |
|
| 1790 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1791 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1792 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1793 | - # pas *ecrire* |
|
| 1794 | - $format_sortie = ''; |
|
| 1795 | - foreach ($formats_sortie as $fmt) { |
|
| 1796 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1797 | - $format_sortie = $fmt; |
|
| 1798 | - break; |
|
| 1799 | - } |
|
| 1800 | - } |
|
| 1801 | - $image = false; |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - |
|
| 1805 | - if (!is_array($image)) { |
|
| 1806 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1810 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1811 | - // on peut resizer en mode html si on dispose des elements |
|
| 1812 | - if ( |
|
| 1813 | - $srcw = extraire_attribut($img, 'width') |
|
| 1814 | - and $srch = extraire_attribut($img, 'height') |
|
| 1815 | - ) { |
|
| 1816 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1817 | - |
|
| 1818 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1819 | - } |
|
| 1820 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1821 | - // sous la forme style='max-width: NNpx;' |
|
| 1822 | - return inserer_attribut( |
|
| 1823 | - $img, |
|
| 1824 | - 'style', |
|
| 1825 | - "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1826 | - ); |
|
| 1827 | - } |
|
| 1828 | - |
|
| 1829 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1830 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1831 | - if ($image['creer']) { |
|
| 1832 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1836 | - } |
|
| 1837 | - |
|
| 1838 | - if ($image['creer'] == false && !$force) { |
|
| 1839 | - return _image_ecrire_tag( |
|
| 1840 | - $image, |
|
| 1841 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1842 | - ); |
|
| 1843 | - } |
|
| 1844 | - |
|
| 1845 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1846 | - $destWidth = $image['largeur_dest']; |
|
| 1847 | - $destHeight = $image['hauteur_dest']; |
|
| 1848 | - $logo = $image['fichier']; |
|
| 1849 | - $date = $image['date_src']; |
|
| 1850 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1851 | - |
|
| 1852 | - if ($preview && $preview['fichier']) { |
|
| 1853 | - $logo = $preview['fichier']; |
|
| 1854 | - $destWidth = $preview['width']; |
|
| 1855 | - $destHeight = $preview['height']; |
|
| 1856 | - $date = $preview['date']; |
|
| 1857 | - } |
|
| 1858 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1859 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1860 | - // quand on fait supprimer/reuploader un logo |
|
| 1861 | - // (pas de filemtime si SAFE MODE) |
|
| 1862 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1863 | - |
|
| 1864 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1865 | - } |
|
| 1866 | - else { |
|
| 1867 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1868 | - return $img; |
|
| 1869 | - } |
|
| 1765 | + $image = false; |
|
| 1766 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1767 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1768 | + } |
|
| 1769 | + # determiner le format de sortie |
|
| 1770 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1771 | + if ($process == 'netpbm') { |
|
| 1772 | + $format_sortie = 'jpg'; |
|
| 1773 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1774 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1775 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1776 | + $gd_formats = formats_image_acceptables(true); |
|
| 1777 | + if ( |
|
| 1778 | + is_array($image) |
|
| 1779 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1780 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1781 | + ) |
|
| 1782 | + ) { |
|
| 1783 | + if ($image['format_source'] == 'jpg') { |
|
| 1784 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1785 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1786 | + { |
|
| 1787 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1788 | + } |
|
| 1789 | + // Choisir le format destination |
|
| 1790 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1791 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1792 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1793 | + # pas *ecrire* |
|
| 1794 | + $format_sortie = ''; |
|
| 1795 | + foreach ($formats_sortie as $fmt) { |
|
| 1796 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1797 | + $format_sortie = $fmt; |
|
| 1798 | + break; |
|
| 1799 | + } |
|
| 1800 | + } |
|
| 1801 | + $image = false; |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + |
|
| 1805 | + if (!is_array($image)) { |
|
| 1806 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1810 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1811 | + // on peut resizer en mode html si on dispose des elements |
|
| 1812 | + if ( |
|
| 1813 | + $srcw = extraire_attribut($img, 'width') |
|
| 1814 | + and $srch = extraire_attribut($img, 'height') |
|
| 1815 | + ) { |
|
| 1816 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1817 | + |
|
| 1818 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1819 | + } |
|
| 1820 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1821 | + // sous la forme style='max-width: NNpx;' |
|
| 1822 | + return inserer_attribut( |
|
| 1823 | + $img, |
|
| 1824 | + 'style', |
|
| 1825 | + "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1826 | + ); |
|
| 1827 | + } |
|
| 1828 | + |
|
| 1829 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1830 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1831 | + if ($image['creer']) { |
|
| 1832 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1836 | + } |
|
| 1837 | + |
|
| 1838 | + if ($image['creer'] == false && !$force) { |
|
| 1839 | + return _image_ecrire_tag( |
|
| 1840 | + $image, |
|
| 1841 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1842 | + ); |
|
| 1843 | + } |
|
| 1844 | + |
|
| 1845 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1846 | + $destWidth = $image['largeur_dest']; |
|
| 1847 | + $destHeight = $image['hauteur_dest']; |
|
| 1848 | + $logo = $image['fichier']; |
|
| 1849 | + $date = $image['date_src']; |
|
| 1850 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1851 | + |
|
| 1852 | + if ($preview && $preview['fichier']) { |
|
| 1853 | + $logo = $preview['fichier']; |
|
| 1854 | + $destWidth = $preview['width']; |
|
| 1855 | + $destHeight = $preview['height']; |
|
| 1856 | + $date = $preview['date']; |
|
| 1857 | + } |
|
| 1858 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1859 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1860 | + // quand on fait supprimer/reuploader un logo |
|
| 1861 | + // (pas de filemtime si SAFE MODE) |
|
| 1862 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1863 | + |
|
| 1864 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1865 | + } |
|
| 1866 | + else { |
|
| 1867 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1868 | + return $img; |
|
| 1869 | + } |
|
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | 1872 | /** |
@@ -1880,145 +1880,145 @@ discard block |
||
| 1880 | 1880 | * Class phpthumb_functions |
| 1881 | 1881 | */ |
| 1882 | 1882 | class phpthumb_functions { |
| 1883 | - /** |
|
| 1884 | - * Retourne la couleur d'un pixel dans une image |
|
| 1885 | - * |
|
| 1886 | - * @param resource|GdImage $img |
|
| 1887 | - * @param int $x |
|
| 1888 | - * @param int $y |
|
| 1889 | - * @return array|bool |
|
| 1890 | - */ |
|
| 1891 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1892 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1893 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1894 | - } |
|
| 1895 | - return false; |
|
| 1896 | - } |
|
| 1897 | - |
|
| 1898 | - /** |
|
| 1899 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1900 | - * |
|
| 1901 | - * @param int $number |
|
| 1902 | - * @param int $minbytes |
|
| 1903 | - * @return string |
|
| 1904 | - */ |
|
| 1905 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1906 | - $intstring = ''; |
|
| 1907 | - while ($number > 0) { |
|
| 1908 | - $intstring = $intstring . chr($number & 255); |
|
| 1909 | - $number >>= 8; |
|
| 1910 | - } |
|
| 1911 | - |
|
| 1912 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - /** |
|
| 1916 | - * Transforme une ressource GD en image au format ICO |
|
| 1917 | - * |
|
| 1918 | - * @param array $gd_image_array |
|
| 1919 | - * Tableau de ressources d'images GD |
|
| 1920 | - * @return string |
|
| 1921 | - * Image au format ICO |
|
| 1922 | - */ |
|
| 1923 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1924 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1925 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1926 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1927 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1928 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1929 | - |
|
| 1930 | - $icXOR[$key] = ''; |
|
| 1931 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1932 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1933 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1934 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1935 | - $r = $argb['red']; |
|
| 1936 | - $g = $argb['green']; |
|
| 1937 | - $b = $argb['blue']; |
|
| 1938 | - |
|
| 1939 | - if ($bpp[$key] == 32) { |
|
| 1940 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1941 | - } elseif ($bpp[$key] == 24) { |
|
| 1942 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1943 | - } |
|
| 1944 | - |
|
| 1945 | - if ($a < 128) { |
|
| 1946 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1947 | - } else { |
|
| 1948 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - // mask bits are 32-bit aligned per scanline |
|
| 1952 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1953 | - $icANDmask[$key][$y] .= '0'; |
|
| 1954 | - } |
|
| 1955 | - } |
|
| 1956 | - $icAND[$key] = ''; |
|
| 1957 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1958 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1959 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1960 | - } |
|
| 1961 | - } |
|
| 1962 | - } |
|
| 1963 | - |
|
| 1964 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1965 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1966 | - |
|
| 1967 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1968 | - $BitmapInfoHeader[$key] = ''; |
|
| 1969 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1970 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1971 | - // The biHeight member specifies the combined |
|
| 1972 | - // height of the XOR and AND masks. |
|
| 1973 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1974 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1975 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1976 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1977 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1978 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1979 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1980 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1981 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - |
|
| 1985 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1986 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1987 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1988 | - |
|
| 1989 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1990 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1991 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1992 | - |
|
| 1993 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1994 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1995 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1996 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1997 | - |
|
| 1998 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1999 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 2000 | - |
|
| 2001 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 2002 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2003 | - $dwBytesInRes, |
|
| 2004 | - 4 |
|
| 2005 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2006 | - |
|
| 2007 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2008 | - $dwImageOffset, |
|
| 2009 | - 4 |
|
| 2010 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 2011 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2012 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 2013 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 2014 | - } |
|
| 2015 | - |
|
| 2016 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 2017 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 2018 | - $icondata .= $icXOR[$key]; |
|
| 2019 | - $icondata .= $icAND[$key]; |
|
| 2020 | - } |
|
| 2021 | - |
|
| 2022 | - return $icondata; |
|
| 2023 | - } |
|
| 1883 | + /** |
|
| 1884 | + * Retourne la couleur d'un pixel dans une image |
|
| 1885 | + * |
|
| 1886 | + * @param resource|GdImage $img |
|
| 1887 | + * @param int $x |
|
| 1888 | + * @param int $y |
|
| 1889 | + * @return array|bool |
|
| 1890 | + */ |
|
| 1891 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1892 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1893 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1894 | + } |
|
| 1895 | + return false; |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + /** |
|
| 1899 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1900 | + * |
|
| 1901 | + * @param int $number |
|
| 1902 | + * @param int $minbytes |
|
| 1903 | + * @return string |
|
| 1904 | + */ |
|
| 1905 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1906 | + $intstring = ''; |
|
| 1907 | + while ($number > 0) { |
|
| 1908 | + $intstring = $intstring . chr($number & 255); |
|
| 1909 | + $number >>= 8; |
|
| 1910 | + } |
|
| 1911 | + |
|
| 1912 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + /** |
|
| 1916 | + * Transforme une ressource GD en image au format ICO |
|
| 1917 | + * |
|
| 1918 | + * @param array $gd_image_array |
|
| 1919 | + * Tableau de ressources d'images GD |
|
| 1920 | + * @return string |
|
| 1921 | + * Image au format ICO |
|
| 1922 | + */ |
|
| 1923 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1924 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1925 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1926 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1927 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1928 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1929 | + |
|
| 1930 | + $icXOR[$key] = ''; |
|
| 1931 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1932 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1933 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1934 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1935 | + $r = $argb['red']; |
|
| 1936 | + $g = $argb['green']; |
|
| 1937 | + $b = $argb['blue']; |
|
| 1938 | + |
|
| 1939 | + if ($bpp[$key] == 32) { |
|
| 1940 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1941 | + } elseif ($bpp[$key] == 24) { |
|
| 1942 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1943 | + } |
|
| 1944 | + |
|
| 1945 | + if ($a < 128) { |
|
| 1946 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1947 | + } else { |
|
| 1948 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + // mask bits are 32-bit aligned per scanline |
|
| 1952 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1953 | + $icANDmask[$key][$y] .= '0'; |
|
| 1954 | + } |
|
| 1955 | + } |
|
| 1956 | + $icAND[$key] = ''; |
|
| 1957 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1958 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1959 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1960 | + } |
|
| 1961 | + } |
|
| 1962 | + } |
|
| 1963 | + |
|
| 1964 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1965 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1966 | + |
|
| 1967 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1968 | + $BitmapInfoHeader[$key] = ''; |
|
| 1969 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1970 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1971 | + // The biHeight member specifies the combined |
|
| 1972 | + // height of the XOR and AND masks. |
|
| 1973 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1974 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1975 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1976 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1977 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1978 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1979 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1980 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1981 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + |
|
| 1985 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1986 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1987 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1988 | + |
|
| 1989 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1990 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1991 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1992 | + |
|
| 1993 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1994 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1995 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1996 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1997 | + |
|
| 1998 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1999 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 2000 | + |
|
| 2001 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 2002 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2003 | + $dwBytesInRes, |
|
| 2004 | + 4 |
|
| 2005 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2006 | + |
|
| 2007 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2008 | + $dwImageOffset, |
|
| 2009 | + 4 |
|
| 2010 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 2011 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2012 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 2013 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 2014 | + } |
|
| 2015 | + |
|
| 2016 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 2017 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 2018 | + $icondata .= $icXOR[$key]; |
|
| 2019 | + $icondata .= $icAND[$key]; |
|
| 2020 | + } |
|
| 2021 | + |
|
| 2022 | + return $icondata; |
|
| 2023 | + } |
|
| 2024 | 2024 | } |
@@ -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 | |
@@ -48,71 +48,71 @@ discard block |
||
| 48 | 48 | * Nom de la fonction, ou false. |
| 49 | 49 | */ |
| 50 | 50 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 51 | - static $echecs = []; |
|
| 52 | - |
|
| 53 | - if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | - $dossier .= '/'; |
|
| 55 | - } |
|
| 56 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | - |
|
| 58 | - if (function_exists($f)) { |
|
| 59 | - return $f; |
|
| 60 | - } |
|
| 61 | - if (function_exists($g = $f . '_dist')) { |
|
| 62 | - return $g; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - if (isset($echecs[$f])) { |
|
| 66 | - return $echecs[$f]; |
|
| 67 | - } |
|
| 68 | - // Sinon charger le fichier de declaration si plausible |
|
| 69 | - |
|
| 70 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | - if ($continue) { |
|
| 72 | - return false; |
|
| 73 | - } //appel interne, on passe |
|
| 74 | - include_spip('inc/minipres'); |
|
| 75 | - echo minipres(); |
|
| 76 | - exit; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // passer en minuscules (cf les balises de formulaires) |
|
| 80 | - // et inclure le fichier |
|
| 81 | - if ( |
|
| 82 | - !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 83 | - // si le fichier truc/machin/nom.php n'existe pas, |
|
| 84 | - // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 85 | - and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 86 | - ) { |
|
| 87 | - include_spip(substr($dossier, 0, -1)); |
|
| 88 | - } |
|
| 89 | - if (function_exists($f)) { |
|
| 90 | - return $f; |
|
| 91 | - } |
|
| 92 | - if (function_exists($g)) { |
|
| 93 | - return $g; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if ($continue) { |
|
| 97 | - return $echecs[$f] = false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Echec : message d'erreur |
|
| 101 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 102 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 103 | - |
|
| 104 | - include_spip('inc/minipres'); |
|
| 105 | - echo minipres( |
|
| 106 | - _T('forum_titre_erreur'), |
|
| 107 | - $inc ? |
|
| 108 | - _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 109 | - . '<br />' |
|
| 110 | - . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 111 | - : |
|
| 112 | - _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 113 | - ['all_inline' => true,'status' => 404] |
|
| 114 | - ); |
|
| 115 | - exit; |
|
| 51 | + static $echecs = []; |
|
| 52 | + |
|
| 53 | + if (strlen($dossier) and substr($dossier, -1) != '/') { |
|
| 54 | + $dossier .= '/'; |
|
| 55 | + } |
|
| 56 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 57 | + |
|
| 58 | + if (function_exists($f)) { |
|
| 59 | + return $f; |
|
| 60 | + } |
|
| 61 | + if (function_exists($g = $f . '_dist')) { |
|
| 62 | + return $g; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + if (isset($echecs[$f])) { |
|
| 66 | + return $echecs[$f]; |
|
| 67 | + } |
|
| 68 | + // Sinon charger le fichier de declaration si plausible |
|
| 69 | + |
|
| 70 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 71 | + if ($continue) { |
|
| 72 | + return false; |
|
| 73 | + } //appel interne, on passe |
|
| 74 | + include_spip('inc/minipres'); |
|
| 75 | + echo minipres(); |
|
| 76 | + exit; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // passer en minuscules (cf les balises de formulaires) |
|
| 80 | + // et inclure le fichier |
|
| 81 | + if ( |
|
| 82 | + !$inc = include_spip($dossier . ($d = strtolower($nom))) |
|
| 83 | + // si le fichier truc/machin/nom.php n'existe pas, |
|
| 84 | + // la fonction peut etre definie dans truc/machin.php qui regroupe plusieurs petites fonctions |
|
| 85 | + and strlen(dirname($dossier)) and dirname($dossier) != '.' |
|
| 86 | + ) { |
|
| 87 | + include_spip(substr($dossier, 0, -1)); |
|
| 88 | + } |
|
| 89 | + if (function_exists($f)) { |
|
| 90 | + return $f; |
|
| 91 | + } |
|
| 92 | + if (function_exists($g)) { |
|
| 93 | + return $g; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if ($continue) { |
|
| 97 | + return $echecs[$f] = false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Echec : message d'erreur |
|
| 101 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 102 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 103 | + |
|
| 104 | + include_spip('inc/minipres'); |
|
| 105 | + echo minipres( |
|
| 106 | + _T('forum_titre_erreur'), |
|
| 107 | + $inc ? |
|
| 108 | + _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 109 | + . '<br />' |
|
| 110 | + . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 111 | + : |
|
| 112 | + _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 113 | + ['all_inline' => true,'status' => 404] |
|
| 114 | + ); |
|
| 115 | + exit; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | /** |
@@ -122,17 +122,17 @@ discard block |
||
| 122 | 122 | * @return bool |
| 123 | 123 | */ |
| 124 | 124 | function include_once_check($file) { |
| 125 | - if (file_exists($file)) { |
|
| 126 | - include_once $file; |
|
| 125 | + if (file_exists($file)) { |
|
| 126 | + include_once $file; |
|
| 127 | 127 | |
| 128 | - return true; |
|
| 129 | - } |
|
| 130 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 131 | - $crash = ($crash ?: []); |
|
| 132 | - $crash[$file] = true; |
|
| 133 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 128 | + return true; |
|
| 129 | + } |
|
| 130 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 131 | + $crash = ($crash ?: []); |
|
| 132 | + $crash[$file] = true; |
|
| 133 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 134 | 134 | |
| 135 | - return false; |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | * - string : chemin du fichier trouvé |
| 157 | 157 | **/ |
| 158 | 158 | function include_spip($f, $include = true) { |
| 159 | - return find_in_path($f . '.php', '', $include); |
|
| 159 | + return find_in_path($f . '.php', '', $include); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | * - string : chemin du fichier trouvé |
| 177 | 177 | **/ |
| 178 | 178 | function require_spip($f) { |
| 179 | - return find_in_path($f . '.php', '', 'required'); |
|
| 179 | + return find_in_path($f . '.php', '', 'required'); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | |
@@ -185,27 +185,27 @@ discard block |
||
| 185 | 185 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 186 | 186 | */ |
| 187 | 187 | function include_fichiers_fonctions() { |
| 188 | - static $done = false; |
|
| 189 | - if (!$done) { |
|
| 190 | - include_spip('inc/lang'); |
|
| 191 | - |
|
| 192 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 193 | - // donc il faut l'inclure "en globals" |
|
| 194 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 195 | - global $dossier_squelettes; |
|
| 196 | - include_once(_ROOT_CWD . $f); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 200 | - // chargement optimise precompile |
|
| 201 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 202 | - } |
|
| 203 | - if (test_espace_prive()) { |
|
| 204 | - include_spip('inc/filtres_ecrire'); |
|
| 205 | - } |
|
| 206 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 207 | - $done = true; |
|
| 208 | - } |
|
| 188 | + static $done = false; |
|
| 189 | + if (!$done) { |
|
| 190 | + include_spip('inc/lang'); |
|
| 191 | + |
|
| 192 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 193 | + // donc il faut l'inclure "en globals" |
|
| 194 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 195 | + global $dossier_squelettes; |
|
| 196 | + include_once(_ROOT_CWD . $f); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 200 | + // chargement optimise precompile |
|
| 201 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 202 | + } |
|
| 203 | + if (test_espace_prive()) { |
|
| 204 | + include_spip('inc/filtres_ecrire'); |
|
| 205 | + } |
|
| 206 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 207 | + $done = true; |
|
| 208 | + } |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -231,23 +231,23 @@ discard block |
||
| 231 | 231 | * Les paramètres du pipeline modifiés |
| 232 | 232 | **/ |
| 233 | 233 | function minipipe($fonc, &$val) { |
| 234 | - // fonction |
|
| 235 | - if (function_exists($fonc)) { |
|
| 236 | - $val = $fonc($val); |
|
| 237 | - } // Class::Methode |
|
| 238 | - else { |
|
| 239 | - if ( |
|
| 240 | - preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 241 | - and $methode = [$regs[1], $regs[2]] |
|
| 242 | - and is_callable($methode) |
|
| 243 | - ) { |
|
| 244 | - $val = $methode($val); |
|
| 245 | - } else { |
|
| 246 | - spip_log("Erreur - '$fonc' non definie !"); |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - return $val; |
|
| 234 | + // fonction |
|
| 235 | + if (function_exists($fonc)) { |
|
| 236 | + $val = $fonc($val); |
|
| 237 | + } // Class::Methode |
|
| 238 | + else { |
|
| 239 | + if ( |
|
| 240 | + preg_match('/^(\w*)::(\w*)$/S', $fonc, $regs) |
|
| 241 | + and $methode = [$regs[1], $regs[2]] |
|
| 242 | + and is_callable($methode) |
|
| 243 | + ) { |
|
| 244 | + $val = $methode($val); |
|
| 245 | + } else { |
|
| 246 | + spip_log("Erreur - '$fonc' non definie !"); |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + return $val; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | /** |
@@ -278,46 +278,46 @@ discard block |
||
| 278 | 278 | * Résultat |
| 279 | 279 | */ |
| 280 | 280 | function pipeline($action, $val = null) { |
| 281 | - static $charger; |
|
| 282 | - |
|
| 283 | - // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 284 | - if (!$charger) { |
|
| 285 | - if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 286 | - include_spip('inc/plugin'); |
|
| 287 | - // generer les fichiers php precompiles |
|
| 288 | - // de chargement des plugins et des pipelines |
|
| 289 | - actualise_plugins_actifs(); |
|
| 290 | - if (!($ok = @is_readable($charger))) { |
|
| 291 | - spip_log("fichier $charger pas cree"); |
|
| 292 | - } |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - if ($ok) { |
|
| 296 | - include_once $charger; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - // appliquer notre fonction si elle existe |
|
| 301 | - $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 302 | - if (function_exists($fonc)) { |
|
| 303 | - $val = $fonc($val); |
|
| 304 | - } // plantage ? |
|
| 305 | - else { |
|
| 306 | - spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // si le flux est une table avec 2 cle args&data |
|
| 310 | - // on ne ressort du pipe que les donnees dans 'data' |
|
| 311 | - // array_key_exists pour php 4.1.0 |
|
| 312 | - if ( |
|
| 313 | - is_array($val) |
|
| 314 | - and count($val) == 2 |
|
| 315 | - and (array_key_exists('data', $val)) |
|
| 316 | - ) { |
|
| 317 | - $val = $val['data']; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - return $val; |
|
| 281 | + static $charger; |
|
| 282 | + |
|
| 283 | + // chargement initial des fonctions mises en cache, ou generation du cache |
|
| 284 | + if (!$charger) { |
|
| 285 | + if (!($ok = @is_readable($charger = _CACHE_PIPELINES))) { |
|
| 286 | + include_spip('inc/plugin'); |
|
| 287 | + // generer les fichiers php precompiles |
|
| 288 | + // de chargement des plugins et des pipelines |
|
| 289 | + actualise_plugins_actifs(); |
|
| 290 | + if (!($ok = @is_readable($charger))) { |
|
| 291 | + spip_log("fichier $charger pas cree"); |
|
| 292 | + } |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + if ($ok) { |
|
| 296 | + include_once $charger; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + // appliquer notre fonction si elle existe |
|
| 301 | + $fonc = 'execute_pipeline_' . strtolower($action); |
|
| 302 | + if (function_exists($fonc)) { |
|
| 303 | + $val = $fonc($val); |
|
| 304 | + } // plantage ? |
|
| 305 | + else { |
|
| 306 | + spip_log("fonction $fonc absente : pipeline desactive", _LOG_ERREUR); |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // si le flux est une table avec 2 cle args&data |
|
| 310 | + // on ne ressort du pipe que les donnees dans 'data' |
|
| 311 | + // array_key_exists pour php 4.1.0 |
|
| 312 | + if ( |
|
| 313 | + is_array($val) |
|
| 314 | + and count($val) == 2 |
|
| 315 | + and (array_key_exists('data', $val)) |
|
| 316 | + ) { |
|
| 317 | + $val = $val['data']; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + return $val; |
|
| 321 | 321 | } |
| 322 | 322 | |
| 323 | 323 | /** |
@@ -361,38 +361,38 @@ discard block |
||
| 361 | 361 | * paramètre est planté pour cause de compatibilité ascendante. |
| 362 | 362 | */ |
| 363 | 363 | function spip_log($message = null, $name = null) { |
| 364 | - static $pre = []; |
|
| 365 | - static $log; |
|
| 366 | - preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 367 | - if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 368 | - $logname = null; |
|
| 369 | - } |
|
| 370 | - if (!isset($regs[2])) { |
|
| 371 | - $niveau = _LOG_INFO; |
|
| 372 | - } |
|
| 373 | - else { |
|
| 374 | - $niveau = intval($regs[2]); |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 378 | - if (!$pre) { |
|
| 379 | - $pre = [ |
|
| 380 | - _LOG_HS => 'HS:', |
|
| 381 | - _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 382 | - _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 383 | - _LOG_ERREUR => 'ERREUR:', |
|
| 384 | - _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 385 | - _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 386 | - _LOG_INFO => 'info:', |
|
| 387 | - _LOG_DEBUG => 'debug:' |
|
| 388 | - ]; |
|
| 389 | - $log = charger_fonction('log', 'inc'); |
|
| 390 | - } |
|
| 391 | - if (!is_string($message)) { |
|
| 392 | - $message = print_r($message, true); |
|
| 393 | - } |
|
| 394 | - $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 395 | - } |
|
| 364 | + static $pre = []; |
|
| 365 | + static $log; |
|
| 366 | + preg_match('/^([a-z_]*)\.?(\d)?$/iS', (string)$name, $regs); |
|
| 367 | + if (!isset($regs[1]) or !$logname = $regs[1]) { |
|
| 368 | + $logname = null; |
|
| 369 | + } |
|
| 370 | + if (!isset($regs[2])) { |
|
| 371 | + $niveau = _LOG_INFO; |
|
| 372 | + } |
|
| 373 | + else { |
|
| 374 | + $niveau = intval($regs[2]); |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + if ($niveau <= (defined('_LOG_FILTRE_GRAVITE') ? _LOG_FILTRE_GRAVITE : _LOG_INFO_IMPORTANTE)) { |
|
| 378 | + if (!$pre) { |
|
| 379 | + $pre = [ |
|
| 380 | + _LOG_HS => 'HS:', |
|
| 381 | + _LOG_ALERTE_ROUGE => 'ALERTE:', |
|
| 382 | + _LOG_CRITIQUE => 'CRITIQUE:', |
|
| 383 | + _LOG_ERREUR => 'ERREUR:', |
|
| 384 | + _LOG_AVERTISSEMENT => 'WARNING:', |
|
| 385 | + _LOG_INFO_IMPORTANTE => '!INFO:', |
|
| 386 | + _LOG_INFO => 'info:', |
|
| 387 | + _LOG_DEBUG => 'debug:' |
|
| 388 | + ]; |
|
| 389 | + $log = charger_fonction('log', 'inc'); |
|
| 390 | + } |
|
| 391 | + if (!is_string($message)) { |
|
| 392 | + $message = print_r($message, true); |
|
| 393 | + } |
|
| 394 | + $log($pre[$niveau] . ' ' . $message, $logname); |
|
| 395 | + } |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -403,8 +403,8 @@ discard block |
||
| 403 | 403 | * @param array $opt Tableau d'options |
| 404 | 404 | **/ |
| 405 | 405 | function journal($phrase, $opt = []) { |
| 406 | - $journal = charger_fonction('journal', 'inc'); |
|
| 407 | - $journal($phrase, $opt); |
|
| 406 | + $journal = charger_fonction('journal', 'inc'); |
|
| 407 | + $journal($phrase, $opt); |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | |
@@ -423,37 +423,37 @@ discard block |
||
| 423 | 423 | **/ |
| 424 | 424 | function _request($var, $c = false) { |
| 425 | 425 | |
| 426 | - if (is_array($c)) { |
|
| 427 | - return $c[$var] ?? null; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if (isset($_GET[$var])) { |
|
| 431 | - $a = $_GET[$var]; |
|
| 432 | - } elseif (isset($_POST[$var])) { |
|
| 433 | - $a = $_POST[$var]; |
|
| 434 | - } else { |
|
| 435 | - return null; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - // Si on est en ajax et en POST tout a ete encode |
|
| 439 | - // via encodeURIComponent, il faut donc repasser |
|
| 440 | - // dans le charset local... |
|
| 441 | - if ( |
|
| 442 | - defined('_AJAX') |
|
| 443 | - and _AJAX |
|
| 444 | - and isset($GLOBALS['meta']['charset']) |
|
| 445 | - and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 446 | - and is_string($a) |
|
| 447 | - // check rapide mais pas fiable |
|
| 448 | - and preg_match(',[\x80-\xFF],', $a) |
|
| 449 | - // check fiable |
|
| 450 | - and include_spip('inc/charsets') |
|
| 451 | - and is_utf8($a) |
|
| 452 | - ) { |
|
| 453 | - return importer_charset($a, 'utf-8'); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - return $a; |
|
| 426 | + if (is_array($c)) { |
|
| 427 | + return $c[$var] ?? null; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if (isset($_GET[$var])) { |
|
| 431 | + $a = $_GET[$var]; |
|
| 432 | + } elseif (isset($_POST[$var])) { |
|
| 433 | + $a = $_POST[$var]; |
|
| 434 | + } else { |
|
| 435 | + return null; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + // Si on est en ajax et en POST tout a ete encode |
|
| 439 | + // via encodeURIComponent, il faut donc repasser |
|
| 440 | + // dans le charset local... |
|
| 441 | + if ( |
|
| 442 | + defined('_AJAX') |
|
| 443 | + and _AJAX |
|
| 444 | + and isset($GLOBALS['meta']['charset']) |
|
| 445 | + and $GLOBALS['meta']['charset'] != 'utf-8' |
|
| 446 | + and is_string($a) |
|
| 447 | + // check rapide mais pas fiable |
|
| 448 | + and preg_match(',[\x80-\xFF],', $a) |
|
| 449 | + // check fiable |
|
| 450 | + and include_spip('inc/charsets') |
|
| 451 | + and is_utf8($a) |
|
| 452 | + ) { |
|
| 453 | + return importer_charset($a, 'utf-8'); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + return $a; |
|
| 457 | 457 | } |
| 458 | 458 | |
| 459 | 459 | |
@@ -471,22 +471,22 @@ discard block |
||
| 471 | 471 | * - false sinon |
| 472 | 472 | **/ |
| 473 | 473 | function set_request($var, $val = null, $c = false) { |
| 474 | - if (is_array($c)) { |
|
| 475 | - unset($c[$var]); |
|
| 476 | - if ($val !== null) { |
|
| 477 | - $c[$var] = $val; |
|
| 478 | - } |
|
| 474 | + if (is_array($c)) { |
|
| 475 | + unset($c[$var]); |
|
| 476 | + if ($val !== null) { |
|
| 477 | + $c[$var] = $val; |
|
| 478 | + } |
|
| 479 | 479 | |
| 480 | - return $c; |
|
| 481 | - } |
|
| 480 | + return $c; |
|
| 481 | + } |
|
| 482 | 482 | |
| 483 | - unset($_GET[$var]); |
|
| 484 | - unset($_POST[$var]); |
|
| 485 | - if ($val !== null) { |
|
| 486 | - $_GET[$var] = $val; |
|
| 487 | - } |
|
| 483 | + unset($_GET[$var]); |
|
| 484 | + unset($_POST[$var]); |
|
| 485 | + if ($val !== null) { |
|
| 486 | + $_GET[$var] = $val; |
|
| 487 | + } |
|
| 488 | 488 | |
| 489 | - return false; # n'affecte pas $c |
|
| 489 | + return false; # n'affecte pas $c |
|
| 490 | 490 | } |
| 491 | 491 | |
| 492 | 492 | /** |
@@ -506,25 +506,25 @@ discard block |
||
| 506 | 506 | * @return array|mixed|string |
| 507 | 507 | */ |
| 508 | 508 | function spip_sanitize_from_request($value, $key, $sanitize_function = 'entites_html') { |
| 509 | - if (is_array($value)) { |
|
| 510 | - if ($key == '*') { |
|
| 511 | - $key = array_keys($value); |
|
| 512 | - } |
|
| 513 | - if (!is_array($key)) { |
|
| 514 | - $key = [$key]; |
|
| 515 | - } |
|
| 516 | - foreach ($key as $k) { |
|
| 517 | - if (!empty($value[$k])) { |
|
| 518 | - $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - return $value; |
|
| 522 | - } |
|
| 523 | - // si la valeur vient des GET ou POST on la sanitize |
|
| 524 | - if (!empty($value) and $value == _request($key)) { |
|
| 525 | - $value = $sanitize_function($value); |
|
| 526 | - } |
|
| 527 | - return $value; |
|
| 509 | + if (is_array($value)) { |
|
| 510 | + if ($key == '*') { |
|
| 511 | + $key = array_keys($value); |
|
| 512 | + } |
|
| 513 | + if (!is_array($key)) { |
|
| 514 | + $key = [$key]; |
|
| 515 | + } |
|
| 516 | + foreach ($key as $k) { |
|
| 517 | + if (!empty($value[$k])) { |
|
| 518 | + $value[$k] = spip_sanitize_from_request($value[$k], $k, $sanitize_function); |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + return $value; |
|
| 522 | + } |
|
| 523 | + // si la valeur vient des GET ou POST on la sanitize |
|
| 524 | + if (!empty($value) and $value == _request($key)) { |
|
| 525 | + $value = $sanitize_function($value); |
|
| 526 | + } |
|
| 527 | + return $value; |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -532,23 +532,22 @@ discard block |
||
| 532 | 532 | * |
| 533 | 533 | * On est sur le web, on exclut certains protocoles, |
| 534 | 534 | * notamment 'file://', 'php://' et d'autres… |
| 535 | - |
|
| 536 | 535 | * @param string $url |
| 537 | 536 | * @return bool |
| 538 | 537 | */ |
| 539 | 538 | function tester_url_absolue($url) { |
| 540 | - $url = trim($url ?? ''); |
|
| 541 | - if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 542 | - if ( |
|
| 543 | - isset($m[1]) |
|
| 544 | - and $p = strtolower(rtrim($m[1], ':')) |
|
| 545 | - and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 546 | - ) { |
|
| 547 | - return false; |
|
| 548 | - } |
|
| 549 | - return true; |
|
| 550 | - } |
|
| 551 | - return false; |
|
| 539 | + $url = trim($url ?? ''); |
|
| 540 | + if ($url && preg_match(';^([a-z]{3,7}:)?//;Uims', $url, $m)) { |
|
| 541 | + if ( |
|
| 542 | + isset($m[1]) |
|
| 543 | + and $p = strtolower(rtrim($m[1], ':')) |
|
| 544 | + and in_array($p, ['file', 'php', 'zlib', 'glob', 'phar', 'ssh2', 'rar', 'ogg', 'expect', 'zip']) |
|
| 545 | + ) { |
|
| 546 | + return false; |
|
| 547 | + } |
|
| 548 | + return true; |
|
| 549 | + } |
|
| 550 | + return false; |
|
| 552 | 551 | } |
| 553 | 552 | |
| 554 | 553 | /** |
@@ -570,95 +569,95 @@ discard block |
||
| 570 | 569 | * @return string URL |
| 571 | 570 | */ |
| 572 | 571 | function parametre_url($url, $c, $v = null, $sep = '&') { |
| 573 | - // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 574 | - if (strpos($c, '|') !== false and is_null($v)) { |
|
| 575 | - return null; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - // lever l'#ancre |
|
| 579 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 580 | - $url = $r[1]; |
|
| 581 | - $ancre = $r[2]; |
|
| 582 | - } else { |
|
| 583 | - $ancre = ''; |
|
| 584 | - } |
|
| 585 | - |
|
| 586 | - // eclater |
|
| 587 | - $url = preg_split(',[?]|&|&,', $url); |
|
| 588 | - |
|
| 589 | - // recuperer la base |
|
| 590 | - $a = array_shift($url); |
|
| 591 | - if (!$a) { |
|
| 592 | - $a = './'; |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 596 | - $ajouts = array_flip(explode('|', $c)); |
|
| 597 | - $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 598 | - $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 599 | - $v_read = null; |
|
| 600 | - // lire les variables et agir |
|
| 601 | - foreach ($url as $n => $val) { |
|
| 602 | - if (preg_match($regexp, urldecode($val), $r)) { |
|
| 603 | - $r = array_pad($r, 3, null); |
|
| 604 | - if ($v === null) { |
|
| 605 | - // c'est un tableau, on memorise les valeurs |
|
| 606 | - if (substr($r[1], -2) == '[]') { |
|
| 607 | - if (!$v_read) { |
|
| 608 | - $v_read = []; |
|
| 609 | - } |
|
| 610 | - $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 611 | - } // c'est un scalaire, on retourne direct |
|
| 612 | - else { |
|
| 613 | - return $r[2] ? substr($r[2], 1) : ''; |
|
| 614 | - } |
|
| 615 | - } // suppression |
|
| 616 | - elseif (!$testv) { |
|
| 617 | - unset($url[$n]); |
|
| 618 | - } |
|
| 619 | - // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 620 | - // pour un tableau ce sera fait dans la prochaine boucle |
|
| 621 | - elseif (substr($r[1], -2) != '[]') { |
|
| 622 | - $url[$n] = $r[1] . '=' . $u; |
|
| 623 | - unset($ajouts[$r[1]]); |
|
| 624 | - } |
|
| 625 | - // Pour les tableaux on laisse tomber les valeurs de |
|
| 626 | - // départ, on remplira à l'étape suivante |
|
| 627 | - else { |
|
| 628 | - unset($url[$n]); |
|
| 629 | - } |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - // traiter les parametres pas encore trouves |
|
| 634 | - if ( |
|
| 635 | - $v === null |
|
| 636 | - and $args = func_get_args() |
|
| 637 | - and count($args) == 2 |
|
| 638 | - ) { |
|
| 639 | - return $v_read; // rien trouve ou un tableau |
|
| 640 | - } elseif ($testv) { |
|
| 641 | - foreach ($ajouts as $k => $n) { |
|
| 642 | - if (!is_array($v)) { |
|
| 643 | - $url[] = $k . '=' . $u; |
|
| 644 | - } else { |
|
| 645 | - $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 646 | - foreach ($v as $w) { |
|
| 647 | - $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - // eliminer les vides |
|
| 654 | - $url = array_filter($url); |
|
| 655 | - |
|
| 656 | - // recomposer l'adresse |
|
| 657 | - if ($url) { |
|
| 658 | - $a .= '?' . join($sep, $url); |
|
| 659 | - } |
|
| 660 | - |
|
| 661 | - return $a . $ancre; |
|
| 572 | + // requete erronnee : plusieurs variable dans $c et aucun $v |
|
| 573 | + if (strpos($c, '|') !== false and is_null($v)) { |
|
| 574 | + return null; |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // lever l'#ancre |
|
| 578 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 579 | + $url = $r[1]; |
|
| 580 | + $ancre = $r[2]; |
|
| 581 | + } else { |
|
| 582 | + $ancre = ''; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + // eclater |
|
| 586 | + $url = preg_split(',[?]|&|&,', $url); |
|
| 587 | + |
|
| 588 | + // recuperer la base |
|
| 589 | + $a = array_shift($url); |
|
| 590 | + if (!$a) { |
|
| 591 | + $a = './'; |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + $regexp = ',^(' . str_replace('[]', '\[\]', $c) . '[[]?[]]?)(=.*)?$,'; |
|
| 595 | + $ajouts = array_flip(explode('|', $c)); |
|
| 596 | + $u = is_array($v) ? $v : rawurlencode((string) $v); |
|
| 597 | + $testv = (is_array($v) ? count($v) : strlen((string) $v)); |
|
| 598 | + $v_read = null; |
|
| 599 | + // lire les variables et agir |
|
| 600 | + foreach ($url as $n => $val) { |
|
| 601 | + if (preg_match($regexp, urldecode($val), $r)) { |
|
| 602 | + $r = array_pad($r, 3, null); |
|
| 603 | + if ($v === null) { |
|
| 604 | + // c'est un tableau, on memorise les valeurs |
|
| 605 | + if (substr($r[1], -2) == '[]') { |
|
| 606 | + if (!$v_read) { |
|
| 607 | + $v_read = []; |
|
| 608 | + } |
|
| 609 | + $v_read[] = $r[2] ? substr($r[2], 1) : ''; |
|
| 610 | + } // c'est un scalaire, on retourne direct |
|
| 611 | + else { |
|
| 612 | + return $r[2] ? substr($r[2], 1) : ''; |
|
| 613 | + } |
|
| 614 | + } // suppression |
|
| 615 | + elseif (!$testv) { |
|
| 616 | + unset($url[$n]); |
|
| 617 | + } |
|
| 618 | + // Ajout. Pour une variable, remplacer au meme endroit, |
|
| 619 | + // pour un tableau ce sera fait dans la prochaine boucle |
|
| 620 | + elseif (substr($r[1], -2) != '[]') { |
|
| 621 | + $url[$n] = $r[1] . '=' . $u; |
|
| 622 | + unset($ajouts[$r[1]]); |
|
| 623 | + } |
|
| 624 | + // Pour les tableaux on laisse tomber les valeurs de |
|
| 625 | + // départ, on remplira à l'étape suivante |
|
| 626 | + else { |
|
| 627 | + unset($url[$n]); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + // traiter les parametres pas encore trouves |
|
| 633 | + if ( |
|
| 634 | + $v === null |
|
| 635 | + and $args = func_get_args() |
|
| 636 | + and count($args) == 2 |
|
| 637 | + ) { |
|
| 638 | + return $v_read; // rien trouve ou un tableau |
|
| 639 | + } elseif ($testv) { |
|
| 640 | + foreach ($ajouts as $k => $n) { |
|
| 641 | + if (!is_array($v)) { |
|
| 642 | + $url[] = $k . '=' . $u; |
|
| 643 | + } else { |
|
| 644 | + $id = (substr($k, -2) == '[]') ? $k : ($k . '[]'); |
|
| 645 | + foreach ($v as $w) { |
|
| 646 | + $url[] = $id . '=' . (is_array($w) ? 'Array' : rawurlencode($w)); |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + // eliminer les vides |
|
| 653 | + $url = array_filter($url); |
|
| 654 | + |
|
| 655 | + // recomposer l'adresse |
|
| 656 | + if ($url) { |
|
| 657 | + $a .= '?' . join($sep, $url); |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + return $a . $ancre; |
|
| 662 | 661 | } |
| 663 | 662 | |
| 664 | 663 | /** |
@@ -676,21 +675,21 @@ discard block |
||
| 676 | 675 | * @return string |
| 677 | 676 | */ |
| 678 | 677 | function ancre_url($url, $ancre) { |
| 679 | - // lever l'#ancre |
|
| 680 | - if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 681 | - $url = $r[1]; |
|
| 682 | - } |
|
| 683 | - if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 684 | - if (!function_exists('translitteration')) { |
|
| 685 | - include_spip('inc/charsets'); |
|
| 686 | - } |
|
| 687 | - $ancre = preg_replace( |
|
| 688 | - ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 689 | - ['', '-'], |
|
| 690 | - translitteration($ancre) |
|
| 691 | - ); |
|
| 692 | - } |
|
| 693 | - return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 678 | + // lever l'#ancre |
|
| 679 | + if (preg_match(',^([^#]*)(#.*)$,', $url, $r)) { |
|
| 680 | + $url = $r[1]; |
|
| 681 | + } |
|
| 682 | + if (preg_match('/[^-_a-zA-Z0-9]+/S', $ancre)) { |
|
| 683 | + if (!function_exists('translitteration')) { |
|
| 684 | + include_spip('inc/charsets'); |
|
| 685 | + } |
|
| 686 | + $ancre = preg_replace( |
|
| 687 | + ['/^[^-_a-zA-Z0-9]+/', '/[^-_a-zA-Z0-9]/'], |
|
| 688 | + ['', '-'], |
|
| 689 | + translitteration($ancre) |
|
| 690 | + ); |
|
| 691 | + } |
|
| 692 | + return $url . (strlen($ancre) ? '#' . $ancre : ''); |
|
| 694 | 693 | } |
| 695 | 694 | |
| 696 | 695 | /** |
@@ -700,16 +699,16 @@ discard block |
||
| 700 | 699 | * @return string |
| 701 | 700 | */ |
| 702 | 701 | function nettoyer_uri($reset = null) { |
| 703 | - static $done = false; |
|
| 704 | - static $propre = ''; |
|
| 705 | - if (!is_null($reset)) { |
|
| 706 | - return $propre = $reset; |
|
| 707 | - } |
|
| 708 | - if ($done) { |
|
| 709 | - return $propre; |
|
| 710 | - } |
|
| 711 | - $done = true; |
|
| 712 | - return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 702 | + static $done = false; |
|
| 703 | + static $propre = ''; |
|
| 704 | + if (!is_null($reset)) { |
|
| 705 | + return $propre = $reset; |
|
| 706 | + } |
|
| 707 | + if ($done) { |
|
| 708 | + return $propre; |
|
| 709 | + } |
|
| 710 | + $done = true; |
|
| 711 | + return $propre = nettoyer_uri_var($GLOBALS['REQUEST_URI']); |
|
| 713 | 712 | } |
| 714 | 713 | |
| 715 | 714 | /** |
@@ -721,16 +720,16 @@ discard block |
||
| 721 | 720 | * @return string |
| 722 | 721 | */ |
| 723 | 722 | function nettoyer_uri_var($request_uri) { |
| 724 | - $uri1 = $request_uri; |
|
| 725 | - do { |
|
| 726 | - $uri = $uri1; |
|
| 727 | - $uri1 = preg_replace( |
|
| 728 | - ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 729 | - '\1', |
|
| 730 | - $uri |
|
| 731 | - ); |
|
| 732 | - } while ($uri <> $uri1); |
|
| 733 | - return preg_replace(',[?&]$,', '', $uri1); |
|
| 723 | + $uri1 = $request_uri; |
|
| 724 | + do { |
|
| 725 | + $uri = $uri1; |
|
| 726 | + $uri1 = preg_replace( |
|
| 727 | + ',([?&])(var_[^=&]*|PHPSESSID|fbclid|utm_[^=&]*)=[^&]*(&|$),i', |
|
| 728 | + '\1', |
|
| 729 | + $uri |
|
| 730 | + ); |
|
| 731 | + } while ($uri <> $uri1); |
|
| 732 | + return preg_replace(',[?&]$,', '', $uri1); |
|
| 734 | 733 | } |
| 735 | 734 | |
| 736 | 735 | |
@@ -744,48 +743,48 @@ discard block |
||
| 744 | 743 | * URL vers soi-même |
| 745 | 744 | **/ |
| 746 | 745 | function self($amp = '&', $root = false) { |
| 747 | - $url = nettoyer_uri(); |
|
| 748 | - if ( |
|
| 749 | - !$root |
|
| 750 | - and ( |
|
| 751 | - // si pas de profondeur on peut tronquer |
|
| 752 | - $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 753 | - // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 754 | - or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 755 | - ) { |
|
| 756 | - $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 757 | - } |
|
| 758 | - // ajouter le cas echeant les variables _POST['id_...'] |
|
| 759 | - foreach ($_POST as $v => $c) { |
|
| 760 | - if (substr($v, 0, 3) == 'id_') { |
|
| 761 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // supprimer les variables sans interet |
|
| 766 | - if (test_espace_prive()) { |
|
| 767 | - $url = preg_replace(',([?&])(' |
|
| 768 | - . 'lang|show_docs|' |
|
| 769 | - . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 770 | - $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 771 | - $url = preg_replace(',[&]$,', '\1', $url); |
|
| 772 | - } |
|
| 773 | - |
|
| 774 | - // eviter les hacks |
|
| 775 | - include_spip('inc/filtres_mini'); |
|
| 776 | - $url = spip_htmlspecialchars($url); |
|
| 777 | - |
|
| 778 | - $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 779 | - |
|
| 780 | - // & ? |
|
| 781 | - if ($amp != '&') { |
|
| 782 | - $url = str_replace('&', $amp, $url); |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - // Si ca demarre par ? ou vide, donner './' |
|
| 786 | - $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 787 | - |
|
| 788 | - return $url; |
|
| 746 | + $url = nettoyer_uri(); |
|
| 747 | + if ( |
|
| 748 | + !$root |
|
| 749 | + and ( |
|
| 750 | + // si pas de profondeur on peut tronquer |
|
| 751 | + $GLOBALS['profondeur_url'] < (_DIR_RESTREINT ? 1 : 2) |
|
| 752 | + // sinon c'est OK si _SET_HTML_BASE a ete force a false |
|
| 753 | + or (defined('_SET_HTML_BASE') and !_SET_HTML_BASE)) |
|
| 754 | + ) { |
|
| 755 | + $url = preg_replace(',^[^?]*/,', '', $url); |
|
| 756 | + } |
|
| 757 | + // ajouter le cas echeant les variables _POST['id_...'] |
|
| 758 | + foreach ($_POST as $v => $c) { |
|
| 759 | + if (substr($v, 0, 3) == 'id_') { |
|
| 760 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + // supprimer les variables sans interet |
|
| 765 | + if (test_espace_prive()) { |
|
| 766 | + $url = preg_replace(',([?&])(' |
|
| 767 | + . 'lang|show_docs|' |
|
| 768 | + . 'changer_lang|var_lang|action)=[^&]*,i', '\1', $url); |
|
| 769 | + $url = preg_replace(',([?&])[&]+,', '\1', $url); |
|
| 770 | + $url = preg_replace(',[&]$,', '\1', $url); |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // eviter les hacks |
|
| 774 | + include_spip('inc/filtres_mini'); |
|
| 775 | + $url = spip_htmlspecialchars($url); |
|
| 776 | + |
|
| 777 | + $url = str_replace(["'", '"', '<', '[', ']', ':'], ['%27', '%22', '%3C', '%5B', '%5D', '%3A'], $url); |
|
| 778 | + |
|
| 779 | + // & ? |
|
| 780 | + if ($amp != '&') { |
|
| 781 | + $url = str_replace('&', $amp, $url); |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // Si ca demarre par ? ou vide, donner './' |
|
| 785 | + $url = preg_replace(',^([?].*)?$,', './\1', $url); |
|
| 786 | + |
|
| 787 | + return $url; |
|
| 789 | 788 | } |
| 790 | 789 | |
| 791 | 790 | |
@@ -796,7 +795,7 @@ discard block |
||
| 796 | 795 | * true si c'est le cas, false sinon. |
| 797 | 796 | */ |
| 798 | 797 | function test_espace_prive() { |
| 799 | - return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 798 | + return defined('_ESPACE_PRIVE') ? _ESPACE_PRIVE : false; |
|
| 800 | 799 | } |
| 801 | 800 | |
| 802 | 801 | /** |
@@ -806,7 +805,7 @@ discard block |
||
| 806 | 805 | * @return bool |
| 807 | 806 | */ |
| 808 | 807 | function test_plugin_actif($plugin) { |
| 809 | - return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 808 | + return ($plugin and defined('_DIR_PLUGIN_' . strtoupper($plugin))) ? true : false; |
|
| 810 | 809 | } |
| 811 | 810 | |
| 812 | 811 | /** |
@@ -837,52 +836,52 @@ discard block |
||
| 837 | 836 | * Texte |
| 838 | 837 | */ |
| 839 | 838 | function _T($texte, $args = [], $options = []) { |
| 840 | - static $traduire = false; |
|
| 841 | - $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 842 | - if ($options) { |
|
| 843 | - // support de l'ancien argument $class |
|
| 844 | - if (is_string($options)) { |
|
| 845 | - $options = ['class' => $options]; |
|
| 846 | - } |
|
| 847 | - $o = array_merge($o, $options); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - if (!$traduire) { |
|
| 851 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 852 | - include_spip('inc/lang'); |
|
| 853 | - } |
|
| 854 | - |
|
| 855 | - // On peut passer explicitement la langue dans le tableau |
|
| 856 | - // On utilise le même nom de variable que la globale |
|
| 857 | - if (isset($args['spip_lang'])) { |
|
| 858 | - $lang = $args['spip_lang']; |
|
| 859 | - // On l'enleve pour ne pas le passer au remplacement |
|
| 860 | - unset($args['spip_lang']); |
|
| 861 | - } // Sinon on prend la langue du contexte |
|
| 862 | - else { |
|
| 863 | - $lang = $GLOBALS['spip_lang']; |
|
| 864 | - } |
|
| 865 | - $text = $traduire($texte, $lang); |
|
| 866 | - |
|
| 867 | - if ($text === null || !strlen($text)) { |
|
| 868 | - if (!$o['force']) { |
|
| 869 | - return ''; |
|
| 870 | - } |
|
| 871 | - |
|
| 872 | - $text = $texte; |
|
| 873 | - |
|
| 874 | - // pour les chaines non traduites, assurer un service minimum |
|
| 875 | - if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 876 | - $n = strpos($text, ':'); |
|
| 877 | - if ($n !== false) { |
|
| 878 | - $text = substr($text, $n + 1); |
|
| 879 | - } |
|
| 880 | - $text = str_replace('_', ' ', $text); |
|
| 881 | - } |
|
| 882 | - $o['class'] = null; |
|
| 883 | - } |
|
| 884 | - |
|
| 885 | - return _L($text, $args, $o); |
|
| 839 | + static $traduire = false; |
|
| 840 | + $o = ['class' => '', 'force' => true, 'sanitize' => true]; |
|
| 841 | + if ($options) { |
|
| 842 | + // support de l'ancien argument $class |
|
| 843 | + if (is_string($options)) { |
|
| 844 | + $options = ['class' => $options]; |
|
| 845 | + } |
|
| 846 | + $o = array_merge($o, $options); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + if (!$traduire) { |
|
| 850 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 851 | + include_spip('inc/lang'); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // On peut passer explicitement la langue dans le tableau |
|
| 855 | + // On utilise le même nom de variable que la globale |
|
| 856 | + if (isset($args['spip_lang'])) { |
|
| 857 | + $lang = $args['spip_lang']; |
|
| 858 | + // On l'enleve pour ne pas le passer au remplacement |
|
| 859 | + unset($args['spip_lang']); |
|
| 860 | + } // Sinon on prend la langue du contexte |
|
| 861 | + else { |
|
| 862 | + $lang = $GLOBALS['spip_lang']; |
|
| 863 | + } |
|
| 864 | + $text = $traduire($texte, $lang); |
|
| 865 | + |
|
| 866 | + if ($text === null || !strlen($text)) { |
|
| 867 | + if (!$o['force']) { |
|
| 868 | + return ''; |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + $text = $texte; |
|
| 872 | + |
|
| 873 | + // pour les chaines non traduites, assurer un service minimum |
|
| 874 | + if (!$GLOBALS['test_i18n'] and (_request('var_mode') != 'traduction')) { |
|
| 875 | + $n = strpos($text, ':'); |
|
| 876 | + if ($n !== false) { |
|
| 877 | + $text = substr($text, $n + 1); |
|
| 878 | + } |
|
| 879 | + $text = str_replace('_', ' ', $text); |
|
| 880 | + } |
|
| 881 | + $o['class'] = null; |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + return _L($text, $args, $o); |
|
| 886 | 885 | } |
| 887 | 886 | |
| 888 | 887 | |
@@ -909,53 +908,53 @@ discard block |
||
| 909 | 908 | * Texte |
| 910 | 909 | */ |
| 911 | 910 | function _L($text, $args = [], $options = []) { |
| 912 | - $f = $text; |
|
| 913 | - $defaut_options = [ |
|
| 914 | - 'class' => null, |
|
| 915 | - 'sanitize' => true, |
|
| 916 | - ]; |
|
| 917 | - // support de l'ancien argument $class |
|
| 918 | - if ($options and is_string($options)) { |
|
| 919 | - $options = ['class' => $options]; |
|
| 920 | - } |
|
| 921 | - if (is_array($options)) { |
|
| 922 | - $options += $defaut_options; |
|
| 923 | - } else { |
|
| 924 | - $options = $defaut_options; |
|
| 925 | - } |
|
| 926 | - |
|
| 927 | - if (is_array($args) and count($args)) { |
|
| 928 | - if (!function_exists('interdire_scripts')) { |
|
| 929 | - include_spip('inc/texte'); |
|
| 930 | - } |
|
| 931 | - if (!function_exists('echapper_html_suspect')) { |
|
| 932 | - include_spip('inc/texte_mini'); |
|
| 933 | - } |
|
| 934 | - foreach ($args as $name => $value) { |
|
| 935 | - if (strpos($text, (string) "@$name@") !== false) { |
|
| 936 | - if ($options['sanitize']) { |
|
| 937 | - $value = echapper_html_suspect($value); |
|
| 938 | - $value = interdire_scripts($value, -1); |
|
| 939 | - } |
|
| 940 | - if (!empty($options['class'])) { |
|
| 941 | - $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 942 | - } |
|
| 943 | - $text = str_replace("@$name@", $value, $text); |
|
| 944 | - unset($args[$name]); |
|
| 945 | - } |
|
| 946 | - } |
|
| 947 | - // Si des variables n'ont pas ete inserees, le signaler |
|
| 948 | - // (chaines de langues pas a jour) |
|
| 949 | - if ($args) { |
|
| 950 | - spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 951 | - } |
|
| 952 | - } |
|
| 953 | - |
|
| 954 | - if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 955 | - return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 956 | - } else { |
|
| 957 | - return $text; |
|
| 958 | - } |
|
| 911 | + $f = $text; |
|
| 912 | + $defaut_options = [ |
|
| 913 | + 'class' => null, |
|
| 914 | + 'sanitize' => true, |
|
| 915 | + ]; |
|
| 916 | + // support de l'ancien argument $class |
|
| 917 | + if ($options and is_string($options)) { |
|
| 918 | + $options = ['class' => $options]; |
|
| 919 | + } |
|
| 920 | + if (is_array($options)) { |
|
| 921 | + $options += $defaut_options; |
|
| 922 | + } else { |
|
| 923 | + $options = $defaut_options; |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + if (is_array($args) and count($args)) { |
|
| 927 | + if (!function_exists('interdire_scripts')) { |
|
| 928 | + include_spip('inc/texte'); |
|
| 929 | + } |
|
| 930 | + if (!function_exists('echapper_html_suspect')) { |
|
| 931 | + include_spip('inc/texte_mini'); |
|
| 932 | + } |
|
| 933 | + foreach ($args as $name => $value) { |
|
| 934 | + if (strpos($text, (string) "@$name@") !== false) { |
|
| 935 | + if ($options['sanitize']) { |
|
| 936 | + $value = echapper_html_suspect($value); |
|
| 937 | + $value = interdire_scripts($value, -1); |
|
| 938 | + } |
|
| 939 | + if (!empty($options['class'])) { |
|
| 940 | + $value = "<span class='" . $options['class'] . "'>$value</span>"; |
|
| 941 | + } |
|
| 942 | + $text = str_replace("@$name@", $value, $text); |
|
| 943 | + unset($args[$name]); |
|
| 944 | + } |
|
| 945 | + } |
|
| 946 | + // Si des variables n'ont pas ete inserees, le signaler |
|
| 947 | + // (chaines de langues pas a jour) |
|
| 948 | + if ($args) { |
|
| 949 | + spip_log("$f: variables inutilisees " . join(', ', array_keys($args)), _LOG_DEBUG); |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + if (($GLOBALS['test_i18n'] or (_request('var_mode') == 'traduction')) and is_null($options['class'])) { |
|
| 954 | + return "<span class='debug-traduction-erreur'>$text</span>"; |
|
| 955 | + } else { |
|
| 956 | + return $text; |
|
| 957 | + } |
|
| 959 | 958 | } |
| 960 | 959 | |
| 961 | 960 | |
@@ -969,13 +968,13 @@ discard block |
||
| 969 | 968 | * @return string |
| 970 | 969 | */ |
| 971 | 970 | function joli_repertoire($rep) { |
| 972 | - $a = substr($rep, 0, 1); |
|
| 973 | - if ($a <> '.' and $a <> '/') { |
|
| 974 | - $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 975 | - } |
|
| 976 | - $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 971 | + $a = substr($rep, 0, 1); |
|
| 972 | + if ($a <> '.' and $a <> '/') { |
|
| 973 | + $rep = (_DIR_RESTREINT ? '' : _DIR_RESTREINT_ABS) . $rep; |
|
| 974 | + } |
|
| 975 | + $rep = preg_replace(',(^\.\.\/),', '', $rep); |
|
| 977 | 976 | |
| 978 | - return $rep; |
|
| 977 | + return $rep; |
|
| 979 | 978 | } |
| 980 | 979 | |
| 981 | 980 | |
@@ -1000,54 +999,54 @@ discard block |
||
| 1000 | 999 | * @return float|int|string|void |
| 1001 | 1000 | */ |
| 1002 | 1001 | function spip_timer($t = 'rien', $raw = false) { |
| 1003 | - static $time; |
|
| 1004 | - $a = time(); |
|
| 1005 | - $b = microtime(); |
|
| 1006 | - // microtime peut contenir les microsecondes et le temps |
|
| 1007 | - $b = explode(' ', $b); |
|
| 1008 | - if (count($b) == 2) { |
|
| 1009 | - $a = end($b); |
|
| 1010 | - } // plus precis ! |
|
| 1011 | - $b = reset($b); |
|
| 1012 | - if (!isset($time[$t])) { |
|
| 1013 | - $time[$t] = $a + $b; |
|
| 1014 | - } else { |
|
| 1015 | - $p = ($a + $b - $time[$t]) * 1000; |
|
| 1016 | - unset($time[$t]); |
|
| 1002 | + static $time; |
|
| 1003 | + $a = time(); |
|
| 1004 | + $b = microtime(); |
|
| 1005 | + // microtime peut contenir les microsecondes et le temps |
|
| 1006 | + $b = explode(' ', $b); |
|
| 1007 | + if (count($b) == 2) { |
|
| 1008 | + $a = end($b); |
|
| 1009 | + } // plus precis ! |
|
| 1010 | + $b = reset($b); |
|
| 1011 | + if (!isset($time[$t])) { |
|
| 1012 | + $time[$t] = $a + $b; |
|
| 1013 | + } else { |
|
| 1014 | + $p = ($a + $b - $time[$t]) * 1000; |
|
| 1015 | + unset($time[$t]); |
|
| 1017 | 1016 | # echo "'$p'";exit; |
| 1018 | - if ($raw) { |
|
| 1019 | - return $p; |
|
| 1020 | - } |
|
| 1021 | - if ($p < 1000) { |
|
| 1022 | - $s = ''; |
|
| 1023 | - } else { |
|
| 1024 | - $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1025 | - $p -= ($x * 1000); |
|
| 1026 | - } |
|
| 1017 | + if ($raw) { |
|
| 1018 | + return $p; |
|
| 1019 | + } |
|
| 1020 | + if ($p < 1000) { |
|
| 1021 | + $s = ''; |
|
| 1022 | + } else { |
|
| 1023 | + $s = sprintf('%d ', $x = floor($p / 1000)); |
|
| 1024 | + $p -= ($x * 1000); |
|
| 1025 | + } |
|
| 1027 | 1026 | |
| 1028 | - return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1029 | - } |
|
| 1027 | + return $s . sprintf($s ? '%07.3f ms' : '%.3f ms', $p); |
|
| 1028 | + } |
|
| 1030 | 1029 | } |
| 1031 | 1030 | |
| 1032 | 1031 | |
| 1033 | 1032 | // Renvoie False si un fichier n'est pas plus vieux que $duree secondes, |
| 1034 | 1033 | // sinon renvoie True et le date sauf si ca n'est pas souhaite |
| 1035 | 1034 | function spip_touch($fichier, $duree = 0, $touch = true) { |
| 1036 | - if ($duree) { |
|
| 1037 | - clearstatcache(); |
|
| 1038 | - if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1039 | - return false; |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - if ($touch !== false) { |
|
| 1043 | - if (!@touch($fichier)) { |
|
| 1044 | - spip_unlink($fichier); |
|
| 1045 | - @touch($fichier); |
|
| 1046 | - }; |
|
| 1047 | - @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1048 | - } |
|
| 1035 | + if ($duree) { |
|
| 1036 | + clearstatcache(); |
|
| 1037 | + if ((@$f = filemtime($fichier)) and ($f >= time() - $duree)) { |
|
| 1038 | + return false; |
|
| 1039 | + } |
|
| 1040 | + } |
|
| 1041 | + if ($touch !== false) { |
|
| 1042 | + if (!@touch($fichier)) { |
|
| 1043 | + spip_unlink($fichier); |
|
| 1044 | + @touch($fichier); |
|
| 1045 | + }; |
|
| 1046 | + @chmod($fichier, _SPIP_CHMOD & ~0111); |
|
| 1047 | + } |
|
| 1049 | 1048 | |
| 1050 | - return true; |
|
| 1049 | + return true; |
|
| 1051 | 1050 | } |
| 1052 | 1051 | |
| 1053 | 1052 | |
@@ -1058,11 +1057,11 @@ discard block |
||
| 1058 | 1057 | * @uses cron() |
| 1059 | 1058 | **/ |
| 1060 | 1059 | function action_cron() { |
| 1061 | - include_spip('inc/headers'); |
|
| 1062 | - http_response_code(204); // No Content |
|
| 1063 | - header('Connection: close'); |
|
| 1064 | - define('_DIRECT_CRON_FORCE', true); |
|
| 1065 | - cron(); |
|
| 1060 | + include_spip('inc/headers'); |
|
| 1061 | + http_response_code(204); // No Content |
|
| 1062 | + header('Connection: close'); |
|
| 1063 | + define('_DIRECT_CRON_FORCE', true); |
|
| 1064 | + cron(); |
|
| 1066 | 1065 | } |
| 1067 | 1066 | |
| 1068 | 1067 | /** |
@@ -1078,26 +1077,26 @@ discard block |
||
| 1078 | 1077 | * True si la tache a pu être effectuée |
| 1079 | 1078 | */ |
| 1080 | 1079 | function cron($taches = [], $taches_old = []) { |
| 1081 | - // si pas en mode cron force, laisser tomber. |
|
| 1082 | - if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1083 | - return false; |
|
| 1084 | - } |
|
| 1085 | - if (!is_array($taches)) { |
|
| 1086 | - $taches = $taches_old; |
|
| 1087 | - } // compat anciens appels |
|
| 1088 | - // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1089 | - // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1090 | - // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1091 | - // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1092 | - if ($taches and count($taches) and !spip_connect()) { |
|
| 1093 | - return false; |
|
| 1094 | - } |
|
| 1095 | - spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1096 | - if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1097 | - return $genie($taches); |
|
| 1098 | - } |
|
| 1099 | - |
|
| 1100 | - return false; |
|
| 1080 | + // si pas en mode cron force, laisser tomber. |
|
| 1081 | + if (!defined('_DIRECT_CRON_FORCE')) { |
|
| 1082 | + return false; |
|
| 1083 | + } |
|
| 1084 | + if (!is_array($taches)) { |
|
| 1085 | + $taches = $taches_old; |
|
| 1086 | + } // compat anciens appels |
|
| 1087 | + // si taches a inserer en base et base inaccessible, laisser tomber |
|
| 1088 | + // sinon on ne verifie pas la connexion tout de suite, car si ca se trouve |
|
| 1089 | + // queue_sleep_time_to_next_job() dira qu'il n'y a rien a faire |
|
| 1090 | + // et on evite d'ouvrir une connexion pour rien (utilisation de _DIRECT_CRON_FORCE dans mes_options.php) |
|
| 1091 | + if ($taches and count($taches) and !spip_connect()) { |
|
| 1092 | + return false; |
|
| 1093 | + } |
|
| 1094 | + spip_log('cron !', 'jq' . _LOG_DEBUG); |
|
| 1095 | + if ($genie = charger_fonction('genie', 'inc', true)) { |
|
| 1096 | + return $genie($taches); |
|
| 1097 | + } |
|
| 1098 | + |
|
| 1099 | + return false; |
|
| 1101 | 1100 | } |
| 1102 | 1101 | |
| 1103 | 1102 | /** |
@@ -1129,17 +1128,17 @@ discard block |
||
| 1129 | 1128 | * Le numéro de travail ajouté ou `0` si aucun travail n’a été ajouté. |
| 1130 | 1129 | */ |
| 1131 | 1130 | function job_queue_add( |
| 1132 | - $function, |
|
| 1133 | - $description, |
|
| 1134 | - $arguments = [], |
|
| 1135 | - $file = '', |
|
| 1136 | - $no_duplicate = false, |
|
| 1137 | - $time = 0, |
|
| 1138 | - $priority = 0 |
|
| 1131 | + $function, |
|
| 1132 | + $description, |
|
| 1133 | + $arguments = [], |
|
| 1134 | + $file = '', |
|
| 1135 | + $no_duplicate = false, |
|
| 1136 | + $time = 0, |
|
| 1137 | + $priority = 0 |
|
| 1139 | 1138 | ) { |
| 1140 | - include_spip('inc/queue'); |
|
| 1139 | + include_spip('inc/queue'); |
|
| 1141 | 1140 | |
| 1142 | - return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1141 | + return queue_add_job($function, $description, $arguments, $file, $no_duplicate, $time, $priority); |
|
| 1143 | 1142 | } |
| 1144 | 1143 | |
| 1145 | 1144 | /** |
@@ -1150,9 +1149,9 @@ discard block |
||
| 1150 | 1149 | * @return bool |
| 1151 | 1150 | */ |
| 1152 | 1151 | function job_queue_remove($id_job) { |
| 1153 | - include_spip('inc/queue'); |
|
| 1152 | + include_spip('inc/queue'); |
|
| 1154 | 1153 | |
| 1155 | - return queue_remove_job($id_job); |
|
| 1154 | + return queue_remove_job($id_job); |
|
| 1156 | 1155 | } |
| 1157 | 1156 | |
| 1158 | 1157 | /** |
@@ -1165,9 +1164,9 @@ discard block |
||
| 1165 | 1164 | * or an array of simple array to link multiples objet in one time |
| 1166 | 1165 | */ |
| 1167 | 1166 | function job_queue_link($id_job, $objets) { |
| 1168 | - include_spip('inc/queue'); |
|
| 1167 | + include_spip('inc/queue'); |
|
| 1169 | 1168 | |
| 1170 | - return queue_link_job($id_job, $objets); |
|
| 1169 | + return queue_link_job($id_job, $objets); |
|
| 1171 | 1170 | } |
| 1172 | 1171 | |
| 1173 | 1172 | |
@@ -1187,36 +1186,36 @@ discard block |
||
| 1187 | 1186 | * - `null` si la queue n'est pas encore initialisée |
| 1188 | 1187 | */ |
| 1189 | 1188 | function queue_sleep_time_to_next_job($force = null) { |
| 1190 | - static $queue_next_job_time = -1; |
|
| 1191 | - if ($force === true) { |
|
| 1192 | - $queue_next_job_time = -1; |
|
| 1193 | - } elseif ($force) { |
|
| 1194 | - $queue_next_job_time = $force; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - if ($queue_next_job_time == -1) { |
|
| 1198 | - if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1199 | - define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1200 | - } |
|
| 1201 | - // utiliser un cache memoire si dispo |
|
| 1202 | - if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1203 | - $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1204 | - } else { |
|
| 1205 | - $queue_next_job_time = null; |
|
| 1206 | - if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1207 | - $queue_next_job_time = intval($contenu); |
|
| 1208 | - } |
|
| 1209 | - } |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - if (is_null($queue_next_job_time)) { |
|
| 1213 | - return null; |
|
| 1214 | - } |
|
| 1215 | - if (!$_SERVER['REQUEST_TIME']) { |
|
| 1216 | - $_SERVER['REQUEST_TIME'] = time(); |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1189 | + static $queue_next_job_time = -1; |
|
| 1190 | + if ($force === true) { |
|
| 1191 | + $queue_next_job_time = -1; |
|
| 1192 | + } elseif ($force) { |
|
| 1193 | + $queue_next_job_time = $force; |
|
| 1194 | + } |
|
| 1195 | + |
|
| 1196 | + if ($queue_next_job_time == -1) { |
|
| 1197 | + if (!defined('_JQ_NEXT_JOB_TIME_FILENAME')) { |
|
| 1198 | + define('_JQ_NEXT_JOB_TIME_FILENAME', _DIR_TMP . 'job_queue_next.txt'); |
|
| 1199 | + } |
|
| 1200 | + // utiliser un cache memoire si dispo |
|
| 1201 | + if (function_exists('cache_get') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 1202 | + $queue_next_job_time = cache_get(_JQ_NEXT_JOB_TIME_FILENAME); |
|
| 1203 | + } else { |
|
| 1204 | + $queue_next_job_time = null; |
|
| 1205 | + if (lire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, $contenu)) { |
|
| 1206 | + $queue_next_job_time = intval($contenu); |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + } |
|
| 1210 | + |
|
| 1211 | + if (is_null($queue_next_job_time)) { |
|
| 1212 | + return null; |
|
| 1213 | + } |
|
| 1214 | + if (!$_SERVER['REQUEST_TIME']) { |
|
| 1215 | + $_SERVER['REQUEST_TIME'] = time(); |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + return $queue_next_job_time - $_SERVER['REQUEST_TIME']; |
|
| 1220 | 1219 | } |
| 1221 | 1220 | |
| 1222 | 1221 | |
@@ -1228,11 +1227,11 @@ discard block |
||
| 1228 | 1227 | * @return string |
| 1229 | 1228 | */ |
| 1230 | 1229 | function quote_amp($u) { |
| 1231 | - return preg_replace( |
|
| 1232 | - '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1233 | - '&', |
|
| 1234 | - $u |
|
| 1235 | - ); |
|
| 1230 | + return preg_replace( |
|
| 1231 | + '/&(?![a-z]{0,4}\w{2,3};|#x?[0-9a-f]{2,6};)/i', |
|
| 1232 | + '&', |
|
| 1233 | + $u |
|
| 1234 | + ); |
|
| 1236 | 1235 | } |
| 1237 | 1236 | |
| 1238 | 1237 | |
@@ -1255,27 +1254,27 @@ discard block |
||
| 1255 | 1254 | * Balise HTML `<script>` et son contenu |
| 1256 | 1255 | **/ |
| 1257 | 1256 | function http_script($script, $src = '', $noscript = '') { |
| 1258 | - static $done = []; |
|
| 1257 | + static $done = []; |
|
| 1259 | 1258 | |
| 1260 | - if ($src && !isset($done[$src])) { |
|
| 1261 | - $done[$src] = true; |
|
| 1262 | - $src = find_in_path($src, _JAVASCRIPT); |
|
| 1263 | - $src = " src='$src'"; |
|
| 1264 | - } else { |
|
| 1265 | - $src = ''; |
|
| 1266 | - } |
|
| 1267 | - if ($script) { |
|
| 1268 | - $script = ("/*<![CDATA[*/\n" . |
|
| 1269 | - preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1270 | - '/*]]>*/'); |
|
| 1271 | - } |
|
| 1272 | - if ($noscript) { |
|
| 1273 | - $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1274 | - } |
|
| 1259 | + if ($src && !isset($done[$src])) { |
|
| 1260 | + $done[$src] = true; |
|
| 1261 | + $src = find_in_path($src, _JAVASCRIPT); |
|
| 1262 | + $src = " src='$src'"; |
|
| 1263 | + } else { |
|
| 1264 | + $src = ''; |
|
| 1265 | + } |
|
| 1266 | + if ($script) { |
|
| 1267 | + $script = ("/*<![CDATA[*/\n" . |
|
| 1268 | + preg_replace(',</([^>]*)>,', '<\/\1>', $script) . |
|
| 1269 | + '/*]]>*/'); |
|
| 1270 | + } |
|
| 1271 | + if ($noscript) { |
|
| 1272 | + $noscript = "<noscript>\n\t$noscript\n</noscript>\n"; |
|
| 1273 | + } |
|
| 1275 | 1274 | |
| 1276 | - return ($src or $script or $noscript) |
|
| 1277 | - ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1278 | - : ''; |
|
| 1275 | + return ($src or $script or $noscript) |
|
| 1276 | + ? "<script type='text/javascript'$src>$script</script>$noscript" |
|
| 1277 | + : ''; |
|
| 1279 | 1278 | } |
| 1280 | 1279 | |
| 1281 | 1280 | |
@@ -1310,7 +1309,7 @@ discard block |
||
| 1310 | 1309 | * Texte échappé |
| 1311 | 1310 | **/ |
| 1312 | 1311 | function texte_script(string $texte): string { |
| 1313 | - return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1312 | + return str_replace('\'', '\\\'', str_replace('\\', '\\\\', $texte)); |
|
| 1314 | 1313 | } |
| 1315 | 1314 | |
| 1316 | 1315 | |
@@ -1347,68 +1346,68 @@ discard block |
||
| 1347 | 1346 | * Liste des chemins, par ordre de priorité. |
| 1348 | 1347 | **/ |
| 1349 | 1348 | function _chemin($dir_path = null) { |
| 1350 | - static $path_base = null; |
|
| 1351 | - static $path_full = null; |
|
| 1352 | - if ($path_base == null) { |
|
| 1353 | - // Chemin standard depuis l'espace public |
|
| 1354 | - $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1355 | - _DIR_RACINE . ':' . |
|
| 1356 | - _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1357 | - _DIR_RACINE . 'prive/:' . |
|
| 1358 | - _DIR_RESTREINT; |
|
| 1359 | - // Ajouter squelettes/ |
|
| 1360 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1361 | - $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1362 | - } |
|
| 1363 | - foreach (explode(':', $path) as $dir) { |
|
| 1364 | - if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1365 | - $dir .= '/'; |
|
| 1366 | - } |
|
| 1367 | - $path_base[] = $dir; |
|
| 1368 | - } |
|
| 1369 | - $path_full = $path_base; |
|
| 1370 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1371 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1372 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1373 | - array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1374 | - } |
|
| 1375 | - } |
|
| 1376 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1377 | - } |
|
| 1378 | - if ($dir_path === null) { |
|
| 1379 | - return $path_full; |
|
| 1380 | - } |
|
| 1381 | - |
|
| 1382 | - if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1383 | - $tete = ''; |
|
| 1384 | - if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1385 | - $tete = array_shift($path_base); |
|
| 1386 | - } |
|
| 1387 | - $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1388 | - $dirs = array_reverse($dirs); |
|
| 1389 | - foreach ($dirs as $dir_path) { |
|
| 1390 | - if (substr($dir_path, -1) != '/') { |
|
| 1391 | - $dir_path .= '/'; |
|
| 1392 | - } |
|
| 1393 | - if (!in_array($dir_path, $path_base)) { |
|
| 1394 | - array_unshift($path_base, $dir_path); |
|
| 1395 | - } |
|
| 1396 | - } |
|
| 1397 | - if (strlen($tete)) { |
|
| 1398 | - array_unshift($path_base, $tete); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - $path_full = $path_base; |
|
| 1402 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 1403 | - if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1404 | - foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1405 | - array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1406 | - } |
|
| 1407 | - } |
|
| 1408 | - |
|
| 1409 | - $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1410 | - |
|
| 1411 | - return $path_full; |
|
| 1349 | + static $path_base = null; |
|
| 1350 | + static $path_full = null; |
|
| 1351 | + if ($path_base == null) { |
|
| 1352 | + // Chemin standard depuis l'espace public |
|
| 1353 | + $path = defined('_SPIP_PATH') ? _SPIP_PATH : |
|
| 1354 | + _DIR_RACINE . ':' . |
|
| 1355 | + _DIR_RACINE . 'squelettes-dist/:' . |
|
| 1356 | + _DIR_RACINE . 'prive/:' . |
|
| 1357 | + _DIR_RESTREINT; |
|
| 1358 | + // Ajouter squelettes/ |
|
| 1359 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 1360 | + $path = _DIR_RACINE . 'squelettes/:' . $path; |
|
| 1361 | + } |
|
| 1362 | + foreach (explode(':', $path) as $dir) { |
|
| 1363 | + if (strlen($dir) and substr($dir, -1) != '/') { |
|
| 1364 | + $dir .= '/'; |
|
| 1365 | + } |
|
| 1366 | + $path_base[] = $dir; |
|
| 1367 | + } |
|
| 1368 | + $path_full = $path_base; |
|
| 1369 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1370 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1371 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1372 | + array_unshift($path_full, ($d[0] == '/' ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1373 | + } |
|
| 1374 | + } |
|
| 1375 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1376 | + } |
|
| 1377 | + if ($dir_path === null) { |
|
| 1378 | + return $path_full; |
|
| 1379 | + } |
|
| 1380 | + |
|
| 1381 | + if (is_array($dir_path) or strlen($dir_path)) { |
|
| 1382 | + $tete = ''; |
|
| 1383 | + if (reset($path_base) == _DIR_RACINE . 'squelettes/') { |
|
| 1384 | + $tete = array_shift($path_base); |
|
| 1385 | + } |
|
| 1386 | + $dirs = (is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 1387 | + $dirs = array_reverse($dirs); |
|
| 1388 | + foreach ($dirs as $dir_path) { |
|
| 1389 | + if (substr($dir_path, -1) != '/') { |
|
| 1390 | + $dir_path .= '/'; |
|
| 1391 | + } |
|
| 1392 | + if (!in_array($dir_path, $path_base)) { |
|
| 1393 | + array_unshift($path_base, $dir_path); |
|
| 1394 | + } |
|
| 1395 | + } |
|
| 1396 | + if (strlen($tete)) { |
|
| 1397 | + array_unshift($path_base, $tete); |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | + $path_full = $path_base; |
|
| 1401 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 1402 | + if (strlen($GLOBALS['dossier_squelettes'])) { |
|
| 1403 | + foreach (array_reverse(explode(':', $GLOBALS['dossier_squelettes'])) as $d) { |
|
| 1404 | + array_unshift($path_full, ((isset($d[0]) and $d[0] == '/') ? '' : _DIR_RACINE) . $d . '/'); |
|
| 1405 | + } |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + $GLOBALS['path_sig'] = md5(serialize($path_full)); |
|
| 1409 | + |
|
| 1410 | + return $path_full; |
|
| 1412 | 1411 | } |
| 1413 | 1412 | |
| 1414 | 1413 | /** |
@@ -1421,78 +1420,78 @@ discard block |
||
| 1421 | 1420 | * @return array Liste de chemins |
| 1422 | 1421 | **/ |
| 1423 | 1422 | function creer_chemin() { |
| 1424 | - $path_a = _chemin(); |
|
| 1425 | - static $c = ''; |
|
| 1423 | + $path_a = _chemin(); |
|
| 1424 | + static $c = ''; |
|
| 1426 | 1425 | |
| 1427 | - // on calcule le chemin si le dossier skel a change |
|
| 1428 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1429 | - // assurer le non plantage lors de la montee de version : |
|
| 1430 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1431 | - $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1432 | - } |
|
| 1426 | + // on calcule le chemin si le dossier skel a change |
|
| 1427 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1428 | + // assurer le non plantage lors de la montee de version : |
|
| 1429 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1430 | + $path_a = _chemin(''); // forcer un recalcul du chemin |
|
| 1431 | + } |
|
| 1433 | 1432 | |
| 1434 | - return $path_a; |
|
| 1433 | + return $path_a; |
|
| 1435 | 1434 | } |
| 1436 | 1435 | |
| 1437 | 1436 | |
| 1438 | 1437 | function lister_themes_prives() { |
| 1439 | - static $themes = null; |
|
| 1440 | - if (is_null($themes)) { |
|
| 1441 | - // si pas encore definie |
|
| 1442 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1443 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1444 | - } |
|
| 1445 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 1446 | - // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1447 | - if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1448 | - $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1449 | - } else { |
|
| 1450 | - $prefs = []; |
|
| 1451 | - } |
|
| 1452 | - if (is_string($prefs)) { |
|
| 1453 | - $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1454 | - } |
|
| 1455 | - if ( |
|
| 1456 | - ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1457 | - or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1458 | - and $theme != _SPIP_THEME_PRIVE |
|
| 1459 | - ) { |
|
| 1460 | - array_unshift($themes, $theme); |
|
| 1461 | - } // placer le theme choisi en tete |
|
| 1462 | - } |
|
| 1463 | - |
|
| 1464 | - return $themes; |
|
| 1438 | + static $themes = null; |
|
| 1439 | + if (is_null($themes)) { |
|
| 1440 | + // si pas encore definie |
|
| 1441 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 1442 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 1443 | + } |
|
| 1444 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 1445 | + // lors d'une installation neuve, prefs n'est pas definie. |
|
| 1446 | + if (isset($GLOBALS['visiteur_session']['prefs'])) { |
|
| 1447 | + $prefs = $GLOBALS['visiteur_session']['prefs']; |
|
| 1448 | + } else { |
|
| 1449 | + $prefs = []; |
|
| 1450 | + } |
|
| 1451 | + if (is_string($prefs)) { |
|
| 1452 | + $prefs = unserialize($GLOBALS['visiteur_session']['prefs']); |
|
| 1453 | + } |
|
| 1454 | + if ( |
|
| 1455 | + ((isset($prefs['theme']) and $theme = $prefs['theme']) |
|
| 1456 | + or (isset($GLOBALS['theme_prive_defaut']) and $theme = $GLOBALS['theme_prive_defaut'])) |
|
| 1457 | + and $theme != _SPIP_THEME_PRIVE |
|
| 1458 | + ) { |
|
| 1459 | + array_unshift($themes, $theme); |
|
| 1460 | + } // placer le theme choisi en tete |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + return $themes; |
|
| 1465 | 1464 | } |
| 1466 | 1465 | |
| 1467 | 1466 | function find_in_theme($file, $subdir = '', $include = false) { |
| 1468 | - static $themefiles = []; |
|
| 1469 | - if (isset($themefiles["$subdir$file"])) { |
|
| 1470 | - return $themefiles["$subdir$file"]; |
|
| 1471 | - } |
|
| 1472 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1473 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1474 | - if ( |
|
| 1475 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1476 | - and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1477 | - and $f = find_in_theme("$file_svg_generique") |
|
| 1478 | - ) { |
|
| 1479 | - if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1480 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 1481 | - } |
|
| 1482 | - else { |
|
| 1483 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - |
|
| 1487 | - $themes = lister_themes_prives(); |
|
| 1488 | - foreach ($themes as $theme) { |
|
| 1489 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1490 | - return $themefiles["$subdir$file"] = $f; |
|
| 1491 | - } |
|
| 1492 | - } |
|
| 1493 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1494 | - |
|
| 1495 | - return $themefiles["$subdir$file"] = ''; |
|
| 1467 | + static $themefiles = []; |
|
| 1468 | + if (isset($themefiles["$subdir$file"])) { |
|
| 1469 | + return $themefiles["$subdir$file"]; |
|
| 1470 | + } |
|
| 1471 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 1472 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 1473 | + if ( |
|
| 1474 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 1475 | + and $file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 1476 | + and $f = find_in_theme("$file_svg_generique") |
|
| 1477 | + ) { |
|
| 1478 | + if ($fsize = substr($f, 0, -6) . $m[1] . '.svg' and file_exists($fsize)) { |
|
| 1479 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 1480 | + } |
|
| 1481 | + else { |
|
| 1482 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 1483 | + } |
|
| 1484 | + } |
|
| 1485 | + |
|
| 1486 | + $themes = lister_themes_prives(); |
|
| 1487 | + foreach ($themes as $theme) { |
|
| 1488 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 1489 | + return $themefiles["$subdir$file"] = $f; |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 1493 | + |
|
| 1494 | + return $themefiles["$subdir$file"] = ''; |
|
| 1496 | 1495 | } |
| 1497 | 1496 | |
| 1498 | 1497 | |
@@ -1516,31 +1515,31 @@ discard block |
||
| 1516 | 1515 | * sinon chaîne vide. |
| 1517 | 1516 | **/ |
| 1518 | 1517 | function chemin_image($icone) { |
| 1519 | - static $icone_renommer; |
|
| 1520 | - if ($p = strpos($icone, '?')) { |
|
| 1521 | - $icone = substr($icone, 0, $p); |
|
| 1522 | - } |
|
| 1523 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1524 | - if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1525 | - return $icone; |
|
| 1526 | - } |
|
| 1527 | - |
|
| 1528 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1529 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1530 | - return $f; |
|
| 1531 | - } |
|
| 1532 | - // sinon passer par le module de renommage |
|
| 1533 | - if (is_null($icone_renommer)) { |
|
| 1534 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1535 | - } |
|
| 1536 | - if ($icone_renommer) { |
|
| 1537 | - [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1538 | - if (file_exists($icone)) { |
|
| 1539 | - return $icone; |
|
| 1540 | - } |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1518 | + static $icone_renommer; |
|
| 1519 | + if ($p = strpos($icone, '?')) { |
|
| 1520 | + $icone = substr($icone, 0, $p); |
|
| 1521 | + } |
|
| 1522 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 1523 | + if (strpos($icone, '/') !== false and file_exists($icone)) { |
|
| 1524 | + return $icone; |
|
| 1525 | + } |
|
| 1526 | + |
|
| 1527 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 1528 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) and $f = find_in_theme("images/$icone")) { |
|
| 1529 | + return $f; |
|
| 1530 | + } |
|
| 1531 | + // sinon passer par le module de renommage |
|
| 1532 | + if (is_null($icone_renommer)) { |
|
| 1533 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 1534 | + } |
|
| 1535 | + if ($icone_renommer) { |
|
| 1536 | + [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 1537 | + if (file_exists($icone)) { |
|
| 1538 | + return $icone; |
|
| 1539 | + } |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 1544 | 1543 | } |
| 1545 | 1544 | |
| 1546 | 1545 | // |
@@ -1578,128 +1577,128 @@ discard block |
||
| 1578 | 1577 | * - false : fichier introuvable |
| 1579 | 1578 | **/ |
| 1580 | 1579 | function find_in_path($file, $dirname = '', $include = false) { |
| 1581 | - static $dirs = []; |
|
| 1582 | - static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1583 | - static $c = ''; |
|
| 1584 | - |
|
| 1585 | - if (!$file and !strlen($file)) { |
|
| 1586 | - return false; |
|
| 1587 | - } |
|
| 1588 | - |
|
| 1589 | - // on calcule le chemin si le dossier skel a change |
|
| 1590 | - if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1591 | - // assurer le non plantage lors de la montee de version : |
|
| 1592 | - $c = $GLOBALS['dossier_squelettes']; |
|
| 1593 | - creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1597 | - if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1598 | - return false; |
|
| 1599 | - } |
|
| 1600 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1601 | - include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1602 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1606 | - } |
|
| 1607 | - |
|
| 1608 | - $a = strrpos($file, '/'); |
|
| 1609 | - if ($a !== false) { |
|
| 1610 | - $dirname .= substr($file, 0, ++$a); |
|
| 1611 | - $file = substr($file, $a); |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - foreach (creer_chemin() as $dir) { |
|
| 1615 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1616 | - $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1617 | - } |
|
| 1618 | - if ($dirs[$a]) { |
|
| 1619 | - if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1620 | - if ($include and !isset($inc[$dirname][$file])) { |
|
| 1621 | - include_once _ROOT_CWD . $a; |
|
| 1622 | - $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1623 | - } |
|
| 1624 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1625 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1626 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1627 | - return $a; |
|
| 1628 | - } |
|
| 1629 | - define('_SAUVER_CHEMIN', true); |
|
| 1630 | - } |
|
| 1631 | - |
|
| 1632 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1633 | - } |
|
| 1634 | - } |
|
| 1635 | - } |
|
| 1636 | - |
|
| 1637 | - if ($include) { |
|
| 1638 | - spip_log("include_spip $dirname$file non trouve"); |
|
| 1639 | - if ($include === 'required') { |
|
| 1640 | - echo '<pre>', |
|
| 1641 | - '<strong>Erreur Fatale</strong><br />'; |
|
| 1642 | - if (function_exists('debug_print_backtrace')) { |
|
| 1643 | - echo debug_print_backtrace(); |
|
| 1644 | - } |
|
| 1645 | - echo '</pre>'; |
|
| 1646 | - die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1647 | - } |
|
| 1648 | - } |
|
| 1649 | - |
|
| 1650 | - if (!defined('_SAUVER_CHEMIN')) { |
|
| 1651 | - // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1652 | - if (is_null($GLOBALS['path_files'])) { |
|
| 1653 | - return false; |
|
| 1654 | - } |
|
| 1655 | - define('_SAUVER_CHEMIN', true); |
|
| 1656 | - } |
|
| 1657 | - |
|
| 1658 | - return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1580 | + static $dirs = []; |
|
| 1581 | + static $inc = []; # cf https://git.spip.net/spip/spip/commit/42e4e028e38c839121efaee84308d08aee307eec |
|
| 1582 | + static $c = ''; |
|
| 1583 | + |
|
| 1584 | + if (!$file and !strlen($file)) { |
|
| 1585 | + return false; |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + // on calcule le chemin si le dossier skel a change |
|
| 1589 | + if ($c != $GLOBALS['dossier_squelettes']) { |
|
| 1590 | + // assurer le non plantage lors de la montee de version : |
|
| 1591 | + $c = $GLOBALS['dossier_squelettes']; |
|
| 1592 | + creer_chemin(); // forcer un recalcul du chemin et la mise a jour de path_sig |
|
| 1593 | + } |
|
| 1594 | + |
|
| 1595 | + if (isset($GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file])) { |
|
| 1596 | + if (!$GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]) { |
|
| 1597 | + return false; |
|
| 1598 | + } |
|
| 1599 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1600 | + include_once _ROOT_CWD . $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1601 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1602 | + } |
|
| 1603 | + |
|
| 1604 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file]; |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + $a = strrpos($file, '/'); |
|
| 1608 | + if ($a !== false) { |
|
| 1609 | + $dirname .= substr($file, 0, ++$a); |
|
| 1610 | + $file = substr($file, $a); |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + foreach (creer_chemin() as $dir) { |
|
| 1614 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 1615 | + $dirs[$a] = (is_dir(_ROOT_CWD . $a) || !$a); |
|
| 1616 | + } |
|
| 1617 | + if ($dirs[$a]) { |
|
| 1618 | + if (file_exists(_ROOT_CWD . ($a .= $file))) { |
|
| 1619 | + if ($include and !isset($inc[$dirname][$file])) { |
|
| 1620 | + include_once _ROOT_CWD . $a; |
|
| 1621 | + $inc[$dirname][$file] = $inc[''][$dirname . $file] = true; |
|
| 1622 | + } |
|
| 1623 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1624 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1625 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1626 | + return $a; |
|
| 1627 | + } |
|
| 1628 | + define('_SAUVER_CHEMIN', true); |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = $a; |
|
| 1632 | + } |
|
| 1633 | + } |
|
| 1634 | + } |
|
| 1635 | + |
|
| 1636 | + if ($include) { |
|
| 1637 | + spip_log("include_spip $dirname$file non trouve"); |
|
| 1638 | + if ($include === 'required') { |
|
| 1639 | + echo '<pre>', |
|
| 1640 | + '<strong>Erreur Fatale</strong><br />'; |
|
| 1641 | + if (function_exists('debug_print_backtrace')) { |
|
| 1642 | + echo debug_print_backtrace(); |
|
| 1643 | + } |
|
| 1644 | + echo '</pre>'; |
|
| 1645 | + die("Erreur interne: ne peut inclure $dirname$file"); |
|
| 1646 | + } |
|
| 1647 | + } |
|
| 1648 | + |
|
| 1649 | + if (!defined('_SAUVER_CHEMIN')) { |
|
| 1650 | + // si le chemin n'a pas encore ete charge, ne pas lever le flag, ne pas cacher |
|
| 1651 | + if (is_null($GLOBALS['path_files'])) { |
|
| 1652 | + return false; |
|
| 1653 | + } |
|
| 1654 | + define('_SAUVER_CHEMIN', true); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + return $GLOBALS['path_files'][$GLOBALS['path_sig']][$dirname][$file] = $GLOBALS['path_files'][$GLOBALS['path_sig']][''][$dirname . $file] = false; |
|
| 1659 | 1658 | } |
| 1660 | 1659 | |
| 1661 | 1660 | function clear_path_cache() { |
| 1662 | - $GLOBALS['path_files'] = []; |
|
| 1663 | - spip_unlink(_CACHE_CHEMIN); |
|
| 1661 | + $GLOBALS['path_files'] = []; |
|
| 1662 | + spip_unlink(_CACHE_CHEMIN); |
|
| 1664 | 1663 | } |
| 1665 | 1664 | |
| 1666 | 1665 | function load_path_cache() { |
| 1667 | - // charger le path des plugins |
|
| 1668 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1669 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1670 | - } |
|
| 1671 | - $GLOBALS['path_files'] = []; |
|
| 1672 | - // si le visiteur est admin, |
|
| 1673 | - // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1674 | - if ( |
|
| 1675 | - // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1676 | - //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1677 | - // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1678 | - // on blinde par un second test au moment de la lecture de la session |
|
| 1679 | - // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1680 | - // et en ignorant ce cache en cas de recalcul explicite |
|
| 1681 | - !_request('var_mode') |
|
| 1682 | - ) { |
|
| 1683 | - // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1684 | - if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1685 | - // mais si semble corrompu on relit avec un verrou |
|
| 1686 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1687 | - lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1688 | - if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1689 | - $GLOBALS['path_files'] = []; |
|
| 1690 | - } |
|
| 1691 | - } |
|
| 1692 | - } |
|
| 1693 | - } |
|
| 1666 | + // charger le path des plugins |
|
| 1667 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1668 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1669 | + } |
|
| 1670 | + $GLOBALS['path_files'] = []; |
|
| 1671 | + // si le visiteur est admin, |
|
| 1672 | + // on ne recharge pas le cache pour forcer sa mise a jour |
|
| 1673 | + if ( |
|
| 1674 | + // la session n'est pas encore chargee a ce moment, on ne peut donc pas s'y fier |
|
| 1675 | + //AND (!isset($GLOBALS['visiteur_session']['statut']) OR $GLOBALS['visiteur_session']['statut']!='0minirezo') |
|
| 1676 | + // utiliser le cookie est un pis aller qui marche 'en general' |
|
| 1677 | + // on blinde par un second test au moment de la lecture de la session |
|
| 1678 | + // !isset($_COOKIE[$GLOBALS['cookie_prefix'].'_admin']) |
|
| 1679 | + // et en ignorant ce cache en cas de recalcul explicite |
|
| 1680 | + !_request('var_mode') |
|
| 1681 | + ) { |
|
| 1682 | + // on essaye de lire directement sans verrou pour aller plus vite |
|
| 1683 | + if ($contenu = spip_file_get_contents(_CACHE_CHEMIN)) { |
|
| 1684 | + // mais si semble corrompu on relit avec un verrou |
|
| 1685 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1686 | + lire_fichier(_CACHE_CHEMIN, $contenu); |
|
| 1687 | + if (!$GLOBALS['path_files'] = unserialize($contenu)) { |
|
| 1688 | + $GLOBALS['path_files'] = []; |
|
| 1689 | + } |
|
| 1690 | + } |
|
| 1691 | + } |
|
| 1692 | + } |
|
| 1694 | 1693 | } |
| 1695 | 1694 | |
| 1696 | 1695 | function save_path_cache() { |
| 1697 | - if ( |
|
| 1698 | - defined('_SAUVER_CHEMIN') |
|
| 1699 | - and _SAUVER_CHEMIN |
|
| 1700 | - ) { |
|
| 1701 | - ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1702 | - } |
|
| 1696 | + if ( |
|
| 1697 | + defined('_SAUVER_CHEMIN') |
|
| 1698 | + and _SAUVER_CHEMIN |
|
| 1699 | + ) { |
|
| 1700 | + ecrire_fichier(_CACHE_CHEMIN, serialize($GLOBALS['path_files'])); |
|
| 1701 | + } |
|
| 1703 | 1702 | } |
| 1704 | 1703 | |
| 1705 | 1704 | |
@@ -1719,33 +1718,33 @@ discard block |
||
| 1719 | 1718 | * @return array |
| 1720 | 1719 | */ |
| 1721 | 1720 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 1722 | - $liste_fichiers = []; |
|
| 1723 | - $maxfiles = 10000; |
|
| 1724 | - |
|
| 1725 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1726 | - // on a pas encore inclus flock.php |
|
| 1727 | - if (!function_exists('preg_files')) { |
|
| 1728 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1729 | - } |
|
| 1730 | - |
|
| 1731 | - // Parcourir le chemin |
|
| 1732 | - foreach (creer_chemin() as $d) { |
|
| 1733 | - $f = $d . $dir; |
|
| 1734 | - if (@is_dir($f)) { |
|
| 1735 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1736 | - foreach ($liste as $chemin) { |
|
| 1737 | - $nom = basename($chemin); |
|
| 1738 | - // ne prendre que les fichiers pas deja trouves |
|
| 1739 | - // car find_in_path prend le premier qu'il trouve, |
|
| 1740 | - // les autres sont donc masques |
|
| 1741 | - if (!isset($liste_fichiers[$nom])) { |
|
| 1742 | - $liste_fichiers[$nom] = $chemin; |
|
| 1743 | - } |
|
| 1744 | - } |
|
| 1745 | - } |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - return $liste_fichiers; |
|
| 1721 | + $liste_fichiers = []; |
|
| 1722 | + $maxfiles = 10000; |
|
| 1723 | + |
|
| 1724 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 1725 | + // on a pas encore inclus flock.php |
|
| 1726 | + if (!function_exists('preg_files')) { |
|
| 1727 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 1728 | + } |
|
| 1729 | + |
|
| 1730 | + // Parcourir le chemin |
|
| 1731 | + foreach (creer_chemin() as $d) { |
|
| 1732 | + $f = $d . $dir; |
|
| 1733 | + if (@is_dir($f)) { |
|
| 1734 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 1735 | + foreach ($liste as $chemin) { |
|
| 1736 | + $nom = basename($chemin); |
|
| 1737 | + // ne prendre que les fichiers pas deja trouves |
|
| 1738 | + // car find_in_path prend le premier qu'il trouve, |
|
| 1739 | + // les autres sont donc masques |
|
| 1740 | + if (!isset($liste_fichiers[$nom])) { |
|
| 1741 | + $liste_fichiers[$nom] = $chemin; |
|
| 1742 | + } |
|
| 1743 | + } |
|
| 1744 | + } |
|
| 1745 | + } |
|
| 1746 | + |
|
| 1747 | + return $liste_fichiers; |
|
| 1749 | 1748 | } |
| 1750 | 1749 | |
| 1751 | 1750 | /** |
@@ -1757,17 +1756,17 @@ discard block |
||
| 1757 | 1756 | * @return bool |
| 1758 | 1757 | */ |
| 1759 | 1758 | function autoriser_sans_cookie($nom, $strict = false) { |
| 1760 | - static $autsanscookie = ['install', 'base_repair']; |
|
| 1759 | + static $autsanscookie = ['install', 'base_repair']; |
|
| 1761 | 1760 | |
| 1762 | - if (in_array($nom, $autsanscookie)) { |
|
| 1763 | - if (test_espace_prive()) { |
|
| 1764 | - include_spip('base/connect_sql'); |
|
| 1765 | - if (!$strict or !spip_connect()) { |
|
| 1766 | - return true; |
|
| 1767 | - } |
|
| 1768 | - } |
|
| 1769 | - } |
|
| 1770 | - return false; |
|
| 1761 | + if (in_array($nom, $autsanscookie)) { |
|
| 1762 | + if (test_espace_prive()) { |
|
| 1763 | + include_spip('base/connect_sql'); |
|
| 1764 | + if (!$strict or !spip_connect()) { |
|
| 1765 | + return true; |
|
| 1766 | + } |
|
| 1767 | + } |
|
| 1768 | + } |
|
| 1769 | + return false; |
|
| 1771 | 1770 | } |
| 1772 | 1771 | |
| 1773 | 1772 | /** |
@@ -1777,59 +1776,59 @@ discard block |
||
| 1777 | 1776 | * @return string |
| 1778 | 1777 | */ |
| 1779 | 1778 | function charger_fonction_url(string $quoi, string $type = '') { |
| 1780 | - if ($type === 'defaut') { |
|
| 1781 | - $objet = objet_type($quoi); |
|
| 1782 | - if ( |
|
| 1783 | - $f = charger_fonction('generer_' . $objet . '_url', 'urls', true) |
|
| 1784 | - // deprecated |
|
| 1785 | - or $f = charger_fonction('generer_url_' . $objet, 'urls', true) |
|
| 1786 | - ) { |
|
| 1787 | - return $f; |
|
| 1788 | - } |
|
| 1789 | - return ''; |
|
| 1790 | - } |
|
| 1791 | - |
|
| 1792 | - if (!$type) { |
|
| 1793 | - $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1794 | - } |
|
| 1795 | - |
|
| 1796 | - // inclure le module d'url |
|
| 1797 | - include_spip('urls/' . $type); |
|
| 1798 | - |
|
| 1799 | - switch ($quoi) { |
|
| 1800 | - case 'page': |
|
| 1801 | - if ( |
|
| 1802 | - function_exists($f = "urls_{$type}_generer_url_page") |
|
| 1803 | - or function_exists($f .= '_dist') |
|
| 1804 | - // ou une fonction custom utilisateur independante du type d'url |
|
| 1805 | - or function_exists($f = 'generer_url_page') |
|
| 1806 | - or function_exists($f .= '_dist') |
|
| 1807 | - ) { |
|
| 1808 | - return $f; |
|
| 1809 | - } |
|
| 1810 | - // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 1811 | - return ''; |
|
| 1812 | - case 'objet': |
|
| 1813 | - case 'decoder': |
|
| 1814 | - default: |
|
| 1815 | - $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 1816 | - if ( |
|
| 1817 | - function_exists($f = "urls_{$type}_{$fquoi}") |
|
| 1818 | - or function_exists($f .= '_dist') |
|
| 1819 | - ) { |
|
| 1820 | - return $f; |
|
| 1821 | - } |
|
| 1822 | - // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 1823 | - // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 1824 | - if ($f = charger_fonction($type, 'urls', true)) { |
|
| 1825 | - return $f; |
|
| 1826 | - } |
|
| 1827 | - // sinon on se rabat sur les urls page |
|
| 1828 | - if ($type !== 'page') { |
|
| 1829 | - return charger_fonction_url($quoi, 'page'); |
|
| 1830 | - } |
|
| 1831 | - return ''; |
|
| 1832 | - } |
|
| 1779 | + if ($type === 'defaut') { |
|
| 1780 | + $objet = objet_type($quoi); |
|
| 1781 | + if ( |
|
| 1782 | + $f = charger_fonction('generer_' . $objet . '_url', 'urls', true) |
|
| 1783 | + // deprecated |
|
| 1784 | + or $f = charger_fonction('generer_url_' . $objet, 'urls', true) |
|
| 1785 | + ) { |
|
| 1786 | + return $f; |
|
| 1787 | + } |
|
| 1788 | + return ''; |
|
| 1789 | + } |
|
| 1790 | + |
|
| 1791 | + if (!$type) { |
|
| 1792 | + $type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 1793 | + } |
|
| 1794 | + |
|
| 1795 | + // inclure le module d'url |
|
| 1796 | + include_spip('urls/' . $type); |
|
| 1797 | + |
|
| 1798 | + switch ($quoi) { |
|
| 1799 | + case 'page': |
|
| 1800 | + if ( |
|
| 1801 | + function_exists($f = "urls_{$type}_generer_url_page") |
|
| 1802 | + or function_exists($f .= '_dist') |
|
| 1803 | + // ou une fonction custom utilisateur independante du type d'url |
|
| 1804 | + or function_exists($f = 'generer_url_page') |
|
| 1805 | + or function_exists($f .= '_dist') |
|
| 1806 | + ) { |
|
| 1807 | + return $f; |
|
| 1808 | + } |
|
| 1809 | + // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 1810 | + return ''; |
|
| 1811 | + case 'objet': |
|
| 1812 | + case 'decoder': |
|
| 1813 | + default: |
|
| 1814 | + $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 1815 | + if ( |
|
| 1816 | + function_exists($f = "urls_{$type}_{$fquoi}") |
|
| 1817 | + or function_exists($f .= '_dist') |
|
| 1818 | + ) { |
|
| 1819 | + return $f; |
|
| 1820 | + } |
|
| 1821 | + // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 1822 | + // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 1823 | + if ($f = charger_fonction($type, 'urls', true)) { |
|
| 1824 | + return $f; |
|
| 1825 | + } |
|
| 1826 | + // sinon on se rabat sur les urls page |
|
| 1827 | + if ($type !== 'page') { |
|
| 1828 | + return charger_fonction_url($quoi, 'page'); |
|
| 1829 | + } |
|
| 1830 | + return ''; |
|
| 1831 | + } |
|
| 1833 | 1832 | } |
| 1834 | 1833 | |
| 1835 | 1834 | |
@@ -1858,48 +1857,48 @@ discard block |
||
| 1858 | 1857 | * (cas des raccourcis personalises [->spip20] : il faut implementer une fonction generer_spip_url et une fonction generer_spip_url_ecrire) |
| 1859 | 1858 | */ |
| 1860 | 1859 | function generer_objet_url($id, string $entite, string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 1861 | - if ($public === null) { |
|
| 1862 | - $public = !test_espace_prive(); |
|
| 1863 | - } |
|
| 1864 | - $id = intval($id); |
|
| 1865 | - $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1866 | - |
|
| 1867 | - if (!$public) { |
|
| 1868 | - if (!$entite) { |
|
| 1869 | - return ''; |
|
| 1870 | - } |
|
| 1871 | - if (!function_exists('generer_objet_url_ecrire')) { |
|
| 1872 | - include_spip('inc/urls'); |
|
| 1873 | - } |
|
| 1874 | - $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 1875 | - } else { |
|
| 1876 | - $f = charger_fonction_url('objet', $type ?? ''); |
|
| 1877 | - |
|
| 1878 | - // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 1879 | - // @see charger_fonction_url |
|
| 1880 | - if (!$entite) { |
|
| 1881 | - return $f; |
|
| 1882 | - } |
|
| 1883 | - |
|
| 1884 | - // mais d'abord il faut tester le cas des urls sur une |
|
| 1885 | - // base distante |
|
| 1886 | - if ( |
|
| 1887 | - $connect |
|
| 1888 | - and $g = charger_fonction('connect', 'urls', true) |
|
| 1889 | - ) { |
|
| 1890 | - $f = $g; |
|
| 1891 | - } |
|
| 1892 | - |
|
| 1893 | - $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 1894 | - } |
|
| 1895 | - if ($res) { |
|
| 1896 | - return $res; |
|
| 1897 | - } |
|
| 1898 | - |
|
| 1899 | - // On a ete gentil mais la .... |
|
| 1900 | - spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1901 | - |
|
| 1902 | - return ''; |
|
| 1860 | + if ($public === null) { |
|
| 1861 | + $public = !test_espace_prive(); |
|
| 1862 | + } |
|
| 1863 | + $id = intval($id); |
|
| 1864 | + $entite = objet_type($entite); // cas particulier d'appels sur objet/id_objet... |
|
| 1865 | + |
|
| 1866 | + if (!$public) { |
|
| 1867 | + if (!$entite) { |
|
| 1868 | + return ''; |
|
| 1869 | + } |
|
| 1870 | + if (!function_exists('generer_objet_url_ecrire')) { |
|
| 1871 | + include_spip('inc/urls'); |
|
| 1872 | + } |
|
| 1873 | + $res = generer_objet_url_ecrire($id, $entite, $args, $ancre, false, $connect); |
|
| 1874 | + } else { |
|
| 1875 | + $f = charger_fonction_url('objet', $type ?? ''); |
|
| 1876 | + |
|
| 1877 | + // @deprecated si $entite='', on veut la fonction de passage URL ==> id |
|
| 1878 | + // @see charger_fonction_url |
|
| 1879 | + if (!$entite) { |
|
| 1880 | + return $f; |
|
| 1881 | + } |
|
| 1882 | + |
|
| 1883 | + // mais d'abord il faut tester le cas des urls sur une |
|
| 1884 | + // base distante |
|
| 1885 | + if ( |
|
| 1886 | + $connect |
|
| 1887 | + and $g = charger_fonction('connect', 'urls', true) |
|
| 1888 | + ) { |
|
| 1889 | + $f = $g; |
|
| 1890 | + } |
|
| 1891 | + |
|
| 1892 | + $res = $f(intval($id), $entite, $args ?: '', $ancre ?: '', $connect); |
|
| 1893 | + } |
|
| 1894 | + if ($res) { |
|
| 1895 | + return $res; |
|
| 1896 | + } |
|
| 1897 | + |
|
| 1898 | + // On a ete gentil mais la .... |
|
| 1899 | + spip_log("generer_objet_url: entite $entite ($f) inconnue $type $public $connect", _LOG_ERREUR); |
|
| 1900 | + |
|
| 1901 | + return ''; |
|
| 1903 | 1902 | } |
| 1904 | 1903 | |
| 1905 | 1904 | /** |
@@ -1907,10 +1906,10 @@ discard block |
||
| 1907 | 1906 | * @see generer_objet_url |
| 1908 | 1907 | */ |
| 1909 | 1908 | function generer_url_entite($id = 0, $entite = '', $args = '', $ancre = '', $public = null, $type = null) { |
| 1910 | - if ($public and is_string($public)) { |
|
| 1911 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 1912 | - } |
|
| 1913 | - return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 1909 | + if ($public and is_string($public)) { |
|
| 1910 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', true, $type ?? '', $public); |
|
| 1911 | + } |
|
| 1912 | + return generer_objet_url(intval($id), $entite, $args ?: '', $ancre ?: '', $public, $type ?? ''); |
|
| 1914 | 1913 | } |
| 1915 | 1914 | |
| 1916 | 1915 | /** |
@@ -1922,19 +1921,19 @@ discard block |
||
| 1922 | 1921 | * @return string |
| 1923 | 1922 | */ |
| 1924 | 1923 | function generer_objet_url_ecrire_edit($id, string $entite, string $args = '', string $ancre = ''): string { |
| 1925 | - $id = intval($id); |
|
| 1926 | - $exec = objet_info($entite, 'url_edit'); |
|
| 1927 | - $url = generer_url_ecrire($exec, $args); |
|
| 1928 | - if (intval($id)) { |
|
| 1929 | - $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1930 | - } else { |
|
| 1931 | - $url = parametre_url($url, 'new', 'oui'); |
|
| 1932 | - } |
|
| 1933 | - if ($ancre) { |
|
| 1934 | - $url = ancre_url($url, $ancre); |
|
| 1935 | - } |
|
| 1924 | + $id = intval($id); |
|
| 1925 | + $exec = objet_info($entite, 'url_edit'); |
|
| 1926 | + $url = generer_url_ecrire($exec, $args); |
|
| 1927 | + if (intval($id)) { |
|
| 1928 | + $url = parametre_url($url, id_table_objet($entite), $id); |
|
| 1929 | + } else { |
|
| 1930 | + $url = parametre_url($url, 'new', 'oui'); |
|
| 1931 | + } |
|
| 1932 | + if ($ancre) { |
|
| 1933 | + $url = ancre_url($url, $ancre); |
|
| 1934 | + } |
|
| 1936 | 1935 | |
| 1937 | - return $url; |
|
| 1936 | + return $url; |
|
| 1938 | 1937 | } |
| 1939 | 1938 | |
| 1940 | 1939 | /** |
@@ -1942,18 +1941,18 @@ discard block |
||
| 1942 | 1941 | * @see generer_objet_url_ecrire_edit |
| 1943 | 1942 | */ |
| 1944 | 1943 | function generer_url_ecrire_entite_edit($id, $entite, $args = '', $ancre = '') { |
| 1945 | - return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 1944 | + return generer_objet_url_ecrire_edit(intval($id), $entite, $args, $ancre); |
|
| 1946 | 1945 | } |
| 1947 | 1946 | |
| 1948 | 1947 | |
| 1949 | 1948 | function urls_connect_dist($i, &$entite, $args = '', $ancre = '', $public = null) { |
| 1950 | - include_spip('base/connect_sql'); |
|
| 1951 | - $id_type = id_table_objet($entite, $public); |
|
| 1949 | + include_spip('base/connect_sql'); |
|
| 1950 | + $id_type = id_table_objet($entite, $public); |
|
| 1952 | 1951 | |
| 1953 | - return _DIR_RACINE . get_spip_script('./') |
|
| 1954 | - . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1955 | - . (!$args ? '' : "&$args") |
|
| 1956 | - . (!$ancre ? '' : "#$ancre"); |
|
| 1952 | + return _DIR_RACINE . get_spip_script('./') |
|
| 1953 | + . '?' . _SPIP_PAGE . "=$entite&$id_type=$i&connect=$public" |
|
| 1954 | + . (!$args ? '' : "&$args") |
|
| 1955 | + . (!$ancre ? '' : "#$ancre"); |
|
| 1957 | 1956 | } |
| 1958 | 1957 | |
| 1959 | 1958 | |
@@ -1964,18 +1963,18 @@ discard block |
||
| 1964 | 1963 | * @return string |
| 1965 | 1964 | */ |
| 1966 | 1965 | function urlencode_1738($url) { |
| 1967 | - if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1968 | - $uri = ''; |
|
| 1969 | - for ($i = 0; $i < strlen($url); $i++) { |
|
| 1970 | - if (ord($a = $url[$i]) > 127) { |
|
| 1971 | - $a = rawurlencode($a); |
|
| 1972 | - } |
|
| 1973 | - $uri .= $a; |
|
| 1974 | - } |
|
| 1975 | - $url = $uri; |
|
| 1976 | - } |
|
| 1966 | + if (preg_match(',[^\x00-\x7E],sS', $url)) { |
|
| 1967 | + $uri = ''; |
|
| 1968 | + for ($i = 0; $i < strlen($url); $i++) { |
|
| 1969 | + if (ord($a = $url[$i]) > 127) { |
|
| 1970 | + $a = rawurlencode($a); |
|
| 1971 | + } |
|
| 1972 | + $uri .= $a; |
|
| 1973 | + } |
|
| 1974 | + $url = $uri; |
|
| 1975 | + } |
|
| 1977 | 1976 | |
| 1978 | - return quote_amp($url); |
|
| 1977 | + return quote_amp($url); |
|
| 1979 | 1978 | } |
| 1980 | 1979 | |
| 1981 | 1980 | /** |
@@ -1991,14 +1990,14 @@ discard block |
||
| 1991 | 1990 | * @return string |
| 1992 | 1991 | */ |
| 1993 | 1992 | function generer_objet_url_absolue($id = 0, string $entite = '', string $args = '', string $ancre = '', ?bool $public = null, string $type = '', string $connect = ''): string { |
| 1994 | - $id = intval($id); |
|
| 1995 | - $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 1996 | - if (!preg_match(',^\w+:,', $h)) { |
|
| 1997 | - include_spip('inc/filtres_mini'); |
|
| 1998 | - $h = url_absolue($h); |
|
| 1999 | - } |
|
| 1993 | + $id = intval($id); |
|
| 1994 | + $h = generer_objet_url($id, $entite, $args, $ancre, $public, $type, $connect); |
|
| 1995 | + if (!preg_match(',^\w+:,', $h)) { |
|
| 1996 | + include_spip('inc/filtres_mini'); |
|
| 1997 | + $h = url_absolue($h); |
|
| 1998 | + } |
|
| 2000 | 1999 | |
| 2001 | - return $h; |
|
| 2000 | + return $h; |
|
| 2002 | 2001 | } |
| 2003 | 2002 | |
| 2004 | 2003 | /** |
@@ -2006,7 +2005,7 @@ discard block |
||
| 2006 | 2005 | * @see generer_objet_url_absolue |
| 2007 | 2006 | */ |
| 2008 | 2007 | function generer_url_entite_absolue($id = 0, $entite = '', $args = '', $ancre = '', $connect = null) { |
| 2009 | - return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect); |
|
| 2008 | + return generer_objet_url_absolue(intval($id), $entite, $args, $ancre, true, '', $connect); |
|
| 2010 | 2009 | } |
| 2011 | 2010 | |
| 2012 | 2011 | |
@@ -2022,11 +2021,11 @@ discard block |
||
| 2022 | 2021 | * true si la valeur est considérée active ; false sinon. |
| 2023 | 2022 | **/ |
| 2024 | 2023 | function test_valeur_serveur($truc) { |
| 2025 | - if (!$truc) { |
|
| 2026 | - return false; |
|
| 2027 | - } |
|
| 2024 | + if (!$truc) { |
|
| 2025 | + return false; |
|
| 2026 | + } |
|
| 2028 | 2027 | |
| 2029 | - return (strtolower($truc) !== 'off'); |
|
| 2028 | + return (strtolower($truc) !== 'off'); |
|
| 2030 | 2029 | } |
| 2031 | 2030 | |
| 2032 | 2031 | // |
@@ -2054,82 +2053,82 @@ discard block |
||
| 2054 | 2053 | */ |
| 2055 | 2054 | function url_de_base($profondeur = null) { |
| 2056 | 2055 | |
| 2057 | - static $url = []; |
|
| 2058 | - if (is_array($profondeur)) { |
|
| 2059 | - return $url = $profondeur; |
|
| 2060 | - } |
|
| 2061 | - if ($profondeur === false) { |
|
| 2062 | - return $url; |
|
| 2063 | - } |
|
| 2064 | - |
|
| 2065 | - if (is_null($profondeur)) { |
|
| 2066 | - $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - if (isset($url[$profondeur])) { |
|
| 2070 | - return $url[$profondeur]; |
|
| 2071 | - } |
|
| 2072 | - |
|
| 2073 | - $http = 'http'; |
|
| 2074 | - |
|
| 2075 | - if ( |
|
| 2076 | - isset($_SERVER['SCRIPT_URI']) |
|
| 2077 | - and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 2078 | - ) { |
|
| 2079 | - $http = 'https'; |
|
| 2080 | - } elseif ( |
|
| 2081 | - isset($_SERVER['HTTPS']) |
|
| 2082 | - and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 2083 | - ) { |
|
| 2084 | - $http = 'https'; |
|
| 2085 | - } |
|
| 2086 | - |
|
| 2087 | - // note : HTTP_HOST contient le :port si necessaire |
|
| 2088 | - $host = $_SERVER['HTTP_HOST'] ?? null; |
|
| 2089 | - // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2090 | - if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2091 | - $host = $GLOBALS['meta']['adresse_site']; |
|
| 2092 | - if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2093 | - $http = $scheme; |
|
| 2094 | - $host = str_replace("{$scheme}://", '', $host); |
|
| 2095 | - } |
|
| 2096 | - } |
|
| 2097 | - if ( |
|
| 2098 | - isset($_SERVER['SERVER_PORT']) |
|
| 2099 | - and $port = $_SERVER['SERVER_PORT'] |
|
| 2100 | - and strpos($host, ':') == false |
|
| 2101 | - ) { |
|
| 2102 | - if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2103 | - define('_PORT_HTTP_STANDARD', '80'); |
|
| 2104 | - } |
|
| 2105 | - if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2106 | - define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2107 | - } |
|
| 2108 | - if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2109 | - $host .= ":$port"; |
|
| 2110 | - } |
|
| 2111 | - if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2112 | - $host .= ":$port"; |
|
| 2113 | - } |
|
| 2114 | - } |
|
| 2115 | - |
|
| 2116 | - if (!$GLOBALS['REQUEST_URI']) { |
|
| 2117 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2118 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2119 | - } else { |
|
| 2120 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2121 | - if ( |
|
| 2122 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2123 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2124 | - ) { |
|
| 2125 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2126 | - } |
|
| 2127 | - } |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2131 | - |
|
| 2132 | - return $url[$profondeur]; |
|
| 2056 | + static $url = []; |
|
| 2057 | + if (is_array($profondeur)) { |
|
| 2058 | + return $url = $profondeur; |
|
| 2059 | + } |
|
| 2060 | + if ($profondeur === false) { |
|
| 2061 | + return $url; |
|
| 2062 | + } |
|
| 2063 | + |
|
| 2064 | + if (is_null($profondeur)) { |
|
| 2065 | + $profondeur = $GLOBALS['profondeur_url'] ?? (_DIR_RESTREINT ? 0 : 1); |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + if (isset($url[$profondeur])) { |
|
| 2069 | + return $url[$profondeur]; |
|
| 2070 | + } |
|
| 2071 | + |
|
| 2072 | + $http = 'http'; |
|
| 2073 | + |
|
| 2074 | + if ( |
|
| 2075 | + isset($_SERVER['SCRIPT_URI']) |
|
| 2076 | + and substr($_SERVER['SCRIPT_URI'], 0, 5) == 'https' |
|
| 2077 | + ) { |
|
| 2078 | + $http = 'https'; |
|
| 2079 | + } elseif ( |
|
| 2080 | + isset($_SERVER['HTTPS']) |
|
| 2081 | + and test_valeur_serveur($_SERVER['HTTPS']) |
|
| 2082 | + ) { |
|
| 2083 | + $http = 'https'; |
|
| 2084 | + } |
|
| 2085 | + |
|
| 2086 | + // note : HTTP_HOST contient le :port si necessaire |
|
| 2087 | + $host = $_SERVER['HTTP_HOST'] ?? null; |
|
| 2088 | + // si on n'a pas trouvé d'hôte du tout, en dernier recours on utilise adresse_site comme fallback |
|
| 2089 | + if (is_null($host) and isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2090 | + $host = $GLOBALS['meta']['adresse_site']; |
|
| 2091 | + if ($scheme = parse_url($host, PHP_URL_SCHEME)) { |
|
| 2092 | + $http = $scheme; |
|
| 2093 | + $host = str_replace("{$scheme}://", '', $host); |
|
| 2094 | + } |
|
| 2095 | + } |
|
| 2096 | + if ( |
|
| 2097 | + isset($_SERVER['SERVER_PORT']) |
|
| 2098 | + and $port = $_SERVER['SERVER_PORT'] |
|
| 2099 | + and strpos($host, ':') == false |
|
| 2100 | + ) { |
|
| 2101 | + if (!defined('_PORT_HTTP_STANDARD')) { |
|
| 2102 | + define('_PORT_HTTP_STANDARD', '80'); |
|
| 2103 | + } |
|
| 2104 | + if (!defined('_PORT_HTTPS_STANDARD')) { |
|
| 2105 | + define('_PORT_HTTPS_STANDARD', '443'); |
|
| 2106 | + } |
|
| 2107 | + if ($http == 'http' and !in_array($port, explode(',', _PORT_HTTP_STANDARD))) { |
|
| 2108 | + $host .= ":$port"; |
|
| 2109 | + } |
|
| 2110 | + if ($http == 'https' and !in_array($port, explode(',', _PORT_HTTPS_STANDARD))) { |
|
| 2111 | + $host .= ":$port"; |
|
| 2112 | + } |
|
| 2113 | + } |
|
| 2114 | + |
|
| 2115 | + if (!$GLOBALS['REQUEST_URI']) { |
|
| 2116 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2117 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2118 | + } else { |
|
| 2119 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2120 | + if ( |
|
| 2121 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2122 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2123 | + ) { |
|
| 2124 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2125 | + } |
|
| 2126 | + } |
|
| 2127 | + } |
|
| 2128 | + |
|
| 2129 | + $url[$profondeur] = url_de_($http, $host, $GLOBALS['REQUEST_URI'], $profondeur); |
|
| 2130 | + |
|
| 2131 | + return $url[$profondeur]; |
|
| 2133 | 2132 | } |
| 2134 | 2133 | |
| 2135 | 2134 | /** |
@@ -2142,26 +2141,26 @@ discard block |
||
| 2142 | 2141 | * @return string |
| 2143 | 2142 | */ |
| 2144 | 2143 | function url_de_($http, $host, $request, $prof = 0) { |
| 2145 | - $prof = max($prof, 0); |
|
| 2144 | + $prof = max($prof, 0); |
|
| 2146 | 2145 | |
| 2147 | - $myself = ltrim($request, '/'); |
|
| 2148 | - # supprimer la chaine de GET |
|
| 2149 | - [$myself] = explode('?', $myself); |
|
| 2150 | - // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2151 | - // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2152 | - if (strpos($myself, '://') !== false) { |
|
| 2153 | - $myself = explode('://', $myself); |
|
| 2154 | - array_shift($myself); |
|
| 2155 | - $myself = implode('://', $myself); |
|
| 2156 | - $myself = explode('/', $myself); |
|
| 2157 | - array_shift($myself); |
|
| 2158 | - $myself = implode('/', $myself); |
|
| 2159 | - } |
|
| 2160 | - $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2146 | + $myself = ltrim($request, '/'); |
|
| 2147 | + # supprimer la chaine de GET |
|
| 2148 | + [$myself] = explode('?', $myself); |
|
| 2149 | + // vieux mode HTTP qui envoie après le nom de la methode l'URL compléte |
|
| 2150 | + // protocole, "://", nom du serveur avant le path dans _SERVER["REQUEST_URI"] |
|
| 2151 | + if (strpos($myself, '://') !== false) { |
|
| 2152 | + $myself = explode('://', $myself); |
|
| 2153 | + array_shift($myself); |
|
| 2154 | + $myself = implode('://', $myself); |
|
| 2155 | + $myself = explode('/', $myself); |
|
| 2156 | + array_shift($myself); |
|
| 2157 | + $myself = implode('/', $myself); |
|
| 2158 | + } |
|
| 2159 | + $url = join('/', array_slice(explode('/', $myself), 0, -1 - $prof)) . '/'; |
|
| 2161 | 2160 | |
| 2162 | - $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2161 | + $url = $http . '://' . rtrim($host, '/') . '/' . ltrim($url, '/'); |
|
| 2163 | 2162 | |
| 2164 | - return $url; |
|
| 2163 | + return $url; |
|
| 2165 | 2164 | } |
| 2166 | 2165 | |
| 2167 | 2166 | |
@@ -2196,25 +2195,25 @@ discard block |
||
| 2196 | 2195 | * @return string URL |
| 2197 | 2196 | **/ |
| 2198 | 2197 | function generer_url_ecrire($script = '', $args = '', $no_entities = false, $rel = false) { |
| 2199 | - if (!$rel) { |
|
| 2200 | - $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2201 | - } else { |
|
| 2202 | - if (!is_string($rel)) { |
|
| 2203 | - $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2204 | - } |
|
| 2205 | - } |
|
| 2206 | - |
|
| 2207 | - [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2208 | - if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2209 | - $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2210 | - } elseif ($args) { |
|
| 2211 | - $args = "?$args"; |
|
| 2212 | - } |
|
| 2213 | - if ($ancre) { |
|
| 2214 | - $args .= "#$ancre"; |
|
| 2215 | - } |
|
| 2216 | - |
|
| 2217 | - return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2198 | + if (!$rel) { |
|
| 2199 | + $rel = url_de_base() . _DIR_RESTREINT_ABS . _SPIP_ECRIRE_SCRIPT; |
|
| 2200 | + } else { |
|
| 2201 | + if (!is_string($rel)) { |
|
| 2202 | + $rel = _DIR_RESTREINT ?: './' . _SPIP_ECRIRE_SCRIPT; |
|
| 2203 | + } |
|
| 2204 | + } |
|
| 2205 | + |
|
| 2206 | + [$script, $ancre] = array_pad(explode('#', $script), 2, null); |
|
| 2207 | + if ($script and ($script <> 'accueil' or $rel)) { |
|
| 2208 | + $args = "?exec=$script" . (!$args ? '' : "&$args"); |
|
| 2209 | + } elseif ($args) { |
|
| 2210 | + $args = "?$args"; |
|
| 2211 | + } |
|
| 2212 | + if ($ancre) { |
|
| 2213 | + $args .= "#$ancre"; |
|
| 2214 | + } |
|
| 2215 | + |
|
| 2216 | + return $rel . ($no_entities ? $args : str_replace('&', '&', $args)); |
|
| 2218 | 2217 | } |
| 2219 | 2218 | |
| 2220 | 2219 | // |
@@ -2236,15 +2235,15 @@ discard block |
||
| 2236 | 2235 | * Nom du fichier (constante _SPIP_SCRIPT), sinon nom par défaut |
| 2237 | 2236 | **/ |
| 2238 | 2237 | function get_spip_script($default = '') { |
| 2239 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2240 | - return 'spip.php'; |
|
| 2241 | - } |
|
| 2242 | - # cas define('_SPIP_SCRIPT', ''); |
|
| 2243 | - if (_SPIP_SCRIPT) { |
|
| 2244 | - return _SPIP_SCRIPT; |
|
| 2245 | - } else { |
|
| 2246 | - return $default; |
|
| 2247 | - } |
|
| 2238 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2239 | + return 'spip.php'; |
|
| 2240 | + } |
|
| 2241 | + # cas define('_SPIP_SCRIPT', ''); |
|
| 2242 | + if (_SPIP_SCRIPT) { |
|
| 2243 | + return _SPIP_SCRIPT; |
|
| 2244 | + } else { |
|
| 2245 | + return $default; |
|
| 2246 | + } |
|
| 2248 | 2247 | } |
| 2249 | 2248 | |
| 2250 | 2249 | /** |
@@ -2273,45 +2272,45 @@ discard block |
||
| 2273 | 2272 | * @return string URL |
| 2274 | 2273 | **/ |
| 2275 | 2274 | function generer_url_public($script = '', $args = '', $no_entities = false, $rel = true, $action = '') { |
| 2276 | - // si le script est une action (spip_pass, spip_inscription), |
|
| 2277 | - // standardiser vers la nouvelle API |
|
| 2278 | - |
|
| 2279 | - if (is_array($args)) { |
|
| 2280 | - $args = http_build_query($args); |
|
| 2281 | - } |
|
| 2282 | - |
|
| 2283 | - $url = ''; |
|
| 2284 | - if ($f = charger_fonction_url('page')) { |
|
| 2285 | - $url = $f($script, $args); |
|
| 2286 | - if ($url and !$rel) { |
|
| 2287 | - include_spip('inc/filtres_mini'); |
|
| 2288 | - $url = url_absolue($url); |
|
| 2289 | - } |
|
| 2290 | - } |
|
| 2291 | - if (!$url) { |
|
| 2292 | - if (!$action) { |
|
| 2293 | - $action = get_spip_script(); |
|
| 2294 | - } |
|
| 2295 | - if ($script) { |
|
| 2296 | - $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2297 | - } |
|
| 2298 | - if ($args) { |
|
| 2299 | - $action .= (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2300 | - } |
|
| 2301 | - // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2302 | - $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2303 | - } |
|
| 2304 | - |
|
| 2305 | - if (!$no_entities) { |
|
| 2306 | - $url = quote_amp($url); |
|
| 2307 | - } |
|
| 2308 | - |
|
| 2309 | - return $url; |
|
| 2275 | + // si le script est une action (spip_pass, spip_inscription), |
|
| 2276 | + // standardiser vers la nouvelle API |
|
| 2277 | + |
|
| 2278 | + if (is_array($args)) { |
|
| 2279 | + $args = http_build_query($args); |
|
| 2280 | + } |
|
| 2281 | + |
|
| 2282 | + $url = ''; |
|
| 2283 | + if ($f = charger_fonction_url('page')) { |
|
| 2284 | + $url = $f($script, $args); |
|
| 2285 | + if ($url and !$rel) { |
|
| 2286 | + include_spip('inc/filtres_mini'); |
|
| 2287 | + $url = url_absolue($url); |
|
| 2288 | + } |
|
| 2289 | + } |
|
| 2290 | + if (!$url) { |
|
| 2291 | + if (!$action) { |
|
| 2292 | + $action = get_spip_script(); |
|
| 2293 | + } |
|
| 2294 | + if ($script) { |
|
| 2295 | + $action = parametre_url($action, _SPIP_PAGE, $script, '&'); |
|
| 2296 | + } |
|
| 2297 | + if ($args) { |
|
| 2298 | + $action .= (strpos($action, '?') !== false ? '&' : '?') . $args; |
|
| 2299 | + } |
|
| 2300 | + // ne pas generer une url avec /./?page= en cas d'url absolue et de _SPIP_SCRIPT vide |
|
| 2301 | + $url = ($rel ? _DIR_RACINE . $action : rtrim(url_de_base(), '/') . preg_replace(',^/[.]/,', '/', "/$action")); |
|
| 2302 | + } |
|
| 2303 | + |
|
| 2304 | + if (!$no_entities) { |
|
| 2305 | + $url = quote_amp($url); |
|
| 2306 | + } |
|
| 2307 | + |
|
| 2308 | + return $url; |
|
| 2310 | 2309 | } |
| 2311 | 2310 | |
| 2312 | 2311 | function generer_url_prive($script, $args = '', $no_entities = false) { |
| 2313 | 2312 | |
| 2314 | - return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2313 | + return generer_url_public($script, $args, $no_entities, false, _DIR_RESTREINT_ABS . 'prive.php'); |
|
| 2315 | 2314 | } |
| 2316 | 2315 | |
| 2317 | 2316 | // Pour les formulaires en methode POST, |
@@ -2336,19 +2335,19 @@ discard block |
||
| 2336 | 2335 | **/ |
| 2337 | 2336 | function generer_form_ecrire($script, $corps, $atts = '', $submit = '') { |
| 2338 | 2337 | |
| 2339 | - $script1 = explode('&', $script); |
|
| 2340 | - $script1 = reset($script1); |
|
| 2338 | + $script1 = explode('&', $script); |
|
| 2339 | + $script1 = reset($script1); |
|
| 2341 | 2340 | |
| 2342 | - return "<form action='" |
|
| 2343 | - . ($script ? generer_url_ecrire($script) : '') |
|
| 2344 | - . "' " |
|
| 2345 | - . ($atts ?: " method='post'") |
|
| 2346 | - . "><div>\n" |
|
| 2347 | - . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2348 | - . $corps |
|
| 2349 | - . (!$submit ? '' : |
|
| 2350 | - ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2351 | - . "</div></form>\n"; |
|
| 2341 | + return "<form action='" |
|
| 2342 | + . ($script ? generer_url_ecrire($script) : '') |
|
| 2343 | + . "' " |
|
| 2344 | + . ($atts ?: " method='post'") |
|
| 2345 | + . "><div>\n" |
|
| 2346 | + . "<input type='hidden' name='exec' value='$script1' />" |
|
| 2347 | + . $corps |
|
| 2348 | + . (!$submit ? '' : |
|
| 2349 | + ("<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><input class='fondo submit btn' type='submit' value=\"" . entites_html($submit) . '" /></div>')) |
|
| 2350 | + . "</div></form>\n"; |
|
| 2352 | 2351 | } |
| 2353 | 2352 | |
| 2354 | 2353 | /** |
@@ -2365,22 +2364,22 @@ discard block |
||
| 2365 | 2364 | * @return string |
| 2366 | 2365 | */ |
| 2367 | 2366 | function generer_form_action($script, $corps, $atts = '', $public = false) { |
| 2368 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2369 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2370 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2371 | - $h = (_DIR_RACINE and !$public) |
|
| 2372 | - ? generer_url_ecrire(_request('exec')) |
|
| 2373 | - : generer_url_public(); |
|
| 2367 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2368 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2369 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2370 | + $h = (_DIR_RACINE and !$public) |
|
| 2371 | + ? generer_url_ecrire(_request('exec')) |
|
| 2372 | + : generer_url_public(); |
|
| 2374 | 2373 | |
| 2375 | - return "\n<form action='" . |
|
| 2376 | - $h . |
|
| 2377 | - "'" . |
|
| 2378 | - $atts . |
|
| 2379 | - ">\n" . |
|
| 2380 | - '<div>' . |
|
| 2381 | - "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2382 | - $corps . |
|
| 2383 | - '</div></form>'; |
|
| 2374 | + return "\n<form action='" . |
|
| 2375 | + $h . |
|
| 2376 | + "'" . |
|
| 2377 | + $atts . |
|
| 2378 | + ">\n" . |
|
| 2379 | + '<div>' . |
|
| 2380 | + "\n<input type='hidden' name='action' value='$script' />" . |
|
| 2381 | + $corps . |
|
| 2382 | + '</div></form>'; |
|
| 2384 | 2383 | } |
| 2385 | 2384 | |
| 2386 | 2385 | /** |
@@ -2399,22 +2398,22 @@ discard block |
||
| 2399 | 2398 | * URL |
| 2400 | 2399 | */ |
| 2401 | 2400 | function generer_url_action($script, $args = '', $no_entities = false, $public = false) { |
| 2402 | - // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2403 | - // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2404 | - // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2405 | - $url = (_DIR_RACINE and !$public) |
|
| 2406 | - ? generer_url_ecrire(_request('exec')) |
|
| 2407 | - : generer_url_public('', '', false, false); |
|
| 2408 | - $url = parametre_url($url, 'action', $script); |
|
| 2409 | - if ($args) { |
|
| 2410 | - $url .= quote_amp('&' . $args); |
|
| 2411 | - } |
|
| 2401 | + // si l'on est dans l'espace prive, on garde dans l'url |
|
| 2402 | + // l'exec a l'origine de l'action, qui permet de savoir si il est necessaire |
|
| 2403 | + // ou non de proceder a l'authentification (cas typique de l'install par exemple) |
|
| 2404 | + $url = (_DIR_RACINE and !$public) |
|
| 2405 | + ? generer_url_ecrire(_request('exec')) |
|
| 2406 | + : generer_url_public('', '', false, false); |
|
| 2407 | + $url = parametre_url($url, 'action', $script); |
|
| 2408 | + if ($args) { |
|
| 2409 | + $url .= quote_amp('&' . $args); |
|
| 2410 | + } |
|
| 2412 | 2411 | |
| 2413 | - if ($no_entities) { |
|
| 2414 | - $url = str_replace('&', '&', $url); |
|
| 2415 | - } |
|
| 2412 | + if ($no_entities) { |
|
| 2413 | + $url = str_replace('&', '&', $url); |
|
| 2414 | + } |
|
| 2416 | 2415 | |
| 2417 | - return $url; |
|
| 2416 | + return $url; |
|
| 2418 | 2417 | } |
| 2419 | 2418 | |
| 2420 | 2419 | |
@@ -2433,23 +2432,23 @@ discard block |
||
| 2433 | 2432 | * URL |
| 2434 | 2433 | */ |
| 2435 | 2434 | function generer_url_api(string $script, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 2436 | - if (is_null($public)) { |
|
| 2437 | - $public = (_DIR_RACINE ? false : ''); |
|
| 2438 | - } |
|
| 2439 | - if (substr($script, -4) !== '.api') { |
|
| 2440 | - $script .= '.api'; |
|
| 2441 | - } |
|
| 2442 | - $url = |
|
| 2443 | - (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 2444 | - . $script . '/' |
|
| 2445 | - . ($path ? trim($path, '/') : '') |
|
| 2446 | - . ($args ? '?' . quote_amp($args) : ''); |
|
| 2435 | + if (is_null($public)) { |
|
| 2436 | + $public = (_DIR_RACINE ? false : ''); |
|
| 2437 | + } |
|
| 2438 | + if (substr($script, -4) !== '.api') { |
|
| 2439 | + $script .= '.api'; |
|
| 2440 | + } |
|
| 2441 | + $url = |
|
| 2442 | + (($public ? _DIR_RACINE : _DIR_RESTREINT) ?: './') |
|
| 2443 | + . $script . '/' |
|
| 2444 | + . ($path ? trim($path, '/') : '') |
|
| 2445 | + . ($args ? '?' . quote_amp($args) : ''); |
|
| 2447 | 2446 | |
| 2448 | - if ($no_entities) { |
|
| 2449 | - $url = str_replace('&', '&', $url); |
|
| 2450 | - } |
|
| 2447 | + if ($no_entities) { |
|
| 2448 | + $url = str_replace('&', '&', $url); |
|
| 2449 | + } |
|
| 2451 | 2450 | |
| 2452 | - return $url; |
|
| 2451 | + return $url; |
|
| 2453 | 2452 | } |
| 2454 | 2453 | |
| 2455 | 2454 | |
@@ -2462,8 +2461,8 @@ discard block |
||
| 2462 | 2461 | * @param string $ta Répertoire temporaire accessible |
| 2463 | 2462 | */ |
| 2464 | 2463 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2465 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2466 | - spip_initialisation_suite(); |
|
| 2464 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 2465 | + spip_initialisation_suite(); |
|
| 2467 | 2466 | } |
| 2468 | 2467 | |
| 2469 | 2468 | /** |
@@ -2483,322 +2482,322 @@ discard block |
||
| 2483 | 2482 | * @param string $ta Répertoire temporaire accessible |
| 2484 | 2483 | */ |
| 2485 | 2484 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 2486 | - static $too_late = 0; |
|
| 2487 | - if ($too_late++) { |
|
| 2488 | - return; |
|
| 2489 | - } |
|
| 2490 | - |
|
| 2491 | - // Declaration des repertoires |
|
| 2492 | - |
|
| 2493 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 2494 | - if (!defined('_DIR_PLUGINS')) { |
|
| 2495 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2496 | - } |
|
| 2497 | - |
|
| 2498 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2499 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2500 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2501 | - } |
|
| 2502 | - |
|
| 2503 | - // le nom du repertoire des librairies |
|
| 2504 | - if (!defined('_DIR_LIB')) { |
|
| 2505 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2506 | - } |
|
| 2507 | - |
|
| 2508 | - if (!defined('_DIR_IMG')) { |
|
| 2509 | - define('_DIR_IMG', $pa); |
|
| 2510 | - } |
|
| 2511 | - if (!defined('_DIR_LOGOS')) { |
|
| 2512 | - define('_DIR_LOGOS', $pa); |
|
| 2513 | - } |
|
| 2514 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 2515 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2516 | - } |
|
| 2517 | - |
|
| 2518 | - if (!defined('_DIR_DUMP')) { |
|
| 2519 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2520 | - } |
|
| 2521 | - if (!defined('_DIR_SESSIONS')) { |
|
| 2522 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2523 | - } |
|
| 2524 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 2525 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2526 | - } |
|
| 2527 | - if (!defined('_DIR_CACHE')) { |
|
| 2528 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2529 | - } |
|
| 2530 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 2531 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2532 | - } |
|
| 2533 | - if (!defined('_DIR_SKELS')) { |
|
| 2534 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2535 | - } |
|
| 2536 | - if (!defined('_DIR_AIDE')) { |
|
| 2537 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2538 | - } |
|
| 2539 | - if (!defined('_DIR_TMP')) { |
|
| 2540 | - define('_DIR_TMP', $ti); |
|
| 2541 | - } |
|
| 2542 | - |
|
| 2543 | - if (!defined('_DIR_VAR')) { |
|
| 2544 | - define('_DIR_VAR', $ta); |
|
| 2545 | - } |
|
| 2546 | - |
|
| 2547 | - if (!defined('_DIR_ETC')) { |
|
| 2548 | - define('_DIR_ETC', $pi); |
|
| 2549 | - } |
|
| 2550 | - if (!defined('_DIR_CONNECT')) { |
|
| 2551 | - define('_DIR_CONNECT', $pi); |
|
| 2552 | - } |
|
| 2553 | - if (!defined('_DIR_CHMOD')) { |
|
| 2554 | - define('_DIR_CHMOD', $pi); |
|
| 2555 | - } |
|
| 2556 | - |
|
| 2557 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 2558 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2559 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2560 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2561 | - } |
|
| 2562 | - |
|
| 2563 | - // Declaration des fichiers |
|
| 2564 | - |
|
| 2565 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2566 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2567 | - } |
|
| 2568 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2569 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2570 | - } |
|
| 2571 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2572 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2573 | - } |
|
| 2574 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 2575 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2576 | - } |
|
| 2577 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 2578 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2579 | - } |
|
| 2580 | - |
|
| 2581 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2582 | - if (!defined('_FILE_META')) { |
|
| 2583 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2584 | - } |
|
| 2585 | - if (!defined('_DIR_LOG')) { |
|
| 2586 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2587 | - } |
|
| 2588 | - if (!defined('_FILE_LOG')) { |
|
| 2589 | - define('_FILE_LOG', 'spip'); |
|
| 2590 | - } |
|
| 2591 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2592 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2593 | - } |
|
| 2594 | - |
|
| 2595 | - // Le fichier de connexion a la base de donnees |
|
| 2596 | - // tient compte des anciennes versions (inc_connect...) |
|
| 2597 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 2598 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 2599 | - } |
|
| 2600 | - if (!defined('_FILE_CONNECT')) { |
|
| 2601 | - define( |
|
| 2602 | - '_FILE_CONNECT', |
|
| 2603 | - (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2604 | - : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2605 | - : false)) |
|
| 2606 | - ); |
|
| 2607 | - } |
|
| 2608 | - |
|
| 2609 | - // Le fichier de reglages des droits |
|
| 2610 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 2611 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2612 | - } |
|
| 2613 | - if (!defined('_FILE_CHMOD')) { |
|
| 2614 | - define( |
|
| 2615 | - '_FILE_CHMOD', |
|
| 2616 | - (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2617 | - : false) |
|
| 2618 | - ); |
|
| 2619 | - } |
|
| 2620 | - |
|
| 2621 | - if (!defined('_FILE_LDAP')) { |
|
| 2622 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 2623 | - } |
|
| 2624 | - |
|
| 2625 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2626 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2627 | - } |
|
| 2628 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2629 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2630 | - } |
|
| 2631 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2632 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2633 | - } |
|
| 2634 | - |
|
| 2635 | - // Definition des droits d'acces en ecriture |
|
| 2636 | - if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2637 | - include_once _FILE_CHMOD; |
|
| 2638 | - } |
|
| 2639 | - |
|
| 2640 | - // Se mefier des fichiers mal remplis! |
|
| 2641 | - if (!defined('_SPIP_CHMOD')) { |
|
| 2642 | - define('_SPIP_CHMOD', 0777); |
|
| 2643 | - } |
|
| 2644 | - |
|
| 2645 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 2646 | - /** Le charset par défaut lors de l'installation */ |
|
| 2647 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2648 | - } |
|
| 2649 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 2650 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2651 | - } |
|
| 2652 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2653 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2654 | - } |
|
| 2655 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2656 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2657 | - } |
|
| 2658 | - |
|
| 2659 | - // La taille des Log |
|
| 2660 | - if (!defined('_MAX_LOG')) { |
|
| 2661 | - define('_MAX_LOG', 100); |
|
| 2662 | - } |
|
| 2663 | - |
|
| 2664 | - // Sommes-nous dans l'empire du Mal ? |
|
| 2665 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2666 | - if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2667 | - if (!defined('_OS_SERVEUR')) { |
|
| 2668 | - define('_OS_SERVEUR', 'windows'); |
|
| 2669 | - } |
|
| 2670 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2671 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2672 | - } // utiliser le flock php |
|
| 2673 | - } else { |
|
| 2674 | - if (!defined('_OS_SERVEUR')) { |
|
| 2675 | - define('_OS_SERVEUR', ''); |
|
| 2676 | - } |
|
| 2677 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2678 | - define('_SPIP_LOCK_MODE', 1); |
|
| 2679 | - } // utiliser le flock php |
|
| 2680 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2681 | - } |
|
| 2682 | - |
|
| 2683 | - // Langue par defaut |
|
| 2684 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2685 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2686 | - } |
|
| 2687 | - |
|
| 2688 | - // |
|
| 2689 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2690 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2691 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2692 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2693 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2694 | - |
|
| 2695 | - // charger tout de suite le path et son cache |
|
| 2696 | - load_path_cache(); |
|
| 2697 | - |
|
| 2698 | - // *********** traiter les variables ************ |
|
| 2699 | - |
|
| 2700 | - // |
|
| 2701 | - // Securite |
|
| 2702 | - // |
|
| 2703 | - |
|
| 2704 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2705 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 2706 | - die(); |
|
| 2707 | - } |
|
| 2708 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2709 | - spip_desinfecte($_GET); |
|
| 2710 | - spip_desinfecte($_POST); |
|
| 2711 | - spip_desinfecte($_COOKIE); |
|
| 2712 | - spip_desinfecte($_REQUEST); |
|
| 2713 | - |
|
| 2714 | - // appliquer le cookie_prefix |
|
| 2715 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2716 | - include_spip('inc/cookie'); |
|
| 2717 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2718 | - } |
|
| 2719 | - |
|
| 2720 | - // |
|
| 2721 | - // Capacites php (en fonction de la version) |
|
| 2722 | - // |
|
| 2723 | - $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2724 | - && function_exists('ini_get') |
|
| 2725 | - && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2726 | - $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2727 | - $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2728 | - $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2729 | - (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2730 | - |
|
| 2731 | - |
|
| 2732 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2733 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2734 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2735 | - } else { |
|
| 2736 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2737 | - if ( |
|
| 2738 | - !empty($_SERVER['QUERY_STRING']) |
|
| 2739 | - and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2740 | - ) { |
|
| 2741 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2742 | - } |
|
| 2743 | - } |
|
| 2744 | - |
|
| 2745 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2746 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2747 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2748 | - } |
|
| 2749 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2750 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2751 | - } |
|
| 2752 | - |
|
| 2753 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 2754 | - // charge aussi effacer_meta et ecrire_meta |
|
| 2755 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2756 | - $inc_meta(); |
|
| 2757 | - |
|
| 2758 | - // nombre de repertoires depuis la racine |
|
| 2759 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2760 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2761 | - // le calcul est faux) |
|
| 2762 | - if (!_DIR_RESTREINT) { |
|
| 2763 | - $GLOBALS['profondeur_url'] = 1; |
|
| 2764 | - } else { |
|
| 2765 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2766 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2767 | - if ( |
|
| 2768 | - !$uri_ref |
|
| 2769 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2770 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2771 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2772 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2773 | - or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2774 | - ) { |
|
| 2775 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2776 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2777 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2778 | - } else { |
|
| 2779 | - $uri_ref = ''; |
|
| 2780 | - } |
|
| 2781 | - } |
|
| 2782 | - if (!$uri or !$uri_ref) { |
|
| 2783 | - $GLOBALS['profondeur_url'] = 0; |
|
| 2784 | - } else { |
|
| 2785 | - $GLOBALS['profondeur_url'] = max( |
|
| 2786 | - 0, |
|
| 2787 | - substr_count($uri[0], '/') |
|
| 2788 | - - substr_count($uri_ref, '/') |
|
| 2789 | - ); |
|
| 2790 | - } |
|
| 2791 | - } |
|
| 2792 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2793 | - if (_FILE_CONNECT) { |
|
| 2794 | - if ( |
|
| 2795 | - verifier_visiteur() == '0minirezo' |
|
| 2796 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2797 | - and !isset($_COOKIE['spip_admin']) |
|
| 2798 | - ) { |
|
| 2799 | - clear_path_cache(); |
|
| 2800 | - } |
|
| 2801 | - } |
|
| 2485 | + static $too_late = 0; |
|
| 2486 | + if ($too_late++) { |
|
| 2487 | + return; |
|
| 2488 | + } |
|
| 2489 | + |
|
| 2490 | + // Declaration des repertoires |
|
| 2491 | + |
|
| 2492 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 2493 | + if (!defined('_DIR_PLUGINS')) { |
|
| 2494 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 2498 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 2499 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 2500 | + } |
|
| 2501 | + |
|
| 2502 | + // le nom du repertoire des librairies |
|
| 2503 | + if (!defined('_DIR_LIB')) { |
|
| 2504 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 2505 | + } |
|
| 2506 | + |
|
| 2507 | + if (!defined('_DIR_IMG')) { |
|
| 2508 | + define('_DIR_IMG', $pa); |
|
| 2509 | + } |
|
| 2510 | + if (!defined('_DIR_LOGOS')) { |
|
| 2511 | + define('_DIR_LOGOS', $pa); |
|
| 2512 | + } |
|
| 2513 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 2514 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 2515 | + } |
|
| 2516 | + |
|
| 2517 | + if (!defined('_DIR_DUMP')) { |
|
| 2518 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 2519 | + } |
|
| 2520 | + if (!defined('_DIR_SESSIONS')) { |
|
| 2521 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 2522 | + } |
|
| 2523 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 2524 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 2525 | + } |
|
| 2526 | + if (!defined('_DIR_CACHE')) { |
|
| 2527 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 2528 | + } |
|
| 2529 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 2530 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 2531 | + } |
|
| 2532 | + if (!defined('_DIR_SKELS')) { |
|
| 2533 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 2534 | + } |
|
| 2535 | + if (!defined('_DIR_AIDE')) { |
|
| 2536 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 2537 | + } |
|
| 2538 | + if (!defined('_DIR_TMP')) { |
|
| 2539 | + define('_DIR_TMP', $ti); |
|
| 2540 | + } |
|
| 2541 | + |
|
| 2542 | + if (!defined('_DIR_VAR')) { |
|
| 2543 | + define('_DIR_VAR', $ta); |
|
| 2544 | + } |
|
| 2545 | + |
|
| 2546 | + if (!defined('_DIR_ETC')) { |
|
| 2547 | + define('_DIR_ETC', $pi); |
|
| 2548 | + } |
|
| 2549 | + if (!defined('_DIR_CONNECT')) { |
|
| 2550 | + define('_DIR_CONNECT', $pi); |
|
| 2551 | + } |
|
| 2552 | + if (!defined('_DIR_CHMOD')) { |
|
| 2553 | + define('_DIR_CHMOD', $pi); |
|
| 2554 | + } |
|
| 2555 | + |
|
| 2556 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 2557 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 2558 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 2559 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 2560 | + } |
|
| 2561 | + |
|
| 2562 | + // Declaration des fichiers |
|
| 2563 | + |
|
| 2564 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 2565 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 2566 | + } |
|
| 2567 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 2568 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 2569 | + } |
|
| 2570 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 2571 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 2572 | + } |
|
| 2573 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 2574 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 2575 | + } |
|
| 2576 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 2577 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 2578 | + } |
|
| 2579 | + |
|
| 2580 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 2581 | + if (!defined('_FILE_META')) { |
|
| 2582 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 2583 | + } |
|
| 2584 | + if (!defined('_DIR_LOG')) { |
|
| 2585 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 2586 | + } |
|
| 2587 | + if (!defined('_FILE_LOG')) { |
|
| 2588 | + define('_FILE_LOG', 'spip'); |
|
| 2589 | + } |
|
| 2590 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 2591 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 2592 | + } |
|
| 2593 | + |
|
| 2594 | + // Le fichier de connexion a la base de donnees |
|
| 2595 | + // tient compte des anciennes versions (inc_connect...) |
|
| 2596 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 2597 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 2598 | + } |
|
| 2599 | + if (!defined('_FILE_CONNECT')) { |
|
| 2600 | + define( |
|
| 2601 | + '_FILE_CONNECT', |
|
| 2602 | + (@is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f |
|
| 2603 | + : (@is_readable($f = _DIR_RESTREINT . 'inc_connect.php') ? $f |
|
| 2604 | + : false)) |
|
| 2605 | + ); |
|
| 2606 | + } |
|
| 2607 | + |
|
| 2608 | + // Le fichier de reglages des droits |
|
| 2609 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 2610 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 2611 | + } |
|
| 2612 | + if (!defined('_FILE_CHMOD')) { |
|
| 2613 | + define( |
|
| 2614 | + '_FILE_CHMOD', |
|
| 2615 | + (@is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f |
|
| 2616 | + : false) |
|
| 2617 | + ); |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + if (!defined('_FILE_LDAP')) { |
|
| 2621 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 2622 | + } |
|
| 2623 | + |
|
| 2624 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 2625 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 2626 | + } |
|
| 2627 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 2628 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 2629 | + } |
|
| 2630 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 2631 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 2632 | + } |
|
| 2633 | + |
|
| 2634 | + // Definition des droits d'acces en ecriture |
|
| 2635 | + if (!defined('_SPIP_CHMOD') and _FILE_CHMOD) { |
|
| 2636 | + include_once _FILE_CHMOD; |
|
| 2637 | + } |
|
| 2638 | + |
|
| 2639 | + // Se mefier des fichiers mal remplis! |
|
| 2640 | + if (!defined('_SPIP_CHMOD')) { |
|
| 2641 | + define('_SPIP_CHMOD', 0777); |
|
| 2642 | + } |
|
| 2643 | + |
|
| 2644 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 2645 | + /** Le charset par défaut lors de l'installation */ |
|
| 2646 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 2647 | + } |
|
| 2648 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 2649 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins/'); |
|
| 2650 | + } |
|
| 2651 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 2652 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist/'); |
|
| 2653 | + } |
|
| 2654 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 2655 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 2656 | + } |
|
| 2657 | + |
|
| 2658 | + // La taille des Log |
|
| 2659 | + if (!defined('_MAX_LOG')) { |
|
| 2660 | + define('_MAX_LOG', 100); |
|
| 2661 | + } |
|
| 2662 | + |
|
| 2663 | + // Sommes-nous dans l'empire du Mal ? |
|
| 2664 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 2665 | + if (isset($_SERVER['SERVER_SOFTWARE']) and strpos($_SERVER['SERVER_SOFTWARE'], '(Win') !== false) { |
|
| 2666 | + if (!defined('_OS_SERVEUR')) { |
|
| 2667 | + define('_OS_SERVEUR', 'windows'); |
|
| 2668 | + } |
|
| 2669 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2670 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2671 | + } // utiliser le flock php |
|
| 2672 | + } else { |
|
| 2673 | + if (!defined('_OS_SERVEUR')) { |
|
| 2674 | + define('_OS_SERVEUR', ''); |
|
| 2675 | + } |
|
| 2676 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 2677 | + define('_SPIP_LOCK_MODE', 1); |
|
| 2678 | + } // utiliser le flock php |
|
| 2679 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 2680 | + } |
|
| 2681 | + |
|
| 2682 | + // Langue par defaut |
|
| 2683 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 2684 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 2685 | + } |
|
| 2686 | + |
|
| 2687 | + // |
|
| 2688 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 2689 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 2690 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 2691 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 2692 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 2693 | + |
|
| 2694 | + // charger tout de suite le path et son cache |
|
| 2695 | + load_path_cache(); |
|
| 2696 | + |
|
| 2697 | + // *********** traiter les variables ************ |
|
| 2698 | + |
|
| 2699 | + // |
|
| 2700 | + // Securite |
|
| 2701 | + // |
|
| 2702 | + |
|
| 2703 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 2704 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 2705 | + die(); |
|
| 2706 | + } |
|
| 2707 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 2708 | + spip_desinfecte($_GET); |
|
| 2709 | + spip_desinfecte($_POST); |
|
| 2710 | + spip_desinfecte($_COOKIE); |
|
| 2711 | + spip_desinfecte($_REQUEST); |
|
| 2712 | + |
|
| 2713 | + // appliquer le cookie_prefix |
|
| 2714 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 2715 | + include_spip('inc/cookie'); |
|
| 2716 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 2717 | + } |
|
| 2718 | + |
|
| 2719 | + // |
|
| 2720 | + // Capacites php (en fonction de la version) |
|
| 2721 | + // |
|
| 2722 | + $GLOBALS['flag_ob'] = (function_exists('ob_start') |
|
| 2723 | + && function_exists('ini_get') |
|
| 2724 | + && !strstr(@ini_get('disable_functions'), 'ob_')); |
|
| 2725 | + $GLOBALS['flag_sapi_name'] = function_exists('php_sapi_name'); |
|
| 2726 | + $GLOBALS['flag_get_cfg_var'] = (@get_cfg_var('error_reporting') != ''); |
|
| 2727 | + $GLOBALS['flag_upload'] = (!$GLOBALS['flag_get_cfg_var'] || |
|
| 2728 | + (get_cfg_var('upload_max_filesize') > 0)); |
|
| 2729 | + |
|
| 2730 | + |
|
| 2731 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 2732 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 2733 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 2734 | + } else { |
|
| 2735 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 2736 | + if ( |
|
| 2737 | + !empty($_SERVER['QUERY_STRING']) |
|
| 2738 | + and !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 2739 | + ) { |
|
| 2740 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 2741 | + } |
|
| 2742 | + } |
|
| 2743 | + |
|
| 2744 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 2745 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 2746 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 2747 | + } |
|
| 2748 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 2749 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 2750 | + } |
|
| 2751 | + |
|
| 2752 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 2753 | + // charge aussi effacer_meta et ecrire_meta |
|
| 2754 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 2755 | + $inc_meta(); |
|
| 2756 | + |
|
| 2757 | + // nombre de repertoires depuis la racine |
|
| 2758 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 2759 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 2760 | + // le calcul est faux) |
|
| 2761 | + if (!_DIR_RESTREINT) { |
|
| 2762 | + $GLOBALS['profondeur_url'] = 1; |
|
| 2763 | + } else { |
|
| 2764 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 2765 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 2766 | + if ( |
|
| 2767 | + !$uri_ref |
|
| 2768 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 2769 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 2770 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 2771 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 2772 | + or $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 2773 | + ) { |
|
| 2774 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 2775 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 2776 | + $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 2777 | + } else { |
|
| 2778 | + $uri_ref = ''; |
|
| 2779 | + } |
|
| 2780 | + } |
|
| 2781 | + if (!$uri or !$uri_ref) { |
|
| 2782 | + $GLOBALS['profondeur_url'] = 0; |
|
| 2783 | + } else { |
|
| 2784 | + $GLOBALS['profondeur_url'] = max( |
|
| 2785 | + 0, |
|
| 2786 | + substr_count($uri[0], '/') |
|
| 2787 | + - substr_count($uri_ref, '/') |
|
| 2788 | + ); |
|
| 2789 | + } |
|
| 2790 | + } |
|
| 2791 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 2792 | + if (_FILE_CONNECT) { |
|
| 2793 | + if ( |
|
| 2794 | + verifier_visiteur() == '0minirezo' |
|
| 2795 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 2796 | + and !isset($_COOKIE['spip_admin']) |
|
| 2797 | + ) { |
|
| 2798 | + clear_path_cache(); |
|
| 2799 | + } |
|
| 2800 | + } |
|
| 2802 | 2801 | } |
| 2803 | 2802 | |
| 2804 | 2803 | /** |
@@ -2807,157 +2806,157 @@ discard block |
||
| 2807 | 2806 | * |
| 2808 | 2807 | */ |
| 2809 | 2808 | function spip_initialisation_suite() { |
| 2810 | - static $too_late = 0; |
|
| 2811 | - if ($too_late++) { |
|
| 2812 | - return; |
|
| 2813 | - } |
|
| 2814 | - |
|
| 2815 | - // taille mini des login |
|
| 2816 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2817 | - define('_LOGIN_TROP_COURT', 4); |
|
| 2818 | - } |
|
| 2819 | - |
|
| 2820 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2821 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2822 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2823 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2824 | - |
|
| 2825 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2826 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2827 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2828 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2829 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2830 | - |
|
| 2831 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2832 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 2833 | - } |
|
| 2834 | - |
|
| 2835 | - // largeur maximale des images dans l'administration |
|
| 2836 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2837 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2838 | - } |
|
| 2839 | - |
|
| 2840 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2841 | - if (!defined('_IMG_QUALITE')) { |
|
| 2842 | - define('_IMG_QUALITE', 85); |
|
| 2843 | - } # valeur par defaut |
|
| 2844 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 2845 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2846 | - } # surcharge pour la lib GD |
|
| 2847 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2848 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2849 | - } # surcharge pour imagick en ligne de commande |
|
| 2850 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2851 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2852 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2853 | - } # surcharge pour imagick en PHP |
|
| 2854 | - |
|
| 2855 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2856 | - define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2857 | - } // poids en octet |
|
| 2858 | - |
|
| 2859 | - // qq chaines standard |
|
| 2860 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2861 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2862 | - } |
|
| 2863 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 2864 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2865 | - } |
|
| 2866 | - if (!defined('_SPIP_DUMP')) { |
|
| 2867 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2868 | - } |
|
| 2869 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2870 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2871 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2872 | - } |
|
| 2873 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2874 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2875 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2876 | - } |
|
| 2877 | - |
|
| 2878 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2879 | - /** |
|
| 2880 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2881 | - * @var int Nombre de caractères */ |
|
| 2882 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2883 | - } |
|
| 2884 | - |
|
| 2885 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2886 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2887 | - } |
|
| 2888 | - |
|
| 2889 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2890 | - /** Définit le doctype de l’espace privé */ |
|
| 2891 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2892 | - } |
|
| 2893 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 2894 | - /** Définit le doctype de l’aide en ligne */ |
|
| 2895 | - define( |
|
| 2896 | - '_DOCTYPE_AIDE', |
|
| 2897 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2898 | - ); |
|
| 2899 | - } |
|
| 2900 | - |
|
| 2901 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 2902 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2903 | - * le script de l'espace public, alias index.php */ |
|
| 2904 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2905 | - } |
|
| 2906 | - if (!defined('_SPIP_PAGE')) { |
|
| 2907 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2908 | - define('_SPIP_PAGE', 'page'); |
|
| 2909 | - } |
|
| 2910 | - |
|
| 2911 | - // le script de l'espace prive |
|
| 2912 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2913 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2914 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2915 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2916 | - if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2917 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2918 | - } else { |
|
| 2919 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2920 | - } |
|
| 2921 | - } |
|
| 2922 | - |
|
| 2923 | - |
|
| 2924 | - if (!defined('_SPIP_AJAX')) { |
|
| 2925 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2926 | - ? 1 |
|
| 2927 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2928 | - } |
|
| 2929 | - |
|
| 2930 | - // La requete est-elle en ajax ? |
|
| 2931 | - if (!defined('_AJAX')) { |
|
| 2932 | - define( |
|
| 2933 | - '_AJAX', |
|
| 2934 | - (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2935 | - or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2936 | - or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2937 | - or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2938 | - ) |
|
| 2939 | - and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2940 | - ); |
|
| 2941 | - } |
|
| 2942 | - |
|
| 2943 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2944 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2945 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2946 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2947 | - define( |
|
| 2948 | - '_IMG_GD_MAX_PIXELS', |
|
| 2949 | - (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2950 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2951 | - : 0 |
|
| 2952 | - ); |
|
| 2953 | - } |
|
| 2954 | - |
|
| 2955 | - // Protocoles a normaliser dans les chaines de langues |
|
| 2956 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 2957 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2958 | - } |
|
| 2959 | - |
|
| 2960 | - init_var_mode(); |
|
| 2809 | + static $too_late = 0; |
|
| 2810 | + if ($too_late++) { |
|
| 2811 | + return; |
|
| 2812 | + } |
|
| 2813 | + |
|
| 2814 | + // taille mini des login |
|
| 2815 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 2816 | + define('_LOGIN_TROP_COURT', 4); |
|
| 2817 | + } |
|
| 2818 | + |
|
| 2819 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2820 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 2821 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 2822 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2823 | + |
|
| 2824 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 2825 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 2826 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 2827 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 2828 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 2829 | + |
|
| 2830 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 2831 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 2832 | + } |
|
| 2833 | + |
|
| 2834 | + // largeur maximale des images dans l'administration |
|
| 2835 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 2836 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 2837 | + } |
|
| 2838 | + |
|
| 2839 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 2840 | + if (!defined('_IMG_QUALITE')) { |
|
| 2841 | + define('_IMG_QUALITE', 85); |
|
| 2842 | + } # valeur par defaut |
|
| 2843 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 2844 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 2845 | + } # surcharge pour la lib GD |
|
| 2846 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 2847 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 2848 | + } # surcharge pour imagick en ligne de commande |
|
| 2849 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 2850 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 2851 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 2852 | + } # surcharge pour imagick en PHP |
|
| 2853 | + |
|
| 2854 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 2855 | + define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 2856 | + } // poids en octet |
|
| 2857 | + |
|
| 2858 | + // qq chaines standard |
|
| 2859 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 2860 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 2861 | + } |
|
| 2862 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 2863 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 2864 | + } |
|
| 2865 | + if (!defined('_SPIP_DUMP')) { |
|
| 2866 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 2867 | + } |
|
| 2868 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 2869 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 2870 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 2871 | + } |
|
| 2872 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 2873 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 2874 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 2875 | + } |
|
| 2876 | + |
|
| 2877 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 2878 | + /** |
|
| 2879 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 2880 | + * @var int Nombre de caractères */ |
|
| 2881 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 2882 | + } |
|
| 2883 | + |
|
| 2884 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 2885 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 2886 | + } |
|
| 2887 | + |
|
| 2888 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 2889 | + /** Définit le doctype de l’espace privé */ |
|
| 2890 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 2891 | + } |
|
| 2892 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 2893 | + /** Définit le doctype de l’aide en ligne */ |
|
| 2894 | + define( |
|
| 2895 | + '_DOCTYPE_AIDE', |
|
| 2896 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 2897 | + ); |
|
| 2898 | + } |
|
| 2899 | + |
|
| 2900 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 2901 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 2902 | + * le script de l'espace public, alias index.php */ |
|
| 2903 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 2904 | + } |
|
| 2905 | + if (!defined('_SPIP_PAGE')) { |
|
| 2906 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 2907 | + define('_SPIP_PAGE', 'page'); |
|
| 2908 | + } |
|
| 2909 | + |
|
| 2910 | + // le script de l'espace prive |
|
| 2911 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 2912 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 2913 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 2914 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 2915 | + if (!empty($_SERVER['SERVER_SOFTWARE']) and preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 2916 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 2917 | + } else { |
|
| 2918 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 2919 | + } |
|
| 2920 | + } |
|
| 2921 | + |
|
| 2922 | + |
|
| 2923 | + if (!defined('_SPIP_AJAX')) { |
|
| 2924 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 2925 | + ? 1 |
|
| 2926 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 2927 | + } |
|
| 2928 | + |
|
| 2929 | + // La requete est-elle en ajax ? |
|
| 2930 | + if (!defined('_AJAX')) { |
|
| 2931 | + define( |
|
| 2932 | + '_AJAX', |
|
| 2933 | + (isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 2934 | + or !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuery |
|
| 2935 | + or !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 2936 | + or !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 2937 | + ) |
|
| 2938 | + and empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 2939 | + ); |
|
| 2940 | + } |
|
| 2941 | + |
|
| 2942 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 2943 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 2944 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 2945 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 2946 | + define( |
|
| 2947 | + '_IMG_GD_MAX_PIXELS', |
|
| 2948 | + (isset($GLOBALS['meta']['max_taille_vignettes']) and $GLOBALS['meta']['max_taille_vignettes']) |
|
| 2949 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 2950 | + : 0 |
|
| 2951 | + ); |
|
| 2952 | + } |
|
| 2953 | + |
|
| 2954 | + // Protocoles a normaliser dans les chaines de langues |
|
| 2955 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 2956 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 2957 | + } |
|
| 2958 | + |
|
| 2959 | + init_var_mode(); |
|
| 2961 | 2960 | } |
| 2962 | 2961 | |
| 2963 | 2962 | /** |
@@ -2991,219 +2990,219 @@ discard block |
||
| 2991 | 2990 | * ` var_mode` (calcul ou recalcul). |
| 2992 | 2991 | */ |
| 2993 | 2992 | function init_var_mode() { |
| 2994 | - static $done = false; |
|
| 2995 | - if (!$done) { |
|
| 2996 | - if (isset($_GET['var_mode'])) { |
|
| 2997 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 2998 | - // tout le monde peut calcul/recalcul |
|
| 2999 | - if (!defined('_VAR_MODE')) { |
|
| 3000 | - if (in_array('recalcul', $var_mode)) { |
|
| 3001 | - define('_VAR_MODE', 'recalcul'); |
|
| 3002 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 3003 | - define('_VAR_MODE', 'calcul'); |
|
| 3004 | - } |
|
| 3005 | - } |
|
| 3006 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 3007 | - if ($var_mode) { |
|
| 3008 | - include_spip('inc/autoriser'); |
|
| 3009 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 3010 | - if ( |
|
| 3011 | - autoriser( |
|
| 3012 | - ($_GET['var_mode'] == 'preview') |
|
| 3013 | - ? 'previsualiser' |
|
| 3014 | - : 'debug' |
|
| 3015 | - ) |
|
| 3016 | - ) { |
|
| 3017 | - if (in_array('traduction', $var_mode)) { |
|
| 3018 | - // forcer le calcul pour passer dans traduire |
|
| 3019 | - if (!defined('_VAR_MODE')) { |
|
| 3020 | - define('_VAR_MODE', 'calcul'); |
|
| 3021 | - } |
|
| 3022 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 3023 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3024 | - define('_VAR_NOCACHE', true); |
|
| 3025 | - } |
|
| 3026 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 3027 | - } |
|
| 3028 | - if (in_array('preview', $var_mode)) { |
|
| 3029 | - // basculer sur les criteres de preview dans les boucles |
|
| 3030 | - if (!defined('_VAR_PREVIEW')) { |
|
| 3031 | - define('_VAR_PREVIEW', true); |
|
| 3032 | - } |
|
| 3033 | - // forcer le calcul |
|
| 3034 | - if (!defined('_VAR_MODE')) { |
|
| 3035 | - define('_VAR_MODE', 'calcul'); |
|
| 3036 | - } |
|
| 3037 | - // et ne pas enregistrer de cache |
|
| 3038 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3039 | - define('_VAR_NOCACHE', true); |
|
| 3040 | - } |
|
| 3041 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 3042 | - } |
|
| 3043 | - if (in_array('inclure', $var_mode)) { |
|
| 3044 | - // forcer le compilo et ignorer les caches existants |
|
| 3045 | - if (!defined('_VAR_MODE')) { |
|
| 3046 | - define('_VAR_MODE', 'calcul'); |
|
| 3047 | - } |
|
| 3048 | - if (!defined('_VAR_INCLURE')) { |
|
| 3049 | - define('_VAR_INCLURE', true); |
|
| 3050 | - } |
|
| 3051 | - // et ne pas enregistrer de cache |
|
| 3052 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3053 | - define('_VAR_NOCACHE', true); |
|
| 3054 | - } |
|
| 3055 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 3056 | - } |
|
| 3057 | - if (in_array('urls', $var_mode)) { |
|
| 3058 | - // forcer le compilo et ignorer les caches existants |
|
| 3059 | - if (!defined('_VAR_MODE')) { |
|
| 3060 | - define('_VAR_MODE', 'calcul'); |
|
| 3061 | - } |
|
| 3062 | - if (!defined('_VAR_URLS')) { |
|
| 3063 | - define('_VAR_URLS', true); |
|
| 3064 | - } |
|
| 3065 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 3066 | - } |
|
| 3067 | - if (in_array('images', $var_mode)) { |
|
| 3068 | - // forcer le compilo et ignorer les caches existants |
|
| 3069 | - if (!defined('_VAR_MODE')) { |
|
| 3070 | - define('_VAR_MODE', 'calcul'); |
|
| 3071 | - } |
|
| 3072 | - // indiquer qu'on doit recalculer les images |
|
| 3073 | - if (!defined('_VAR_IMAGES')) { |
|
| 3074 | - define('_VAR_IMAGES', true); |
|
| 3075 | - } |
|
| 3076 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 3077 | - } |
|
| 3078 | - if (in_array('debug', $var_mode)) { |
|
| 3079 | - if (!defined('_VAR_MODE')) { |
|
| 3080 | - define('_VAR_MODE', 'debug'); |
|
| 3081 | - } |
|
| 3082 | - // et ne pas enregistrer de cache |
|
| 3083 | - if (!defined('_VAR_NOCACHE')) { |
|
| 3084 | - define('_VAR_NOCACHE', true); |
|
| 3085 | - } |
|
| 3086 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 3087 | - } |
|
| 3088 | - if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 3089 | - define('_VAR_MODE', reset($var_mode)); |
|
| 3090 | - } |
|
| 3091 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 3092 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 3093 | - . ' ' . _VAR_MODE); |
|
| 3094 | - } |
|
| 3095 | - } // pas autorise ? |
|
| 3096 | - else { |
|
| 3097 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3098 | - if ( |
|
| 3099 | - !$GLOBALS['visiteur_session'] |
|
| 3100 | - and !empty($_SERVER['HTTP_HOST']) |
|
| 3101 | - and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3102 | - and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3103 | - ) { |
|
| 3104 | - $self = self('&', true); |
|
| 3105 | - if (strpos($self, 'page=login') === false) { |
|
| 3106 | - include_spip('inc/headers'); |
|
| 3107 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3108 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3109 | - } |
|
| 3110 | - } |
|
| 3111 | - // sinon tant pis |
|
| 3112 | - } |
|
| 3113 | - } |
|
| 3114 | - } |
|
| 3115 | - if (!defined('_VAR_MODE')) { |
|
| 3116 | - /** |
|
| 3117 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 3118 | - * @see init_var_mode() |
|
| 3119 | - */ |
|
| 3120 | - define('_VAR_MODE', false); |
|
| 3121 | - } |
|
| 3122 | - $done = true; |
|
| 3123 | - } |
|
| 2993 | + static $done = false; |
|
| 2994 | + if (!$done) { |
|
| 2995 | + if (isset($_GET['var_mode'])) { |
|
| 2996 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 2997 | + // tout le monde peut calcul/recalcul |
|
| 2998 | + if (!defined('_VAR_MODE')) { |
|
| 2999 | + if (in_array('recalcul', $var_mode)) { |
|
| 3000 | + define('_VAR_MODE', 'recalcul'); |
|
| 3001 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 3002 | + define('_VAR_MODE', 'calcul'); |
|
| 3003 | + } |
|
| 3004 | + } |
|
| 3005 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 3006 | + if ($var_mode) { |
|
| 3007 | + include_spip('inc/autoriser'); |
|
| 3008 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 3009 | + if ( |
|
| 3010 | + autoriser( |
|
| 3011 | + ($_GET['var_mode'] == 'preview') |
|
| 3012 | + ? 'previsualiser' |
|
| 3013 | + : 'debug' |
|
| 3014 | + ) |
|
| 3015 | + ) { |
|
| 3016 | + if (in_array('traduction', $var_mode)) { |
|
| 3017 | + // forcer le calcul pour passer dans traduire |
|
| 3018 | + if (!defined('_VAR_MODE')) { |
|
| 3019 | + define('_VAR_MODE', 'calcul'); |
|
| 3020 | + } |
|
| 3021 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 3022 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3023 | + define('_VAR_NOCACHE', true); |
|
| 3024 | + } |
|
| 3025 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 3026 | + } |
|
| 3027 | + if (in_array('preview', $var_mode)) { |
|
| 3028 | + // basculer sur les criteres de preview dans les boucles |
|
| 3029 | + if (!defined('_VAR_PREVIEW')) { |
|
| 3030 | + define('_VAR_PREVIEW', true); |
|
| 3031 | + } |
|
| 3032 | + // forcer le calcul |
|
| 3033 | + if (!defined('_VAR_MODE')) { |
|
| 3034 | + define('_VAR_MODE', 'calcul'); |
|
| 3035 | + } |
|
| 3036 | + // et ne pas enregistrer de cache |
|
| 3037 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3038 | + define('_VAR_NOCACHE', true); |
|
| 3039 | + } |
|
| 3040 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 3041 | + } |
|
| 3042 | + if (in_array('inclure', $var_mode)) { |
|
| 3043 | + // forcer le compilo et ignorer les caches existants |
|
| 3044 | + if (!defined('_VAR_MODE')) { |
|
| 3045 | + define('_VAR_MODE', 'calcul'); |
|
| 3046 | + } |
|
| 3047 | + if (!defined('_VAR_INCLURE')) { |
|
| 3048 | + define('_VAR_INCLURE', true); |
|
| 3049 | + } |
|
| 3050 | + // et ne pas enregistrer de cache |
|
| 3051 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3052 | + define('_VAR_NOCACHE', true); |
|
| 3053 | + } |
|
| 3054 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 3055 | + } |
|
| 3056 | + if (in_array('urls', $var_mode)) { |
|
| 3057 | + // forcer le compilo et ignorer les caches existants |
|
| 3058 | + if (!defined('_VAR_MODE')) { |
|
| 3059 | + define('_VAR_MODE', 'calcul'); |
|
| 3060 | + } |
|
| 3061 | + if (!defined('_VAR_URLS')) { |
|
| 3062 | + define('_VAR_URLS', true); |
|
| 3063 | + } |
|
| 3064 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 3065 | + } |
|
| 3066 | + if (in_array('images', $var_mode)) { |
|
| 3067 | + // forcer le compilo et ignorer les caches existants |
|
| 3068 | + if (!defined('_VAR_MODE')) { |
|
| 3069 | + define('_VAR_MODE', 'calcul'); |
|
| 3070 | + } |
|
| 3071 | + // indiquer qu'on doit recalculer les images |
|
| 3072 | + if (!defined('_VAR_IMAGES')) { |
|
| 3073 | + define('_VAR_IMAGES', true); |
|
| 3074 | + } |
|
| 3075 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 3076 | + } |
|
| 3077 | + if (in_array('debug', $var_mode)) { |
|
| 3078 | + if (!defined('_VAR_MODE')) { |
|
| 3079 | + define('_VAR_MODE', 'debug'); |
|
| 3080 | + } |
|
| 3081 | + // et ne pas enregistrer de cache |
|
| 3082 | + if (!defined('_VAR_NOCACHE')) { |
|
| 3083 | + define('_VAR_NOCACHE', true); |
|
| 3084 | + } |
|
| 3085 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 3086 | + } |
|
| 3087 | + if (count($var_mode) and !defined('_VAR_MODE')) { |
|
| 3088 | + define('_VAR_MODE', reset($var_mode)); |
|
| 3089 | + } |
|
| 3090 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 3091 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 3092 | + . ' ' . _VAR_MODE); |
|
| 3093 | + } |
|
| 3094 | + } // pas autorise ? |
|
| 3095 | + else { |
|
| 3096 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 3097 | + if ( |
|
| 3098 | + !$GLOBALS['visiteur_session'] |
|
| 3099 | + and !empty($_SERVER['HTTP_HOST']) |
|
| 3100 | + and !empty($_SERVER['REQUEST_METHOD']) |
|
| 3101 | + and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 3102 | + ) { |
|
| 3103 | + $self = self('&', true); |
|
| 3104 | + if (strpos($self, 'page=login') === false) { |
|
| 3105 | + include_spip('inc/headers'); |
|
| 3106 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 3107 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 3108 | + } |
|
| 3109 | + } |
|
| 3110 | + // sinon tant pis |
|
| 3111 | + } |
|
| 3112 | + } |
|
| 3113 | + } |
|
| 3114 | + if (!defined('_VAR_MODE')) { |
|
| 3115 | + /** |
|
| 3116 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 3117 | + * @see init_var_mode() |
|
| 3118 | + */ |
|
| 3119 | + define('_VAR_MODE', false); |
|
| 3120 | + } |
|
| 3121 | + $done = true; |
|
| 3122 | + } |
|
| 3124 | 3123 | } |
| 3125 | 3124 | |
| 3126 | 3125 | // Annuler les magic quotes \' sur GET POST COOKIE et GLOBALS ; |
| 3127 | 3126 | // supprimer aussi les eventuels caracteres nuls %00, qui peuvent tromper |
| 3128 | 3127 | // la commande is_readable('chemin/vers/fichier/interdit%00truc_normal') |
| 3129 | 3128 | function spip_desinfecte(&$t, $deep = true) { |
| 3130 | - foreach ($t as $key => $val) { |
|
| 3131 | - if (is_string($t[$key])) { |
|
| 3132 | - $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3133 | - } // traiter aussi les "texte_plus" de article_edit |
|
| 3134 | - else { |
|
| 3135 | - if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3136 | - spip_desinfecte($t[$key], $deep); |
|
| 3137 | - } |
|
| 3138 | - } |
|
| 3139 | - } |
|
| 3129 | + foreach ($t as $key => $val) { |
|
| 3130 | + if (is_string($t[$key])) { |
|
| 3131 | + $t[$key] = str_replace(chr(0), '-', $t[$key]); |
|
| 3132 | + } // traiter aussi les "texte_plus" de article_edit |
|
| 3133 | + else { |
|
| 3134 | + if ($deep and is_array($t[$key]) and $key !== 'GLOBALS') { |
|
| 3135 | + spip_desinfecte($t[$key], $deep); |
|
| 3136 | + } |
|
| 3137 | + } |
|
| 3138 | + } |
|
| 3140 | 3139 | } |
| 3141 | 3140 | |
| 3142 | 3141 | // retourne le statut du visiteur s'il s'annonce |
| 3143 | 3142 | |
| 3144 | 3143 | function verifier_visiteur() { |
| 3145 | - // Rq: pour que cette fonction marche depuis mes_options |
|
| 3146 | - // il faut forcer l'init si ce n'est fait |
|
| 3147 | - // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3148 | - // certaines constantes |
|
| 3149 | - @spip_initialisation_core( |
|
| 3150 | - (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3151 | - (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3152 | - (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3153 | - (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3154 | - ); |
|
| 3155 | - |
|
| 3156 | - // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3157 | - // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3158 | - // Attention on separe bien session_nom et nom, pour eviter |
|
| 3159 | - // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3160 | - $variables_session = ['session_nom', 'session_email']; |
|
| 3161 | - foreach ($variables_session as $var) { |
|
| 3162 | - if (_request($var) !== null) { |
|
| 3163 | - $init = true; |
|
| 3164 | - break; |
|
| 3165 | - } |
|
| 3166 | - } |
|
| 3167 | - if (isset($init)) { |
|
| 3168 | - #@spip_initialisation_suite(); |
|
| 3169 | - $session = charger_fonction('session', 'inc'); |
|
| 3170 | - $session(); |
|
| 3171 | - include_spip('inc/texte'); |
|
| 3172 | - foreach ($variables_session as $var) { |
|
| 3173 | - if (($a = _request($var)) !== null) { |
|
| 3174 | - $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3175 | - } |
|
| 3176 | - } |
|
| 3177 | - if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3178 | - $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3179 | - } |
|
| 3180 | - $session($GLOBALS['visiteur_session']); |
|
| 3181 | - |
|
| 3182 | - return 0; |
|
| 3183 | - } |
|
| 3184 | - |
|
| 3185 | - $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3186 | - if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3187 | - $session = charger_fonction('session', 'inc'); |
|
| 3188 | - if ($session()) { |
|
| 3189 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3190 | - } |
|
| 3191 | - if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3192 | - include_spip('inc/auth'); |
|
| 3193 | - $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3194 | - } |
|
| 3195 | - if ($h) { |
|
| 3196 | - $GLOBALS['visiteur_session'] = $h; |
|
| 3197 | - |
|
| 3198 | - return $GLOBALS['visiteur_session']['statut']; |
|
| 3199 | - } |
|
| 3200 | - } |
|
| 3201 | - |
|
| 3202 | - // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3203 | - include_spip('inc/lang'); |
|
| 3204 | - utiliser_langue_visiteur(); |
|
| 3205 | - |
|
| 3206 | - return false; |
|
| 3144 | + // Rq: pour que cette fonction marche depuis mes_options |
|
| 3145 | + // il faut forcer l'init si ce n'est fait |
|
| 3146 | + // mais on risque de perturber des plugins en initialisant trop tot |
|
| 3147 | + // certaines constantes |
|
| 3148 | + @spip_initialisation_core( |
|
| 3149 | + (_DIR_RACINE . _NOM_PERMANENTS_INACCESSIBLES), |
|
| 3150 | + (_DIR_RACINE . _NOM_PERMANENTS_ACCESSIBLES), |
|
| 3151 | + (_DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES), |
|
| 3152 | + (_DIR_RACINE . _NOM_TEMPORAIRES_ACCESSIBLES) |
|
| 3153 | + ); |
|
| 3154 | + |
|
| 3155 | + // Demarrer une session NON AUTHENTIFIEE si on donne son nom |
|
| 3156 | + // dans un formulaire sans login (ex: #FORMULAIRE_FORUM) |
|
| 3157 | + // Attention on separe bien session_nom et nom, pour eviter |
|
| 3158 | + // les melanges entre donnees SQL et variables plus aleatoires |
|
| 3159 | + $variables_session = ['session_nom', 'session_email']; |
|
| 3160 | + foreach ($variables_session as $var) { |
|
| 3161 | + if (_request($var) !== null) { |
|
| 3162 | + $init = true; |
|
| 3163 | + break; |
|
| 3164 | + } |
|
| 3165 | + } |
|
| 3166 | + if (isset($init)) { |
|
| 3167 | + #@spip_initialisation_suite(); |
|
| 3168 | + $session = charger_fonction('session', 'inc'); |
|
| 3169 | + $session(); |
|
| 3170 | + include_spip('inc/texte'); |
|
| 3171 | + foreach ($variables_session as $var) { |
|
| 3172 | + if (($a = _request($var)) !== null) { |
|
| 3173 | + $GLOBALS['visiteur_session'][$var] = safehtml($a); |
|
| 3174 | + } |
|
| 3175 | + } |
|
| 3176 | + if (!isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 3177 | + $GLOBALS['visiteur_session']['id_auteur'] = 0; |
|
| 3178 | + } |
|
| 3179 | + $session($GLOBALS['visiteur_session']); |
|
| 3180 | + |
|
| 3181 | + return 0; |
|
| 3182 | + } |
|
| 3183 | + |
|
| 3184 | + $h = (isset($_SERVER['PHP_AUTH_USER']) and !$GLOBALS['ignore_auth_http']); |
|
| 3185 | + if ($h or isset($_COOKIE['spip_session']) or isset($_COOKIE[$GLOBALS['cookie_prefix'] . '_session'])) { |
|
| 3186 | + $session = charger_fonction('session', 'inc'); |
|
| 3187 | + if ($session()) { |
|
| 3188 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3189 | + } |
|
| 3190 | + if ($h and isset($_SERVER['PHP_AUTH_PW'])) { |
|
| 3191 | + include_spip('inc/auth'); |
|
| 3192 | + $h = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW']); |
|
| 3193 | + } |
|
| 3194 | + if ($h) { |
|
| 3195 | + $GLOBALS['visiteur_session'] = $h; |
|
| 3196 | + |
|
| 3197 | + return $GLOBALS['visiteur_session']['statut']; |
|
| 3198 | + } |
|
| 3199 | + } |
|
| 3200 | + |
|
| 3201 | + // au moins son navigateur nous dit la langue preferee de cet inconnu |
|
| 3202 | + include_spip('inc/lang'); |
|
| 3203 | + utiliser_langue_visiteur(); |
|
| 3204 | + |
|
| 3205 | + return false; |
|
| 3207 | 3206 | } |
| 3208 | 3207 | |
| 3209 | 3208 | |
@@ -3226,21 +3225,21 @@ discard block |
||
| 3226 | 3225 | * - string Langue utilisée. |
| 3227 | 3226 | **/ |
| 3228 | 3227 | function lang_select($lang = null) { |
| 3229 | - static $pile_langues = []; |
|
| 3230 | - if (!function_exists('changer_langue')) { |
|
| 3231 | - include_spip('inc/lang'); |
|
| 3232 | - } |
|
| 3233 | - if ($lang === null) { |
|
| 3234 | - $lang = array_pop($pile_langues); |
|
| 3235 | - } else { |
|
| 3236 | - array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3237 | - } |
|
| 3238 | - if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3239 | - return $lang; |
|
| 3240 | - } |
|
| 3241 | - changer_langue($lang); |
|
| 3228 | + static $pile_langues = []; |
|
| 3229 | + if (!function_exists('changer_langue')) { |
|
| 3230 | + include_spip('inc/lang'); |
|
| 3231 | + } |
|
| 3232 | + if ($lang === null) { |
|
| 3233 | + $lang = array_pop($pile_langues); |
|
| 3234 | + } else { |
|
| 3235 | + array_push($pile_langues, $GLOBALS['spip_lang']); |
|
| 3236 | + } |
|
| 3237 | + if (isset($GLOBALS['spip_lang']) and $lang == $GLOBALS['spip_lang']) { |
|
| 3238 | + return $lang; |
|
| 3239 | + } |
|
| 3240 | + changer_langue($lang); |
|
| 3242 | 3241 | |
| 3243 | - return $lang; |
|
| 3242 | + return $lang; |
|
| 3244 | 3243 | } |
| 3245 | 3244 | |
| 3246 | 3245 | /** |
@@ -3257,20 +3256,20 @@ discard block |
||
| 3257 | 3256 | * Identifiant de la session |
| 3258 | 3257 | **/ |
| 3259 | 3258 | function spip_session($force = false) { |
| 3260 | - static $session; |
|
| 3261 | - if ($force or !isset($session)) { |
|
| 3262 | - $s = pipeline( |
|
| 3263 | - 'definir_session', |
|
| 3264 | - $GLOBALS['visiteur_session'] |
|
| 3265 | - ? serialize($GLOBALS['visiteur_session']) |
|
| 3266 | - . '_' . @$_COOKIE['spip_session'] |
|
| 3267 | - : '' |
|
| 3268 | - ); |
|
| 3269 | - $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3270 | - } |
|
| 3259 | + static $session; |
|
| 3260 | + if ($force or !isset($session)) { |
|
| 3261 | + $s = pipeline( |
|
| 3262 | + 'definir_session', |
|
| 3263 | + $GLOBALS['visiteur_session'] |
|
| 3264 | + ? serialize($GLOBALS['visiteur_session']) |
|
| 3265 | + . '_' . @$_COOKIE['spip_session'] |
|
| 3266 | + : '' |
|
| 3267 | + ); |
|
| 3268 | + $session = $s ? substr(md5($s), 0, 8) : ''; |
|
| 3269 | + } |
|
| 3271 | 3270 | |
| 3272 | - #spip_log('session: '.$session); |
|
| 3273 | - return $session; |
|
| 3271 | + #spip_log('session: '.$session); |
|
| 3272 | + return $session; |
|
| 3274 | 3273 | } |
| 3275 | 3274 | |
| 3276 | 3275 | |
@@ -3289,9 +3288,9 @@ discard block |
||
| 3289 | 3288 | * Lien sur une icone d'aide |
| 3290 | 3289 | **/ |
| 3291 | 3290 | function aider($aide = '', $distante = false) { |
| 3292 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 3291 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 3293 | 3292 | |
| 3294 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3293 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 3295 | 3294 | } |
| 3296 | 3295 | |
| 3297 | 3296 | /** |
@@ -3301,24 +3300,24 @@ discard block |
||
| 3301 | 3300 | */ |
| 3302 | 3301 | function exec_info_dist() { |
| 3303 | 3302 | |
| 3304 | - include_spip('inc/autoriser'); |
|
| 3305 | - if (autoriser('phpinfos')) { |
|
| 3306 | - $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3307 | - $cookies_backup = []; |
|
| 3308 | - foreach ($cookies_masques as $k) { |
|
| 3309 | - if (!empty($_COOKIE[$k])) { |
|
| 3310 | - $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3311 | - $_COOKIE[$k] = '******************************'; |
|
| 3312 | - } |
|
| 3313 | - } |
|
| 3314 | - phpinfo(); |
|
| 3315 | - foreach ($cookies_backup as $k => $v) { |
|
| 3316 | - $_COOKIE[$k] = $v; |
|
| 3317 | - } |
|
| 3318 | - } else { |
|
| 3319 | - include_spip('inc/filtres'); |
|
| 3320 | - sinon_interdire_acces(); |
|
| 3321 | - } |
|
| 3303 | + include_spip('inc/autoriser'); |
|
| 3304 | + if (autoriser('phpinfos')) { |
|
| 3305 | + $cookies_masques = ['spip_session', 'PHPSESSID']; |
|
| 3306 | + $cookies_backup = []; |
|
| 3307 | + foreach ($cookies_masques as $k) { |
|
| 3308 | + if (!empty($_COOKIE[$k])) { |
|
| 3309 | + $cookies_backup[$k] = $_COOKIE[$k]; |
|
| 3310 | + $_COOKIE[$k] = '******************************'; |
|
| 3311 | + } |
|
| 3312 | + } |
|
| 3313 | + phpinfo(); |
|
| 3314 | + foreach ($cookies_backup as $k => $v) { |
|
| 3315 | + $_COOKIE[$k] = $v; |
|
| 3316 | + } |
|
| 3317 | + } else { |
|
| 3318 | + include_spip('inc/filtres'); |
|
| 3319 | + sinon_interdire_acces(); |
|
| 3320 | + } |
|
| 3322 | 3321 | } |
| 3323 | 3322 | |
| 3324 | 3323 | /** |
@@ -3338,13 +3337,13 @@ discard block |
||
| 3338 | 3337 | * - string si $message à false. |
| 3339 | 3338 | **/ |
| 3340 | 3339 | function erreur_squelette($message = '', $lieu = '') { |
| 3341 | - $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3342 | - if (is_array($lieu)) { |
|
| 3343 | - include_spip('public/compiler'); |
|
| 3344 | - $lieu = reconstruire_contexte_compil($lieu); |
|
| 3345 | - } |
|
| 3340 | + $debusquer = charger_fonction('debusquer', 'public'); |
|
| 3341 | + if (is_array($lieu)) { |
|
| 3342 | + include_spip('public/compiler'); |
|
| 3343 | + $lieu = reconstruire_contexte_compil($lieu); |
|
| 3344 | + } |
|
| 3346 | 3345 | |
| 3347 | - return $debusquer($message, $lieu); |
|
| 3346 | + return $debusquer($message, $lieu); |
|
| 3348 | 3347 | } |
| 3349 | 3348 | |
| 3350 | 3349 | /** |
@@ -3381,108 +3380,108 @@ discard block |
||
| 3381 | 3380 | * - ou tableau d'information sur le squelette. |
| 3382 | 3381 | */ |
| 3383 | 3382 | function recuperer_fond($fond, $contexte = [], $options = [], string $connect = '') { |
| 3384 | - if (!function_exists('evaluer_fond')) { |
|
| 3385 | - include_spip('public/assembler'); |
|
| 3386 | - } |
|
| 3387 | - // assurer la compat avec l'ancienne syntaxe |
|
| 3388 | - // (trim etait le 3eme argument, par defaut a true) |
|
| 3389 | - if (!is_array($options)) { |
|
| 3390 | - $options = ['trim' => $options]; |
|
| 3391 | - } |
|
| 3392 | - if (!isset($options['trim'])) { |
|
| 3393 | - $options['trim'] = true; |
|
| 3394 | - } |
|
| 3395 | - |
|
| 3396 | - if (isset($contexte['connect'])) { |
|
| 3397 | - $connect = $contexte['connect']; |
|
| 3398 | - unset($contexte['connect']); |
|
| 3399 | - } |
|
| 3400 | - |
|
| 3401 | - $texte = ''; |
|
| 3402 | - $pages = []; |
|
| 3403 | - $lang_select = ''; |
|
| 3404 | - if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3405 | - // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3406 | - if (!isset($contexte['lang'])) { |
|
| 3407 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3408 | - } |
|
| 3409 | - |
|
| 3410 | - if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3411 | - $lang_select = lang_select($contexte['lang']); |
|
| 3412 | - } |
|
| 3413 | - } |
|
| 3414 | - |
|
| 3415 | - if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3416 | - $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3417 | - } |
|
| 3418 | - |
|
| 3419 | - $GLOBALS['_INC_PUBLIC']++; |
|
| 3420 | - |
|
| 3421 | - // fix #4235 |
|
| 3422 | - $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3423 | - |
|
| 3424 | - |
|
| 3425 | - foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3426 | - unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3427 | - |
|
| 3428 | - $page = evaluer_fond($f, $contexte, $connect); |
|
| 3429 | - if ($page === '') { |
|
| 3430 | - $c = $options['compil'] ?? ''; |
|
| 3431 | - $a = ['fichier' => $f]; |
|
| 3432 | - $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3433 | - erreur_squelette($erreur, $c); |
|
| 3434 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3435 | - $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3436 | - } |
|
| 3437 | - |
|
| 3438 | - $page = pipeline('recuperer_fond', [ |
|
| 3439 | - 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3440 | - 'data' => $page |
|
| 3441 | - ]); |
|
| 3442 | - if (isset($options['ajax']) and $options['ajax']) { |
|
| 3443 | - if (!function_exists('encoder_contexte_ajax')) { |
|
| 3444 | - include_spip('inc/filtres'); |
|
| 3445 | - } |
|
| 3446 | - $page['texte'] = encoder_contexte_ajax( |
|
| 3447 | - array_merge( |
|
| 3448 | - $contexte, |
|
| 3449 | - ['fond' => $f], |
|
| 3450 | - ($connect ? ['connect' => $connect] : []) |
|
| 3451 | - ), |
|
| 3452 | - '', |
|
| 3453 | - $page['texte'], |
|
| 3454 | - $options['ajax'] |
|
| 3455 | - ); |
|
| 3456 | - } |
|
| 3457 | - |
|
| 3458 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3459 | - $pages[] = $page; |
|
| 3460 | - } else { |
|
| 3461 | - $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte']; |
|
| 3462 | - } |
|
| 3463 | - |
|
| 3464 | - // contamination de la session appelante, pour les inclusions statiques |
|
| 3465 | - if (isset($page['invalideurs']['session'])) { |
|
| 3466 | - $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3467 | - } |
|
| 3468 | - } |
|
| 3469 | - |
|
| 3470 | - // restaurer le sessionnement du contexte appelant, |
|
| 3471 | - // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3472 | - if (isset($cache_utilise_session_appelant)) { |
|
| 3473 | - $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3474 | - } |
|
| 3475 | - |
|
| 3476 | - $GLOBALS['_INC_PUBLIC']--; |
|
| 3477 | - |
|
| 3478 | - if ($lang_select) { |
|
| 3479 | - lang_select(); |
|
| 3480 | - } |
|
| 3481 | - if (isset($options['raw']) and $options['raw']) { |
|
| 3482 | - return is_array($fond) ? $pages : reset($pages); |
|
| 3483 | - } else { |
|
| 3484 | - return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3485 | - } |
|
| 3383 | + if (!function_exists('evaluer_fond')) { |
|
| 3384 | + include_spip('public/assembler'); |
|
| 3385 | + } |
|
| 3386 | + // assurer la compat avec l'ancienne syntaxe |
|
| 3387 | + // (trim etait le 3eme argument, par defaut a true) |
|
| 3388 | + if (!is_array($options)) { |
|
| 3389 | + $options = ['trim' => $options]; |
|
| 3390 | + } |
|
| 3391 | + if (!isset($options['trim'])) { |
|
| 3392 | + $options['trim'] = true; |
|
| 3393 | + } |
|
| 3394 | + |
|
| 3395 | + if (isset($contexte['connect'])) { |
|
| 3396 | + $connect = $contexte['connect']; |
|
| 3397 | + unset($contexte['connect']); |
|
| 3398 | + } |
|
| 3399 | + |
|
| 3400 | + $texte = ''; |
|
| 3401 | + $pages = []; |
|
| 3402 | + $lang_select = ''; |
|
| 3403 | + if (!isset($options['etoile']) or !$options['etoile']) { |
|
| 3404 | + // Si on a inclus sans fixer le critere de lang, on prend la langue courante |
|
| 3405 | + if (!isset($contexte['lang'])) { |
|
| 3406 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 3407 | + } |
|
| 3408 | + |
|
| 3409 | + if ($contexte['lang'] != $GLOBALS['meta']['langue_site']) { |
|
| 3410 | + $lang_select = lang_select($contexte['lang']); |
|
| 3411 | + } |
|
| 3412 | + } |
|
| 3413 | + |
|
| 3414 | + if (!isset($GLOBALS['_INC_PUBLIC'])) { |
|
| 3415 | + $GLOBALS['_INC_PUBLIC'] = 0; |
|
| 3416 | + } |
|
| 3417 | + |
|
| 3418 | + $GLOBALS['_INC_PUBLIC']++; |
|
| 3419 | + |
|
| 3420 | + // fix #4235 |
|
| 3421 | + $cache_utilise_session_appelant = ($GLOBALS['cache_utilise_session'] ?? null); |
|
| 3422 | + |
|
| 3423 | + |
|
| 3424 | + foreach (is_array($fond) ? $fond : [$fond] as $f) { |
|
| 3425 | + unset($GLOBALS['cache_utilise_session']); // fix #4235 |
|
| 3426 | + |
|
| 3427 | + $page = evaluer_fond($f, $contexte, $connect); |
|
| 3428 | + if ($page === '') { |
|
| 3429 | + $c = $options['compil'] ?? ''; |
|
| 3430 | + $a = ['fichier' => $f]; |
|
| 3431 | + $erreur = _T('info_erreur_squelette2', $a); // squelette introuvable |
|
| 3432 | + erreur_squelette($erreur, $c); |
|
| 3433 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 3434 | + $page = ['texte' => '', 'erreur' => $erreur]; |
|
| 3435 | + } |
|
| 3436 | + |
|
| 3437 | + $page = pipeline('recuperer_fond', [ |
|
| 3438 | + 'args' => ['fond' => $f, 'contexte' => $contexte, 'options' => $options, 'connect' => $connect], |
|
| 3439 | + 'data' => $page |
|
| 3440 | + ]); |
|
| 3441 | + if (isset($options['ajax']) and $options['ajax']) { |
|
| 3442 | + if (!function_exists('encoder_contexte_ajax')) { |
|
| 3443 | + include_spip('inc/filtres'); |
|
| 3444 | + } |
|
| 3445 | + $page['texte'] = encoder_contexte_ajax( |
|
| 3446 | + array_merge( |
|
| 3447 | + $contexte, |
|
| 3448 | + ['fond' => $f], |
|
| 3449 | + ($connect ? ['connect' => $connect] : []) |
|
| 3450 | + ), |
|
| 3451 | + '', |
|
| 3452 | + $page['texte'], |
|
| 3453 | + $options['ajax'] |
|
| 3454 | + ); |
|
| 3455 | + } |
|
| 3456 | + |
|
| 3457 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3458 | + $pages[] = $page; |
|
| 3459 | + } else { |
|
| 3460 | + $texte .= $options['trim'] ? rtrim($page['texte'] ?? '') : $page['texte']; |
|
| 3461 | + } |
|
| 3462 | + |
|
| 3463 | + // contamination de la session appelante, pour les inclusions statiques |
|
| 3464 | + if (isset($page['invalideurs']['session'])) { |
|
| 3465 | + $cache_utilise_session_appelant = $page['invalideurs']['session']; |
|
| 3466 | + } |
|
| 3467 | + } |
|
| 3468 | + |
|
| 3469 | + // restaurer le sessionnement du contexte appelant, |
|
| 3470 | + // éventuellement contaminé si on vient de récupérer une inclusion statique sessionnée |
|
| 3471 | + if (isset($cache_utilise_session_appelant)) { |
|
| 3472 | + $GLOBALS['cache_utilise_session'] = $cache_utilise_session_appelant; |
|
| 3473 | + } |
|
| 3474 | + |
|
| 3475 | + $GLOBALS['_INC_PUBLIC']--; |
|
| 3476 | + |
|
| 3477 | + if ($lang_select) { |
|
| 3478 | + lang_select(); |
|
| 3479 | + } |
|
| 3480 | + if (isset($options['raw']) and $options['raw']) { |
|
| 3481 | + return is_array($fond) ? $pages : reset($pages); |
|
| 3482 | + } else { |
|
| 3483 | + return $options['trim'] ? ltrim($texte) : $texte; |
|
| 3484 | + } |
|
| 3486 | 3485 | } |
| 3487 | 3486 | |
| 3488 | 3487 | /** |
@@ -3492,7 +3491,7 @@ discard block |
||
| 3492 | 3491 | * @return string |
| 3493 | 3492 | */ |
| 3494 | 3493 | function trouve_modele($nom) { |
| 3495 | - return trouver_fond($nom, 'modeles/'); |
|
| 3494 | + return trouver_fond($nom, 'modeles/'); |
|
| 3496 | 3495 | } |
| 3497 | 3496 | |
| 3498 | 3497 | /** |
@@ -3508,21 +3507,21 @@ discard block |
||
| 3508 | 3507 | * @return array|string |
| 3509 | 3508 | */ |
| 3510 | 3509 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 3511 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3512 | - if (!$pathinfo) { |
|
| 3513 | - return $f; |
|
| 3514 | - } |
|
| 3515 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 3516 | - $p = pathinfo($f); |
|
| 3517 | - if (!isset($p['extension']) or !$p['extension']) { |
|
| 3518 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3519 | - } |
|
| 3520 | - if (!isset($p['extension']) or !$p['filename']) { |
|
| 3521 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3522 | - } |
|
| 3523 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3510 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 3511 | + if (!$pathinfo) { |
|
| 3512 | + return $f; |
|
| 3513 | + } |
|
| 3514 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 3515 | + $p = pathinfo($f); |
|
| 3516 | + if (!isset($p['extension']) or !$p['extension']) { |
|
| 3517 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 3518 | + } |
|
| 3519 | + if (!isset($p['extension']) or !$p['filename']) { |
|
| 3520 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 3521 | + } |
|
| 3522 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 3524 | 3523 | |
| 3525 | - return $p; |
|
| 3524 | + return $p; |
|
| 3526 | 3525 | } |
| 3527 | 3526 | |
| 3528 | 3527 | /** |
@@ -3542,21 +3541,21 @@ discard block |
||
| 3542 | 3541 | * Nom de l'exec, sinon chaîne vide. |
| 3543 | 3542 | **/ |
| 3544 | 3543 | function tester_url_ecrire($nom) { |
| 3545 | - static $exec = []; |
|
| 3546 | - if (isset($exec[$nom])) { |
|
| 3547 | - return $exec[$nom]; |
|
| 3548 | - } |
|
| 3549 | - // tester si c'est une page en squelette |
|
| 3550 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3551 | - return $exec[$nom] = 'fond'; |
|
| 3552 | - } // echafaudage d'un fond ! |
|
| 3553 | - elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3554 | - return $exec[$nom] = 'fond'; |
|
| 3555 | - } |
|
| 3556 | - // attention, il ne faut pas inclure l'exec ici |
|
| 3557 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3558 | - // et des define intrusifs potentiels |
|
| 3559 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3544 | + static $exec = []; |
|
| 3545 | + if (isset($exec[$nom])) { |
|
| 3546 | + return $exec[$nom]; |
|
| 3547 | + } |
|
| 3548 | + // tester si c'est une page en squelette |
|
| 3549 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 3550 | + return $exec[$nom] = 'fond'; |
|
| 3551 | + } // echafaudage d'un fond ! |
|
| 3552 | + elseif (include_spip('public/styliser_par_z') and z_echafaudable($nom)) { |
|
| 3553 | + return $exec[$nom] = 'fond'; |
|
| 3554 | + } |
|
| 3555 | + // attention, il ne faut pas inclure l'exec ici |
|
| 3556 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 3557 | + // et des define intrusifs potentiels |
|
| 3558 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') or charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 3560 | 3559 | } |
| 3561 | 3560 | |
| 3562 | 3561 | /** |
@@ -3566,8 +3565,8 @@ discard block |
||
| 3566 | 3565 | * true si la constante _VERSION_HTML n'est pas définie ou égale à html5 |
| 3567 | 3566 | **/ |
| 3568 | 3567 | function html5_permis() { |
| 3569 | - return (!defined('_VERSION_HTML') |
|
| 3570 | - or _VERSION_HTML !== 'html4'); |
|
| 3568 | + return (!defined('_VERSION_HTML') |
|
| 3569 | + or _VERSION_HTML !== 'html4'); |
|
| 3571 | 3570 | } |
| 3572 | 3571 | |
| 3573 | 3572 | /** |
@@ -3577,30 +3576,30 @@ discard block |
||
| 3577 | 3576 | * @return array |
| 3578 | 3577 | */ |
| 3579 | 3578 | function formats_image_acceptables($gd = null, $svg_allowed = true) { |
| 3580 | - $formats = null; |
|
| 3581 | - if (!is_null($gd)) { |
|
| 3582 | - $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3583 | - if (isset($GLOBALS['meta'][$config])) { |
|
| 3584 | - $formats = $GLOBALS['meta'][$config]; |
|
| 3585 | - $formats = explode(',', $formats); |
|
| 3586 | - $formats = array_filter($formats); |
|
| 3587 | - $formats = array_map('trim', $formats); |
|
| 3588 | - } |
|
| 3589 | - } |
|
| 3590 | - if (is_null($formats)) { |
|
| 3591 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 3592 | - $formats = _image_extensions_acceptees_en_entree(); |
|
| 3593 | - } |
|
| 3594 | - |
|
| 3595 | - if ($svg_allowed) { |
|
| 3596 | - if (!in_array('svg', $formats)) { |
|
| 3597 | - $formats[] = 'svg'; |
|
| 3598 | - } |
|
| 3599 | - } |
|
| 3600 | - else { |
|
| 3601 | - $formats = array_diff($formats, ['svg']); |
|
| 3602 | - } |
|
| 3603 | - return $formats; |
|
| 3579 | + $formats = null; |
|
| 3580 | + if (!is_null($gd)) { |
|
| 3581 | + $config = ($gd ? 'gd_formats' : 'formats_graphiques'); |
|
| 3582 | + if (isset($GLOBALS['meta'][$config])) { |
|
| 3583 | + $formats = $GLOBALS['meta'][$config]; |
|
| 3584 | + $formats = explode(',', $formats); |
|
| 3585 | + $formats = array_filter($formats); |
|
| 3586 | + $formats = array_map('trim', $formats); |
|
| 3587 | + } |
|
| 3588 | + } |
|
| 3589 | + if (is_null($formats)) { |
|
| 3590 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 3591 | + $formats = _image_extensions_acceptees_en_entree(); |
|
| 3592 | + } |
|
| 3593 | + |
|
| 3594 | + if ($svg_allowed) { |
|
| 3595 | + if (!in_array('svg', $formats)) { |
|
| 3596 | + $formats[] = 'svg'; |
|
| 3597 | + } |
|
| 3598 | + } |
|
| 3599 | + else { |
|
| 3600 | + $formats = array_diff($formats, ['svg']); |
|
| 3601 | + } |
|
| 3602 | + return $formats; |
|
| 3604 | 3603 | } |
| 3605 | 3604 | |
| 3606 | 3605 | /** |
@@ -3609,20 +3608,20 @@ discard block |
||
| 3609 | 3608 | * @return array|bool |
| 3610 | 3609 | */ |
| 3611 | 3610 | function spip_getimagesize($fichier) { |
| 3612 | - if (!$imagesize = @getimagesize($fichier)) { |
|
| 3613 | - include_spip('inc/svg'); |
|
| 3614 | - if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3615 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3616 | - $imagesize = [ |
|
| 3617 | - $width, |
|
| 3618 | - $height, |
|
| 3619 | - IMAGETYPE_SVG, |
|
| 3620 | - "width=\"{$width}\" height=\"{$height}\"", |
|
| 3621 | - 'mime' => 'image/svg+xml' |
|
| 3622 | - ]; |
|
| 3623 | - } |
|
| 3624 | - } |
|
| 3625 | - return $imagesize; |
|
| 3611 | + if (!$imagesize = @getimagesize($fichier)) { |
|
| 3612 | + include_spip('inc/svg'); |
|
| 3613 | + if ($attrs = svg_lire_attributs($fichier)) { |
|
| 3614 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 3615 | + $imagesize = [ |
|
| 3616 | + $width, |
|
| 3617 | + $height, |
|
| 3618 | + IMAGETYPE_SVG, |
|
| 3619 | + "width=\"{$width}\" height=\"{$height}\"", |
|
| 3620 | + 'mime' => 'image/svg+xml' |
|
| 3621 | + ]; |
|
| 3622 | + } |
|
| 3623 | + } |
|
| 3624 | + return $imagesize; |
|
| 3626 | 3625 | } |
| 3627 | 3626 | |
| 3628 | 3627 | /** |
@@ -3636,19 +3635,19 @@ discard block |
||
| 3636 | 3635 | * @param string $statut |
| 3637 | 3636 | */ |
| 3638 | 3637 | function avertir_auteurs($nom, $message, $statut = '') { |
| 3639 | - $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3640 | - if ( |
|
| 3641 | - !$alertes |
|
| 3642 | - or !is_array($alertes = unserialize($alertes)) |
|
| 3643 | - ) { |
|
| 3644 | - $alertes = []; |
|
| 3645 | - } |
|
| 3638 | + $alertes = $GLOBALS['meta']['message_alertes_auteurs']; |
|
| 3639 | + if ( |
|
| 3640 | + !$alertes |
|
| 3641 | + or !is_array($alertes = unserialize($alertes)) |
|
| 3642 | + ) { |
|
| 3643 | + $alertes = []; |
|
| 3644 | + } |
|
| 3646 | 3645 | |
| 3647 | - if (!isset($alertes[$statut])) { |
|
| 3648 | - $alertes[$statut] = []; |
|
| 3649 | - } |
|
| 3650 | - $alertes[$statut][$nom] = $message; |
|
| 3651 | - ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3646 | + if (!isset($alertes[$statut])) { |
|
| 3647 | + $alertes[$statut] = []; |
|
| 3648 | + } |
|
| 3649 | + $alertes[$statut][$nom] = $message; |
|
| 3650 | + ecrire_meta('message_alertes_auteurs', serialize($alertes)); |
|
| 3652 | 3651 | } |
| 3653 | 3652 | |
| 3654 | 3653 | /** |
@@ -3662,10 +3661,10 @@ discard block |
||
| 3662 | 3661 | * @return string|string[] |
| 3663 | 3662 | */ |
| 3664 | 3663 | function spip_sanitize_classname($classes) { |
| 3665 | - if (is_array($classes)) { |
|
| 3666 | - return array_map('spip_sanitize_classname', $classes); |
|
| 3667 | - } |
|
| 3668 | - return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3664 | + if (is_array($classes)) { |
|
| 3665 | + return array_map('spip_sanitize_classname', $classes); |
|
| 3666 | + } |
|
| 3667 | + return preg_replace('/[^ 0-9a-z_\-+@]/i', '', $classes); |
|
| 3669 | 3668 | } |
| 3670 | 3669 | |
| 3671 | 3670 | |
@@ -3690,32 +3689,32 @@ discard block |
||
| 3690 | 3689 | * Avec operateur : bool. |
| 3691 | 3690 | **/ |
| 3692 | 3691 | function spip_version_compare($v1, $v2, $op = null) { |
| 3693 | - $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3694 | - $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3695 | - $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3696 | - $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3697 | - |
|
| 3698 | - $v1 = explode('.', $v1); |
|
| 3699 | - $v2 = explode('.', $v2); |
|
| 3700 | - // $v1 est toujours une version, donc sans etoile |
|
| 3701 | - while (count($v1) < count($v2)) { |
|
| 3702 | - $v1[] = '0'; |
|
| 3703 | - } |
|
| 3704 | - |
|
| 3705 | - // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3706 | - $etoile = false; |
|
| 3707 | - foreach ($v1 as $k => $v) { |
|
| 3708 | - if (!isset($v2[$k])) { |
|
| 3709 | - $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3710 | - } else { |
|
| 3711 | - if ($v2[$k] == '*') { |
|
| 3712 | - $etoile = true; |
|
| 3713 | - $v2[$k] = $v; |
|
| 3714 | - } |
|
| 3715 | - } |
|
| 3716 | - } |
|
| 3717 | - $v1 = implode('.', $v1); |
|
| 3718 | - $v2 = implode('.', $v2); |
|
| 3719 | - |
|
| 3720 | - return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3692 | + $v1 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v1)); |
|
| 3693 | + $v2 = strtolower(preg_replace(',([0-9])[\s.-]?(dev|alpha|a|beta|b|rc|pl|p),i', '\\1.\\2', $v2)); |
|
| 3694 | + $v1 = str_replace('rc', 'RC', $v1); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3695 | + $v2 = str_replace('rc', 'RC', $v2); // certaines versions de PHP ne comprennent RC qu'en majuscule |
|
| 3696 | + |
|
| 3697 | + $v1 = explode('.', $v1); |
|
| 3698 | + $v2 = explode('.', $v2); |
|
| 3699 | + // $v1 est toujours une version, donc sans etoile |
|
| 3700 | + while (count($v1) < count($v2)) { |
|
| 3701 | + $v1[] = '0'; |
|
| 3702 | + } |
|
| 3703 | + |
|
| 3704 | + // $v2 peut etre une borne, donc accepte l'etoile |
|
| 3705 | + $etoile = false; |
|
| 3706 | + foreach ($v1 as $k => $v) { |
|
| 3707 | + if (!isset($v2[$k])) { |
|
| 3708 | + $v2[] = ($etoile and (is_numeric($v) or $v == 'pl' or $v == 'p')) ? $v : '0'; |
|
| 3709 | + } else { |
|
| 3710 | + if ($v2[$k] == '*') { |
|
| 3711 | + $etoile = true; |
|
| 3712 | + $v2[$k] = $v; |
|
| 3713 | + } |
|
| 3714 | + } |
|
| 3715 | + } |
|
| 3716 | + $v1 = implode('.', $v1); |
|
| 3717 | + $v2 = implode('.', $v2); |
|
| 3718 | + |
|
| 3719 | + return $op ? version_compare($v1, $v2, $op) : version_compare($v1, $v2); |
|
| 3721 | 3720 | } |