@@ -11,298 +11,298 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | // methodes sql |
| 19 | 19 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 20 | 20 | |
| 21 | - // options par defaut |
|
| 22 | - $options = array_merge( |
|
| 23 | - [ |
|
| 24 | - 'score' => true, |
|
| 25 | - 'champs' => false, |
|
| 26 | - 'toutvoir' => false, |
|
| 27 | - 'matches' => false, |
|
| 28 | - 'jointures' => false |
|
| 29 | - ], |
|
| 30 | - $options |
|
| 31 | - ); |
|
| 21 | + // options par defaut |
|
| 22 | + $options = array_merge( |
|
| 23 | + [ |
|
| 24 | + 'score' => true, |
|
| 25 | + 'champs' => false, |
|
| 26 | + 'toutvoir' => false, |
|
| 27 | + 'matches' => false, |
|
| 28 | + 'jointures' => false |
|
| 29 | + ], |
|
| 30 | + $options |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - include_spip('inc/rechercher'); |
|
| 34 | - include_spip('inc/autoriser'); |
|
| 33 | + include_spip('inc/rechercher'); |
|
| 34 | + include_spip('inc/autoriser'); |
|
| 35 | 35 | |
| 36 | - $requete = [ |
|
| 37 | - 'SELECT' => [], |
|
| 38 | - 'FROM' => [], |
|
| 39 | - 'WHERE' => [], |
|
| 40 | - 'GROUPBY' => [], |
|
| 41 | - 'ORDERBY' => [], |
|
| 42 | - 'LIMIT' => '', |
|
| 43 | - 'HAVING' => [] |
|
| 44 | - ]; |
|
| 36 | + $requete = [ |
|
| 37 | + 'SELECT' => [], |
|
| 38 | + 'FROM' => [], |
|
| 39 | + 'WHERE' => [], |
|
| 40 | + 'GROUPBY' => [], |
|
| 41 | + 'ORDERBY' => [], |
|
| 42 | + 'LIMIT' => '', |
|
| 43 | + 'HAVING' => [] |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $table = sinon($options['table'], 'article'); |
|
| 47 | - if ($options['champs']) { |
|
| 48 | - $champs = $options['champs']; |
|
| 49 | - } else { |
|
| 50 | - $l = liste_des_champs(); |
|
| 51 | - $champs = $l['article']; |
|
| 52 | - } |
|
| 53 | - $serveur = $options['serveur']; |
|
| 46 | + $table = sinon($options['table'], 'article'); |
|
| 47 | + if ($options['champs']) { |
|
| 48 | + $champs = $options['champs']; |
|
| 49 | + } else { |
|
| 50 | + $l = liste_des_champs(); |
|
| 51 | + $champs = $l['article']; |
|
| 52 | + } |
|
| 53 | + $serveur = $options['serveur']; |
|
| 54 | 54 | |
| 55 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 56 | 56 | |
| 57 | - $jointures = $options['jointures'] |
|
| 58 | - ? liste_des_jointures() |
|
| 59 | - : []; |
|
| 57 | + $jointures = $options['jointures'] |
|
| 58 | + ? liste_des_jointures() |
|
| 59 | + : []; |
|
| 60 | 60 | |
| 61 | - $_id_table = id_table_objet($table); |
|
| 61 | + $_id_table = id_table_objet($table); |
|
| 62 | 62 | |
| 63 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | - if (strpos($_id_table, ',') !== false) { |
|
| 66 | - $_id_table = explode(',', $_id_table); |
|
| 67 | - $_id_table = reset($_id_table); |
|
| 68 | - } |
|
| 63 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | + if (strpos($_id_table, ',') !== false) { |
|
| 66 | + $_id_table = explode(',', $_id_table); |
|
| 67 | + $_id_table = reset($_id_table); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | - $a = []; |
|
| 72 | - // Recherche fulltext |
|
| 73 | - foreach ($champs as $champ => $poids) { |
|
| 74 | - if (is_array($champ)) { |
|
| 75 | - spip_log('requetes imbriquees interdites'); |
|
| 76 | - } else { |
|
| 77 | - if (strpos($champ, '.') === false) { |
|
| 78 | - $champ = "t.$champ"; |
|
| 79 | - } |
|
| 80 | - $requete['SELECT'][] = $champ; |
|
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - if ($a) { |
|
| 85 | - $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | - } |
|
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 70 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | + $a = []; |
|
| 72 | + // Recherche fulltext |
|
| 73 | + foreach ($champs as $champ => $poids) { |
|
| 74 | + if (is_array($champ)) { |
|
| 75 | + spip_log('requetes imbriquees interdites'); |
|
| 76 | + } else { |
|
| 77 | + if (strpos($champ, '.') === false) { |
|
| 78 | + $champ = "t.$champ"; |
|
| 79 | + } |
|
| 80 | + $requete['SELECT'][] = $champ; |
|
| 81 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + if ($a) { |
|
| 85 | + $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | + } |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 88 | 88 | |
| 89 | - $results = []; |
|
| 89 | + $results = []; |
|
| 90 | 90 | |
| 91 | - $s = sql_select( |
|
| 92 | - $requete['SELECT'], |
|
| 93 | - $requete['FROM'], |
|
| 94 | - $requete['WHERE'], |
|
| 95 | - implode(' ', $requete['GROUPBY']), |
|
| 96 | - $requete['ORDERBY'], |
|
| 97 | - $requete['LIMIT'], |
|
| 98 | - $requete['HAVING'], |
|
| 99 | - $serveur |
|
| 100 | - ); |
|
| 91 | + $s = sql_select( |
|
| 92 | + $requete['SELECT'], |
|
| 93 | + $requete['FROM'], |
|
| 94 | + $requete['WHERE'], |
|
| 95 | + implode(' ', $requete['GROUPBY']), |
|
| 96 | + $requete['ORDERBY'], |
|
| 97 | + $requete['LIMIT'], |
|
| 98 | + $requete['HAVING'], |
|
| 99 | + $serveur |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - while ( |
|
| 103 | - $t = sql_fetch($s, $serveur) |
|
| 104 | - and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | - ) { |
|
| 106 | - $id = intval($t[$_id_table]); |
|
| 102 | + while ( |
|
| 103 | + $t = sql_fetch($s, $serveur) |
|
| 104 | + and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | + ) { |
|
| 106 | + $id = intval($t[$_id_table]); |
|
| 107 | 107 | |
| 108 | - if ( |
|
| 109 | - $options['toutvoir'] |
|
| 110 | - or autoriser('voir', $table, $id) |
|
| 111 | - ) { |
|
| 112 | - // indiquer les champs concernes |
|
| 113 | - $champs_vus = []; |
|
| 114 | - $score = 0; |
|
| 115 | - $matches = []; |
|
| 108 | + if ( |
|
| 109 | + $options['toutvoir'] |
|
| 110 | + or autoriser('voir', $table, $id) |
|
| 111 | + ) { |
|
| 112 | + // indiquer les champs concernes |
|
| 113 | + $champs_vus = []; |
|
| 114 | + $score = 0; |
|
| 115 | + $matches = []; |
|
| 116 | 116 | |
| 117 | - $vu = false; |
|
| 118 | - foreach ($champs as $champ => $poids) { |
|
| 119 | - $champ = explode('.', $champ); |
|
| 120 | - $champ = end($champ); |
|
| 121 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | - if ( |
|
| 124 | - $n = |
|
| 125 | - ($options['score'] || $options['matches']) |
|
| 126 | - ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | - : preg_match($preg, $value) |
|
| 128 | - ) { |
|
| 129 | - $vu = true; |
|
| 117 | + $vu = false; |
|
| 118 | + foreach ($champs as $champ => $poids) { |
|
| 119 | + $champ = explode('.', $champ); |
|
| 120 | + $champ = end($champ); |
|
| 121 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | + if ( |
|
| 124 | + $n = |
|
| 125 | + ($options['score'] || $options['matches']) |
|
| 126 | + ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | + : preg_match($preg, $value) |
|
| 128 | + ) { |
|
| 129 | + $vu = true; |
|
| 130 | 130 | |
| 131 | - if ($options['champs']) { |
|
| 132 | - $champs_vus[$champ] = $t[$champ]; |
|
| 133 | - } |
|
| 134 | - if ($options['score']) { |
|
| 135 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | - } |
|
| 131 | + if ($options['champs']) { |
|
| 132 | + $champs_vus[$champ] = $t[$champ]; |
|
| 133 | + } |
|
| 134 | + if ($options['score']) { |
|
| 135 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($options['matches']) { |
|
| 140 | - $matches[$champ] = $regs; |
|
| 141 | - } |
|
| 139 | + if ($options['matches']) { |
|
| 140 | + $matches[$champ] = $regs; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ( |
|
| 144 | - !$options['champs'] |
|
| 145 | - and !$options['score'] |
|
| 146 | - and !$options['matches'] |
|
| 147 | - ) { |
|
| 148 | - break; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 143 | + if ( |
|
| 144 | + !$options['champs'] |
|
| 145 | + and !$options['score'] |
|
| 146 | + and !$options['matches'] |
|
| 147 | + ) { |
|
| 148 | + break; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($vu) { |
|
| 154 | - if (!isset($results)) { |
|
| 155 | - $results = []; |
|
| 156 | - } |
|
| 157 | - $results[$id] = []; |
|
| 158 | - if ($champs_vus) { |
|
| 159 | - $results[$id]['champs'] = $champs_vus; |
|
| 160 | - } |
|
| 161 | - if ($score) { |
|
| 162 | - $results[$id]['score'] = $score; |
|
| 163 | - } |
|
| 164 | - if ($matches) { |
|
| 165 | - $results[$id]['matches'] = $matches; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 153 | + if ($vu) { |
|
| 154 | + if (!isset($results)) { |
|
| 155 | + $results = []; |
|
| 156 | + } |
|
| 157 | + $results[$id] = []; |
|
| 158 | + if ($champs_vus) { |
|
| 159 | + $results[$id]['champs'] = $champs_vus; |
|
| 160 | + } |
|
| 161 | + if ($score) { |
|
| 162 | + $results[$id]['score'] = $score; |
|
| 163 | + } |
|
| 164 | + if ($matches) { |
|
| 165 | + $results[$id]['matches'] = $matches; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - // Gerer les donnees associees |
|
| 173 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | - // on ne sait passer que par table de laison en 1 coup |
|
| 175 | - if ( |
|
| 176 | - isset($jointures[$table]) |
|
| 177 | - and $joints = recherche_en_base( |
|
| 178 | - $recherche, |
|
| 179 | - $jointures[$table], |
|
| 180 | - array_merge($options, ['jointures' => false]) |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - include_spip('action/editer_liens'); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $cle_depart = id_table_objet($table); |
|
| 186 | - $table_depart = table_objet($table, $serveur); |
|
| 187 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | - $depart_associable = objet_associable($table); |
|
| 189 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | - if ( |
|
| 192 | - !( |
|
| 193 | - $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | - or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | - or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | - // cas simple : $cle_depart dans la table_liee |
|
| 202 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | - $s = sql_select( |
|
| 204 | - "$cle_depart, $cle_arrivee", |
|
| 205 | - $desc_arrivee['table_sql'], |
|
| 206 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - '', |
|
| 210 | - '', |
|
| 211 | - $serveur |
|
| 212 | - ); |
|
| 213 | - } // cas simple : $cle_arrivee dans la table |
|
| 214 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | - $s = sql_select( |
|
| 216 | - "$cle_depart, $cle_arrivee", |
|
| 217 | - $desc_depart['table_sql'], |
|
| 218 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - '', |
|
| 223 | - $serveur |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - // sinon cherchons une table de liaison |
|
| 227 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | - elseif ($l = objet_associable($table_liee)) { |
|
| 229 | - [$primary, $table_liens] = $l; |
|
| 230 | - $s = sql_select( |
|
| 231 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | - $table_liens, |
|
| 233 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - $serveur |
|
| 239 | - ); |
|
| 240 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | - elseif ($l = $depart_associable) { |
|
| 242 | - [$primary, $table_liens] = $l; |
|
| 243 | - $s = sql_select( |
|
| 244 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | - $table_liens, |
|
| 246 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | - '', |
|
| 248 | - '', |
|
| 249 | - '', |
|
| 250 | - '', |
|
| 251 | - $serveur |
|
| 252 | - ); |
|
| 253 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | - elseif ( |
|
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | - ) { |
|
| 258 | - $s = sql_select( |
|
| 259 | - "$cle_depart,$cle_arrivee", |
|
| 260 | - $t['table_sql'], |
|
| 261 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | - $table, |
|
| 272 | - $table_liee, |
|
| 273 | - array_keys($ids_trouves), |
|
| 274 | - $serveur |
|
| 275 | - ); |
|
| 276 | - } |
|
| 172 | + // Gerer les donnees associees |
|
| 173 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | + // on ne sait passer que par table de laison en 1 coup |
|
| 175 | + if ( |
|
| 176 | + isset($jointures[$table]) |
|
| 177 | + and $joints = recherche_en_base( |
|
| 178 | + $recherche, |
|
| 179 | + $jointures[$table], |
|
| 180 | + array_merge($options, ['jointures' => false]) |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + include_spip('action/editer_liens'); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $cle_depart = id_table_objet($table); |
|
| 186 | + $table_depart = table_objet($table, $serveur); |
|
| 187 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | + $depart_associable = objet_associable($table); |
|
| 189 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | + if ( |
|
| 192 | + !( |
|
| 193 | + $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | + or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | + or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | + // cas simple : $cle_depart dans la table_liee |
|
| 202 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | + $s = sql_select( |
|
| 204 | + "$cle_depart, $cle_arrivee", |
|
| 205 | + $desc_arrivee['table_sql'], |
|
| 206 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + '', |
|
| 210 | + '', |
|
| 211 | + $serveur |
|
| 212 | + ); |
|
| 213 | + } // cas simple : $cle_arrivee dans la table |
|
| 214 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | + $s = sql_select( |
|
| 216 | + "$cle_depart, $cle_arrivee", |
|
| 217 | + $desc_depart['table_sql'], |
|
| 218 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + '', |
|
| 223 | + $serveur |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + // sinon cherchons une table de liaison |
|
| 227 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | + elseif ($l = objet_associable($table_liee)) { |
|
| 229 | + [$primary, $table_liens] = $l; |
|
| 230 | + $s = sql_select( |
|
| 231 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | + $table_liens, |
|
| 233 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + $serveur |
|
| 239 | + ); |
|
| 240 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | + elseif ($l = $depart_associable) { |
|
| 242 | + [$primary, $table_liens] = $l; |
|
| 243 | + $s = sql_select( |
|
| 244 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | + $table_liens, |
|
| 246 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | + '', |
|
| 248 | + '', |
|
| 249 | + '', |
|
| 250 | + '', |
|
| 251 | + $serveur |
|
| 252 | + ); |
|
| 253 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | + elseif ( |
|
| 255 | + $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | + ) { |
|
| 258 | + $s = sql_select( |
|
| 259 | + "$cle_depart,$cle_arrivee", |
|
| 260 | + $t['table_sql'], |
|
| 261 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | + $table, |
|
| 272 | + $table_liee, |
|
| 273 | + array_keys($ids_trouves), |
|
| 274 | + $serveur |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | - $id = $t[$cle_depart]; |
|
| 280 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | - if (!isset($results)) { |
|
| 282 | - $results = []; |
|
| 283 | - } |
|
| 284 | - if (!isset($results[$id])) { |
|
| 285 | - $results[$id] = []; |
|
| 286 | - } |
|
| 287 | - if (isset($joint['score']) and $joint['score']) { |
|
| 288 | - if (!isset($results[$id]['score'])) { |
|
| 289 | - $results[$id]['score'] = 0; |
|
| 290 | - } |
|
| 291 | - $results[$id]['score'] += $joint['score']; |
|
| 292 | - } |
|
| 293 | - if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | - foreach ($joint['champs'] as $c => $val) { |
|
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | - foreach ($joint['matches'] as $c => $val) { |
|
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 278 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | + $id = $t[$cle_depart]; |
|
| 280 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | + if (!isset($results)) { |
|
| 282 | + $results = []; |
|
| 283 | + } |
|
| 284 | + if (!isset($results[$id])) { |
|
| 285 | + $results[$id] = []; |
|
| 286 | + } |
|
| 287 | + if (isset($joint['score']) and $joint['score']) { |
|
| 288 | + if (!isset($results[$id]['score'])) { |
|
| 289 | + $results[$id]['score'] = 0; |
|
| 290 | + } |
|
| 291 | + $results[$id]['score'] += $joint['score']; |
|
| 292 | + } |
|
| 293 | + if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | + foreach ($joint['champs'] as $c => $val) { |
|
| 295 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | + foreach ($joint['matches'] as $c => $val) { |
|
| 300 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $results; |
|
| 307 | + return $results; |
|
| 308 | 308 | } |
@@ -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/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return ['', '']; |
|
| 37 | + return ['', '']; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * Texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter à part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter à part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string Texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,39 +415,39 @@ discard block |
||
| 415 | 415 | * Texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if (!$t) { |
|
| 431 | - return strval($t); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | - // avant echappement des balises <html> |
|
| 436 | - // https://core.spip.net/issues/3371 |
|
| 437 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | - // https://core.spip.net/issues/4166 |
|
| 439 | - if ( |
|
| 440 | - $interdire_script |
|
| 441 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - ) { |
|
| 445 | - $t = echapper_html_suspect($t, false); |
|
| 446 | - } |
|
| 447 | - $t = echappe_html($t); |
|
| 448 | - $t = expanser_liens($t, $connect, $env); |
|
| 449 | - $t = traiter_raccourcis($t); |
|
| 450 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | - |
|
| 452 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if (!$t) { |
|
| 431 | + return strval($t); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | + // avant echappement des balises <html> |
|
| 436 | + // https://core.spip.net/issues/3371 |
|
| 437 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | + // https://core.spip.net/issues/4166 |
|
| 439 | + if ( |
|
| 440 | + $interdire_script |
|
| 441 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + ) { |
|
| 445 | + $t = echapper_html_suspect($t, false); |
|
| 446 | + } |
|
| 447 | + $t = echappe_html($t); |
|
| 448 | + $t = expanser_liens($t, $connect, $env); |
|
| 449 | + $t = traiter_raccourcis($t); |
|
| 450 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | + |
|
| 452 | + return $t; |
|
| 453 | 453 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Queue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | define('_JQ_SCHEDULED', 1); |
@@ -50,103 +50,103 @@ discard block |
||
| 50 | 50 | * id of job |
| 51 | 51 | */ |
| 52 | 52 | function queue_add_job( |
| 53 | - $function, |
|
| 54 | - $description, |
|
| 55 | - $arguments = [], |
|
| 56 | - $file = '', |
|
| 57 | - $no_duplicate = false, |
|
| 58 | - $time = 0, |
|
| 59 | - $priority = 0 |
|
| 53 | + $function, |
|
| 54 | + $description, |
|
| 55 | + $arguments = [], |
|
| 56 | + $file = '', |
|
| 57 | + $no_duplicate = false, |
|
| 58 | + $time = 0, |
|
| 59 | + $priority = 0 |
|
| 60 | 60 | ) { |
| 61 | - include_spip('base/abstract_sql'); |
|
| 62 | - |
|
| 63 | - // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | - if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | - $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // serialiser les arguments |
|
| 69 | - $arguments = serialize($arguments); |
|
| 70 | - $md5args = md5($arguments); |
|
| 71 | - |
|
| 72 | - // si pas de date programee, des que possible |
|
| 73 | - $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | - if (!$time) { |
|
| 75 | - $time = time(); |
|
| 76 | - $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | - } |
|
| 78 | - $date = date('Y-m-d H:i:s', $time); |
|
| 79 | - |
|
| 80 | - $set_job = [ |
|
| 81 | - 'fonction' => $function, |
|
| 82 | - 'descriptif' => $description, |
|
| 83 | - 'args' => $arguments, |
|
| 84 | - 'md5args' => $md5args, |
|
| 85 | - 'inclure' => $file, |
|
| 86 | - 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | - 'date' => $date, |
|
| 88 | - 'status' => _JQ_SCHEDULED, |
|
| 89 | - ]; |
|
| 90 | - // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | - // avec les memes args et file |
|
| 92 | - if ( |
|
| 93 | - $no_duplicate |
|
| 94 | - and |
|
| 95 | - $id_job = sql_getfetsel( |
|
| 96 | - 'id_job', |
|
| 97 | - 'spip_jobs', |
|
| 98 | - $duplicate_where = |
|
| 99 | - $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | - . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | - ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | - ) |
|
| 103 | - ) { |
|
| 104 | - return $id_job; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | - // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | - // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | - // doit s'effacer |
|
| 111 | - if ( |
|
| 112 | - $no_duplicate |
|
| 113 | - and |
|
| 114 | - $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | - ) { |
|
| 116 | - sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | - |
|
| 118 | - return $id_prev; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | - // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | - |
|
| 124 | - // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | - // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | - // qui coupe la valeur |
|
| 127 | - if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | - $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | - if ($args !== $arguments) { |
|
| 130 | - spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | - $arguments, |
|
| 132 | - true |
|
| 133 | - ), 'queue'); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - if ($id_job) { |
|
| 138 | - queue_update_next_job_time($time); |
|
| 139 | - } |
|
| 140 | - // si la mise en file d'attente du job echoue, |
|
| 141 | - // il ne faut pas perdre l'execution de la fonction |
|
| 142 | - // on la lance immediatement, c'est un fallback |
|
| 143 | - // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | - elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | - $set_job['id_job'] = 0; |
|
| 146 | - queue_start_job($set_job); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - return $id_job; |
|
| 61 | + include_spip('base/abstract_sql'); |
|
| 62 | + |
|
| 63 | + // cas pourri de ecrire/action/editer_site avec l'option reload=oui |
|
| 64 | + if (defined('_GENIE_SYNDIC_NOW')) { |
|
| 65 | + $arguments['id_syndic'] = _GENIE_SYNDIC_NOW; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // serialiser les arguments |
|
| 69 | + $arguments = serialize($arguments); |
|
| 70 | + $md5args = md5($arguments); |
|
| 71 | + |
|
| 72 | + // si pas de date programee, des que possible |
|
| 73 | + $duplicate_where = 'status=' . intval(_JQ_SCHEDULED) . ' AND '; |
|
| 74 | + if (!$time) { |
|
| 75 | + $time = time(); |
|
| 76 | + $duplicate_where = ''; // ne pas dupliquer si deja le meme job en cours d'execution |
|
| 77 | + } |
|
| 78 | + $date = date('Y-m-d H:i:s', $time); |
|
| 79 | + |
|
| 80 | + $set_job = [ |
|
| 81 | + 'fonction' => $function, |
|
| 82 | + 'descriptif' => $description, |
|
| 83 | + 'args' => $arguments, |
|
| 84 | + 'md5args' => $md5args, |
|
| 85 | + 'inclure' => $file, |
|
| 86 | + 'priorite' => max(-10, min(10, intval($priority))), |
|
| 87 | + 'date' => $date, |
|
| 88 | + 'status' => _JQ_SCHEDULED, |
|
| 89 | + ]; |
|
| 90 | + // si option ne pas dupliquer, regarder si la fonction existe deja |
|
| 91 | + // avec les memes args et file |
|
| 92 | + if ( |
|
| 93 | + $no_duplicate |
|
| 94 | + and |
|
| 95 | + $id_job = sql_getfetsel( |
|
| 96 | + 'id_job', |
|
| 97 | + 'spip_jobs', |
|
| 98 | + $duplicate_where = |
|
| 99 | + $duplicate_where . 'fonction=' . sql_quote($function) |
|
| 100 | + . (($no_duplicate === 'function_only') ? '' : |
|
| 101 | + ' AND md5args=' . sql_quote($md5args) . ' AND inclure=' . sql_quote($file)) |
|
| 102 | + ) |
|
| 103 | + ) { |
|
| 104 | + return $id_job; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $id_job = sql_insertq('spip_jobs', $set_job); |
|
| 108 | + // en cas de concurrence, deux process peuvent arriver jusqu'ici en parallele |
|
| 109 | + // avec le meme job unique a inserer. Dans ce cas, celui qui a eu l'id le plus grand |
|
| 110 | + // doit s'effacer |
|
| 111 | + if ( |
|
| 112 | + $no_duplicate |
|
| 113 | + and |
|
| 114 | + $id_prev = sql_getfetsel('id_job', 'spip_jobs', 'id_job<' . intval($id_job) . " AND $duplicate_where") |
|
| 115 | + ) { |
|
| 116 | + sql_delete('spip_jobs', 'id_job=' . intval($id_job)); |
|
| 117 | + |
|
| 118 | + return $id_prev; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // verifier la non duplication qui peut etre problematique en cas de concurence |
|
| 122 | + // il faut dans ce cas que seul le dernier ajoute se supprime ! |
|
| 123 | + |
|
| 124 | + // une option de debug pour verifier que les arguments en base sont bons |
|
| 125 | + // ie cas d'un char non acceptables sur certains type de champs |
|
| 126 | + // qui coupe la valeur |
|
| 127 | + if (defined('_JQ_INSERT_CHECK_ARGS') and $id_job) { |
|
| 128 | + $args = sql_getfetsel('args', 'spip_jobs', 'id_job=' . intval($id_job)); |
|
| 129 | + if ($args !== $arguments) { |
|
| 130 | + spip_log('arguments job errones / longueur ' . strlen($args) . ' vs ' . strlen($arguments) . ' / valeur : ' . var_export( |
|
| 131 | + $arguments, |
|
| 132 | + true |
|
| 133 | + ), 'queue'); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + if ($id_job) { |
|
| 138 | + queue_update_next_job_time($time); |
|
| 139 | + } |
|
| 140 | + // si la mise en file d'attente du job echoue, |
|
| 141 | + // il ne faut pas perdre l'execution de la fonction |
|
| 142 | + // on la lance immediatement, c'est un fallback |
|
| 143 | + // sauf en cas d'upgrade necessaire (table spip_jobs inexistante) |
|
| 144 | + elseif ($GLOBALS['meta']['version_installee'] == $GLOBALS['spip_version_base']) { |
|
| 145 | + $set_job['id_job'] = 0; |
|
| 146 | + queue_start_job($set_job); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + return $id_job; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -155,11 +155,11 @@ discard block |
||
| 155 | 155 | * @return void |
| 156 | 156 | */ |
| 157 | 157 | function queue_purger() { |
| 158 | - include_spip('base/abstract_sql'); |
|
| 159 | - sql_delete('spip_jobs'); |
|
| 160 | - sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | - include_spip('inc/genie'); |
|
| 162 | - genie_queue_watch_dist(); |
|
| 158 | + include_spip('base/abstract_sql'); |
|
| 159 | + sql_delete('spip_jobs'); |
|
| 160 | + sql_delete('spip_jobs_liens', 'id_job NOT IN (' . sql_get_select('id_job', 'spip_jobs') . ')'); |
|
| 161 | + include_spip('inc/genie'); |
|
| 162 | + genie_queue_watch_dist(); |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -170,25 +170,25 @@ discard block |
||
| 170 | 170 | * @return int|bool |
| 171 | 171 | */ |
| 172 | 172 | function queue_remove_job($id_job) { |
| 173 | - include_spip('base/abstract_sql'); |
|
| 174 | - |
|
| 175 | - if ( |
|
| 176 | - $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | - and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | - ) { |
|
| 179 | - queue_unlink_job($id_job); |
|
| 180 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | - // relancer avec les nouveaux arguments de temps |
|
| 183 | - include_spip('inc/genie'); |
|
| 184 | - // relancer avec la periode prevue |
|
| 185 | - queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | - } |
|
| 187 | - queue_update_next_job_time(); |
|
| 188 | - return $res; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 173 | + include_spip('base/abstract_sql'); |
|
| 174 | + |
|
| 175 | + if ( |
|
| 176 | + $row = sql_fetsel('fonction,inclure,date', 'spip_jobs', 'id_job=' . intval($id_job)) |
|
| 177 | + and $res = sql_delete('spip_jobs', 'id_job=' . intval($id_job)) |
|
| 178 | + ) { |
|
| 179 | + queue_unlink_job($id_job); |
|
| 180 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 181 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 182 | + // relancer avec les nouveaux arguments de temps |
|
| 183 | + include_spip('inc/genie'); |
|
| 184 | + // relancer avec la periode prevue |
|
| 185 | + queue_genie_replan_job($row['fonction'], $periode, strtotime($row['date'])); |
|
| 186 | + } |
|
| 187 | + queue_update_next_job_time(); |
|
| 188 | + return $res; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -201,18 +201,18 @@ discard block |
||
| 201 | 201 | * ou un tableau composé de tableaux simples pour lieur plusieurs objets en une fois |
| 202 | 202 | */ |
| 203 | 203 | function queue_link_job($id_job, $objets) { |
| 204 | - include_spip('base/abstract_sql'); |
|
| 205 | - |
|
| 206 | - if (is_array($objets) and count($objets)) { |
|
| 207 | - if (is_array(reset($objets))) { |
|
| 208 | - foreach ($objets as $k => $o) { |
|
| 209 | - $objets[$k]['id_job'] = $id_job; |
|
| 210 | - } |
|
| 211 | - sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | - } else { |
|
| 213 | - sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | - } |
|
| 215 | - } |
|
| 204 | + include_spip('base/abstract_sql'); |
|
| 205 | + |
|
| 206 | + if (is_array($objets) and count($objets)) { |
|
| 207 | + if (is_array(reset($objets))) { |
|
| 208 | + foreach ($objets as $k => $o) { |
|
| 209 | + $objets[$k]['id_job'] = $id_job; |
|
| 210 | + } |
|
| 211 | + sql_insertq_multi('spip_jobs_liens', $objets); |
|
| 212 | + } else { |
|
| 213 | + sql_insertq('spip_jobs_liens', array_merge(['id_job' => $id_job], $objets)); |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | * resultat du sql_delete |
| 225 | 225 | */ |
| 226 | 226 | function queue_unlink_job($id_job) { |
| 227 | - return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 227 | + return sql_delete('spip_jobs_liens', 'id_job=' . intval($id_job)); |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,84 +237,84 @@ discard block |
||
| 237 | 237 | */ |
| 238 | 238 | function queue_start_job($row) { |
| 239 | 239 | |
| 240 | - // deserialiser les arguments |
|
| 241 | - $args = unserialize($row['args']); |
|
| 242 | - if ($args === false) { |
|
| 243 | - spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | - $args = []; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - $fonction = $row['fonction']; |
|
| 248 | - if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | - if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | - $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | - if ($f) { |
|
| 252 | - $fonction = $f; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - include_spip($inclure); |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - if (!function_exists($fonction)) { |
|
| 260 | - spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | - |
|
| 262 | - return false; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | - switch (is_countable($args) ? count($args) : 0) { |
|
| 267 | - case 0: |
|
| 268 | - $res = $fonction(); |
|
| 269 | - break; |
|
| 270 | - case 1: |
|
| 271 | - $res = $fonction($args[0]); |
|
| 272 | - break; |
|
| 273 | - case 2: |
|
| 274 | - $res = $fonction($args[0], $args[1]); |
|
| 275 | - break; |
|
| 276 | - case 3: |
|
| 277 | - $res = $fonction($args[0], $args[1], $args[2]); |
|
| 278 | - break; |
|
| 279 | - case 4: |
|
| 280 | - $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 281 | - break; |
|
| 282 | - case 5: |
|
| 283 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 284 | - break; |
|
| 285 | - case 6: |
|
| 286 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 287 | - break; |
|
| 288 | - case 7: |
|
| 289 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 290 | - break; |
|
| 291 | - case 8: |
|
| 292 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 293 | - break; |
|
| 294 | - case 9: |
|
| 295 | - $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 296 | - break; |
|
| 297 | - case 10: |
|
| 298 | - $res = $fonction( |
|
| 299 | - $args[0], |
|
| 300 | - $args[1], |
|
| 301 | - $args[2], |
|
| 302 | - $args[3], |
|
| 303 | - $args[4], |
|
| 304 | - $args[5], |
|
| 305 | - $args[6], |
|
| 306 | - $args[7], |
|
| 307 | - $args[8], |
|
| 308 | - $args[9] |
|
| 309 | - ); |
|
| 310 | - break; |
|
| 311 | - default: |
|
| 312 | - # plus lent mais completement generique |
|
| 313 | - $res = call_user_func_array($fonction, $args); |
|
| 314 | - } |
|
| 315 | - spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 316 | - |
|
| 317 | - return $res; |
|
| 240 | + // deserialiser les arguments |
|
| 241 | + $args = unserialize($row['args']); |
|
| 242 | + if ($args === false) { |
|
| 243 | + spip_log('arguments job errones ' . var_export($row, true), 'queue'); |
|
| 244 | + $args = []; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + $fonction = $row['fonction']; |
|
| 248 | + if (strlen($inclure = trim($row['inclure']))) { |
|
| 249 | + if (substr($inclure, -1) == '/') { // c'est un chemin pour charger_fonction |
|
| 250 | + $f = charger_fonction($fonction, rtrim($inclure, '/'), false); |
|
| 251 | + if ($f) { |
|
| 252 | + $fonction = $f; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + include_spip($inclure); |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + if (!function_exists($fonction)) { |
|
| 260 | + spip_log("fonction $fonction ($inclure) inexistante " . var_export($row, true), 'queue'); |
|
| 261 | + |
|
| 262 | + return false; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() start", 'queue'); |
|
| 266 | + switch (is_countable($args) ? count($args) : 0) { |
|
| 267 | + case 0: |
|
| 268 | + $res = $fonction(); |
|
| 269 | + break; |
|
| 270 | + case 1: |
|
| 271 | + $res = $fonction($args[0]); |
|
| 272 | + break; |
|
| 273 | + case 2: |
|
| 274 | + $res = $fonction($args[0], $args[1]); |
|
| 275 | + break; |
|
| 276 | + case 3: |
|
| 277 | + $res = $fonction($args[0], $args[1], $args[2]); |
|
| 278 | + break; |
|
| 279 | + case 4: |
|
| 280 | + $res = $fonction($args[0], $args[1], $args[2], $args[3]); |
|
| 281 | + break; |
|
| 282 | + case 5: |
|
| 283 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4]); |
|
| 284 | + break; |
|
| 285 | + case 6: |
|
| 286 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); |
|
| 287 | + break; |
|
| 288 | + case 7: |
|
| 289 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); |
|
| 290 | + break; |
|
| 291 | + case 8: |
|
| 292 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); |
|
| 293 | + break; |
|
| 294 | + case 9: |
|
| 295 | + $res = $fonction($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); |
|
| 296 | + break; |
|
| 297 | + case 10: |
|
| 298 | + $res = $fonction( |
|
| 299 | + $args[0], |
|
| 300 | + $args[1], |
|
| 301 | + $args[2], |
|
| 302 | + $args[3], |
|
| 303 | + $args[4], |
|
| 304 | + $args[5], |
|
| 305 | + $args[6], |
|
| 306 | + $args[7], |
|
| 307 | + $args[8], |
|
| 308 | + $args[9] |
|
| 309 | + ); |
|
| 310 | + break; |
|
| 311 | + default: |
|
| 312 | + # plus lent mais completement generique |
|
| 313 | + $res = call_user_func_array($fonction, $args); |
|
| 314 | + } |
|
| 315 | + spip_log('queue [' . $row['id_job'] . "]: $fonction() end", 'queue'); |
|
| 316 | + |
|
| 317 | + return $res; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | /** |
@@ -341,89 +341,89 @@ discard block |
||
| 341 | 341 | * - true : une planification a été faite. |
| 342 | 342 | */ |
| 343 | 343 | function queue_schedule($force_jobs = null) { |
| 344 | - $time = time(); |
|
| 345 | - if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 346 | - spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 347 | - |
|
| 348 | - return; |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // rien a faire si le prochain job est encore dans le futur |
|
| 352 | - if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 353 | - spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 354 | - |
|
| 355 | - return; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - include_spip('base/abstract_sql'); |
|
| 359 | - // on ne peut rien faire si pas de connexion SQL |
|
| 360 | - if (!spip_connect()) { |
|
| 361 | - return false; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 365 | - $max_time = ini_get('max_execution_time') / 2; |
|
| 366 | - // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 367 | - if (!$max_time) { |
|
| 368 | - $max_time = 5; |
|
| 369 | - } |
|
| 370 | - define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 371 | - } |
|
| 372 | - $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 373 | - |
|
| 374 | - spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 375 | - |
|
| 376 | - if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 377 | - define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 378 | - } |
|
| 379 | - $nbj = 0; |
|
| 380 | - // attraper les jobs |
|
| 381 | - // dont la date est passee (echus en attente), |
|
| 382 | - // par ordre : |
|
| 383 | - // - de priorite |
|
| 384 | - // - de date |
|
| 385 | - // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 386 | - // pour qu'il ne bloque pas les autres jobs en attente |
|
| 387 | - if (is_array($force_jobs) and count($force_jobs)) { |
|
| 388 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 389 | - } else { |
|
| 390 | - $now = date('Y-m-d H:i:s', $time); |
|
| 391 | - $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 395 | - $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 396 | - do { |
|
| 397 | - if ($row = array_shift($res)) { |
|
| 398 | - $nbj++; |
|
| 399 | - // il faut un verrou, a base de sql_delete |
|
| 400 | - if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 401 | - #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 402 | - // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 403 | - $row['status'] = _JQ_PENDING; |
|
| 404 | - $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 405 | - sql_insertq('spip_jobs', $row); |
|
| 406 | - |
|
| 407 | - // on a la main sur le job : |
|
| 408 | - // l'executer |
|
| 409 | - $result = queue_start_job($row); |
|
| 410 | - |
|
| 411 | - $time = time(); |
|
| 412 | - queue_close_job($row, $time, $result); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 416 | - } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 417 | - spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 418 | - |
|
| 419 | - if ($row = array_shift($res)) { |
|
| 420 | - queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 421 | - spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 422 | - } else { |
|
| 423 | - queue_update_next_job_time(); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - return true; |
|
| 344 | + $time = time(); |
|
| 345 | + if (defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 346 | + spip_log('_DEBUG_BLOCK_QUEUE : schedule stop', 'jq' . _LOG_DEBUG); |
|
| 347 | + |
|
| 348 | + return; |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // rien a faire si le prochain job est encore dans le futur |
|
| 352 | + if (queue_sleep_time_to_next_job() > 0 and (!$force_jobs or !count($force_jobs))) { |
|
| 353 | + spip_log('queue_sleep_time_to_next_job', 'jq' . _LOG_DEBUG); |
|
| 354 | + |
|
| 355 | + return; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + include_spip('base/abstract_sql'); |
|
| 359 | + // on ne peut rien faire si pas de connexion SQL |
|
| 360 | + if (!spip_connect()) { |
|
| 361 | + return false; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!defined('_JQ_MAX_JOBS_TIME_TO_EXECUTE')) { |
|
| 365 | + $max_time = ini_get('max_execution_time') / 2; |
|
| 366 | + // valeur conservatrice si on a pas reussi a lire le max_execution_time |
|
| 367 | + if (!$max_time) { |
|
| 368 | + $max_time = 5; |
|
| 369 | + } |
|
| 370 | + define('_JQ_MAX_JOBS_TIME_TO_EXECUTE', min($max_time, 15)); // une valeur maxi en temps. |
|
| 371 | + } |
|
| 372 | + $end_time = $time + _JQ_MAX_JOBS_TIME_TO_EXECUTE; |
|
| 373 | + |
|
| 374 | + spip_log("JQ schedule $time / $end_time", 'jq' . _LOG_DEBUG); |
|
| 375 | + |
|
| 376 | + if (!defined('_JQ_MAX_JOBS_EXECUTE')) { |
|
| 377 | + define('_JQ_MAX_JOBS_EXECUTE', 200); |
|
| 378 | + } |
|
| 379 | + $nbj = 0; |
|
| 380 | + // attraper les jobs |
|
| 381 | + // dont la date est passee (echus en attente), |
|
| 382 | + // par ordre : |
|
| 383 | + // - de priorite |
|
| 384 | + // - de date |
|
| 385 | + // lorsqu'un job cron n'a pas fini, sa priorite est descendue |
|
| 386 | + // pour qu'il ne bloque pas les autres jobs en attente |
|
| 387 | + if (is_array($force_jobs) and count($force_jobs)) { |
|
| 388 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND ' . sql_in('id_job', $force_jobs); |
|
| 389 | + } else { |
|
| 390 | + $now = date('Y-m-d H:i:s', $time); |
|
| 391 | + $cond = 'status=' . intval(_JQ_SCHEDULED) . ' AND date<=' . sql_quote($now); |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + register_shutdown_function('queue_error_handler'); // recuperer les erreurs auant que possible |
|
| 395 | + $res = sql_allfetsel('*', 'spip_jobs', $cond, '', 'priorite DESC,date', '0,' . (_JQ_MAX_JOBS_EXECUTE + 1)); |
|
| 396 | + do { |
|
| 397 | + if ($row = array_shift($res)) { |
|
| 398 | + $nbj++; |
|
| 399 | + // il faut un verrou, a base de sql_delete |
|
| 400 | + if (sql_delete('spip_jobs', 'id_job=' . intval($row['id_job']) . ' AND status=' . intval(_JQ_SCHEDULED))) { |
|
| 401 | + #spip_log("JQ schedule job ".$nbj." OK",'jq'); |
|
| 402 | + // on reinsert dans la base aussitot avec un status=_JQ_PENDING |
|
| 403 | + $row['status'] = _JQ_PENDING; |
|
| 404 | + $row['date'] = date('Y-m-d H:i:s', $time); |
|
| 405 | + sql_insertq('spip_jobs', $row); |
|
| 406 | + |
|
| 407 | + // on a la main sur le job : |
|
| 408 | + // l'executer |
|
| 409 | + $result = queue_start_job($row); |
|
| 410 | + |
|
| 411 | + $time = time(); |
|
| 412 | + queue_close_job($row, $time, $result); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + spip_log('JQ schedule job end time ' . $time, 'jq' . _LOG_DEBUG); |
|
| 416 | + } while ($nbj < _JQ_MAX_JOBS_EXECUTE and $row and $time < $end_time); |
|
| 417 | + spip_log('JQ schedule end time ' . time(), 'jq' . _LOG_DEBUG); |
|
| 418 | + |
|
| 419 | + if ($row = array_shift($res)) { |
|
| 420 | + queue_update_next_job_time(0); // on sait qu'il y a encore des jobs a lancer ASAP |
|
| 421 | + spip_log('JQ encore !', 'jq' . _LOG_DEBUG); |
|
| 422 | + } else { |
|
| 423 | + queue_update_next_job_time(); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + return true; |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | /** |
@@ -441,21 +441,21 @@ discard block |
||
| 441 | 441 | * @param int $result |
| 442 | 442 | */ |
| 443 | 443 | function queue_close_job(&$row, $time, $result = 0) { |
| 444 | - // est-ce une tache cron qu'il faut relancer ? |
|
| 445 | - if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 446 | - // relancer avec les nouveaux arguments de temps |
|
| 447 | - include_spip('inc/genie'); |
|
| 448 | - if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 449 | - queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 450 | - } else // relancer avec la periode prevue |
|
| 451 | - { |
|
| 452 | - queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - // purger ses liens eventuels avec des objets |
|
| 456 | - sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 457 | - // supprimer le job fini |
|
| 458 | - sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 444 | + // est-ce une tache cron qu'il faut relancer ? |
|
| 445 | + if ($periode = queue_is_cron_job($row['fonction'], $row['inclure'])) { |
|
| 446 | + // relancer avec les nouveaux arguments de temps |
|
| 447 | + include_spip('inc/genie'); |
|
| 448 | + if ($result < 0) { // relancer tout de suite, mais en baissant la priorite |
|
| 449 | + queue_genie_replan_job($row['fonction'], $periode, 0 - $result, null, $row['priorite'] - 1); |
|
| 450 | + } else // relancer avec la periode prevue |
|
| 451 | + { |
|
| 452 | + queue_genie_replan_job($row['fonction'], $periode, $time); |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + // purger ses liens eventuels avec des objets |
|
| 456 | + sql_delete('spip_jobs_liens', 'id_job=' . intval($row['id_job'])); |
|
| 457 | + // supprimer le job fini |
|
| 458 | + sql_delete('spip_jobs', 'id_job=' . intval($row['id_job'])); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,10 +465,10 @@ discard block |
||
| 465 | 465 | * @uses queue_update_next_job_time() |
| 466 | 466 | */ |
| 467 | 467 | function queue_error_handler() { |
| 468 | - // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 469 | - chdir(_ROOT_CWD); |
|
| 468 | + // se remettre dans le bon dossier, car Apache le change parfois (toujours?) |
|
| 469 | + chdir(_ROOT_CWD); |
|
| 470 | 470 | |
| 471 | - queue_update_next_job_time(); |
|
| 471 | + queue_update_next_job_time(); |
|
| 472 | 472 | } |
| 473 | 473 | |
| 474 | 474 | |
@@ -485,18 +485,18 @@ discard block |
||
| 485 | 485 | * Périodicité de la tâche en secondes, si tâche périodique, sinon false. |
| 486 | 486 | */ |
| 487 | 487 | function queue_is_cron_job($function, $inclure) { |
| 488 | - static $taches = null; |
|
| 489 | - if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 490 | - if (is_null($taches)) { |
|
| 491 | - include_spip('inc/genie'); |
|
| 492 | - $taches = taches_generales(); |
|
| 493 | - } |
|
| 494 | - if (isset($taches[$function])) { |
|
| 495 | - return $taches[$function]; |
|
| 496 | - } |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - return false; |
|
| 488 | + static $taches = null; |
|
| 489 | + if (strncmp($inclure, 'genie/', 6) == 0) { |
|
| 490 | + if (is_null($taches)) { |
|
| 491 | + include_spip('inc/genie'); |
|
| 492 | + $taches = taches_generales(); |
|
| 493 | + } |
|
| 494 | + if (isset($taches[$function])) { |
|
| 495 | + return $taches[$function]; |
|
| 496 | + } |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + return false; |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -510,62 +510,62 @@ discard block |
||
| 510 | 510 | * temps de la tache ajoutee ou 0 pour ASAP |
| 511 | 511 | */ |
| 512 | 512 | function queue_update_next_job_time($next_time = null) { |
| 513 | - static $nb_jobs_scheduled = null; |
|
| 514 | - static $deja_la = false; |
|
| 515 | - // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 516 | - static $next = null; |
|
| 517 | - // queue_close_job peut etre reentrant ici |
|
| 518 | - if ($deja_la) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - $deja_la = true; |
|
| 522 | - |
|
| 523 | - include_spip('base/abstract_sql'); |
|
| 524 | - $time = time(); |
|
| 525 | - |
|
| 526 | - // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 527 | - // pour cause de timeout ou autre erreur fatale |
|
| 528 | - $res = sql_allfetsel( |
|
| 529 | - '*', |
|
| 530 | - 'spip_jobs', |
|
| 531 | - 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 532 | - ); |
|
| 533 | - if (is_array($res)) { |
|
| 534 | - foreach ($res as $row) { |
|
| 535 | - queue_close_job($row, $time); |
|
| 536 | - spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // chercher la date du prochain job si pas connu |
|
| 541 | - if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 542 | - $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 543 | - $next = strtotime($date); |
|
| 544 | - } |
|
| 545 | - if (!is_null($next_time)) { |
|
| 546 | - if (is_null($next) or $next > $next_time) { |
|
| 547 | - $next = $next_time; |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - |
|
| 551 | - if ($next) { |
|
| 552 | - if (is_null($nb_jobs_scheduled)) { |
|
| 553 | - $nb_jobs_scheduled = sql_countsel( |
|
| 554 | - 'spip_jobs', |
|
| 555 | - 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 556 | - ); |
|
| 557 | - } elseif ($next <= $time) { |
|
| 558 | - $nb_jobs_scheduled++; |
|
| 559 | - } |
|
| 560 | - // si trop de jobs en attente, on force la purge en fin de hit |
|
| 561 | - // pour assurer le coup |
|
| 562 | - if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 563 | - define('_DIRECT_CRON_FORCE', true); |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - queue_set_next_job_time($next); |
|
| 568 | - $deja_la = false; |
|
| 513 | + static $nb_jobs_scheduled = null; |
|
| 514 | + static $deja_la = false; |
|
| 515 | + // prendre le min des $next_time que l'on voit passer ici, en cas de reentrance |
|
| 516 | + static $next = null; |
|
| 517 | + // queue_close_job peut etre reentrant ici |
|
| 518 | + if ($deja_la) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + $deja_la = true; |
|
| 522 | + |
|
| 523 | + include_spip('base/abstract_sql'); |
|
| 524 | + $time = time(); |
|
| 525 | + |
|
| 526 | + // traiter les jobs morts au combat (_JQ_PENDING depuis plus de 180s) |
|
| 527 | + // pour cause de timeout ou autre erreur fatale |
|
| 528 | + $res = sql_allfetsel( |
|
| 529 | + '*', |
|
| 530 | + 'spip_jobs', |
|
| 531 | + 'status=' . intval(_JQ_PENDING) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time - 180)) |
|
| 532 | + ); |
|
| 533 | + if (is_array($res)) { |
|
| 534 | + foreach ($res as $row) { |
|
| 535 | + queue_close_job($row, $time); |
|
| 536 | + spip_log('queue_close_job car _JQ_PENDING depuis +180s : ' . print_r($row, 1), 'job_mort' . _LOG_ERREUR); |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // chercher la date du prochain job si pas connu |
|
| 541 | + if (is_null($next) or is_null(queue_sleep_time_to_next_job())) { |
|
| 542 | + $date = sql_getfetsel('date', 'spip_jobs', 'status=' . intval(_JQ_SCHEDULED), '', 'date', '0,1'); |
|
| 543 | + $next = strtotime($date); |
|
| 544 | + } |
|
| 545 | + if (!is_null($next_time)) { |
|
| 546 | + if (is_null($next) or $next > $next_time) { |
|
| 547 | + $next = $next_time; |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + |
|
| 551 | + if ($next) { |
|
| 552 | + if (is_null($nb_jobs_scheduled)) { |
|
| 553 | + $nb_jobs_scheduled = sql_countsel( |
|
| 554 | + 'spip_jobs', |
|
| 555 | + 'status=' . intval(_JQ_SCHEDULED) . ' AND date<' . sql_quote(date('Y-m-d H:i:s', $time)) |
|
| 556 | + ); |
|
| 557 | + } elseif ($next <= $time) { |
|
| 558 | + $nb_jobs_scheduled++; |
|
| 559 | + } |
|
| 560 | + // si trop de jobs en attente, on force la purge en fin de hit |
|
| 561 | + // pour assurer le coup |
|
| 562 | + if ($nb_jobs_scheduled > (defined('_JQ_NB_JOBS_OVERFLOW') ? _JQ_NB_JOBS_OVERFLOW : 10000)) { |
|
| 563 | + define('_DIRECT_CRON_FORCE', true); |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + queue_set_next_job_time($next); |
|
| 568 | + $deja_la = false; |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -576,26 +576,26 @@ discard block |
||
| 576 | 576 | */ |
| 577 | 577 | function queue_set_next_job_time($next) { |
| 578 | 578 | |
| 579 | - // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 580 | - $time = time(); |
|
| 581 | - |
|
| 582 | - // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 583 | - // et ne mettre a jour que si il y a un interet a le faire |
|
| 584 | - // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 585 | - $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 586 | - if ( |
|
| 587 | - ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 588 | - or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 589 | - ) { |
|
| 590 | - if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 591 | - cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 592 | - } else { |
|
| 593 | - ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 594 | - } |
|
| 595 | - queue_sleep_time_to_next_job($next); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - return queue_sleep_time_to_next_job(); |
|
| 579 | + // utiliser le temps courant reel plutot que temps de la requete ici |
|
| 580 | + $time = time(); |
|
| 581 | + |
|
| 582 | + // toujours relire la valeur pour comparer, pour tenir compte des maj concourrantes |
|
| 583 | + // et ne mettre a jour que si il y a un interet a le faire |
|
| 584 | + // permet ausis d'initialiser le nom de fichier a coup sur |
|
| 585 | + $curr_next = $_SERVER['REQUEST_TIME'] + max(0, queue_sleep_time_to_next_job(true)); |
|
| 586 | + if ( |
|
| 587 | + ($curr_next <= $time and $next > $time) // le prochain job est dans le futur mais pas la date planifiee actuelle |
|
| 588 | + or $curr_next > $next // le prochain job est plus tot que la date planifiee actuelle |
|
| 589 | + ) { |
|
| 590 | + if (function_exists('cache_set') and defined('_MEMOIZE_MEMORY') and _MEMOIZE_MEMORY) { |
|
| 591 | + cache_set(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 592 | + } else { |
|
| 593 | + ecrire_fichier(_JQ_NEXT_JOB_TIME_FILENAME, intval($next)); |
|
| 594 | + } |
|
| 595 | + queue_sleep_time_to_next_job($next); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + return queue_sleep_time_to_next_job(); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | /** |
@@ -612,60 +612,60 @@ discard block |
||
| 612 | 612 | * @return string |
| 613 | 613 | */ |
| 614 | 614 | function queue_affichage_cron() { |
| 615 | - $texte = ''; |
|
| 616 | - |
|
| 617 | - $time_to_next = queue_sleep_time_to_next_job(); |
|
| 618 | - // rien a faire si le prochain job est encore dans le futur |
|
| 619 | - if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 620 | - return $texte; |
|
| 621 | - } |
|
| 622 | - |
|
| 623 | - // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 624 | - if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 625 | - return $texte; |
|
| 626 | - } |
|
| 627 | - |
|
| 628 | - @touch($lock); |
|
| 629 | - |
|
| 630 | - // il y a des taches en attentes |
|
| 631 | - // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 632 | - // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 633 | - $urgent = false; |
|
| 634 | - if ($time_to_next < -300) { |
|
| 635 | - $urgent = true; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - $url_cron = generer_url_action('cron', '', false, true); |
|
| 639 | - |
|
| 640 | - if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 641 | - if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 642 | - return $texte; |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - // si deja force, on retourne sans rien |
|
| 647 | - if (defined('_DIRECT_CRON_FORCE')) { |
|
| 648 | - return $texte; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // si c'est un bot |
|
| 652 | - // inutile de faire un appel par image background, |
|
| 653 | - // on force un appel direct en fin de hit |
|
| 654 | - if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 655 | - define('_DIRECT_CRON_FORCE', true); |
|
| 656 | - |
|
| 657 | - return $texte; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 661 | - // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 662 | - $url_cron = generer_url_action('cron'); |
|
| 663 | - $texte = '<!-- SPIP-CRON -->' |
|
| 664 | - . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 665 | - . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 666 | - } |
|
| 667 | - |
|
| 668 | - return $texte; |
|
| 615 | + $texte = ''; |
|
| 616 | + |
|
| 617 | + $time_to_next = queue_sleep_time_to_next_job(); |
|
| 618 | + // rien a faire si le prochain job est encore dans le futur |
|
| 619 | + if ($time_to_next > 0 or defined('_DEBUG_BLOCK_QUEUE')) { |
|
| 620 | + return $texte; |
|
| 621 | + } |
|
| 622 | + |
|
| 623 | + // ne pas relancer si on vient de lancer dans la meme seconde par un hit concurent |
|
| 624 | + if (file_exists($lock = _DIR_TMP . 'cron.lock') and !(@filemtime($lock) < $_SERVER['REQUEST_TIME'])) { |
|
| 625 | + return $texte; |
|
| 626 | + } |
|
| 627 | + |
|
| 628 | + @touch($lock); |
|
| 629 | + |
|
| 630 | + // il y a des taches en attentes |
|
| 631 | + // si depuis plus de 5min, on essaye de lancer le cron par tous les moyens pour rattraper le coup |
|
| 632 | + // on est sans doute sur un site qui n'autorise pas http sortant ou avec peu de trafic |
|
| 633 | + $urgent = false; |
|
| 634 | + if ($time_to_next < -300) { |
|
| 635 | + $urgent = true; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + $url_cron = generer_url_action('cron', '', false, true); |
|
| 639 | + |
|
| 640 | + if (!defined('_HTML_BG_CRON_FORCE') or !_HTML_BG_CRON_FORCE) { |
|
| 641 | + if (queue_lancer_url_http_async($url_cron) and !$urgent) { |
|
| 642 | + return $texte; |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + // si deja force, on retourne sans rien |
|
| 647 | + if (defined('_DIRECT_CRON_FORCE')) { |
|
| 648 | + return $texte; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // si c'est un bot |
|
| 652 | + // inutile de faire un appel par image background, |
|
| 653 | + // on force un appel direct en fin de hit |
|
| 654 | + if ((defined('_IS_BOT') and _IS_BOT)) { |
|
| 655 | + define('_DIRECT_CRON_FORCE', true); |
|
| 656 | + |
|
| 657 | + return $texte; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + if (!defined('_HTML_BG_CRON_INHIB') or !_HTML_BG_CRON_INHIB) { |
|
| 661 | + // en derniere solution, on insere un appel xhr non bloquant ou une image background dans la page si pas de JS |
|
| 662 | + $url_cron = generer_url_action('cron'); |
|
| 663 | + $texte = '<!-- SPIP-CRON -->' |
|
| 664 | + . "<script>setTimeout(function(){var xo = new XMLHttpRequest();xo.open('GET', '$url_cron', true);xo.send('');},100);</script>" |
|
| 665 | + . "<noscript><div style=\"background-image: url('$url_cron');\"></div></noscript>"; |
|
| 666 | + } |
|
| 667 | + |
|
| 668 | + return $texte; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -674,73 +674,73 @@ discard block |
||
| 674 | 674 | * @return bool : true si l'url a pu être appelée en asynchrone, false sinon |
| 675 | 675 | */ |
| 676 | 676 | function queue_lancer_url_http_async($url_cron) { |
| 677 | - // methode la plus rapide : |
|
| 678 | - // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 679 | - // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 680 | - // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 681 | - // mais on renvoie false direct |
|
| 682 | - if (function_exists('fsockopen')) { |
|
| 683 | - $parts = parse_url($url_cron); |
|
| 684 | - |
|
| 685 | - switch ($parts['scheme']) { |
|
| 686 | - case 'https': |
|
| 687 | - $scheme = 'ssl://'; |
|
| 688 | - $port = 443; |
|
| 689 | - break; |
|
| 690 | - case 'http': |
|
| 691 | - default: |
|
| 692 | - $scheme = ''; |
|
| 693 | - $port = 80; |
|
| 694 | - } |
|
| 695 | - $fp = @fsockopen( |
|
| 696 | - $scheme . $parts['host'], |
|
| 697 | - $parts['port'] ?? $port, |
|
| 698 | - $errno, |
|
| 699 | - $errstr, |
|
| 700 | - 1 |
|
| 701 | - ); |
|
| 702 | - |
|
| 703 | - if ($fp) { |
|
| 704 | - $host_sent = $parts['host']; |
|
| 705 | - if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 706 | - $host_sent .= ':' . $parts['port']; |
|
| 707 | - } |
|
| 708 | - $timeout = 200; // ms |
|
| 709 | - stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 710 | - $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 711 | - $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 712 | - $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 713 | - $out .= "Connection: Close\r\n\r\n"; |
|
| 714 | - fwrite($fp, $out); |
|
| 715 | - spip_timer('read'); |
|
| 716 | - $t = 0; |
|
| 717 | - // on lit la reponse si possible pour fermer proprement la connexion |
|
| 718 | - // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 719 | - while (!feof($fp) and $t < $timeout) { |
|
| 720 | - @fgets($fp, 1024); |
|
| 721 | - $t += spip_timer('read', true); |
|
| 722 | - spip_timer('read'); |
|
| 723 | - } |
|
| 724 | - fclose($fp); |
|
| 725 | - return true; |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - // si fsockopen n'est pas dispo on essaye cURL : |
|
| 729 | - // lancer le cron par un cURL asynchrone si cURL est present |
|
| 730 | - elseif (function_exists('curl_init')) { |
|
| 731 | - //setting the curl parameters. |
|
| 732 | - $ch = curl_init($url_cron); |
|
| 733 | - curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 734 | - // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 735 | - curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 736 | - // valeur mini pour que la requete soit lancee |
|
| 737 | - curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 738 | - // lancer |
|
| 739 | - curl_exec($ch); |
|
| 740 | - // fermer |
|
| 741 | - curl_close($ch); |
|
| 742 | - return true; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return false; |
|
| 677 | + // methode la plus rapide : |
|
| 678 | + // Si fsockopen est possible, on lance le cron via un socket en asynchrone |
|
| 679 | + // si fsockopen echoue (disponibilite serveur, firewall) on essaye pas cURL |
|
| 680 | + // car on a toutes les chances d'echouer pareil mais sans moyen de le savoir |
|
| 681 | + // mais on renvoie false direct |
|
| 682 | + if (function_exists('fsockopen')) { |
|
| 683 | + $parts = parse_url($url_cron); |
|
| 684 | + |
|
| 685 | + switch ($parts['scheme']) { |
|
| 686 | + case 'https': |
|
| 687 | + $scheme = 'ssl://'; |
|
| 688 | + $port = 443; |
|
| 689 | + break; |
|
| 690 | + case 'http': |
|
| 691 | + default: |
|
| 692 | + $scheme = ''; |
|
| 693 | + $port = 80; |
|
| 694 | + } |
|
| 695 | + $fp = @fsockopen( |
|
| 696 | + $scheme . $parts['host'], |
|
| 697 | + $parts['port'] ?? $port, |
|
| 698 | + $errno, |
|
| 699 | + $errstr, |
|
| 700 | + 1 |
|
| 701 | + ); |
|
| 702 | + |
|
| 703 | + if ($fp) { |
|
| 704 | + $host_sent = $parts['host']; |
|
| 705 | + if (isset($parts['port']) and $parts['port'] !== $port) { |
|
| 706 | + $host_sent .= ':' . $parts['port']; |
|
| 707 | + } |
|
| 708 | + $timeout = 200; // ms |
|
| 709 | + stream_set_timeout($fp, 0, $timeout * 1000); |
|
| 710 | + $query = $parts['path'] . ($parts['query'] ? '?' . $parts['query'] : ''); |
|
| 711 | + $out = 'GET ' . $query . " HTTP/1.1\r\n"; |
|
| 712 | + $out .= 'Host: ' . $host_sent . "\r\n"; |
|
| 713 | + $out .= "Connection: Close\r\n\r\n"; |
|
| 714 | + fwrite($fp, $out); |
|
| 715 | + spip_timer('read'); |
|
| 716 | + $t = 0; |
|
| 717 | + // on lit la reponse si possible pour fermer proprement la connexion |
|
| 718 | + // avec un timeout total de 200ms pour ne pas se bloquer |
|
| 719 | + while (!feof($fp) and $t < $timeout) { |
|
| 720 | + @fgets($fp, 1024); |
|
| 721 | + $t += spip_timer('read', true); |
|
| 722 | + spip_timer('read'); |
|
| 723 | + } |
|
| 724 | + fclose($fp); |
|
| 725 | + return true; |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + // si fsockopen n'est pas dispo on essaye cURL : |
|
| 729 | + // lancer le cron par un cURL asynchrone si cURL est present |
|
| 730 | + elseif (function_exists('curl_init')) { |
|
| 731 | + //setting the curl parameters. |
|
| 732 | + $ch = curl_init($url_cron); |
|
| 733 | + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
|
| 734 | + // cf bug : http://www.php.net/manual/en/function.curl-setopt.php#104597 |
|
| 735 | + curl_setopt($ch, CURLOPT_NOSIGNAL, 1); |
|
| 736 | + // valeur mini pour que la requete soit lancee |
|
| 737 | + curl_setopt($ch, CURLOPT_TIMEOUT_MS, 200); |
|
| 738 | + // lancer |
|
| 739 | + curl_exec($ch); |
|
| 740 | + // fermer |
|
| 741 | + curl_close($ch); |
|
| 742 | + return true; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return false; |
|
| 746 | 746 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | /** |
@@ -43,22 +43,22 @@ discard block |
||
| 43 | 43 | * Pile complétée par le code à générer |
| 44 | 44 | */ |
| 45 | 45 | function balise_ALERTE_MESSAGE_dist($p) { |
| 46 | - $_texte = interprete_argument_balise(1, $p); |
|
| 47 | - $_titre = interprete_argument_balise(2, $p); |
|
| 48 | - $_class = interprete_argument_balise(3, $p); |
|
| 49 | - $_role = interprete_argument_balise(4, $p); |
|
| 50 | - $_id = interprete_argument_balise(5, $p); |
|
| 51 | - $_texte = ($_texte ?: "''"); |
|
| 52 | - $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 46 | + $_texte = interprete_argument_balise(1, $p); |
|
| 47 | + $_titre = interprete_argument_balise(2, $p); |
|
| 48 | + $_class = interprete_argument_balise(3, $p); |
|
| 49 | + $_role = interprete_argument_balise(4, $p); |
|
| 50 | + $_id = interprete_argument_balise(5, $p); |
|
| 51 | + $_texte = ($_texte ?: "''"); |
|
| 52 | + $_titre = ($_titre ? ", $_titre" : ', null'); |
|
| 53 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 54 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 55 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 56 | 56 | |
| 57 | - $f = chercher_filtre('message_alerte'); |
|
| 58 | - $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | - $p->interdire_scripts = false; |
|
| 57 | + $f = chercher_filtre('message_alerte'); |
|
| 58 | + $p->code = "$f($_texte$_titre$_class$_role$_id)"; |
|
| 59 | + $p->interdire_scripts = false; |
|
| 60 | 60 | |
| 61 | - return $p; |
|
| 61 | + return $p; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -86,20 +86,20 @@ discard block |
||
| 86 | 86 | * Pile complétée par le code à générer |
| 87 | 87 | */ |
| 88 | 88 | function balise_ALERTE_OUVRIR_dist($p) { |
| 89 | - $_titre = interprete_argument_balise(1, $p); |
|
| 90 | - $_class = interprete_argument_balise(2, $p); |
|
| 91 | - $_role = interprete_argument_balise(3, $p); |
|
| 92 | - $_id = interprete_argument_balise(4, $p); |
|
| 93 | - $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | - $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | - $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | - $_id = ($_id ? ", $_id" : ', null'); |
|
| 89 | + $_titre = interprete_argument_balise(1, $p); |
|
| 90 | + $_class = interprete_argument_balise(2, $p); |
|
| 91 | + $_role = interprete_argument_balise(3, $p); |
|
| 92 | + $_id = interprete_argument_balise(4, $p); |
|
| 93 | + $_titre = ($_titre ? "$_titre" : 'null'); |
|
| 94 | + $_class = ($_class ? ", $_class" : ', null'); |
|
| 95 | + $_role = ($_role ? ", $_role" : ', null'); |
|
| 96 | + $_id = ($_id ? ", $_id" : ', null'); |
|
| 97 | 97 | |
| 98 | - $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | - $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | - $p->interdire_scripts = false; |
|
| 98 | + $f = chercher_filtre('message_alerte_ouvrir'); |
|
| 99 | + $p->code = "$f($_titre$_class$_role$_id)"; |
|
| 100 | + $p->interdire_scripts = false; |
|
| 101 | 101 | |
| 102 | - return $p; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -121,11 +121,11 @@ discard block |
||
| 121 | 121 | * Pile complétée par le code à générer |
| 122 | 122 | */ |
| 123 | 123 | function balise_ALERTE_FERMER_dist($p) { |
| 124 | - $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | - $p->code = "$f()"; |
|
| 126 | - $p->interdire_scripts = false; |
|
| 124 | + $f = chercher_filtre('message_alerte_fermer'); |
|
| 125 | + $p->code = "$f()"; |
|
| 126 | + $p->interdire_scripts = false; |
|
| 127 | 127 | |
| 128 | - return $p; |
|
| 128 | + return $p; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -160,14 +160,14 @@ discard block |
||
| 160 | 160 | */ |
| 161 | 161 | function message_alerte(string $texte, ?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 162 | 162 | |
| 163 | - $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | - $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | - $message = |
|
| 166 | - $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | - $texte . |
|
| 168 | - $message_alerte_fermer(); |
|
| 163 | + $message_alerte_ouvrir = chercher_filtre('message_alerte_ouvrir'); |
|
| 164 | + $message_alerte_fermer = chercher_filtre('message_alerte_fermer'); |
|
| 165 | + $message = |
|
| 166 | + $message_alerte_ouvrir($titre, $class, $role, $id) . |
|
| 167 | + $texte . |
|
| 168 | + $message_alerte_fermer(); |
|
| 169 | 169 | |
| 170 | - return $message; |
|
| 170 | + return $message; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -198,55 +198,55 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | function message_alerte_ouvrir(?string $titre = null, ?string $class = null, ?string $role = null, ?string $id = null): string { |
| 200 | 200 | |
| 201 | - $prive = test_espace_prive(); |
|
| 201 | + $prive = test_espace_prive(); |
|
| 202 | 202 | |
| 203 | - // Valeurs par défaut |
|
| 204 | - $role ??= 'alert'; // fallback uniquement si null |
|
| 205 | - $class ??= 'notice'; // fallback uniquement si null |
|
| 203 | + // Valeurs par défaut |
|
| 204 | + $role ??= 'alert'; // fallback uniquement si null |
|
| 205 | + $class ??= 'notice'; // fallback uniquement si null |
|
| 206 | 206 | |
| 207 | - // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | - $types = [ |
|
| 209 | - 'notice', |
|
| 210 | - 'error', |
|
| 211 | - 'success', |
|
| 212 | - 'info', |
|
| 213 | - ]; |
|
| 214 | - $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | - $type = reset($type); |
|
| 216 | - $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 207 | + // Type d'alerte : le chercher dans les classes, nettoyer celles-ci, puis le réinjecter |
|
| 208 | + $types = [ |
|
| 209 | + 'notice', |
|
| 210 | + 'error', |
|
| 211 | + 'success', |
|
| 212 | + 'info', |
|
| 213 | + ]; |
|
| 214 | + $type = array_intersect(explode(' ', $class), $types); |
|
| 215 | + $type = reset($type); |
|
| 216 | + $class = trim(str_replace($types, '', $class) . " $type"); |
|
| 217 | 217 | |
| 218 | - // Classes |
|
| 219 | - $class_racine = 'msg-alert'; |
|
| 220 | - $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | - $class_alerte = "$class_racine $class"; |
|
| 222 | - $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | - $class_titre = "${class_racine}__heading"; |
|
| 218 | + // Classes |
|
| 219 | + $class_racine = 'msg-alert'; |
|
| 220 | + $clearfix = ($prive ? 'clearfix' : ''); |
|
| 221 | + $class_alerte = "$class_racine $class"; |
|
| 222 | + $class_texte = "${class_racine}__text $clearfix"; |
|
| 223 | + $class_titre = "${class_racine}__heading"; |
|
| 224 | 224 | |
| 225 | - // Titre : markup |
|
| 226 | - $titre = trim($titre); |
|
| 227 | - if (strlen($titre)) { |
|
| 228 | - include_spip('inc/filtres'); |
|
| 229 | - // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | - $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | - $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | - if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | - $titre = wrap($titre, $wrap_tag); |
|
| 234 | - } |
|
| 235 | - // puis on ajoute la classe |
|
| 236 | - $titre = ajouter_class($titre, $class_titre); |
|
| 237 | - } |
|
| 225 | + // Titre : markup |
|
| 226 | + $titre = trim($titre); |
|
| 227 | + if (strlen($titre)) { |
|
| 228 | + include_spip('inc/filtres'); |
|
| 229 | + // Si besoin on encapsule le titre : un h3 dans le privé, un simple div sinon. |
|
| 230 | + $cherche_tag = ($prive ? '<h' : '<'); |
|
| 231 | + $wrap_tag = ($prive ? '<h3>' : '<div>'); |
|
| 232 | + if (strpos($titre, $cherche_tag) !== 0) { |
|
| 233 | + $titre = wrap($titre, $wrap_tag); |
|
| 234 | + } |
|
| 235 | + // puis on ajoute la classe |
|
| 236 | + $titre = ajouter_class($titre, $class_titre); |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - // Attributs |
|
| 240 | - $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | - $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | - $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 239 | + // Attributs |
|
| 240 | + $attr_role = ($role ? "role=\"$role\"" : ''); |
|
| 241 | + $attr_id = ($id ? "id=\"$id\"" : ''); |
|
| 242 | + $attr_data = ($type ? "data-alert=\"$type\"" : ''); |
|
| 243 | 243 | |
| 244 | - $message = |
|
| 245 | - "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | - . $titre |
|
| 247 | - . "<div class=\"$class_texte\">"; |
|
| 244 | + $message = |
|
| 245 | + "<div class=\"$class_alerte\" $attr_role $attr_id $attr_data>" |
|
| 246 | + . $titre |
|
| 247 | + . "<div class=\"$class_texte\">"; |
|
| 248 | 248 | |
| 249 | - return $message; |
|
| 249 | + return $message; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -260,5 +260,5 @@ discard block |
||
| 260 | 260 | * HTML de fin de l'alerte |
| 261 | 261 | */ |
| 262 | 262 | function message_alerte_fermer(): string { |
| 263 | - return '</div></div>'; |
|
| 263 | + return '</div></div>'; |
|
| 264 | 264 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | include_spip('inc/config'); |
@@ -32,31 +32,31 @@ discard block |
||
| 32 | 32 | * @return array |
| 33 | 33 | */ |
| 34 | 34 | function cvtconf_formulaire_charger($flux) { |
| 35 | - if ( |
|
| 36 | - $form = $flux['args']['form'] |
|
| 37 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | - ) { |
|
| 39 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | - include_spip('inc/autoriser'); |
|
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 35 | + if ( |
|
| 36 | + $form = $flux['args']['form'] |
|
| 37 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | + ) { |
|
| 39 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | + include_spip('inc/autoriser'); |
|
| 41 | + if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | - $flux['data']['editable'] = true; |
|
| 49 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | - if (!_AJAX) { |
|
| 51 | - var_dump($flux['data']); |
|
| 52 | - } |
|
| 53 | - // reinjecter pour la trace au traitement |
|
| 54 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 45 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | + $flux['data']['editable'] = true; |
|
| 49 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | + if (!_AJAX) { |
|
| 51 | + var_dump($flux['data']); |
|
| 52 | + } |
|
| 53 | + // reinjecter pour la trace au traitement |
|
| 54 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $flux; |
|
| 59 | + return $flux; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | 68 | function cvtconf_formulaire_traiter($flux) { |
| 69 | - if ( |
|
| 70 | - $form = $flux['args']['form'] |
|
| 71 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | - and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | - ) { |
|
| 74 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | - } |
|
| 69 | + if ( |
|
| 70 | + $form = $flux['args']['form'] |
|
| 71 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | + and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | + ) { |
|
| 74 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - return $flux; |
|
| 78 | + return $flux; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | 93 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 94 | - $valeurs = []; |
|
| 95 | - // charger les valeurs |
|
| 96 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | - // qui prend alors la main sur l'auto detection |
|
| 98 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | - $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 100 | - } |
|
| 101 | - $valeurs = pipeline( |
|
| 102 | - 'formulaire_charger', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | - 'data' => $valeurs |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - // ne pas stocker editable ! |
|
| 109 | - unset($valeurs['editable']); |
|
| 94 | + $valeurs = []; |
|
| 95 | + // charger les valeurs |
|
| 96 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | + // qui prend alors la main sur l'auto detection |
|
| 98 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | + $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 100 | + } |
|
| 101 | + $valeurs = pipeline( |
|
| 102 | + 'formulaire_charger', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | + 'data' => $valeurs |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + // ne pas stocker editable ! |
|
| 109 | + unset($valeurs['editable']); |
|
| 110 | 110 | |
| 111 | - // recuperer les valeurs postees |
|
| 112 | - $store = []; |
|
| 113 | - foreach ($valeurs as $k => $v) { |
|
| 114 | - if (substr($k, 0, 1) !== '_') { |
|
| 115 | - $store[$k] = _request($k); |
|
| 116 | - } |
|
| 117 | - } |
|
| 111 | + // recuperer les valeurs postees |
|
| 112 | + $store = []; |
|
| 113 | + foreach ($valeurs as $k => $v) { |
|
| 114 | + if (substr($k, 0, 1) !== '_') { |
|
| 115 | + $store[$k] = _request($k); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -132,31 +132,31 @@ discard block |
||
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | 134 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 135 | - // stocker en base |
|
| 136 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | - $casier = substr($form, 11); |
|
| 138 | - $table = 'meta'; |
|
| 139 | - $prefixe = ''; |
|
| 140 | - $stockage = ''; |
|
| 135 | + // stocker en base |
|
| 136 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | + $casier = substr($form, 11); |
|
| 138 | + $table = 'meta'; |
|
| 139 | + $prefixe = ''; |
|
| 140 | + $stockage = ''; |
|
| 141 | 141 | |
| 142 | - if (isset($valeurs['_meta_casier'])) { |
|
| 143 | - $casier = $valeurs['_meta_casier']; |
|
| 144 | - } |
|
| 145 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | - } |
|
| 148 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | - } |
|
| 142 | + if (isset($valeurs['_meta_casier'])) { |
|
| 143 | + $casier = $valeurs['_meta_casier']; |
|
| 144 | + } |
|
| 145 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | + } |
|
| 148 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | - if (isset($valeurs['_meta_table'])) { |
|
| 155 | - $table = $valeurs['_meta_table']; |
|
| 156 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | - } |
|
| 152 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | + if (isset($valeurs['_meta_table'])) { |
|
| 155 | + $table = $valeurs['_meta_table']; |
|
| 156 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -167,48 +167,48 @@ discard block |
||
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | 169 | function cvtconf_formulaires_configurer_recense($form) { |
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | - and lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | + and lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - $n = extraire_attribut($b, 'name') |
|
| 193 | - and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | - and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + $n = extraire_attribut($b, 'name') |
|
| 193 | + and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | + and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach ($valeurs as $k => $v) { |
|
| 265 | - if (substr($k, 0, 1) !== '_') { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach ($valeurs as $k => $v) { |
|
| 265 | + if (substr($k, 0, 1) !== '_') { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | - spip_initialisation_suite(); |
|
| 393 | - } |
|
| 394 | - include_spip('inc/minipres'); |
|
| 395 | - $dir = dirname($fichier); |
|
| 396 | - http_response_code(401); |
|
| 397 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | - . " <a href='" |
|
| 400 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | - . "'>" |
|
| 402 | - . _T('texte_inc_meta_2') |
|
| 403 | - . '</a> ' |
|
| 404 | - . _T( |
|
| 405 | - 'texte_inc_meta_3', |
|
| 406 | - ['repertoire' => joli_repertoire($dir)] |
|
| 407 | - ) |
|
| 408 | - . "</h4>\n"); |
|
| 409 | - exit; |
|
| 391 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | + spip_initialisation_suite(); |
|
| 393 | + } |
|
| 394 | + include_spip('inc/minipres'); |
|
| 395 | + $dir = dirname($fichier); |
|
| 396 | + http_response_code(401); |
|
| 397 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | + . " <a href='" |
|
| 400 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | + . "'>" |
|
| 402 | + . _T('texte_inc_meta_2') |
|
| 403 | + . '</a> ' |
|
| 404 | + . _T( |
|
| 405 | + 'texte_inc_meta_3', |
|
| 406 | + ['repertoire' => joli_repertoire($dir)] |
|
| 407 | + ) |
|
| 408 | + . "</h4>\n"); |
|
| 409 | + exit; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | * - true si récent, false sinon |
| 422 | 422 | */ |
| 423 | 423 | function jeune_fichier($fichier, $n) { |
| 424 | - if (!file_exists($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - if (!$c = @filemtime($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return (time() - $n <= $c); |
|
| 424 | + if (!file_exists($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + if (!$c = @filemtime($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return (time() - $n <= $c); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 444 | 444 | */ |
| 445 | 445 | function supprimer_fichier($fichier, $lock = true) { |
| 446 | - if (!@file_exists($fichier)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - if ($lock) { |
|
| 451 | - // verrouiller le fichier destination |
|
| 452 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | - return false; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // liberer le verrou |
|
| 457 | - spip_fclose_unlock($fp); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // supprimer |
|
| 461 | - return @unlink($fichier); |
|
| 446 | + if (!@file_exists($fichier)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + if ($lock) { |
|
| 451 | + // verrouiller le fichier destination |
|
| 452 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | + return false; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // liberer le verrou |
|
| 457 | + spip_fclose_unlock($fp); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // supprimer |
|
| 461 | + return @unlink($fichier); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | * Chemin du fichier |
| 469 | 469 | */ |
| 470 | 470 | function spip_unlink($f) { |
| 471 | - if (!is_dir($f)) { |
|
| 472 | - supprimer_fichier($f, false); |
|
| 473 | - } else { |
|
| 474 | - @unlink("$f/.ok"); |
|
| 475 | - @rmdir($f); |
|
| 476 | - } |
|
| 471 | + if (!is_dir($f)) { |
|
| 472 | + supprimer_fichier($f, false); |
|
| 473 | + } else { |
|
| 474 | + @unlink("$f/.ok"); |
|
| 475 | + @rmdir($f); |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | * The absolute path of the PHP file to invalidate. |
| 488 | 488 | */ |
| 489 | 489 | function spip_clear_opcode_cache($filepath) { |
| 490 | - clearstatcache(true, $filepath); |
|
| 491 | - |
|
| 492 | - // Zend OPcache |
|
| 493 | - if (function_exists('opcache_invalidate')) { |
|
| 494 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | - // si l'invalidation a echoue lever un flag |
|
| 496 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | - } |
|
| 499 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - // APC. |
|
| 504 | - if (function_exists('apc_delete_file')) { |
|
| 505 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | - // not compiled yet. |
|
| 507 | - // @see http://php.net/apc-delete-file |
|
| 508 | - @apc_delete_file($filepath); |
|
| 509 | - } |
|
| 490 | + clearstatcache(true, $filepath); |
|
| 491 | + |
|
| 492 | + // Zend OPcache |
|
| 493 | + if (function_exists('opcache_invalidate')) { |
|
| 494 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | + // si l'invalidation a echoue lever un flag |
|
| 496 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | + } |
|
| 499 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + // APC. |
|
| 504 | + if (function_exists('apc_delete_file')) { |
|
| 505 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | + // not compiled yet. |
|
| 507 | + // @see http://php.net/apc-delete-file |
|
| 508 | + @apc_delete_file($filepath); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -529,25 +529,25 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | */ |
| 531 | 531 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 532 | - if ( |
|
| 533 | - function_exists('opcache_get_configuration') |
|
| 534 | - and @ini_get('opcache.enable') |
|
| 535 | - and @ini_get('opcache.validate_timestamps') |
|
| 536 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | - ) { |
|
| 539 | - $wait = $duree + 1; |
|
| 540 | - if ($timestamp) { |
|
| 541 | - $wait -= (time() - $timestamp); |
|
| 542 | - if ($wait < 0) { |
|
| 543 | - $wait = 0; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | - if ($wait) { |
|
| 548 | - sleep($duree + 1); |
|
| 549 | - } |
|
| 550 | - } |
|
| 532 | + if ( |
|
| 533 | + function_exists('opcache_get_configuration') |
|
| 534 | + and @ini_get('opcache.enable') |
|
| 535 | + and @ini_get('opcache.validate_timestamps') |
|
| 536 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | + ) { |
|
| 539 | + $wait = $duree + 1; |
|
| 540 | + if ($timestamp) { |
|
| 541 | + $wait -= (time() - $timestamp); |
|
| 542 | + if ($wait < 0) { |
|
| 543 | + $wait = 0; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | + if ($wait) { |
|
| 548 | + sleep($duree + 1); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | * @return bool Suppression reussie. |
| 561 | 561 | */ |
| 562 | 562 | function supprimer_repertoire($dir) { |
| 563 | - if (!file_exists($dir)) { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | - return @unlink($dir); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - foreach (scandir($dir) as $item) { |
|
| 571 | - if ($item == '.' || $item == '..') { |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | - @chmod($dir . '/' . $item, 0777); |
|
| 576 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - }; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return @rmdir($dir); |
|
| 563 | + if (!file_exists($dir)) { |
|
| 564 | + return true; |
|
| 565 | + } |
|
| 566 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | + return @unlink($dir); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + foreach (scandir($dir) as $item) { |
|
| 571 | + if ($item == '.' || $item == '..') { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | + @chmod($dir . '/' . $item, 0777); |
|
| 576 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + }; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return @rmdir($dir); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -608,57 +608,57 @@ discard block |
||
| 608 | 608 | * Chemin du répertoire créé. |
| 609 | 609 | **/ |
| 610 | 610 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 611 | - static $dirs = []; |
|
| 612 | - |
|
| 613 | - $base = str_replace('//', '/', $base); |
|
| 614 | - |
|
| 615 | - # suppr le dernier caractere si c'est un / |
|
| 616 | - $base = rtrim($base, '/'); |
|
| 617 | - |
|
| 618 | - if (!strlen($subdir)) { |
|
| 619 | - $n = strrpos($base, '/'); |
|
| 620 | - if ($n === false) { |
|
| 621 | - return $nobase ? '' : ($base . '/'); |
|
| 622 | - } |
|
| 623 | - $subdir = substr($base, $n + 1); |
|
| 624 | - $base = substr($base, 0, $n + 1); |
|
| 625 | - } else { |
|
| 626 | - $base .= '/'; |
|
| 627 | - $subdir = str_replace('/', '', $subdir); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - $baseaff = $nobase ? '' : $base; |
|
| 631 | - if (isset($dirs[$base . $subdir])) { |
|
| 632 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | - |
|
| 637 | - if (file_exists("$path/.ok")) { |
|
| 638 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - @mkdir($path, _SPIP_CHMOD); |
|
| 642 | - @chmod($path, _SPIP_CHMOD); |
|
| 643 | - |
|
| 644 | - if (is_dir($path) && is_writable($path)) { |
|
| 645 | - @touch("$path/.ok"); |
|
| 646 | - spip_log("creation $base$subdir/"); |
|
| 647 | - |
|
| 648 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | - spip_log("echec creation $base${subdir}"); |
|
| 654 | - if ($tantpis) { |
|
| 655 | - return ''; |
|
| 656 | - } |
|
| 657 | - if (!_DIR_RESTREINT) { |
|
| 658 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | - } |
|
| 660 | - $base .= $subdir; |
|
| 661 | - raler_fichier($base . '/.ok'); |
|
| 611 | + static $dirs = []; |
|
| 612 | + |
|
| 613 | + $base = str_replace('//', '/', $base); |
|
| 614 | + |
|
| 615 | + # suppr le dernier caractere si c'est un / |
|
| 616 | + $base = rtrim($base, '/'); |
|
| 617 | + |
|
| 618 | + if (!strlen($subdir)) { |
|
| 619 | + $n = strrpos($base, '/'); |
|
| 620 | + if ($n === false) { |
|
| 621 | + return $nobase ? '' : ($base . '/'); |
|
| 622 | + } |
|
| 623 | + $subdir = substr($base, $n + 1); |
|
| 624 | + $base = substr($base, 0, $n + 1); |
|
| 625 | + } else { |
|
| 626 | + $base .= '/'; |
|
| 627 | + $subdir = str_replace('/', '', $subdir); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + $baseaff = $nobase ? '' : $base; |
|
| 631 | + if (isset($dirs[$base . $subdir])) { |
|
| 632 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | + |
|
| 637 | + if (file_exists("$path/.ok")) { |
|
| 638 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + @mkdir($path, _SPIP_CHMOD); |
|
| 642 | + @chmod($path, _SPIP_CHMOD); |
|
| 643 | + |
|
| 644 | + if (is_dir($path) && is_writable($path)) { |
|
| 645 | + @touch("$path/.ok"); |
|
| 646 | + spip_log("creation $base$subdir/"); |
|
| 647 | + |
|
| 648 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | + spip_log("echec creation $base${subdir}"); |
|
| 654 | + if ($tantpis) { |
|
| 655 | + return ''; |
|
| 656 | + } |
|
| 657 | + if (!_DIR_RESTREINT) { |
|
| 658 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | + } |
|
| 660 | + $base .= $subdir; |
|
| 661 | + raler_fichier($base . '/.ok'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -691,56 +691,56 @@ discard block |
||
| 691 | 691 | * Chemins des fichiers trouvés. |
| 692 | 692 | **/ |
| 693 | 693 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 694 | - $nbfiles = 0; |
|
| 695 | - if ($pattern == -1) { |
|
| 696 | - $pattern = "^$dir"; |
|
| 697 | - } |
|
| 698 | - $fichiers = []; |
|
| 699 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | - if ($dir == '') { |
|
| 703 | - $dir = '.'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | - if ( |
|
| 709 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | - and $f != 'CVS' |
|
| 711 | - and $f != 'remove.txt' |
|
| 712 | - and is_readable($f = "$dir/$f") |
|
| 713 | - ) { |
|
| 714 | - if (is_file($f)) { |
|
| 715 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | - $fichiers[] = $f; |
|
| 717 | - $nbfiles++; |
|
| 718 | - } |
|
| 719 | - } else { |
|
| 720 | - if (is_dir($f) and is_array($recurs)) { |
|
| 721 | - $rp = @realpath($f); |
|
| 722 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | - $rp = $f; |
|
| 724 | - } # realpath n'est peut etre pas autorise |
|
| 725 | - if (!isset($recurs[$rp])) { |
|
| 726 | - $recurs[$rp] = true; |
|
| 727 | - $beginning = $fichiers; |
|
| 728 | - $end = preg_files( |
|
| 729 | - "$f/", |
|
| 730 | - $pattern, |
|
| 731 | - $maxfiles - $nbfiles, |
|
| 732 | - $recurs |
|
| 733 | - ); |
|
| 734 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | - $nbfiles = count($fichiers); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - closedir($d); |
|
| 742 | - } |
|
| 743 | - sort($fichiers); |
|
| 744 | - |
|
| 745 | - return $fichiers; |
|
| 694 | + $nbfiles = 0; |
|
| 695 | + if ($pattern == -1) { |
|
| 696 | + $pattern = "^$dir"; |
|
| 697 | + } |
|
| 698 | + $fichiers = []; |
|
| 699 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | + if ($dir == '') { |
|
| 703 | + $dir = '.'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | + if ( |
|
| 709 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | + and $f != 'CVS' |
|
| 711 | + and $f != 'remove.txt' |
|
| 712 | + and is_readable($f = "$dir/$f") |
|
| 713 | + ) { |
|
| 714 | + if (is_file($f)) { |
|
| 715 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | + $fichiers[] = $f; |
|
| 717 | + $nbfiles++; |
|
| 718 | + } |
|
| 719 | + } else { |
|
| 720 | + if (is_dir($f) and is_array($recurs)) { |
|
| 721 | + $rp = @realpath($f); |
|
| 722 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | + $rp = $f; |
|
| 724 | + } # realpath n'est peut etre pas autorise |
|
| 725 | + if (!isset($recurs[$rp])) { |
|
| 726 | + $recurs[$rp] = true; |
|
| 727 | + $beginning = $fichiers; |
|
| 728 | + $end = preg_files( |
|
| 729 | + "$f/", |
|
| 730 | + $pattern, |
|
| 731 | + $maxfiles - $nbfiles, |
|
| 732 | + $recurs |
|
| 733 | + ); |
|
| 734 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | + $nbfiles = count($fichiers); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + closedir($d); |
|
| 742 | + } |
|
| 743 | + sort($fichiers); |
|
| 744 | + |
|
| 745 | + return $fichiers; |
|
| 746 | 746 | } |
@@ -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 | |
@@ -36,10 +36,10 @@ discard block |
||
| 36 | 36 | * Date au format SQL tel que `2008-04-01` |
| 37 | 37 | **/ |
| 38 | 38 | function extraire_date($texte) { |
| 39 | - // format = 2001-08 |
|
| 40 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | - } |
|
| 39 | + // format = 2001-08 |
|
| 40 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + } |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | |
@@ -61,29 +61,29 @@ discard block |
||
| 61 | 61 | * - une chaîne vide si la date est considérée nulle |
| 62 | 62 | **/ |
| 63 | 63 | function normaliser_date($date, $forcer_jour = false) { |
| 64 | - $date = vider_date($date); |
|
| 65 | - if ($date) { |
|
| 66 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 67 | - $date = date('Y-m-d H:i:s', $date); |
|
| 68 | - } |
|
| 69 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 70 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 71 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 72 | - } else { |
|
| 73 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 74 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 75 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 76 | - } else { |
|
| 77 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - if ($forcer_jour) { |
|
| 82 | - $date = str_replace('-00', '-01', $date); |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - return $date; |
|
| 64 | + $date = vider_date($date); |
|
| 65 | + if ($date) { |
|
| 66 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 67 | + $date = date('Y-m-d H:i:s', $date); |
|
| 68 | + } |
|
| 69 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 70 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 71 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 72 | + } else { |
|
| 73 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 74 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 75 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 76 | + } else { |
|
| 77 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + if ($forcer_jour) { |
|
| 82 | + $date = str_replace('-00', '-01', $date); |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + return $date; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,22 +96,22 @@ discard block |
||
| 96 | 96 | * - Une chaine vide |
| 97 | 97 | **/ |
| 98 | 98 | function vider_date($letexte, $verif_format_date = false) { |
| 99 | - if ( |
|
| 100 | - !$verif_format_date |
|
| 101 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 102 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 103 | - ) { |
|
| 104 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 105 | - return ''; |
|
| 106 | - } |
|
| 107 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 108 | - return ''; |
|
| 109 | - } |
|
| 110 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 111 | - return ''; |
|
| 112 | - } // eviter le bug GMT-1 |
|
| 113 | - } |
|
| 114 | - return $letexte; |
|
| 99 | + if ( |
|
| 100 | + !$verif_format_date |
|
| 101 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 102 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 103 | + ) { |
|
| 104 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 105 | + return ''; |
|
| 106 | + } |
|
| 107 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 108 | + return ''; |
|
| 109 | + } |
|
| 110 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 111 | + return ''; |
|
| 112 | + } // eviter le bug GMT-1 |
|
| 113 | + } |
|
| 114 | + return $letexte; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -127,14 +127,14 @@ discard block |
||
| 127 | 127 | **/ |
| 128 | 128 | function recup_heure($date) { |
| 129 | 129 | |
| 130 | - static $d = [0, 0, 0]; |
|
| 131 | - if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) { |
|
| 132 | - return $d; |
|
| 133 | - } |
|
| 130 | + static $d = [0, 0, 0]; |
|
| 131 | + if (!preg_match('#([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2})#', $date, $r)) { |
|
| 132 | + return $d; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - array_shift($r); |
|
| 135 | + array_shift($r); |
|
| 136 | 136 | |
| 137 | - return $r; |
|
| 137 | + return $r; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -148,13 +148,13 @@ discard block |
||
| 148 | 148 | * @return int heures, sinon 0 |
| 149 | 149 | **/ |
| 150 | 150 | function heures($numdate) { |
| 151 | - $heures = null; |
|
| 152 | - $date_array = recup_heure($numdate); |
|
| 153 | - if ($date_array) { |
|
| 154 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 155 | - } |
|
| 151 | + $heures = null; |
|
| 152 | + $date_array = recup_heure($numdate); |
|
| 153 | + if ($date_array) { |
|
| 154 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - return $heures; |
|
| 157 | + return $heures; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -168,13 +168,13 @@ discard block |
||
| 168 | 168 | * @return int minutes, sinon 0 |
| 169 | 169 | **/ |
| 170 | 170 | function minutes($numdate) { |
| 171 | - $minutes = null; |
|
| 172 | - $date_array = recup_heure($numdate); |
|
| 173 | - if ($date_array) { |
|
| 174 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 175 | - } |
|
| 171 | + $minutes = null; |
|
| 172 | + $date_array = recup_heure($numdate); |
|
| 173 | + if ($date_array) { |
|
| 174 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - return $minutes; |
|
| 177 | + return $minutes; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -188,13 +188,13 @@ discard block |
||
| 188 | 188 | * @return int secondes, sinon 0 |
| 189 | 189 | **/ |
| 190 | 190 | function secondes($numdate) { |
| 191 | - $secondes = null; |
|
| 192 | - $date_array = recup_heure($numdate); |
|
| 193 | - if ($date_array) { |
|
| 194 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 195 | - } |
|
| 191 | + $secondes = null; |
|
| 192 | + $date_array = recup_heure($numdate); |
|
| 193 | + if ($date_array) { |
|
| 194 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 195 | + } |
|
| 196 | 196 | |
| 197 | - return $secondes; |
|
| 197 | + return $secondes; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -213,12 +213,12 @@ discard block |
||
| 213 | 213 | * @return string L'heure formatée dans la langue en cours. |
| 214 | 214 | **/ |
| 215 | 215 | function heures_minutes($numdate, $forme = '') { |
| 216 | - if ($forme != 'abbr') { |
|
| 217 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 218 | - } |
|
| 219 | - else { |
|
| 220 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 221 | - } |
|
| 216 | + if ($forme != 'abbr') { |
|
| 217 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 218 | + } |
|
| 219 | + else { |
|
| 220 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 221 | + } |
|
| 222 | 222 | } |
| 223 | 223 | |
| 224 | 224 | /** |
@@ -243,56 +243,56 @@ discard block |
||
| 243 | 243 | * @return array [année, mois, jour, heures, minutes, secondes] |
| 244 | 244 | **/ |
| 245 | 245 | function recup_date($numdate, $forcer_jour = true) { |
| 246 | - if (!$numdate) { |
|
| 247 | - return ''; |
|
| 248 | - } |
|
| 249 | - $heures = $minutes = $secondes = 0; |
|
| 250 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 251 | - $jour = $regs[1]; |
|
| 252 | - $mois = $regs[2]; |
|
| 253 | - $annee = $regs[3]; |
|
| 254 | - if ($annee < 90) { |
|
| 255 | - $annee = 2000 + $annee; |
|
| 256 | - } elseif ($annee < 100) { |
|
| 257 | - $annee = 1900 + $annee; |
|
| 258 | - } |
|
| 259 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 260 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 261 | - $annee = $regs[1]; |
|
| 262 | - $mois = $regs[2]; |
|
| 263 | - $jour = $regs[3]; |
|
| 264 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 266 | - $annee = $regs[1]; |
|
| 267 | - $mois = $regs[2]; |
|
| 268 | - $jour = ''; |
|
| 269 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 271 | - $annee = $regs[1]; |
|
| 272 | - $mois = $regs[2]; |
|
| 273 | - $jour = $regs[3]; |
|
| 274 | - $heures = $regs[4]; |
|
| 275 | - $minutes = $regs[5]; |
|
| 276 | - $secondes = $regs[6]; |
|
| 277 | - } else { |
|
| 278 | - $annee = $mois = $jour = ''; |
|
| 279 | - } |
|
| 280 | - if ($annee > 4000) { |
|
| 281 | - $annee -= 9000; |
|
| 282 | - } |
|
| 283 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 284 | - $jour = substr($jour, 1); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if ($forcer_jour and $jour == '0') { |
|
| 288 | - $jour = '1'; |
|
| 289 | - } |
|
| 290 | - if ($forcer_jour and $mois == '0') { |
|
| 291 | - $mois = '1'; |
|
| 292 | - } |
|
| 293 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 294 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 295 | - } |
|
| 246 | + if (!$numdate) { |
|
| 247 | + return ''; |
|
| 248 | + } |
|
| 249 | + $heures = $minutes = $secondes = 0; |
|
| 250 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 251 | + $jour = $regs[1]; |
|
| 252 | + $mois = $regs[2]; |
|
| 253 | + $annee = $regs[3]; |
|
| 254 | + if ($annee < 90) { |
|
| 255 | + $annee = 2000 + $annee; |
|
| 256 | + } elseif ($annee < 100) { |
|
| 257 | + $annee = 1900 + $annee; |
|
| 258 | + } |
|
| 259 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 260 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 261 | + $annee = $regs[1]; |
|
| 262 | + $mois = $regs[2]; |
|
| 263 | + $jour = $regs[3]; |
|
| 264 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 265 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 266 | + $annee = $regs[1]; |
|
| 267 | + $mois = $regs[2]; |
|
| 268 | + $jour = ''; |
|
| 269 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 270 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 271 | + $annee = $regs[1]; |
|
| 272 | + $mois = $regs[2]; |
|
| 273 | + $jour = $regs[3]; |
|
| 274 | + $heures = $regs[4]; |
|
| 275 | + $minutes = $regs[5]; |
|
| 276 | + $secondes = $regs[6]; |
|
| 277 | + } else { |
|
| 278 | + $annee = $mois = $jour = ''; |
|
| 279 | + } |
|
| 280 | + if ($annee > 4000) { |
|
| 281 | + $annee -= 9000; |
|
| 282 | + } |
|
| 283 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 284 | + $jour = substr($jour, 1); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if ($forcer_jour and $jour == '0') { |
|
| 288 | + $jour = '1'; |
|
| 289 | + } |
|
| 290 | + if ($forcer_jour and $mois == '0') { |
|
| 291 | + $mois = '1'; |
|
| 292 | + } |
|
| 293 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 294 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 295 | + } |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | /** |
@@ -319,10 +319,10 @@ discard block |
||
| 319 | 319 | * La date relative ou complète |
| 320 | 320 | **/ |
| 321 | 321 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */) { |
| 322 | - return sinon( |
|
| 323 | - date_relative($date, $decalage_maxi), |
|
| 324 | - affdate_heure($date) |
|
| 325 | - ); |
|
| 322 | + return sinon( |
|
| 323 | + date_relative($date, $decalage_maxi), |
|
| 324 | + affdate_heure($date) |
|
| 325 | + ); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -355,85 +355,85 @@ discard block |
||
| 355 | 355 | **/ |
| 356 | 356 | function date_relative($date, $decalage_maxi = 0, $ref_date = null) { |
| 357 | 357 | |
| 358 | - if (is_null($ref_date)) { |
|
| 359 | - $ref_time = time(); |
|
| 360 | - } else { |
|
| 361 | - $ref_time = strtotime($ref_date); |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - if (!$date) { |
|
| 365 | - return; |
|
| 366 | - } |
|
| 367 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 368 | - |
|
| 369 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 370 | - return ''; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if ($decal < 0) { |
|
| 374 | - $il_y_a = 'date_dans'; |
|
| 375 | - $decal = -1 * $decal; |
|
| 376 | - } else { |
|
| 377 | - $il_y_a = 'date_il_y_a'; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 381 | - return affdate_court($date); |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if ($decal > 3600 * 24 * 30) { |
|
| 385 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 386 | - if ($mois < 2) { |
|
| 387 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 388 | - } else { |
|
| 389 | - $delai = "$mois " . _T('date_mois'); |
|
| 390 | - } |
|
| 391 | - } else { |
|
| 392 | - if ($decal > 3600 * 24 * 7) { |
|
| 393 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 394 | - if ($semaines < 2) { |
|
| 395 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 396 | - } else { |
|
| 397 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 398 | - } |
|
| 399 | - } else { |
|
| 400 | - if ($decal > 3600 * 24) { |
|
| 401 | - $jours = floor($decal / (3600 * 24)); |
|
| 402 | - if ($jours < 2) { |
|
| 403 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 404 | - } else { |
|
| 405 | - $delai = "$jours " . _T('date_jours'); |
|
| 406 | - } |
|
| 407 | - } else { |
|
| 408 | - if ($decal >= 3600) { |
|
| 409 | - $heures = floor($decal / 3600); |
|
| 410 | - if ($heures < 2) { |
|
| 411 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 412 | - } else { |
|
| 413 | - $delai = "$heures " . _T('date_heures'); |
|
| 414 | - } |
|
| 415 | - } else { |
|
| 416 | - if ($decal >= 60) { |
|
| 417 | - $minutes = floor($decal / 60); |
|
| 418 | - if ($minutes < 2) { |
|
| 419 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 420 | - } else { |
|
| 421 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 422 | - } |
|
| 423 | - } else { |
|
| 424 | - $secondes = ceil($decal); |
|
| 425 | - if ($secondes < 2) { |
|
| 426 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 427 | - } else { |
|
| 428 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 358 | + if (is_null($ref_date)) { |
|
| 359 | + $ref_time = time(); |
|
| 360 | + } else { |
|
| 361 | + $ref_time = strtotime($ref_date); |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + if (!$date) { |
|
| 365 | + return; |
|
| 366 | + } |
|
| 367 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 368 | + |
|
| 369 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 370 | + return ''; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if ($decal < 0) { |
|
| 374 | + $il_y_a = 'date_dans'; |
|
| 375 | + $decal = -1 * $decal; |
|
| 376 | + } else { |
|
| 377 | + $il_y_a = 'date_il_y_a'; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 381 | + return affdate_court($date); |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if ($decal > 3600 * 24 * 30) { |
|
| 385 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 386 | + if ($mois < 2) { |
|
| 387 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 388 | + } else { |
|
| 389 | + $delai = "$mois " . _T('date_mois'); |
|
| 390 | + } |
|
| 391 | + } else { |
|
| 392 | + if ($decal > 3600 * 24 * 7) { |
|
| 393 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 394 | + if ($semaines < 2) { |
|
| 395 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 396 | + } else { |
|
| 397 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 398 | + } |
|
| 399 | + } else { |
|
| 400 | + if ($decal > 3600 * 24) { |
|
| 401 | + $jours = floor($decal / (3600 * 24)); |
|
| 402 | + if ($jours < 2) { |
|
| 403 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 404 | + } else { |
|
| 405 | + $delai = "$jours " . _T('date_jours'); |
|
| 406 | + } |
|
| 407 | + } else { |
|
| 408 | + if ($decal >= 3600) { |
|
| 409 | + $heures = floor($decal / 3600); |
|
| 410 | + if ($heures < 2) { |
|
| 411 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 412 | + } else { |
|
| 413 | + $delai = "$heures " . _T('date_heures'); |
|
| 414 | + } |
|
| 415 | + } else { |
|
| 416 | + if ($decal >= 60) { |
|
| 417 | + $minutes = floor($decal / 60); |
|
| 418 | + if ($minutes < 2) { |
|
| 419 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 420 | + } else { |
|
| 421 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 422 | + } |
|
| 423 | + } else { |
|
| 424 | + $secondes = ceil($decal); |
|
| 425 | + if ($secondes < 2) { |
|
| 426 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 427 | + } else { |
|
| 428 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -459,32 +459,32 @@ discard block |
||
| 459 | 459 | **/ |
| 460 | 460 | function date_relativecourt($date, $decalage_maxi = 0) { |
| 461 | 461 | |
| 462 | - if (!$date) { |
|
| 463 | - return; |
|
| 464 | - } |
|
| 465 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 466 | - |
|
| 467 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 468 | - return ''; |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($decal < -24 * 3600) { |
|
| 472 | - $retour = date_relative($date, $decalage_maxi); |
|
| 473 | - } elseif ($decal < 0) { |
|
| 474 | - $retour = _T('date_demain'); |
|
| 475 | - } else { |
|
| 476 | - if ($decal < (3600 * 24)) { |
|
| 477 | - $retour = _T('date_aujourdhui'); |
|
| 478 | - } else { |
|
| 479 | - if ($decal < (3600 * 24 * 2)) { |
|
| 480 | - $retour = _T('date_hier'); |
|
| 481 | - } else { |
|
| 482 | - $retour = date_relative($date, $decalage_maxi); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $retour; |
|
| 462 | + if (!$date) { |
|
| 463 | + return; |
|
| 464 | + } |
|
| 465 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 466 | + |
|
| 467 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 468 | + return ''; |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($decal < -24 * 3600) { |
|
| 472 | + $retour = date_relative($date, $decalage_maxi); |
|
| 473 | + } elseif ($decal < 0) { |
|
| 474 | + $retour = _T('date_demain'); |
|
| 475 | + } else { |
|
| 476 | + if ($decal < (3600 * 24)) { |
|
| 477 | + $retour = _T('date_aujourdhui'); |
|
| 478 | + } else { |
|
| 479 | + if ($decal < (3600 * 24 * 2)) { |
|
| 480 | + $retour = _T('date_hier'); |
|
| 481 | + } else { |
|
| 482 | + $retour = date_relative($date, $decalage_maxi); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $retour; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | /** |
@@ -503,174 +503,174 @@ discard block |
||
| 503 | 503 | * @return mixed|string |
| 504 | 504 | */ |
| 505 | 505 | function affdate_base($numdate, $vue, $options = []) { |
| 506 | - if (is_string($options)) { |
|
| 507 | - $options = ['param' => $options]; |
|
| 508 | - } |
|
| 509 | - $date_array = recup_date($numdate, false); |
|
| 510 | - if (!$date_array) { |
|
| 511 | - return; |
|
| 512 | - } |
|
| 513 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 514 | - |
|
| 515 | - // 1er, 21st, etc. |
|
| 516 | - $journum = $jour; |
|
| 517 | - |
|
| 518 | - if ($jour == 0) { |
|
| 519 | - $jour = ''; |
|
| 520 | - $njour = 0; |
|
| 521 | - } else { |
|
| 522 | - $njour = intval($jour); |
|
| 523 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 524 | - $jour = $jourth; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - $mois = intval($mois); |
|
| 529 | - if ($mois > 0 and $mois < 13) { |
|
| 530 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 531 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 532 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | - if ($jour) { |
|
| 534 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 535 | - } else { |
|
| 536 | - $jourmois = $nommois; |
|
| 537 | - } |
|
| 538 | - } else { |
|
| 539 | - $nommois = ''; |
|
| 540 | - $jourmois = ''; |
|
| 541 | - } |
|
| 542 | - |
|
| 543 | - if ($annee < 0) { |
|
| 544 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 545 | - $avjc = true; |
|
| 546 | - } else { |
|
| 547 | - $avjc = false; |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - switch ($vue) { |
|
| 551 | - case 'saison': |
|
| 552 | - case 'saison_annee': |
|
| 553 | - $saison = ''; |
|
| 554 | - if ($mois > 0) { |
|
| 555 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 556 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 557 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 558 | - } |
|
| 559 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 560 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 561 | - } |
|
| 562 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 563 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 564 | - } |
|
| 565 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 566 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 567 | - } |
|
| 568 | - } |
|
| 569 | - if ($vue == 'saison') { |
|
| 570 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 571 | - } else { |
|
| 572 | - return $saison ? trim(_T( |
|
| 573 | - 'date_fmt_saison_annee', |
|
| 574 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 575 | - )) : ''; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - case 'court': |
|
| 579 | - if ($avjc) { |
|
| 580 | - return $annee; |
|
| 581 | - } |
|
| 582 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 583 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 584 | - return $annee; |
|
| 585 | - } |
|
| 586 | - if ($annee != $a) { |
|
| 587 | - return _T( |
|
| 588 | - 'date_fmt_mois_annee', |
|
| 589 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 590 | - ); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return _T( |
|
| 594 | - 'date_fmt_jour_mois', |
|
| 595 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 596 | - ); |
|
| 597 | - |
|
| 598 | - case 'jourcourt': |
|
| 599 | - if ($avjc) { |
|
| 600 | - return $annee; |
|
| 601 | - } |
|
| 602 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 603 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 604 | - return $annee; |
|
| 605 | - } |
|
| 606 | - if ($annee != $a) { |
|
| 607 | - return _T( |
|
| 608 | - 'date_fmt_jour_mois_annee', |
|
| 609 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 610 | - ); |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - return _T( |
|
| 614 | - 'date_fmt_jour_mois', |
|
| 615 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 616 | - ); |
|
| 617 | - |
|
| 618 | - case 'entier': |
|
| 619 | - if ($avjc) { |
|
| 620 | - return $annee; |
|
| 621 | - } |
|
| 622 | - if ($jour) { |
|
| 623 | - return _T( |
|
| 624 | - 'date_fmt_jour_mois_annee', |
|
| 625 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 626 | - ); |
|
| 627 | - } elseif ($mois) { |
|
| 628 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 629 | - } else { |
|
| 630 | - return $annee; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - case 'nom_mois': |
|
| 634 | - return $nommois; |
|
| 635 | - |
|
| 636 | - case 'mois': |
|
| 637 | - return sprintf('%02s', $mois); |
|
| 638 | - |
|
| 639 | - case 'jour': |
|
| 640 | - return $jour; |
|
| 641 | - |
|
| 642 | - case 'journum': |
|
| 643 | - return $journum; |
|
| 644 | - |
|
| 645 | - case 'nom_jour': |
|
| 646 | - if (!$mois or !$njour) { |
|
| 647 | - return ''; |
|
| 648 | - } |
|
| 649 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 650 | - $nom = 1 + date('w', $nom); |
|
| 651 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 652 | - |
|
| 653 | - return _T('date_jour_' . $nom . $param); |
|
| 654 | - |
|
| 655 | - case 'mois_annee': |
|
| 656 | - if ($avjc) { |
|
| 657 | - return $annee; |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 661 | - |
|
| 662 | - case 'annee': |
|
| 663 | - return $annee; |
|
| 664 | - |
|
| 665 | - // Cas d'une vue non definie : retomber sur le format |
|
| 666 | - // de date propose par http://www.php.net/date |
|
| 667 | - default: |
|
| 668 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 669 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 670 | - $time = strtotime($numdate); |
|
| 671 | - } |
|
| 672 | - return date($vue, $time); |
|
| 673 | - } |
|
| 506 | + if (is_string($options)) { |
|
| 507 | + $options = ['param' => $options]; |
|
| 508 | + } |
|
| 509 | + $date_array = recup_date($numdate, false); |
|
| 510 | + if (!$date_array) { |
|
| 511 | + return; |
|
| 512 | + } |
|
| 513 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 514 | + |
|
| 515 | + // 1er, 21st, etc. |
|
| 516 | + $journum = $jour; |
|
| 517 | + |
|
| 518 | + if ($jour == 0) { |
|
| 519 | + $jour = ''; |
|
| 520 | + $njour = 0; |
|
| 521 | + } else { |
|
| 522 | + $njour = intval($jour); |
|
| 523 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 524 | + $jour = $jourth; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + $mois = intval($mois); |
|
| 529 | + if ($mois > 0 and $mois < 13) { |
|
| 530 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 531 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 532 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 533 | + if ($jour) { |
|
| 534 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 535 | + } else { |
|
| 536 | + $jourmois = $nommois; |
|
| 537 | + } |
|
| 538 | + } else { |
|
| 539 | + $nommois = ''; |
|
| 540 | + $jourmois = ''; |
|
| 541 | + } |
|
| 542 | + |
|
| 543 | + if ($annee < 0) { |
|
| 544 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 545 | + $avjc = true; |
|
| 546 | + } else { |
|
| 547 | + $avjc = false; |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + switch ($vue) { |
|
| 551 | + case 'saison': |
|
| 552 | + case 'saison_annee': |
|
| 553 | + $saison = ''; |
|
| 554 | + if ($mois > 0) { |
|
| 555 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 556 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 557 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 558 | + } |
|
| 559 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 560 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 561 | + } |
|
| 562 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 563 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 564 | + } |
|
| 565 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 566 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 567 | + } |
|
| 568 | + } |
|
| 569 | + if ($vue == 'saison') { |
|
| 570 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 571 | + } else { |
|
| 572 | + return $saison ? trim(_T( |
|
| 573 | + 'date_fmt_saison_annee', |
|
| 574 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 575 | + )) : ''; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + case 'court': |
|
| 579 | + if ($avjc) { |
|
| 580 | + return $annee; |
|
| 581 | + } |
|
| 582 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 583 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 584 | + return $annee; |
|
| 585 | + } |
|
| 586 | + if ($annee != $a) { |
|
| 587 | + return _T( |
|
| 588 | + 'date_fmt_mois_annee', |
|
| 589 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 590 | + ); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return _T( |
|
| 594 | + 'date_fmt_jour_mois', |
|
| 595 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 596 | + ); |
|
| 597 | + |
|
| 598 | + case 'jourcourt': |
|
| 599 | + if ($avjc) { |
|
| 600 | + return $annee; |
|
| 601 | + } |
|
| 602 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 603 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 604 | + return $annee; |
|
| 605 | + } |
|
| 606 | + if ($annee != $a) { |
|
| 607 | + return _T( |
|
| 608 | + 'date_fmt_jour_mois_annee', |
|
| 609 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 610 | + ); |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + return _T( |
|
| 614 | + 'date_fmt_jour_mois', |
|
| 615 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 616 | + ); |
|
| 617 | + |
|
| 618 | + case 'entier': |
|
| 619 | + if ($avjc) { |
|
| 620 | + return $annee; |
|
| 621 | + } |
|
| 622 | + if ($jour) { |
|
| 623 | + return _T( |
|
| 624 | + 'date_fmt_jour_mois_annee', |
|
| 625 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 626 | + ); |
|
| 627 | + } elseif ($mois) { |
|
| 628 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 629 | + } else { |
|
| 630 | + return $annee; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + case 'nom_mois': |
|
| 634 | + return $nommois; |
|
| 635 | + |
|
| 636 | + case 'mois': |
|
| 637 | + return sprintf('%02s', $mois); |
|
| 638 | + |
|
| 639 | + case 'jour': |
|
| 640 | + return $jour; |
|
| 641 | + |
|
| 642 | + case 'journum': |
|
| 643 | + return $journum; |
|
| 644 | + |
|
| 645 | + case 'nom_jour': |
|
| 646 | + if (!$mois or !$njour) { |
|
| 647 | + return ''; |
|
| 648 | + } |
|
| 649 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 650 | + $nom = 1 + date('w', $nom); |
|
| 651 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 652 | + |
|
| 653 | + return _T('date_jour_' . $nom . $param); |
|
| 654 | + |
|
| 655 | + case 'mois_annee': |
|
| 656 | + if ($avjc) { |
|
| 657 | + return $annee; |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 661 | + |
|
| 662 | + case 'annee': |
|
| 663 | + return $annee; |
|
| 664 | + |
|
| 665 | + // Cas d'une vue non definie : retomber sur le format |
|
| 666 | + // de date propose par http://www.php.net/date |
|
| 667 | + default: |
|
| 668 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 669 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 670 | + $time = strtotime($numdate); |
|
| 671 | + } |
|
| 672 | + return date($vue, $time); |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | |
@@ -697,11 +697,11 @@ discard block |
||
| 697 | 697 | * Nom du jour |
| 698 | 698 | **/ |
| 699 | 699 | function nom_jour($numdate, $forme = '') { |
| 700 | - if (!($forme == 'abbr' or $forme == 'initiale')) { |
|
| 701 | - $forme = ''; |
|
| 702 | - } |
|
| 700 | + if (!($forme == 'abbr' or $forme == 'initiale')) { |
|
| 701 | + $forme = ''; |
|
| 702 | + } |
|
| 703 | 703 | |
| 704 | - return affdate_base($numdate, 'nom_jour', $forme); |
|
| 704 | + return affdate_base($numdate, 'nom_jour', $forme); |
|
| 705 | 705 | } |
| 706 | 706 | |
| 707 | 707 | /** |
@@ -723,7 +723,7 @@ discard block |
||
| 723 | 723 | * Numéro du jour |
| 724 | 724 | **/ |
| 725 | 725 | function jour($numdate) { |
| 726 | - return affdate_base($numdate, 'jour'); |
|
| 726 | + return affdate_base($numdate, 'jour'); |
|
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | /** |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | * Numéro du jour |
| 742 | 742 | **/ |
| 743 | 743 | function journum($numdate) { |
| 744 | - return affdate_base($numdate, 'journum'); |
|
| 744 | + return affdate_base($numdate, 'journum'); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -759,7 +759,7 @@ discard block |
||
| 759 | 759 | * Numéro du mois (sur 2 chiffres) |
| 760 | 760 | **/ |
| 761 | 761 | function mois($numdate) { |
| 762 | - return affdate_base($numdate, 'mois'); |
|
| 762 | + return affdate_base($numdate, 'mois'); |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | /** |
@@ -783,11 +783,11 @@ discard block |
||
| 783 | 783 | * Nom du mois |
| 784 | 784 | **/ |
| 785 | 785 | function nom_mois($numdate, $forme = '') { |
| 786 | - if (!($forme == 'abbr')) { |
|
| 787 | - $forme = ''; |
|
| 788 | - } |
|
| 786 | + if (!($forme == 'abbr')) { |
|
| 787 | + $forme = ''; |
|
| 788 | + } |
|
| 789 | 789 | |
| 790 | - return affdate_base($numdate, 'nom_mois', $forme); |
|
| 790 | + return affdate_base($numdate, 'nom_mois', $forme); |
|
| 791 | 791 | } |
| 792 | 792 | |
| 793 | 793 | /** |
@@ -805,7 +805,7 @@ discard block |
||
| 805 | 805 | * Année (sur 4 chiffres) |
| 806 | 806 | **/ |
| 807 | 807 | function annee($numdate) { |
| 808 | - return affdate_base($numdate, 'annee'); |
|
| 808 | + return affdate_base($numdate, 'annee'); |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | |
@@ -835,11 +835,11 @@ discard block |
||
| 835 | 835 | * La date formatée |
| 836 | 836 | **/ |
| 837 | 837 | function saison($numdate, $hemisphere = 'nord') { |
| 838 | - if ($hemisphere != 'sud') { |
|
| 839 | - $hemisphere = 'nord'; |
|
| 840 | - } |
|
| 838 | + if ($hemisphere != 'sud') { |
|
| 839 | + $hemisphere = 'nord'; |
|
| 840 | + } |
|
| 841 | 841 | |
| 842 | - return affdate_base($numdate, 'saison', $hemisphere); |
|
| 842 | + return affdate_base($numdate, 'saison', $hemisphere); |
|
| 843 | 843 | } |
| 844 | 844 | |
| 845 | 845 | |
@@ -868,11 +868,11 @@ discard block |
||
| 868 | 868 | * La date formatée |
| 869 | 869 | **/ |
| 870 | 870 | function saison_annee($numdate, $hemisphere = 'nord') { |
| 871 | - if ($hemisphere != 'sud') { |
|
| 872 | - $hemisphere = 'nord'; |
|
| 873 | - } |
|
| 871 | + if ($hemisphere != 'sud') { |
|
| 872 | + $hemisphere = 'nord'; |
|
| 873 | + } |
|
| 874 | 874 | |
| 875 | - return affdate_base($numdate, 'saison_annee', $hemisphere); |
|
| 875 | + return affdate_base($numdate, 'saison_annee', $hemisphere); |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | * La date formatée |
| 901 | 901 | **/ |
| 902 | 902 | function affdate($numdate, $format = 'entier') { |
| 903 | - return affdate_base($numdate, $format); |
|
| 903 | + return affdate_base($numdate, $format); |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | |
@@ -927,7 +927,7 @@ discard block |
||
| 927 | 927 | * La date formatée |
| 928 | 928 | **/ |
| 929 | 929 | function affdate_court($numdate, $annee_courante = null) { |
| 930 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 930 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | * La date formatée |
| 955 | 955 | **/ |
| 956 | 956 | function affdate_jourcourt($numdate, $annee_courante = null) { |
| 957 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 957 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -972,7 +972,7 @@ discard block |
||
| 972 | 972 | * La date formatée |
| 973 | 973 | **/ |
| 974 | 974 | function affdate_mois_annee($numdate) { |
| 975 | - return affdate_base($numdate, 'mois_annee'); |
|
| 975 | + return affdate_base($numdate, 'mois_annee'); |
|
| 976 | 976 | } |
| 977 | 977 | |
| 978 | 978 | /** |
@@ -990,16 +990,16 @@ discard block |
||
| 990 | 990 | * La date formatée |
| 991 | 991 | **/ |
| 992 | 992 | function affdate_heure($numdate) { |
| 993 | - $date_array = recup_date($numdate); |
|
| 994 | - if (!$date_array) { |
|
| 995 | - return; |
|
| 996 | - } |
|
| 997 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 998 | - |
|
| 999 | - return _T('date_fmt_jour_heure', [ |
|
| 1000 | - 'jour' => affdate($numdate), |
|
| 1001 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1002 | - ]); |
|
| 993 | + $date_array = recup_date($numdate); |
|
| 994 | + if (!$date_array) { |
|
| 995 | + return; |
|
| 996 | + } |
|
| 997 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 998 | + |
|
| 999 | + return _T('date_fmt_jour_heure', [ |
|
| 1000 | + 'jour' => affdate($numdate), |
|
| 1001 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1002 | + ]); |
|
| 1003 | 1003 | } |
| 1004 | 1004 | |
| 1005 | 1005 | /** |
@@ -1031,117 +1031,117 @@ discard block |
||
| 1031 | 1031 | * Texte de la date |
| 1032 | 1032 | */ |
| 1033 | 1033 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = '') { |
| 1034 | - $abbr = $jour = ''; |
|
| 1035 | - $affdate = 'affdate_jourcourt'; |
|
| 1036 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1037 | - $abbr = 'abbr'; |
|
| 1038 | - } |
|
| 1039 | - if (strpos($forme, 'annee') !== false) { |
|
| 1040 | - $affdate = 'affdate'; |
|
| 1041 | - } |
|
| 1042 | - if (strpos($forme, 'jour') !== false) { |
|
| 1043 | - $jour = 'jour'; |
|
| 1044 | - } |
|
| 1045 | - |
|
| 1046 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1047 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1048 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1049 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | - $dtabbr = '</abbr>'; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - $date_debut = strtotime($date_debut); |
|
| 1054 | - $date_fin = strtotime($date_fin); |
|
| 1055 | - $d = date('Y-m-d', $date_debut); |
|
| 1056 | - $f = date('Y-m-d', $date_fin); |
|
| 1057 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1058 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1059 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1060 | - |
|
| 1061 | - if ($d == $f) { // meme jour |
|
| 1062 | - $nomjour = nom_jour($d, $abbr); |
|
| 1063 | - $s = $affdate($d); |
|
| 1064 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1065 | - if ($h) { |
|
| 1066 | - if ($hd == $hf) { |
|
| 1067 | - // Lundi 20 fevrier a 18h25 |
|
| 1068 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1069 | - $s = "$dtstart$s$dtabbr"; |
|
| 1070 | - } else { |
|
| 1071 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1072 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1073 | - $s = _T( |
|
| 1074 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1075 | - [ |
|
| 1076 | - 'jour' => spip_ucfirst($s), |
|
| 1077 | - 'heure_debut' => $hd, |
|
| 1078 | - 'heure_fin' => $hf, |
|
| 1079 | - 'dtstart' => $dtstart, |
|
| 1080 | - 'dtend' => $dtend, |
|
| 1081 | - 'dtabbr' => $dtabbr |
|
| 1082 | - ], |
|
| 1083 | - [ |
|
| 1084 | - 'sanitize' => false |
|
| 1085 | - ] |
|
| 1086 | - ); |
|
| 1087 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1088 | - else { |
|
| 1089 | - $s = spip_ucfirst(_T( |
|
| 1090 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1091 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1092 | - )); |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } else { |
|
| 1096 | - if ($dtabbr && $dtstart) { |
|
| 1097 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1098 | - } else { |
|
| 1099 | - $s = spip_ucfirst($s); |
|
| 1100 | - } |
|
| 1101 | - } |
|
| 1102 | - } else { |
|
| 1103 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1104 | - if (!$h) { |
|
| 1105 | - $date_debut = jour($d); |
|
| 1106 | - } else { |
|
| 1107 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1108 | - } |
|
| 1109 | - $date_fin = $affdate($f); |
|
| 1110 | - if ($jour) { |
|
| 1111 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1112 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1113 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1114 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1115 | - } |
|
| 1116 | - if ($h) { |
|
| 1117 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1118 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1119 | - } |
|
| 1120 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | - |
|
| 1123 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1124 | - } else { |
|
| 1125 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1126 | - $date_fin = $affdate($f); |
|
| 1127 | - if ($jour) { |
|
| 1128 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1129 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1130 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1131 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1132 | - } |
|
| 1133 | - if ($h) { |
|
| 1134 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1135 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1139 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1141 | - } |
|
| 1142 | - } |
|
| 1143 | - |
|
| 1144 | - return $s; |
|
| 1034 | + $abbr = $jour = ''; |
|
| 1035 | + $affdate = 'affdate_jourcourt'; |
|
| 1036 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1037 | + $abbr = 'abbr'; |
|
| 1038 | + } |
|
| 1039 | + if (strpos($forme, 'annee') !== false) { |
|
| 1040 | + $affdate = 'affdate'; |
|
| 1041 | + } |
|
| 1042 | + if (strpos($forme, 'jour') !== false) { |
|
| 1043 | + $jour = 'jour'; |
|
| 1044 | + } |
|
| 1045 | + |
|
| 1046 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1047 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1048 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1049 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1050 | + $dtabbr = '</abbr>'; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + $date_debut = strtotime($date_debut); |
|
| 1054 | + $date_fin = strtotime($date_fin); |
|
| 1055 | + $d = date('Y-m-d', $date_debut); |
|
| 1056 | + $f = date('Y-m-d', $date_fin); |
|
| 1057 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1058 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1059 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1060 | + |
|
| 1061 | + if ($d == $f) { // meme jour |
|
| 1062 | + $nomjour = nom_jour($d, $abbr); |
|
| 1063 | + $s = $affdate($d); |
|
| 1064 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1065 | + if ($h) { |
|
| 1066 | + if ($hd == $hf) { |
|
| 1067 | + // Lundi 20 fevrier a 18h25 |
|
| 1068 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1069 | + $s = "$dtstart$s$dtabbr"; |
|
| 1070 | + } else { |
|
| 1071 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1072 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1073 | + $s = _T( |
|
| 1074 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1075 | + [ |
|
| 1076 | + 'jour' => spip_ucfirst($s), |
|
| 1077 | + 'heure_debut' => $hd, |
|
| 1078 | + 'heure_fin' => $hf, |
|
| 1079 | + 'dtstart' => $dtstart, |
|
| 1080 | + 'dtend' => $dtend, |
|
| 1081 | + 'dtabbr' => $dtabbr |
|
| 1082 | + ], |
|
| 1083 | + [ |
|
| 1084 | + 'sanitize' => false |
|
| 1085 | + ] |
|
| 1086 | + ); |
|
| 1087 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1088 | + else { |
|
| 1089 | + $s = spip_ucfirst(_T( |
|
| 1090 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1091 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1092 | + )); |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } else { |
|
| 1096 | + if ($dtabbr && $dtstart) { |
|
| 1097 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1098 | + } else { |
|
| 1099 | + $s = spip_ucfirst($s); |
|
| 1100 | + } |
|
| 1101 | + } |
|
| 1102 | + } else { |
|
| 1103 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1104 | + if (!$h) { |
|
| 1105 | + $date_debut = jour($d); |
|
| 1106 | + } else { |
|
| 1107 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1108 | + } |
|
| 1109 | + $date_fin = $affdate($f); |
|
| 1110 | + if ($jour) { |
|
| 1111 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1112 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1113 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1114 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1115 | + } |
|
| 1116 | + if ($h) { |
|
| 1117 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1118 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1119 | + } |
|
| 1120 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1121 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1122 | + |
|
| 1123 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1124 | + } else { |
|
| 1125 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1126 | + $date_fin = $affdate($f); |
|
| 1127 | + if ($jour) { |
|
| 1128 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1129 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1130 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1131 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1132 | + } |
|
| 1133 | + if ($h) { |
|
| 1134 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1135 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1139 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1140 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1141 | + } |
|
| 1142 | + } |
|
| 1143 | + |
|
| 1144 | + return $s; |
|
| 1145 | 1145 | } |
| 1146 | 1146 | |
| 1147 | 1147 | /** |
@@ -1162,10 +1162,10 @@ discard block |
||
| 1162 | 1162 | * Date au format ical |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function date_ical($date, $addminutes = 0) { |
| 1165 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1166 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1165 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1166 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1167 | 1167 | |
| 1168 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1168 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | |
@@ -1189,11 +1189,11 @@ discard block |
||
| 1189 | 1189 | * La date formatée |
| 1190 | 1190 | **/ |
| 1191 | 1191 | function date_iso($date_heure) { |
| 1192 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1193 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1194 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1192 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1193 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1194 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1195 | 1195 | |
| 1196 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1196 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1197 | 1197 | } |
| 1198 | 1198 | |
| 1199 | 1199 | /** |
@@ -1216,11 +1216,11 @@ discard block |
||
| 1216 | 1216 | * La date formatée |
| 1217 | 1217 | **/ |
| 1218 | 1218 | function date_822($date_heure) { |
| 1219 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1220 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1221 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1219 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1220 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1221 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1222 | 1222 | |
| 1223 | - return date('r', $time); |
|
| 1223 | + return date('r', $time); |
|
| 1224 | 1224 | } |
| 1225 | 1225 | |
| 1226 | 1226 | /** |
@@ -1236,11 +1236,11 @@ discard block |
||
| 1236 | 1236 | * Date au format `Ymd` |
| 1237 | 1237 | **/ |
| 1238 | 1238 | function date_anneemoisjour($d) { |
| 1239 | - if (!$d) { |
|
| 1240 | - $d = date('Y-m-d'); |
|
| 1241 | - } |
|
| 1239 | + if (!$d) { |
|
| 1240 | + $d = date('Y-m-d'); |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1243 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1244 | 1244 | } |
| 1245 | 1245 | |
| 1246 | 1246 | /** |
@@ -1256,11 +1256,11 @@ discard block |
||
| 1256 | 1256 | * Date au format `Ym` |
| 1257 | 1257 | **/ |
| 1258 | 1258 | function date_anneemois($d) { |
| 1259 | - if (!$d) { |
|
| 1260 | - $d = date('Y-m-d'); |
|
| 1261 | - } |
|
| 1259 | + if (!$d) { |
|
| 1260 | + $d = date('Y-m-d'); |
|
| 1261 | + } |
|
| 1262 | 1262 | |
| 1263 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1263 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1264 | 1264 | } |
| 1265 | 1265 | |
| 1266 | 1266 | /** |
@@ -1276,13 +1276,13 @@ discard block |
||
| 1276 | 1276 | * Date au lundi de la même semaine au format `Ymd` |
| 1277 | 1277 | **/ |
| 1278 | 1278 | function date_debut_semaine($annee, $mois, $jour) { |
| 1279 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1280 | - if ($w_day == 0) { |
|
| 1281 | - $w_day = 7; |
|
| 1282 | - } // Gaffe: le dimanche est zero |
|
| 1283 | - $debut = $jour - $w_day + 1; |
|
| 1279 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1280 | + if ($w_day == 0) { |
|
| 1281 | + $w_day = 7; |
|
| 1282 | + } // Gaffe: le dimanche est zero |
|
| 1283 | + $debut = $jour - $w_day + 1; |
|
| 1284 | 1284 | |
| 1285 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1285 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1286 | 1286 | } |
| 1287 | 1287 | |
| 1288 | 1288 | /** |
@@ -1298,11 +1298,11 @@ discard block |
||
| 1298 | 1298 | * Date au dimanche de la même semaine au format `Ymd` |
| 1299 | 1299 | **/ |
| 1300 | 1300 | function date_fin_semaine($annee, $mois, $jour) { |
| 1301 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1302 | - if ($w_day == 0) { |
|
| 1303 | - $w_day = 7; |
|
| 1304 | - } // Gaffe: le dimanche est zero |
|
| 1305 | - $debut = $jour - $w_day + 1; |
|
| 1301 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1302 | + if ($w_day == 0) { |
|
| 1303 | + $w_day = 7; |
|
| 1304 | + } // Gaffe: le dimanche est zero |
|
| 1305 | + $debut = $jour - $w_day + 1; |
|
| 1306 | 1306 | |
| 1307 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1307 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1308 | 1308 | } |
@@ -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 | include_spip('inc/filtres_boites'); |
@@ -41,25 +41,25 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function parametres_css_prive() { |
| 43 | 43 | |
| 44 | - $args = []; |
|
| 45 | - $args['v'] = $GLOBALS['spip_version_code']; |
|
| 46 | - $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4); |
|
| 47 | - $args['themes'] = implode(',', lister_themes_prives()); |
|
| 48 | - $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 49 | - // un md5 des menus : si un menu change il faut maj la css |
|
| 50 | - $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 44 | + $args = []; |
|
| 45 | + $args['v'] = $GLOBALS['spip_version_code']; |
|
| 46 | + $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4); |
|
| 47 | + $args['themes'] = implode(',', lister_themes_prives()); |
|
| 48 | + $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 49 | + // un md5 des menus : si un menu change il faut maj la css |
|
| 50 | + $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 51 | 51 | |
| 52 | - $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 52 | + $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 53 | 53 | |
| 54 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 55 | - parse_str($couleurs($c), $c); |
|
| 56 | - $args = array_merge($args, $c); |
|
| 54 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 55 | + parse_str($couleurs($c), $c); |
|
| 56 | + $args = array_merge($args, $c); |
|
| 57 | 57 | |
| 58 | - if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) { |
|
| 59 | - $args['var_mode'] = 'recalcul'; |
|
| 60 | - } |
|
| 58 | + if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) { |
|
| 59 | + $args['var_mode'] = 'recalcul'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return http_build_query($args); |
|
| 62 | + return http_build_query($args); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
@@ -82,91 +82,91 @@ discard block |
||
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | 84 | function chercher_rubrique( |
| 85 | - $titre, |
|
| 86 | - $id_objet, |
|
| 87 | - $id_parent, |
|
| 88 | - $objet, |
|
| 89 | - $id_secteur, |
|
| 90 | - $restreint, |
|
| 91 | - $actionable = false, |
|
| 92 | - $retour_sans_cadre = false |
|
| 85 | + $titre, |
|
| 86 | + $id_objet, |
|
| 87 | + $id_parent, |
|
| 88 | + $objet, |
|
| 89 | + $id_secteur, |
|
| 90 | + $restreint, |
|
| 91 | + $actionable = false, |
|
| 92 | + $retour_sans_cadre = false |
|
| 93 | 93 | ) { |
| 94 | 94 | |
| 95 | - include_spip('inc/autoriser'); |
|
| 96 | - if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) { |
|
| 97 | - return ''; |
|
| 98 | - } |
|
| 99 | - if (!sql_countsel('spip_rubriques')) { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 102 | - $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 103 | - $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 104 | - |
|
| 105 | - if ($id_parent == 0) { |
|
| 106 | - $logo = 'racine-24.png'; |
|
| 107 | - } elseif ($id_secteur == $id_parent) { |
|
| 108 | - $logo = 'secteur-24.png'; |
|
| 109 | - } else { |
|
| 110 | - $logo = 'rubrique-24.png'; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $confirm = ''; |
|
| 114 | - if ($objet == 'rubrique') { |
|
| 115 | - // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | - // confirmation du deplacement |
|
| 117 | - $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet)); |
|
| 118 | - |
|
| 119 | - if ($contient_breves > 0) { |
|
| 120 | - $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 121 | - $scb = _T( |
|
| 122 | - 'avis_deplacement_rubrique', |
|
| 123 | - [ |
|
| 124 | - 'contient_breves' => $contient_breves, |
|
| 125 | - 'scb' => $scb |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 129 | - . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 130 | - . $scb . |
|
| 131 | - "</label></div></div>\n"; |
|
| 132 | - } else { |
|
| 133 | - $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $form .= $confirm; |
|
| 137 | - if ($actionable) { |
|
| 138 | - if (strpos($form, '<select') !== false) { |
|
| 139 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 140 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 141 | - . '</div>'; |
|
| 142 | - } |
|
| 143 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 144 | - if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 145 | - $form = generer_action_auteur( |
|
| 146 | - "editer_$objet", |
|
| 147 | - $id_objet, |
|
| 148 | - self(), |
|
| 149 | - $form, |
|
| 150 | - " method='post' class='submit_plongeur'" |
|
| 151 | - ); |
|
| 152 | - } else { |
|
| 153 | - $form = generer_action_auteur( |
|
| 154 | - 'editer_objet', |
|
| 155 | - "$objet/$id_objet", |
|
| 156 | - self(), |
|
| 157 | - $form, |
|
| 158 | - " method='post' class='submit_plongeur'" |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ($retour_sans_cadre) { |
|
| 164 | - return $form; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - include_spip('inc/presentation'); |
|
| 168 | - |
|
| 169 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 95 | + include_spip('inc/autoriser'); |
|
| 96 | + if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) { |
|
| 97 | + return ''; |
|
| 98 | + } |
|
| 99 | + if (!sql_countsel('spip_rubriques')) { |
|
| 100 | + return ''; |
|
| 101 | + } |
|
| 102 | + $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 103 | + $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 104 | + |
|
| 105 | + if ($id_parent == 0) { |
|
| 106 | + $logo = 'racine-24.png'; |
|
| 107 | + } elseif ($id_secteur == $id_parent) { |
|
| 108 | + $logo = 'secteur-24.png'; |
|
| 109 | + } else { |
|
| 110 | + $logo = 'rubrique-24.png'; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $confirm = ''; |
|
| 114 | + if ($objet == 'rubrique') { |
|
| 115 | + // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | + // confirmation du deplacement |
|
| 117 | + $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet)); |
|
| 118 | + |
|
| 119 | + if ($contient_breves > 0) { |
|
| 120 | + $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 121 | + $scb = _T( |
|
| 122 | + 'avis_deplacement_rubrique', |
|
| 123 | + [ |
|
| 124 | + 'contient_breves' => $contient_breves, |
|
| 125 | + 'scb' => $scb |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 129 | + . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 130 | + . $scb . |
|
| 131 | + "</label></div></div>\n"; |
|
| 132 | + } else { |
|
| 133 | + $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $form .= $confirm; |
|
| 137 | + if ($actionable) { |
|
| 138 | + if (strpos($form, '<select') !== false) { |
|
| 139 | + $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 140 | + . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 141 | + . '</div>'; |
|
| 142 | + } |
|
| 143 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 144 | + if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 145 | + $form = generer_action_auteur( |
|
| 146 | + "editer_$objet", |
|
| 147 | + $id_objet, |
|
| 148 | + self(), |
|
| 149 | + $form, |
|
| 150 | + " method='post' class='submit_plongeur'" |
|
| 151 | + ); |
|
| 152 | + } else { |
|
| 153 | + $form = generer_action_auteur( |
|
| 154 | + 'editer_objet', |
|
| 155 | + "$objet/$id_objet", |
|
| 156 | + self(), |
|
| 157 | + $form, |
|
| 158 | + " method='post' class='submit_plongeur'" |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ($retour_sans_cadre) { |
|
| 164 | + return $form; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + include_spip('inc/presentation'); |
|
| 168 | + |
|
| 169 | + return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -180,24 +180,24 @@ discard block |
||
| 180 | 180 | * @return bool |
| 181 | 181 | */ |
| 182 | 182 | function avoir_visiteurs($past = false, $accepter = true) { |
| 183 | - if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 184 | - return true; |
|
| 185 | - } |
|
| 186 | - if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') { |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 190 | - return true; |
|
| 191 | - } |
|
| 192 | - if (!$past) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return sql_countsel( |
|
| 197 | - 'spip_auteurs', |
|
| 198 | - "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 183 | + if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 184 | + return true; |
|
| 185 | + } |
|
| 186 | + if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if (!$past) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return sql_countsel( |
|
| 197 | + 'spip_auteurs', |
|
| 198 | + "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 199 | 199 | AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))" |
| 200 | - ); |
|
| 200 | + ); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function statuts_articles_visibles($statut_auteur) { |
| 216 | - static $auth = []; |
|
| 217 | - if (!isset($auth[$statut_auteur])) { |
|
| 218 | - $auth[$statut_auteur] = []; |
|
| 219 | - $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 220 | - foreach ($statuts as $s) { |
|
| 221 | - if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 222 | - $auth[$statut_auteur][] = $s; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $auth[$statut_auteur]; |
|
| 216 | + static $auth = []; |
|
| 217 | + if (!isset($auth[$statut_auteur])) { |
|
| 218 | + $auth[$statut_auteur] = []; |
|
| 219 | + $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 220 | + foreach ($statuts as $s) { |
|
| 221 | + if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 222 | + $auth[$statut_auteur][] = $s; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $auth[$statut_auteur]; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -238,38 +238,38 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function traduire_statut_auteur($statut, $attente = '') { |
| 241 | - $plus = ''; |
|
| 242 | - if ($statut == 'nouveau') { |
|
| 243 | - if ($attente) { |
|
| 244 | - $statut = $attente; |
|
| 245 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 246 | - } else { |
|
| 247 | - return _T('info_statut_auteur_a_confirmer'); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $recom = [ |
|
| 252 | - 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 253 | - 'info_redacteurs' => _T('intem_redacteur'), |
|
| 254 | - 'info_visiteurs' => _T('item_visiteur'), |
|
| 255 | - '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 256 | - ]; |
|
| 257 | - if (isset($recom[$statut])) { |
|
| 258 | - return $recom[$statut] . $plus; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // retrouver directement par le statut sinon |
|
| 262 | - if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 263 | - if (isset($recom[$t])) { |
|
| 264 | - return $recom[$t] . $plus; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return _T($t) . $plus; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 271 | - // c'est toujours plus informatif que rien du tout |
|
| 272 | - return $statut; |
|
| 241 | + $plus = ''; |
|
| 242 | + if ($statut == 'nouveau') { |
|
| 243 | + if ($attente) { |
|
| 244 | + $statut = $attente; |
|
| 245 | + $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 246 | + } else { |
|
| 247 | + return _T('info_statut_auteur_a_confirmer'); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $recom = [ |
|
| 252 | + 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 253 | + 'info_redacteurs' => _T('intem_redacteur'), |
|
| 254 | + 'info_visiteurs' => _T('item_visiteur'), |
|
| 255 | + '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 256 | + ]; |
|
| 257 | + if (isset($recom[$statut])) { |
|
| 258 | + return $recom[$statut] . $plus; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // retrouver directement par le statut sinon |
|
| 262 | + if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 263 | + if (isset($recom[$t])) { |
|
| 264 | + return $recom[$t] . $plus; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return _T($t) . $plus; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 271 | + // c'est toujours plus informatif que rien du tout |
|
| 272 | + return $statut; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -280,28 +280,28 @@ discard block |
||
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | 282 | function afficher_qui_edite($id_objet, $objet) { |
| 283 | - static $qui = []; |
|
| 284 | - if (isset($qui[$objet][$id_objet])) { |
|
| 285 | - return $qui[$objet][$id_objet]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if ($GLOBALS['meta']['articles_modif'] == 'non') { |
|
| 289 | - return $qui[$objet][$id_objet] = ''; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - include_spip('inc/drapeau_edition'); |
|
| 293 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 294 | - if (!$modif) { |
|
| 295 | - return $qui[$objet][$id_objet] = ''; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - include_spip('base/objets'); |
|
| 299 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 300 | - if (isset($infos['texte_signale_edition'])) { |
|
| 301 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 283 | + static $qui = []; |
|
| 284 | + if (isset($qui[$objet][$id_objet])) { |
|
| 285 | + return $qui[$objet][$id_objet]; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if ($GLOBALS['meta']['articles_modif'] == 'non') { |
|
| 289 | + return $qui[$objet][$id_objet] = ''; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + include_spip('inc/drapeau_edition'); |
|
| 293 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 294 | + if (!$modif) { |
|
| 295 | + return $qui[$objet][$id_objet] = ''; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + include_spip('base/objets'); |
|
| 299 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 300 | + if (isset($infos['texte_signale_edition'])) { |
|
| 301 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,57 +319,57 @@ discard block |
||
| 319 | 319 | * @return array |
| 320 | 320 | */ |
| 321 | 321 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true) { |
| 322 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 323 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - switch ($quoi) { |
|
| 327 | - case 'redacteurs': |
|
| 328 | - $statut = AUTEURS_MIN_REDAC; |
|
| 329 | - $statut = explode(',', $statut); |
|
| 330 | - if ($en_base) { |
|
| 331 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 332 | - $retire = array_diff($statut, $check); |
|
| 333 | - $statut = array_diff($statut, $retire); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return array_unique($statut); |
|
| 337 | - break; |
|
| 338 | - case 'visiteurs': |
|
| 339 | - $statut = []; |
|
| 340 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 341 | - $exclus = explode(',', $exclus); |
|
| 342 | - if (!$en_base) { |
|
| 343 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 344 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 345 | - } |
|
| 346 | - $s_complement = array_column( |
|
| 347 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 348 | - 'statut' |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - return array_unique(array_merge($statut, $s_complement)); |
|
| 352 | - break; |
|
| 353 | - default: |
|
| 354 | - case 'tous': |
|
| 355 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 356 | - $s_complement = array_column( |
|
| 357 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 358 | - 'statut' |
|
| 359 | - ); |
|
| 360 | - $statut = array_merge($statut, $s_complement); |
|
| 361 | - if ($en_base) { |
|
| 362 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 363 | - $retire = array_diff($statut, $check); |
|
| 364 | - $statut = array_diff($statut, $retire); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return array_unique($statut); |
|
| 368 | - break; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // on arrive jamais ici |
|
| 372 | - return array_values($GLOBALS['liste_des_statuts']); |
|
| 322 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 323 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + switch ($quoi) { |
|
| 327 | + case 'redacteurs': |
|
| 328 | + $statut = AUTEURS_MIN_REDAC; |
|
| 329 | + $statut = explode(',', $statut); |
|
| 330 | + if ($en_base) { |
|
| 331 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 332 | + $retire = array_diff($statut, $check); |
|
| 333 | + $statut = array_diff($statut, $retire); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return array_unique($statut); |
|
| 337 | + break; |
|
| 338 | + case 'visiteurs': |
|
| 339 | + $statut = []; |
|
| 340 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 341 | + $exclus = explode(',', $exclus); |
|
| 342 | + if (!$en_base) { |
|
| 343 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 344 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 345 | + } |
|
| 346 | + $s_complement = array_column( |
|
| 347 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 348 | + 'statut' |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + return array_unique(array_merge($statut, $s_complement)); |
|
| 352 | + break; |
|
| 353 | + default: |
|
| 354 | + case 'tous': |
|
| 355 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 356 | + $s_complement = array_column( |
|
| 357 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 358 | + 'statut' |
|
| 359 | + ); |
|
| 360 | + $statut = array_merge($statut, $s_complement); |
|
| 361 | + if ($en_base) { |
|
| 362 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 363 | + $retire = array_diff($statut, $check); |
|
| 364 | + $statut = array_diff($statut, $retire); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return array_unique($statut); |
|
| 368 | + break; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // on arrive jamais ici |
|
| 372 | + return array_values($GLOBALS['liste_des_statuts']); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,28 +385,28 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 387 | 387 | |
| 388 | - if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | - $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | - ? '' |
|
| 391 | - : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 392 | - |
|
| 393 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | - if ($objet == 'rubrique') { |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return $id_rubrique; |
|
| 388 | + if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | + $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | + ? '' |
|
| 391 | + : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 392 | + |
|
| 393 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | + if ($objet == 'rubrique') { |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return $id_rubrique; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function lien_article_virtuel($virtuel) { |
| 420 | - include_spip('inc/lien'); |
|
| 421 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 420 | + include_spip('inc/lien'); |
|
| 421 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - return propre('[->' . $virtuel . ']'); |
|
| 425 | + return propre('[->' . $virtuel . ']'); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
@@ -445,12 +445,12 @@ discard block |
||
| 445 | 445 | * Code HTML du lien |
| 446 | 446 | */ |
| 447 | 447 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 448 | - include_spip('inc/acces'); |
|
| 449 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 450 | - $args = param_low_sec($op, $args, $lang, 'rss'); |
|
| 451 | - $url = generer_url_public('rss', $args); |
|
| 448 | + include_spip('inc/acces'); |
|
| 449 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 450 | + $args = param_low_sec($op, $args, $lang, 'rss'); |
|
| 451 | + $url = generer_url_public('rss', $args); |
|
| 452 | 452 | |
| 453 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 453 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 454 | 454 | } |
| 455 | 455 | |
| 456 | 456 | |
@@ -462,74 +462,74 @@ discard block |
||
| 462 | 462 | */ |
| 463 | 463 | function alertes_auteur($id_auteur) { |
| 464 | 464 | |
| 465 | - $alertes = []; |
|
| 466 | - |
|
| 467 | - if ( |
|
| 468 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 469 | - and autoriser('detruire', null, null, $id_auteur) |
|
| 470 | - ) { |
|
| 471 | - include_spip('genie/maintenance'); |
|
| 472 | - if ($msg = message_crash_tables()) { |
|
| 473 | - $alertes[] = $msg; |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - if ( |
|
| 478 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 479 | - and $GLOBALS['meta']['message_crash_plugins'] |
|
| 480 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 481 | - and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 482 | - ) { |
|
| 483 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 484 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 488 | - if ( |
|
| 489 | - $a |
|
| 490 | - and is_array($a = unserialize($a)) |
|
| 491 | - and count($a) |
|
| 492 | - ) { |
|
| 493 | - $update = false; |
|
| 494 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 495 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 496 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 497 | - $update = true; |
|
| 498 | - } |
|
| 499 | - if (isset($a[''])) { |
|
| 500 | - $alertes = array_merge($alertes, $a['']); |
|
| 501 | - unset($a['']); |
|
| 502 | - $update = true; |
|
| 503 | - } |
|
| 504 | - if ($update) { |
|
| 505 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - |
|
| 509 | - if ( |
|
| 510 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 511 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 512 | - ) { |
|
| 513 | - include_spip('inc/plugin'); |
|
| 514 | - $alertes[] = plugin_donne_erreurs(); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $alertes = pipeline( |
|
| 518 | - 'alertes_auteur', |
|
| 519 | - [ |
|
| 520 | - 'args' => [ |
|
| 521 | - 'id_auteur' => $id_auteur, |
|
| 522 | - 'exec' => _request('exec'), |
|
| 523 | - ], |
|
| 524 | - 'data' => $alertes |
|
| 525 | - ] |
|
| 526 | - ); |
|
| 527 | - |
|
| 528 | - if ($alertes = array_filter($alertes)) { |
|
| 529 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 530 | - join(' | ', $alertes) |
|
| 531 | - . '</div></div>'; |
|
| 532 | - } |
|
| 465 | + $alertes = []; |
|
| 466 | + |
|
| 467 | + if ( |
|
| 468 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 469 | + and autoriser('detruire', null, null, $id_auteur) |
|
| 470 | + ) { |
|
| 471 | + include_spip('genie/maintenance'); |
|
| 472 | + if ($msg = message_crash_tables()) { |
|
| 473 | + $alertes[] = $msg; |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + if ( |
|
| 478 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 479 | + and $GLOBALS['meta']['message_crash_plugins'] |
|
| 480 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 481 | + and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 482 | + ) { |
|
| 483 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 484 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 488 | + if ( |
|
| 489 | + $a |
|
| 490 | + and is_array($a = unserialize($a)) |
|
| 491 | + and count($a) |
|
| 492 | + ) { |
|
| 493 | + $update = false; |
|
| 494 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 495 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 496 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 497 | + $update = true; |
|
| 498 | + } |
|
| 499 | + if (isset($a[''])) { |
|
| 500 | + $alertes = array_merge($alertes, $a['']); |
|
| 501 | + unset($a['']); |
|
| 502 | + $update = true; |
|
| 503 | + } |
|
| 504 | + if ($update) { |
|
| 505 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + |
|
| 509 | + if ( |
|
| 510 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 511 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 512 | + ) { |
|
| 513 | + include_spip('inc/plugin'); |
|
| 514 | + $alertes[] = plugin_donne_erreurs(); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $alertes = pipeline( |
|
| 518 | + 'alertes_auteur', |
|
| 519 | + [ |
|
| 520 | + 'args' => [ |
|
| 521 | + 'id_auteur' => $id_auteur, |
|
| 522 | + 'exec' => _request('exec'), |
|
| 523 | + ], |
|
| 524 | + 'data' => $alertes |
|
| 525 | + ] |
|
| 526 | + ); |
|
| 527 | + |
|
| 528 | + if ($alertes = array_filter($alertes)) { |
|
| 529 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 530 | + join(' | ', $alertes) |
|
| 531 | + . '</div></div>'; |
|
| 532 | + } |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -539,9 +539,9 @@ discard block |
||
| 539 | 539 | * @return string |
| 540 | 540 | */ |
| 541 | 541 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 542 | - include_spip('inc/presenter_enfants'); |
|
| 542 | + include_spip('inc/presenter_enfants'); |
|
| 543 | 543 | |
| 544 | - return afficher_enfant_rub(intval($id_rubrique)); |
|
| 544 | + return afficher_enfant_rub(intval($id_rubrique)); |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -559,15 +559,15 @@ discard block |
||
| 559 | 559 | * @return string |
| 560 | 560 | */ |
| 561 | 561 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 562 | - $titre = attribut_html($titre); |
|
| 563 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 564 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 565 | - |
|
| 566 | - if (!$titre_lien) { |
|
| 567 | - return $icone; |
|
| 568 | - } else { |
|
| 569 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 570 | - } |
|
| 562 | + $titre = attribut_html($titre); |
|
| 563 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 564 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 565 | + |
|
| 566 | + if (!$titre_lien) { |
|
| 567 | + return $icone; |
|
| 568 | + } else { |
|
| 569 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -586,17 +586,17 @@ discard block |
||
| 586 | 586 | * @return array |
| 587 | 587 | */ |
| 588 | 588 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 589 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 590 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 591 | - return []; |
|
| 592 | - } |
|
| 593 | - $r = reset($res); |
|
| 594 | - if (isset($r['rang_lien'])) { |
|
| 595 | - $l = array_column($res, 'rang_lien', $objet_source); |
|
| 596 | - asort($l); |
|
| 597 | - $l = array_keys($l); |
|
| 598 | - } else { |
|
| 599 | - $l = array_column($res, $objet_source); |
|
| 600 | - } |
|
| 601 | - return $l; |
|
| 589 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 590 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 591 | + return []; |
|
| 592 | + } |
|
| 593 | + $r = reset($res); |
|
| 594 | + if (isset($r['rang_lien'])) { |
|
| 595 | + $l = array_column($res, 'rang_lien', $objet_source); |
|
| 596 | + asort($l); |
|
| 597 | + $l = array_keys($l); |
|
| 598 | + } else { |
|
| 599 | + $l = array_column($res, $objet_source); |
|
| 600 | + } |
|
| 601 | + return $l; |
|
| 602 | 602 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -47,27 +47,27 @@ discard block |
||
| 47 | 47 | * @return array |
| 48 | 48 | **/ |
| 49 | 49 | function liste_plugin_files($dir_plugins = null) { |
| 50 | - static $plugin_files = []; |
|
| 51 | - if (is_null($dir_plugins)) { |
|
| 52 | - $dir_plugins = _DIR_PLUGINS; |
|
| 53 | - } |
|
| 54 | - if ( |
|
| 55 | - !isset($plugin_files[$dir_plugins]) |
|
| 56 | - or (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 57 | - ) { |
|
| 58 | - $plugin_files[$dir_plugins] = []; |
|
| 59 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 60 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - sort($plugin_files[$dir_plugins]); |
|
| 64 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 65 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 66 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 67 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return $plugin_files[$dir_plugins]; |
|
| 50 | + static $plugin_files = []; |
|
| 51 | + if (is_null($dir_plugins)) { |
|
| 52 | + $dir_plugins = _DIR_PLUGINS; |
|
| 53 | + } |
|
| 54 | + if ( |
|
| 55 | + !isset($plugin_files[$dir_plugins]) |
|
| 56 | + or (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 57 | + ) { |
|
| 58 | + $plugin_files[$dir_plugins] = []; |
|
| 59 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 60 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + sort($plugin_files[$dir_plugins]); |
|
| 64 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 65 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 66 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 67 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return $plugin_files[$dir_plugins]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -83,45 +83,45 @@ discard block |
||
| 83 | 83 | * Liste complète des répeertoires |
| 84 | 84 | **/ |
| 85 | 85 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 86 | - $fichiers = []; |
|
| 87 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 88 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 89 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 90 | - if ($dir == '') { |
|
| 91 | - $dir = '.'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (!is_dir($dir)) { |
|
| 95 | - return $fichiers; |
|
| 96 | - } |
|
| 97 | - if (is_plugin_dir($dir, '')) { |
|
| 98 | - $fichiers[] = $dir; |
|
| 99 | - |
|
| 100 | - return $fichiers; |
|
| 101 | - } |
|
| 102 | - if ($max_prof <= 0) { |
|
| 103 | - return $fichiers; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $subdirs = []; |
|
| 107 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 108 | - while (($f = readdir($d)) !== false) { |
|
| 109 | - if ( |
|
| 110 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 111 | - and $f != 'CVS' |
|
| 112 | - and is_dir($f = "$dir/$f") |
|
| 113 | - ) { |
|
| 114 | - $subdirs[] = $f; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - closedir($d); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - foreach ($subdirs as $d) { |
|
| 121 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $fichiers; |
|
| 86 | + $fichiers = []; |
|
| 87 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 88 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 89 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 90 | + if ($dir == '') { |
|
| 91 | + $dir = '.'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (!is_dir($dir)) { |
|
| 95 | + return $fichiers; |
|
| 96 | + } |
|
| 97 | + if (is_plugin_dir($dir, '')) { |
|
| 98 | + $fichiers[] = $dir; |
|
| 99 | + |
|
| 100 | + return $fichiers; |
|
| 101 | + } |
|
| 102 | + if ($max_prof <= 0) { |
|
| 103 | + return $fichiers; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $subdirs = []; |
|
| 107 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 108 | + while (($f = readdir($d)) !== false) { |
|
| 109 | + if ( |
|
| 110 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 111 | + and $f != 'CVS' |
|
| 112 | + and is_dir($f = "$dir/$f") |
|
| 113 | + ) { |
|
| 114 | + $subdirs[] = $f; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + closedir($d); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + foreach ($subdirs as $d) { |
|
| 121 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $fichiers; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -142,27 +142,27 @@ discard block |
||
| 142 | 142 | **/ |
| 143 | 143 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 144 | 144 | |
| 145 | - if (is_array($dir)) { |
|
| 146 | - foreach ($dir as $k => $d) { |
|
| 147 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 148 | - unset($dir[$k]); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $dir; |
|
| 153 | - } |
|
| 154 | - if (is_null($dir_plugins)) { |
|
| 155 | - $dir_plugins = _DIR_PLUGINS; |
|
| 156 | - } |
|
| 157 | - $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 158 | - |
|
| 159 | - foreach ($search as $s) { |
|
| 160 | - if (file_exists($s)) { |
|
| 161 | - return $dir; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return ''; |
|
| 145 | + if (is_array($dir)) { |
|
| 146 | + foreach ($dir as $k => $d) { |
|
| 147 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 148 | + unset($dir[$k]); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $dir; |
|
| 153 | + } |
|
| 154 | + if (is_null($dir_plugins)) { |
|
| 155 | + $dir_plugins = _DIR_PLUGINS; |
|
| 156 | + } |
|
| 157 | + $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 158 | + |
|
| 159 | + foreach ($search as $s) { |
|
| 160 | + if (file_exists($s)) { |
|
| 161 | + return $dir; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return ''; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -189,51 +189,51 @@ discard block |
||
| 189 | 189 | **/ |
| 190 | 190 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 191 | 191 | |
| 192 | - if (!strlen($intervalle)) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 199 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 200 | - $minimum = $regs[1]; |
|
| 201 | - $maximum = $regs[2]; |
|
| 202 | - |
|
| 203 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 204 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 205 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 206 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 207 | - // entre plugins) |
|
| 208 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 209 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 210 | - return true; |
|
| 211 | - } |
|
| 212 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 213 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $minimum_inc = $intervalle[0] == '['; |
|
| 217 | - $maximum_inc = substr($intervalle, -1) == ']'; |
|
| 218 | - |
|
| 219 | - if (strlen($minimum)) { |
|
| 220 | - if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 224 | - return false; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - if (strlen($maximum)) { |
|
| 228 | - if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return true; |
|
| 192 | + if (!strlen($intervalle)) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 199 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 200 | + $minimum = $regs[1]; |
|
| 201 | + $maximum = $regs[2]; |
|
| 202 | + |
|
| 203 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 204 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 205 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 206 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 207 | + // entre plugins) |
|
| 208 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 209 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 212 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 213 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $minimum_inc = $intervalle[0] == '['; |
|
| 217 | + $maximum_inc = substr($intervalle, -1) == ']'; |
|
| 218 | + |
|
| 219 | + if (strlen($minimum)) { |
|
| 220 | + if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + if (strlen($maximum)) { |
|
| 228 | + if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return true; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -250,62 +250,62 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function liste_plugin_valides($liste_plug, $force = false) { |
| 253 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 254 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 255 | - $infos = [ |
|
| 256 | - // lister les extensions qui sont automatiquement actives |
|
| 257 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 258 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 259 | - ]; |
|
| 260 | - |
|
| 261 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 262 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 263 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 264 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 265 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 266 | - $liste_non_classee = [ |
|
| 267 | - 'SPIP' => [ |
|
| 268 | - 'nom' => 'SPIP', |
|
| 269 | - 'etat' => 'stable', |
|
| 270 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 271 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 272 | - 'dir' => '', |
|
| 273 | - ] |
|
| 274 | - ]; |
|
| 275 | - |
|
| 276 | - $invalides = []; |
|
| 277 | - foreach ($liste_ext as $plug) { |
|
| 278 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 279 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - foreach ($liste_plug as $plug) { |
|
| 283 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 284 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 285 | - if (is_array($r)) { |
|
| 286 | - $invalides = array_merge($invalides, $r); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 292 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 293 | - foreach ($liste_plug as $plug) { |
|
| 294 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 295 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 296 | - if (is_array($r)) { |
|
| 297 | - $invalides = array_merge($invalides, $r); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 304 | - |
|
| 305 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 306 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 307 | - |
|
| 308 | - return [$infos, $liste_non_classee, $invalides]; |
|
| 253 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 254 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 255 | + $infos = [ |
|
| 256 | + // lister les extensions qui sont automatiquement actives |
|
| 257 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 258 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 259 | + ]; |
|
| 260 | + |
|
| 261 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 262 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 263 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 264 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 265 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 266 | + $liste_non_classee = [ |
|
| 267 | + 'SPIP' => [ |
|
| 268 | + 'nom' => 'SPIP', |
|
| 269 | + 'etat' => 'stable', |
|
| 270 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 271 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 272 | + 'dir' => '', |
|
| 273 | + ] |
|
| 274 | + ]; |
|
| 275 | + |
|
| 276 | + $invalides = []; |
|
| 277 | + foreach ($liste_ext as $plug) { |
|
| 278 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 279 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + foreach ($liste_plug as $plug) { |
|
| 283 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 284 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 285 | + if (is_array($r)) { |
|
| 286 | + $invalides = array_merge($invalides, $r); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 292 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 293 | + foreach ($liste_plug as $plug) { |
|
| 294 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 295 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 296 | + if (is_array($r)) { |
|
| 297 | + $invalides = array_merge($invalides, $r); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 304 | + |
|
| 305 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 306 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 307 | + |
|
| 308 | + return [$infos, $liste_non_classee, $invalides]; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -325,30 +325,30 @@ discard block |
||
| 325 | 325 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 326 | 326 | */ |
| 327 | 327 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 328 | - $i = $infos[$dir_type][$plug]; |
|
| 329 | - $p = strtoupper($i['prefix']); |
|
| 330 | - $short_desc = [ |
|
| 331 | - 'nom' => $i['nom'], |
|
| 332 | - 'etat' => $i['etat'], |
|
| 333 | - 'version' => $i['version'], |
|
| 334 | - 'dir' => $plug, |
|
| 335 | - 'dir_type' => $dir_type |
|
| 336 | - ]; |
|
| 337 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 338 | - $short_desc['erreur'] = $i['erreur']; |
|
| 339 | - return [$p => $short_desc]; |
|
| 340 | - } |
|
| 341 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 342 | - return [$p => $short_desc]; |
|
| 343 | - } |
|
| 344 | - if ( |
|
| 345 | - !isset($liste[$p]) |
|
| 346 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 347 | - ) { |
|
| 348 | - $liste[$p] = $short_desc; |
|
| 349 | - } |
|
| 350 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 351 | - return $p; |
|
| 328 | + $i = $infos[$dir_type][$plug]; |
|
| 329 | + $p = strtoupper($i['prefix']); |
|
| 330 | + $short_desc = [ |
|
| 331 | + 'nom' => $i['nom'], |
|
| 332 | + 'etat' => $i['etat'], |
|
| 333 | + 'version' => $i['version'], |
|
| 334 | + 'dir' => $plug, |
|
| 335 | + 'dir_type' => $dir_type |
|
| 336 | + ]; |
|
| 337 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 338 | + $short_desc['erreur'] = $i['erreur']; |
|
| 339 | + return [$p => $short_desc]; |
|
| 340 | + } |
|
| 341 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 342 | + return [$p => $short_desc]; |
|
| 343 | + } |
|
| 344 | + if ( |
|
| 345 | + !isset($liste[$p]) |
|
| 346 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 347 | + ) { |
|
| 348 | + $liste[$p] = $short_desc; |
|
| 349 | + } |
|
| 350 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 351 | + return $p; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | /** |
@@ -364,47 +364,47 @@ discard block |
||
| 364 | 364 | * @param array $infos |
| 365 | 365 | */ |
| 366 | 366 | function plugin_fixer_procure(&$liste, &$infos) { |
| 367 | - foreach ($liste as $p => $resume) { |
|
| 368 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 369 | - if (isset($i['procure']) and $i['procure']) { |
|
| 370 | - foreach ($i['procure'] as $procure) { |
|
| 371 | - $p = strtoupper($procure['nom']); |
|
| 372 | - $dir = $resume['dir']; |
|
| 373 | - if ($dir) { |
|
| 374 | - $dir .= '/'; |
|
| 375 | - } |
|
| 376 | - $dir .= 'procure:' . $procure['nom']; |
|
| 377 | - |
|
| 378 | - $procure['etat'] = '?'; |
|
| 379 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 380 | - $procure['dir'] = $dir; |
|
| 381 | - |
|
| 382 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 383 | - // on ajoute cette version a la liste |
|
| 384 | - if ( |
|
| 385 | - !isset($liste[$p]) |
|
| 386 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 387 | - ) { |
|
| 388 | - $liste[$p] = $procure; |
|
| 389 | - |
|
| 390 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 391 | - $infos[$resume['dir_type']][$dir] = [ |
|
| 392 | - 'prefix' => $procure['nom'], |
|
| 393 | - 'nom' => $procure['nom'], |
|
| 394 | - 'etat' => $procure['etat'], |
|
| 395 | - 'version' => $procure['version'], |
|
| 396 | - 'chemin' => [], |
|
| 397 | - 'necessite' => [], |
|
| 398 | - 'utilise' => [], |
|
| 399 | - 'lib' => [], |
|
| 400 | - 'menu' => [], |
|
| 401 | - 'onglet' => [], |
|
| 402 | - 'procure' => [], |
|
| 403 | - ]; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 367 | + foreach ($liste as $p => $resume) { |
|
| 368 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 369 | + if (isset($i['procure']) and $i['procure']) { |
|
| 370 | + foreach ($i['procure'] as $procure) { |
|
| 371 | + $p = strtoupper($procure['nom']); |
|
| 372 | + $dir = $resume['dir']; |
|
| 373 | + if ($dir) { |
|
| 374 | + $dir .= '/'; |
|
| 375 | + } |
|
| 376 | + $dir .= 'procure:' . $procure['nom']; |
|
| 377 | + |
|
| 378 | + $procure['etat'] = '?'; |
|
| 379 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 380 | + $procure['dir'] = $dir; |
|
| 381 | + |
|
| 382 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 383 | + // on ajoute cette version a la liste |
|
| 384 | + if ( |
|
| 385 | + !isset($liste[$p]) |
|
| 386 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 387 | + ) { |
|
| 388 | + $liste[$p] = $procure; |
|
| 389 | + |
|
| 390 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 391 | + $infos[$resume['dir_type']][$dir] = [ |
|
| 392 | + 'prefix' => $procure['nom'], |
|
| 393 | + 'nom' => $procure['nom'], |
|
| 394 | + 'etat' => $procure['etat'], |
|
| 395 | + 'version' => $procure['version'], |
|
| 396 | + 'chemin' => [], |
|
| 397 | + 'necessite' => [], |
|
| 398 | + 'utilise' => [], |
|
| 399 | + 'lib' => [], |
|
| 400 | + 'menu' => [], |
|
| 401 | + 'onglet' => [], |
|
| 402 | + 'procure' => [], |
|
| 403 | + ]; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | 408 | } |
| 409 | 409 | |
| 410 | 410 | /** |
@@ -418,20 +418,20 @@ discard block |
||
| 418 | 418 | * @return array |
| 419 | 419 | */ |
| 420 | 420 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 421 | - foreach ($liste as $prefix => $infos) { |
|
| 422 | - if ( |
|
| 423 | - !$dir_plugins |
|
| 424 | - or ( |
|
| 425 | - defined($infos['dir_type']) |
|
| 426 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 427 | - ) { |
|
| 428 | - $liste[$prefix] = $infos['dir']; |
|
| 429 | - } else { |
|
| 430 | - unset($liste[$prefix]); |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $liste; |
|
| 421 | + foreach ($liste as $prefix => $infos) { |
|
| 422 | + if ( |
|
| 423 | + !$dir_plugins |
|
| 424 | + or ( |
|
| 425 | + defined($infos['dir_type']) |
|
| 426 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 427 | + ) { |
|
| 428 | + $liste[$prefix] = $infos['dir']; |
|
| 429 | + } else { |
|
| 430 | + unset($liste[$prefix]); |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $liste; |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | 437 | /** |
@@ -446,9 +446,9 @@ discard block |
||
| 446 | 446 | * @return array |
| 447 | 447 | */ |
| 448 | 448 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 449 | - include_spip('plugins/installer'); |
|
| 449 | + include_spip('plugins/installer'); |
|
| 450 | 450 | |
| 451 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 451 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | /** |
@@ -479,54 +479,54 @@ discard block |
||
| 479 | 479 | * qui n'ont pas satisfait leurs dépendances |
| 480 | 480 | **/ |
| 481 | 481 | function plugin_trier($infos, $liste_non_classee) { |
| 482 | - $toute_la_liste = $liste_non_classee; |
|
| 483 | - $liste = $ordre = []; |
|
| 484 | - $count = 0; |
|
| 485 | - |
|
| 486 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 487 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 488 | - $count = $c; |
|
| 489 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 490 | - $plug = $resume['dir']; |
|
| 491 | - $dir_type = $resume['dir_type']; |
|
| 492 | - $info1 = $infos[$dir_type][$plug]; |
|
| 493 | - // si des plugins sont necessaires, |
|
| 494 | - // on ne peut inserer qu'apres eux |
|
| 495 | - foreach ($info1['necessite'] as $need) { |
|
| 496 | - $nom = strtoupper($need['nom']); |
|
| 497 | - $compat = $need['compatibilite'] ?? ''; |
|
| 498 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 499 | - $info1 = false; |
|
| 500 | - break; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - if (!$info1) { |
|
| 504 | - continue; |
|
| 505 | - } |
|
| 506 | - // idem si des plugins sont utiles, |
|
| 507 | - // sauf si ils sont de toute facon absents de la liste |
|
| 508 | - foreach ($info1['utilise'] as $need) { |
|
| 509 | - $nom = strtoupper($need['nom']); |
|
| 510 | - $compat = $need['compatibilite'] ?? ''; |
|
| 511 | - if (isset($toute_la_liste[$nom])) { |
|
| 512 | - if ( |
|
| 513 | - !isset($liste[$nom]) or |
|
| 514 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 515 | - ) { |
|
| 516 | - $info1 = false; |
|
| 517 | - break; |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - if ($info1) { |
|
| 522 | - $ordre[$p] = $info1; |
|
| 523 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 524 | - unset($liste_non_classee[$p]); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - return [$liste, $ordre, $liste_non_classee]; |
|
| 482 | + $toute_la_liste = $liste_non_classee; |
|
| 483 | + $liste = $ordre = []; |
|
| 484 | + $count = 0; |
|
| 485 | + |
|
| 486 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 487 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 488 | + $count = $c; |
|
| 489 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 490 | + $plug = $resume['dir']; |
|
| 491 | + $dir_type = $resume['dir_type']; |
|
| 492 | + $info1 = $infos[$dir_type][$plug]; |
|
| 493 | + // si des plugins sont necessaires, |
|
| 494 | + // on ne peut inserer qu'apres eux |
|
| 495 | + foreach ($info1['necessite'] as $need) { |
|
| 496 | + $nom = strtoupper($need['nom']); |
|
| 497 | + $compat = $need['compatibilite'] ?? ''; |
|
| 498 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 499 | + $info1 = false; |
|
| 500 | + break; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + if (!$info1) { |
|
| 504 | + continue; |
|
| 505 | + } |
|
| 506 | + // idem si des plugins sont utiles, |
|
| 507 | + // sauf si ils sont de toute facon absents de la liste |
|
| 508 | + foreach ($info1['utilise'] as $need) { |
|
| 509 | + $nom = strtoupper($need['nom']); |
|
| 510 | + $compat = $need['compatibilite'] ?? ''; |
|
| 511 | + if (isset($toute_la_liste[$nom])) { |
|
| 512 | + if ( |
|
| 513 | + !isset($liste[$nom]) or |
|
| 514 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 515 | + ) { |
|
| 516 | + $info1 = false; |
|
| 517 | + break; |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + if ($info1) { |
|
| 522 | + $ordre[$p] = $info1; |
|
| 523 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 524 | + unset($liste_non_classee[$p]); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + return [$liste, $ordre, $liste_non_classee]; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | /** |
@@ -543,40 +543,40 @@ discard block |
||
| 543 | 543 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 544 | 544 | **/ |
| 545 | 545 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = []) { |
| 546 | - static $erreurs = []; |
|
| 547 | - |
|
| 548 | - if (!is_array($liste)) { |
|
| 549 | - $liste = []; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 553 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 554 | - |
|
| 555 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 556 | - $dir_type = $resume['dir_type']; |
|
| 557 | - $plug = $resume['dir']; |
|
| 558 | - $k = $infos[$dir_type][$plug]; |
|
| 559 | - |
|
| 560 | - $plug = constant($dir_type) . $plug; |
|
| 561 | - if (!isset($msg[$p])) { |
|
| 562 | - if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 563 | - $msg[$p] = [$resume['erreur']]; |
|
| 564 | - } |
|
| 565 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 566 | - $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 567 | - } |
|
| 568 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 569 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 570 | - } |
|
| 571 | - } else { |
|
| 572 | - foreach ($msg[$p] as $c => $l) { |
|
| 573 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - $erreurs[$plug] = $msg[$p]; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 546 | + static $erreurs = []; |
|
| 547 | + |
|
| 548 | + if (!is_array($liste)) { |
|
| 549 | + $liste = []; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 553 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 554 | + |
|
| 555 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 556 | + $dir_type = $resume['dir_type']; |
|
| 557 | + $plug = $resume['dir']; |
|
| 558 | + $k = $infos[$dir_type][$plug]; |
|
| 559 | + |
|
| 560 | + $plug = constant($dir_type) . $plug; |
|
| 561 | + if (!isset($msg[$p])) { |
|
| 562 | + if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 563 | + $msg[$p] = [$resume['erreur']]; |
|
| 564 | + } |
|
| 565 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 566 | + $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 567 | + } |
|
| 568 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 569 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 570 | + } |
|
| 571 | + } else { |
|
| 572 | + foreach ($msg[$p] as $c => $l) { |
|
| 573 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + $erreurs[$plug] = $msg[$p]; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -591,25 +591,25 @@ discard block |
||
| 591 | 591 | * - Liste des erreurs ou code HTML des erreurs |
| 592 | 592 | **/ |
| 593 | 593 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 594 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 595 | - return $raw ? [] : ''; |
|
| 596 | - } |
|
| 597 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 598 | - // Compat ancienne version |
|
| 599 | - if (!$list) { |
|
| 600 | - $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 601 | - } elseif (!$raw) { |
|
| 602 | - foreach ($list as $plug => $msg) { |
|
| 603 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 604 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 605 | - } |
|
| 606 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 607 | - } |
|
| 608 | - if ($raz) { |
|
| 609 | - effacer_meta('plugin_erreur_activation'); |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - return $list; |
|
| 594 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 595 | + return $raw ? [] : ''; |
|
| 596 | + } |
|
| 597 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 598 | + // Compat ancienne version |
|
| 599 | + if (!$list) { |
|
| 600 | + $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 601 | + } elseif (!$raw) { |
|
| 602 | + foreach ($list as $plug => $msg) { |
|
| 603 | + $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 604 | + . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 605 | + } |
|
| 606 | + $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 607 | + } |
|
| 608 | + if ($raz) { |
|
| 609 | + effacer_meta('plugin_erreur_activation'); |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + return $list; |
|
| 613 | 613 | } |
| 614 | 614 | |
| 615 | 615 | /** |
@@ -629,21 +629,21 @@ discard block |
||
| 629 | 629 | * |
| 630 | 630 | **/ |
| 631 | 631 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 632 | - $msg = []; |
|
| 633 | - foreach ($n as $need) { |
|
| 634 | - $id = strtoupper($need['nom']); |
|
| 635 | - $r = plugin_controler_necessite( |
|
| 636 | - $liste, |
|
| 637 | - $id, |
|
| 638 | - $need['compatibilite'] ?? '', |
|
| 639 | - $balise |
|
| 640 | - ); |
|
| 641 | - if ($r) { |
|
| 642 | - $msg[] = $r; |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - |
|
| 646 | - return $msg; |
|
| 632 | + $msg = []; |
|
| 633 | + foreach ($n as $need) { |
|
| 634 | + $id = strtoupper($need['nom']); |
|
| 635 | + $r = plugin_controler_necessite( |
|
| 636 | + $liste, |
|
| 637 | + $id, |
|
| 638 | + $need['compatibilite'] ?? '', |
|
| 639 | + $balise |
|
| 640 | + ); |
|
| 641 | + if ($r) { |
|
| 642 | + $msg[] = $r; |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + |
|
| 646 | + return $msg; |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | /** |
@@ -665,19 +665,19 @@ discard block |
||
| 665 | 665 | * Message d'erreur lorsque la dépendance est absente. |
| 666 | 666 | **/ |
| 667 | 667 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 668 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 669 | - return ''; |
|
| 670 | - } |
|
| 671 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 672 | - if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 673 | - return ''; |
|
| 674 | - } |
|
| 675 | - return plugin_message_incompatibilite( |
|
| 676 | - $intervalle, |
|
| 677 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 678 | - $nom, |
|
| 679 | - $balise |
|
| 680 | - ); |
|
| 668 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 669 | + return ''; |
|
| 670 | + } |
|
| 671 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 672 | + if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 673 | + return ''; |
|
| 674 | + } |
|
| 675 | + return plugin_message_incompatibilite( |
|
| 676 | + $intervalle, |
|
| 677 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 678 | + $nom, |
|
| 679 | + $balise |
|
| 680 | + ); |
|
| 681 | 681 | } |
| 682 | 682 | |
| 683 | 683 | /** |
@@ -694,70 +694,70 @@ discard block |
||
| 694 | 694 | */ |
| 695 | 695 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 696 | 696 | |
| 697 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 698 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 699 | - $type = 'plugin'; |
|
| 700 | - if ($nom === 'SPIP') { |
|
| 701 | - $type = 'spip'; |
|
| 702 | - } elseif ($nom === 'PHP') { |
|
| 703 | - $type = 'php'; |
|
| 704 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 705 | - $type = 'extension_php'; |
|
| 706 | - [, $nom] = explode(':', $nom, 2); |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 710 | - $minimum = $regs[1]; |
|
| 711 | - $maximum = $regs[2]; |
|
| 712 | - |
|
| 713 | - $minimum_inclus = $intervalle[0] == '['; |
|
| 714 | - $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 715 | - |
|
| 716 | - if (strlen($minimum)) { |
|
| 717 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 718 | - return _T("plugin_${balise}_${type}", [ |
|
| 719 | - 'plugin' => $nom, |
|
| 720 | - 'version' => ' ≥ ' . $minimum |
|
| 721 | - ]); |
|
| 722 | - } |
|
| 723 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 724 | - return _T("plugin_${balise}_${type}", [ |
|
| 725 | - 'plugin' => $nom, |
|
| 726 | - 'version' => ' > ' . $minimum |
|
| 727 | - ]); |
|
| 728 | - } |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - if (strlen($maximum)) { |
|
| 732 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 733 | - return _T("plugin_${balise}_${type}", [ |
|
| 734 | - 'plugin' => $nom, |
|
| 735 | - 'version' => ' ≤ ' . $maximum |
|
| 736 | - ]); |
|
| 737 | - } |
|
| 738 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 739 | - return _T("plugin_${balise}_plugin", [ |
|
| 740 | - 'plugin' => $nom, |
|
| 741 | - 'version' => ' < ' . $maximum |
|
| 742 | - ]); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - |
|
| 747 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 748 | - // - un 'utilise' sans version. |
|
| 749 | - // - un 'php' sans version. |
|
| 750 | - return _T("plugin_necessite_${type}_sans_version", ['plugin' => $nom]); |
|
| 697 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 698 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 699 | + $type = 'plugin'; |
|
| 700 | + if ($nom === 'SPIP') { |
|
| 701 | + $type = 'spip'; |
|
| 702 | + } elseif ($nom === 'PHP') { |
|
| 703 | + $type = 'php'; |
|
| 704 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 705 | + $type = 'extension_php'; |
|
| 706 | + [, $nom] = explode(':', $nom, 2); |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 710 | + $minimum = $regs[1]; |
|
| 711 | + $maximum = $regs[2]; |
|
| 712 | + |
|
| 713 | + $minimum_inclus = $intervalle[0] == '['; |
|
| 714 | + $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 715 | + |
|
| 716 | + if (strlen($minimum)) { |
|
| 717 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 718 | + return _T("plugin_${balise}_${type}", [ |
|
| 719 | + 'plugin' => $nom, |
|
| 720 | + 'version' => ' ≥ ' . $minimum |
|
| 721 | + ]); |
|
| 722 | + } |
|
| 723 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 724 | + return _T("plugin_${balise}_${type}", [ |
|
| 725 | + 'plugin' => $nom, |
|
| 726 | + 'version' => ' > ' . $minimum |
|
| 727 | + ]); |
|
| 728 | + } |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + if (strlen($maximum)) { |
|
| 732 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 733 | + return _T("plugin_${balise}_${type}", [ |
|
| 734 | + 'plugin' => $nom, |
|
| 735 | + 'version' => ' ≤ ' . $maximum |
|
| 736 | + ]); |
|
| 737 | + } |
|
| 738 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 739 | + return _T("plugin_${balise}_plugin", [ |
|
| 740 | + 'plugin' => $nom, |
|
| 741 | + 'version' => ' < ' . $maximum |
|
| 742 | + ]); |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + |
|
| 747 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 748 | + // - un 'utilise' sans version. |
|
| 749 | + // - un 'php' sans version. |
|
| 750 | + return _T("plugin_necessite_${type}_sans_version", ['plugin' => $nom]); |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | |
| 754 | 754 | function plugin_controler_lib($lib, $url) { |
| 755 | - /* Feature sortie du core, voir STP |
|
| 755 | + /* Feature sortie du core, voir STP |
|
| 756 | 756 | * if ($url) { |
| 757 | 757 | include_spip('inc/charger_plugin'); |
| 758 | 758 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 759 | 759 | }*/ |
| 760 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 760 | + return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | |
@@ -772,7 +772,7 @@ discard block |
||
| 772 | 772 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 773 | 773 | **/ |
| 774 | 774 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 775 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 775 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 776 | 776 | } |
| 777 | 777 | |
| 778 | 778 | |
@@ -799,116 +799,116 @@ discard block |
||
| 799 | 799 | **/ |
| 800 | 800 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 801 | 801 | |
| 802 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 803 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 804 | - |
|
| 805 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 806 | - if (!$cache and !spip_connect()) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - |
|
| 810 | - if ($operation != 'raz') { |
|
| 811 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 812 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 813 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 814 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 815 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 816 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 817 | - } |
|
| 818 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 819 | - // on les reinjecte ici |
|
| 820 | - if ( |
|
| 821 | - isset($GLOBALS['meta']['plugin_attente']) |
|
| 822 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 823 | - ) { |
|
| 824 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - if ($operation == 'ajoute') { |
|
| 828 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 829 | - } elseif ($operation == 'enleve') { |
|
| 830 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 831 | - } else { |
|
| 832 | - $plugin = $plugin_valides; |
|
| 833 | - } |
|
| 834 | - } |
|
| 835 | - $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 836 | - |
|
| 837 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 838 | - if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 839 | - $plugin = $ajouter_dependances($plugin); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - // recharger le xml des plugins a activer |
|
| 843 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 844 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 845 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 846 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 847 | - [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 848 | - // trouver l'ordre d'activation |
|
| 849 | - [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 850 | - if ($invalides or $reste) { |
|
| 851 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 852 | - } |
|
| 853 | - |
|
| 854 | - // Ignorer les plugins necessitant une lib absente |
|
| 855 | - // et preparer la meta d'entete Http |
|
| 856 | - $err = $msg = $header = []; |
|
| 857 | - foreach ($plugin_valides as $p => $resume) { |
|
| 858 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 859 | - if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 860 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 861 | - } |
|
| 862 | - if ($resume['dir']) { |
|
| 863 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 864 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 865 | - $err[$p] = $resume; |
|
| 866 | - $msg[$p][] = $l; |
|
| 867 | - unset($plugin_valides[$p]); |
|
| 868 | - } |
|
| 869 | - } |
|
| 870 | - } |
|
| 871 | - } |
|
| 872 | - if ($err) { |
|
| 873 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 874 | - } |
|
| 875 | - |
|
| 876 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 877 | - effacer_meta('message_crash_plugins'); |
|
| 878 | - } |
|
| 879 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 880 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 881 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 882 | - $header = strtolower(implode(',', $header)); |
|
| 883 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 884 | - ecrire_fichier( |
|
| 885 | - _DIR_VAR . 'config.txt', |
|
| 886 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 887 | - ); |
|
| 888 | - } else { |
|
| 889 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 890 | - } |
|
| 891 | - // generer charger_plugins_chemin.php |
|
| 892 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 893 | - // generer les fichiers |
|
| 894 | - // - charger_plugins_options.php |
|
| 895 | - // - charger_plugins_fonctions.php |
|
| 896 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 897 | - // charger les chemins des plugins et les fichiers d'options |
|
| 898 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 899 | - plugins_amorcer_plugins_actifs(); |
|
| 900 | - // mise a jour de la matrice des pipelines |
|
| 901 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 902 | - // generer le fichier _CACHE_PIPELINE |
|
| 903 | - pipeline_precompile($prepend_code); |
|
| 904 | - |
|
| 905 | - if (spip_connect()) { |
|
| 906 | - // lancer et initialiser les nouveaux crons ! |
|
| 907 | - include_spip('inc/genie'); |
|
| 908 | - genie_queue_watch_dist(); |
|
| 909 | - } |
|
| 910 | - |
|
| 911 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 802 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 803 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 804 | + |
|
| 805 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 806 | + if (!$cache and !spip_connect()) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + |
|
| 810 | + if ($operation != 'raz') { |
|
| 811 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 812 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 813 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 814 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 815 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 816 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 817 | + } |
|
| 818 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 819 | + // on les reinjecte ici |
|
| 820 | + if ( |
|
| 821 | + isset($GLOBALS['meta']['plugin_attente']) |
|
| 822 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 823 | + ) { |
|
| 824 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + if ($operation == 'ajoute') { |
|
| 828 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 829 | + } elseif ($operation == 'enleve') { |
|
| 830 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 831 | + } else { |
|
| 832 | + $plugin = $plugin_valides; |
|
| 833 | + } |
|
| 834 | + } |
|
| 835 | + $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 836 | + |
|
| 837 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 838 | + if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 839 | + $plugin = $ajouter_dependances($plugin); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + // recharger le xml des plugins a activer |
|
| 843 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 844 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 845 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 846 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 847 | + [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 848 | + // trouver l'ordre d'activation |
|
| 849 | + [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 850 | + if ($invalides or $reste) { |
|
| 851 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 852 | + } |
|
| 853 | + |
|
| 854 | + // Ignorer les plugins necessitant une lib absente |
|
| 855 | + // et preparer la meta d'entete Http |
|
| 856 | + $err = $msg = $header = []; |
|
| 857 | + foreach ($plugin_valides as $p => $resume) { |
|
| 858 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 859 | + if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 860 | + $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 861 | + } |
|
| 862 | + if ($resume['dir']) { |
|
| 863 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 864 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 865 | + $err[$p] = $resume; |
|
| 866 | + $msg[$p][] = $l; |
|
| 867 | + unset($plugin_valides[$p]); |
|
| 868 | + } |
|
| 869 | + } |
|
| 870 | + } |
|
| 871 | + } |
|
| 872 | + if ($err) { |
|
| 873 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 874 | + } |
|
| 875 | + |
|
| 876 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 877 | + effacer_meta('message_crash_plugins'); |
|
| 878 | + } |
|
| 879 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 880 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 881 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 882 | + $header = strtolower(implode(',', $header)); |
|
| 883 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 884 | + ecrire_fichier( |
|
| 885 | + _DIR_VAR . 'config.txt', |
|
| 886 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 887 | + ); |
|
| 888 | + } else { |
|
| 889 | + @unlink(_DIR_VAR . 'config.txt'); |
|
| 890 | + } |
|
| 891 | + // generer charger_plugins_chemin.php |
|
| 892 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 893 | + // generer les fichiers |
|
| 894 | + // - charger_plugins_options.php |
|
| 895 | + // - charger_plugins_fonctions.php |
|
| 896 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 897 | + // charger les chemins des plugins et les fichiers d'options |
|
| 898 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 899 | + plugins_amorcer_plugins_actifs(); |
|
| 900 | + // mise a jour de la matrice des pipelines |
|
| 901 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 902 | + // generer le fichier _CACHE_PIPELINE |
|
| 903 | + pipeline_precompile($prepend_code); |
|
| 904 | + |
|
| 905 | + if (spip_connect()) { |
|
| 906 | + // lancer et initialiser les nouveaux crons ! |
|
| 907 | + include_spip('inc/genie'); |
|
| 908 | + genie_queue_watch_dist(); |
|
| 909 | + } |
|
| 910 | + |
|
| 911 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 912 | 912 | } |
| 913 | 913 | |
| 914 | 914 | /** |
@@ -927,74 +927,74 @@ discard block |
||
| 927 | 927 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 928 | 928 | **/ |
| 929 | 929 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 930 | - $chemins = [ |
|
| 931 | - 'public' => [], |
|
| 932 | - 'prive' => [] |
|
| 933 | - ]; |
|
| 934 | - $contenu = ''; |
|
| 935 | - foreach ($ordre as $p => $info) { |
|
| 936 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 937 | - if (isset($plugin_valides[$p])) { |
|
| 938 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 939 | - $plug = $plugin_valides[$p]['dir']; |
|
| 940 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 941 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 942 | - |
|
| 943 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 944 | - |
|
| 945 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 946 | - if ( |
|
| 947 | - $prefix !== 'SPIP' |
|
| 948 | - and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 949 | - ) { |
|
| 950 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 951 | - if (!$info['chemin']) { |
|
| 952 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 953 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 954 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 955 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 956 | - } |
|
| 957 | - } |
|
| 958 | - else { |
|
| 959 | - foreach ($info['chemin'] as $chemin) { |
|
| 960 | - if ( |
|
| 961 | - !isset($chemin['version']) or plugin_version_compatible( |
|
| 962 | - $chemin['version'], |
|
| 963 | - $GLOBALS['spip_version_branche'], |
|
| 964 | - 'spip' |
|
| 965 | - ) |
|
| 966 | - ) { |
|
| 967 | - $dir = $chemin['path']; |
|
| 968 | - if (strlen($dir) and $dir[0] == '/') { |
|
| 969 | - $dir = substr($dir, 1); |
|
| 970 | - } |
|
| 971 | - if (strlen($dir) and $dir == './') { |
|
| 972 | - $dir = ''; |
|
| 973 | - } |
|
| 974 | - if (strlen($dir)) { |
|
| 975 | - $dir = rtrim($dir, '/') . '/'; |
|
| 976 | - } |
|
| 977 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 978 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 979 | - } |
|
| 980 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 981 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 982 | - } |
|
| 983 | - } |
|
| 984 | - } |
|
| 985 | - } |
|
| 986 | - } |
|
| 987 | - } |
|
| 988 | - } |
|
| 989 | - if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 990 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 991 | - ',', |
|
| 992 | - array_reverse($chemins['public']) |
|
| 993 | - ) . "]);\n" |
|
| 994 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 995 | - } |
|
| 996 | - |
|
| 997 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 930 | + $chemins = [ |
|
| 931 | + 'public' => [], |
|
| 932 | + 'prive' => [] |
|
| 933 | + ]; |
|
| 934 | + $contenu = ''; |
|
| 935 | + foreach ($ordre as $p => $info) { |
|
| 936 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 937 | + if (isset($plugin_valides[$p])) { |
|
| 938 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 939 | + $plug = $plugin_valides[$p]['dir']; |
|
| 940 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 941 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 942 | + |
|
| 943 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 944 | + |
|
| 945 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 946 | + if ( |
|
| 947 | + $prefix !== 'SPIP' |
|
| 948 | + and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 949 | + ) { |
|
| 950 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 951 | + if (!$info['chemin']) { |
|
| 952 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 953 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 954 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 955 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 956 | + } |
|
| 957 | + } |
|
| 958 | + else { |
|
| 959 | + foreach ($info['chemin'] as $chemin) { |
|
| 960 | + if ( |
|
| 961 | + !isset($chemin['version']) or plugin_version_compatible( |
|
| 962 | + $chemin['version'], |
|
| 963 | + $GLOBALS['spip_version_branche'], |
|
| 964 | + 'spip' |
|
| 965 | + ) |
|
| 966 | + ) { |
|
| 967 | + $dir = $chemin['path']; |
|
| 968 | + if (strlen($dir) and $dir[0] == '/') { |
|
| 969 | + $dir = substr($dir, 1); |
|
| 970 | + } |
|
| 971 | + if (strlen($dir) and $dir == './') { |
|
| 972 | + $dir = ''; |
|
| 973 | + } |
|
| 974 | + if (strlen($dir)) { |
|
| 975 | + $dir = rtrim($dir, '/') . '/'; |
|
| 976 | + } |
|
| 977 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 978 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 979 | + } |
|
| 980 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 981 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 982 | + } |
|
| 983 | + } |
|
| 984 | + } |
|
| 985 | + } |
|
| 986 | + } |
|
| 987 | + } |
|
| 988 | + } |
|
| 989 | + if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 990 | + $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 991 | + ',', |
|
| 992 | + array_reverse($chemins['public']) |
|
| 993 | + ) . "]);\n" |
|
| 994 | + . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 995 | + } |
|
| 996 | + |
|
| 997 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 998 | 998 | } |
| 999 | 999 | |
| 1000 | 1000 | /** |
@@ -1012,67 +1012,67 @@ discard block |
||
| 1012 | 1012 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 1013 | 1013 | **/ |
| 1014 | 1014 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1015 | - $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1016 | - $boutons = []; |
|
| 1017 | - $onglets = []; |
|
| 1018 | - $sign = ''; |
|
| 1019 | - |
|
| 1020 | - foreach ($ordre as $p => $info) { |
|
| 1021 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1022 | - if (isset($plugin_valides[$p])) { |
|
| 1023 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1024 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1025 | - $dir = constant($dir_type); |
|
| 1026 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1027 | - if ($info['menu']) { |
|
| 1028 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1029 | - } |
|
| 1030 | - if ($info['onglet']) { |
|
| 1031 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1032 | - } |
|
| 1033 | - foreach ($contenu as $charge => $v) { |
|
| 1034 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1035 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1036 | - // donc ni sa relecture, ni sa detection |
|
| 1037 | - if ( |
|
| 1038 | - !isset($info[$charge]) |
|
| 1039 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 1040 | - and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 1041 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1042 | - ) { |
|
| 1043 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1044 | - $info[$charge] = [$file]; |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - if (isset($info[$charge])) { |
|
| 1048 | - $files = $info[$charge]; |
|
| 1049 | - foreach ($files as $k => $file) { |
|
| 1050 | - // on genere un if file_exists devant chaque include |
|
| 1051 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1052 | - $file = trim($file); |
|
| 1053 | - if ( |
|
| 1054 | - !is_readable("$dir$plug/$file") |
|
| 1055 | - // uniquement pour les paquet.xml |
|
| 1056 | - and file_exists("$dir$plug/paquet.xml") |
|
| 1057 | - ) { |
|
| 1058 | - unset($info[$charge][$k]); |
|
| 1059 | - } else { |
|
| 1060 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1061 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1062 | - } |
|
| 1063 | - } |
|
| 1064 | - } |
|
| 1065 | - } |
|
| 1066 | - $sign .= md5(serialize($info)); |
|
| 1067 | - } |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1071 | - $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1072 | - . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1073 | - |
|
| 1074 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1075 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1015 | + $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1016 | + $boutons = []; |
|
| 1017 | + $onglets = []; |
|
| 1018 | + $sign = ''; |
|
| 1019 | + |
|
| 1020 | + foreach ($ordre as $p => $info) { |
|
| 1021 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1022 | + if (isset($plugin_valides[$p])) { |
|
| 1023 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1024 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1025 | + $dir = constant($dir_type); |
|
| 1026 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1027 | + if ($info['menu']) { |
|
| 1028 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1029 | + } |
|
| 1030 | + if ($info['onglet']) { |
|
| 1031 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1032 | + } |
|
| 1033 | + foreach ($contenu as $charge => $v) { |
|
| 1034 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1035 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1036 | + // donc ni sa relecture, ni sa detection |
|
| 1037 | + if ( |
|
| 1038 | + !isset($info[$charge]) |
|
| 1039 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 1040 | + and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 1041 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1042 | + ) { |
|
| 1043 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1044 | + $info[$charge] = [$file]; |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + if (isset($info[$charge])) { |
|
| 1048 | + $files = $info[$charge]; |
|
| 1049 | + foreach ($files as $k => $file) { |
|
| 1050 | + // on genere un if file_exists devant chaque include |
|
| 1051 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1052 | + $file = trim($file); |
|
| 1053 | + if ( |
|
| 1054 | + !is_readable("$dir$plug/$file") |
|
| 1055 | + // uniquement pour les paquet.xml |
|
| 1056 | + and file_exists("$dir$plug/paquet.xml") |
|
| 1057 | + ) { |
|
| 1058 | + unset($info[$charge][$k]); |
|
| 1059 | + } else { |
|
| 1060 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1061 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1062 | + } |
|
| 1063 | + } |
|
| 1064 | + } |
|
| 1065 | + } |
|
| 1066 | + $sign .= md5(serialize($info)); |
|
| 1067 | + } |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1071 | + $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1072 | + . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1073 | + |
|
| 1074 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1075 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1076 | 1076 | } |
| 1077 | 1077 | |
| 1078 | 1078 | /** |
@@ -1091,24 +1091,24 @@ discard block |
||
| 1091 | 1091 | * @return string Code php |
| 1092 | 1092 | */ |
| 1093 | 1093 | function plugin_ongletbouton($nom, $val) { |
| 1094 | - if (!$val) { |
|
| 1095 | - $val = []; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - $val = serialize($val); |
|
| 1099 | - $md5 = md5($val); |
|
| 1100 | - |
|
| 1101 | - if (!defined("_UPDATED_$nom")) { |
|
| 1102 | - define("_UPDATED_$nom", $val); |
|
| 1103 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1104 | - } |
|
| 1105 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1106 | - |
|
| 1107 | - return |
|
| 1108 | - "if (!function_exists('$nom')) {\n" |
|
| 1109 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1110 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1111 | - . "}\n"; |
|
| 1094 | + if (!$val) { |
|
| 1095 | + $val = []; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + $val = serialize($val); |
|
| 1099 | + $md5 = md5($val); |
|
| 1100 | + |
|
| 1101 | + if (!defined("_UPDATED_$nom")) { |
|
| 1102 | + define("_UPDATED_$nom", $val); |
|
| 1103 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1104 | + } |
|
| 1105 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1106 | + |
|
| 1107 | + return |
|
| 1108 | + "if (!function_exists('$nom')) {\n" |
|
| 1109 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1110 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1111 | + . "}\n"; |
|
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | 1114 | /** |
@@ -1123,15 +1123,15 @@ discard block |
||
| 1123 | 1123 | **/ |
| 1124 | 1124 | function plugins_amorcer_plugins_actifs() { |
| 1125 | 1125 | |
| 1126 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1127 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1128 | - } |
|
| 1126 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1127 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1128 | + } |
|
| 1129 | 1129 | |
| 1130 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1131 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1132 | - } else { |
|
| 1133 | - spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1134 | - } |
|
| 1130 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1131 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1132 | + } else { |
|
| 1133 | + spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1134 | + } |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | /** |
@@ -1154,140 +1154,140 @@ discard block |
||
| 1154 | 1154 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1155 | 1155 | **/ |
| 1156 | 1156 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1157 | - static $liste_pipe_manquants = []; |
|
| 1158 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1159 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - $prepend_code = []; |
|
| 1163 | - |
|
| 1164 | - foreach ($ordre as $p => $info) { |
|
| 1165 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1166 | - if (isset($plugin_valides[$p])) { |
|
| 1167 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1168 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1169 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1170 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1171 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1172 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1173 | - $nom = $pipe['nom']; |
|
| 1174 | - if (isset($pipe['action'])) { |
|
| 1175 | - $action = $pipe['action']; |
|
| 1176 | - } else { |
|
| 1177 | - $action = $nom; |
|
| 1178 | - } |
|
| 1179 | - $nomlower = strtolower($nom); |
|
| 1180 | - if ( |
|
| 1181 | - $nomlower != $nom |
|
| 1182 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1183 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1184 | - ) { |
|
| 1185 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1186 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1187 | - } |
|
| 1188 | - $nom = $nomlower; |
|
| 1189 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1190 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1191 | - $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1192 | - } |
|
| 1193 | - if ($action) { |
|
| 1194 | - if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1195 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1196 | - ',(\|\||$),', |
|
| 1197 | - "|$prefix$action\\1", |
|
| 1198 | - $GLOBALS['spip_pipeline'][$nom], |
|
| 1199 | - 1 |
|
| 1200 | - ); |
|
| 1201 | - } |
|
| 1202 | - if (isset($pipe['inclure'])) { |
|
| 1203 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1204 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1205 | - } |
|
| 1206 | - } |
|
| 1207 | - } |
|
| 1208 | - } |
|
| 1209 | - if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1210 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1211 | - $prepend_code['taches_generales_cron'] = ''; |
|
| 1212 | - } |
|
| 1213 | - foreach ($info['genie'] as $genie) { |
|
| 1214 | - $nom = $prefix . $genie['nom']; |
|
| 1215 | - $periode = max(60, intval($genie['periode'])); |
|
| 1216 | - if (charger_fonction($nom, 'genie', true)) { |
|
| 1217 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1218 | - } else { |
|
| 1219 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1220 | - } |
|
| 1221 | - } |
|
| 1222 | - } |
|
| 1223 | - if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1224 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1225 | - $prepend_code['insert_head_css'] = ''; |
|
| 1226 | - } |
|
| 1227 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1228 | - $prepend_code['header_prive_css'] = ''; |
|
| 1229 | - } |
|
| 1230 | - foreach ($info['style'] as $style) { |
|
| 1231 | - if (isset($style['path']) and $style['path']) { |
|
| 1232 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1233 | - } else { |
|
| 1234 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1235 | - } |
|
| 1236 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1237 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1238 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1239 | - } |
|
| 1240 | - $code .= "/>';\n"; |
|
| 1241 | - if ($style['type'] != 'prive') { |
|
| 1242 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1243 | - } |
|
| 1244 | - if ($style['type'] != 'public') { |
|
| 1245 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1246 | - } |
|
| 1247 | - } |
|
| 1248 | - } |
|
| 1249 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1250 | - $prepend_code['insert_head'] = ''; |
|
| 1251 | - } |
|
| 1252 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1253 | - $prepend_code['header_prive'] = ''; |
|
| 1254 | - } |
|
| 1255 | - if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1256 | - foreach ($info['script'] as $script) { |
|
| 1257 | - if (isset($script['path']) and $script['path']) { |
|
| 1258 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1259 | - } else { |
|
| 1260 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1261 | - } |
|
| 1262 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1263 | - if ($script['type'] != 'prive') { |
|
| 1264 | - $prepend_code['insert_head'] .= $code; |
|
| 1265 | - } |
|
| 1266 | - if ($script['type'] != 'public') { |
|
| 1267 | - $prepend_code['header_prive'] .= $code; |
|
| 1268 | - } |
|
| 1269 | - } |
|
| 1270 | - } |
|
| 1271 | - } |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - $prepend_code['insert_head'] = |
|
| 1275 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1276 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1277 | - . $prepend_code['insert_head']; |
|
| 1278 | - $prepend_code['header_prive'] = |
|
| 1279 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1280 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1281 | - . $prepend_code['header_prive']; |
|
| 1282 | - |
|
| 1283 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1284 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1285 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1286 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1287 | - } |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - return $prepend_code; |
|
| 1157 | + static $liste_pipe_manquants = []; |
|
| 1158 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1159 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + $prepend_code = []; |
|
| 1163 | + |
|
| 1164 | + foreach ($ordre as $p => $info) { |
|
| 1165 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1166 | + if (isset($plugin_valides[$p])) { |
|
| 1167 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1168 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1169 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1170 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1171 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1172 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1173 | + $nom = $pipe['nom']; |
|
| 1174 | + if (isset($pipe['action'])) { |
|
| 1175 | + $action = $pipe['action']; |
|
| 1176 | + } else { |
|
| 1177 | + $action = $nom; |
|
| 1178 | + } |
|
| 1179 | + $nomlower = strtolower($nom); |
|
| 1180 | + if ( |
|
| 1181 | + $nomlower != $nom |
|
| 1182 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1183 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1184 | + ) { |
|
| 1185 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1186 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1187 | + } |
|
| 1188 | + $nom = $nomlower; |
|
| 1189 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1190 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1191 | + $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1192 | + } |
|
| 1193 | + if ($action) { |
|
| 1194 | + if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1195 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1196 | + ',(\|\||$),', |
|
| 1197 | + "|$prefix$action\\1", |
|
| 1198 | + $GLOBALS['spip_pipeline'][$nom], |
|
| 1199 | + 1 |
|
| 1200 | + ); |
|
| 1201 | + } |
|
| 1202 | + if (isset($pipe['inclure'])) { |
|
| 1203 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1204 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1205 | + } |
|
| 1206 | + } |
|
| 1207 | + } |
|
| 1208 | + } |
|
| 1209 | + if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1210 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1211 | + $prepend_code['taches_generales_cron'] = ''; |
|
| 1212 | + } |
|
| 1213 | + foreach ($info['genie'] as $genie) { |
|
| 1214 | + $nom = $prefix . $genie['nom']; |
|
| 1215 | + $periode = max(60, intval($genie['periode'])); |
|
| 1216 | + if (charger_fonction($nom, 'genie', true)) { |
|
| 1217 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1218 | + } else { |
|
| 1219 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1220 | + } |
|
| 1221 | + } |
|
| 1222 | + } |
|
| 1223 | + if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1224 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1225 | + $prepend_code['insert_head_css'] = ''; |
|
| 1226 | + } |
|
| 1227 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1228 | + $prepend_code['header_prive_css'] = ''; |
|
| 1229 | + } |
|
| 1230 | + foreach ($info['style'] as $style) { |
|
| 1231 | + if (isset($style['path']) and $style['path']) { |
|
| 1232 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1233 | + } else { |
|
| 1234 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1235 | + } |
|
| 1236 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1237 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1238 | + $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1239 | + } |
|
| 1240 | + $code .= "/>';\n"; |
|
| 1241 | + if ($style['type'] != 'prive') { |
|
| 1242 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1243 | + } |
|
| 1244 | + if ($style['type'] != 'public') { |
|
| 1245 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1246 | + } |
|
| 1247 | + } |
|
| 1248 | + } |
|
| 1249 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1250 | + $prepend_code['insert_head'] = ''; |
|
| 1251 | + } |
|
| 1252 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1253 | + $prepend_code['header_prive'] = ''; |
|
| 1254 | + } |
|
| 1255 | + if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1256 | + foreach ($info['script'] as $script) { |
|
| 1257 | + if (isset($script['path']) and $script['path']) { |
|
| 1258 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1259 | + } else { |
|
| 1260 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1261 | + } |
|
| 1262 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1263 | + if ($script['type'] != 'prive') { |
|
| 1264 | + $prepend_code['insert_head'] .= $code; |
|
| 1265 | + } |
|
| 1266 | + if ($script['type'] != 'public') { |
|
| 1267 | + $prepend_code['header_prive'] .= $code; |
|
| 1268 | + } |
|
| 1269 | + } |
|
| 1270 | + } |
|
| 1271 | + } |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + $prepend_code['insert_head'] = |
|
| 1275 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1276 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1277 | + . $prepend_code['insert_head']; |
|
| 1278 | + $prepend_code['header_prive'] = |
|
| 1279 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1280 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1281 | + . $prepend_code['header_prive']; |
|
| 1282 | + |
|
| 1283 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1284 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1285 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1286 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1287 | + } |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + return $prepend_code; |
|
| 1291 | 1291 | } |
| 1292 | 1292 | |
| 1293 | 1293 | /** |
@@ -1314,62 +1314,62 @@ discard block |
||
| 1314 | 1314 | **/ |
| 1315 | 1315 | function pipeline_precompile($prepend_code = []) { |
| 1316 | 1316 | |
| 1317 | - $all_pipes = $all_pipes_end = ''; |
|
| 1318 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1319 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1320 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1321 | - $all_pipes = trim(array_shift($a)); |
|
| 1322 | - if ($all_pipes) { |
|
| 1323 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1324 | - } |
|
| 1325 | - if (count($a)) { |
|
| 1326 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1327 | - } |
|
| 1328 | - } |
|
| 1329 | - $content = ''; |
|
| 1330 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1331 | - $s_inc = ''; |
|
| 1332 | - $s_call = ''; |
|
| 1333 | - if ($all_pipes) { |
|
| 1334 | - $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1335 | - } |
|
| 1336 | - if ($all_pipes_end) { |
|
| 1337 | - $pipeline .= $all_pipes_end; |
|
| 1338 | - } |
|
| 1339 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1340 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1341 | - foreach ($pipe as $fonc) { |
|
| 1342 | - $fonc = trim($fonc); |
|
| 1343 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1344 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1345 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1346 | - $file = "'$file'"; |
|
| 1347 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1348 | - if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1349 | - $dir = $regs[1]; |
|
| 1350 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1351 | - if (defined($root_dir)) { |
|
| 1352 | - $dir = $root_dir; |
|
| 1353 | - } |
|
| 1354 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1355 | - $file = str_replace("''.", '', $file); |
|
| 1356 | - $file = str_replace(constant($dir), '', $file); |
|
| 1357 | - } |
|
| 1358 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1359 | - } |
|
| 1360 | - } |
|
| 1361 | - if (strlen($s_inc)) { |
|
| 1362 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1363 | - } |
|
| 1364 | - $content .= "// Pipeline $action \n" |
|
| 1365 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1366 | - . $s_inc |
|
| 1367 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1368 | - . $s_call |
|
| 1369 | - . "return \$val;\n}\n"; |
|
| 1370 | - } |
|
| 1371 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1372 | - clear_path_cache(); |
|
| 1317 | + $all_pipes = $all_pipes_end = ''; |
|
| 1318 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1319 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1320 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1321 | + $all_pipes = trim(array_shift($a)); |
|
| 1322 | + if ($all_pipes) { |
|
| 1323 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1324 | + } |
|
| 1325 | + if (count($a)) { |
|
| 1326 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1327 | + } |
|
| 1328 | + } |
|
| 1329 | + $content = ''; |
|
| 1330 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1331 | + $s_inc = ''; |
|
| 1332 | + $s_call = ''; |
|
| 1333 | + if ($all_pipes) { |
|
| 1334 | + $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1335 | + } |
|
| 1336 | + if ($all_pipes_end) { |
|
| 1337 | + $pipeline .= $all_pipes_end; |
|
| 1338 | + } |
|
| 1339 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1340 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1341 | + foreach ($pipe as $fonc) { |
|
| 1342 | + $fonc = trim($fonc); |
|
| 1343 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1344 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1345 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1346 | + $file = "'$file'"; |
|
| 1347 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1348 | + if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1349 | + $dir = $regs[1]; |
|
| 1350 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1351 | + if (defined($root_dir)) { |
|
| 1352 | + $dir = $root_dir; |
|
| 1353 | + } |
|
| 1354 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1355 | + $file = str_replace("''.", '', $file); |
|
| 1356 | + $file = str_replace(constant($dir), '', $file); |
|
| 1357 | + } |
|
| 1358 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1359 | + } |
|
| 1360 | + } |
|
| 1361 | + if (strlen($s_inc)) { |
|
| 1362 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1363 | + } |
|
| 1364 | + $content .= "// Pipeline $action \n" |
|
| 1365 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1366 | + . $s_inc |
|
| 1367 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1368 | + . $s_call |
|
| 1369 | + . "return \$val;\n}\n"; |
|
| 1370 | + } |
|
| 1371 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1372 | + clear_path_cache(); |
|
| 1373 | 1373 | } |
| 1374 | 1374 | |
| 1375 | 1375 | |
@@ -1382,12 +1382,12 @@ discard block |
||
| 1382 | 1382 | * true si le plugin est actif, false sinon |
| 1383 | 1383 | **/ |
| 1384 | 1384 | function plugin_est_installe($plug_path) { |
| 1385 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1386 | - if (!$plugin_installes) { |
|
| 1387 | - return false; |
|
| 1388 | - } |
|
| 1385 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1386 | + if (!$plugin_installes) { |
|
| 1387 | + return false; |
|
| 1388 | + } |
|
| 1389 | 1389 | |
| 1390 | - return in_array($plug_path, $plugin_installes); |
|
| 1390 | + return in_array($plug_path, $plugin_installes); |
|
| 1391 | 1391 | } |
| 1392 | 1392 | |
| 1393 | 1393 | |
@@ -1400,46 +1400,46 @@ discard block |
||
| 1400 | 1400 | * @uses plugins_installer_dist() |
| 1401 | 1401 | **/ |
| 1402 | 1402 | function plugin_installes_meta() { |
| 1403 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1404 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1405 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1406 | - } |
|
| 1407 | - |
|
| 1408 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1409 | - $meta_plug_installes = []; |
|
| 1410 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1411 | - if ($plug = $resume['dir']) { |
|
| 1412 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1413 | - if ($infos) { |
|
| 1414 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1415 | - $meta_plug_installes[] = $plug; |
|
| 1416 | - } |
|
| 1417 | - if (is_array($infos)) { |
|
| 1418 | - [$ok, $trace] = $infos['install_test']; |
|
| 1419 | - $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1420 | - $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1421 | - if (_IS_CLI) { |
|
| 1422 | - include_spip('inc/filtres'); |
|
| 1423 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1424 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1425 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1426 | - $trace, |
|
| 1427 | - "\n"; |
|
| 1428 | - } |
|
| 1429 | - else { |
|
| 1430 | - include_spip('inc/filtres_boites'); |
|
| 1431 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1432 | - . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1433 | - . $trace |
|
| 1434 | - . "<div class='result'>$result</div>" |
|
| 1435 | - . boite_fermer() |
|
| 1436 | - . '</div>'; |
|
| 1437 | - } |
|
| 1438 | - } |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1403 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1404 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1405 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1406 | + } |
|
| 1407 | + |
|
| 1408 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1409 | + $meta_plug_installes = []; |
|
| 1410 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1411 | + if ($plug = $resume['dir']) { |
|
| 1412 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1413 | + if ($infos) { |
|
| 1414 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1415 | + $meta_plug_installes[] = $plug; |
|
| 1416 | + } |
|
| 1417 | + if (is_array($infos)) { |
|
| 1418 | + [$ok, $trace] = $infos['install_test']; |
|
| 1419 | + $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1420 | + $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1421 | + if (_IS_CLI) { |
|
| 1422 | + include_spip('inc/filtres'); |
|
| 1423 | + $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1424 | + $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1425 | + echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1426 | + $trace, |
|
| 1427 | + "\n"; |
|
| 1428 | + } |
|
| 1429 | + else { |
|
| 1430 | + include_spip('inc/filtres_boites'); |
|
| 1431 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1432 | + . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1433 | + . $trace |
|
| 1434 | + . "<div class='result'>$result</div>" |
|
| 1435 | + . boite_fermer() |
|
| 1436 | + . '</div>'; |
|
| 1437 | + } |
|
| 1438 | + } |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1443 | 1443 | } |
| 1444 | 1444 | |
| 1445 | 1445 | /** |
@@ -1453,29 +1453,29 @@ discard block |
||
| 1453 | 1453 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1454 | 1454 | **/ |
| 1455 | 1455 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1456 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1457 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1458 | - } |
|
| 1459 | - |
|
| 1460 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1461 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1462 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1463 | - if (file_exists($nom)) { |
|
| 1464 | - if (substr($nom, -4) == '.php') { |
|
| 1465 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1466 | - } |
|
| 1467 | - else { |
|
| 1468 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1469 | - } |
|
| 1470 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1471 | - if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1472 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1473 | - @unlink($fichier_tmp); |
|
| 1474 | - return; |
|
| 1475 | - } |
|
| 1476 | - @unlink($fichier_tmp); |
|
| 1477 | - } |
|
| 1478 | - ecrire_fichier($nom, $contenu); |
|
| 1479 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1480 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1456 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1457 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1458 | + } |
|
| 1459 | + |
|
| 1460 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1461 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1462 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1463 | + if (file_exists($nom)) { |
|
| 1464 | + if (substr($nom, -4) == '.php') { |
|
| 1465 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1466 | + } |
|
| 1467 | + else { |
|
| 1468 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1469 | + } |
|
| 1470 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1471 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1472 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1473 | + @unlink($fichier_tmp); |
|
| 1474 | + return; |
|
| 1475 | + } |
|
| 1476 | + @unlink($fichier_tmp); |
|
| 1477 | + } |
|
| 1478 | + ecrire_fichier($nom, $contenu); |
|
| 1479 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1480 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1481 | 1481 | } |