@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | function extraire_date($texte): string { |
| 40 | 40 | // format = 2001-08 |
| 41 | 41 | if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + return $regs[1].'-'.sprintf('%02d', $regs[2]).'-01'; |
|
| 43 | 43 | } |
| 44 | 44 | return ''; |
| 45 | 45 | } |
@@ -70,11 +70,11 @@ discard block |
||
| 70 | 70 | } |
| 71 | 71 | if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 72 | 72 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | + $date = $regs[1].'-00-00'.$regs[3]; |
|
| 74 | 74 | } else { |
| 75 | 75 | if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
| 76 | 76 | $regs = array_pad($regs, 4, null); // eviter notice php |
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]).'-00'.$regs[3]; |
|
| 78 | 78 | } else { |
| 79 | 79 | $date = date('Y-m-d H:i:s', strtotime($date)); |
| 80 | 80 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $letexte ??= ''; |
| 102 | 102 | if ( |
| 103 | 103 | !$verif_format_date |
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | + or (in_array(strlen($letexte), [10, 19]) and |
|
| 105 | 105 | preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
| 106 | 106 | ) { |
| 107 | 107 | if (strncmp('0000-00-00', $letexte, 10) == 0) { |
@@ -388,17 +388,17 @@ discard block |
||
| 388 | 388 | if ($decal > 3600 * 24 * 30) { |
| 389 | 389 | $mois = floor($decal / (3600 * 24 * 30)); |
| 390 | 390 | if ($mois < 2) { |
| 391 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 391 | + $delai = "$mois "._T('date_un_mois'); |
|
| 392 | 392 | } else { |
| 393 | - $delai = "$mois " . _T('date_mois'); |
|
| 393 | + $delai = "$mois "._T('date_mois'); |
|
| 394 | 394 | } |
| 395 | 395 | } else { |
| 396 | 396 | if ($decal > 3600 * 24 * 7) { |
| 397 | 397 | $semaines = floor($decal / (3600 * 24 * 7)); |
| 398 | 398 | if ($semaines < 2) { |
| 399 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 399 | + $delai = "$semaines "._T('date_une_semaine'); |
|
| 400 | 400 | } else { |
| 401 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 401 | + $delai = "$semaines "._T('date_semaines'); |
|
| 402 | 402 | } |
| 403 | 403 | } else { |
| 404 | 404 | if ($decal > 3600 * 24) { |
@@ -406,30 +406,30 @@ discard block |
||
| 406 | 406 | if ($jours < 2) { |
| 407 | 407 | return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
| 408 | 408 | } else { |
| 409 | - $delai = "$jours " . _T('date_jours'); |
|
| 409 | + $delai = "$jours "._T('date_jours'); |
|
| 410 | 410 | } |
| 411 | 411 | } else { |
| 412 | 412 | if ($decal >= 3600) { |
| 413 | 413 | $heures = floor($decal / 3600); |
| 414 | 414 | if ($heures < 2) { |
| 415 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 415 | + $delai = "$heures "._T('date_une_heure'); |
|
| 416 | 416 | } else { |
| 417 | - $delai = "$heures " . _T('date_heures'); |
|
| 417 | + $delai = "$heures "._T('date_heures'); |
|
| 418 | 418 | } |
| 419 | 419 | } else { |
| 420 | 420 | if ($decal >= 60) { |
| 421 | 421 | $minutes = floor($decal / 60); |
| 422 | 422 | if ($minutes < 2) { |
| 423 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 423 | + $delai = "$minutes "._T('date_une_minute'); |
|
| 424 | 424 | } else { |
| 425 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 425 | + $delai = "$minutes "._T('date_minutes'); |
|
| 426 | 426 | } |
| 427 | 427 | } else { |
| 428 | 428 | $secondes = ceil($decal); |
| 429 | 429 | if ($secondes < 2) { |
| 430 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 430 | + $delai = "$secondes "._T('date_une_seconde'); |
|
| 431 | 431 | } else { |
| 432 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 432 | + $delai = "$secondes "._T('date_secondes'); |
|
| 433 | 433 | } |
| 434 | 434 | } |
| 435 | 435 | } |
@@ -522,7 +522,7 @@ discard block |
||
| 522 | 522 | $njour = 0; |
| 523 | 523 | } else { |
| 524 | 524 | $njour = intval($jour); |
| 525 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 525 | + if ($jourth = _T('date_jnum'.$jour)) { |
|
| 526 | 526 | $jour = $jourth; |
| 527 | 527 | } |
| 528 | 528 | } |
@@ -530,10 +530,10 @@ discard block |
||
| 530 | 530 | $mois = intval($mois); |
| 531 | 531 | if ($mois > 0 and $mois < 13) { |
| 532 | 532 | /* Traiter le cas "abbr" pour les noms de mois */ |
| 533 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 534 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_'.$options['param'] : ''); |
|
| 534 | + $nommois = _T('date_mois_'.$mois.$param); |
|
| 535 | 535 | if ($jour) { |
| 536 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 536 | + $jourmois = _T('date_de_mois_'.$mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 537 | 537 | } else { |
| 538 | 538 | $jourmois = $nommois; |
| 539 | 539 | } |
@@ -543,7 +543,7 @@ discard block |
||
| 543 | 543 | } |
| 544 | 544 | |
| 545 | 545 | if ($annee < 0) { |
| 546 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 546 | + $annee = -$annee.' '._T('date_avant_jc'); |
|
| 547 | 547 | $avjc = true; |
| 548 | 548 | } else { |
| 549 | 549 | $avjc = false; |
@@ -569,11 +569,11 @@ discard block |
||
| 569 | 569 | } |
| 570 | 570 | } |
| 571 | 571 | if ($vue == 'saison') { |
| 572 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 572 | + return $saison ? _T('date_saison_'.$saison) : ''; |
|
| 573 | 573 | } else { |
| 574 | 574 | return $saison ? trim(_T( |
| 575 | 575 | 'date_fmt_saison_annee', |
| 576 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 576 | + ['saison' => _T('date_saison_'.$saison), 'annee' => $annee] |
|
| 577 | 577 | )) : ''; |
| 578 | 578 | } |
| 579 | 579 | |
@@ -650,9 +650,9 @@ discard block |
||
| 650 | 650 | } |
| 651 | 651 | $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
| 652 | 652 | $nom = 1 + (int) date('w', $nom); |
| 653 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 653 | + $param = ((isset($options['param']) and $options['param']) ? '_'.$options['param'] : ''); |
|
| 654 | 654 | |
| 655 | - return _T('date_jour_' . $nom . $param); |
|
| 655 | + return _T('date_jour_'.$nom.$param); |
|
| 656 | 656 | |
| 657 | 657 | case 'mois_annee': |
| 658 | 658 | if ($avjc) { |
@@ -1047,8 +1047,8 @@ discard block |
||
| 1047 | 1047 | |
| 1048 | 1048 | $dtstart = $dtend = $dtabbr = ''; |
| 1049 | 1049 | if (strpos($forme, 'hcal') !== false) { |
| 1050 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1051 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | + $dtstart = "<abbr class='dtstart' title='".date_iso($date_debut)."'>"; |
|
| 1051 | + $dtend = "<abbr class='dtend' title='".date_iso($date_fin)."'>"; |
|
| 1052 | 1052 | $dtabbr = '</abbr>'; |
| 1053 | 1053 | } |
| 1054 | 1054 | |
@@ -1096,7 +1096,7 @@ discard block |
||
| 1096 | 1096 | } |
| 1097 | 1097 | } else { |
| 1098 | 1098 | if ($dtabbr && $dtstart) { |
| 1099 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1099 | + $s = $dtstart.spip_ucfirst($s).$dtabbr; |
|
| 1100 | 1100 | } else { |
| 1101 | 1101 | $s = spip_ucfirst($s); |
| 1102 | 1102 | } |
@@ -1119,8 +1119,8 @@ discard block |
||
| 1119 | 1119 | $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
| 1120 | 1120 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1121 | 1121 | } |
| 1122 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1123 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1123 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1124 | 1124 | |
| 1125 | 1125 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1126 | 1126 | } else { |
@@ -1137,8 +1137,8 @@ discard block |
||
| 1137 | 1137 | $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1141 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | + $date_debut = $dtstart.$date_debut.$dtabbr; |
|
| 1141 | + $date_fin = $dtend.$date_fin.$dtabbr; |
|
| 1142 | 1142 | $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
| 1143 | 1143 | } |
| 1144 | 1144 | } |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | $d = date('Y-m-d'); |
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1245 | + return substr($d, 0, 4).substr($d, 5, 2).substr($d, 8, 2); |
|
| 1246 | 1246 | } |
| 1247 | 1247 | |
| 1248 | 1248 | /** |
@@ -1262,7 +1262,7 @@ discard block |
||
| 1262 | 1262 | $d = date('Y-m-d'); |
| 1263 | 1263 | } |
| 1264 | 1264 | |
| 1265 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1265 | + return substr($d, 0, 4).substr($d, 5, 2); |
|
| 1266 | 1266 | } |
| 1267 | 1267 | |
| 1268 | 1268 | /** |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -37,11 +37,11 @@ discard block |
||
| 37 | 37 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 38 | 38 | **/ |
| 39 | 39 | function extraire_date($texte): string { |
| 40 | - // format = 2001-08 |
|
| 41 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | - } |
|
| 44 | - return ''; |
|
| 40 | + // format = 2001-08 |
|
| 41 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 42 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 43 | + } |
|
| 44 | + return ''; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | |
@@ -63,29 +63,29 @@ discard block |
||
| 63 | 63 | * - une chaîne vide si la date est considérée nulle |
| 64 | 64 | **/ |
| 65 | 65 | function normaliser_date($date, $forcer_jour = false): string { |
| 66 | - $date = vider_date($date); |
|
| 67 | - if ($date) { |
|
| 68 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | - $date = date('Y-m-d H:i:s', $date); |
|
| 70 | - } |
|
| 71 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | - } else { |
|
| 75 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | - } else { |
|
| 79 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - if ($forcer_jour) { |
|
| 84 | - $date = str_replace('-00', '-01', $date); |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return $date; |
|
| 66 | + $date = vider_date($date); |
|
| 67 | + if ($date) { |
|
| 68 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 69 | + $date = date('Y-m-d H:i:s', $date); |
|
| 70 | + } |
|
| 71 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 72 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 73 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 74 | + } else { |
|
| 75 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 76 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 77 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 78 | + } else { |
|
| 79 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + if ($forcer_jour) { |
|
| 84 | + $date = str_replace('-00', '-01', $date); |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return $date; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -98,23 +98,23 @@ discard block |
||
| 98 | 98 | * - Une chaine vide |
| 99 | 99 | **/ |
| 100 | 100 | function vider_date($letexte, $verif_format_date = false): string { |
| 101 | - $letexte ??= ''; |
|
| 102 | - if ( |
|
| 103 | - !$verif_format_date |
|
| 104 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | - ) { |
|
| 107 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | - return ''; |
|
| 112 | - } |
|
| 113 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | - return ''; |
|
| 115 | - } // eviter le bug GMT-1 |
|
| 116 | - } |
|
| 117 | - return $letexte; |
|
| 101 | + $letexte ??= ''; |
|
| 102 | + if ( |
|
| 103 | + !$verif_format_date |
|
| 104 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 105 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 106 | + ) { |
|
| 107 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 111 | + return ''; |
|
| 112 | + } |
|
| 113 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 114 | + return ''; |
|
| 115 | + } // eviter le bug GMT-1 |
|
| 116 | + } |
|
| 117 | + return $letexte; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | /** |
@@ -130,17 +130,17 @@ discard block |
||
| 130 | 130 | **/ |
| 131 | 131 | function recup_heure($date): array { |
| 132 | 132 | |
| 133 | - if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | - array_shift($elements); |
|
| 135 | - if (!isset($elements[2])) { |
|
| 136 | - $elements[2] = 0; |
|
| 137 | - } |
|
| 138 | - $heure = $elements; |
|
| 139 | - } else { |
|
| 140 | - $heure = [0, 0, 0]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return $heure; |
|
| 133 | + if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 134 | + array_shift($elements); |
|
| 135 | + if (!isset($elements[2])) { |
|
| 136 | + $elements[2] = 0; |
|
| 137 | + } |
|
| 138 | + $heure = $elements; |
|
| 139 | + } else { |
|
| 140 | + $heure = [0, 0, 0]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return $heure; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | /** |
@@ -154,13 +154,13 @@ discard block |
||
| 154 | 154 | * @return string heures, sinon 0 |
| 155 | 155 | **/ |
| 156 | 156 | function heures($numdate): string { |
| 157 | - $heures = null; |
|
| 158 | - $date_array = recup_heure($numdate); |
|
| 159 | - if ($date_array) { |
|
| 160 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | - } |
|
| 157 | + $heures = null; |
|
| 158 | + $date_array = recup_heure($numdate); |
|
| 159 | + if ($date_array) { |
|
| 160 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | - return $heures; |
|
| 163 | + return $heures; |
|
| 164 | 164 | } |
| 165 | 165 | |
| 166 | 166 | /** |
@@ -174,13 +174,13 @@ discard block |
||
| 174 | 174 | * @return string minutes, sinon 0 |
| 175 | 175 | **/ |
| 176 | 176 | function minutes($numdate): string { |
| 177 | - $minutes = null; |
|
| 178 | - $date_array = recup_heure($numdate); |
|
| 179 | - if ($date_array) { |
|
| 180 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | - } |
|
| 177 | + $minutes = null; |
|
| 178 | + $date_array = recup_heure($numdate); |
|
| 179 | + if ($date_array) { |
|
| 180 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $minutes; |
|
| 183 | + return $minutes; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,13 +194,13 @@ discard block |
||
| 194 | 194 | * @return string secondes, sinon 0 |
| 195 | 195 | **/ |
| 196 | 196 | function secondes($numdate): string { |
| 197 | - $secondes = null; |
|
| 198 | - $date_array = recup_heure($numdate); |
|
| 199 | - if ($date_array) { |
|
| 200 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | - } |
|
| 197 | + $secondes = null; |
|
| 198 | + $date_array = recup_heure($numdate); |
|
| 199 | + if ($date_array) { |
|
| 200 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $secondes; |
|
| 203 | + return $secondes; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -219,11 +219,11 @@ discard block |
||
| 219 | 219 | * @return string L'heure formatée dans la langue en cours. |
| 220 | 220 | **/ |
| 221 | 221 | function heures_minutes($numdate, $forme = ''): string { |
| 222 | - if ($forme !== 'abbr') { |
|
| 223 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | - } else { |
|
| 225 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | - } |
|
| 222 | + if ($forme !== 'abbr') { |
|
| 223 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 224 | + } else { |
|
| 225 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 226 | + } |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -248,57 +248,57 @@ discard block |
||
| 248 | 248 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 249 | 249 | **/ |
| 250 | 250 | function recup_date($numdate, $forcer_jour = true): array { |
| 251 | - if (!$numdate) { |
|
| 252 | - return []; |
|
| 253 | - } |
|
| 254 | - $heures = $minutes = $secondes = 0; |
|
| 255 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | - $jour = $regs[1]; |
|
| 257 | - $mois = $regs[2]; |
|
| 258 | - $annee = $regs[3]; |
|
| 259 | - if ($annee < 90) { |
|
| 260 | - $annee = 2000 + $annee; |
|
| 261 | - } elseif ($annee < 100) { |
|
| 262 | - $annee = 1900 + $annee; |
|
| 263 | - } |
|
| 264 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | - $annee = $regs[1]; |
|
| 267 | - $mois = $regs[2]; |
|
| 268 | - $jour = $regs[3]; |
|
| 269 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | - $annee = $regs[1]; |
|
| 272 | - $mois = $regs[2]; |
|
| 273 | - $jour = ''; |
|
| 274 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | - $annee = $regs[1]; |
|
| 277 | - $mois = $regs[2]; |
|
| 278 | - $jour = $regs[3]; |
|
| 279 | - $heures = $regs[4]; |
|
| 280 | - $minutes = $regs[5]; |
|
| 281 | - $secondes = $regs[6]; |
|
| 282 | - } else { |
|
| 283 | - $annee = $mois = $jour = ''; |
|
| 284 | - } |
|
| 285 | - if ($annee > 4000) { |
|
| 286 | - $annee -= 9000; |
|
| 287 | - } |
|
| 288 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | - $jour = substr($jour, 1); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - if ($forcer_jour and $jour == '0') { |
|
| 293 | - $jour = '1'; |
|
| 294 | - } |
|
| 295 | - if ($forcer_jour and $mois == '0') { |
|
| 296 | - $mois = '1'; |
|
| 297 | - } |
|
| 298 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | - } |
|
| 301 | - return []; |
|
| 251 | + if (!$numdate) { |
|
| 252 | + return []; |
|
| 253 | + } |
|
| 254 | + $heures = $minutes = $secondes = 0; |
|
| 255 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 256 | + $jour = $regs[1]; |
|
| 257 | + $mois = $regs[2]; |
|
| 258 | + $annee = $regs[3]; |
|
| 259 | + if ($annee < 90) { |
|
| 260 | + $annee = 2000 + $annee; |
|
| 261 | + } elseif ($annee < 100) { |
|
| 262 | + $annee = 1900 + $annee; |
|
| 263 | + } |
|
| 264 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 266 | + $annee = $regs[1]; |
|
| 267 | + $mois = $regs[2]; |
|
| 268 | + $jour = $regs[3]; |
|
| 269 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 271 | + $annee = $regs[1]; |
|
| 272 | + $mois = $regs[2]; |
|
| 273 | + $jour = ''; |
|
| 274 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 275 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 276 | + $annee = $regs[1]; |
|
| 277 | + $mois = $regs[2]; |
|
| 278 | + $jour = $regs[3]; |
|
| 279 | + $heures = $regs[4]; |
|
| 280 | + $minutes = $regs[5]; |
|
| 281 | + $secondes = $regs[6]; |
|
| 282 | + } else { |
|
| 283 | + $annee = $mois = $jour = ''; |
|
| 284 | + } |
|
| 285 | + if ($annee > 4000) { |
|
| 286 | + $annee -= 9000; |
|
| 287 | + } |
|
| 288 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 289 | + $jour = substr($jour, 1); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + if ($forcer_jour and $jour == '0') { |
|
| 293 | + $jour = '1'; |
|
| 294 | + } |
|
| 295 | + if ($forcer_jour and $mois == '0') { |
|
| 296 | + $mois = '1'; |
|
| 297 | + } |
|
| 298 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 299 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 300 | + } |
|
| 301 | + return []; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | * La date relative ou complète |
| 326 | 326 | **/ |
| 327 | 327 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 328 | - return sinon( |
|
| 329 | - date_relative($date, $decalage_maxi), |
|
| 330 | - affdate_heure($date) |
|
| 331 | - ); |
|
| 328 | + return sinon( |
|
| 329 | + date_relative($date, $decalage_maxi), |
|
| 330 | + affdate_heure($date) |
|
| 331 | + ); |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -361,86 +361,86 @@ discard block |
||
| 361 | 361 | **/ |
| 362 | 362 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 363 | 363 | |
| 364 | - if (!$date) { |
|
| 365 | - return ''; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - if (is_null($ref_date)) { |
|
| 369 | - $ref_time = time(); |
|
| 370 | - } else { |
|
| 371 | - $ref_time = strtotime($ref_date); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | - |
|
| 376 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | - return ''; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($decal < 0) { |
|
| 381 | - $il_y_a = 'date_dans'; |
|
| 382 | - $decal = -1 * $decal; |
|
| 383 | - } else { |
|
| 384 | - $il_y_a = 'date_il_y_a'; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | - return affdate_court($date); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - if ($decal > 3600 * 24 * 30) { |
|
| 392 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | - if ($mois < 2) { |
|
| 394 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | - } else { |
|
| 396 | - $delai = "$mois " . _T('date_mois'); |
|
| 397 | - } |
|
| 398 | - } else { |
|
| 399 | - if ($decal > 3600 * 24 * 7) { |
|
| 400 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | - if ($semaines < 2) { |
|
| 402 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | - } else { |
|
| 404 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | - } |
|
| 406 | - } else { |
|
| 407 | - if ($decal > 3600 * 24) { |
|
| 408 | - $jours = floor($decal / (3600 * 24)); |
|
| 409 | - if ($jours < 2) { |
|
| 410 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | - } else { |
|
| 412 | - $delai = "$jours " . _T('date_jours'); |
|
| 413 | - } |
|
| 414 | - } else { |
|
| 415 | - if ($decal >= 3600) { |
|
| 416 | - $heures = floor($decal / 3600); |
|
| 417 | - if ($heures < 2) { |
|
| 418 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | - } else { |
|
| 420 | - $delai = "$heures " . _T('date_heures'); |
|
| 421 | - } |
|
| 422 | - } else { |
|
| 423 | - if ($decal >= 60) { |
|
| 424 | - $minutes = floor($decal / 60); |
|
| 425 | - if ($minutes < 2) { |
|
| 426 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | - } else { |
|
| 428 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | - } |
|
| 430 | - } else { |
|
| 431 | - $secondes = ceil($decal); |
|
| 432 | - if ($secondes < 2) { |
|
| 433 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | - } else { |
|
| 435 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 364 | + if (!$date) { |
|
| 365 | + return ''; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + if (is_null($ref_date)) { |
|
| 369 | + $ref_time = time(); |
|
| 370 | + } else { |
|
| 371 | + $ref_time = strtotime($ref_date); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 375 | + |
|
| 376 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 377 | + return ''; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($decal < 0) { |
|
| 381 | + $il_y_a = 'date_dans'; |
|
| 382 | + $decal = -1 * $decal; |
|
| 383 | + } else { |
|
| 384 | + $il_y_a = 'date_il_y_a'; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 388 | + return affdate_court($date); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + if ($decal > 3600 * 24 * 30) { |
|
| 392 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 393 | + if ($mois < 2) { |
|
| 394 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 395 | + } else { |
|
| 396 | + $delai = "$mois " . _T('date_mois'); |
|
| 397 | + } |
|
| 398 | + } else { |
|
| 399 | + if ($decal > 3600 * 24 * 7) { |
|
| 400 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 401 | + if ($semaines < 2) { |
|
| 402 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 403 | + } else { |
|
| 404 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 405 | + } |
|
| 406 | + } else { |
|
| 407 | + if ($decal > 3600 * 24) { |
|
| 408 | + $jours = floor($decal / (3600 * 24)); |
|
| 409 | + if ($jours < 2) { |
|
| 410 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 411 | + } else { |
|
| 412 | + $delai = "$jours " . _T('date_jours'); |
|
| 413 | + } |
|
| 414 | + } else { |
|
| 415 | + if ($decal >= 3600) { |
|
| 416 | + $heures = floor($decal / 3600); |
|
| 417 | + if ($heures < 2) { |
|
| 418 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 419 | + } else { |
|
| 420 | + $delai = "$heures " . _T('date_heures'); |
|
| 421 | + } |
|
| 422 | + } else { |
|
| 423 | + if ($decal >= 60) { |
|
| 424 | + $minutes = floor($decal / 60); |
|
| 425 | + if ($minutes < 2) { |
|
| 426 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 427 | + } else { |
|
| 428 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 429 | + } |
|
| 430 | + } else { |
|
| 431 | + $secondes = ceil($decal); |
|
| 432 | + if ($secondes < 2) { |
|
| 433 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 434 | + } else { |
|
| 435 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
@@ -466,32 +466,32 @@ discard block |
||
| 466 | 466 | **/ |
| 467 | 467 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 468 | 468 | |
| 469 | - if (!$date) { |
|
| 470 | - return ''; |
|
| 471 | - } |
|
| 472 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | - |
|
| 474 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | - return ''; |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if ($decal < -24 * 3600) { |
|
| 479 | - $retour = date_relative($date, $decalage_maxi); |
|
| 480 | - } elseif ($decal < 0) { |
|
| 481 | - $retour = _T('date_demain'); |
|
| 482 | - } else { |
|
| 483 | - if ($decal < (3600 * 24)) { |
|
| 484 | - $retour = _T('date_aujourdhui'); |
|
| 485 | - } else { |
|
| 486 | - if ($decal < (3600 * 24 * 2)) { |
|
| 487 | - $retour = _T('date_hier'); |
|
| 488 | - } else { |
|
| 489 | - $retour = date_relative($date, $decalage_maxi); |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return $retour; |
|
| 469 | + if (!$date) { |
|
| 470 | + return ''; |
|
| 471 | + } |
|
| 472 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 473 | + |
|
| 474 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 475 | + return ''; |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($decal < -24 * 3600) { |
|
| 479 | + $retour = date_relative($date, $decalage_maxi); |
|
| 480 | + } elseif ($decal < 0) { |
|
| 481 | + $retour = _T('date_demain'); |
|
| 482 | + } else { |
|
| 483 | + if ($decal < (3600 * 24)) { |
|
| 484 | + $retour = _T('date_aujourdhui'); |
|
| 485 | + } else { |
|
| 486 | + if ($decal < (3600 * 24 * 2)) { |
|
| 487 | + $retour = _T('date_hier'); |
|
| 488 | + } else { |
|
| 489 | + $retour = date_relative($date, $decalage_maxi); |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return $retour; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -508,174 +508,174 @@ discard block |
||
| 508 | 508 | * @return string |
| 509 | 509 | */ |
| 510 | 510 | function affdate_base($numdate, $vue, $options = []): string { |
| 511 | - if (is_string($options)) { |
|
| 512 | - $options = ['param' => $options]; |
|
| 513 | - } |
|
| 514 | - $date_array = recup_date($numdate, false); |
|
| 515 | - if (!$date_array) { |
|
| 516 | - return ''; |
|
| 517 | - } |
|
| 518 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | - |
|
| 520 | - // 1er, 21st, etc. |
|
| 521 | - $journum = $jour; |
|
| 522 | - |
|
| 523 | - if ($jour == 0) { |
|
| 524 | - $jour = ''; |
|
| 525 | - $njour = 0; |
|
| 526 | - } else { |
|
| 527 | - $njour = intval($jour); |
|
| 528 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | - $jour = $jourth; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - $mois = intval($mois); |
|
| 534 | - if ($mois > 0 and $mois < 13) { |
|
| 535 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | - if ($jour) { |
|
| 539 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | - } else { |
|
| 541 | - $jourmois = $nommois; |
|
| 542 | - } |
|
| 543 | - } else { |
|
| 544 | - $nommois = ''; |
|
| 545 | - $jourmois = ''; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - if ($annee < 0) { |
|
| 549 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | - $avjc = true; |
|
| 551 | - } else { |
|
| 552 | - $avjc = false; |
|
| 553 | - } |
|
| 554 | - |
|
| 555 | - switch ($vue) { |
|
| 556 | - case 'saison': |
|
| 557 | - case 'saison_annee': |
|
| 558 | - $saison = ''; |
|
| 559 | - if ($mois > 0) { |
|
| 560 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | - } |
|
| 564 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | - } |
|
| 567 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | - } |
|
| 570 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | - } |
|
| 573 | - } |
|
| 574 | - if ($vue == 'saison') { |
|
| 575 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | - } else { |
|
| 577 | - return $saison ? trim(_T( |
|
| 578 | - 'date_fmt_saison_annee', |
|
| 579 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | - )) : ''; |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - case 'court': |
|
| 584 | - if ($avjc) { |
|
| 585 | - return $annee; |
|
| 586 | - } |
|
| 587 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | - return $annee; |
|
| 590 | - } |
|
| 591 | - if ($annee != $a) { |
|
| 592 | - return _T( |
|
| 593 | - 'date_fmt_mois_annee', |
|
| 594 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | - ); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return _T( |
|
| 599 | - 'date_fmt_jour_mois', |
|
| 600 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | - ); |
|
| 602 | - |
|
| 603 | - case 'jourcourt': |
|
| 604 | - if ($avjc) { |
|
| 605 | - return $annee; |
|
| 606 | - } |
|
| 607 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | - return $annee; |
|
| 610 | - } |
|
| 611 | - if ($annee != $a) { |
|
| 612 | - return _T( |
|
| 613 | - 'date_fmt_jour_mois_annee', |
|
| 614 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | - ); |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - return _T( |
|
| 619 | - 'date_fmt_jour_mois', |
|
| 620 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | - ); |
|
| 622 | - |
|
| 623 | - case 'entier': |
|
| 624 | - if ($avjc) { |
|
| 625 | - return $annee; |
|
| 626 | - } |
|
| 627 | - if ($jour) { |
|
| 628 | - return _T( |
|
| 629 | - 'date_fmt_jour_mois_annee', |
|
| 630 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | - ); |
|
| 632 | - } elseif ($mois) { |
|
| 633 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | - } else { |
|
| 635 | - return $annee; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - case 'nom_mois': |
|
| 639 | - return $nommois; |
|
| 640 | - |
|
| 641 | - case 'mois': |
|
| 642 | - return sprintf('%02s', $mois); |
|
| 643 | - |
|
| 644 | - case 'jour': |
|
| 645 | - return $jour; |
|
| 646 | - |
|
| 647 | - case 'journum': |
|
| 648 | - return $journum; |
|
| 649 | - |
|
| 650 | - case 'nom_jour': |
|
| 651 | - if (!$mois or !$njour) { |
|
| 652 | - return ''; |
|
| 653 | - } |
|
| 654 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | - $nom = 1 + (int) date('w', $nom); |
|
| 656 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | - |
|
| 658 | - return _T('date_jour_' . $nom . $param); |
|
| 659 | - |
|
| 660 | - case 'mois_annee': |
|
| 661 | - if ($avjc) { |
|
| 662 | - return $annee; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | - |
|
| 667 | - case 'annee': |
|
| 668 | - return $annee; |
|
| 669 | - |
|
| 670 | - // Cas d'une vue non definie : retomber sur le format |
|
| 671 | - // de date propose par http://www.php.net/date |
|
| 672 | - default: |
|
| 673 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | - $time = strtotime($numdate); |
|
| 676 | - } |
|
| 677 | - return date($vue, $time); |
|
| 678 | - } |
|
| 511 | + if (is_string($options)) { |
|
| 512 | + $options = ['param' => $options]; |
|
| 513 | + } |
|
| 514 | + $date_array = recup_date($numdate, false); |
|
| 515 | + if (!$date_array) { |
|
| 516 | + return ''; |
|
| 517 | + } |
|
| 518 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 519 | + |
|
| 520 | + // 1er, 21st, etc. |
|
| 521 | + $journum = $jour; |
|
| 522 | + |
|
| 523 | + if ($jour == 0) { |
|
| 524 | + $jour = ''; |
|
| 525 | + $njour = 0; |
|
| 526 | + } else { |
|
| 527 | + $njour = intval($jour); |
|
| 528 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 529 | + $jour = $jourth; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + $mois = intval($mois); |
|
| 534 | + if ($mois > 0 and $mois < 13) { |
|
| 535 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 536 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 537 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 538 | + if ($jour) { |
|
| 539 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 540 | + } else { |
|
| 541 | + $jourmois = $nommois; |
|
| 542 | + } |
|
| 543 | + } else { |
|
| 544 | + $nommois = ''; |
|
| 545 | + $jourmois = ''; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + if ($annee < 0) { |
|
| 549 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 550 | + $avjc = true; |
|
| 551 | + } else { |
|
| 552 | + $avjc = false; |
|
| 553 | + } |
|
| 554 | + |
|
| 555 | + switch ($vue) { |
|
| 556 | + case 'saison': |
|
| 557 | + case 'saison_annee': |
|
| 558 | + $saison = ''; |
|
| 559 | + if ($mois > 0) { |
|
| 560 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 561 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 562 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 563 | + } |
|
| 564 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 565 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 566 | + } |
|
| 567 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 568 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 569 | + } |
|
| 570 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 571 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 572 | + } |
|
| 573 | + } |
|
| 574 | + if ($vue == 'saison') { |
|
| 575 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 576 | + } else { |
|
| 577 | + return $saison ? trim(_T( |
|
| 578 | + 'date_fmt_saison_annee', |
|
| 579 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 580 | + )) : ''; |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + case 'court': |
|
| 584 | + if ($avjc) { |
|
| 585 | + return $annee; |
|
| 586 | + } |
|
| 587 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 588 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 589 | + return $annee; |
|
| 590 | + } |
|
| 591 | + if ($annee != $a) { |
|
| 592 | + return _T( |
|
| 593 | + 'date_fmt_mois_annee', |
|
| 594 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 595 | + ); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return _T( |
|
| 599 | + 'date_fmt_jour_mois', |
|
| 600 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 601 | + ); |
|
| 602 | + |
|
| 603 | + case 'jourcourt': |
|
| 604 | + if ($avjc) { |
|
| 605 | + return $annee; |
|
| 606 | + } |
|
| 607 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 608 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 609 | + return $annee; |
|
| 610 | + } |
|
| 611 | + if ($annee != $a) { |
|
| 612 | + return _T( |
|
| 613 | + 'date_fmt_jour_mois_annee', |
|
| 614 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 615 | + ); |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + return _T( |
|
| 619 | + 'date_fmt_jour_mois', |
|
| 620 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 621 | + ); |
|
| 622 | + |
|
| 623 | + case 'entier': |
|
| 624 | + if ($avjc) { |
|
| 625 | + return $annee; |
|
| 626 | + } |
|
| 627 | + if ($jour) { |
|
| 628 | + return _T( |
|
| 629 | + 'date_fmt_jour_mois_annee', |
|
| 630 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 631 | + ); |
|
| 632 | + } elseif ($mois) { |
|
| 633 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 634 | + } else { |
|
| 635 | + return $annee; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + case 'nom_mois': |
|
| 639 | + return $nommois; |
|
| 640 | + |
|
| 641 | + case 'mois': |
|
| 642 | + return sprintf('%02s', $mois); |
|
| 643 | + |
|
| 644 | + case 'jour': |
|
| 645 | + return $jour; |
|
| 646 | + |
|
| 647 | + case 'journum': |
|
| 648 | + return $journum; |
|
| 649 | + |
|
| 650 | + case 'nom_jour': |
|
| 651 | + if (!$mois or !$njour) { |
|
| 652 | + return ''; |
|
| 653 | + } |
|
| 654 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 655 | + $nom = 1 + (int) date('w', $nom); |
|
| 656 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 657 | + |
|
| 658 | + return _T('date_jour_' . $nom . $param); |
|
| 659 | + |
|
| 660 | + case 'mois_annee': |
|
| 661 | + if ($avjc) { |
|
| 662 | + return $annee; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 666 | + |
|
| 667 | + case 'annee': |
|
| 668 | + return $annee; |
|
| 669 | + |
|
| 670 | + // Cas d'une vue non definie : retomber sur le format |
|
| 671 | + // de date propose par http://www.php.net/date |
|
| 672 | + default: |
|
| 673 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 674 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 675 | + $time = strtotime($numdate); |
|
| 676 | + } |
|
| 677 | + return date($vue, $time); |
|
| 678 | + } |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -702,11 +702,11 @@ discard block |
||
| 702 | 702 | * Nom du jour |
| 703 | 703 | **/ |
| 704 | 704 | function nom_jour($numdate, $forme = ''): string { |
| 705 | - if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | - $forme = ''; |
|
| 707 | - } |
|
| 705 | + if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 706 | + $forme = ''; |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 709 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | * Numéro du jour |
| 729 | 729 | **/ |
| 730 | 730 | function jour($numdate): string { |
| 731 | - return affdate_base($numdate, 'jour'); |
|
| 731 | + return affdate_base($numdate, 'jour'); |
|
| 732 | 732 | } |
| 733 | 733 | |
| 734 | 734 | /** |
@@ -746,7 +746,7 @@ discard block |
||
| 746 | 746 | * Numéro du jour |
| 747 | 747 | **/ |
| 748 | 748 | function journum($numdate): string { |
| 749 | - return affdate_base($numdate, 'journum'); |
|
| 749 | + return affdate_base($numdate, 'journum'); |
|
| 750 | 750 | } |
| 751 | 751 | |
| 752 | 752 | /** |
@@ -764,7 +764,7 @@ discard block |
||
| 764 | 764 | * Numéro du mois (sur 2 chiffres) |
| 765 | 765 | **/ |
| 766 | 766 | function mois($numdate): string { |
| 767 | - return affdate_base($numdate, 'mois'); |
|
| 767 | + return affdate_base($numdate, 'mois'); |
|
| 768 | 768 | } |
| 769 | 769 | |
| 770 | 770 | /** |
@@ -788,11 +788,11 @@ discard block |
||
| 788 | 788 | * Nom du mois |
| 789 | 789 | **/ |
| 790 | 790 | function nom_mois($numdate, $forme = ''): string { |
| 791 | - if (!($forme === 'abbr')) { |
|
| 792 | - $forme = ''; |
|
| 793 | - } |
|
| 791 | + if (!($forme === 'abbr')) { |
|
| 792 | + $forme = ''; |
|
| 793 | + } |
|
| 794 | 794 | |
| 795 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 795 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -810,7 +810,7 @@ discard block |
||
| 810 | 810 | * Année (sur 4 chiffres) |
| 811 | 811 | **/ |
| 812 | 812 | function annee($numdate): string { |
| 813 | - return affdate_base($numdate, 'annee'); |
|
| 813 | + return affdate_base($numdate, 'annee'); |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | |
@@ -840,11 +840,11 @@ discard block |
||
| 840 | 840 | * La date formatée |
| 841 | 841 | **/ |
| 842 | 842 | function saison($numdate, $hemisphere = 'nord'): string { |
| 843 | - if ($hemisphere !== 'sud') { |
|
| 844 | - $hemisphere = 'nord'; |
|
| 845 | - } |
|
| 843 | + if ($hemisphere !== 'sud') { |
|
| 844 | + $hemisphere = 'nord'; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 847 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 848 | 848 | } |
| 849 | 849 | |
| 850 | 850 | |
@@ -873,11 +873,11 @@ discard block |
||
| 873 | 873 | * La date formatée |
| 874 | 874 | **/ |
| 875 | 875 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 876 | - if ($hemisphere !== 'sud') { |
|
| 877 | - $hemisphere = 'nord'; |
|
| 878 | - } |
|
| 876 | + if ($hemisphere !== 'sud') { |
|
| 877 | + $hemisphere = 'nord'; |
|
| 878 | + } |
|
| 879 | 879 | |
| 880 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 880 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 881 | 881 | } |
| 882 | 882 | |
| 883 | 883 | /** |
@@ -905,7 +905,7 @@ discard block |
||
| 905 | 905 | * La date formatée |
| 906 | 906 | **/ |
| 907 | 907 | function affdate($numdate, $format = 'entier'): string { |
| 908 | - return affdate_base($numdate, $format); |
|
| 908 | + return affdate_base($numdate, $format); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | |
@@ -932,7 +932,7 @@ discard block |
||
| 932 | 932 | * La date formatée |
| 933 | 933 | **/ |
| 934 | 934 | function affdate_court($numdate, $annee_courante = null): string { |
| 935 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 935 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 936 | 936 | } |
| 937 | 937 | |
| 938 | 938 | |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | * La date formatée |
| 960 | 960 | **/ |
| 961 | 961 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 962 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 962 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 963 | 963 | } |
| 964 | 964 | |
| 965 | 965 | /** |
@@ -977,7 +977,7 @@ discard block |
||
| 977 | 977 | * La date formatée |
| 978 | 978 | **/ |
| 979 | 979 | function affdate_mois_annee($numdate): string { |
| 980 | - return affdate_base($numdate, 'mois_annee'); |
|
| 980 | + return affdate_base($numdate, 'mois_annee'); |
|
| 981 | 981 | } |
| 982 | 982 | |
| 983 | 983 | /** |
@@ -995,16 +995,16 @@ discard block |
||
| 995 | 995 | * La date formatée, sinon '' |
| 996 | 996 | **/ |
| 997 | 997 | function affdate_heure($numdate): string { |
| 998 | - $date_array = recup_date($numdate); |
|
| 999 | - if (!$date_array) { |
|
| 1000 | - return ''; |
|
| 1001 | - } |
|
| 1002 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | - |
|
| 1004 | - return _T('date_fmt_jour_heure', [ |
|
| 1005 | - 'jour' => affdate($numdate), |
|
| 1006 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | - ]); |
|
| 998 | + $date_array = recup_date($numdate); |
|
| 999 | + if (!$date_array) { |
|
| 1000 | + return ''; |
|
| 1001 | + } |
|
| 1002 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1003 | + |
|
| 1004 | + return _T('date_fmt_jour_heure', [ |
|
| 1005 | + 'jour' => affdate($numdate), |
|
| 1006 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1007 | + ]); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1036,117 +1036,117 @@ discard block |
||
| 1036 | 1036 | * texte de la date |
| 1037 | 1037 | */ |
| 1038 | 1038 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1039 | - $abbr = $jour = ''; |
|
| 1040 | - $affdate = 'affdate_jourcourt'; |
|
| 1041 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | - $abbr = 'abbr'; |
|
| 1043 | - } |
|
| 1044 | - if (strpos($forme, 'annee') !== false) { |
|
| 1045 | - $affdate = 'affdate'; |
|
| 1046 | - } |
|
| 1047 | - if (strpos($forme, 'jour') !== false) { |
|
| 1048 | - $jour = 'jour'; |
|
| 1049 | - } |
|
| 1050 | - |
|
| 1051 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | - $dtabbr = '</abbr>'; |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - $date_debut = strtotime($date_debut); |
|
| 1059 | - $date_fin = strtotime($date_fin); |
|
| 1060 | - $d = date('Y-m-d', $date_debut); |
|
| 1061 | - $f = date('Y-m-d', $date_fin); |
|
| 1062 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | - |
|
| 1066 | - if ($d == $f) { // meme jour |
|
| 1067 | - $nomjour = nom_jour($d, $abbr); |
|
| 1068 | - $s = $affdate($d); |
|
| 1069 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | - if ($h) { |
|
| 1071 | - if ($hd == $hf) { |
|
| 1072 | - // Lundi 20 fevrier a 18h25 |
|
| 1073 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | - $s = "$dtstart$s$dtabbr"; |
|
| 1075 | - } else { |
|
| 1076 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | - $s = _T( |
|
| 1079 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | - [ |
|
| 1081 | - 'jour' => spip_ucfirst($s), |
|
| 1082 | - 'heure_debut' => $hd, |
|
| 1083 | - 'heure_fin' => $hf, |
|
| 1084 | - 'dtstart' => $dtstart, |
|
| 1085 | - 'dtend' => $dtend, |
|
| 1086 | - 'dtabbr' => $dtabbr |
|
| 1087 | - ], |
|
| 1088 | - [ |
|
| 1089 | - 'sanitize' => false |
|
| 1090 | - ] |
|
| 1091 | - ); |
|
| 1092 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | - else { |
|
| 1094 | - $s = spip_ucfirst(_T( |
|
| 1095 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | - )); |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - } else { |
|
| 1101 | - if ($dtabbr && $dtstart) { |
|
| 1102 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | - } else { |
|
| 1104 | - $s = spip_ucfirst($s); |
|
| 1105 | - } |
|
| 1106 | - } |
|
| 1107 | - } else { |
|
| 1108 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | - if (!$h) { |
|
| 1110 | - $date_debut = jour($d); |
|
| 1111 | - } else { |
|
| 1112 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | - } |
|
| 1114 | - $date_fin = $affdate($f); |
|
| 1115 | - if ($jour) { |
|
| 1116 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | - } |
|
| 1121 | - if ($h) { |
|
| 1122 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | - } |
|
| 1125 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | - |
|
| 1128 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | - } else { |
|
| 1130 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | - $date_fin = $affdate($f); |
|
| 1132 | - if ($jour) { |
|
| 1133 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | - } |
|
| 1138 | - if ($h) { |
|
| 1139 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | - } |
|
| 1142 | - |
|
| 1143 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | - } |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - return $s; |
|
| 1039 | + $abbr = $jour = ''; |
|
| 1040 | + $affdate = 'affdate_jourcourt'; |
|
| 1041 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1042 | + $abbr = 'abbr'; |
|
| 1043 | + } |
|
| 1044 | + if (strpos($forme, 'annee') !== false) { |
|
| 1045 | + $affdate = 'affdate'; |
|
| 1046 | + } |
|
| 1047 | + if (strpos($forme, 'jour') !== false) { |
|
| 1048 | + $jour = 'jour'; |
|
| 1049 | + } |
|
| 1050 | + |
|
| 1051 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1052 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1053 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1054 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1055 | + $dtabbr = '</abbr>'; |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + $date_debut = strtotime($date_debut); |
|
| 1059 | + $date_fin = strtotime($date_fin); |
|
| 1060 | + $d = date('Y-m-d', $date_debut); |
|
| 1061 | + $f = date('Y-m-d', $date_fin); |
|
| 1062 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1063 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1064 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1065 | + |
|
| 1066 | + if ($d == $f) { // meme jour |
|
| 1067 | + $nomjour = nom_jour($d, $abbr); |
|
| 1068 | + $s = $affdate($d); |
|
| 1069 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1070 | + if ($h) { |
|
| 1071 | + if ($hd == $hf) { |
|
| 1072 | + // Lundi 20 fevrier a 18h25 |
|
| 1073 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1074 | + $s = "$dtstart$s$dtabbr"; |
|
| 1075 | + } else { |
|
| 1076 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1077 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1078 | + $s = _T( |
|
| 1079 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1080 | + [ |
|
| 1081 | + 'jour' => spip_ucfirst($s), |
|
| 1082 | + 'heure_debut' => $hd, |
|
| 1083 | + 'heure_fin' => $hf, |
|
| 1084 | + 'dtstart' => $dtstart, |
|
| 1085 | + 'dtend' => $dtend, |
|
| 1086 | + 'dtabbr' => $dtabbr |
|
| 1087 | + ], |
|
| 1088 | + [ |
|
| 1089 | + 'sanitize' => false |
|
| 1090 | + ] |
|
| 1091 | + ); |
|
| 1092 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1093 | + else { |
|
| 1094 | + $s = spip_ucfirst(_T( |
|
| 1095 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1096 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1097 | + )); |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + } else { |
|
| 1101 | + if ($dtabbr && $dtstart) { |
|
| 1102 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1103 | + } else { |
|
| 1104 | + $s = spip_ucfirst($s); |
|
| 1105 | + } |
|
| 1106 | + } |
|
| 1107 | + } else { |
|
| 1108 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1109 | + if (!$h) { |
|
| 1110 | + $date_debut = jour($d); |
|
| 1111 | + } else { |
|
| 1112 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1113 | + } |
|
| 1114 | + $date_fin = $affdate($f); |
|
| 1115 | + if ($jour) { |
|
| 1116 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1117 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1118 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1119 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1120 | + } |
|
| 1121 | + if ($h) { |
|
| 1122 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1123 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1124 | + } |
|
| 1125 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1126 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1127 | + |
|
| 1128 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1129 | + } else { |
|
| 1130 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1131 | + $date_fin = $affdate($f); |
|
| 1132 | + if ($jour) { |
|
| 1133 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1134 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1135 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1136 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1137 | + } |
|
| 1138 | + if ($h) { |
|
| 1139 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1140 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1141 | + } |
|
| 1142 | + |
|
| 1143 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1144 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1145 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1146 | + } |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + return $s; |
|
| 1150 | 1150 | } |
| 1151 | 1151 | |
| 1152 | 1152 | /** |
@@ -1167,10 +1167,10 @@ discard block |
||
| 1167 | 1167 | * Date au format ical |
| 1168 | 1168 | **/ |
| 1169 | 1169 | function date_ical($date, $addminutes = 0): string { |
| 1170 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1170 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1171 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1172 | 1172 | |
| 1173 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1173 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1174 | 1174 | } |
| 1175 | 1175 | |
| 1176 | 1176 | |
@@ -1194,11 +1194,11 @@ discard block |
||
| 1194 | 1194 | * La date formatée |
| 1195 | 1195 | **/ |
| 1196 | 1196 | function date_iso($date_heure): string { |
| 1197 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1197 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1198 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1199 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1200 | 1200 | |
| 1201 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1201 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | /** |
@@ -1221,11 +1221,11 @@ discard block |
||
| 1221 | 1221 | * La date formatée |
| 1222 | 1222 | **/ |
| 1223 | 1223 | function date_822($date_heure): string { |
| 1224 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1224 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1225 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1226 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1227 | 1227 | |
| 1228 | - return date('r', $time); |
|
| 1228 | + return date('r', $time); |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1241,11 +1241,11 @@ discard block |
||
| 1241 | 1241 | * Date au format `Ymd` |
| 1242 | 1242 | **/ |
| 1243 | 1243 | function date_anneemoisjour($d): string { |
| 1244 | - if (!$d) { |
|
| 1245 | - $d = date('Y-m-d'); |
|
| 1246 | - } |
|
| 1244 | + if (!$d) { |
|
| 1245 | + $d = date('Y-m-d'); |
|
| 1246 | + } |
|
| 1247 | 1247 | |
| 1248 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1248 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1249 | 1249 | } |
| 1250 | 1250 | |
| 1251 | 1251 | /** |
@@ -1261,11 +1261,11 @@ discard block |
||
| 1261 | 1261 | * Date au format `Ym` |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function date_anneemois($d): string { |
| 1264 | - if (!$d) { |
|
| 1265 | - $d = date('Y-m-d'); |
|
| 1266 | - } |
|
| 1264 | + if (!$d) { |
|
| 1265 | + $d = date('Y-m-d'); |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1268 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1269 | 1269 | } |
| 1270 | 1270 | |
| 1271 | 1271 | /** |
@@ -1281,13 +1281,13 @@ discard block |
||
| 1281 | 1281 | * Date au lundi de la même semaine au format `Ymd` |
| 1282 | 1282 | **/ |
| 1283 | 1283 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1284 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | - if ($w_day == 0) { |
|
| 1286 | - $w_day = 7; |
|
| 1287 | - } // Gaffe: le dimanche est zero |
|
| 1288 | - $debut = $jour - $w_day + 1; |
|
| 1284 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1285 | + if ($w_day == 0) { |
|
| 1286 | + $w_day = 7; |
|
| 1287 | + } // Gaffe: le dimanche est zero |
|
| 1288 | + $debut = $jour - $w_day + 1; |
|
| 1289 | 1289 | |
| 1290 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1290 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | /** |
@@ -1303,11 +1303,11 @@ discard block |
||
| 1303 | 1303 | * Date au dimanche de la même semaine au format `Ymd` |
| 1304 | 1304 | **/ |
| 1305 | 1305 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1306 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | - if ($w_day == 0) { |
|
| 1308 | - $w_day = 7; |
|
| 1309 | - } // Gaffe: le dimanche est zero |
|
| 1310 | - $debut = $jour - $w_day + 1; |
|
| 1306 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1307 | + if ($w_day == 0) { |
|
| 1308 | + $w_day = 7; |
|
| 1309 | + } // Gaffe: le dimanche est zero |
|
| 1310 | + $debut = $jour - $w_day + 1; |
|
| 1311 | 1311 | |
| 1312 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1312 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1313 | 1313 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -46,33 +46,33 @@ discard block |
||
| 46 | 46 | * Environnement du formulaire |
| 47 | 47 | **/ |
| 48 | 48 | function formulaires_editer_article_charger_dist( |
| 49 | - $id_article = 'new', |
|
| 50 | - $id_rubrique = 0, |
|
| 51 | - $retour = '', |
|
| 52 | - $lier_trad = 0, |
|
| 53 | - $config_fonc = 'articles_edit_config', |
|
| 54 | - $row = [], |
|
| 55 | - $hidden = '' |
|
| 49 | + $id_article = 'new', |
|
| 50 | + $id_rubrique = 0, |
|
| 51 | + $retour = '', |
|
| 52 | + $lier_trad = 0, |
|
| 53 | + $config_fonc = 'articles_edit_config', |
|
| 54 | + $row = [], |
|
| 55 | + $hidden = '' |
|
| 56 | 56 | ) { |
| 57 | - $valeurs = formulaires_editer_objet_charger( |
|
| 58 | - 'article', |
|
| 59 | - $id_article, |
|
| 60 | - $id_rubrique, |
|
| 61 | - $lier_trad, |
|
| 62 | - $retour, |
|
| 63 | - $config_fonc, |
|
| 64 | - $row, |
|
| 65 | - $hidden |
|
| 66 | - ); |
|
| 57 | + $valeurs = formulaires_editer_objet_charger( |
|
| 58 | + 'article', |
|
| 59 | + $id_article, |
|
| 60 | + $id_rubrique, |
|
| 61 | + $lier_trad, |
|
| 62 | + $retour, |
|
| 63 | + $config_fonc, |
|
| 64 | + $row, |
|
| 65 | + $hidden |
|
| 66 | + ); |
|
| 67 | 67 | |
| 68 | - if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 69 | - $valeurs['editable'] = ''; |
|
| 70 | - } |
|
| 68 | + if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 69 | + $valeurs['editable'] = ''; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // il faut enlever l'id_rubrique car la saisie se fait sur id_parent |
|
| 73 | - // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale |
|
| 74 | - // et sera perdue si elle est supposee saisie |
|
| 75 | - return $valeurs; |
|
| 72 | + // il faut enlever l'id_rubrique car la saisie se fait sur id_parent |
|
| 73 | + // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale |
|
| 74 | + // et sera perdue si elle est supposee saisie |
|
| 75 | + return $valeurs; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * Hash du formulaire |
| 98 | 98 | */ |
| 99 | 99 | function formulaires_editer_article_identifier_dist( |
| 100 | - $id_article = 'new', |
|
| 101 | - $id_rubrique = 0, |
|
| 102 | - $retour = '', |
|
| 103 | - $lier_trad = 0, |
|
| 104 | - $config_fonc = 'articles_edit_config', |
|
| 105 | - $row = [], |
|
| 106 | - $hidden = '' |
|
| 100 | + $id_article = 'new', |
|
| 101 | + $id_rubrique = 0, |
|
| 102 | + $retour = '', |
|
| 103 | + $lier_trad = 0, |
|
| 104 | + $config_fonc = 'articles_edit_config', |
|
| 105 | + $row = [], |
|
| 106 | + $hidden = '' |
|
| 107 | 107 | ) { |
| 108 | - return serialize([intval($id_article), $lier_trad]); |
|
| 108 | + return serialize([intval($id_article), $lier_trad]); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -118,12 +118,12 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function articles_edit_config(array $row): array { |
| 120 | 120 | |
| 121 | - $config = []; |
|
| 122 | - $config['lignes'] = 8; |
|
| 123 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 124 | - $config['restreint'] = ($row['statut'] === 'publie'); |
|
| 121 | + $config = []; |
|
| 122 | + $config['lignes'] = 8; |
|
| 123 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 124 | + $config['restreint'] = ($row['statut'] === 'publie'); |
|
| 125 | 125 | |
| 126 | - return $config; |
|
| 126 | + return $config; |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -149,43 +149,43 @@ discard block |
||
| 149 | 149 | * Erreurs du formulaire |
| 150 | 150 | **/ |
| 151 | 151 | function formulaires_editer_article_verifier_dist( |
| 152 | - $id_article = 'new', |
|
| 153 | - $id_rubrique = 0, |
|
| 154 | - $retour = '', |
|
| 155 | - $lier_trad = 0, |
|
| 156 | - $config_fonc = 'articles_edit_config', |
|
| 157 | - $row = [], |
|
| 158 | - $hidden = '' |
|
| 152 | + $id_article = 'new', |
|
| 153 | + $id_rubrique = 0, |
|
| 154 | + $retour = '', |
|
| 155 | + $lier_trad = 0, |
|
| 156 | + $config_fonc = 'articles_edit_config', |
|
| 157 | + $row = [], |
|
| 158 | + $hidden = '' |
|
| 159 | 159 | ) { |
| 160 | - // auto-renseigner le titre si il n'existe pas |
|
| 161 | - titre_automatique('titre', ['descriptif', 'chapo', 'texte']); |
|
| 162 | - if (!_request('id_parent') and !intval($id_article)) { |
|
| 163 | - $valeurs = formulaires_editer_objet_charger( |
|
| 164 | - 'article', |
|
| 165 | - $id_article, |
|
| 166 | - $id_rubrique, |
|
| 167 | - $lier_trad, |
|
| 168 | - $retour, |
|
| 169 | - $config_fonc, |
|
| 170 | - $row, |
|
| 171 | - $hidden |
|
| 172 | - ); |
|
| 173 | - set_request('id_parent', $valeurs['id_parent']); |
|
| 174 | - } |
|
| 175 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 176 | - $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']); |
|
| 177 | - // si on utilise le formulaire dans le public |
|
| 178 | - if (!function_exists('autoriser')) { |
|
| 179 | - include_spip('inc/autoriser'); |
|
| 180 | - } |
|
| 181 | - if ( |
|
| 182 | - !isset($erreurs['id_parent']) |
|
| 183 | - and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 184 | - ) { |
|
| 185 | - $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 186 | - } |
|
| 160 | + // auto-renseigner le titre si il n'existe pas |
|
| 161 | + titre_automatique('titre', ['descriptif', 'chapo', 'texte']); |
|
| 162 | + if (!_request('id_parent') and !intval($id_article)) { |
|
| 163 | + $valeurs = formulaires_editer_objet_charger( |
|
| 164 | + 'article', |
|
| 165 | + $id_article, |
|
| 166 | + $id_rubrique, |
|
| 167 | + $lier_trad, |
|
| 168 | + $retour, |
|
| 169 | + $config_fonc, |
|
| 170 | + $row, |
|
| 171 | + $hidden |
|
| 172 | + ); |
|
| 173 | + set_request('id_parent', $valeurs['id_parent']); |
|
| 174 | + } |
|
| 175 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 176 | + $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']); |
|
| 177 | + // si on utilise le formulaire dans le public |
|
| 178 | + if (!function_exists('autoriser')) { |
|
| 179 | + include_spip('inc/autoriser'); |
|
| 180 | + } |
|
| 181 | + if ( |
|
| 182 | + !isset($erreurs['id_parent']) |
|
| 183 | + and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 184 | + ) { |
|
| 185 | + $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | - return $erreurs; |
|
| 188 | + return $erreurs; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -211,29 +211,29 @@ discard block |
||
| 211 | 211 | * Retours des traitements |
| 212 | 212 | **/ |
| 213 | 213 | function formulaires_editer_article_traiter_dist( |
| 214 | - $id_article = 'new', |
|
| 215 | - $id_rubrique = 0, |
|
| 216 | - $retour = '', |
|
| 217 | - $lier_trad = 0, |
|
| 218 | - $config_fonc = 'articles_edit_config', |
|
| 219 | - $row = [], |
|
| 220 | - $hidden = '' |
|
| 214 | + $id_article = 'new', |
|
| 215 | + $id_rubrique = 0, |
|
| 216 | + $retour = '', |
|
| 217 | + $lier_trad = 0, |
|
| 218 | + $config_fonc = 'articles_edit_config', |
|
| 219 | + $row = [], |
|
| 220 | + $hidden = '' |
|
| 221 | 221 | ) { |
| 222 | - // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 223 | - // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 224 | - // en fonction de la config du site et de la rubrique choisie |
|
| 225 | - if (!$lier_trad) { |
|
| 226 | - set_request('changer_lang'); |
|
| 227 | - } |
|
| 222 | + // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 223 | + // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 224 | + // en fonction de la config du site et de la rubrique choisie |
|
| 225 | + if (!$lier_trad) { |
|
| 226 | + set_request('changer_lang'); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return formulaires_editer_objet_traiter( |
|
| 230 | - 'article', |
|
| 231 | - $id_article, |
|
| 232 | - $id_rubrique, |
|
| 233 | - $lier_trad, |
|
| 234 | - $retour, |
|
| 235 | - $config_fonc, |
|
| 236 | - $row, |
|
| 237 | - $hidden |
|
| 238 | - ); |
|
| 229 | + return formulaires_editer_objet_traiter( |
|
| 230 | + 'article', |
|
| 231 | + $id_article, |
|
| 232 | + $id_rubrique, |
|
| 233 | + $lier_trad, |
|
| 234 | + $retour, |
|
| 235 | + $config_fonc, |
|
| 236 | + $row, |
|
| 237 | + $hidden |
|
| 238 | + ); |
|
| 239 | 239 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | * Environnement du formulaire |
| 48 | 48 | **/ |
| 49 | 49 | function formulaires_editer_rubrique_charger_dist( |
| 50 | - $id_rubrique = 'new', |
|
| 51 | - $id_parent = 0, |
|
| 52 | - $retour = '', |
|
| 53 | - $lier_trad = 0, |
|
| 54 | - $config_fonc = 'rubriques_edit_config', |
|
| 55 | - $row = [], |
|
| 56 | - $hidden = '' |
|
| 50 | + $id_rubrique = 'new', |
|
| 51 | + $id_parent = 0, |
|
| 52 | + $retour = '', |
|
| 53 | + $lier_trad = 0, |
|
| 54 | + $config_fonc = 'rubriques_edit_config', |
|
| 55 | + $row = [], |
|
| 56 | + $hidden = '' |
|
| 57 | 57 | ) { |
| 58 | - $valeurs = formulaires_editer_objet_charger( |
|
| 59 | - 'rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - $id_parent, |
|
| 62 | - $lier_trad, |
|
| 63 | - $retour, |
|
| 64 | - $config_fonc, |
|
| 65 | - $row, |
|
| 66 | - $hidden |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | - $valeurs['editable'] = ''; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $valeurs; |
|
| 58 | + $valeurs = formulaires_editer_objet_charger( |
|
| 59 | + 'rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + $id_parent, |
|
| 62 | + $lier_trad, |
|
| 63 | + $retour, |
|
| 64 | + $config_fonc, |
|
| 65 | + $row, |
|
| 66 | + $hidden |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | + $valeurs['editable'] = ''; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $valeurs; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -83,12 +83,12 @@ discard block |
||
| 83 | 83 | */ |
| 84 | 84 | function rubriques_edit_config(array $row): array { |
| 85 | 85 | |
| 86 | - $config = []; |
|
| 87 | - $config['lignes'] = 8; |
|
| 88 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | - $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 86 | + $config = []; |
|
| 87 | + $config['lignes'] = 8; |
|
| 88 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 89 | + $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 90 | 90 | |
| 91 | - return $config; |
|
| 91 | + return $config; |
|
| 92 | 92 | } |
| 93 | 93 | |
| 94 | 94 | /** |
@@ -113,15 +113,15 @@ discard block |
||
| 113 | 113 | * Hash du formulaire |
| 114 | 114 | */ |
| 115 | 115 | function formulaires_editer_rubrique_identifier_dist( |
| 116 | - $id_rubrique = 'new', |
|
| 117 | - $id_parent = 0, |
|
| 118 | - $retour = '', |
|
| 119 | - $lier_trad = 0, |
|
| 120 | - $config_fonc = 'rubriques_edit_config', |
|
| 121 | - $row = [], |
|
| 122 | - $hidden = '' |
|
| 116 | + $id_rubrique = 'new', |
|
| 117 | + $id_parent = 0, |
|
| 118 | + $retour = '', |
|
| 119 | + $lier_trad = 0, |
|
| 120 | + $config_fonc = 'rubriques_edit_config', |
|
| 121 | + $row = [], |
|
| 122 | + $hidden = '' |
|
| 123 | 123 | ) { |
| 124 | - return serialize([intval($id_rubrique), $lier_trad]); |
|
| 124 | + return serialize([intval($id_rubrique), $lier_trad]); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -147,34 +147,34 @@ discard block |
||
| 147 | 147 | * Erreurs du formulaire |
| 148 | 148 | **/ |
| 149 | 149 | function formulaires_editer_rubrique_verifier_dist( |
| 150 | - $id_rubrique = 'new', |
|
| 151 | - $id_parent = 0, |
|
| 152 | - $retour = '', |
|
| 153 | - $lier_trad = 0, |
|
| 154 | - $config_fonc = 'rubriques_edit_config', |
|
| 155 | - $row = [], |
|
| 156 | - $hidden = '' |
|
| 150 | + $id_rubrique = 'new', |
|
| 151 | + $id_parent = 0, |
|
| 152 | + $retour = '', |
|
| 153 | + $lier_trad = 0, |
|
| 154 | + $config_fonc = 'rubriques_edit_config', |
|
| 155 | + $row = [], |
|
| 156 | + $hidden = '' |
|
| 157 | 157 | ) { |
| 158 | - // auto-renseigner le titre si il n'existe pas |
|
| 159 | - titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | - $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | - |
|
| 163 | - // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | - if ( |
|
| 165 | - intval($id_rubrique) |
|
| 166 | - and empty($erreurs['id_parent']) |
|
| 167 | - and $id_parent = _request('id_parent') |
|
| 168 | - ) { |
|
| 169 | - include_spip('inc/rubriques'); |
|
| 170 | - $branche = calcul_branche_in($id_rubrique); |
|
| 171 | - $branche = explode(',', $branche); |
|
| 172 | - if (in_array($id_parent, $branche)) { |
|
| 173 | - $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - return $erreurs; |
|
| 158 | + // auto-renseigner le titre si il n'existe pas |
|
| 159 | + titre_automatique('titre', ['descriptif', 'texte']); |
|
| 160 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 161 | + $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, []); |
|
| 162 | + |
|
| 163 | + // s'assurer qu'on ne s'auto-designe pas comme parent ! |
|
| 164 | + if ( |
|
| 165 | + intval($id_rubrique) |
|
| 166 | + and empty($erreurs['id_parent']) |
|
| 167 | + and $id_parent = _request('id_parent') |
|
| 168 | + ) { |
|
| 169 | + include_spip('inc/rubriques'); |
|
| 170 | + $branche = calcul_branche_in($id_rubrique); |
|
| 171 | + $branche = explode(',', $branche); |
|
| 172 | + if (in_array($id_parent, $branche)) { |
|
| 173 | + $erreurs['id_parent'] = _L('Impossible de déplacer une rubrique dans sa propre branche, on tourne en rond !'); |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + return $erreurs; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -200,22 +200,22 @@ discard block |
||
| 200 | 200 | * Retour des traitements |
| 201 | 201 | **/ |
| 202 | 202 | function formulaires_editer_rubrique_traiter_dist( |
| 203 | - $id_rubrique = 'new', |
|
| 204 | - $id_parent = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $lier_trad = 0, |
|
| 207 | - $config_fonc = 'rubriques_edit_config', |
|
| 208 | - $row = [], |
|
| 209 | - $hidden = '' |
|
| 203 | + $id_rubrique = 'new', |
|
| 204 | + $id_parent = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $lier_trad = 0, |
|
| 207 | + $config_fonc = 'rubriques_edit_config', |
|
| 208 | + $row = [], |
|
| 209 | + $hidden = '' |
|
| 210 | 210 | ) { |
| 211 | - return formulaires_editer_objet_traiter( |
|
| 212 | - 'rubrique', |
|
| 213 | - $id_rubrique, |
|
| 214 | - $id_parent, |
|
| 215 | - $lier_trad, |
|
| 216 | - $retour, |
|
| 217 | - $config_fonc, |
|
| 218 | - $row, |
|
| 219 | - $hidden |
|
| 220 | - ); |
|
| 211 | + return formulaires_editer_objet_traiter( |
|
| 212 | + 'rubrique', |
|
| 213 | + $id_rubrique, |
|
| 214 | + $id_parent, |
|
| 215 | + $lier_trad, |
|
| 216 | + $retour, |
|
| 217 | + $config_fonc, |
|
| 218 | + $row, |
|
| 219 | + $hidden |
|
| 220 | + ); |
|
| 221 | 221 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,46 +31,46 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - $s = ''; |
|
| 38 | - $pass = ''; |
|
| 39 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | - if (!$s) { |
|
| 41 | - $s = random_int(0, mt_getrandmax()); |
|
| 42 | - if (!$s) { |
|
| 43 | - $s = random_int(0, mt_getrandmax()); |
|
| 44 | - } |
|
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | - } |
|
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | - $x = $r['r'] & 63; |
|
| 49 | - if ($x < 10) { |
|
| 50 | - $x = chr($x + 48); |
|
| 51 | - } else { |
|
| 52 | - if ($x < 36) { |
|
| 53 | - $x = chr($x + 55); |
|
| 54 | - } else { |
|
| 55 | - if ($x < 62) { |
|
| 56 | - $x = chr($x + 61); |
|
| 57 | - } else { |
|
| 58 | - if ($x == 63) { |
|
| 59 | - $x = '/'; |
|
| 60 | - } else { |
|
| 61 | - $x = '.'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $pass .= $x; |
|
| 67 | - $s = substr($s, 2); |
|
| 68 | - } |
|
| 69 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | - |
|
| 73 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + $s = ''; |
|
| 38 | + $pass = ''; |
|
| 39 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | + if (!$s) { |
|
| 41 | + $s = random_int(0, mt_getrandmax()); |
|
| 42 | + if (!$s) { |
|
| 43 | + $s = random_int(0, mt_getrandmax()); |
|
| 44 | + } |
|
| 45 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + } |
|
| 47 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $x = $r['r'] & 63; |
|
| 49 | + if ($x < 10) { |
|
| 50 | + $x = chr($x + 48); |
|
| 51 | + } else { |
|
| 52 | + if ($x < 36) { |
|
| 53 | + $x = chr($x + 55); |
|
| 54 | + } else { |
|
| 55 | + if ($x < 62) { |
|
| 56 | + $x = chr($x + 61); |
|
| 57 | + } else { |
|
| 58 | + if ($x == 63) { |
|
| 59 | + $x = '/'; |
|
| 60 | + } else { |
|
| 61 | + $x = '.'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $pass .= $x; |
|
| 67 | + $s = substr($s, 2); |
|
| 68 | + } |
|
| 69 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | + |
|
| 73 | + return $pass; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | * @return string Identifiant |
| 80 | 80 | */ |
| 81 | 81 | function creer_uniqid() { |
| 82 | - static $seeded; |
|
| 82 | + static $seeded; |
|
| 83 | 83 | |
| 84 | - if (!$seeded) { |
|
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | - mt_srand($seed); |
|
| 87 | - $seeded = true; |
|
| 88 | - } |
|
| 84 | + if (!$seeded) { |
|
| 85 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + mt_srand($seed); |
|
| 87 | + $seeded = true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $s = random_int(0, mt_getrandmax()); |
|
| 91 | - if (!$s) { |
|
| 92 | - $s = random_int(0, mt_getrandmax()); |
|
| 93 | - } |
|
| 90 | + $s = random_int(0, mt_getrandmax()); |
|
| 91 | + if (!$s) { |
|
| 92 | + $s = random_int(0, mt_getrandmax()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return uniqid($s, 1); |
|
| 95 | + return uniqid($s, 1); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | * @return string Retourne l'alea éphemère actuel au passage |
| 107 | 107 | */ |
| 108 | 108 | function charger_aleas() { |
| 109 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | - include_spip('base/abstract_sql'); |
|
| 111 | - $aleas = sql_allfetsel( |
|
| 112 | - ['nom', 'valeur'], |
|
| 113 | - 'spip_meta', |
|
| 114 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - 'continue' |
|
| 121 | - ); |
|
| 122 | - if ($aleas) { |
|
| 123 | - foreach ($aleas as $a) { |
|
| 124 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | - } else { |
|
| 128 | - spip_log('aleas indisponibles', 'session'); |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 109 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | + include_spip('base/abstract_sql'); |
|
| 111 | + $aleas = sql_allfetsel( |
|
| 112 | + ['nom', 'valeur'], |
|
| 113 | + 'spip_meta', |
|
| 114 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + 'continue' |
|
| 121 | + ); |
|
| 122 | + if ($aleas) { |
|
| 123 | + foreach ($aleas as $a) { |
|
| 124 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | + } else { |
|
| 128 | + spip_log('aleas indisponibles', 'session'); |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 137 | 137 | **/ |
| 138 | 138 | function renouvelle_alea() { |
| 139 | - charger_aleas(); |
|
| 140 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | + charger_aleas(); |
|
| 140 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * Clé de sécurité. |
| 162 | 162 | **/ |
| 163 | 163 | function low_sec($id_auteur) { |
| 164 | - // Pas d'id_auteur : low_sec |
|
| 165 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | - include_spip('inc/config'); |
|
| 167 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | - if (!$low_sec) { |
|
| 173 | - $low_sec = creer_pass_aleatoire(); |
|
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $low_sec; |
|
| 164 | + // Pas d'id_auteur : low_sec |
|
| 165 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | + include_spip('inc/config'); |
|
| 167 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | + if (!$low_sec) { |
|
| 173 | + $low_sec = creer_pass_aleatoire(); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $low_sec; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * @filtre |
| 209 | 209 | */ |
| 210 | 210 | function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 211 | - if ($op) { |
|
| 212 | - $dir .= " $op $args"; |
|
| 213 | - } |
|
| 211 | + if ($op) { |
|
| 212 | + $dir .= " $op $args"; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 230 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -249,27 +249,27 @@ discard block |
||
| 249 | 249 | * @deprecated 4.1 |
| 250 | 250 | */ |
| 251 | 251 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 252 | - $a = $b = ''; |
|
| 253 | - foreach ($args as $val => $var) { |
|
| 254 | - if ($var) { |
|
| 255 | - if ($val <> 'statut') { |
|
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 257 | - } |
|
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $a = substr($a, 1); |
|
| 262 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | - |
|
| 264 | - return $b |
|
| 265 | - . 'op=' |
|
| 266 | - . $op |
|
| 267 | - . '&id=' |
|
| 268 | - . $id |
|
| 269 | - . '&cle=' |
|
| 270 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | - . (!$a ? '' : "&args=$a") |
|
| 272 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 252 | + $a = $b = ''; |
|
| 253 | + foreach ($args as $val => $var) { |
|
| 254 | + if ($var) { |
|
| 255 | + if ($val <> 'statut') { |
|
| 256 | + $a .= ':' . $val . '-' . $var; |
|
| 257 | + } |
|
| 258 | + $b .= $val . '=' . $var . '&'; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $a = substr($a, 1); |
|
| 262 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | + |
|
| 264 | + return $b |
|
| 265 | + . 'op=' |
|
| 266 | + . $op |
|
| 267 | + . '&id=' |
|
| 268 | + . $id |
|
| 269 | + . '&cle=' |
|
| 270 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | + . (!$a ? '' : "&args=$a") |
|
| 272 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * true si les clés corresponde, false sinon |
| 304 | 304 | **/ |
| 305 | 305 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 306 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Identifiant de l'auteur |
| 314 | 314 | **/ |
| 315 | 315 | function effacer_low_sec($id_auteur) { |
| 316 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | - return; |
|
| 318 | - } // jamais trop prudent ;) |
|
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 316 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | + return; |
|
| 318 | + } // jamais trop prudent ;) |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,31 +334,31 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 339 | - |
|
| 340 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 341 | - // par exemple acces_restreint ; |
|
| 342 | - // si .htaccess existe, outrepasser spip_meta |
|
| 343 | - if ( |
|
| 344 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 345 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 346 | - and !@file_exists($htaccess) |
|
| 347 | - ) { |
|
| 348 | - spip_unlink($htpasswd); |
|
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 354 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 355 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 356 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 357 | - if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 358 | - return; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 337 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 339 | + |
|
| 340 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 341 | + // par exemple acces_restreint ; |
|
| 342 | + // si .htaccess existe, outrepasser spip_meta |
|
| 343 | + if ( |
|
| 344 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 345 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 346 | + and !@file_exists($htaccess) |
|
| 347 | + ) { |
|
| 348 | + spip_unlink($htpasswd); |
|
| 349 | + spip_unlink($htpasswd . '-admin'); |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 354 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 355 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 356 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 357 | + if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 358 | + return; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -367,29 +367,29 @@ discard block |
||
| 367 | 367 | * @param $htpasswd_admin |
| 368 | 368 | */ |
| 369 | 369 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 370 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 371 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $pwd_all = ''; // login:htpass pour tous |
|
| 375 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 376 | - |
|
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | - while ($row = sql_fetch($res)) { |
|
| 379 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 381 | - $pwd_all .= $ligne; |
|
| 382 | - if ($row['statut'] == '0minirezo') { |
|
| 383 | - $pwd_admin .= $ligne; |
|
| 384 | - } |
|
| 385 | - } |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - if ($pwd_all) { |
|
| 389 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 390 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 391 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 392 | - } |
|
| 370 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 371 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $pwd_all = ''; // login:htpass pour tous |
|
| 375 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 376 | + |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | + while ($row = sql_fetch($res)) { |
|
| 379 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 380 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 381 | + $pwd_all .= $ligne; |
|
| 382 | + if ($row['statut'] == '0minirezo') { |
|
| 383 | + $pwd_admin .= $ligne; |
|
| 384 | + } |
|
| 385 | + } |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + if ($pwd_all) { |
|
| 389 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 390 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 391 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 392 | + } |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | /** |
@@ -403,11 +403,11 @@ discard block |
||
| 403 | 403 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 404 | 404 | */ |
| 405 | 405 | function generer_htpass($pass) { |
| 406 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 407 | - return $generer_htpass($pass); |
|
| 408 | - } |
|
| 406 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 407 | + return $generer_htpass($pass); |
|
| 408 | + } |
|
| 409 | 409 | |
| 410 | - return ''; |
|
| 410 | + return ''; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -420,14 +420,14 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 424 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - // directive deny compatible Apache 2.0+ |
|
| 429 | - $deny = |
|
| 430 | - '# Deny all requests from Apache 2.4+. |
|
| 423 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 424 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + // directive deny compatible Apache 2.0+ |
|
| 429 | + $deny = |
|
| 430 | + '# Deny all requests from Apache 2.4+. |
|
| 431 | 431 | <IfModule mod_authz_core.c> |
| 432 | 432 | Require all denied |
| 433 | 433 | </IfModule> |
@@ -436,32 +436,32 @@ discard block |
||
| 436 | 436 | Deny from all |
| 437 | 437 | </IfModule> |
| 438 | 438 | '; |
| 439 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 440 | - if ( |
|
| 441 | - function_exists('apache_get_version') |
|
| 442 | - and $v = apache_get_version() |
|
| 443 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 444 | - ) { |
|
| 445 | - $deny = "deny from all\n"; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 449 | - fputs($ht, $deny); |
|
| 450 | - fclose($ht); |
|
| 451 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 453 | - if ($ht = @fopen($t, 'w')) { |
|
| 454 | - @fclose($ht); |
|
| 455 | - include_spip('inc/distant'); |
|
| 456 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 457 | - $t = url_de_base() . $t; |
|
| 458 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 459 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 463 | - |
|
| 464 | - return $ht; |
|
| 439 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 440 | + if ( |
|
| 441 | + function_exists('apache_get_version') |
|
| 442 | + and $v = apache_get_version() |
|
| 443 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 444 | + ) { |
|
| 445 | + $deny = "deny from all\n"; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 449 | + fputs($ht, $deny); |
|
| 450 | + fclose($ht); |
|
| 451 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 452 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 453 | + if ($ht = @fopen($t, 'w')) { |
|
| 454 | + @fclose($ht); |
|
| 455 | + include_spip('inc/distant'); |
|
| 456 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 457 | + $t = url_de_base() . $t; |
|
| 458 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 459 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 463 | + |
|
| 464 | + return $ht; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -479,20 +479,20 @@ discard block |
||
| 479 | 479 | * Valeur de la configuration `creer_htaccess` |
| 480 | 480 | */ |
| 481 | 481 | function gerer_htaccess() { |
| 482 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 483 | - // par exemple acces_restreint |
|
| 484 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 485 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 486 | - $dirs[] = ['extension' => 'distant']; |
|
| 487 | - foreach ($dirs as $e) { |
|
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 489 | - if ($f) { |
|
| 490 | - verifier_htaccess($dir); |
|
| 491 | - } else { |
|
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 482 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 483 | + // par exemple acces_restreint |
|
| 484 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 485 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 486 | + $dirs[] = ['extension' => 'distant']; |
|
| 487 | + foreach ($dirs as $e) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 489 | + if ($f) { |
|
| 490 | + verifier_htaccess($dir); |
|
| 491 | + } else { |
|
| 492 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 498 | 498 | } |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 34 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 35 | 35 | |
| 36 | 36 | mt_srand($seed); |
| 37 | 37 | $s = ''; |
@@ -42,9 +42,9 @@ discard block |
||
| 42 | 42 | if (!$s) { |
| 43 | 43 | $s = random_int(0, mt_getrandmax()); |
| 44 | 44 | } |
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 45 | + $s = substr(md5(uniqid($s).$sel), 0, 16); |
|
| 46 | 46 | } |
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 47 | + $r = unpack('Cr', pack('H2', $s.$s)); |
|
| 48 | 48 | $x = $r['r'] & 63; |
| 49 | 49 | if ($x < 10) { |
| 50 | 50 | $x = chr($x + 48); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | static $seeded; |
| 83 | 83 | |
| 84 | 84 | if (!$seeded) { |
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 85 | + $seed = (int) round(((float) microtime() + 1) * time()); |
|
| 86 | 86 | mt_srand($seed); |
| 87 | 87 | $seeded = true; |
| 88 | 88 | } |
@@ -168,10 +168,10 @@ discard block |
||
| 168 | 168 | ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
| 169 | 169 | } |
| 170 | 170 | } else { |
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = '.intval($id_auteur)); |
|
| 172 | 172 | if (!$low_sec) { |
| 173 | 173 | $low_sec = creer_pass_aleatoire(); |
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = '.intval($id_auteur)); |
|
| 175 | 175 | } |
| 176 | 176 | } |
| 177 | 177 | |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | 230 | $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
| 231 | 231 | $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond".($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | 234 | return generer_url_api($script, $path, $args, $no_entities = false, $public); |
| 235 | 235 | } |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | foreach ($args as $val => $var) { |
| 254 | 254 | if ($var) { |
| 255 | 255 | if ($val <> 'statut') { |
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 256 | + $a .= ':'.$val.'-'.$var; |
|
| 257 | 257 | } |
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 258 | + $b .= $val.'='.$var.'&'; |
|
| 259 | 259 | } |
| 260 | 260 | } |
| 261 | 261 | $a = substr($a, 1); |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action.low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -316,7 +316,7 @@ discard block |
||
| 316 | 316 | if (!$id_auteur = intval($id_auteur)) { |
| 317 | 317 | return; |
| 318 | 318 | } // jamais trop prudent ;) |
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = '.intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | |
@@ -334,8 +334,8 @@ discard block |
||
| 334 | 334 | * - void sinon. |
| 335 | 335 | **/ |
| 336 | 336 | function ecrire_acces() { |
| 337 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 338 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 337 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 338 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 339 | 339 | |
| 340 | 340 | // Cette variable de configuration peut etre posee par un plugin |
| 341 | 341 | // par exemple acces_restreint ; |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | and !@file_exists($htaccess) |
| 347 | 347 | ) { |
| 348 | 348 | spip_unlink($htpasswd); |
| 349 | - spip_unlink($htpasswd . '-admin'); |
|
| 349 | + spip_unlink($htpasswd.'-admin'); |
|
| 350 | 350 | return; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -374,10 +374,10 @@ discard block |
||
| 374 | 374 | $pwd_all = ''; // login:htpass pour tous |
| 375 | 375 | $pwd_admin = ''; // login:htpass pour les admins |
| 376 | 376 | |
| 377 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 377 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND ".sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 378 | 378 | while ($row = sql_fetch($res)) { |
| 379 | 379 | if (strlen($row['login']) and strlen($row['htpass'])) { |
| 380 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 380 | + $ligne = $row['login'].':'.$row['htpass']."\n"; |
|
| 381 | 381 | $pwd_all .= $ligne; |
| 382 | 382 | if ($row['statut'] == '0minirezo') { |
| 383 | 383 | $pwd_admin .= $ligne; |
@@ -420,7 +420,7 @@ discard block |
||
| 420 | 420 | * @return boolean |
| 421 | 421 | */ |
| 422 | 422 | function verifier_htaccess($rep, $force = false) { |
| 423 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 423 | + $htaccess = rtrim($rep, '/').'/'._ACCESS_FILE_NAME; |
|
| 424 | 424 | if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
| 425 | 425 | return true; |
| 426 | 426 | } |
@@ -449,17 +449,17 @@ discard block |
||
| 449 | 449 | fputs($ht, $deny); |
| 450 | 450 | fclose($ht); |
| 451 | 451 | @chmod($htaccess, _SPIP_CHMOD & 0666); |
| 452 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 452 | + $t = rtrim($rep, '/').'/.ok'; |
|
| 453 | 453 | if ($ht = @fopen($t, 'w')) { |
| 454 | 454 | @fclose($ht); |
| 455 | 455 | include_spip('inc/distant'); |
| 456 | 456 | $t = substr($t, strlen(_DIR_RACINE)); |
| 457 | - $t = url_de_base() . $t; |
|
| 457 | + $t = url_de_base().$t; |
|
| 458 | 458 | $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
| 459 | 459 | $ht = ($ht['status'] ?? null) === 403; |
| 460 | 460 | } |
| 461 | 461 | } |
| 462 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 462 | + spip_log("Creation de $htaccess ".($ht ? ' reussie' : ' manquee')); |
|
| 463 | 463 | |
| 464 | 464 | return $ht; |
| 465 | 465 | } |
@@ -485,11 +485,11 @@ discard block |
||
| 485 | 485 | $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
| 486 | 486 | $dirs[] = ['extension' => 'distant']; |
| 487 | 487 | foreach ($dirs as $e) { |
| 488 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 488 | + if (is_dir($dir = _DIR_IMG.$e['extension'])) { |
|
| 489 | 489 | if ($f) { |
| 490 | 490 | verifier_htaccess($dir); |
| 491 | 491 | } else { |
| 492 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 492 | + spip_unlink($dir.'/'._ACCESS_FILE_NAME); |
|
| 493 | 493 | } |
| 494 | 494 | } |
| 495 | 495 | } |
@@ -312,8 +312,7 @@ |
||
| 312 | 312 | ecrire_meta($casier, $serialized_store, null, $table); |
| 313 | 313 | } |
| 314 | 314 | } |
| 315 | - } |
|
| 316 | - else { |
|
| 315 | + } else { |
|
| 317 | 316 | ecrire_meta($casier, $store, null, $table); |
| 318 | 317 | } |
| 319 | 318 | } |
@@ -303,9 +303,9 @@ |
||
| 303 | 303 | // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
| 304 | 304 | // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
| 305 | 305 | if ($has_planes) { |
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_'.$table, 'nom='.sql_quote($casier)); |
|
| 307 | 307 | if ($check_store !== $serialized_store) { |
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 308 | + array_walk_recursive($store, function(&$value, $key) { |
|
| 309 | 309 | if (is_string($value)) { |
| 310 | 310 | $value = utf8_noplanes($value); |
| 311 | 311 | } |
@@ -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 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | function inc_config_dist() { |
| 31 | - actualise_metas(liste_metas()); |
|
| 31 | + actualise_metas(liste_metas()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -45,34 +45,34 @@ discard block |
||
| 45 | 45 | * Liste (table, casier, sous_casier) |
| 46 | 46 | */ |
| 47 | 47 | function expliquer_config($cfg) { |
| 48 | - // par defaut, sur la table des meta |
|
| 49 | - $table = 'meta'; |
|
| 50 | - $casier = null; |
|
| 51 | - $sous_casier = []; |
|
| 52 | - $cfg = explode('/', $cfg); |
|
| 53 | - |
|
| 54 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | - if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | - array_shift($cfg); |
|
| 57 | - $table = array_shift($cfg); |
|
| 58 | - if (!isset($GLOBALS[$table])) { |
|
| 59 | - lire_metas($table); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | - if (count($cfg)) { |
|
| 65 | - // pas sur un appel vide '' |
|
| 66 | - if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | - $casier = $c; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (count($cfg)) { |
|
| 72 | - $sous_casier = $cfg; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return [$table, $casier, $sous_casier]; |
|
| 48 | + // par defaut, sur la table des meta |
|
| 49 | + $table = 'meta'; |
|
| 50 | + $casier = null; |
|
| 51 | + $sous_casier = []; |
|
| 52 | + $cfg = explode('/', $cfg); |
|
| 53 | + |
|
| 54 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | + if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | + array_shift($cfg); |
|
| 57 | + $table = array_shift($cfg); |
|
| 58 | + if (!isset($GLOBALS[$table])) { |
|
| 59 | + lire_metas($table); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | + if (count($cfg)) { |
|
| 65 | + // pas sur un appel vide '' |
|
| 66 | + if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | + $casier = $c; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (count($cfg)) { |
|
| 72 | + $sous_casier = $cfg; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return [$table, $casier, $sous_casier]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -100,65 +100,65 @@ discard block |
||
| 100 | 100 | * Contenu de la configuration obtenue |
| 101 | 101 | */ |
| 102 | 102 | function lire_config($cfg = '', $def = null, $unserialize = true) { |
| 103 | - // lire le stockage sous la forme /table/valeur |
|
| 104 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | - |
|
| 107 | - // traiter en priorite le cas simple et frequent |
|
| 108 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | - if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | - $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | - ((!$unserialize |
|
| 112 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | - or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | - or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | - or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | - : $def; |
|
| 118 | - |
|
| 119 | - return $r; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Brancher sur methodes externes si besoin |
|
| 123 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | - $methode = substr($cfg, 0, $p); |
|
| 125 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | - |
|
| 127 | - return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | - |
|
| 132 | - if (!isset($GLOBALS[$table])) { |
|
| 133 | - return $def; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $r = $GLOBALS[$table]; |
|
| 137 | - |
|
| 138 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | - if (!$casier) { |
|
| 140 | - return $unserialize ? $r : serialize($r); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // casier principal : |
|
| 144 | - // le deserializer si demande |
|
| 145 | - // ou si on a besoin |
|
| 146 | - // d'un sous casier |
|
| 147 | - $r = $r[$casier] ?? null; |
|
| 148 | - if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | - $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // aller chercher le sous_casier |
|
| 153 | - while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | - $r = $r[$casier] ?? null; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($r)) { |
|
| 158 | - return $def; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $r; |
|
| 103 | + // lire le stockage sous la forme /table/valeur |
|
| 104 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | + |
|
| 107 | + // traiter en priorite le cas simple et frequent |
|
| 108 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | + if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | + $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | + ((!$unserialize |
|
| 112 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | + or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | + or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | + or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | + : $def; |
|
| 118 | + |
|
| 119 | + return $r; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Brancher sur methodes externes si besoin |
|
| 123 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | + $methode = substr($cfg, 0, $p); |
|
| 125 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | + |
|
| 127 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | + |
|
| 132 | + if (!isset($GLOBALS[$table])) { |
|
| 133 | + return $def; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $r = $GLOBALS[$table]; |
|
| 137 | + |
|
| 138 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | + if (!$casier) { |
|
| 140 | + return $unserialize ? $r : serialize($r); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // casier principal : |
|
| 144 | + // le deserializer si demande |
|
| 145 | + // ou si on a besoin |
|
| 146 | + // d'un sous casier |
|
| 147 | + $r = $r[$casier] ?? null; |
|
| 148 | + if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | + $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // aller chercher le sous_casier |
|
| 153 | + while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | + $r = $r[$casier] ?? null; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($r)) { |
|
| 158 | + return $def; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $r; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | 174 | function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) { |
| 175 | - return lire_config($cfg, $def, $unserialize); |
|
| 175 | + return lire_config($cfg, $def, $unserialize); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -184,144 +184,144 @@ discard block |
||
| 184 | 184 | * @return bool |
| 185 | 185 | */ |
| 186 | 186 | function ecrire_config($cfg, $store) { |
| 187 | - // Brancher sur methodes externes si besoin |
|
| 188 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | - $methode = substr($cfg, 0, $p); |
|
| 190 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | - |
|
| 192 | - return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | - // il faut au moins un casier pour ecrire |
|
| 197 | - if (!$casier) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // trouvons ou creons le pointeur sur le casier |
|
| 202 | - $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | - if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | - if ($st === null) { |
|
| 205 | - // ne rien creer si c'est une demande d'effacement |
|
| 206 | - if ($store === null) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - $st = []; |
|
| 210 | - } else { |
|
| 211 | - $st = unserialize($st); |
|
| 212 | - if ($st === false) { |
|
| 213 | - // ne rien creer si c'est une demande d'effacement |
|
| 214 | - if ($store === null) { |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - $st = []; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $has_planes = false; |
|
| 223 | - // si on a affaire a un sous caiser |
|
| 224 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | - if ($c = $sous_casier) { |
|
| 226 | - $sc = &$st; |
|
| 227 | - $pointeurs = []; |
|
| 228 | - while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | - // creer l'entree si elle n'existe pas |
|
| 230 | - if (!isset($sc[$cc])) { |
|
| 231 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | - // ne rien creer mais sortir |
|
| 233 | - if (is_null($store)) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - $sc[$cc] = []; |
|
| 237 | - } |
|
| 238 | - $pointeurs[$cc] = &$sc; |
|
| 239 | - $sc = &$sc[$cc]; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // si c'est une demande d'effacement |
|
| 243 | - if (is_null($store)) { |
|
| 244 | - $c = $sous_casier; |
|
| 245 | - $sous = array_pop($c); |
|
| 246 | - // effacer, et remonter pour effacer les parents vides |
|
| 247 | - do { |
|
| 248 | - unset($pointeurs[$sous][$sous]); |
|
| 249 | - } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | - |
|
| 251 | - // si on a vide tous les sous casiers, |
|
| 252 | - // et que le casier est vide |
|
| 253 | - // vider aussi la meta |
|
| 254 | - if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | - $st = null; |
|
| 256 | - } |
|
| 257 | - } // dans tous les autres cas, on ecrase |
|
| 258 | - else { |
|
| 259 | - if ( |
|
| 260 | - defined('_MYSQL_NOPLANES') |
|
| 261 | - and _MYSQL_NOPLANES |
|
| 262 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | - ) { |
|
| 265 | - // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | - // @see utf8_noplanes |
|
| 267 | - $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | - // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | - if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | - if (!function_exists('utf8_noplanes')) { |
|
| 271 | - include_spip('inc/charsets'); |
|
| 272 | - } |
|
| 273 | - if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | - $has_planes = true; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $sc = $store; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Maintenant que $st est modifiee |
|
| 283 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | - $store = $st; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (is_null($store)) { |
|
| 288 | - if (is_null($st) and !$sous_casier) { |
|
| 289 | - return false; |
|
| 290 | - } // la config n'existait deja pas ! |
|
| 291 | - effacer_meta($casier, $table); |
|
| 292 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | - } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | - else { |
|
| 295 | - if (!isset($GLOBALS[$table])) { |
|
| 296 | - installer_table_meta($table); |
|
| 297 | - } |
|
| 298 | - // si ce n'est pas une chaine |
|
| 299 | - // il faut serializer |
|
| 300 | - if (!is_string($store)) { |
|
| 301 | - $serialized_store = serialize($store); |
|
| 302 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | - // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | - // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | - if ($has_planes) { |
|
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | - if ($check_store !== $serialized_store) { |
|
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | - if (is_string($value)) { |
|
| 310 | - $value = utf8_noplanes($value); |
|
| 311 | - } |
|
| 312 | - }); |
|
| 313 | - $serialized_store = serialize($store); |
|
| 314 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - else { |
|
| 319 | - ecrire_meta($casier, $store, null, $table); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // verifier que lire_config($cfg)==$store ? |
|
| 324 | - return true; |
|
| 187 | + // Brancher sur methodes externes si besoin |
|
| 188 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | + $methode = substr($cfg, 0, $p); |
|
| 190 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | + |
|
| 192 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | + // il faut au moins un casier pour ecrire |
|
| 197 | + if (!$casier) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // trouvons ou creons le pointeur sur le casier |
|
| 202 | + $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | + if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | + if ($st === null) { |
|
| 205 | + // ne rien creer si c'est une demande d'effacement |
|
| 206 | + if ($store === null) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + $st = []; |
|
| 210 | + } else { |
|
| 211 | + $st = unserialize($st); |
|
| 212 | + if ($st === false) { |
|
| 213 | + // ne rien creer si c'est une demande d'effacement |
|
| 214 | + if ($store === null) { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + $st = []; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $has_planes = false; |
|
| 223 | + // si on a affaire a un sous caiser |
|
| 224 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | + if ($c = $sous_casier) { |
|
| 226 | + $sc = &$st; |
|
| 227 | + $pointeurs = []; |
|
| 228 | + while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | + // creer l'entree si elle n'existe pas |
|
| 230 | + if (!isset($sc[$cc])) { |
|
| 231 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | + // ne rien creer mais sortir |
|
| 233 | + if (is_null($store)) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + $sc[$cc] = []; |
|
| 237 | + } |
|
| 238 | + $pointeurs[$cc] = &$sc; |
|
| 239 | + $sc = &$sc[$cc]; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // si c'est une demande d'effacement |
|
| 243 | + if (is_null($store)) { |
|
| 244 | + $c = $sous_casier; |
|
| 245 | + $sous = array_pop($c); |
|
| 246 | + // effacer, et remonter pour effacer les parents vides |
|
| 247 | + do { |
|
| 248 | + unset($pointeurs[$sous][$sous]); |
|
| 249 | + } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | + |
|
| 251 | + // si on a vide tous les sous casiers, |
|
| 252 | + // et que le casier est vide |
|
| 253 | + // vider aussi la meta |
|
| 254 | + if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | + $st = null; |
|
| 256 | + } |
|
| 257 | + } // dans tous les autres cas, on ecrase |
|
| 258 | + else { |
|
| 259 | + if ( |
|
| 260 | + defined('_MYSQL_NOPLANES') |
|
| 261 | + and _MYSQL_NOPLANES |
|
| 262 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | + ) { |
|
| 265 | + // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | + // @see utf8_noplanes |
|
| 267 | + $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | + // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | + if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | + if (!function_exists('utf8_noplanes')) { |
|
| 271 | + include_spip('inc/charsets'); |
|
| 272 | + } |
|
| 273 | + if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | + $has_planes = true; |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $sc = $store; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Maintenant que $st est modifiee |
|
| 283 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | + $store = $st; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (is_null($store)) { |
|
| 288 | + if (is_null($st) and !$sous_casier) { |
|
| 289 | + return false; |
|
| 290 | + } // la config n'existait deja pas ! |
|
| 291 | + effacer_meta($casier, $table); |
|
| 292 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | + } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | + else { |
|
| 295 | + if (!isset($GLOBALS[$table])) { |
|
| 296 | + installer_table_meta($table); |
|
| 297 | + } |
|
| 298 | + // si ce n'est pas une chaine |
|
| 299 | + // il faut serializer |
|
| 300 | + if (!is_string($store)) { |
|
| 301 | + $serialized_store = serialize($store); |
|
| 302 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | + // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | + // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | + if ($has_planes) { |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | + if ($check_store !== $serialized_store) { |
|
| 308 | + array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | + if (is_string($value)) { |
|
| 310 | + $value = utf8_noplanes($value); |
|
| 311 | + } |
|
| 312 | + }); |
|
| 313 | + $serialized_store = serialize($store); |
|
| 314 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + else { |
|
| 319 | + ecrire_meta($casier, $store, null, $table); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // verifier que lire_config($cfg)==$store ? |
|
| 324 | + return true; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -335,14 +335,14 @@ discard block |
||
| 335 | 335 | * @return bool |
| 336 | 336 | */ |
| 337 | 337 | function ecrire_config_metapack_dist($cfg, $store) { |
| 338 | - // cas particulier en metapack:: |
|
| 339 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | - // intacte en sortie ... |
|
| 341 | - if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | - $store = serialize($store); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return ecrire_config($cfg, $store); |
|
| 338 | + // cas particulier en metapack:: |
|
| 339 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | + // intacte en sortie ... |
|
| 341 | + if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | + $store = serialize($store); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return ecrire_config($cfg, $store); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | * @return bool |
| 353 | 353 | */ |
| 354 | 354 | function effacer_config($cfg) { |
| 355 | - ecrire_config($cfg, null); |
|
| 355 | + ecrire_config($cfg, null); |
|
| 356 | 356 | |
| 357 | - return true; |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,58 +371,58 @@ discard block |
||
| 371 | 371 | * Couples nom de la `meta` => valeur par défaut |
| 372 | 372 | */ |
| 373 | 373 | function liste_metas() { |
| 374 | - return pipeline('configurer_liste_metas', [ |
|
| 375 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | - 'slogan_site' => '', |
|
| 377 | - 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | - 'descriptif_site' => '', |
|
| 379 | - 'activer_logos' => 'oui', |
|
| 380 | - 'activer_logos_survol' => 'non', |
|
| 381 | - 'articles_surtitre' => 'non', |
|
| 382 | - 'articles_soustitre' => 'non', |
|
| 383 | - 'articles_descriptif' => 'non', |
|
| 384 | - 'articles_chapeau' => 'non', |
|
| 385 | - 'articles_texte' => 'oui', |
|
| 386 | - 'articles_ps' => 'non', |
|
| 387 | - 'articles_redac' => 'non', |
|
| 388 | - 'post_dates' => 'non', |
|
| 389 | - 'articles_urlref' => 'non', |
|
| 390 | - 'articles_redirection' => 'non', |
|
| 391 | - 'creer_preview' => 'non', |
|
| 392 | - 'taille_preview' => 150, |
|
| 393 | - 'articles_modif' => 'non', |
|
| 394 | - |
|
| 395 | - 'rubriques_descriptif' => 'non', |
|
| 396 | - 'rubriques_texte' => 'oui', |
|
| 397 | - |
|
| 398 | - 'accepter_inscriptions' => 'non', |
|
| 399 | - 'accepter_visiteurs' => 'non', |
|
| 400 | - 'prevenir_auteurs' => 'non', |
|
| 401 | - 'suivi_edito' => 'non', |
|
| 402 | - 'adresse_suivi' => '', |
|
| 403 | - 'adresse_suivi_inscription' => '', |
|
| 404 | - 'adresse_neuf' => '', |
|
| 405 | - 'jours_neuf' => '', |
|
| 406 | - 'quoi_de_neuf' => 'non', |
|
| 407 | - 'preview' => ',0minirezo,1comite,', |
|
| 408 | - |
|
| 409 | - 'syndication_integrale' => 'oui', |
|
| 410 | - 'charset' => _DEFAULT_CHARSET, |
|
| 411 | - 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | - |
|
| 413 | - 'multi_rubriques' => 'non', |
|
| 414 | - 'multi_secteurs' => 'non', |
|
| 415 | - 'gerer_trad' => 'non', |
|
| 416 | - 'langues_multilingue' => '', |
|
| 417 | - |
|
| 418 | - 'version_html_max' => 'html4', |
|
| 419 | - |
|
| 420 | - 'type_urls' => 'page', |
|
| 421 | - |
|
| 422 | - 'email_envoi' => '', |
|
| 423 | - 'email_webmaster' => '', |
|
| 424 | - 'auto_compress_http' => 'non', |
|
| 425 | - ]); |
|
| 374 | + return pipeline('configurer_liste_metas', [ |
|
| 375 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | + 'slogan_site' => '', |
|
| 377 | + 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | + 'descriptif_site' => '', |
|
| 379 | + 'activer_logos' => 'oui', |
|
| 380 | + 'activer_logos_survol' => 'non', |
|
| 381 | + 'articles_surtitre' => 'non', |
|
| 382 | + 'articles_soustitre' => 'non', |
|
| 383 | + 'articles_descriptif' => 'non', |
|
| 384 | + 'articles_chapeau' => 'non', |
|
| 385 | + 'articles_texte' => 'oui', |
|
| 386 | + 'articles_ps' => 'non', |
|
| 387 | + 'articles_redac' => 'non', |
|
| 388 | + 'post_dates' => 'non', |
|
| 389 | + 'articles_urlref' => 'non', |
|
| 390 | + 'articles_redirection' => 'non', |
|
| 391 | + 'creer_preview' => 'non', |
|
| 392 | + 'taille_preview' => 150, |
|
| 393 | + 'articles_modif' => 'non', |
|
| 394 | + |
|
| 395 | + 'rubriques_descriptif' => 'non', |
|
| 396 | + 'rubriques_texte' => 'oui', |
|
| 397 | + |
|
| 398 | + 'accepter_inscriptions' => 'non', |
|
| 399 | + 'accepter_visiteurs' => 'non', |
|
| 400 | + 'prevenir_auteurs' => 'non', |
|
| 401 | + 'suivi_edito' => 'non', |
|
| 402 | + 'adresse_suivi' => '', |
|
| 403 | + 'adresse_suivi_inscription' => '', |
|
| 404 | + 'adresse_neuf' => '', |
|
| 405 | + 'jours_neuf' => '', |
|
| 406 | + 'quoi_de_neuf' => 'non', |
|
| 407 | + 'preview' => ',0minirezo,1comite,', |
|
| 408 | + |
|
| 409 | + 'syndication_integrale' => 'oui', |
|
| 410 | + 'charset' => _DEFAULT_CHARSET, |
|
| 411 | + 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | + |
|
| 413 | + 'multi_rubriques' => 'non', |
|
| 414 | + 'multi_secteurs' => 'non', |
|
| 415 | + 'gerer_trad' => 'non', |
|
| 416 | + 'langues_multilingue' => '', |
|
| 417 | + |
|
| 418 | + 'version_html_max' => 'html4', |
|
| 419 | + |
|
| 420 | + 'type_urls' => 'page', |
|
| 421 | + |
|
| 422 | + 'email_envoi' => '', |
|
| 423 | + 'email_webmaster' => '', |
|
| 424 | + 'auto_compress_http' => 'non', |
|
| 425 | + ]); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -433,43 +433,43 @@ discard block |
||
| 433 | 433 | * @return void |
| 434 | 434 | */ |
| 435 | 435 | function actualise_metas($liste_meta) { |
| 436 | - $meta_serveur = |
|
| 437 | - [ |
|
| 438 | - 'version_installee', |
|
| 439 | - 'adresse_site', |
|
| 440 | - 'alea_ephemere_ancien', |
|
| 441 | - 'alea_ephemere', |
|
| 442 | - 'alea_ephemere_date', |
|
| 443 | - 'langue_site', |
|
| 444 | - 'langues_proposees', |
|
| 445 | - 'date_calcul_rubriques', |
|
| 446 | - 'derniere_modif', |
|
| 447 | - 'optimiser_table', |
|
| 448 | - 'drapeau_edition', |
|
| 449 | - 'creer_preview', |
|
| 450 | - 'taille_preview', |
|
| 451 | - 'creer_htpasswd', |
|
| 452 | - 'creer_htaccess', |
|
| 453 | - 'gd_formats_read', |
|
| 454 | - 'gd_formats', |
|
| 455 | - 'netpbm_formats', |
|
| 456 | - 'formats_graphiques', |
|
| 457 | - 'image_process', |
|
| 458 | - 'plugin_header', |
|
| 459 | - 'plugin' |
|
| 460 | - ]; |
|
| 461 | - // verifier le impt=non |
|
| 462 | - sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | - |
|
| 464 | - foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | - if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | - ecrire_meta($nom, $valeur); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - include_spip('inc/rubriques'); |
|
| 471 | - $langues = calculer_langues_utilisees(); |
|
| 472 | - ecrire_meta('langues_utilisees', $langues); |
|
| 436 | + $meta_serveur = |
|
| 437 | + [ |
|
| 438 | + 'version_installee', |
|
| 439 | + 'adresse_site', |
|
| 440 | + 'alea_ephemere_ancien', |
|
| 441 | + 'alea_ephemere', |
|
| 442 | + 'alea_ephemere_date', |
|
| 443 | + 'langue_site', |
|
| 444 | + 'langues_proposees', |
|
| 445 | + 'date_calcul_rubriques', |
|
| 446 | + 'derniere_modif', |
|
| 447 | + 'optimiser_table', |
|
| 448 | + 'drapeau_edition', |
|
| 449 | + 'creer_preview', |
|
| 450 | + 'taille_preview', |
|
| 451 | + 'creer_htpasswd', |
|
| 452 | + 'creer_htaccess', |
|
| 453 | + 'gd_formats_read', |
|
| 454 | + 'gd_formats', |
|
| 455 | + 'netpbm_formats', |
|
| 456 | + 'formats_graphiques', |
|
| 457 | + 'image_process', |
|
| 458 | + 'plugin_header', |
|
| 459 | + 'plugin' |
|
| 460 | + ]; |
|
| 461 | + // verifier le impt=non |
|
| 462 | + sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | + |
|
| 464 | + foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | + if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | + ecrire_meta($nom, $valeur); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + include_spip('inc/rubriques'); |
|
| 471 | + $langues = calculer_langues_utilisees(); |
|
| 472 | + ecrire_meta('langues_utilisees', $langues); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | |
@@ -491,18 +491,18 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | function appliquer_modifs_config($purger_skel = false) { |
| 493 | 493 | |
| 494 | - foreach (liste_metas() as $i => $v) { |
|
| 495 | - if (($x = _request($i)) !== null) { |
|
| 496 | - ecrire_meta($i, $x); |
|
| 497 | - } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | - ecrire_meta($i, $v); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - if ($purger_skel) { |
|
| 503 | - include_spip('inc/invalideur'); |
|
| 504 | - purger_repertoire(_DIR_SKELS); |
|
| 505 | - } |
|
| 494 | + foreach (liste_metas() as $i => $v) { |
|
| 495 | + if (($x = _request($i)) !== null) { |
|
| 496 | + ecrire_meta($i, $x); |
|
| 497 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | + ecrire_meta($i, $v); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + if ($purger_skel) { |
|
| 503 | + include_spip('inc/invalideur'); |
|
| 504 | + purger_repertoire(_DIR_SKELS); |
|
| 505 | + } |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -513,21 +513,21 @@ discard block |
||
| 513 | 513 | * @return string |
| 514 | 514 | */ |
| 515 | 515 | function appliquer_adresse_site($adresse_site) { |
| 516 | - if ($adresse_site !== null) { |
|
| 517 | - if (!strlen($adresse_site)) { |
|
| 518 | - $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | - $adresse_site = url_de_base(); |
|
| 520 | - } |
|
| 521 | - $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 516 | + if ($adresse_site !== null) { |
|
| 517 | + if (!strlen($adresse_site)) { |
|
| 518 | + $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | + $adresse_site = url_de_base(); |
|
| 520 | + } |
|
| 521 | + $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 522 | 522 | |
| 523 | - if (!tester_url_absolue($adresse_site)) { |
|
| 524 | - $adresse_site = "http://$adresse_site"; |
|
| 525 | - } |
|
| 523 | + if (!tester_url_absolue($adresse_site)) { |
|
| 524 | + $adresse_site = "http://$adresse_site"; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | - $adresse_site = entites_html($adresse_site); |
|
| 527 | + $adresse_site = entites_html($adresse_site); |
|
| 528 | 528 | |
| 529 | - ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | - } |
|
| 529 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - return $adresse_site; |
|
| 532 | + return $adresse_site; |
|
| 533 | 533 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Fonctions |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -29,29 +29,29 @@ discard block |
||
| 29 | 29 | * @param bool $left |
| 30 | 30 | */ |
| 31 | 31 | function critere_compteur_articles_filtres_dist($idb, &$boucles, $crit, $left = false) { |
| 32 | - $boucle = &$boucles[$idb]; |
|
| 32 | + $boucle = &$boucles[$idb]; |
|
| 33 | 33 | |
| 34 | - $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent); |
|
| 34 | + $_statut = calculer_liste($crit->param[0], [], $boucles, $boucle->id_parent); |
|
| 35 | 35 | |
| 36 | - $not = ''; |
|
| 37 | - if ($crit->not) { |
|
| 38 | - $not = ", 'NOT'"; |
|
| 39 | - } |
|
| 40 | - $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 41 | - $boucle->from_type['LAA'] = 'left'; |
|
| 42 | - $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"]; |
|
| 36 | + $not = ''; |
|
| 37 | + if ($crit->not) { |
|
| 38 | + $not = ", 'NOT'"; |
|
| 39 | + } |
|
| 40 | + $boucle->from['LAA'] = 'spip_auteurs_liens'; |
|
| 41 | + $boucle->from_type['LAA'] = 'left'; |
|
| 42 | + $boucle->join['LAA'] = ["'auteurs'", "'id_auteur'", "'id_auteur'", "'LAA.objet=\'article\''"]; |
|
| 43 | 43 | |
| 44 | - $boucle->from['articles'] = 'spip_articles'; |
|
| 45 | - $boucle->from_type['articles'] = 'left'; |
|
| 46 | - $boucle->join['articles'] = [ |
|
| 47 | - "'LAA'", |
|
| 48 | - "'id_article'", |
|
| 49 | - "'id_objet'", |
|
| 50 | - "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'" |
|
| 51 | - ]; |
|
| 44 | + $boucle->from['articles'] = 'spip_articles'; |
|
| 45 | + $boucle->from_type['articles'] = 'left'; |
|
| 46 | + $boucle->join['articles'] = [ |
|
| 47 | + "'LAA'", |
|
| 48 | + "'id_article'", |
|
| 49 | + "'id_objet'", |
|
| 50 | + "'(articles.statut IS NULL OR '.sql_in_quote('articles.statut',[$_statut]$not).')'" |
|
| 51 | + ]; |
|
| 52 | 52 | |
| 53 | - $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 54 | - $boucle->group[] = 'auteurs.id_auteur'; |
|
| 53 | + $boucle->select[] = 'COUNT(articles.id_article) AS compteur_articles'; |
|
| 54 | + $boucle->group[] = 'auteurs.id_auteur'; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * Pile complétée par le code à générer |
| 70 | 70 | */ |
| 71 | 71 | function balise_COMPTEUR_ARTICLES_dist($p) { |
| 72 | - return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 72 | + return rindex_pile($p, 'compteur_articles', 'compteur_articles_filtres'); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -85,44 +85,44 @@ discard block |
||
| 85 | 85 | * @return string |
| 86 | 86 | */ |
| 87 | 87 | function afficher_initiale($url, $initiale, $compteur, $debut, $pas) { |
| 88 | - static $memo = null; |
|
| 89 | - static $res = []; |
|
| 90 | - $out = ''; |
|
| 91 | - if ( |
|
| 92 | - !$memo |
|
| 93 | - or (!$initiale and !$url) |
|
| 94 | - or ($initiale !== $memo['initiale']) |
|
| 95 | - ) { |
|
| 96 | - $newcompt = intval(floor(($compteur - 1) / $pas) * $pas); |
|
| 97 | - // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 98 | - if (!$initiale and !$url and !$memo['compteur']) { |
|
| 99 | - $memo = null; |
|
| 100 | - } |
|
| 101 | - if ($memo) { |
|
| 102 | - $on = (($memo['compteur'] <= $debut) |
|
| 103 | - and ( |
|
| 104 | - $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
|
| 105 | - )); |
|
| 106 | - $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 107 | - } |
|
| 108 | - if ($initiale) { |
|
| 109 | - $memo = [ |
|
| 110 | - 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 111 | - 'initiale' => $initiale, |
|
| 112 | - 'url' => parametre_url($url, 'i', $initiale), |
|
| 113 | - 'compteur' => $newcompt |
|
| 114 | - ]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - if (!$initiale and !$url) { |
|
| 118 | - if ((is_countable($res) ? count($res) : 0) > 1) { |
|
| 119 | - $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 120 | - } |
|
| 121 | - $memo = null; |
|
| 122 | - $res = []; |
|
| 123 | - } |
|
| 88 | + static $memo = null; |
|
| 89 | + static $res = []; |
|
| 90 | + $out = ''; |
|
| 91 | + if ( |
|
| 92 | + !$memo |
|
| 93 | + or (!$initiale and !$url) |
|
| 94 | + or ($initiale !== $memo['initiale']) |
|
| 95 | + ) { |
|
| 96 | + $newcompt = intval(floor(($compteur - 1) / $pas) * $pas); |
|
| 97 | + // si fin de la pagination et une seule entree, ne pas l'afficher, ca ne sert a rien |
|
| 98 | + if (!$initiale and !$url and !$memo['compteur']) { |
|
| 99 | + $memo = null; |
|
| 100 | + } |
|
| 101 | + if ($memo) { |
|
| 102 | + $on = (($memo['compteur'] <= $debut) |
|
| 103 | + and ( |
|
| 104 | + $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
|
| 105 | + )); |
|
| 106 | + $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 107 | + } |
|
| 108 | + if ($initiale) { |
|
| 109 | + $memo = [ |
|
| 110 | + 'entree' => isset($memo['entree']) ? $memo['entree'] + 1 : 0, |
|
| 111 | + 'initiale' => $initiale, |
|
| 112 | + 'url' => parametre_url($url, 'i', $initiale), |
|
| 113 | + 'compteur' => $newcompt |
|
| 114 | + ]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + if (!$initiale and !$url) { |
|
| 118 | + if ((is_countable($res) ? count($res) : 0) > 1) { |
|
| 119 | + $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 120 | + } |
|
| 121 | + $memo = null; |
|
| 122 | + $res = []; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - return $out; |
|
| 125 | + return $out; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | /** |
@@ -141,24 +141,24 @@ discard block |
||
| 141 | 141 | * @return string |
| 142 | 142 | */ |
| 143 | 143 | function auteur_lien_messagerie($id_auteur, $en_ligne, $statut, $imessage, $email = '') { |
| 144 | - static $time = null; |
|
| 145 | - if (!in_array($statut, ['0minirezo', '1comite'])) { |
|
| 146 | - return ''; |
|
| 147 | - } |
|
| 144 | + static $time = null; |
|
| 145 | + if (!in_array($statut, ['0minirezo', '1comite'])) { |
|
| 146 | + return ''; |
|
| 147 | + } |
|
| 148 | 148 | |
| 149 | - if (is_null($time)) { |
|
| 150 | - $time = time(); |
|
| 151 | - } |
|
| 152 | - $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 149 | + if (is_null($time)) { |
|
| 150 | + $time = time(); |
|
| 151 | + } |
|
| 152 | + $parti = (($time - strtotime($en_ligne)) > 15 * 60); |
|
| 153 | 153 | |
| 154 | - if ( |
|
| 155 | - $imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 156 | - and $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 157 | - ) { |
|
| 158 | - return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 159 | - } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
|
| 160 | - return 'mailto:' . $email; |
|
| 161 | - } else { |
|
| 162 | - return ''; |
|
| 163 | - } |
|
| 154 | + if ( |
|
| 155 | + $imessage != 'non' and !$parti // historique : est-ce que ca a encore un sens de limiter vu qu'on a la notification par email ? |
|
| 156 | + and $GLOBALS['meta']['messagerie_agenda'] != 'non' |
|
| 157 | + ) { |
|
| 158 | + return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
|
| 159 | + } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
|
| 160 | + return 'mailto:' . $email; |
|
| 161 | + } else { |
|
| 162 | + return ''; |
|
| 163 | + } |
|
| 164 | 164 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | and ( |
| 104 | 104 | $newcompt > $debut or ($newcompt == $debut and $newcompt == $memo['compteur']) |
| 105 | 105 | )); |
| 106 | - $res[] = "<li class='pagination-item'>" . lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination') . '</li>'; |
|
| 106 | + $res[] = "<li class='pagination-item'>".lien_ou_expose($memo['url'], $memo['initiale'], $on ? 'span.pagination-item-label' : '', 'pagination-item-label lien_pagination').'</li>'; |
|
| 107 | 107 | } |
| 108 | 108 | if ($initiale) { |
| 109 | 109 | $memo = [ |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | } |
| 117 | 117 | if (!$initiale and !$url) { |
| 118 | 118 | if ((is_countable($res) ? count($res) : 0) > 1) { |
| 119 | - $out = "<ul class='pagination-items'>" . implode(' ', $res) . '</ul>'; |
|
| 119 | + $out = "<ul class='pagination-items'>".implode(' ', $res).'</ul>'; |
|
| 120 | 120 | } |
| 121 | 121 | $memo = null; |
| 122 | 122 | $res = []; |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ) { |
| 158 | 158 | return parametre_url(parametre_url(generer_url_ecrire('message_edit', 'new=oui'), 'to', $id_auteur), 'redirect', self()); |
| 159 | 159 | } elseif (strlen($email) and autoriser('voir', 'auteur', $id_auteur)) { |
| 160 | - return 'mailto:' . $email; |
|
| 160 | + return 'mailto:'.$email; |
|
| 161 | 161 | } else { |
| 162 | 162 | return ''; |
| 163 | 163 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/config'); |
@@ -37,26 +37,26 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | function exec_admin_plugin_dist($retour = '') { |
| 39 | 39 | |
| 40 | - if (!autoriser('configurer', '_plugins')) { |
|
| 41 | - include_spip('inc/minipres'); |
|
| 42 | - echo minipres(); |
|
| 43 | - } else { |
|
| 44 | - // on fait la verif du path avant tout, |
|
| 45 | - // et l'installation des qu'on est dans la colonne principale |
|
| 46 | - // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 47 | - // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 48 | - $new = actualise_plugins_actifs(); |
|
| 49 | - if ($new and _request('actualise') < 2) { |
|
| 50 | - include_spip('inc/headers'); |
|
| 51 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 52 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 53 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 54 | - } |
|
| 55 | - redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&')); |
|
| 56 | - } else { |
|
| 57 | - admin_plug_args(_request('voir'), _request('erreur'), _request('format')); |
|
| 58 | - } |
|
| 59 | - } |
|
| 40 | + if (!autoriser('configurer', '_plugins')) { |
|
| 41 | + include_spip('inc/minipres'); |
|
| 42 | + echo minipres(); |
|
| 43 | + } else { |
|
| 44 | + // on fait la verif du path avant tout, |
|
| 45 | + // et l'installation des qu'on est dans la colonne principale |
|
| 46 | + // si jamais la liste des plugins actifs change, il faut faire un refresh du hit |
|
| 47 | + // pour etre sur que les bons fichiers seront charges lors de l'install |
|
| 48 | + $new = actualise_plugins_actifs(); |
|
| 49 | + if ($new and _request('actualise') < 2) { |
|
| 50 | + include_spip('inc/headers'); |
|
| 51 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 52 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 53 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 54 | + } |
|
| 55 | + redirige_par_entete(parametre_url(self(), 'actualise', _request('actualise') + 1, '&')); |
|
| 56 | + } else { |
|
| 57 | + admin_plug_args(_request('voir'), _request('erreur'), _request('format')); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -81,132 +81,132 @@ discard block |
||
| 81 | 81 | * Format d'affichage (liste ou arborescence) |
| 82 | 82 | **/ |
| 83 | 83 | function admin_plug_args($quoi, $erreur, $format) { |
| 84 | - $lpf = null; |
|
| 85 | - $lcpas = null; |
|
| 86 | - $lcpaffichesup = null; |
|
| 87 | - if (!$quoi) { |
|
| 88 | - $quoi = 'actifs'; |
|
| 89 | - } |
|
| 90 | - // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite |
|
| 91 | - // format brut par plugin |
|
| 92 | - $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false); |
|
| 93 | - // format resume mis en forme |
|
| 94 | - $erreur_activation = plugin_donne_erreurs(); |
|
| 95 | - $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 96 | - echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin'); |
|
| 97 | - |
|
| 98 | - echo debut_gauche(); |
|
| 99 | - echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']); |
|
| 100 | - |
|
| 101 | - echo pipeline( |
|
| 102 | - 'affiche_gauche', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['exec' => 'admin_plugin'], |
|
| 105 | - 'data' => afficher_librairies() |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - echo debut_droite(); |
|
| 110 | - echo gros_titre(_T('icone_admin_plugin'), ''); |
|
| 111 | - |
|
| 112 | - // Barre d'onglets de premier niveau |
|
| 113 | - echo barre_onglets('plugins', 'plugins_actifs'); |
|
| 114 | - // Barre d'onglets de second niveau |
|
| 115 | - $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin'; |
|
| 116 | - echo debut_onglet('onglets_simple second'); |
|
| 117 | - echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2); |
|
| 118 | - echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2); |
|
| 119 | - echo fin_onglet(); |
|
| 120 | - |
|
| 121 | - // message d'erreur au retour d'une operation |
|
| 122 | - if ($erreur) { |
|
| 123 | - echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>'; |
|
| 124 | - } |
|
| 125 | - if ($erreur_activation) { |
|
| 126 | - echo "<div class='error'>$erreur_activation</div>"; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs |
|
| 130 | - $actifs = (array) unserialize($GLOBALS['meta']['plugin']); |
|
| 131 | - $lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']); |
|
| 132 | - |
|
| 133 | - // Les affichages se basent sur le repertoire, pas sur le nom |
|
| 134 | - $actifs = liste_chemin_plugin($actifs, ''); |
|
| 135 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 136 | - $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL); |
|
| 137 | - } |
|
| 138 | - $lcpa = liste_chemin_plugin($lcpa); |
|
| 139 | - |
|
| 140 | - // on installe les plugins maintenant, |
|
| 141 | - // cela permet aux scripts d'install de faire des affichages (moches...) |
|
| 142 | - plugin_installes_meta(); |
|
| 143 | - |
|
| 144 | - echo "<div class='liste-plugins formulaire_spip'>"; |
|
| 145 | - echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins'); |
|
| 146 | - |
|
| 147 | - if ($quoi !== 'actifs') { |
|
| 148 | - $lpf = liste_plugin_files(); |
|
| 149 | - if ($lpf) { |
|
| 150 | - echo '<p>' . _T('texte_presente_plugin') . '</p>'; |
|
| 151 | - } else { |
|
| 152 | - if (!@is_dir(_DIR_PLUGINS)) { |
|
| 153 | - echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | - . ' — ' . _T('plugin_info_automatique_creer') . '</p>'; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - $lcpaffiche = $lpf; |
|
| 158 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 159 | - $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL); |
|
| 160 | - } |
|
| 161 | - } else { |
|
| 162 | - // la liste |
|
| 163 | - // $quoi=='actifs' |
|
| 164 | - $lcpaffiche = $lcpa; |
|
| 165 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 166 | - $lcpaffichesup = $lcpas; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - if ($quoi == 'actifs' or $lpf) { |
|
| 171 | - $nb = is_countable($lcpa) ? count($lcpa) : 0; |
|
| 172 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 173 | - $nb += is_countable($lcpas) ? count($lcpas) : 0; |
|
| 174 | - } |
|
| 175 | - echo '<h3>' . sinon( |
|
| 176 | - singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 177 | - _T('plugins_actif_aucun') |
|
| 178 | - ) . '</h3>'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - if (empty($format)) { |
|
| 182 | - $format = 'liste'; |
|
| 183 | - } elseif (!in_array($format, ['liste', 'repertoires'])) { |
|
| 184 | - $format = 'repertoires'; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - $afficher = charger_fonction("afficher_$format", 'plugins'); |
|
| 188 | - $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs); |
|
| 189 | - if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 190 | - $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ($corps) { |
|
| 194 | - $corps .= "\n<div class='boutons' style='display:none;'>" |
|
| 195 | - . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 196 | - . "' />" |
|
| 197 | - . '</div>'; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps); |
|
| 201 | - |
|
| 202 | - echo fin_cadre_trait_couleur(); |
|
| 203 | - |
|
| 204 | - if ($quoi == 'actifs') { |
|
| 205 | - echo affiche_les_plugins_verrouilles($actifs); |
|
| 206 | - } |
|
| 207 | - echo '</div>'; |
|
| 208 | - |
|
| 209 | - echo http_script(" |
|
| 84 | + $lpf = null; |
|
| 85 | + $lcpas = null; |
|
| 86 | + $lcpaffichesup = null; |
|
| 87 | + if (!$quoi) { |
|
| 88 | + $quoi = 'actifs'; |
|
| 89 | + } |
|
| 90 | + // empecher l'affichage des erreurs dans le bandeau, on le donne ensuite |
|
| 91 | + // format brut par plugin |
|
| 92 | + $GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false); |
|
| 93 | + // format resume mis en forme |
|
| 94 | + $erreur_activation = plugin_donne_erreurs(); |
|
| 95 | + $commencer_page = charger_fonction('commencer_page', 'inc'); |
|
| 96 | + echo $commencer_page(_T('icone_admin_plugin'), 'configuration', 'plugin'); |
|
| 97 | + |
|
| 98 | + echo debut_gauche(); |
|
| 99 | + echo recuperer_fond('prive/squelettes/navigation/configurer', ['exec' => 'admin_plugin']); |
|
| 100 | + |
|
| 101 | + echo pipeline( |
|
| 102 | + 'affiche_gauche', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['exec' => 'admin_plugin'], |
|
| 105 | + 'data' => afficher_librairies() |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + echo debut_droite(); |
|
| 110 | + echo gros_titre(_T('icone_admin_plugin'), ''); |
|
| 111 | + |
|
| 112 | + // Barre d'onglets de premier niveau |
|
| 113 | + echo barre_onglets('plugins', 'plugins_actifs'); |
|
| 114 | + // Barre d'onglets de second niveau |
|
| 115 | + $onglet2 = $quoi == 'actifs' ? 'plugins_actifs' : 'admin_plugin'; |
|
| 116 | + echo debut_onglet('onglets_simple second'); |
|
| 117 | + echo onglet(_T('plugins_tous_liste'), generer_url_ecrire('admin_plugin', 'voir=tous'), 'admin_plugin', $onglet2); |
|
| 118 | + echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire('admin_plugin'), 'plugins_actifs', $onglet2); |
|
| 119 | + echo fin_onglet(); |
|
| 120 | + |
|
| 121 | + // message d'erreur au retour d'une operation |
|
| 122 | + if ($erreur) { |
|
| 123 | + echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>'; |
|
| 124 | + } |
|
| 125 | + if ($erreur_activation) { |
|
| 126 | + echo "<div class='error'>$erreur_activation</div>"; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + // la mise a jour de cette meta a ete faite par ecrire_plugin_actifs |
|
| 130 | + $actifs = (array) unserialize($GLOBALS['meta']['plugin']); |
|
| 131 | + $lcpa = $actifs + (array) unserialize($GLOBALS['meta']['plugin_attente']); |
|
| 132 | + |
|
| 133 | + // Les affichages se basent sur le repertoire, pas sur le nom |
|
| 134 | + $actifs = liste_chemin_plugin($actifs, ''); |
|
| 135 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 136 | + $lcpas = liste_chemin_plugin($lcpa, _DIR_PLUGINS_SUPPL); |
|
| 137 | + } |
|
| 138 | + $lcpa = liste_chemin_plugin($lcpa); |
|
| 139 | + |
|
| 140 | + // on installe les plugins maintenant, |
|
| 141 | + // cela permet aux scripts d'install de faire des affichages (moches...) |
|
| 142 | + plugin_installes_meta(); |
|
| 143 | + |
|
| 144 | + echo "<div class='liste-plugins formulaire_spip'>"; |
|
| 145 | + echo debut_cadre_trait_couleur('plugin-24.png', true, '', _T('plugins_liste'), 'plugins'); |
|
| 146 | + |
|
| 147 | + if ($quoi !== 'actifs') { |
|
| 148 | + $lpf = liste_plugin_files(); |
|
| 149 | + if ($lpf) { |
|
| 150 | + echo '<p>' . _T('texte_presente_plugin') . '</p>'; |
|
| 151 | + } else { |
|
| 152 | + if (!@is_dir(_DIR_PLUGINS)) { |
|
| 153 | + echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | + . ' — ' . _T('plugin_info_automatique_creer') . '</p>'; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + $lcpaffiche = $lpf; |
|
| 158 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 159 | + $lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL); |
|
| 160 | + } |
|
| 161 | + } else { |
|
| 162 | + // la liste |
|
| 163 | + // $quoi=='actifs' |
|
| 164 | + $lcpaffiche = $lcpa; |
|
| 165 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 166 | + $lcpaffichesup = $lcpas; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + if ($quoi == 'actifs' or $lpf) { |
|
| 171 | + $nb = is_countable($lcpa) ? count($lcpa) : 0; |
|
| 172 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 173 | + $nb += is_countable($lcpas) ? count($lcpas) : 0; |
|
| 174 | + } |
|
| 175 | + echo '<h3>' . sinon( |
|
| 176 | + singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
|
| 177 | + _T('plugins_actif_aucun') |
|
| 178 | + ) . '</h3>'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + if (empty($format)) { |
|
| 182 | + $format = 'liste'; |
|
| 183 | + } elseif (!in_array($format, ['liste', 'repertoires'])) { |
|
| 184 | + $format = 'repertoires'; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + $afficher = charger_fonction("afficher_$format", 'plugins'); |
|
| 188 | + $corps = $afficher(self(), $lcpaffiche, $lcpa, $actifs); |
|
| 189 | + if (defined('_DIR_PLUGINS_SUPPL')) { |
|
| 190 | + $corps .= $afficher(self(), $lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ($corps) { |
|
| 194 | + $corps .= "\n<div class='boutons' style='display:none;'>" |
|
| 195 | + . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 196 | + . "' />" |
|
| 197 | + . '</div>'; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + echo redirige_action_post('activer_plugins', 'activer', 'admin_plugin', '', $corps); |
|
| 201 | + |
|
| 202 | + echo fin_cadre_trait_couleur(); |
|
| 203 | + |
|
| 204 | + if ($quoi == 'actifs') { |
|
| 205 | + echo affiche_les_plugins_verrouilles($actifs); |
|
| 206 | + } |
|
| 207 | + echo '</div>'; |
|
| 208 | + |
|
| 209 | + echo http_script(" |
|
| 210 | 210 | jQuery(function(){ |
| 211 | 211 | jQuery('.plugins li.item a[rel=info]').click(function(){ |
| 212 | 212 | var li = jQuery(this).parents('li').eq(0); |
@@ -232,15 +232,15 @@ discard block |
||
| 232 | 232 | }); |
| 233 | 233 | "); |
| 234 | 234 | |
| 235 | - echo pipeline( |
|
| 236 | - 'affiche_milieu', |
|
| 237 | - [ |
|
| 238 | - 'args' => ['exec' => 'admin_plugin'], |
|
| 239 | - 'data' => '' |
|
| 240 | - ] |
|
| 241 | - ); |
|
| 235 | + echo pipeline( |
|
| 236 | + 'affiche_milieu', |
|
| 237 | + [ |
|
| 238 | + 'args' => ['exec' => 'admin_plugin'], |
|
| 239 | + 'data' => '' |
|
| 240 | + ] |
|
| 241 | + ); |
|
| 242 | 242 | |
| 243 | - echo fin_gauche(), fin_page(); |
|
| 243 | + echo fin_gauche(), fin_page(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -254,23 +254,23 @@ discard block |
||
| 254 | 254 | * Code HTML |
| 255 | 255 | **/ |
| 256 | 256 | function affiche_les_plugins_verrouilles($actifs) { |
| 257 | - if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) { |
|
| 258 | - return ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 262 | - $liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST); |
|
| 263 | - |
|
| 264 | - return |
|
| 265 | - "<div id='plugins_dist'>" |
|
| 266 | - . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
|
| 267 | - . '<p>' |
|
| 268 | - . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)]) |
|
| 269 | - . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 270 | - . '</p>' |
|
| 271 | - . $liste |
|
| 272 | - . fin_cadre_trait_couleur() |
|
| 273 | - . "</div>\n"; |
|
| 257 | + if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) { |
|
| 258 | + return ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + $afficher = charger_fonction('afficher_liste', 'plugins'); |
|
| 262 | + $liste = $afficher(self(), $liste, [], $actifs, _DIR_PLUGINS_DIST); |
|
| 263 | + |
|
| 264 | + return |
|
| 265 | + "<div id='plugins_dist'>" |
|
| 266 | + . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
|
| 267 | + . '<p>' |
|
| 268 | + . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)]) |
|
| 269 | + . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 270 | + . '</p>' |
|
| 271 | + . $liste |
|
| 272 | + . fin_cadre_trait_couleur() |
|
| 273 | + . "</div>\n"; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -282,19 +282,19 @@ discard block |
||
| 282 | 282 | */ |
| 283 | 283 | function afficher_librairies() { |
| 284 | 284 | |
| 285 | - if (!$libs = liste_librairies()) { |
|
| 286 | - return ''; |
|
| 287 | - } |
|
| 288 | - ksort($libs); |
|
| 289 | - $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
|
| 290 | - $res .= '<dl>'; |
|
| 291 | - foreach ($libs as $lib => $rep) { |
|
| 292 | - $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 293 | - } |
|
| 294 | - $res .= '</dl>'; |
|
| 295 | - $res .= fin_cadre_enfonce(); |
|
| 296 | - |
|
| 297 | - return $res; |
|
| 285 | + if (!$libs = liste_librairies()) { |
|
| 286 | + return ''; |
|
| 287 | + } |
|
| 288 | + ksort($libs); |
|
| 289 | + $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
|
| 290 | + $res .= '<dl>'; |
|
| 291 | + foreach ($libs as $lib => $rep) { |
|
| 292 | + $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 293 | + } |
|
| 294 | + $res .= '</dl>'; |
|
| 295 | + $res .= fin_cadre_enfonce(); |
|
| 296 | + |
|
| 297 | + return $res; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -305,22 +305,22 @@ discard block |
||
| 305 | 305 | * Tableau (nom de la lib => repertoire , ...) |
| 306 | 306 | */ |
| 307 | 307 | function liste_librairies() { |
| 308 | - $libs = []; |
|
| 309 | - foreach (array_reverse(creer_chemin()) as $d) { |
|
| 310 | - if ( |
|
| 311 | - is_dir($dir = $d . 'lib/') |
|
| 312 | - and $t = opendir($dir) |
|
| 313 | - ) { |
|
| 314 | - while (($f = readdir($t)) !== false) { |
|
| 315 | - if ( |
|
| 316 | - $f[0] != '.' |
|
| 317 | - and is_dir("$dir/$f") |
|
| 318 | - ) { |
|
| 319 | - $libs[$f] = $dir; |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - return $libs; |
|
| 308 | + $libs = []; |
|
| 309 | + foreach (array_reverse(creer_chemin()) as $d) { |
|
| 310 | + if ( |
|
| 311 | + is_dir($dir = $d . 'lib/') |
|
| 312 | + and $t = opendir($dir) |
|
| 313 | + ) { |
|
| 314 | + while (($f = readdir($t)) !== false) { |
|
| 315 | + if ( |
|
| 316 | + $f[0] != '.' |
|
| 317 | + and is_dir("$dir/$f") |
|
| 318 | + ) { |
|
| 319 | + $libs[$f] = $dir; |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + return $libs; |
|
| 326 | 326 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | |
| 121 | 121 | // message d'erreur au retour d'une operation |
| 122 | 122 | if ($erreur) { |
| 123 | - echo "<div class='error'>" . spip_htmlspecialchars($erreur) . '</div>'; |
|
| 123 | + echo "<div class='error'>".spip_htmlspecialchars($erreur).'</div>'; |
|
| 124 | 124 | } |
| 125 | 125 | if ($erreur_activation) { |
| 126 | 126 | echo "<div class='error'>$erreur_activation</div>"; |
@@ -147,11 +147,11 @@ discard block |
||
| 147 | 147 | if ($quoi !== 'actifs') { |
| 148 | 148 | $lpf = liste_plugin_files(); |
| 149 | 149 | if ($lpf) { |
| 150 | - echo '<p>' . _T('texte_presente_plugin') . '</p>'; |
|
| 150 | + echo '<p>'._T('texte_presente_plugin').'</p>'; |
|
| 151 | 151 | } else { |
| 152 | 152 | if (!@is_dir(_DIR_PLUGINS)) { |
| 153 | - echo '<p>' . _T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | - . ' — ' . _T('plugin_info_automatique_creer') . '</p>'; |
|
| 153 | + echo '<p>'._T('plugin_info_automatique_ftp', ['rep' => joli_repertoire(_DIR_PLUGINS)]) |
|
| 154 | + . ' — '._T('plugin_info_automatique_creer').'</p>'; |
|
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | $lcpaffiche = $lpf; |
@@ -172,10 +172,10 @@ discard block |
||
| 172 | 172 | if (defined('_DIR_PLUGINS_SUPPL')) { |
| 173 | 173 | $nb += is_countable($lcpas) ? count($lcpas) : 0; |
| 174 | 174 | } |
| 175 | - echo '<h3>' . sinon( |
|
| 175 | + echo '<h3>'.sinon( |
|
| 176 | 176 | singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), |
| 177 | 177 | _T('plugins_actif_aucun') |
| 178 | - ) . '</h3>'; |
|
| 178 | + ).'</h3>'; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | if (empty($format)) { |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | |
| 193 | 193 | if ($corps) { |
| 194 | 194 | $corps .= "\n<div class='boutons' style='display:none;'>" |
| 195 | - . "<input type='submit' class='submit save' value='" . _T('bouton_enregistrer') |
|
| 195 | + . "<input type='submit' class='submit save' value='"._T('bouton_enregistrer') |
|
| 196 | 196 | . "' />" |
| 197 | 197 | . '</div>'; |
| 198 | 198 | } |
@@ -266,7 +266,7 @@ discard block |
||
| 266 | 266 | . debut_cadre_trait_couleur('', true, '', _T('plugins_liste_dist'), 'liste_plugins_dist') |
| 267 | 267 | . '<p>' |
| 268 | 268 | . _T('plugin_info_plugins_dist_1', ['plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)]) |
| 269 | - . '<br />' . _T('plugin_info_plugins_dist_2') |
|
| 269 | + . '<br />'._T('plugin_info_plugins_dist_2') |
|
| 270 | 270 | . '</p>' |
| 271 | 271 | . $liste |
| 272 | 272 | . fin_cadre_trait_couleur() |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | $res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees')); |
| 290 | 290 | $res .= '<dl>'; |
| 291 | 291 | foreach ($libs as $lib => $rep) { |
| 292 | - $res .= "<dt>$lib</dt><dd>" . joli_repertoire($rep) . "</dd>\n"; |
|
| 292 | + $res .= "<dt>$lib</dt><dd>".joli_repertoire($rep)."</dd>\n"; |
|
| 293 | 293 | } |
| 294 | 294 | $res .= '</dl>'; |
| 295 | 295 | $res .= fin_cadre_enfonce(); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | $libs = []; |
| 309 | 309 | foreach (array_reverse(creer_chemin()) as $d) { |
| 310 | 310 | if ( |
| 311 | - is_dir($dir = $d . 'lib/') |
|
| 311 | + is_dir($dir = $d.'lib/') |
|
| 312 | 312 | and $t = opendir($dir) |
| 313 | 313 | ) { |
| 314 | 314 | while (($f = readdir($t)) !== false) { |
@@ -42,8 +42,7 @@ |
||
| 42 | 42 | if ((is_countable($logo) ? count($logo) : 0) < 6) { |
| 43 | 43 | spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
| 44 | 44 | spip_unlink($logo[0]); |
| 45 | - } |
|
| 46 | - elseif ( |
|
| 45 | + } elseif ( |
|
| 47 | 46 | $doc = $logo[5] |
| 48 | 47 | and isset($doc['id_document']) |
| 49 | 48 | and $id_document = $doc['id_document'] |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -30,36 +30,36 @@ discard block |
||
| 30 | 30 | * `on` ou `off` |
| 31 | 31 | */ |
| 32 | 32 | function logo_supprimer($objet, $id_objet, $etat) { |
| 33 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | - $objet = objet_type($objet); |
|
| 35 | - $primary = id_table_objet($objet); |
|
| 36 | - include_spip('inc/chercher_logo'); |
|
| 37 | - |
|
| 38 | - // existe-t-il deja un logo ? |
|
| 39 | - $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 40 | - if ($logo) { |
|
| 41 | - # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 42 | - if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 43 | - spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 44 | - spip_unlink($logo[0]); |
|
| 45 | - } |
|
| 46 | - elseif ( |
|
| 47 | - $doc = $logo[5] |
|
| 48 | - and isset($doc['id_document']) |
|
| 49 | - and $id_document = $doc['id_document'] |
|
| 50 | - ) { |
|
| 51 | - include_spip('action/editer_liens'); |
|
| 52 | - // supprimer le lien dans la base |
|
| 53 | - objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 54 | - |
|
| 55 | - // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 56 | - $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 57 | - if (!count($liens)) { |
|
| 58 | - $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 59 | - $supprimer_document($doc['id_document']); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 33 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 34 | + $objet = objet_type($objet); |
|
| 35 | + $primary = id_table_objet($objet); |
|
| 36 | + include_spip('inc/chercher_logo'); |
|
| 37 | + |
|
| 38 | + // existe-t-il deja un logo ? |
|
| 39 | + $logo = $chercher_logo($id_objet, $primary, $etat); |
|
| 40 | + if ($logo) { |
|
| 41 | + # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
|
| 42 | + if ((is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 43 | + spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 44 | + spip_unlink($logo[0]); |
|
| 45 | + } |
|
| 46 | + elseif ( |
|
| 47 | + $doc = $logo[5] |
|
| 48 | + and isset($doc['id_document']) |
|
| 49 | + and $id_document = $doc['id_document'] |
|
| 50 | + ) { |
|
| 51 | + include_spip('action/editer_liens'); |
|
| 52 | + // supprimer le lien dans la base |
|
| 53 | + objet_dissocier(['document' => $id_document], [$objet => $id_objet], ['role' => '*']); |
|
| 54 | + |
|
| 55 | + // verifier si il reste des liens avec d'autres objets et sinon supprimer |
|
| 56 | + $liens = objet_trouver_liens(['document' => $id_document], '*'); |
|
| 57 | + if (!count($liens)) { |
|
| 58 | + $supprimer_document = charger_fonction('supprimer_document', 'action'); |
|
| 59 | + $supprimer_document($doc['id_document']); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -76,200 +76,200 @@ discard block |
||
| 76 | 76 | * Erreur, sinon '' |
| 77 | 77 | */ |
| 78 | 78 | function logo_modifier($objet, $id_objet, $etat, $source) { |
| 79 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 80 | - $objet = objet_type($objet); |
|
| 81 | - $primary = id_table_objet($objet); |
|
| 82 | - include_spip('inc/chercher_logo'); |
|
| 83 | - |
|
| 84 | - $mode = preg_replace(',\W,', '', $etat); |
|
| 85 | - if (!$mode) { |
|
| 86 | - spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 87 | - $erreur = 'etat invalide'; |
|
| 88 | - |
|
| 89 | - return $erreur; |
|
| 90 | - } |
|
| 91 | - // chercher dans la base |
|
| 92 | - $mode_document = 'logo' . $mode; |
|
| 93 | - |
|
| 94 | - include_spip('inc/documents'); |
|
| 95 | - $erreur = ''; |
|
| 96 | - |
|
| 97 | - if (!$source) { |
|
| 98 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 99 | - $erreur = 'source inconnue'; |
|
| 100 | - |
|
| 101 | - return $erreur; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - // fichier dans upload/ |
|
| 105 | - if (is_string($source)) { |
|
| 106 | - $tmp_name = false; |
|
| 107 | - if (file_exists($source)) { |
|
| 108 | - $tmp_name = $source; |
|
| 109 | - } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 110 | - $tmp_name = $f; |
|
| 111 | - } |
|
| 112 | - if (!$tmp_name) { |
|
| 113 | - spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 114 | - $erreur = 'source inconnue'; |
|
| 115 | - |
|
| 116 | - return $erreur; |
|
| 117 | - } |
|
| 118 | - $source = [ |
|
| 119 | - 'tmp_name' => $tmp_name, |
|
| 120 | - 'name' => basename($tmp_name), |
|
| 121 | - ]; |
|
| 122 | - } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 123 | - return $erreur; |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - // supprimer le logo eventueel existant |
|
| 127 | - // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 128 | - // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 129 | - if (empty($GLOBALS['logo_migrer_en_base'])) { |
|
| 130 | - logo_supprimer($objet, $id_objet, $etat); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - |
|
| 134 | - include_spip('inc/autoriser'); |
|
| 135 | - $source['mode'] = $mode_document; |
|
| 136 | - $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 137 | - autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 138 | - $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 139 | - autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 140 | - |
|
| 141 | - $id_document = reset($ajoutes); |
|
| 142 | - |
|
| 143 | - if (!is_numeric($id_document)) { |
|
| 144 | - $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 145 | - spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 146 | - return $erreur; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return ''; // tout est bon, pas d'erreur |
|
| 79 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 80 | + $objet = objet_type($objet); |
|
| 81 | + $primary = id_table_objet($objet); |
|
| 82 | + include_spip('inc/chercher_logo'); |
|
| 83 | + |
|
| 84 | + $mode = preg_replace(',\W,', '', $etat); |
|
| 85 | + if (!$mode) { |
|
| 86 | + spip_log("logo_modifier : etat $etat invalide", 'logo'); |
|
| 87 | + $erreur = 'etat invalide'; |
|
| 88 | + |
|
| 89 | + return $erreur; |
|
| 90 | + } |
|
| 91 | + // chercher dans la base |
|
| 92 | + $mode_document = 'logo' . $mode; |
|
| 93 | + |
|
| 94 | + include_spip('inc/documents'); |
|
| 95 | + $erreur = ''; |
|
| 96 | + |
|
| 97 | + if (!$source) { |
|
| 98 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 99 | + $erreur = 'source inconnue'; |
|
| 100 | + |
|
| 101 | + return $erreur; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + // fichier dans upload/ |
|
| 105 | + if (is_string($source)) { |
|
| 106 | + $tmp_name = false; |
|
| 107 | + if (file_exists($source)) { |
|
| 108 | + $tmp_name = $source; |
|
| 109 | + } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 110 | + $tmp_name = $f; |
|
| 111 | + } |
|
| 112 | + if (!$tmp_name) { |
|
| 113 | + spip_log('spip_image_ajouter : source inconnue', 'logo'); |
|
| 114 | + $erreur = 'source inconnue'; |
|
| 115 | + |
|
| 116 | + return $erreur; |
|
| 117 | + } |
|
| 118 | + $source = [ |
|
| 119 | + 'tmp_name' => $tmp_name, |
|
| 120 | + 'name' => basename($tmp_name), |
|
| 121 | + ]; |
|
| 122 | + } elseif ($erreur = check_upload_error($source['error'], '', true)) { |
|
| 123 | + return $erreur; |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + // supprimer le logo eventueel existant |
|
| 127 | + // TODO : si un logo existe, le modifier plutot que supprimer + reinserer (mais il faut gerer le cas ou il est utilise par plusieurs objets, donc pas si simple) |
|
| 128 | + // mais de toute facon l'interface actuelle oblige a supprimer + reinserer |
|
| 129 | + if (empty($GLOBALS['logo_migrer_en_base'])) { |
|
| 130 | + logo_supprimer($objet, $id_objet, $etat); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + |
|
| 134 | + include_spip('inc/autoriser'); |
|
| 135 | + $source['mode'] = $mode_document; |
|
| 136 | + $ajouter_documents = charger_fonction('ajouter_documents', 'action'); |
|
| 137 | + autoriser_exception('associerdocuments', $objet, $id_objet); |
|
| 138 | + $ajoutes = $ajouter_documents('new', [$source], $objet, $id_objet, $mode_document); |
|
| 139 | + autoriser_exception('associerdocuments', $objet, $id_objet, false); |
|
| 140 | + |
|
| 141 | + $id_document = reset($ajoutes); |
|
| 142 | + |
|
| 143 | + if (!is_numeric($id_document)) { |
|
| 144 | + $erreur = ($id_document ?: 'Erreur inconnue'); |
|
| 145 | + spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 146 | + return $erreur; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return ''; // tout est bon, pas d'erreur |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | function logo_migrer_en_base($objet, $time_limit) { |
| 153 | 153 | |
| 154 | - $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 155 | - $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 156 | - $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 157 | - if (isset($GLOBALS['formats_logos'])) { |
|
| 158 | - $formats_logos = $GLOBALS['formats_logos']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - |
|
| 162 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 163 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 164 | - include_spip('inc/chercher_logo'); |
|
| 165 | - $_id_objet = id_table_objet($objet); |
|
| 166 | - $table = table_objet_sql($objet); |
|
| 167 | - $type = type_du_logo($_id_objet); |
|
| 168 | - $desc = $trouver_table($table); |
|
| 169 | - |
|
| 170 | - // on desactive les revisions |
|
| 171 | - $liste_objets_versionnes = $GLOBALS['meta']['objets_versions'] ?? ''; |
|
| 172 | - unset($GLOBALS['meta']['objets_versions']); |
|
| 173 | - // et le signalement des editions |
|
| 174 | - $articles_modif = $GLOBALS['meta']['articles_modif'] ?? ''; |
|
| 175 | - $GLOBALS['meta']['articles_modif'] = 'non'; |
|
| 176 | - |
|
| 177 | - foreach (['on', 'off'] as $mode) { |
|
| 178 | - $nom_base = $type . $mode; |
|
| 179 | - $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 180 | - |
|
| 181 | - $files = glob($dir . $nom_base . '*'); |
|
| 182 | - // est-ce que c'est une nouvelle tentative de migration ? |
|
| 183 | - // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 184 | - if (!(is_countable($files) ? count($files) : 0)) { |
|
| 185 | - $files = glob($dir_logos . $nom_base . '*'); |
|
| 186 | - if (is_countable($files) ? count($files) : 0) { |
|
| 187 | - // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 188 | - $filescheck = []; |
|
| 189 | - foreach ($files as $file) { |
|
| 190 | - $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 191 | - $filescheck[$short] = $file; |
|
| 192 | - } |
|
| 193 | - // trouver ceux deja migres |
|
| 194 | - $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 195 | - if (is_countable($deja) ? count($deja) : 0) { |
|
| 196 | - $deja = array_column($deja, 'fichier'); |
|
| 197 | - $restant = array_diff(array_keys($filescheck), $deja); |
|
| 198 | - $files = []; |
|
| 199 | - if (count($restant)) { |
|
| 200 | - foreach ($restant as $r) { |
|
| 201 | - $files[] = $filescheck[$r]; |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - // et si il en reste on peut y aller... |
|
| 206 | - // mais il faut modifier $dir qui sert de base dans la suite |
|
| 207 | - if (is_countable($files) ? count($files) : 0) { |
|
| 208 | - $dir = $dir_logos; |
|
| 209 | - } |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $count = (is_countable($files) ? count($files) : 0); |
|
| 214 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 215 | - |
|
| 216 | - $deja = []; |
|
| 217 | - foreach ($files as $file) { |
|
| 218 | - $logo = substr($file, strlen($dir . $nom_base)); |
|
| 219 | - $logo = explode('.', $logo); |
|
| 220 | - if ( |
|
| 221 | - is_numeric($logo[0]) |
|
| 222 | - and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique'])) |
|
| 223 | - ) { |
|
| 224 | - if (!isset($deja[$id_objet])) { |
|
| 225 | - $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 226 | - // if no logo in base |
|
| 227 | - if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 228 | - foreach ($formats_logos as $format) { |
|
| 229 | - if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 230 | - if (isset($desc['field']['date_modif'])) { |
|
| 231 | - $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 232 | - } else { |
|
| 233 | - $date_modif = null; |
|
| 234 | - } |
|
| 235 | - // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
|
| 236 | - @chmod($d, _SPIP_CHMOD & 0666); |
|
| 237 | - // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 238 | - @rename($d, $dir_logos . $nom); |
|
| 239 | - // et on le declare comme nouveau logo |
|
| 240 | - logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 241 | - if ($date_modif) { |
|
| 242 | - sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 243 | - } |
|
| 244 | - break; |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - $deja[$id_objet] = true; |
|
| 249 | - } |
|
| 250 | - } |
|
| 251 | - // si le fichier est encore la on le move : rien a faire ici |
|
| 252 | - // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 253 | - if ($dir !== $dir_logos and file_exists($file)) { |
|
| 254 | - @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - $count--; |
|
| 258 | - if ($count % 250 === 0) { |
|
| 259 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if ($time_limit and time() > $time_limit) { |
|
| 263 | - effacer_meta('drapeau_edition'); |
|
| 264 | - return; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - if ($liste_objets_versionnes) { |
|
| 270 | - $GLOBALS['meta']['objets_versions'] = $liste_objets_versionnes; |
|
| 271 | - } |
|
| 272 | - $GLOBALS['meta']['articles_modif'] = $articles_modif; |
|
| 273 | - |
|
| 274 | - effacer_meta('drapeau_edition'); |
|
| 154 | + $dir_logos_erreurs = sous_repertoire(_DIR_IMG, 'logo_erreurs'); |
|
| 155 | + $dir_logos = sous_repertoire(_DIR_IMG, 'logo'); |
|
| 156 | + $formats_logos = ['jpg', 'png', 'svg', 'gif']; |
|
| 157 | + if (isset($GLOBALS['formats_logos'])) { |
|
| 158 | + $formats_logos = $GLOBALS['formats_logos']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + |
|
| 162 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 163 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 164 | + include_spip('inc/chercher_logo'); |
|
| 165 | + $_id_objet = id_table_objet($objet); |
|
| 166 | + $table = table_objet_sql($objet); |
|
| 167 | + $type = type_du_logo($_id_objet); |
|
| 168 | + $desc = $trouver_table($table); |
|
| 169 | + |
|
| 170 | + // on desactive les revisions |
|
| 171 | + $liste_objets_versionnes = $GLOBALS['meta']['objets_versions'] ?? ''; |
|
| 172 | + unset($GLOBALS['meta']['objets_versions']); |
|
| 173 | + // et le signalement des editions |
|
| 174 | + $articles_modif = $GLOBALS['meta']['articles_modif'] ?? ''; |
|
| 175 | + $GLOBALS['meta']['articles_modif'] = 'non'; |
|
| 176 | + |
|
| 177 | + foreach (['on', 'off'] as $mode) { |
|
| 178 | + $nom_base = $type . $mode; |
|
| 179 | + $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
|
| 180 | + |
|
| 181 | + $files = glob($dir . $nom_base . '*'); |
|
| 182 | + // est-ce que c'est une nouvelle tentative de migration ? |
|
| 183 | + // dans ce cas les logos sont deja dans IMG/logo/ |
|
| 184 | + if (!(is_countable($files) ? count($files) : 0)) { |
|
| 185 | + $files = glob($dir_logos . $nom_base . '*'); |
|
| 186 | + if (is_countable($files) ? count($files) : 0) { |
|
| 187 | + // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
|
| 188 | + $filescheck = []; |
|
| 189 | + foreach ($files as $file) { |
|
| 190 | + $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 191 | + $filescheck[$short] = $file; |
|
| 192 | + } |
|
| 193 | + // trouver ceux deja migres |
|
| 194 | + $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 195 | + if (is_countable($deja) ? count($deja) : 0) { |
|
| 196 | + $deja = array_column($deja, 'fichier'); |
|
| 197 | + $restant = array_diff(array_keys($filescheck), $deja); |
|
| 198 | + $files = []; |
|
| 199 | + if (count($restant)) { |
|
| 200 | + foreach ($restant as $r) { |
|
| 201 | + $files[] = $filescheck[$r]; |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + // et si il en reste on peut y aller... |
|
| 206 | + // mais il faut modifier $dir qui sert de base dans la suite |
|
| 207 | + if (is_countable($files) ? count($files) : 0) { |
|
| 208 | + $dir = $dir_logos; |
|
| 209 | + } |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $count = (is_countable($files) ? count($files) : 0); |
|
| 214 | + spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 215 | + |
|
| 216 | + $deja = []; |
|
| 217 | + foreach ($files as $file) { |
|
| 218 | + $logo = substr($file, strlen($dir . $nom_base)); |
|
| 219 | + $logo = explode('.', $logo); |
|
| 220 | + if ( |
|
| 221 | + is_numeric($logo[0]) |
|
| 222 | + and ($id_objet = intval($logo[0]) or in_array($objet, ['site', 'rubrique'])) |
|
| 223 | + ) { |
|
| 224 | + if (!isset($deja[$id_objet])) { |
|
| 225 | + $logo = $chercher_logo($id_objet, $_id_objet, $mode); |
|
| 226 | + // if no logo in base |
|
| 227 | + if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
|
| 228 | + foreach ($formats_logos as $format) { |
|
| 229 | + if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 230 | + if (isset($desc['field']['date_modif'])) { |
|
| 231 | + $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
|
| 232 | + } else { |
|
| 233 | + $date_modif = null; |
|
| 234 | + } |
|
| 235 | + // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
|
| 236 | + @chmod($d, _SPIP_CHMOD & 0666); |
|
| 237 | + // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
|
| 238 | + @rename($d, $dir_logos . $nom); |
|
| 239 | + // et on le declare comme nouveau logo |
|
| 240 | + logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 241 | + if ($date_modif) { |
|
| 242 | + sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
|
| 243 | + } |
|
| 244 | + break; |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + $deja[$id_objet] = true; |
|
| 249 | + } |
|
| 250 | + } |
|
| 251 | + // si le fichier est encore la on le move : rien a faire ici |
|
| 252 | + // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
|
| 253 | + if ($dir !== $dir_logos and file_exists($file)) { |
|
| 254 | + @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + $count--; |
|
| 258 | + if ($count % 250 === 0) { |
|
| 259 | + spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if ($time_limit and time() > $time_limit) { |
|
| 263 | + effacer_meta('drapeau_edition'); |
|
| 264 | + return; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + if ($liste_objets_versionnes) { |
|
| 270 | + $GLOBALS['meta']['objets_versions'] = $liste_objets_versionnes; |
|
| 271 | + } |
|
| 272 | + $GLOBALS['meta']['articles_modif'] = $articles_modif; |
|
| 273 | + |
|
| 274 | + effacer_meta('drapeau_edition'); |
|
| 275 | 275 | } |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | if ($logo) { |
| 41 | 41 | # TODO : deprecated, a supprimer -> anciens logos IMG/artonxx.png pas en base |
| 42 | 42 | if ((is_countable($logo) ? count($logo) : 0) < 6) { |
| 43 | - spip_log('Supprimer ancien logo ' . json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 43 | + spip_log('Supprimer ancien logo '.json_encode($logo, JSON_THROW_ON_ERROR), 'logo'); |
|
| 44 | 44 | spip_unlink($logo[0]); |
| 45 | 45 | } |
| 46 | 46 | elseif ( |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | return $erreur; |
| 90 | 90 | } |
| 91 | 91 | // chercher dans la base |
| 92 | - $mode_document = 'logo' . $mode; |
|
| 92 | + $mode_document = 'logo'.$mode; |
|
| 93 | 93 | |
| 94 | 94 | include_spip('inc/documents'); |
| 95 | 95 | $erreur = ''; |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | $tmp_name = false; |
| 107 | 107 | if (file_exists($source)) { |
| 108 | 108 | $tmp_name = $source; |
| 109 | - } elseif (file_exists($f = determine_upload() . $source)) { |
|
| 109 | + } elseif (file_exists($f = determine_upload().$source)) { |
|
| 110 | 110 | $tmp_name = $f; |
| 111 | 111 | } |
| 112 | 112 | if (!$tmp_name) { |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | if (!is_numeric($id_document)) { |
| 144 | 144 | $erreur = ($id_document ?: 'Erreur inconnue'); |
| 145 | - spip_log("Erreur ajout logo : $erreur pour source=" . json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 145 | + spip_log("Erreur ajout logo : $erreur pour source=".json_encode($source, JSON_THROW_ON_ERROR), 'logo'); |
|
| 146 | 146 | return $erreur; |
| 147 | 147 | } |
| 148 | 148 | |
@@ -175,23 +175,23 @@ discard block |
||
| 175 | 175 | $GLOBALS['meta']['articles_modif'] = 'non'; |
| 176 | 176 | |
| 177 | 177 | foreach (['on', 'off'] as $mode) { |
| 178 | - $nom_base = $type . $mode; |
|
| 178 | + $nom_base = $type.$mode; |
|
| 179 | 179 | $dir = (defined('_DIR_LOGOS') ? _DIR_LOGOS : _DIR_IMG); |
| 180 | 180 | |
| 181 | - $files = glob($dir . $nom_base . '*'); |
|
| 181 | + $files = glob($dir.$nom_base.'*'); |
|
| 182 | 182 | // est-ce que c'est une nouvelle tentative de migration ? |
| 183 | 183 | // dans ce cas les logos sont deja dans IMG/logo/ |
| 184 | 184 | if (!(is_countable($files) ? count($files) : 0)) { |
| 185 | - $files = glob($dir_logos . $nom_base . '*'); |
|
| 185 | + $files = glob($dir_logos.$nom_base.'*'); |
|
| 186 | 186 | if (is_countable($files) ? count($files) : 0) { |
| 187 | 187 | // mais il faut verifier si ils ont pas deja ete migres pour tout ou partie |
| 188 | 188 | $filescheck = []; |
| 189 | 189 | foreach ($files as $file) { |
| 190 | - $short = basename(dirname($file)) . DIRECTORY_SEPARATOR . basename($file); |
|
| 190 | + $short = basename(dirname($file)).DIRECTORY_SEPARATOR.basename($file); |
|
| 191 | 191 | $filescheck[$short] = $file; |
| 192 | 192 | } |
| 193 | 193 | // trouver ceux deja migres |
| 194 | - $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck)) . " AND mode LIKE 'logo%'"); |
|
| 194 | + $deja = sql_allfetsel('fichier', 'spip_documents', sql_in('fichier', array_keys($filescheck))." AND mode LIKE 'logo%'"); |
|
| 195 | 195 | if (is_countable($deja) ? count($deja) : 0) { |
| 196 | 196 | $deja = array_column($deja, 'fichier'); |
| 197 | 197 | $restant = array_diff(array_keys($filescheck), $deja); |
@@ -211,11 +211,11 @@ discard block |
||
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | $count = (is_countable($files) ? count($files) : 0); |
| 214 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 214 | + spip_log("logo_migrer_en_base $objet $mode : ".$count.' logos restant', 'maj'._LOG_INFO_IMPORTANTE); |
|
| 215 | 215 | |
| 216 | 216 | $deja = []; |
| 217 | 217 | foreach ($files as $file) { |
| 218 | - $logo = substr($file, strlen($dir . $nom_base)); |
|
| 218 | + $logo = substr($file, strlen($dir.$nom_base)); |
|
| 219 | 219 | $logo = explode('.', $logo); |
| 220 | 220 | if ( |
| 221 | 221 | is_numeric($logo[0]) |
@@ -226,7 +226,7 @@ discard block |
||
| 226 | 226 | // if no logo in base |
| 227 | 227 | if (!$logo or (is_countable($logo) ? count($logo) : 0) < 6) { |
| 228 | 228 | foreach ($formats_logos as $format) { |
| 229 | - if (@file_exists($d = ($dir . ($nom = $nom_base . intval($id_objet) . '.' . $format)))) { |
|
| 229 | + if (@file_exists($d = ($dir.($nom = $nom_base.intval($id_objet).'.'.$format)))) { |
|
| 230 | 230 | if (isset($desc['field']['date_modif'])) { |
| 231 | 231 | $date_modif = sql_getfetsel('date_modif', $table, "$_id_objet=$id_objet"); |
| 232 | 232 | } else { |
@@ -235,9 +235,9 @@ discard block |
||
| 235 | 235 | // s'assurer que le logo a les bon droits au passage (evite un echec en cas de sanitization d'un svg) |
| 236 | 236 | @chmod($d, _SPIP_CHMOD & 0666); |
| 237 | 237 | // logo_modifier commence par supprimer le logo existant, donc on le deplace pour pas le perdre |
| 238 | - @rename($d, $dir_logos . $nom); |
|
| 238 | + @rename($d, $dir_logos.$nom); |
|
| 239 | 239 | // et on le declare comme nouveau logo |
| 240 | - logo_modifier($objet, $id_objet, $mode, $dir_logos . $nom); |
|
| 240 | + logo_modifier($objet, $id_objet, $mode, $dir_logos.$nom); |
|
| 241 | 241 | if ($date_modif) { |
| 242 | 242 | sql_updateq($table, ['date_modif' => $date_modif], "$_id_objet=$id_objet"); |
| 243 | 243 | } |
@@ -251,12 +251,12 @@ discard block |
||
| 251 | 251 | // si le fichier est encore la on le move : rien a faire ici |
| 252 | 252 | // (sauf si c'est une re-migration : il est deja dans logo/ donc il bouge pas) |
| 253 | 253 | if ($dir !== $dir_logos and file_exists($file)) { |
| 254 | - @rename($file, $dir_logos_erreurs . basename($file)); |
|
| 254 | + @rename($file, $dir_logos_erreurs.basename($file)); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | $count--; |
| 258 | 258 | if ($count % 250 === 0) { |
| 259 | - spip_log("logo_migrer_en_base $objet $mode : " . $count . ' logos restant', 'maj' . _LOG_INFO_IMPORTANTE); |
|
| 259 | + spip_log("logo_migrer_en_base $objet $mode : ".$count.' logos restant', 'maj'._LOG_INFO_IMPORTANTE); |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | if ($time_limit and time() > $time_limit) { |
@@ -11,109 +11,109 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) { |
| 18 | - static $test_repertoire = []; |
|
| 19 | - static $compteur = []; |
|
| 20 | - static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | - |
|
| 22 | - if (is_null($logname) or !is_string($logname)) { |
|
| 23 | - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | - } |
|
| 25 | - if (!isset($compteur[$logname])) { |
|
| 26 | - $compteur[$logname] = 0; |
|
| 27 | - } |
|
| 28 | - if ( |
|
| 29 | - $logname != 'maj' |
|
| 30 | - and defined('_MAX_LOG') |
|
| 31 | - and ( |
|
| 32 | - $compteur[$logname]++ > _MAX_LOG |
|
| 33 | - or !$GLOBALS['nombre_de_logs'] |
|
| 34 | - or !$GLOBALS['taille_des_logs'] |
|
| 35 | - ) |
|
| 36 | - ) { |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 41 | - $logfile = |
|
| 42 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | - . $logname |
|
| 44 | - . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 45 | - |
|
| 46 | - if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 47 | - $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 48 | - $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 49 | - $d, |
|
| 50 | - '', |
|
| 51 | - false, |
|
| 52 | - true |
|
| 53 | - ) : false)); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 57 | - if (!$test_repertoire[$d]) { |
|
| 58 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $rotate = 0; |
|
| 62 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 63 | - |
|
| 64 | - // accepter spip_log( Array ) |
|
| 65 | - if (!is_string($message)) { |
|
| 66 | - $message = var_export($message, true); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 70 | - $debug = debug_backtrace(); |
|
| 71 | - $l = $debug[1]['line']; |
|
| 72 | - $fi = $debug[1]['file']; |
|
| 73 | - if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 74 | - $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 75 | - } |
|
| 76 | - $fu = $debug[2]['function'] ?? ''; |
|
| 77 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 81 | - //distinguer les logs prives et publics dans les grep |
|
| 82 | - . $debugverb |
|
| 83 | - . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 84 | - . preg_replace("/\n*$/", "\n", $message); |
|
| 85 | - |
|
| 86 | - |
|
| 87 | - if ( |
|
| 88 | - @is_readable($logfile) |
|
| 89 | - and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 90 | - ) { |
|
| 91 | - $rotate = $GLOBALS['nombre_de_logs']; |
|
| 92 | - $m .= "[-- rotate --]\n"; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - $f = @fopen($logfile, 'ab'); |
|
| 96 | - if ($f) { |
|
| 97 | - fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 98 | - fclose($f); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ( |
|
| 102 | - $rotate-- > 0 |
|
| 103 | - and function_exists('spip_unlink') |
|
| 104 | - ) { |
|
| 105 | - spip_unlink($logfile . '.' . $rotate); |
|
| 106 | - while ($rotate--) { |
|
| 107 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - // Dupliquer les erreurs specifiques dans le log general |
|
| 112 | - if ( |
|
| 113 | - defined('_FILE_LOG') |
|
| 114 | - and ($logname !== _FILE_LOG) |
|
| 115 | - ) { |
|
| 116 | - inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 117 | - } |
|
| 118 | - $debugverb = ''; |
|
| 18 | + static $test_repertoire = []; |
|
| 19 | + static $compteur = []; |
|
| 20 | + static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | + |
|
| 22 | + if (is_null($logname) or !is_string($logname)) { |
|
| 23 | + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | + } |
|
| 25 | + if (!isset($compteur[$logname])) { |
|
| 26 | + $compteur[$logname] = 0; |
|
| 27 | + } |
|
| 28 | + if ( |
|
| 29 | + $logname != 'maj' |
|
| 30 | + and defined('_MAX_LOG') |
|
| 31 | + and ( |
|
| 32 | + $compteur[$logname]++ > _MAX_LOG |
|
| 33 | + or !$GLOBALS['nombre_de_logs'] |
|
| 34 | + or !$GLOBALS['taille_des_logs'] |
|
| 35 | + ) |
|
| 36 | + ) { |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
|
| 41 | + $logfile = |
|
| 42 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | + . $logname |
|
| 44 | + . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
|
| 45 | + |
|
| 46 | + if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 47 | + $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 48 | + $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 49 | + $d, |
|
| 50 | + '', |
|
| 51 | + false, |
|
| 52 | + true |
|
| 53 | + ) : false)); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Si le repertoire défini n'existe pas, poser dans tmp/ |
|
| 57 | + if (!$test_repertoire[$d]) { |
|
| 58 | + $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $rotate = 0; |
|
| 62 | + $pid = '(pid ' . @getmypid() . ')'; |
|
| 63 | + |
|
| 64 | + // accepter spip_log( Array ) |
|
| 65 | + if (!is_string($message)) { |
|
| 66 | + $message = var_export($message, true); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 70 | + $debug = debug_backtrace(); |
|
| 71 | + $l = $debug[1]['line']; |
|
| 72 | + $fi = $debug[1]['file']; |
|
| 73 | + if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 74 | + $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 75 | + } |
|
| 76 | + $fu = $debug[2]['function'] ?? ''; |
|
| 77 | + $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 81 | + //distinguer les logs prives et publics dans les grep |
|
| 82 | + . $debugverb |
|
| 83 | + . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 84 | + . preg_replace("/\n*$/", "\n", $message); |
|
| 85 | + |
|
| 86 | + |
|
| 87 | + if ( |
|
| 88 | + @is_readable($logfile) |
|
| 89 | + and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 90 | + ) { |
|
| 91 | + $rotate = $GLOBALS['nombre_de_logs']; |
|
| 92 | + $m .= "[-- rotate --]\n"; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + $f = @fopen($logfile, 'ab'); |
|
| 96 | + if ($f) { |
|
| 97 | + fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 98 | + fclose($f); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ( |
|
| 102 | + $rotate-- > 0 |
|
| 103 | + and function_exists('spip_unlink') |
|
| 104 | + ) { |
|
| 105 | + spip_unlink($logfile . '.' . $rotate); |
|
| 106 | + while ($rotate--) { |
|
| 107 | + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + // Dupliquer les erreurs specifiques dans le log general |
|
| 112 | + if ( |
|
| 113 | + defined('_FILE_LOG') |
|
| 114 | + and ($logname !== _FILE_LOG) |
|
| 115 | + ) { |
|
| 116 | + inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 117 | + } |
|
| 118 | + $debugverb = ''; |
|
| 119 | 119 | } |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | // si spip_log() est appelé dans mes_options, toutes les constantes n'ont pas été définies |
| 41 | 41 | $logfile = |
| 42 | - ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 42 | + ($logdir ?? (defined('_DIR_LOG') ? _DIR_LOG : _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES)) |
|
| 43 | 43 | . $logname |
| 44 | 44 | . ($logsuf ?? (defined('_FILE_LOG_SUFFIX') ? _FILE_LOG_SUFFIX : '.log')); |
| 45 | 45 | |
@@ -55,11 +55,11 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | // Si le repertoire défini n'existe pas, poser dans tmp/ |
| 57 | 57 | if (!$test_repertoire[$d]) { |
| 58 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 58 | + $logfile = _DIR_RACINE._NOM_TEMPORAIRES_INACCESSIBLES.$logname.'.log'; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | $rotate = 0; |
| 62 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 62 | + $pid = '(pid '.@getmypid().')'; |
|
| 63 | 63 | |
| 64 | 64 | // accepter spip_log( Array ) |
| 65 | 65 | if (!is_string($message)) { |
@@ -74,10 +74,10 @@ discard block |
||
| 74 | 74 | $fi = substr($fi, strlen(_ROOT_RACINE)); |
| 75 | 75 | } |
| 76 | 76 | $fu = $debug[2]['function'] ?? ''; |
| 77 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 77 | + $debugverb = "$fi:L$l:$fu".'():'; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 80 | + $m = date('Y-m-d H:i:s').' '.($GLOBALS['ip'] ?? '').' '.$pid.' ' |
|
| 81 | 81 | //distinguer les logs prives et publics dans les grep |
| 82 | 82 | . $debugverb |
| 83 | 83 | . (test_espace_prive() ? ':Pri:' : ':Pub:') |
@@ -102,9 +102,9 @@ discard block |
||
| 102 | 102 | $rotate-- > 0 |
| 103 | 103 | and function_exists('spip_unlink') |
| 104 | 104 | ) { |
| 105 | - spip_unlink($logfile . '.' . $rotate); |
|
| 105 | + spip_unlink($logfile.'.'.$rotate); |
|
| 106 | 106 | while ($rotate--) { |
| 107 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 107 | + @rename($logfile.($rotate ? '.'.$rotate : ''), $logfile.'.'.($rotate + 1)); |
|
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | |