@@ -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,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,38 +325,38 @@ 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 | - // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 330 | - $short_desc = [ |
|
| 331 | - 'dir' => $plug, |
|
| 332 | - 'dir_type' => $dir_type |
|
| 333 | - ]; |
|
| 334 | - if (empty($i['prefix'])) { |
|
| 335 | - // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 336 | - $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 337 | - return [$plug => $short_desc]; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $p = strtoupper($i['prefix']); |
|
| 341 | - $short_desc['nom'] = $i['nom']; |
|
| 342 | - $short_desc['etat'] = $i['etat']; |
|
| 343 | - $short_desc['version'] = $i['version']; |
|
| 344 | - |
|
| 345 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 346 | - $short_desc['erreur'] = $i['erreur']; |
|
| 347 | - return [$p => $short_desc]; |
|
| 348 | - } |
|
| 349 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 350 | - return [$p => $short_desc]; |
|
| 351 | - } |
|
| 352 | - if ( |
|
| 353 | - !isset($liste[$p]) |
|
| 354 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 355 | - ) { |
|
| 356 | - $liste[$p] = $short_desc; |
|
| 357 | - } |
|
| 358 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 359 | - return $p; |
|
| 328 | + $i = $infos[$dir_type][$plug]; |
|
| 329 | + // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 330 | + $short_desc = [ |
|
| 331 | + 'dir' => $plug, |
|
| 332 | + 'dir_type' => $dir_type |
|
| 333 | + ]; |
|
| 334 | + if (empty($i['prefix'])) { |
|
| 335 | + // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 336 | + $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 337 | + return [$plug => $short_desc]; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $p = strtoupper($i['prefix']); |
|
| 341 | + $short_desc['nom'] = $i['nom']; |
|
| 342 | + $short_desc['etat'] = $i['etat']; |
|
| 343 | + $short_desc['version'] = $i['version']; |
|
| 344 | + |
|
| 345 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 346 | + $short_desc['erreur'] = $i['erreur']; |
|
| 347 | + return [$p => $short_desc]; |
|
| 348 | + } |
|
| 349 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 350 | + return [$p => $short_desc]; |
|
| 351 | + } |
|
| 352 | + if ( |
|
| 353 | + !isset($liste[$p]) |
|
| 354 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 355 | + ) { |
|
| 356 | + $liste[$p] = $short_desc; |
|
| 357 | + } |
|
| 358 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 359 | + return $p; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -372,47 +372,47 @@ discard block |
||
| 372 | 372 | * @param array $infos |
| 373 | 373 | */ |
| 374 | 374 | function plugin_fixer_procure(&$liste, &$infos) { |
| 375 | - foreach ($liste as $p => $resume) { |
|
| 376 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 377 | - if (isset($i['procure']) and $i['procure']) { |
|
| 378 | - foreach ($i['procure'] as $procure) { |
|
| 379 | - $p = strtoupper($procure['nom']); |
|
| 380 | - $dir = $resume['dir']; |
|
| 381 | - if ($dir) { |
|
| 382 | - $dir .= '/'; |
|
| 383 | - } |
|
| 384 | - $dir .= 'procure:' . $procure['nom']; |
|
| 385 | - |
|
| 386 | - $procure['etat'] = '?'; |
|
| 387 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 388 | - $procure['dir'] = $dir; |
|
| 389 | - |
|
| 390 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 391 | - // on ajoute cette version a la liste |
|
| 392 | - if ( |
|
| 393 | - !isset($liste[$p]) |
|
| 394 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 395 | - ) { |
|
| 396 | - $liste[$p] = $procure; |
|
| 397 | - |
|
| 398 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 399 | - $infos[$resume['dir_type']][$dir] = [ |
|
| 400 | - 'prefix' => $procure['nom'], |
|
| 401 | - 'nom' => $procure['nom'], |
|
| 402 | - 'etat' => $procure['etat'], |
|
| 403 | - 'version' => $procure['version'], |
|
| 404 | - 'chemin' => [], |
|
| 405 | - 'necessite' => [], |
|
| 406 | - 'utilise' => [], |
|
| 407 | - 'lib' => [], |
|
| 408 | - 'menu' => [], |
|
| 409 | - 'onglet' => [], |
|
| 410 | - 'procure' => [], |
|
| 411 | - ]; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 375 | + foreach ($liste as $p => $resume) { |
|
| 376 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 377 | + if (isset($i['procure']) and $i['procure']) { |
|
| 378 | + foreach ($i['procure'] as $procure) { |
|
| 379 | + $p = strtoupper($procure['nom']); |
|
| 380 | + $dir = $resume['dir']; |
|
| 381 | + if ($dir) { |
|
| 382 | + $dir .= '/'; |
|
| 383 | + } |
|
| 384 | + $dir .= 'procure:' . $procure['nom']; |
|
| 385 | + |
|
| 386 | + $procure['etat'] = '?'; |
|
| 387 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 388 | + $procure['dir'] = $dir; |
|
| 389 | + |
|
| 390 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 391 | + // on ajoute cette version a la liste |
|
| 392 | + if ( |
|
| 393 | + !isset($liste[$p]) |
|
| 394 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 395 | + ) { |
|
| 396 | + $liste[$p] = $procure; |
|
| 397 | + |
|
| 398 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 399 | + $infos[$resume['dir_type']][$dir] = [ |
|
| 400 | + 'prefix' => $procure['nom'], |
|
| 401 | + 'nom' => $procure['nom'], |
|
| 402 | + 'etat' => $procure['etat'], |
|
| 403 | + 'version' => $procure['version'], |
|
| 404 | + 'chemin' => [], |
|
| 405 | + 'necessite' => [], |
|
| 406 | + 'utilise' => [], |
|
| 407 | + 'lib' => [], |
|
| 408 | + 'menu' => [], |
|
| 409 | + 'onglet' => [], |
|
| 410 | + 'procure' => [], |
|
| 411 | + ]; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -426,20 +426,20 @@ discard block |
||
| 426 | 426 | * @return array |
| 427 | 427 | */ |
| 428 | 428 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 429 | - foreach ($liste as $prefix => $infos) { |
|
| 430 | - if ( |
|
| 431 | - !$dir_plugins |
|
| 432 | - or ( |
|
| 433 | - defined($infos['dir_type']) |
|
| 434 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 435 | - ) { |
|
| 436 | - $liste[$prefix] = $infos['dir']; |
|
| 437 | - } else { |
|
| 438 | - unset($liste[$prefix]); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return $liste; |
|
| 429 | + foreach ($liste as $prefix => $infos) { |
|
| 430 | + if ( |
|
| 431 | + !$dir_plugins |
|
| 432 | + or ( |
|
| 433 | + defined($infos['dir_type']) |
|
| 434 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 435 | + ) { |
|
| 436 | + $liste[$prefix] = $infos['dir']; |
|
| 437 | + } else { |
|
| 438 | + unset($liste[$prefix]); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return $liste; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -454,9 +454,9 @@ discard block |
||
| 454 | 454 | * @return array |
| 455 | 455 | */ |
| 456 | 456 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 457 | - include_spip('plugins/installer'); |
|
| 457 | + include_spip('plugins/installer'); |
|
| 458 | 458 | |
| 459 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 459 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -487,54 +487,54 @@ discard block |
||
| 487 | 487 | * qui n'ont pas satisfait leurs dépendances |
| 488 | 488 | **/ |
| 489 | 489 | function plugin_trier($infos, $liste_non_classee) { |
| 490 | - $toute_la_liste = $liste_non_classee; |
|
| 491 | - $liste = $ordre = []; |
|
| 492 | - $count = 0; |
|
| 493 | - |
|
| 494 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 495 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 496 | - $count = $c; |
|
| 497 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 498 | - $plug = $resume['dir']; |
|
| 499 | - $dir_type = $resume['dir_type']; |
|
| 500 | - $info1 = $infos[$dir_type][$plug]; |
|
| 501 | - // si des plugins sont necessaires, |
|
| 502 | - // on ne peut inserer qu'apres eux |
|
| 503 | - foreach ($info1['necessite'] as $need) { |
|
| 504 | - $nom = strtoupper($need['nom']); |
|
| 505 | - $compat = $need['compatibilite'] ?? ''; |
|
| 506 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 507 | - $info1 = false; |
|
| 508 | - break; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - if (!$info1) { |
|
| 512 | - continue; |
|
| 513 | - } |
|
| 514 | - // idem si des plugins sont utiles, |
|
| 515 | - // sauf si ils sont de toute facon absents de la liste |
|
| 516 | - foreach ($info1['utilise'] as $need) { |
|
| 517 | - $nom = strtoupper($need['nom']); |
|
| 518 | - $compat = $need['compatibilite'] ?? ''; |
|
| 519 | - if (isset($toute_la_liste[$nom])) { |
|
| 520 | - if ( |
|
| 521 | - !isset($liste[$nom]) or |
|
| 522 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 523 | - ) { |
|
| 524 | - $info1 = false; |
|
| 525 | - break; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - if ($info1) { |
|
| 530 | - $ordre[$p] = $info1; |
|
| 531 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 532 | - unset($liste_non_classee[$p]); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return [$liste, $ordre, $liste_non_classee]; |
|
| 490 | + $toute_la_liste = $liste_non_classee; |
|
| 491 | + $liste = $ordre = []; |
|
| 492 | + $count = 0; |
|
| 493 | + |
|
| 494 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 495 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 496 | + $count = $c; |
|
| 497 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 498 | + $plug = $resume['dir']; |
|
| 499 | + $dir_type = $resume['dir_type']; |
|
| 500 | + $info1 = $infos[$dir_type][$plug]; |
|
| 501 | + // si des plugins sont necessaires, |
|
| 502 | + // on ne peut inserer qu'apres eux |
|
| 503 | + foreach ($info1['necessite'] as $need) { |
|
| 504 | + $nom = strtoupper($need['nom']); |
|
| 505 | + $compat = $need['compatibilite'] ?? ''; |
|
| 506 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 507 | + $info1 = false; |
|
| 508 | + break; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + if (!$info1) { |
|
| 512 | + continue; |
|
| 513 | + } |
|
| 514 | + // idem si des plugins sont utiles, |
|
| 515 | + // sauf si ils sont de toute facon absents de la liste |
|
| 516 | + foreach ($info1['utilise'] as $need) { |
|
| 517 | + $nom = strtoupper($need['nom']); |
|
| 518 | + $compat = $need['compatibilite'] ?? ''; |
|
| 519 | + if (isset($toute_la_liste[$nom])) { |
|
| 520 | + if ( |
|
| 521 | + !isset($liste[$nom]) or |
|
| 522 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 523 | + ) { |
|
| 524 | + $info1 = false; |
|
| 525 | + break; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + if ($info1) { |
|
| 530 | + $ordre[$p] = $info1; |
|
| 531 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 532 | + unset($liste_non_classee[$p]); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return [$liste, $ordre, $liste_non_classee]; |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -551,40 +551,40 @@ discard block |
||
| 551 | 551 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 552 | 552 | **/ |
| 553 | 553 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = []) { |
| 554 | - static $erreurs = []; |
|
| 555 | - |
|
| 556 | - if (!is_array($liste)) { |
|
| 557 | - $liste = []; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 561 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 562 | - |
|
| 563 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 564 | - $dir_type = $resume['dir_type']; |
|
| 565 | - $plug = $resume['dir']; |
|
| 566 | - $k = $infos[$dir_type][$plug]; |
|
| 567 | - |
|
| 568 | - $plug = constant($dir_type) . $plug; |
|
| 569 | - if (!isset($msg[$p])) { |
|
| 570 | - if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 571 | - $msg[$p] = [$resume['erreur']]; |
|
| 572 | - } |
|
| 573 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 574 | - $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 575 | - } |
|
| 576 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 577 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 578 | - } |
|
| 579 | - } else { |
|
| 580 | - foreach ($msg[$p] as $c => $l) { |
|
| 581 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - $erreurs[$plug] = $msg[$p]; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 554 | + static $erreurs = []; |
|
| 555 | + |
|
| 556 | + if (!is_array($liste)) { |
|
| 557 | + $liste = []; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 561 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 562 | + |
|
| 563 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 564 | + $dir_type = $resume['dir_type']; |
|
| 565 | + $plug = $resume['dir']; |
|
| 566 | + $k = $infos[$dir_type][$plug]; |
|
| 567 | + |
|
| 568 | + $plug = constant($dir_type) . $plug; |
|
| 569 | + if (!isset($msg[$p])) { |
|
| 570 | + if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 571 | + $msg[$p] = [$resume['erreur']]; |
|
| 572 | + } |
|
| 573 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 574 | + $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 575 | + } |
|
| 576 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 577 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 578 | + } |
|
| 579 | + } else { |
|
| 580 | + foreach ($msg[$p] as $c => $l) { |
|
| 581 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + $erreurs[$plug] = $msg[$p]; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -599,25 +599,25 @@ discard block |
||
| 599 | 599 | * - Liste des erreurs ou code HTML des erreurs |
| 600 | 600 | **/ |
| 601 | 601 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 602 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 603 | - return $raw ? [] : ''; |
|
| 604 | - } |
|
| 605 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 606 | - // Compat ancienne version |
|
| 607 | - if (!$list) { |
|
| 608 | - $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 609 | - } elseif (!$raw) { |
|
| 610 | - foreach ($list as $plug => $msg) { |
|
| 611 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 613 | - } |
|
| 614 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 615 | - } |
|
| 616 | - if ($raz) { |
|
| 617 | - effacer_meta('plugin_erreur_activation'); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return $list; |
|
| 602 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 603 | + return $raw ? [] : ''; |
|
| 604 | + } |
|
| 605 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 606 | + // Compat ancienne version |
|
| 607 | + if (!$list) { |
|
| 608 | + $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 609 | + } elseif (!$raw) { |
|
| 610 | + foreach ($list as $plug => $msg) { |
|
| 611 | + $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | + . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 613 | + } |
|
| 614 | + $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 615 | + } |
|
| 616 | + if ($raz) { |
|
| 617 | + effacer_meta('plugin_erreur_activation'); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return $list; |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | /** |
@@ -637,21 +637,21 @@ discard block |
||
| 637 | 637 | * |
| 638 | 638 | **/ |
| 639 | 639 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 640 | - $msg = []; |
|
| 641 | - foreach ($n as $need) { |
|
| 642 | - $id = strtoupper($need['nom']); |
|
| 643 | - $r = plugin_controler_necessite( |
|
| 644 | - $liste, |
|
| 645 | - $id, |
|
| 646 | - $need['compatibilite'] ?? '', |
|
| 647 | - $balise |
|
| 648 | - ); |
|
| 649 | - if ($r) { |
|
| 650 | - $msg[] = $r; |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $msg; |
|
| 640 | + $msg = []; |
|
| 641 | + foreach ($n as $need) { |
|
| 642 | + $id = strtoupper($need['nom']); |
|
| 643 | + $r = plugin_controler_necessite( |
|
| 644 | + $liste, |
|
| 645 | + $id, |
|
| 646 | + $need['compatibilite'] ?? '', |
|
| 647 | + $balise |
|
| 648 | + ); |
|
| 649 | + if ($r) { |
|
| 650 | + $msg[] = $r; |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $msg; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -673,19 +673,19 @@ discard block |
||
| 673 | 673 | * Message d'erreur lorsque la dépendance est absente. |
| 674 | 674 | **/ |
| 675 | 675 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 676 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 677 | - return ''; |
|
| 678 | - } |
|
| 679 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 680 | - if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 681 | - return ''; |
|
| 682 | - } |
|
| 683 | - return plugin_message_incompatibilite( |
|
| 684 | - $intervalle, |
|
| 685 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 686 | - $nom, |
|
| 687 | - $balise |
|
| 688 | - ); |
|
| 676 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 677 | + return ''; |
|
| 678 | + } |
|
| 679 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 680 | + if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 681 | + return ''; |
|
| 682 | + } |
|
| 683 | + return plugin_message_incompatibilite( |
|
| 684 | + $intervalle, |
|
| 685 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 686 | + $nom, |
|
| 687 | + $balise |
|
| 688 | + ); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -702,70 +702,70 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 704 | 704 | |
| 705 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 706 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 707 | - $type = 'plugin'; |
|
| 708 | - if ($nom === 'SPIP') { |
|
| 709 | - $type = 'spip'; |
|
| 710 | - } elseif ($nom === 'PHP') { |
|
| 711 | - $type = 'php'; |
|
| 712 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 713 | - $type = 'extension_php'; |
|
| 714 | - [, $nom] = explode(':', $nom, 2); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 718 | - $minimum = $regs[1]; |
|
| 719 | - $maximum = $regs[2]; |
|
| 720 | - |
|
| 721 | - $minimum_inclus = $intervalle[0] == '['; |
|
| 722 | - $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 723 | - |
|
| 724 | - if (strlen($minimum)) { |
|
| 725 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 726 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 727 | - 'plugin' => $nom, |
|
| 728 | - 'version' => ' ≥ ' . $minimum |
|
| 729 | - ]); |
|
| 730 | - } |
|
| 731 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 732 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 733 | - 'plugin' => $nom, |
|
| 734 | - 'version' => ' > ' . $minimum |
|
| 735 | - ]); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if (strlen($maximum)) { |
|
| 740 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 741 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 742 | - 'plugin' => $nom, |
|
| 743 | - 'version' => ' ≤ ' . $maximum |
|
| 744 | - ]); |
|
| 745 | - } |
|
| 746 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 747 | - return _T("plugin_{$balise}_plugin", [ |
|
| 748 | - 'plugin' => $nom, |
|
| 749 | - 'version' => ' < ' . $maximum |
|
| 750 | - ]); |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 756 | - // - un 'utilise' sans version. |
|
| 757 | - // - un 'php' sans version. |
|
| 758 | - return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 705 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 706 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 707 | + $type = 'plugin'; |
|
| 708 | + if ($nom === 'SPIP') { |
|
| 709 | + $type = 'spip'; |
|
| 710 | + } elseif ($nom === 'PHP') { |
|
| 711 | + $type = 'php'; |
|
| 712 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 713 | + $type = 'extension_php'; |
|
| 714 | + [, $nom] = explode(':', $nom, 2); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 718 | + $minimum = $regs[1]; |
|
| 719 | + $maximum = $regs[2]; |
|
| 720 | + |
|
| 721 | + $minimum_inclus = $intervalle[0] == '['; |
|
| 722 | + $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 723 | + |
|
| 724 | + if (strlen($minimum)) { |
|
| 725 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 726 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 727 | + 'plugin' => $nom, |
|
| 728 | + 'version' => ' ≥ ' . $minimum |
|
| 729 | + ]); |
|
| 730 | + } |
|
| 731 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 732 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 733 | + 'plugin' => $nom, |
|
| 734 | + 'version' => ' > ' . $minimum |
|
| 735 | + ]); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if (strlen($maximum)) { |
|
| 740 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 741 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 742 | + 'plugin' => $nom, |
|
| 743 | + 'version' => ' ≤ ' . $maximum |
|
| 744 | + ]); |
|
| 745 | + } |
|
| 746 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 747 | + return _T("plugin_{$balise}_plugin", [ |
|
| 748 | + 'plugin' => $nom, |
|
| 749 | + 'version' => ' < ' . $maximum |
|
| 750 | + ]); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 756 | + // - un 'utilise' sans version. |
|
| 757 | + // - un 'php' sans version. |
|
| 758 | + return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
| 762 | 762 | function plugin_controler_lib($lib, $url) { |
| 763 | - /* Feature sortie du core, voir STP |
|
| 763 | + /* Feature sortie du core, voir STP |
|
| 764 | 764 | * if ($url) { |
| 765 | 765 | include_spip('inc/charger_plugin'); |
| 766 | 766 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 767 | 767 | }*/ |
| 768 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 768 | + return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 781 | 781 | **/ |
| 782 | 782 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 783 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 783 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | |
@@ -807,116 +807,116 @@ discard block |
||
| 807 | 807 | **/ |
| 808 | 808 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 809 | 809 | |
| 810 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 811 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 812 | - |
|
| 813 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 814 | - if (!$cache and !spip_connect()) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($operation != 'raz') { |
|
| 819 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 820 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 821 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 822 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 823 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 824 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 825 | - } |
|
| 826 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 827 | - // on les reinjecte ici |
|
| 828 | - if ( |
|
| 829 | - isset($GLOBALS['meta']['plugin_attente']) |
|
| 830 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 831 | - ) { |
|
| 832 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - if ($operation == 'ajoute') { |
|
| 836 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 837 | - } elseif ($operation == 'enleve') { |
|
| 838 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 839 | - } else { |
|
| 840 | - $plugin = $plugin_valides; |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 844 | - |
|
| 845 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 846 | - if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 847 | - $plugin = $ajouter_dependances($plugin); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // recharger le xml des plugins a activer |
|
| 851 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 852 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 853 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 854 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 855 | - [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 856 | - // trouver l'ordre d'activation |
|
| 857 | - [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 858 | - if ($invalides or $reste) { |
|
| 859 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - // Ignorer les plugins necessitant une lib absente |
|
| 863 | - // et preparer la meta d'entete Http |
|
| 864 | - $err = $msg = $header = []; |
|
| 865 | - foreach ($plugin_valides as $p => $resume) { |
|
| 866 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 867 | - if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 868 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 869 | - } |
|
| 870 | - if ($resume['dir']) { |
|
| 871 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 872 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 873 | - $err[$p] = $resume; |
|
| 874 | - $msg[$p][] = $l; |
|
| 875 | - unset($plugin_valides[$p]); |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - if ($err) { |
|
| 881 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 885 | - effacer_meta('message_crash_plugins'); |
|
| 886 | - } |
|
| 887 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 888 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 889 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 890 | - $header = strtolower(implode(',', $header)); |
|
| 891 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 892 | - ecrire_fichier( |
|
| 893 | - _DIR_VAR . 'config.txt', |
|
| 894 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 895 | - ); |
|
| 896 | - } else { |
|
| 897 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 898 | - } |
|
| 899 | - // generer charger_plugins_chemin.php |
|
| 900 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 901 | - // generer les fichiers |
|
| 902 | - // - charger_plugins_options.php |
|
| 903 | - // - charger_plugins_fonctions.php |
|
| 904 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 905 | - // charger les chemins des plugins et les fichiers d'options |
|
| 906 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 907 | - plugins_amorcer_plugins_actifs(); |
|
| 908 | - // mise a jour de la matrice des pipelines |
|
| 909 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 910 | - // generer le fichier _CACHE_PIPELINE |
|
| 911 | - pipeline_precompile($prepend_code); |
|
| 912 | - |
|
| 913 | - if (spip_connect()) { |
|
| 914 | - // lancer et initialiser les nouveaux crons ! |
|
| 915 | - include_spip('inc/genie'); |
|
| 916 | - genie_queue_watch_dist(); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 810 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 811 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 812 | + |
|
| 813 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 814 | + if (!$cache and !spip_connect()) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($operation != 'raz') { |
|
| 819 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 820 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 821 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 822 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 823 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 824 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 825 | + } |
|
| 826 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 827 | + // on les reinjecte ici |
|
| 828 | + if ( |
|
| 829 | + isset($GLOBALS['meta']['plugin_attente']) |
|
| 830 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 831 | + ) { |
|
| 832 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + if ($operation == 'ajoute') { |
|
| 836 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 837 | + } elseif ($operation == 'enleve') { |
|
| 838 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 839 | + } else { |
|
| 840 | + $plugin = $plugin_valides; |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 844 | + |
|
| 845 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 846 | + if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 847 | + $plugin = $ajouter_dependances($plugin); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + // recharger le xml des plugins a activer |
|
| 851 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 852 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 853 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 854 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 855 | + [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 856 | + // trouver l'ordre d'activation |
|
| 857 | + [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 858 | + if ($invalides or $reste) { |
|
| 859 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + // Ignorer les plugins necessitant une lib absente |
|
| 863 | + // et preparer la meta d'entete Http |
|
| 864 | + $err = $msg = $header = []; |
|
| 865 | + foreach ($plugin_valides as $p => $resume) { |
|
| 866 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 867 | + if (0 !== strpos($p, 'PHP:') and $p !== 'PHP') { |
|
| 868 | + $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 869 | + } |
|
| 870 | + if ($resume['dir']) { |
|
| 871 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 872 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 873 | + $err[$p] = $resume; |
|
| 874 | + $msg[$p][] = $l; |
|
| 875 | + unset($plugin_valides[$p]); |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + if ($err) { |
|
| 881 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 885 | + effacer_meta('message_crash_plugins'); |
|
| 886 | + } |
|
| 887 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 888 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 889 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 890 | + $header = strtolower(implode(',', $header)); |
|
| 891 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 892 | + ecrire_fichier( |
|
| 893 | + _DIR_VAR . 'config.txt', |
|
| 894 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 895 | + ); |
|
| 896 | + } else { |
|
| 897 | + @unlink(_DIR_VAR . 'config.txt'); |
|
| 898 | + } |
|
| 899 | + // generer charger_plugins_chemin.php |
|
| 900 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 901 | + // generer les fichiers |
|
| 902 | + // - charger_plugins_options.php |
|
| 903 | + // - charger_plugins_fonctions.php |
|
| 904 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 905 | + // charger les chemins des plugins et les fichiers d'options |
|
| 906 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 907 | + plugins_amorcer_plugins_actifs(); |
|
| 908 | + // mise a jour de la matrice des pipelines |
|
| 909 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 910 | + // generer le fichier _CACHE_PIPELINE |
|
| 911 | + pipeline_precompile($prepend_code); |
|
| 912 | + |
|
| 913 | + if (spip_connect()) { |
|
| 914 | + // lancer et initialiser les nouveaux crons ! |
|
| 915 | + include_spip('inc/genie'); |
|
| 916 | + genie_queue_watch_dist(); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -935,74 +935,74 @@ discard block |
||
| 935 | 935 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 936 | 936 | **/ |
| 937 | 937 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 938 | - $chemins = [ |
|
| 939 | - 'public' => [], |
|
| 940 | - 'prive' => [] |
|
| 941 | - ]; |
|
| 942 | - $contenu = ''; |
|
| 943 | - foreach ($ordre as $p => $info) { |
|
| 944 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 945 | - if (isset($plugin_valides[$p])) { |
|
| 946 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 947 | - $plug = $plugin_valides[$p]['dir']; |
|
| 948 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 949 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 950 | - |
|
| 951 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 952 | - |
|
| 953 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 954 | - if ( |
|
| 955 | - $prefix !== 'SPIP' |
|
| 956 | - and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 957 | - ) { |
|
| 958 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 959 | - if (!$info['chemin']) { |
|
| 960 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 961 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 962 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 963 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - else { |
|
| 967 | - foreach ($info['chemin'] as $chemin) { |
|
| 968 | - if ( |
|
| 969 | - !isset($chemin['version']) or plugin_version_compatible( |
|
| 970 | - $chemin['version'], |
|
| 971 | - $GLOBALS['spip_version_branche'], |
|
| 972 | - 'spip' |
|
| 973 | - ) |
|
| 974 | - ) { |
|
| 975 | - $dir = $chemin['path']; |
|
| 976 | - if (strlen($dir) and $dir[0] == '/') { |
|
| 977 | - $dir = substr($dir, 1); |
|
| 978 | - } |
|
| 979 | - if (strlen($dir) and $dir == './') { |
|
| 980 | - $dir = ''; |
|
| 981 | - } |
|
| 982 | - if (strlen($dir)) { |
|
| 983 | - $dir = rtrim($dir, '/') . '/'; |
|
| 984 | - } |
|
| 985 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 986 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | - } |
|
| 988 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 989 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 998 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 999 | - ',', |
|
| 1000 | - array_reverse($chemins['public']) |
|
| 1001 | - ) . "]);\n" |
|
| 1002 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 938 | + $chemins = [ |
|
| 939 | + 'public' => [], |
|
| 940 | + 'prive' => [] |
|
| 941 | + ]; |
|
| 942 | + $contenu = ''; |
|
| 943 | + foreach ($ordre as $p => $info) { |
|
| 944 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 945 | + if (isset($plugin_valides[$p])) { |
|
| 946 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 947 | + $plug = $plugin_valides[$p]['dir']; |
|
| 948 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 949 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 950 | + |
|
| 951 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 952 | + |
|
| 953 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 954 | + if ( |
|
| 955 | + $prefix !== 'SPIP' |
|
| 956 | + and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 957 | + ) { |
|
| 958 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 959 | + if (!$info['chemin']) { |
|
| 960 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 961 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 962 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 963 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + else { |
|
| 967 | + foreach ($info['chemin'] as $chemin) { |
|
| 968 | + if ( |
|
| 969 | + !isset($chemin['version']) or plugin_version_compatible( |
|
| 970 | + $chemin['version'], |
|
| 971 | + $GLOBALS['spip_version_branche'], |
|
| 972 | + 'spip' |
|
| 973 | + ) |
|
| 974 | + ) { |
|
| 975 | + $dir = $chemin['path']; |
|
| 976 | + if (strlen($dir) and $dir[0] == '/') { |
|
| 977 | + $dir = substr($dir, 1); |
|
| 978 | + } |
|
| 979 | + if (strlen($dir) and $dir == './') { |
|
| 980 | + $dir = ''; |
|
| 981 | + } |
|
| 982 | + if (strlen($dir)) { |
|
| 983 | + $dir = rtrim($dir, '/') . '/'; |
|
| 984 | + } |
|
| 985 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 986 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | + } |
|
| 988 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 989 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 998 | + $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 999 | + ',', |
|
| 1000 | + array_reverse($chemins['public']) |
|
| 1001 | + ) . "]);\n" |
|
| 1002 | + . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1020,67 +1020,67 @@ discard block |
||
| 1020 | 1020 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 1021 | 1021 | **/ |
| 1022 | 1022 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1023 | - $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1024 | - $boutons = []; |
|
| 1025 | - $onglets = []; |
|
| 1026 | - $sign = ''; |
|
| 1027 | - |
|
| 1028 | - foreach ($ordre as $p => $info) { |
|
| 1029 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1030 | - if (isset($plugin_valides[$p])) { |
|
| 1031 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1032 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1033 | - $dir = constant($dir_type); |
|
| 1034 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1035 | - if ($info['menu']) { |
|
| 1036 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1037 | - } |
|
| 1038 | - if ($info['onglet']) { |
|
| 1039 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1040 | - } |
|
| 1041 | - foreach ($contenu as $charge => $v) { |
|
| 1042 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1043 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1044 | - // donc ni sa relecture, ni sa detection |
|
| 1045 | - if ( |
|
| 1046 | - !isset($info[$charge]) |
|
| 1047 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 1048 | - and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 1049 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1050 | - ) { |
|
| 1051 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1052 | - $info[$charge] = [$file]; |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - if (isset($info[$charge])) { |
|
| 1056 | - $files = $info[$charge]; |
|
| 1057 | - foreach ($files as $k => $file) { |
|
| 1058 | - // on genere un if file_exists devant chaque include |
|
| 1059 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1060 | - $file = trim($file); |
|
| 1061 | - if ( |
|
| 1062 | - !is_readable("$dir$plug/$file") |
|
| 1063 | - // uniquement pour les paquet.xml |
|
| 1064 | - and file_exists("$dir$plug/paquet.xml") |
|
| 1065 | - ) { |
|
| 1066 | - unset($info[$charge][$k]); |
|
| 1067 | - } else { |
|
| 1068 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1069 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - $sign .= md5(serialize($info)); |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1079 | - $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1080 | - . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1081 | - |
|
| 1082 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1083 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1023 | + $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1024 | + $boutons = []; |
|
| 1025 | + $onglets = []; |
|
| 1026 | + $sign = ''; |
|
| 1027 | + |
|
| 1028 | + foreach ($ordre as $p => $info) { |
|
| 1029 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1030 | + if (isset($plugin_valides[$p])) { |
|
| 1031 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1032 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1033 | + $dir = constant($dir_type); |
|
| 1034 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1035 | + if ($info['menu']) { |
|
| 1036 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1037 | + } |
|
| 1038 | + if ($info['onglet']) { |
|
| 1039 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1040 | + } |
|
| 1041 | + foreach ($contenu as $charge => $v) { |
|
| 1042 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1043 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1044 | + // donc ni sa relecture, ni sa detection |
|
| 1045 | + if ( |
|
| 1046 | + !isset($info[$charge]) |
|
| 1047 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 1048 | + and strpos($dir, ':') === false // exclure le cas des procure: |
|
| 1049 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1050 | + ) { |
|
| 1051 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1052 | + $info[$charge] = [$file]; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + if (isset($info[$charge])) { |
|
| 1056 | + $files = $info[$charge]; |
|
| 1057 | + foreach ($files as $k => $file) { |
|
| 1058 | + // on genere un if file_exists devant chaque include |
|
| 1059 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1060 | + $file = trim($file); |
|
| 1061 | + if ( |
|
| 1062 | + !is_readable("$dir$plug/$file") |
|
| 1063 | + // uniquement pour les paquet.xml |
|
| 1064 | + and file_exists("$dir$plug/paquet.xml") |
|
| 1065 | + ) { |
|
| 1066 | + unset($info[$charge][$k]); |
|
| 1067 | + } else { |
|
| 1068 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1069 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + $sign .= md5(serialize($info)); |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1079 | + $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1080 | + . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1081 | + |
|
| 1082 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1083 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
@@ -1099,24 +1099,24 @@ discard block |
||
| 1099 | 1099 | * @return string Code php |
| 1100 | 1100 | */ |
| 1101 | 1101 | function plugin_ongletbouton($nom, $val) { |
| 1102 | - if (!$val) { |
|
| 1103 | - $val = []; |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - $val = serialize($val); |
|
| 1107 | - $md5 = md5($val); |
|
| 1108 | - |
|
| 1109 | - if (!defined("_UPDATED_$nom")) { |
|
| 1110 | - define("_UPDATED_$nom", $val); |
|
| 1111 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1112 | - } |
|
| 1113 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1114 | - |
|
| 1115 | - return |
|
| 1116 | - "if (!function_exists('$nom')) {\n" |
|
| 1117 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1118 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1119 | - . "}\n"; |
|
| 1102 | + if (!$val) { |
|
| 1103 | + $val = []; |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + $val = serialize($val); |
|
| 1107 | + $md5 = md5($val); |
|
| 1108 | + |
|
| 1109 | + if (!defined("_UPDATED_$nom")) { |
|
| 1110 | + define("_UPDATED_$nom", $val); |
|
| 1111 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1112 | + } |
|
| 1113 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1114 | + |
|
| 1115 | + return |
|
| 1116 | + "if (!function_exists('$nom')) {\n" |
|
| 1117 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1118 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1119 | + . "}\n"; |
|
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | /** |
@@ -1131,15 +1131,15 @@ discard block |
||
| 1131 | 1131 | **/ |
| 1132 | 1132 | function plugins_amorcer_plugins_actifs() { |
| 1133 | 1133 | |
| 1134 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1135 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1136 | - } |
|
| 1134 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1135 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1139 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1140 | - } else { |
|
| 1141 | - spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1142 | - } |
|
| 1138 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1139 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1140 | + } else { |
|
| 1141 | + spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1142 | + } |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1162,140 +1162,140 @@ discard block |
||
| 1162 | 1162 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1165 | - static $liste_pipe_manquants = []; |
|
| 1166 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1167 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - $prepend_code = []; |
|
| 1171 | - |
|
| 1172 | - foreach ($ordre as $p => $info) { |
|
| 1173 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1174 | - if (isset($plugin_valides[$p])) { |
|
| 1175 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1176 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1177 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1178 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1179 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1180 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1181 | - $nom = $pipe['nom']; |
|
| 1182 | - if (isset($pipe['action'])) { |
|
| 1183 | - $action = $pipe['action']; |
|
| 1184 | - } else { |
|
| 1185 | - $action = $nom; |
|
| 1186 | - } |
|
| 1187 | - $nomlower = strtolower($nom); |
|
| 1188 | - if ( |
|
| 1189 | - $nomlower != $nom |
|
| 1190 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1191 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1192 | - ) { |
|
| 1193 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1194 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1195 | - } |
|
| 1196 | - $nom = $nomlower; |
|
| 1197 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1198 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1199 | - $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1200 | - } |
|
| 1201 | - if ($action) { |
|
| 1202 | - if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1203 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1204 | - ',(\|\||$),', |
|
| 1205 | - "|$prefix$action\\1", |
|
| 1206 | - $GLOBALS['spip_pipeline'][$nom], |
|
| 1207 | - 1 |
|
| 1208 | - ); |
|
| 1209 | - } |
|
| 1210 | - if (isset($pipe['inclure'])) { |
|
| 1211 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1212 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1218 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1219 | - $prepend_code['taches_generales_cron'] = ''; |
|
| 1220 | - } |
|
| 1221 | - foreach ($info['genie'] as $genie) { |
|
| 1222 | - $nom = $prefix . $genie['nom']; |
|
| 1223 | - $periode = max(60, intval($genie['periode'])); |
|
| 1224 | - if (charger_fonction($nom, 'genie', true)) { |
|
| 1225 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1226 | - } else { |
|
| 1227 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1232 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1233 | - $prepend_code['insert_head_css'] = ''; |
|
| 1234 | - } |
|
| 1235 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1236 | - $prepend_code['header_prive_css'] = ''; |
|
| 1237 | - } |
|
| 1238 | - foreach ($info['style'] as $style) { |
|
| 1239 | - if (isset($style['path']) and $style['path']) { |
|
| 1240 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1241 | - } else { |
|
| 1242 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1243 | - } |
|
| 1244 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1245 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1246 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1247 | - } |
|
| 1248 | - $code .= "/>';\n"; |
|
| 1249 | - if ($style['type'] != 'prive') { |
|
| 1250 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1251 | - } |
|
| 1252 | - if ($style['type'] != 'public') { |
|
| 1253 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1258 | - $prepend_code['insert_head'] = ''; |
|
| 1259 | - } |
|
| 1260 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1261 | - $prepend_code['header_prive'] = ''; |
|
| 1262 | - } |
|
| 1263 | - if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1264 | - foreach ($info['script'] as $script) { |
|
| 1265 | - if (isset($script['path']) and $script['path']) { |
|
| 1266 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1267 | - } else { |
|
| 1268 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1269 | - } |
|
| 1270 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1271 | - if ($script['type'] != 'prive') { |
|
| 1272 | - $prepend_code['insert_head'] .= $code; |
|
| 1273 | - } |
|
| 1274 | - if ($script['type'] != 'public') { |
|
| 1275 | - $prepend_code['header_prive'] .= $code; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - $prepend_code['insert_head'] = |
|
| 1283 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1284 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1285 | - . $prepend_code['insert_head']; |
|
| 1286 | - $prepend_code['header_prive'] = |
|
| 1287 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1288 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1289 | - . $prepend_code['header_prive']; |
|
| 1290 | - |
|
| 1291 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1292 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1293 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1294 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - return $prepend_code; |
|
| 1165 | + static $liste_pipe_manquants = []; |
|
| 1166 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1167 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + $prepend_code = []; |
|
| 1171 | + |
|
| 1172 | + foreach ($ordre as $p => $info) { |
|
| 1173 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1174 | + if (isset($plugin_valides[$p])) { |
|
| 1175 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1176 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1177 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1178 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1179 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1180 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1181 | + $nom = $pipe['nom']; |
|
| 1182 | + if (isset($pipe['action'])) { |
|
| 1183 | + $action = $pipe['action']; |
|
| 1184 | + } else { |
|
| 1185 | + $action = $nom; |
|
| 1186 | + } |
|
| 1187 | + $nomlower = strtolower($nom); |
|
| 1188 | + if ( |
|
| 1189 | + $nomlower != $nom |
|
| 1190 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1191 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1192 | + ) { |
|
| 1193 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1194 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1195 | + } |
|
| 1196 | + $nom = $nomlower; |
|
| 1197 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1198 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1199 | + $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1200 | + } |
|
| 1201 | + if ($action) { |
|
| 1202 | + if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1203 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1204 | + ',(\|\||$),', |
|
| 1205 | + "|$prefix$action\\1", |
|
| 1206 | + $GLOBALS['spip_pipeline'][$nom], |
|
| 1207 | + 1 |
|
| 1208 | + ); |
|
| 1209 | + } |
|
| 1210 | + if (isset($pipe['inclure'])) { |
|
| 1211 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1212 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1218 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1219 | + $prepend_code['taches_generales_cron'] = ''; |
|
| 1220 | + } |
|
| 1221 | + foreach ($info['genie'] as $genie) { |
|
| 1222 | + $nom = $prefix . $genie['nom']; |
|
| 1223 | + $periode = max(60, intval($genie['periode'])); |
|
| 1224 | + if (charger_fonction($nom, 'genie', true)) { |
|
| 1225 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1226 | + } else { |
|
| 1227 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1232 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1233 | + $prepend_code['insert_head_css'] = ''; |
|
| 1234 | + } |
|
| 1235 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1236 | + $prepend_code['header_prive_css'] = ''; |
|
| 1237 | + } |
|
| 1238 | + foreach ($info['style'] as $style) { |
|
| 1239 | + if (isset($style['path']) and $style['path']) { |
|
| 1240 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1241 | + } else { |
|
| 1242 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1243 | + } |
|
| 1244 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1245 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1246 | + $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1247 | + } |
|
| 1248 | + $code .= "/>';\n"; |
|
| 1249 | + if ($style['type'] != 'prive') { |
|
| 1250 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1251 | + } |
|
| 1252 | + if ($style['type'] != 'public') { |
|
| 1253 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1258 | + $prepend_code['insert_head'] = ''; |
|
| 1259 | + } |
|
| 1260 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1261 | + $prepend_code['header_prive'] = ''; |
|
| 1262 | + } |
|
| 1263 | + if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1264 | + foreach ($info['script'] as $script) { |
|
| 1265 | + if (isset($script['path']) and $script['path']) { |
|
| 1266 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1267 | + } else { |
|
| 1268 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1269 | + } |
|
| 1270 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1271 | + if ($script['type'] != 'prive') { |
|
| 1272 | + $prepend_code['insert_head'] .= $code; |
|
| 1273 | + } |
|
| 1274 | + if ($script['type'] != 'public') { |
|
| 1275 | + $prepend_code['header_prive'] .= $code; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + $prepend_code['insert_head'] = |
|
| 1283 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1284 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1285 | + . $prepend_code['insert_head']; |
|
| 1286 | + $prepend_code['header_prive'] = |
|
| 1287 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1288 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1289 | + . $prepend_code['header_prive']; |
|
| 1290 | + |
|
| 1291 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1292 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1293 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1294 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + return $prepend_code; |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | /** |
@@ -1322,62 +1322,62 @@ discard block |
||
| 1322 | 1322 | **/ |
| 1323 | 1323 | function pipeline_precompile($prepend_code = []) { |
| 1324 | 1324 | |
| 1325 | - $all_pipes = $all_pipes_end = ''; |
|
| 1326 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1327 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1328 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1329 | - $all_pipes = trim(array_shift($a)); |
|
| 1330 | - if ($all_pipes) { |
|
| 1331 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1332 | - } |
|
| 1333 | - if (count($a)) { |
|
| 1334 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - $content = ''; |
|
| 1338 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1339 | - $s_inc = ''; |
|
| 1340 | - $s_call = ''; |
|
| 1341 | - if ($all_pipes) { |
|
| 1342 | - $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1343 | - } |
|
| 1344 | - if ($all_pipes_end) { |
|
| 1345 | - $pipeline .= $all_pipes_end; |
|
| 1346 | - } |
|
| 1347 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1348 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1349 | - foreach ($pipe as $fonc) { |
|
| 1350 | - $fonc = trim($fonc); |
|
| 1351 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1352 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1353 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1354 | - $file = "'$file'"; |
|
| 1355 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1356 | - if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1357 | - $dir = $regs[1]; |
|
| 1358 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1359 | - if (defined($root_dir)) { |
|
| 1360 | - $dir = $root_dir; |
|
| 1361 | - } |
|
| 1362 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1363 | - $file = str_replace("''.", '', $file); |
|
| 1364 | - $file = str_replace(constant($dir), '', $file); |
|
| 1365 | - } |
|
| 1366 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - if (strlen($s_inc)) { |
|
| 1370 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1371 | - } |
|
| 1372 | - $content .= "// Pipeline $action \n" |
|
| 1373 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1374 | - . $s_inc |
|
| 1375 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1376 | - . $s_call |
|
| 1377 | - . "return \$val;\n}\n"; |
|
| 1378 | - } |
|
| 1379 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1380 | - clear_path_cache(); |
|
| 1325 | + $all_pipes = $all_pipes_end = ''; |
|
| 1326 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1327 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1328 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1329 | + $all_pipes = trim(array_shift($a)); |
|
| 1330 | + if ($all_pipes) { |
|
| 1331 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1332 | + } |
|
| 1333 | + if (count($a)) { |
|
| 1334 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + $content = ''; |
|
| 1338 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1339 | + $s_inc = ''; |
|
| 1340 | + $s_call = ''; |
|
| 1341 | + if ($all_pipes) { |
|
| 1342 | + $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1343 | + } |
|
| 1344 | + if ($all_pipes_end) { |
|
| 1345 | + $pipeline .= $all_pipes_end; |
|
| 1346 | + } |
|
| 1347 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1348 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1349 | + foreach ($pipe as $fonc) { |
|
| 1350 | + $fonc = trim($fonc); |
|
| 1351 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1352 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1353 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1354 | + $file = "'$file'"; |
|
| 1355 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1356 | + if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1357 | + $dir = $regs[1]; |
|
| 1358 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1359 | + if (defined($root_dir)) { |
|
| 1360 | + $dir = $root_dir; |
|
| 1361 | + } |
|
| 1362 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1363 | + $file = str_replace("''.", '', $file); |
|
| 1364 | + $file = str_replace(constant($dir), '', $file); |
|
| 1365 | + } |
|
| 1366 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + if (strlen($s_inc)) { |
|
| 1370 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1371 | + } |
|
| 1372 | + $content .= "// Pipeline $action \n" |
|
| 1373 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1374 | + . $s_inc |
|
| 1375 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1376 | + . $s_call |
|
| 1377 | + . "return \$val;\n}\n"; |
|
| 1378 | + } |
|
| 1379 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1380 | + clear_path_cache(); |
|
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | |
@@ -1390,12 +1390,12 @@ discard block |
||
| 1390 | 1390 | * true si le plugin est actif, false sinon |
| 1391 | 1391 | **/ |
| 1392 | 1392 | function plugin_est_installe($plug_path) { |
| 1393 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1394 | - if (!$plugin_installes) { |
|
| 1395 | - return false; |
|
| 1396 | - } |
|
| 1393 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1394 | + if (!$plugin_installes) { |
|
| 1395 | + return false; |
|
| 1396 | + } |
|
| 1397 | 1397 | |
| 1398 | - return in_array($plug_path, $plugin_installes); |
|
| 1398 | + return in_array($plug_path, $plugin_installes); |
|
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | 1401 | |
@@ -1408,46 +1408,46 @@ discard block |
||
| 1408 | 1408 | * @uses plugins_installer_dist() |
| 1409 | 1409 | **/ |
| 1410 | 1410 | function plugin_installes_meta() { |
| 1411 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1412 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1413 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1417 | - $meta_plug_installes = []; |
|
| 1418 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1419 | - if ($plug = $resume['dir']) { |
|
| 1420 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1421 | - if ($infos) { |
|
| 1422 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1423 | - $meta_plug_installes[] = $plug; |
|
| 1424 | - } |
|
| 1425 | - if (is_array($infos)) { |
|
| 1426 | - [$ok, $trace] = $infos['install_test']; |
|
| 1427 | - $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1428 | - $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1429 | - if (_IS_CLI) { |
|
| 1430 | - include_spip('inc/filtres'); |
|
| 1431 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1434 | - $trace, |
|
| 1435 | - "\n"; |
|
| 1436 | - } |
|
| 1437 | - else { |
|
| 1438 | - include_spip('inc/filtres_boites'); |
|
| 1439 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1440 | - . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1441 | - . $trace |
|
| 1442 | - . "<div class='result'>$result</div>" |
|
| 1443 | - . boite_fermer() |
|
| 1444 | - . '</div>'; |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1411 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1412 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1413 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1417 | + $meta_plug_installes = []; |
|
| 1418 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1419 | + if ($plug = $resume['dir']) { |
|
| 1420 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1421 | + if ($infos) { |
|
| 1422 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1423 | + $meta_plug_installes[] = $plug; |
|
| 1424 | + } |
|
| 1425 | + if (is_array($infos)) { |
|
| 1426 | + [$ok, $trace] = $infos['install_test']; |
|
| 1427 | + $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1428 | + $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1429 | + if (_IS_CLI) { |
|
| 1430 | + include_spip('inc/filtres'); |
|
| 1431 | + $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | + $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | + echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1434 | + $trace, |
|
| 1435 | + "\n"; |
|
| 1436 | + } |
|
| 1437 | + else { |
|
| 1438 | + include_spip('inc/filtres_boites'); |
|
| 1439 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1440 | + . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1441 | + . $trace |
|
| 1442 | + . "<div class='result'>$result</div>" |
|
| 1443 | + . boite_fermer() |
|
| 1444 | + . '</div>'; |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | /** |
@@ -1461,29 +1461,29 @@ discard block |
||
| 1461 | 1461 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1464 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1465 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1469 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1470 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1471 | - if (file_exists($nom)) { |
|
| 1472 | - if (substr($nom, -4) == '.php') { |
|
| 1473 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1474 | - } |
|
| 1475 | - else { |
|
| 1476 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1477 | - } |
|
| 1478 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1479 | - if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1480 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1481 | - @unlink($fichier_tmp); |
|
| 1482 | - return; |
|
| 1483 | - } |
|
| 1484 | - @unlink($fichier_tmp); |
|
| 1485 | - } |
|
| 1486 | - ecrire_fichier($nom, $contenu); |
|
| 1487 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1488 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1464 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1465 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1469 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1470 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1471 | + if (file_exists($nom)) { |
|
| 1472 | + if (substr($nom, -4) == '.php') { |
|
| 1473 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1474 | + } |
|
| 1475 | + else { |
|
| 1476 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1477 | + } |
|
| 1478 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1479 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1480 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1481 | + @unlink($fichier_tmp); |
|
| 1482 | + return; |
|
| 1483 | + } |
|
| 1484 | + @unlink($fichier_tmp); |
|
| 1485 | + } |
|
| 1486 | + ecrire_fichier($nom, $contenu); |
|
| 1487 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1488 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1489 | 1489 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -38,20 +38,20 @@ discard block |
||
| 38 | 38 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 39 | 39 | */ |
| 40 | 40 | function find_langs_in_path($file, $dirname = 'lang') { |
| 41 | - static $dirs = []; |
|
| 42 | - $liste = []; |
|
| 43 | - foreach (creer_chemin() as $dir) { |
|
| 44 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | - } |
|
| 47 | - if ($dirs[$a]) { |
|
| 48 | - if (is_readable($a .= $file)) { |
|
| 49 | - $liste[] = $a; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 41 | + static $dirs = []; |
|
| 42 | + $liste = []; |
|
| 43 | + foreach (creer_chemin() as $dir) { |
|
| 44 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | + } |
|
| 47 | + if ($dirs[$a]) { |
|
| 48 | + if (is_readable($a .= $file)) { |
|
| 49 | + $liste[] = $a; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return array_reverse($liste); |
|
| 54 | + return array_reverse($liste); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -66,23 +66,23 @@ discard block |
||
| 66 | 66 | * Liste des fichiers touvés pour ce module et cette langue. |
| 67 | 67 | **/ |
| 68 | 68 | function chercher_module_lang($module, $lang = '') { |
| 69 | - if ($lang) { |
|
| 70 | - $lang = '_' . $lang; |
|
| 71 | - } |
|
| 69 | + if ($lang) { |
|
| 70 | + $lang = '_' . $lang; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | - if ( |
|
| 75 | - $f = ($module == 'local' |
|
| 76 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | - ) { |
|
| 79 | - return is_array($f) ? $f : [$f]; |
|
| 80 | - } |
|
| 73 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | + if ( |
|
| 75 | + $f = ($module == 'local' |
|
| 76 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | + ) { |
|
| 79 | + return is_array($f) ? $f : [$f]; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | - return (($module == 'local') or strpos($module, '/')) |
|
| 84 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | - : false; |
|
| 82 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | + return (($module == 'local') or strpos($module, '/')) |
|
| 84 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | + : false; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -104,33 +104,33 @@ discard block |
||
| 104 | 104 | * @return void |
| 105 | 105 | **/ |
| 106 | 106 | function charger_langue($lang, $module = 'spip') { |
| 107 | - static $langs = []; |
|
| 108 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | - if (!isset($langs[$lang])) { |
|
| 110 | - $langs[$lang] = []; |
|
| 111 | - if ($lang) { |
|
| 112 | - $langs[$lang][] = $lang; |
|
| 113 | - if (strpos($lang, '_') !== false) { |
|
| 114 | - $l = explode('_', $lang); |
|
| 115 | - $langs[$lang][] = reset($l); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | - } |
|
| 121 | - foreach ($langs[$lang] as $l) { |
|
| 122 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 125 | - surcharger_langue($fichiers_lang); |
|
| 126 | - if ($l !== $lang) { |
|
| 127 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | - } |
|
| 129 | - $GLOBALS['lang_' . $var] = $l; |
|
| 130 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - } |
|
| 107 | + static $langs = []; |
|
| 108 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | + if (!isset($langs[$lang])) { |
|
| 110 | + $langs[$lang] = []; |
|
| 111 | + if ($lang) { |
|
| 112 | + $langs[$lang][] = $lang; |
|
| 113 | + if (strpos($lang, '_') !== false) { |
|
| 114 | + $l = explode('_', $lang); |
|
| 115 | + $langs[$lang][] = reset($l); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | + } |
|
| 121 | + foreach ($langs[$lang] as $l) { |
|
| 122 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 125 | + surcharger_langue($fichiers_lang); |
|
| 126 | + if ($l !== $lang) { |
|
| 127 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | + } |
|
| 129 | + $GLOBALS['lang_' . $var] = $l; |
|
| 130 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -143,21 +143,21 @@ discard block |
||
| 143 | 143 | * @return array<string, string> |
| 144 | 144 | */ |
| 145 | 145 | function lire_fichier_langue(string $fichier): array { |
| 146 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 147 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 148 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 149 | - $idx_lang = include $fichier; |
|
| 150 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 151 | - if (!is_array($idx_lang)) { |
|
| 152 | - if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 153 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | - } else { |
|
| 155 | - $idx_lang = []; |
|
| 156 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | - } |
|
| 158 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | - } |
|
| 160 | - return $idx_lang; |
|
| 146 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 147 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 148 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 149 | + $idx_lang = include $fichier; |
|
| 150 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 151 | + if (!is_array($idx_lang)) { |
|
| 152 | + if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 153 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | + } else { |
|
| 155 | + $idx_lang = []; |
|
| 156 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | + } |
|
| 158 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | + } |
|
| 160 | + return $idx_lang; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -177,46 +177,46 @@ discard block |
||
| 177 | 177 | * Liste des chemins de fichiers de langue à surcharger. |
| 178 | 178 | **/ |
| 179 | 179 | function surcharger_langue($fichiers) { |
| 180 | - static $surcharges = []; |
|
| 181 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | - return; |
|
| 183 | - } |
|
| 180 | + static $surcharges = []; |
|
| 181 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - if (!is_array($fichiers)) { |
|
| 186 | - $fichiers = [$fichiers]; |
|
| 187 | - } |
|
| 188 | - if (!count($fichiers)) { |
|
| 189 | - return; |
|
| 190 | - } |
|
| 191 | - foreach ($fichiers as $fichier) { |
|
| 192 | - if (!isset($surcharges[$fichier])) { |
|
| 193 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | - } |
|
| 195 | - if (is_array($surcharges[$fichier])) { |
|
| 196 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | - $surcharges[$fichier] |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 185 | + if (!is_array($fichiers)) { |
|
| 186 | + $fichiers = [$fichiers]; |
|
| 187 | + } |
|
| 188 | + if (!count($fichiers)) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 191 | + foreach ($fichiers as $fichier) { |
|
| 192 | + if (!isset($surcharges[$fichier])) { |
|
| 193 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | + } |
|
| 195 | + if (is_array($surcharges[$fichier])) { |
|
| 196 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | + $surcharges[$fichier] |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | class SPIP_Traductions_Description { |
| 208 | - /** @var string code de langue (hors module) */ |
|
| 209 | - public $code; |
|
| 210 | - /** @var string nom du module de langue */ |
|
| 211 | - public $module; |
|
| 212 | - /** @var string langue de la traduction */ |
|
| 213 | - public $langue; |
|
| 214 | - /** @var string traduction */ |
|
| 215 | - public $texte; |
|
| 216 | - /** @var string var mode particulier appliqué ? */ |
|
| 217 | - public $mode; |
|
| 218 | - /** @var bool Corrections des textes appliqué ? */ |
|
| 219 | - public $corrections = false; |
|
| 208 | + /** @var string code de langue (hors module) */ |
|
| 209 | + public $code; |
|
| 210 | + /** @var string nom du module de langue */ |
|
| 211 | + public $module; |
|
| 212 | + /** @var string langue de la traduction */ |
|
| 213 | + public $langue; |
|
| 214 | + /** @var string traduction */ |
|
| 215 | + public $texte; |
|
| 216 | + /** @var string var mode particulier appliqué ? */ |
|
| 217 | + public $mode; |
|
| 218 | + /** @var bool Corrections des textes appliqué ? */ |
|
| 219 | + public $corrections = false; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | |
@@ -258,99 +258,99 @@ discard block |
||
| 258 | 258 | * - SPIP_Traductions_Description : traduction et description (texte, module, langue) |
| 259 | 259 | **/ |
| 260 | 260 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 261 | - static $deja_vu = []; |
|
| 262 | - static $local = []; |
|
| 261 | + static $deja_vu = []; |
|
| 262 | + static $local = []; |
|
| 263 | 263 | |
| 264 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 265 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 266 | - } |
|
| 264 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 265 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 269 | - if (strpos($ori, ':')) { |
|
| 270 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 271 | - $modules = explode('|', $modules); |
|
| 272 | - $ori_complet = $ori; |
|
| 273 | - } else { |
|
| 274 | - $modules = ['spip', 'ecrire']; |
|
| 275 | - $code = $ori; |
|
| 276 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 277 | - } |
|
| 268 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 269 | + if (strpos($ori, ':')) { |
|
| 270 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 271 | + $modules = explode('|', $modules); |
|
| 272 | + $ori_complet = $ori; |
|
| 273 | + } else { |
|
| 274 | + $modules = ['spip', 'ecrire']; |
|
| 275 | + $code = $ori; |
|
| 276 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - $desc = new SPIP_Traductions_Description(); |
|
| 279 | + $desc = new SPIP_Traductions_Description(); |
|
| 280 | 280 | |
| 281 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 282 | - foreach ($modules as $module) { |
|
| 283 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 281 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 282 | + foreach ($modules as $module) { |
|
| 283 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 284 | 284 | |
| 285 | - if (empty($GLOBALS[$var])) { |
|
| 286 | - charger_langue($lang, $module); |
|
| 287 | - // surcharges persos -- on cherche |
|
| 288 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 289 | - if (!isset($local['local_' . $lang])) { |
|
| 290 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 291 | - $GLOBALS['idx_lang'] = $var; |
|
| 292 | - // ... (lang/)local_xx.php |
|
| 293 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 294 | - } |
|
| 295 | - if ($local['local_' . $lang]) { |
|
| 296 | - surcharger_langue($local['local_' . $lang]); |
|
| 297 | - } |
|
| 298 | - // ... puis (lang/)local.php |
|
| 299 | - if (!isset($local['local'])) { |
|
| 300 | - $local['local'] = chercher_module_lang('local'); |
|
| 301 | - } |
|
| 302 | - if ($local['local']) { |
|
| 303 | - surcharger_langue($local['local']); |
|
| 304 | - } |
|
| 305 | - } |
|
| 285 | + if (empty($GLOBALS[$var])) { |
|
| 286 | + charger_langue($lang, $module); |
|
| 287 | + // surcharges persos -- on cherche |
|
| 288 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 289 | + if (!isset($local['local_' . $lang])) { |
|
| 290 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 291 | + $GLOBALS['idx_lang'] = $var; |
|
| 292 | + // ... (lang/)local_xx.php |
|
| 293 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 294 | + } |
|
| 295 | + if ($local['local_' . $lang]) { |
|
| 296 | + surcharger_langue($local['local_' . $lang]); |
|
| 297 | + } |
|
| 298 | + // ... puis (lang/)local.php |
|
| 299 | + if (!isset($local['local'])) { |
|
| 300 | + $local['local'] = chercher_module_lang('local'); |
|
| 301 | + } |
|
| 302 | + if ($local['local']) { |
|
| 303 | + surcharger_langue($local['local']); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - if (isset($GLOBALS[$var][$code])) { |
|
| 308 | - $desc->code = $code; |
|
| 309 | - $desc->module = $module; |
|
| 310 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 311 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 312 | - break; |
|
| 313 | - } |
|
| 314 | - } |
|
| 307 | + if (isset($GLOBALS[$var][$code])) { |
|
| 308 | + $desc->code = $code; |
|
| 309 | + $desc->module = $module; |
|
| 310 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 311 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 312 | + break; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - if (!$desc->corrections) { |
|
| 317 | - $desc->corrections = true; |
|
| 318 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 319 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 320 | - if ( |
|
| 321 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 322 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 323 | - ) { |
|
| 324 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 325 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 326 | - } else { |
|
| 327 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 328 | - } |
|
| 329 | - } |
|
| 316 | + if (!$desc->corrections) { |
|
| 317 | + $desc->corrections = true; |
|
| 318 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 319 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 320 | + if ( |
|
| 321 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 322 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 323 | + ) { |
|
| 324 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 325 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 326 | + } else { |
|
| 327 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 332 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 333 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 334 | - } |
|
| 331 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 332 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 333 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 337 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 338 | - if ( |
|
| 339 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 340 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 341 | - ) { |
|
| 342 | - include_spip('inc/charsets'); |
|
| 343 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 344 | - } |
|
| 345 | - } |
|
| 336 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 337 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 338 | + if ( |
|
| 339 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 340 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 341 | + ) { |
|
| 342 | + include_spip('inc/charsets'); |
|
| 343 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - if (_request('var_mode') == 'traduction') { |
|
| 348 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 349 | - } else { |
|
| 350 | - $deja_vu[$lang][$ori] = $desc; |
|
| 351 | - } |
|
| 347 | + if (_request('var_mode') == 'traduction') { |
|
| 348 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 349 | + } else { |
|
| 350 | + $deja_vu[$lang][$ori] = $desc; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - return $raw ? $desc : $desc->texte; |
|
| 353 | + return $raw ? $desc : $desc->texte; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -362,23 +362,23 @@ discard block |
||
| 362 | 362 | * @return SPIP_Traductions_Description |
| 363 | 363 | */ |
| 364 | 364 | function definir_details_traduction($desc, $modules) { |
| 365 | - if (!$desc->mode and $desc->texte) { |
|
| 366 | - // ne pas modifier 2 fois l'affichage |
|
| 367 | - $desc->mode = 'traduction'; |
|
| 368 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | - $desc->texte = '<span ' |
|
| 370 | - . 'lang=' . $desc->langue |
|
| 371 | - . ' class=' . $classe |
|
| 372 | - . ' data-module=' . $desc->module |
|
| 373 | - . ' data-code=' . $desc->code |
|
| 374 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 375 | - . $desc->texte |
|
| 376 | - . '</span>'; |
|
| 377 | - $desc->texte = str_replace( |
|
| 378 | - ["$desc->module:", "$desc->module|"], |
|
| 379 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 380 | - $desc->texte |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - return $desc; |
|
| 365 | + if (!$desc->mode and $desc->texte) { |
|
| 366 | + // ne pas modifier 2 fois l'affichage |
|
| 367 | + $desc->mode = 'traduction'; |
|
| 368 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | + $desc->texte = '<span ' |
|
| 370 | + . 'lang=' . $desc->langue |
|
| 371 | + . ' class=' . $classe |
|
| 372 | + . ' data-module=' . $desc->module |
|
| 373 | + . ' data-code=' . $desc->code |
|
| 374 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 375 | + . $desc->texte |
|
| 376 | + . '</span>'; |
|
| 377 | + $desc->texte = str_replace( |
|
| 378 | + ["$desc->module:", "$desc->module|"], |
|
| 379 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 380 | + $desc->texte |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + return $desc; |
|
| 384 | 384 | } |
@@ -17,11 +17,11 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = [ |
|
| 47 | - 'field' => [ |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = [ |
|
| 47 | + 'field' => [ |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,518 +62,518 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** Tableau de données */ |
|
| 66 | - protected array $tableau = []; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Conditions de filtrage |
|
| 70 | - * ie criteres de selection |
|
| 71 | - */ |
|
| 72 | - protected array $filtre = []; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Cle courante |
|
| 77 | - * |
|
| 78 | - * @var scalar |
|
| 79 | - */ |
|
| 80 | - protected $cle = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Valeur courante |
|
| 84 | - * |
|
| 85 | - * @var mixed |
|
| 86 | - */ |
|
| 87 | - protected $valeur = null; |
|
| 88 | - |
|
| 89 | - protected string $type = 'DATA'; |
|
| 90 | - |
|
| 91 | - protected array $command = []; |
|
| 92 | - |
|
| 93 | - protected array $info = []; |
|
| 94 | - |
|
| 95 | - /** Erreur presente ? */ |
|
| 96 | - public bool $err = false; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Calcul du total des elements |
|
| 100 | - * |
|
| 101 | - * @var int|null |
|
| 102 | - **/ |
|
| 103 | - public $total = null; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Constructeur |
|
| 107 | - * |
|
| 108 | - * @param $command |
|
| 109 | - * @param array $info |
|
| 110 | - */ |
|
| 111 | - public function __construct($command, $info = []) { |
|
| 112 | - $this->type = 'DATA'; |
|
| 113 | - $this->command = $command; |
|
| 114 | - $this->info = $info; |
|
| 115 | - |
|
| 116 | - $this->select($command); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Revenir au depart |
|
| 121 | - * |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public function rewind(): void { |
|
| 125 | - reset($this->tableau); |
|
| 126 | - $this->cle = array_key_first($this->tableau); |
|
| 127 | - $this->valeur = current($this->tableau); |
|
| 128 | - next($this->tableau); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Déclarer les critères exceptions |
|
| 133 | - * |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - public function exception_des_criteres() { |
|
| 137 | - return ['tableau']; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Récupérer depuis le cache si possible |
|
| 142 | - * |
|
| 143 | - * @param string $cle |
|
| 144 | - * @return mixed |
|
| 145 | - */ |
|
| 146 | - protected function cache_get($cle) { |
|
| 147 | - if (!$cle) { |
|
| 148 | - return; |
|
| 149 | - } |
|
| 150 | - # utiliser memoization si dispo |
|
| 151 | - if (!function_exists('cache_get')) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return cache_get($cle); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Stocker en cache si possible |
|
| 160 | - * |
|
| 161 | - * @param string $cle |
|
| 162 | - * @param int $ttl |
|
| 163 | - * @param null|mixed $valeur |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 167 | - if (!$cle) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 170 | - if (is_null($valeur)) { |
|
| 171 | - $valeur = $this->tableau; |
|
| 172 | - } |
|
| 173 | - # utiliser memoization si dispo |
|
| 174 | - if (!function_exists('cache_set')) { |
|
| 175 | - return; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return cache_set( |
|
| 179 | - $cle, |
|
| 180 | - [ |
|
| 181 | - 'data' => $valeur, |
|
| 182 | - 'time' => time(), |
|
| 183 | - 'ttl' => $ttl |
|
| 184 | - ], |
|
| 185 | - 3600 + $ttl |
|
| 186 | - ); |
|
| 187 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 188 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Aller chercher les données de la boucle DATA |
|
| 193 | - * |
|
| 194 | - * @throws Exception |
|
| 195 | - * @param array $command |
|
| 196 | - * @return void |
|
| 197 | - */ |
|
| 198 | - protected function select($command) { |
|
| 199 | - |
|
| 200 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 201 | - // le type se retrouve dans la commande 'from' |
|
| 202 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 203 | - if (isset($this->command['from'][0])) { |
|
| 204 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 205 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 206 | - } |
|
| 207 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 211 | - // les commandes connues pour l'iterateur DATA |
|
| 212 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 213 | - |
|
| 214 | - // {source format, [URL], [arg2]...} |
|
| 215 | - if ( |
|
| 216 | - isset($this->command['source']) |
|
| 217 | - and isset($this->command['sourcemode']) |
|
| 218 | - ) { |
|
| 219 | - $this->select_source(); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // Critere {liste X1, X2, X3} |
|
| 223 | - if (isset($this->command['liste'])) { |
|
| 224 | - $this->select_liste(); |
|
| 225 | - } |
|
| 226 | - if (isset($this->command['enum'])) { |
|
| 227 | - $this->select_enum(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 231 | - if (!is_array($this->tableau)) { |
|
| 232 | - $this->err = true; |
|
| 233 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // {datapath query.results} |
|
| 237 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 238 | - if ( |
|
| 239 | - !$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if ( |
|
| 272 | - isset($this->command['sourcemode']) |
|
| 273 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 274 | - ) { |
|
| 275 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - # le premier argument peut etre un array, une URL etc. |
|
| 279 | - $src = $this->command['source'][0]; |
|
| 280 | - |
|
| 281 | - # avons-nous un cache dispo ? |
|
| 282 | - $cle = null; |
|
| 283 | - if (is_string($src)) { |
|
| 284 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $cache = $this->cache_get($cle); |
|
| 288 | - if (isset($this->command['datacache'])) { |
|
| 289 | - $ttl = intval($this->command['datacache']); |
|
| 290 | - } |
|
| 291 | - if ( |
|
| 292 | - $cache |
|
| 293 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 294 | - > time()) |
|
| 295 | - and !(_request('var_mode') === 'recalcul' |
|
| 296 | - and include_spip('inc/autoriser') |
|
| 297 | - and autoriser('recalcul') |
|
| 298 | - ) |
|
| 299 | - ) { |
|
| 300 | - $this->tableau = $cache['data']; |
|
| 301 | - } else { |
|
| 302 | - try { |
|
| 303 | - if ( |
|
| 304 | - isset($this->command['sourcemode']) |
|
| 305 | - and in_array( |
|
| 306 | - $this->command['sourcemode'], |
|
| 307 | - ['table', 'array', 'tableau'] |
|
| 308 | - ) |
|
| 309 | - ) { |
|
| 310 | - if ( |
|
| 311 | - is_array($a = $src) |
|
| 312 | - or (is_string($a) |
|
| 313 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 314 | - and is_array($a = @unserialize($a))) |
|
| 315 | - ) { |
|
| 316 | - $this->tableau = $a; |
|
| 317 | - } |
|
| 318 | - } else { |
|
| 319 | - $data = $src; |
|
| 320 | - if (is_string($src)) { |
|
| 321 | - if (tester_url_absolue($src)) { |
|
| 322 | - include_spip('inc/distant'); |
|
| 323 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 324 | - $data = $data['page'] ?? ''; |
|
| 325 | - if (!$data) { |
|
| 326 | - throw new Exception('404'); |
|
| 327 | - } |
|
| 328 | - if (!isset($ttl)) { |
|
| 329 | - $ttl = 24 * 3600; |
|
| 330 | - } |
|
| 331 | - } elseif (@is_dir($src)) { |
|
| 332 | - $data = $src; |
|
| 333 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 334 | - $data = spip_file_get_contents($src); |
|
| 335 | - } |
|
| 336 | - if (!isset($ttl)) { |
|
| 337 | - $ttl = 10; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - if ( |
|
| 342 | - !$this->err |
|
| 343 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 344 | - ) { |
|
| 345 | - $args = $this->command['source']; |
|
| 346 | - $args[0] = $data; |
|
| 347 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 348 | - $this->tableau = $a; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!is_array($this->tableau)) { |
|
| 354 | - $this->err = true; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 358 | - $this->cache_set($cle, $ttl); |
|
| 359 | - } |
|
| 360 | - } catch (Exception $e) { |
|
| 361 | - $e = $e->getMessage(); |
|
| 362 | - $err = sprintf( |
|
| 363 | - "[%s, %s] $e", |
|
| 364 | - $src, |
|
| 365 | - $this->command['sourcemode'] |
|
| 366 | - ); |
|
| 367 | - erreur_squelette([$err, []]); |
|
| 368 | - $this->err = true; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 373 | - if ( |
|
| 374 | - $this->err |
|
| 375 | - and $cache |
|
| 376 | - ) { |
|
| 377 | - $this->tableau = $cache['data']; |
|
| 378 | - $this->err = false; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Retourne un tableau donne depuis un critère liste |
|
| 385 | - * |
|
| 386 | - * Critère `{liste X1, X2, X3}` |
|
| 387 | - * |
|
| 388 | - * @see critere_DATA_liste_dist() |
|
| 389 | - * |
|
| 390 | - **/ |
|
| 391 | - protected function select_liste() { |
|
| 392 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 393 | - if (!isset($this->command['liste'][1])) { |
|
| 394 | - if (!is_array($this->command['liste'][0])) { |
|
| 395 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 396 | - } else { |
|
| 397 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - $this->tableau = $this->command['liste']; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Retourne un tableau donne depuis un critere liste |
|
| 405 | - * Critere {enum Xmin, Xmax} |
|
| 406 | - * |
|
| 407 | - **/ |
|
| 408 | - protected function select_enum() { |
|
| 409 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 410 | - if (!isset($this->command['enum'][1])) { |
|
| 411 | - if (!is_array($this->command['enum'][0])) { |
|
| 412 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 413 | - } else { |
|
| 414 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 418 | - $enum = range( |
|
| 419 | - array_shift($this->command['enum']), |
|
| 420 | - array_shift($this->command['enum']), |
|
| 421 | - array_shift($this->command['enum']) |
|
| 422 | - ); |
|
| 423 | - } else { |
|
| 424 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 425 | - } |
|
| 426 | - $this->tableau = $enum; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 432 | - * {datapath query.results} |
|
| 433 | - * |
|
| 434 | - **/ |
|
| 435 | - protected function select_datapath() { |
|
| 436 | - $base = reset($this->command['datapath']); |
|
| 437 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 438 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 439 | - if (!is_array($this->tableau)) { |
|
| 440 | - $this->tableau = []; |
|
| 441 | - $this->err = true; |
|
| 442 | - spip_log("datapath '$base' absent"); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Ordonner les resultats |
|
| 449 | - * {par x} |
|
| 450 | - * |
|
| 451 | - **/ |
|
| 452 | - protected function select_orderby() { |
|
| 453 | - $sortfunc = ''; |
|
| 454 | - $aleas = 0; |
|
| 455 | - foreach ($this->command['orderby'] as $tri) { |
|
| 456 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 457 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 458 | - $r = array_pad($r, 3, null); |
|
| 459 | - |
|
| 460 | - // tri par cle |
|
| 461 | - if ($r[1] == 'cle') { |
|
| 462 | - if (isset($r[2]) and $r[2]) { |
|
| 463 | - krsort($this->tableau); |
|
| 464 | - } else { |
|
| 465 | - ksort($this->tableau); |
|
| 466 | - } |
|
| 467 | - } # {par hasard} |
|
| 468 | - else { |
|
| 469 | - if ($r[1] == 'hasard') { |
|
| 470 | - $k = array_keys($this->tableau); |
|
| 471 | - shuffle($k); |
|
| 472 | - $v = []; |
|
| 473 | - foreach ($k as $cle) { |
|
| 474 | - $v[$cle] = $this->tableau[$cle]; |
|
| 475 | - } |
|
| 476 | - $this->tableau = $v; |
|
| 477 | - } else { |
|
| 478 | - # {par valeur} |
|
| 479 | - if ($r[1] == 'valeur') { |
|
| 480 | - $tv = '%s'; |
|
| 481 | - } # {par valeur/xx/yy} ?? |
|
| 482 | - else { |
|
| 483 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 484 | - } |
|
| 485 | - $sortfunc .= ' |
|
| 65 | + /** Tableau de données */ |
|
| 66 | + protected array $tableau = []; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Conditions de filtrage |
|
| 70 | + * ie criteres de selection |
|
| 71 | + */ |
|
| 72 | + protected array $filtre = []; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Cle courante |
|
| 77 | + * |
|
| 78 | + * @var scalar |
|
| 79 | + */ |
|
| 80 | + protected $cle = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Valeur courante |
|
| 84 | + * |
|
| 85 | + * @var mixed |
|
| 86 | + */ |
|
| 87 | + protected $valeur = null; |
|
| 88 | + |
|
| 89 | + protected string $type = 'DATA'; |
|
| 90 | + |
|
| 91 | + protected array $command = []; |
|
| 92 | + |
|
| 93 | + protected array $info = []; |
|
| 94 | + |
|
| 95 | + /** Erreur presente ? */ |
|
| 96 | + public bool $err = false; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Calcul du total des elements |
|
| 100 | + * |
|
| 101 | + * @var int|null |
|
| 102 | + **/ |
|
| 103 | + public $total = null; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Constructeur |
|
| 107 | + * |
|
| 108 | + * @param $command |
|
| 109 | + * @param array $info |
|
| 110 | + */ |
|
| 111 | + public function __construct($command, $info = []) { |
|
| 112 | + $this->type = 'DATA'; |
|
| 113 | + $this->command = $command; |
|
| 114 | + $this->info = $info; |
|
| 115 | + |
|
| 116 | + $this->select($command); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Revenir au depart |
|
| 121 | + * |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public function rewind(): void { |
|
| 125 | + reset($this->tableau); |
|
| 126 | + $this->cle = array_key_first($this->tableau); |
|
| 127 | + $this->valeur = current($this->tableau); |
|
| 128 | + next($this->tableau); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Déclarer les critères exceptions |
|
| 133 | + * |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + public function exception_des_criteres() { |
|
| 137 | + return ['tableau']; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Récupérer depuis le cache si possible |
|
| 142 | + * |
|
| 143 | + * @param string $cle |
|
| 144 | + * @return mixed |
|
| 145 | + */ |
|
| 146 | + protected function cache_get($cle) { |
|
| 147 | + if (!$cle) { |
|
| 148 | + return; |
|
| 149 | + } |
|
| 150 | + # utiliser memoization si dispo |
|
| 151 | + if (!function_exists('cache_get')) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return cache_get($cle); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Stocker en cache si possible |
|
| 160 | + * |
|
| 161 | + * @param string $cle |
|
| 162 | + * @param int $ttl |
|
| 163 | + * @param null|mixed $valeur |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 167 | + if (!$cle) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | + if (is_null($valeur)) { |
|
| 171 | + $valeur = $this->tableau; |
|
| 172 | + } |
|
| 173 | + # utiliser memoization si dispo |
|
| 174 | + if (!function_exists('cache_set')) { |
|
| 175 | + return; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return cache_set( |
|
| 179 | + $cle, |
|
| 180 | + [ |
|
| 181 | + 'data' => $valeur, |
|
| 182 | + 'time' => time(), |
|
| 183 | + 'ttl' => $ttl |
|
| 184 | + ], |
|
| 185 | + 3600 + $ttl |
|
| 186 | + ); |
|
| 187 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 188 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Aller chercher les données de la boucle DATA |
|
| 193 | + * |
|
| 194 | + * @throws Exception |
|
| 195 | + * @param array $command |
|
| 196 | + * @return void |
|
| 197 | + */ |
|
| 198 | + protected function select($command) { |
|
| 199 | + |
|
| 200 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 201 | + // le type se retrouve dans la commande 'from' |
|
| 202 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 203 | + if (isset($this->command['from'][0])) { |
|
| 204 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 205 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 206 | + } |
|
| 207 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 211 | + // les commandes connues pour l'iterateur DATA |
|
| 212 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 213 | + |
|
| 214 | + // {source format, [URL], [arg2]...} |
|
| 215 | + if ( |
|
| 216 | + isset($this->command['source']) |
|
| 217 | + and isset($this->command['sourcemode']) |
|
| 218 | + ) { |
|
| 219 | + $this->select_source(); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // Critere {liste X1, X2, X3} |
|
| 223 | + if (isset($this->command['liste'])) { |
|
| 224 | + $this->select_liste(); |
|
| 225 | + } |
|
| 226 | + if (isset($this->command['enum'])) { |
|
| 227 | + $this->select_enum(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 231 | + if (!is_array($this->tableau)) { |
|
| 232 | + $this->err = true; |
|
| 233 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // {datapath query.results} |
|
| 237 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 238 | + if ( |
|
| 239 | + !$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if ( |
|
| 272 | + isset($this->command['sourcemode']) |
|
| 273 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 274 | + ) { |
|
| 275 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + # le premier argument peut etre un array, une URL etc. |
|
| 279 | + $src = $this->command['source'][0]; |
|
| 280 | + |
|
| 281 | + # avons-nous un cache dispo ? |
|
| 282 | + $cle = null; |
|
| 283 | + if (is_string($src)) { |
|
| 284 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $cache = $this->cache_get($cle); |
|
| 288 | + if (isset($this->command['datacache'])) { |
|
| 289 | + $ttl = intval($this->command['datacache']); |
|
| 290 | + } |
|
| 291 | + if ( |
|
| 292 | + $cache |
|
| 293 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 294 | + > time()) |
|
| 295 | + and !(_request('var_mode') === 'recalcul' |
|
| 296 | + and include_spip('inc/autoriser') |
|
| 297 | + and autoriser('recalcul') |
|
| 298 | + ) |
|
| 299 | + ) { |
|
| 300 | + $this->tableau = $cache['data']; |
|
| 301 | + } else { |
|
| 302 | + try { |
|
| 303 | + if ( |
|
| 304 | + isset($this->command['sourcemode']) |
|
| 305 | + and in_array( |
|
| 306 | + $this->command['sourcemode'], |
|
| 307 | + ['table', 'array', 'tableau'] |
|
| 308 | + ) |
|
| 309 | + ) { |
|
| 310 | + if ( |
|
| 311 | + is_array($a = $src) |
|
| 312 | + or (is_string($a) |
|
| 313 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 314 | + and is_array($a = @unserialize($a))) |
|
| 315 | + ) { |
|
| 316 | + $this->tableau = $a; |
|
| 317 | + } |
|
| 318 | + } else { |
|
| 319 | + $data = $src; |
|
| 320 | + if (is_string($src)) { |
|
| 321 | + if (tester_url_absolue($src)) { |
|
| 322 | + include_spip('inc/distant'); |
|
| 323 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 324 | + $data = $data['page'] ?? ''; |
|
| 325 | + if (!$data) { |
|
| 326 | + throw new Exception('404'); |
|
| 327 | + } |
|
| 328 | + if (!isset($ttl)) { |
|
| 329 | + $ttl = 24 * 3600; |
|
| 330 | + } |
|
| 331 | + } elseif (@is_dir($src)) { |
|
| 332 | + $data = $src; |
|
| 333 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 334 | + $data = spip_file_get_contents($src); |
|
| 335 | + } |
|
| 336 | + if (!isset($ttl)) { |
|
| 337 | + $ttl = 10; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + if ( |
|
| 342 | + !$this->err |
|
| 343 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 344 | + ) { |
|
| 345 | + $args = $this->command['source']; |
|
| 346 | + $args[0] = $data; |
|
| 347 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 348 | + $this->tableau = $a; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!is_array($this->tableau)) { |
|
| 354 | + $this->err = true; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 358 | + $this->cache_set($cle, $ttl); |
|
| 359 | + } |
|
| 360 | + } catch (Exception $e) { |
|
| 361 | + $e = $e->getMessage(); |
|
| 362 | + $err = sprintf( |
|
| 363 | + "[%s, %s] $e", |
|
| 364 | + $src, |
|
| 365 | + $this->command['sourcemode'] |
|
| 366 | + ); |
|
| 367 | + erreur_squelette([$err, []]); |
|
| 368 | + $this->err = true; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 373 | + if ( |
|
| 374 | + $this->err |
|
| 375 | + and $cache |
|
| 376 | + ) { |
|
| 377 | + $this->tableau = $cache['data']; |
|
| 378 | + $this->err = false; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Retourne un tableau donne depuis un critère liste |
|
| 385 | + * |
|
| 386 | + * Critère `{liste X1, X2, X3}` |
|
| 387 | + * |
|
| 388 | + * @see critere_DATA_liste_dist() |
|
| 389 | + * |
|
| 390 | + **/ |
|
| 391 | + protected function select_liste() { |
|
| 392 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 393 | + if (!isset($this->command['liste'][1])) { |
|
| 394 | + if (!is_array($this->command['liste'][0])) { |
|
| 395 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 396 | + } else { |
|
| 397 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + $this->tableau = $this->command['liste']; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Retourne un tableau donne depuis un critere liste |
|
| 405 | + * Critere {enum Xmin, Xmax} |
|
| 406 | + * |
|
| 407 | + **/ |
|
| 408 | + protected function select_enum() { |
|
| 409 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 410 | + if (!isset($this->command['enum'][1])) { |
|
| 411 | + if (!is_array($this->command['enum'][0])) { |
|
| 412 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 413 | + } else { |
|
| 414 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 418 | + $enum = range( |
|
| 419 | + array_shift($this->command['enum']), |
|
| 420 | + array_shift($this->command['enum']), |
|
| 421 | + array_shift($this->command['enum']) |
|
| 422 | + ); |
|
| 423 | + } else { |
|
| 424 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 425 | + } |
|
| 426 | + $this->tableau = $enum; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 432 | + * {datapath query.results} |
|
| 433 | + * |
|
| 434 | + **/ |
|
| 435 | + protected function select_datapath() { |
|
| 436 | + $base = reset($this->command['datapath']); |
|
| 437 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 438 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 439 | + if (!is_array($this->tableau)) { |
|
| 440 | + $this->tableau = []; |
|
| 441 | + $this->err = true; |
|
| 442 | + spip_log("datapath '$base' absent"); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Ordonner les resultats |
|
| 449 | + * {par x} |
|
| 450 | + * |
|
| 451 | + **/ |
|
| 452 | + protected function select_orderby() { |
|
| 453 | + $sortfunc = ''; |
|
| 454 | + $aleas = 0; |
|
| 455 | + foreach ($this->command['orderby'] as $tri) { |
|
| 456 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 457 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 458 | + $r = array_pad($r, 3, null); |
|
| 459 | + |
|
| 460 | + // tri par cle |
|
| 461 | + if ($r[1] == 'cle') { |
|
| 462 | + if (isset($r[2]) and $r[2]) { |
|
| 463 | + krsort($this->tableau); |
|
| 464 | + } else { |
|
| 465 | + ksort($this->tableau); |
|
| 466 | + } |
|
| 467 | + } # {par hasard} |
|
| 468 | + else { |
|
| 469 | + if ($r[1] == 'hasard') { |
|
| 470 | + $k = array_keys($this->tableau); |
|
| 471 | + shuffle($k); |
|
| 472 | + $v = []; |
|
| 473 | + foreach ($k as $cle) { |
|
| 474 | + $v[$cle] = $this->tableau[$cle]; |
|
| 475 | + } |
|
| 476 | + $this->tableau = $v; |
|
| 477 | + } else { |
|
| 478 | + # {par valeur} |
|
| 479 | + if ($r[1] == 'valeur') { |
|
| 480 | + $tv = '%s'; |
|
| 481 | + } # {par valeur/xx/yy} ?? |
|
| 482 | + else { |
|
| 483 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 484 | + } |
|
| 485 | + $sortfunc .= ' |
|
| 486 | 486 | $a = ' . sprintf($tv, '$aa') . '; |
| 487 | 487 | $b = ' . sprintf($tv, '$bb') . '; |
| 488 | 488 | if ($a <> $b) |
| 489 | 489 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ($sortfunc) { |
|
| 496 | - $sortfunc .= "\n return 0;"; |
|
| 497 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Grouper les resultats |
|
| 504 | - * {fusion /x/y/z} |
|
| 505 | - * |
|
| 506 | - **/ |
|
| 507 | - protected function select_groupby() { |
|
| 508 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 509 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 510 | - $vu = []; |
|
| 511 | - foreach ($this->tableau as $k => $v) { |
|
| 512 | - $val = table_valeur($v, $fusion); |
|
| 513 | - if (isset($vu[$val])) { |
|
| 514 | - unset($this->tableau[$k]); |
|
| 515 | - } else { |
|
| 516 | - $vu[$val] = true; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * L'iterateur est-il encore valide ? |
|
| 525 | - * |
|
| 526 | - * @return bool |
|
| 527 | - */ |
|
| 528 | - public function valid(): bool { |
|
| 529 | - return !is_null($this->cle); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Retourner la valeur |
|
| 534 | - * |
|
| 535 | - * @return mixed |
|
| 536 | - */ |
|
| 537 | - #[\ReturnTypeWillChange] |
|
| 538 | - public function current() { |
|
| 539 | - return $this->valeur; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Retourner la cle |
|
| 544 | - * |
|
| 545 | - * @return mixed |
|
| 546 | - */ |
|
| 547 | - #[\ReturnTypeWillChange] |
|
| 548 | - public function key() { |
|
| 549 | - return $this->cle; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Passer a la valeur suivante |
|
| 554 | - * |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - public function next(): void { |
|
| 558 | - if ($this->valid()) { |
|
| 559 | - $this->cle = key($this->tableau); |
|
| 560 | - $this->valeur = current($this->tableau); |
|
| 561 | - next($this->tableau); |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Compter le nombre total de resultats |
|
| 567 | - * |
|
| 568 | - * @return int |
|
| 569 | - */ |
|
| 570 | - public function count() { |
|
| 571 | - if (is_null($this->total)) { |
|
| 572 | - $this->total = count($this->tableau); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $this->total; |
|
| 576 | - } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ($sortfunc) { |
|
| 496 | + $sortfunc .= "\n return 0;"; |
|
| 497 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Grouper les resultats |
|
| 504 | + * {fusion /x/y/z} |
|
| 505 | + * |
|
| 506 | + **/ |
|
| 507 | + protected function select_groupby() { |
|
| 508 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 509 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 510 | + $vu = []; |
|
| 511 | + foreach ($this->tableau as $k => $v) { |
|
| 512 | + $val = table_valeur($v, $fusion); |
|
| 513 | + if (isset($vu[$val])) { |
|
| 514 | + unset($this->tableau[$k]); |
|
| 515 | + } else { |
|
| 516 | + $vu[$val] = true; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * L'iterateur est-il encore valide ? |
|
| 525 | + * |
|
| 526 | + * @return bool |
|
| 527 | + */ |
|
| 528 | + public function valid(): bool { |
|
| 529 | + return !is_null($this->cle); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Retourner la valeur |
|
| 534 | + * |
|
| 535 | + * @return mixed |
|
| 536 | + */ |
|
| 537 | + #[\ReturnTypeWillChange] |
|
| 538 | + public function current() { |
|
| 539 | + return $this->valeur; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Retourner la cle |
|
| 544 | + * |
|
| 545 | + * @return mixed |
|
| 546 | + */ |
|
| 547 | + #[\ReturnTypeWillChange] |
|
| 548 | + public function key() { |
|
| 549 | + return $this->cle; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Passer a la valeur suivante |
|
| 554 | + * |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + public function next(): void { |
|
| 558 | + if ($this->valid()) { |
|
| 559 | + $this->cle = key($this->tableau); |
|
| 560 | + $this->valeur = current($this->tableau); |
|
| 561 | + next($this->tableau); |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Compter le nombre total de resultats |
|
| 567 | + * |
|
| 568 | + * @return int |
|
| 569 | + */ |
|
| 570 | + public function count() { |
|
| 571 | + if (is_null($this->total)) { |
|
| 572 | + $this->total = count($this->tableau); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $this->total; |
|
| 576 | + } |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /* |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * @return array |
| 588 | 588 | */ |
| 589 | 589 | function inc_file_to_array_dist($data) { |
| 590 | - return preg_split('/\r?\n/', $data); |
|
| 590 | + return preg_split('/\r?\n/', $data); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -596,9 +596,9 @@ discard block |
||
| 596 | 596 | * @return array |
| 597 | 597 | */ |
| 598 | 598 | function inc_plugins_to_array_dist() { |
| 599 | - include_spip('inc/plugin'); |
|
| 599 | + include_spip('inc/plugin'); |
|
| 600 | 600 | |
| 601 | - return liste_chemin_plugin_actifs(); |
|
| 601 | + return liste_chemin_plugin_actifs(); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @return array |
| 609 | 609 | */ |
| 610 | 610 | function inc_xml_to_array_dist($data) { |
| 611 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 611 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -620,14 +620,14 @@ discard block |
||
| 620 | 620 | * |
| 621 | 621 | */ |
| 622 | 622 | function inc_object_to_array($object) { |
| 623 | - if (!is_object($object) && !is_array($object)) { |
|
| 624 | - return $object; |
|
| 625 | - } |
|
| 626 | - if (is_object($object)) { |
|
| 627 | - $object = get_object_vars($object); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - return array_map('inc_object_to_array', $object); |
|
| 623 | + if (!is_object($object) && !is_array($object)) { |
|
| 624 | + return $object; |
|
| 625 | + } |
|
| 626 | + if (is_object($object)) { |
|
| 627 | + $object = get_object_vars($object); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + return array_map('inc_object_to_array', $object); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -637,20 +637,20 @@ discard block |
||
| 637 | 637 | * @return array|bool |
| 638 | 638 | */ |
| 639 | 639 | function inc_sql_to_array_dist($data) { |
| 640 | - # sortir le connecteur de $data |
|
| 641 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 642 | - $serveur = (string)$v[1]; |
|
| 643 | - $req = trim($v[2]); |
|
| 644 | - if ($s = sql_query($req, $serveur)) { |
|
| 645 | - $r = []; |
|
| 646 | - while ($t = sql_fetch($s)) { |
|
| 647 | - $r[] = $t; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $r; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return false; |
|
| 640 | + # sortir le connecteur de $data |
|
| 641 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 642 | + $serveur = (string)$v[1]; |
|
| 643 | + $req = trim($v[2]); |
|
| 644 | + if ($s = sql_query($req, $serveur)) { |
|
| 645 | + $r = []; |
|
| 646 | + while ($t = sql_fetch($s)) { |
|
| 647 | + $r[] = $t; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $r; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return false; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -660,13 +660,13 @@ discard block |
||
| 660 | 660 | * @return array|bool |
| 661 | 661 | */ |
| 662 | 662 | function inc_json_to_array_dist($data) { |
| 663 | - try { |
|
| 664 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 665 | - } catch (JsonException $e) { |
|
| 666 | - $json = null; |
|
| 667 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 668 | - } |
|
| 669 | - return is_array($json) ? (array) $json : []; |
|
| 663 | + try { |
|
| 664 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 665 | + } catch (JsonException $e) { |
|
| 666 | + $json = null; |
|
| 667 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 668 | + } |
|
| 669 | + return is_array($json) ? (array) $json : []; |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
@@ -676,30 +676,30 @@ discard block |
||
| 676 | 676 | * @return array|bool |
| 677 | 677 | */ |
| 678 | 678 | function inc_csv_to_array_dist($data) { |
| 679 | - include_spip('inc/csv'); |
|
| 680 | - [$entete, $csv] = analyse_csv($data); |
|
| 681 | - array_unshift($csv, $entete); |
|
| 682 | - |
|
| 683 | - include_spip('inc/charsets'); |
|
| 684 | - $i = 1; |
|
| 685 | - foreach ($entete as $k => $v) { |
|
| 686 | - if (trim($v) == '') { |
|
| 687 | - $v = 'col' . $i; |
|
| 688 | - } // reperer des eventuelles cases vides |
|
| 689 | - if (is_numeric($v) and $v < 0) { |
|
| 690 | - $v = '__' . $v; |
|
| 691 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 692 | - if (is_numeric($v)) { |
|
| 693 | - $v = '_' . $v; |
|
| 694 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 695 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 696 | - foreach ($csv as &$item) { |
|
| 697 | - $item[$v] = &$item[$k]; |
|
| 698 | - } |
|
| 699 | - $i++; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return $csv; |
|
| 679 | + include_spip('inc/csv'); |
|
| 680 | + [$entete, $csv] = analyse_csv($data); |
|
| 681 | + array_unshift($csv, $entete); |
|
| 682 | + |
|
| 683 | + include_spip('inc/charsets'); |
|
| 684 | + $i = 1; |
|
| 685 | + foreach ($entete as $k => $v) { |
|
| 686 | + if (trim($v) == '') { |
|
| 687 | + $v = 'col' . $i; |
|
| 688 | + } // reperer des eventuelles cases vides |
|
| 689 | + if (is_numeric($v) and $v < 0) { |
|
| 690 | + $v = '__' . $v; |
|
| 691 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 692 | + if (is_numeric($v)) { |
|
| 693 | + $v = '_' . $v; |
|
| 694 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 695 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 696 | + foreach ($csv as &$item) { |
|
| 697 | + $item[$v] = &$item[$k]; |
|
| 698 | + } |
|
| 699 | + $i++; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return $csv; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -709,13 +709,13 @@ discard block |
||
| 709 | 709 | * @return array|bool |
| 710 | 710 | */ |
| 711 | 711 | function inc_rss_to_array_dist($data) { |
| 712 | - $tableau = null; |
|
| 713 | - include_spip('inc/syndic'); |
|
| 714 | - if (is_array($rss = analyser_backend($data))) { |
|
| 715 | - $tableau = $rss; |
|
| 716 | - } |
|
| 712 | + $tableau = null; |
|
| 713 | + include_spip('inc/syndic'); |
|
| 714 | + if (is_array($rss = analyser_backend($data))) { |
|
| 715 | + $tableau = $rss; |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - return $tableau; |
|
| 718 | + return $tableau; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | * @return array|bool |
| 726 | 726 | */ |
| 727 | 727 | function inc_atom_to_array_dist($data) { |
| 728 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 728 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 729 | 729 | |
| 730 | - return $rss_to_array($data); |
|
| 730 | + return $rss_to_array($data); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -738,12 +738,12 @@ discard block |
||
| 738 | 738 | * @return array|bool |
| 739 | 739 | */ |
| 740 | 740 | function inc_glob_to_array_dist($data) { |
| 741 | - $a = glob( |
|
| 742 | - $data, |
|
| 743 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 744 | - ); |
|
| 741 | + $a = glob( |
|
| 742 | + $data, |
|
| 743 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 744 | + ); |
|
| 745 | 745 | |
| 746 | - return $a ?: []; |
|
| 746 | + return $a ?: []; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -754,14 +754,14 @@ discard block |
||
| 754 | 754 | * @throws Exception |
| 755 | 755 | */ |
| 756 | 756 | function inc_yaml_to_array_dist($data) { |
| 757 | - include_spip('inc/yaml-mini'); |
|
| 758 | - if (!function_exists('yaml_decode')) { |
|
| 759 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 757 | + include_spip('inc/yaml-mini'); |
|
| 758 | + if (!function_exists('yaml_decode')) { |
|
| 759 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 760 | 760 | |
| 761 | - return false; |
|
| 762 | - } |
|
| 761 | + return false; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | - return yaml_decode($data); |
|
| 764 | + return yaml_decode($data); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * @return array|bool |
| 777 | 777 | */ |
| 778 | 778 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 779 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 779 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -788,23 +788,23 @@ discard block |
||
| 788 | 788 | * @return array|bool |
| 789 | 789 | */ |
| 790 | 790 | function inc_ls_to_array_dist($data) { |
| 791 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 792 | - $a = $glob_to_array($data); |
|
| 793 | - foreach ($a as &$v) { |
|
| 794 | - $b = (array)@stat($v); |
|
| 795 | - foreach ($b as $k => $ignore) { |
|
| 796 | - if (is_numeric($k)) { |
|
| 797 | - unset($b[$k]); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 801 | - $v = array_merge( |
|
| 802 | - pathinfo($v), |
|
| 803 | - $b |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - return $a; |
|
| 791 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 792 | + $a = $glob_to_array($data); |
|
| 793 | + foreach ($a as &$v) { |
|
| 794 | + $b = (array)@stat($v); |
|
| 795 | + foreach ($b as $k => $ignore) { |
|
| 796 | + if (is_numeric($k)) { |
|
| 797 | + unset($b[$k]); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 801 | + $v = array_merge( |
|
| 802 | + pathinfo($v), |
|
| 803 | + $b |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + return $a; |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | /** |
@@ -814,25 +814,25 @@ discard block |
||
| 814 | 814 | * @return array|bool |
| 815 | 815 | */ |
| 816 | 816 | function XMLObjectToArray($object) { |
| 817 | - $xml_array = []; |
|
| 818 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 819 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 820 | - $key .= '-' . uniqid(); |
|
| 821 | - } |
|
| 822 | - $vars = get_object_vars($object->current()); |
|
| 823 | - if (isset($vars['@attributes'])) { |
|
| 824 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 825 | - $xml_array[$key][$k] = $v; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - if ($object->hasChildren()) { |
|
| 829 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 830 | - $object->current() |
|
| 831 | - ); |
|
| 832 | - } else { |
|
| 833 | - $xml_array[$key][] = strval($object->current()); |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - return $xml_array; |
|
| 817 | + $xml_array = []; |
|
| 818 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 819 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 820 | + $key .= '-' . uniqid(); |
|
| 821 | + } |
|
| 822 | + $vars = get_object_vars($object->current()); |
|
| 823 | + if (isset($vars['@attributes'])) { |
|
| 824 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 825 | + $xml_array[$key][$k] = $v; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + if ($object->hasChildren()) { |
|
| 829 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 830 | + $object->current() |
|
| 831 | + ); |
|
| 832 | + } else { |
|
| 833 | + $xml_array[$key][] = strval($object->current()); |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + return $xml_array; |
|
| 838 | 838 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -27,215 +27,215 @@ discard block |
||
| 27 | 27 | * Permet d'itérer sur des données en base de données |
| 28 | 28 | */ |
| 29 | 29 | class IterateurSQL implements Iterator { |
| 30 | - /** |
|
| 31 | - * Ressource sql |
|
| 32 | - * |
|
| 33 | - * @var Object|bool |
|
| 34 | - */ |
|
| 35 | - protected $sqlresult = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * row sql courante |
|
| 39 | - * |
|
| 40 | - * @var array|null |
|
| 41 | - */ |
|
| 42 | - protected $row = null; |
|
| 43 | - |
|
| 44 | - protected bool $firstseek = false; |
|
| 45 | - |
|
| 46 | - protected int $pos = -1; |
|
| 47 | - |
|
| 48 | - protected string $type = 'SQL'; |
|
| 49 | - |
|
| 50 | - protected array $command = []; |
|
| 51 | - |
|
| 52 | - protected array $info = []; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** Erreur presente ? **/ |
|
| 56 | - public bool $err = false; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Calcul du total des elements |
|
| 60 | - * |
|
| 61 | - * @var int|null |
|
| 62 | - **/ |
|
| 63 | - public $total = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * selectionner les donnees, ie faire la requete SQL |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - protected function select() { |
|
| 71 | - $this->row = null; |
|
| 72 | - $v = &$this->command; |
|
| 73 | - $this->sqlresult = calculer_select( |
|
| 74 | - $v['select'], |
|
| 75 | - $v['from'], |
|
| 76 | - $v['type'], |
|
| 77 | - $v['where'], |
|
| 78 | - $v['join'], |
|
| 79 | - $v['groupby'], |
|
| 80 | - $v['orderby'], |
|
| 81 | - $v['limit'], |
|
| 82 | - $v['having'], |
|
| 83 | - $v['table'], |
|
| 84 | - $v['id'], |
|
| 85 | - $v['connect'], |
|
| 86 | - $this->info |
|
| 87 | - ); |
|
| 88 | - $this->err = !$this->sqlresult; |
|
| 89 | - $this->firstseek = false; |
|
| 90 | - $this->pos = -1; |
|
| 91 | - |
|
| 92 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 93 | - //$this->total = $this->count(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /* |
|
| 30 | + /** |
|
| 31 | + * Ressource sql |
|
| 32 | + * |
|
| 33 | + * @var Object|bool |
|
| 34 | + */ |
|
| 35 | + protected $sqlresult = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * row sql courante |
|
| 39 | + * |
|
| 40 | + * @var array|null |
|
| 41 | + */ |
|
| 42 | + protected $row = null; |
|
| 43 | + |
|
| 44 | + protected bool $firstseek = false; |
|
| 45 | + |
|
| 46 | + protected int $pos = -1; |
|
| 47 | + |
|
| 48 | + protected string $type = 'SQL'; |
|
| 49 | + |
|
| 50 | + protected array $command = []; |
|
| 51 | + |
|
| 52 | + protected array $info = []; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** Erreur presente ? **/ |
|
| 56 | + public bool $err = false; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Calcul du total des elements |
|
| 60 | + * |
|
| 61 | + * @var int|null |
|
| 62 | + **/ |
|
| 63 | + public $total = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * selectionner les donnees, ie faire la requete SQL |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + protected function select() { |
|
| 71 | + $this->row = null; |
|
| 72 | + $v = &$this->command; |
|
| 73 | + $this->sqlresult = calculer_select( |
|
| 74 | + $v['select'], |
|
| 75 | + $v['from'], |
|
| 76 | + $v['type'], |
|
| 77 | + $v['where'], |
|
| 78 | + $v['join'], |
|
| 79 | + $v['groupby'], |
|
| 80 | + $v['orderby'], |
|
| 81 | + $v['limit'], |
|
| 82 | + $v['having'], |
|
| 83 | + $v['table'], |
|
| 84 | + $v['id'], |
|
| 85 | + $v['connect'], |
|
| 86 | + $this->info |
|
| 87 | + ); |
|
| 88 | + $this->err = !$this->sqlresult; |
|
| 89 | + $this->firstseek = false; |
|
| 90 | + $this->pos = -1; |
|
| 91 | + |
|
| 92 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 93 | + //$this->total = $this->count(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /* |
|
| 97 | 97 | * array command: les commandes d'initialisation |
| 98 | 98 | * array info: les infos sur le squelette |
| 99 | 99 | */ |
| 100 | - public function __construct($command, $info = []) { |
|
| 101 | - $this->type = 'SQL'; |
|
| 102 | - $this->command = $command; |
|
| 103 | - $this->info = $info; |
|
| 104 | - $this->select(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Rembobiner |
|
| 109 | - * |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function rewind(): void { |
|
| 113 | - if ($this->pos > 0) { |
|
| 114 | - $this->seek(0); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Verifier l'etat de l'iterateur |
|
| 120 | - * |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function valid(): bool { |
|
| 124 | - if ($this->err) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - if (!$this->firstseek) { |
|
| 128 | - $this->next(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return is_array($this->row); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Valeurs sur la position courante |
|
| 136 | - * |
|
| 137 | - * @return array |
|
| 138 | - */ |
|
| 139 | - #[\ReturnTypeWillChange] |
|
| 140 | - public function current() { |
|
| 141 | - return $this->row; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - #[\ReturnTypeWillChange] |
|
| 145 | - public function key() { |
|
| 146 | - return $this->pos; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Sauter a une position absolue |
|
| 151 | - * |
|
| 152 | - * @param int $n |
|
| 153 | - * @param null|string $continue |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - public function seek($n = 0, $continue = null) { |
|
| 157 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 158 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 159 | - // si la position courante est apres la position visee |
|
| 160 | - // il faut relancer la requete |
|
| 161 | - if ($this->pos > $n) { |
|
| 162 | - $this->free(); |
|
| 163 | - $this->select(); |
|
| 164 | - $this->valid(); |
|
| 165 | - } |
|
| 166 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 167 | - // (sera fait en cas d'echec de cette fonction) |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 171 | - $this->pos = min($n, $this->count()); |
|
| 172 | - |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Avancer d'un cran |
|
| 178 | - * |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - public function next(): void { |
|
| 182 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 183 | - $this->pos++; |
|
| 184 | - $this->firstseek |= true; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Avancer et retourner les donnees pour le nouvel element |
|
| 189 | - * |
|
| 190 | - * @return array|bool|null |
|
| 191 | - */ |
|
| 192 | - public function fetch() { |
|
| 193 | - if ($this->valid()) { |
|
| 194 | - $r = $this->current(); |
|
| 195 | - $this->next(); |
|
| 196 | - } else { |
|
| 197 | - $r = false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $r; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * liberer les ressources |
|
| 205 | - * |
|
| 206 | - * @return bool |
|
| 207 | - */ |
|
| 208 | - public function free() { |
|
| 209 | - if (!$this->sqlresult) { |
|
| 210 | - return true; |
|
| 211 | - } |
|
| 212 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 213 | - $this->sqlresult = null; |
|
| 214 | - |
|
| 215 | - return $a; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Compter le nombre de resultats |
|
| 220 | - * |
|
| 221 | - * @return int |
|
| 222 | - */ |
|
| 223 | - public function count() { |
|
| 224 | - if (is_null($this->total)) { |
|
| 225 | - if (!$this->sqlresult) { |
|
| 226 | - $this->total = 0; |
|
| 227 | - } else { |
|
| 228 | - # cas count(*) |
|
| 229 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 230 | - $this->valid(); |
|
| 231 | - $s = $this->current(); |
|
| 232 | - $this->total = $s['count(*)']; |
|
| 233 | - } else { |
|
| 234 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $this->total; |
|
| 240 | - } |
|
| 100 | + public function __construct($command, $info = []) { |
|
| 101 | + $this->type = 'SQL'; |
|
| 102 | + $this->command = $command; |
|
| 103 | + $this->info = $info; |
|
| 104 | + $this->select(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Rembobiner |
|
| 109 | + * |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function rewind(): void { |
|
| 113 | + if ($this->pos > 0) { |
|
| 114 | + $this->seek(0); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Verifier l'etat de l'iterateur |
|
| 120 | + * |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function valid(): bool { |
|
| 124 | + if ($this->err) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + if (!$this->firstseek) { |
|
| 128 | + $this->next(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return is_array($this->row); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Valeurs sur la position courante |
|
| 136 | + * |
|
| 137 | + * @return array |
|
| 138 | + */ |
|
| 139 | + #[\ReturnTypeWillChange] |
|
| 140 | + public function current() { |
|
| 141 | + return $this->row; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + #[\ReturnTypeWillChange] |
|
| 145 | + public function key() { |
|
| 146 | + return $this->pos; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Sauter a une position absolue |
|
| 151 | + * |
|
| 152 | + * @param int $n |
|
| 153 | + * @param null|string $continue |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + public function seek($n = 0, $continue = null) { |
|
| 157 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 158 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 159 | + // si la position courante est apres la position visee |
|
| 160 | + // il faut relancer la requete |
|
| 161 | + if ($this->pos > $n) { |
|
| 162 | + $this->free(); |
|
| 163 | + $this->select(); |
|
| 164 | + $this->valid(); |
|
| 165 | + } |
|
| 166 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 167 | + // (sera fait en cas d'echec de cette fonction) |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 171 | + $this->pos = min($n, $this->count()); |
|
| 172 | + |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Avancer d'un cran |
|
| 178 | + * |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + public function next(): void { |
|
| 182 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 183 | + $this->pos++; |
|
| 184 | + $this->firstseek |= true; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Avancer et retourner les donnees pour le nouvel element |
|
| 189 | + * |
|
| 190 | + * @return array|bool|null |
|
| 191 | + */ |
|
| 192 | + public function fetch() { |
|
| 193 | + if ($this->valid()) { |
|
| 194 | + $r = $this->current(); |
|
| 195 | + $this->next(); |
|
| 196 | + } else { |
|
| 197 | + $r = false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $r; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * liberer les ressources |
|
| 205 | + * |
|
| 206 | + * @return bool |
|
| 207 | + */ |
|
| 208 | + public function free() { |
|
| 209 | + if (!$this->sqlresult) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 212 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 213 | + $this->sqlresult = null; |
|
| 214 | + |
|
| 215 | + return $a; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Compter le nombre de resultats |
|
| 220 | + * |
|
| 221 | + * @return int |
|
| 222 | + */ |
|
| 223 | + public function count() { |
|
| 224 | + if (is_null($this->total)) { |
|
| 225 | + if (!$this->sqlresult) { |
|
| 226 | + $this->total = 0; |
|
| 227 | + } else { |
|
| 228 | + # cas count(*) |
|
| 229 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 230 | + $this->valid(); |
|
| 231 | + $s = $this->current(); |
|
| 232 | + $this->total = $s['count(*)']; |
|
| 233 | + } else { |
|
| 234 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $this->total; |
|
| 240 | + } |
|
| 241 | 241 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | **/ |
| 27 | 27 | |
| 28 | 28 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 29 | - return; |
|
| 29 | + return; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | * Code PHP si cet argument est présent, sinon null |
| 49 | 49 | **/ |
| 50 | 50 | function interprete_argument_balise(int $n, Champ $p): ?string { |
| 51 | - if (($p->param) && (!$p->param[0][0]) && ((is_countable($p->param[0]) ? count($p->param[0]) : 0) > $n)) { |
|
| 52 | - return calculer_liste( |
|
| 53 | - $p->param[0][$n], |
|
| 54 | - $p->descr, |
|
| 55 | - $p->boucles, |
|
| 56 | - $p->id_boucle |
|
| 57 | - ); |
|
| 58 | - } else { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 51 | + if (($p->param) && (!$p->param[0][0]) && ((is_countable($p->param[0]) ? count($p->param[0]) : 0) > $n)) { |
|
| 52 | + return calculer_liste( |
|
| 53 | + $p->param[0][$n], |
|
| 54 | + $p->descr, |
|
| 55 | + $p->boucles, |
|
| 56 | + $p->id_boucle |
|
| 57 | + ); |
|
| 58 | + } else { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | * Pile complétée par le code à générer |
| 78 | 78 | **/ |
| 79 | 79 | function balise_NOM_SITE_SPIP_dist($p) { |
| 80 | - $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 80 | + $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 81 | 81 | |
| 82 | - #$p->interdire_scripts = true; |
|
| 83 | - return $p; |
|
| 82 | + #$p->interdire_scripts = true; |
|
| 83 | + return $p; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | * Pile complétée par le code à générer |
| 97 | 97 | **/ |
| 98 | 98 | function balise_EMAIL_WEBMASTER_dist($p) { |
| 99 | - $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 99 | + $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 100 | 100 | |
| 101 | - #$p->interdire_scripts = true; |
|
| 102 | - return $p; |
|
| 101 | + #$p->interdire_scripts = true; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * Pile complétée par le code à générer |
| 116 | 116 | **/ |
| 117 | 117 | function balise_DESCRIPTIF_SITE_SPIP_dist($p) { |
| 118 | - $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 118 | + $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 119 | 119 | |
| 120 | - #$p->interdire_scripts = true; |
|
| 121 | - return $p; |
|
| 120 | + #$p->interdire_scripts = true; |
|
| 121 | + return $p; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * Pile complétée par le code à générer |
| 140 | 140 | **/ |
| 141 | 141 | function balise_CHARSET_dist($p) { |
| 142 | - $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 142 | + $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 143 | 143 | |
| 144 | - #$p->interdire_scripts = true; |
|
| 145 | - return $p; |
|
| 144 | + #$p->interdire_scripts = true; |
|
| 145 | + return $p; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * Pile complétée par le code à générer |
| 168 | 168 | **/ |
| 169 | 169 | function balise_LANG_LEFT_dist($p) { |
| 170 | - $_lang = champ_sql('lang', $p); |
|
| 171 | - $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | - $p->interdire_scripts = false; |
|
| 170 | + $_lang = champ_sql('lang', $p); |
|
| 171 | + $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | + $p->interdire_scripts = false; |
|
| 173 | 173 | |
| 174 | - return $p; |
|
| 174 | + return $p; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | * Pile complétée par le code à générer |
| 192 | 192 | **/ |
| 193 | 193 | function balise_LANG_RIGHT_dist($p) { |
| 194 | - $_lang = champ_sql('lang', $p); |
|
| 195 | - $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | - $p->interdire_scripts = false; |
|
| 194 | + $_lang = champ_sql('lang', $p); |
|
| 195 | + $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | + $p->interdire_scripts = false; |
|
| 197 | 197 | |
| 198 | - return $p; |
|
| 198 | + return $p; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | * Pile complétée par le code à générer |
| 221 | 221 | **/ |
| 222 | 222 | function balise_LANG_DIR_dist($p) { |
| 223 | - $_lang = champ_sql('lang', $p); |
|
| 224 | - $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | - $p->interdire_scripts = false; |
|
| 223 | + $_lang = champ_sql('lang', $p); |
|
| 224 | + $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | + $p->interdire_scripts = false; |
|
| 226 | 226 | |
| 227 | - return $p; |
|
| 227 | + return $p; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * Pile complétée par le code à générer |
| 242 | 242 | **/ |
| 243 | 243 | function balise_PUCE_dist($p) { |
| 244 | - $p->code = 'definir_puce()'; |
|
| 245 | - $p->interdire_scripts = false; |
|
| 244 | + $p->code = 'definir_puce()'; |
|
| 245 | + $p->interdire_scripts = false; |
|
| 246 | 246 | |
| 247 | - return $p; |
|
| 247 | + return $p; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * Pile completée du code PHP d'exécution de la balise |
| 269 | 269 | */ |
| 270 | 270 | function balise_DATE_dist($p) { |
| 271 | - $p->code = champ_sql('date', $p); |
|
| 271 | + $p->code = champ_sql('date', $p); |
|
| 272 | 272 | |
| 273 | - return $p; |
|
| 273 | + return $p; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | * Pile completée du code PHP d'exécution de la balise |
| 291 | 291 | */ |
| 292 | 292 | function balise_DATE_REDAC_dist($p) { |
| 293 | - $p->code = champ_sql('date_redac', $p); |
|
| 294 | - $p->interdire_scripts = false; |
|
| 293 | + $p->code = champ_sql('date_redac', $p); |
|
| 294 | + $p->interdire_scripts = false; |
|
| 295 | 295 | |
| 296 | - return $p; |
|
| 296 | + return $p; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | * Pile completée du code PHP d'exécution de la balise |
| 313 | 313 | */ |
| 314 | 314 | function balise_DATE_MODIF_dist($p) { |
| 315 | - $p->code = champ_sql('date_modif', $p); |
|
| 316 | - $p->interdire_scripts = false; |
|
| 315 | + $p->code = champ_sql('date_modif', $p); |
|
| 316 | + $p->interdire_scripts = false; |
|
| 317 | 317 | |
| 318 | - return $p; |
|
| 318 | + return $p; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | * Pile completée du code PHP d'exécution de la balise |
| 334 | 334 | */ |
| 335 | 335 | function balise_DATE_NOUVEAUTES_dist($p) { |
| 336 | - $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 336 | + $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 337 | 337 | AND isset(\$GLOBALS['meta']['dernier_envoi_neuf'])) ? |
| 338 | 338 | \$GLOBALS['meta']['dernier_envoi_neuf'] : |
| 339 | 339 | \"'0000-00-00'\")"; |
| 340 | - $p->interdire_scripts = false; |
|
| 340 | + $p->interdire_scripts = false; |
|
| 341 | 341 | |
| 342 | - return $p; |
|
| 342 | + return $p; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | * Pile completée du code PHP d'exécution de la balise |
| 358 | 358 | */ |
| 359 | 359 | function balise_DOSSIER_SQUELETTE_dist($p) { |
| 360 | - $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | - $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | - $p->interdire_scripts = false; |
|
| 360 | + $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | + $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | + $p->interdire_scripts = false; |
|
| 363 | 363 | |
| 364 | - return $p; |
|
| 364 | + return $p; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * Pile completée du code PHP d'exécution de la balise |
| 377 | 377 | */ |
| 378 | 378 | function balise_SQUELETTE_dist($p) { |
| 379 | - $code = addslashes($p->descr['sourcefile']); |
|
| 380 | - $p->code = "'$code'" . |
|
| 381 | - $p->interdire_scripts = false; |
|
| 379 | + $code = addslashes($p->descr['sourcefile']); |
|
| 380 | + $p->code = "'$code'" . |
|
| 381 | + $p->interdire_scripts = false; |
|
| 382 | 382 | |
| 383 | - return $p; |
|
| 383 | + return $p; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -399,10 +399,10 @@ discard block |
||
| 399 | 399 | * Pile completée du code PHP d'exécution de la balise |
| 400 | 400 | */ |
| 401 | 401 | function balise_SPIP_VERSION_dist($p) { |
| 402 | - $p->code = 'spip_version()'; |
|
| 403 | - $p->interdire_scripts = false; |
|
| 402 | + $p->code = 'spip_version()'; |
|
| 403 | + $p->interdire_scripts = false; |
|
| 404 | 404 | |
| 405 | - return $p; |
|
| 405 | + return $p; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -428,18 +428,18 @@ discard block |
||
| 428 | 428 | * Pile complétée par le code à générer |
| 429 | 429 | **/ |
| 430 | 430 | function balise_NOM_SITE_dist($p) { |
| 431 | - if (!$p->etoile) { |
|
| 432 | - $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | - champ_sql('url_site', $p) . ',' . |
|
| 434 | - champ_sql('nom_site', $p) . |
|
| 435 | - ", 'titre', \$connect, false))"; |
|
| 436 | - } else { |
|
| 437 | - $p->code = champ_sql('nom_site', $p); |
|
| 438 | - } |
|
| 431 | + if (!$p->etoile) { |
|
| 432 | + $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | + champ_sql('url_site', $p) . ',' . |
|
| 434 | + champ_sql('nom_site', $p) . |
|
| 435 | + ", 'titre', \$connect, false))"; |
|
| 436 | + } else { |
|
| 437 | + $p->code = champ_sql('nom_site', $p); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $p->interdire_scripts = true; |
|
| 440 | + $p->interdire_scripts = true; |
|
| 441 | 441 | |
| 442 | - return $p; |
|
| 442 | + return $p; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | * Pile complétée par le code à générer |
| 457 | 457 | **/ |
| 458 | 458 | function balise_NOTES_dist($p) { |
| 459 | - // Recuperer les notes |
|
| 460 | - $p->code = 'calculer_notes()'; |
|
| 459 | + // Recuperer les notes |
|
| 460 | + $p->code = 'calculer_notes()'; |
|
| 461 | 461 | |
| 462 | - #$p->interdire_scripts = true; |
|
| 463 | - return $p; |
|
| 462 | + #$p->interdire_scripts = true; |
|
| 463 | + return $p; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | * Pile complétée par le code à générer |
| 483 | 483 | **/ |
| 484 | 484 | function balise_RECHERCHE_dist($p) { |
| 485 | - $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | - $p->interdire_scripts = false; |
|
| 485 | + $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | + $p->interdire_scripts = false; |
|
| 487 | 487 | |
| 488 | - return $p; |
|
| 488 | + return $p; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -503,17 +503,17 @@ discard block |
||
| 503 | 503 | * Pile complétée par le code à générer |
| 504 | 504 | **/ |
| 505 | 505 | function balise_COMPTEUR_BOUCLE_dist($p) { |
| 506 | - $b = index_boucle_mere($p); |
|
| 507 | - if ($b === '') { |
|
| 508 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | - erreur_squelette($msg, $p); |
|
| 510 | - } else { |
|
| 511 | - $p->code = "(\$Numrows['$b']['compteur_boucle'] ?? 0)"; |
|
| 512 | - $p->boucles[$b]->cptrows = true; |
|
| 513 | - $p->interdire_scripts = false; |
|
| 506 | + $b = index_boucle_mere($p); |
|
| 507 | + if ($b === '') { |
|
| 508 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | + erreur_squelette($msg, $p); |
|
| 510 | + } else { |
|
| 511 | + $p->code = "(\$Numrows['$b']['compteur_boucle'] ?? 0)"; |
|
| 512 | + $p->boucles[$b]->cptrows = true; |
|
| 513 | + $p->interdire_scripts = false; |
|
| 514 | 514 | |
| 515 | - return $p; |
|
| 516 | - } |
|
| 515 | + return $p; |
|
| 516 | + } |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -531,17 +531,17 @@ discard block |
||
| 531 | 531 | * Pile complétée par le code à générer |
| 532 | 532 | **/ |
| 533 | 533 | function balise_TOTAL_BOUCLE_dist($p) { |
| 534 | - $b = index_boucle_mere($p); |
|
| 535 | - if ($b === '') { |
|
| 536 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | - erreur_squelette($msg, $p); |
|
| 538 | - } else { |
|
| 539 | - $p->code = "(\$Numrows['$b']['total'] ?? 0)"; |
|
| 540 | - $p->boucles[$b]->numrows = true; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 534 | + $b = index_boucle_mere($p); |
|
| 535 | + if ($b === '') { |
|
| 536 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | + erreur_squelette($msg, $p); |
|
| 538 | + } else { |
|
| 539 | + $p->code = "(\$Numrows['$b']['total'] ?? 0)"; |
|
| 540 | + $p->boucles[$b]->numrows = true; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - return $p; |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | * Pile complétée par le code à générer |
| 562 | 562 | **/ |
| 563 | 563 | function balise_POINTS_dist($p) { |
| 564 | - return rindex_pile($p, 'points', 'recherche'); |
|
| 564 | + return rindex_pile($p, 'points', 'recherche'); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -582,12 +582,12 @@ discard block |
||
| 582 | 582 | * Pile complétée par le code à générer |
| 583 | 583 | **/ |
| 584 | 584 | function balise_POPULARITE_ABSOLUE_dist($p) { |
| 585 | - $p->code = 'ceil(' . |
|
| 586 | - champ_sql('popularite', $p) . |
|
| 587 | - ')'; |
|
| 588 | - $p->interdire_scripts = false; |
|
| 585 | + $p->code = 'ceil(' . |
|
| 586 | + champ_sql('popularite', $p) . |
|
| 587 | + ')'; |
|
| 588 | + $p->interdire_scripts = false; |
|
| 589 | 589 | |
| 590 | - return $p; |
|
| 590 | + return $p; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | * Pile complétée par le code à générer |
| 608 | 608 | **/ |
| 609 | 609 | function balise_POPULARITE_SITE_dist($p) { |
| 610 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | - $p->interdire_scripts = false; |
|
| 610 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | + $p->interdire_scripts = false; |
|
| 612 | 612 | |
| 613 | - return $p; |
|
| 613 | + return $p; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -631,10 +631,10 @@ discard block |
||
| 631 | 631 | * Pile complétée par le code à générer |
| 632 | 632 | **/ |
| 633 | 633 | function balise_POPULARITE_MAX_dist($p) { |
| 634 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | - $p->interdire_scripts = false; |
|
| 634 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | + $p->interdire_scripts = false; |
|
| 636 | 636 | |
| 637 | - return $p; |
|
| 637 | + return $p; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | |
@@ -660,15 +660,15 @@ discard block |
||
| 660 | 660 | * Pile complétée par le code à générer |
| 661 | 661 | **/ |
| 662 | 662 | function balise_VALEUR_dist($p) { |
| 663 | - $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 664 | - $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 663 | + $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 664 | + $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 665 | 665 | ; |
| 666 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | - $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | - } |
|
| 669 | - $p->interdire_scripts = true; |
|
| 666 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | + $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | + } |
|
| 669 | + $p->interdire_scripts = true; |
|
| 670 | 670 | |
| 671 | - return $p; |
|
| 671 | + return $p; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -697,16 +697,16 @@ discard block |
||
| 697 | 697 | * Pile complétée par le code à générer |
| 698 | 698 | **/ |
| 699 | 699 | function balise_EXPOSE_dist($p) { |
| 700 | - $on = "'on'"; |
|
| 701 | - $off = "''"; |
|
| 702 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | - $on = $v; |
|
| 704 | - if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | - $off = $v; |
|
| 706 | - } |
|
| 707 | - } |
|
| 700 | + $on = "'on'"; |
|
| 701 | + $off = "''"; |
|
| 702 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | + $on = $v; |
|
| 704 | + if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | + $off = $v; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return calculer_balise_expose($p, $on, $off); |
|
| 709 | + return calculer_balise_expose($p, $on, $off); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -724,35 +724,35 @@ discard block |
||
| 724 | 724 | * Pile complétée par le code à générer |
| 725 | 725 | **/ |
| 726 | 726 | function calculer_balise_expose($p, $on, $off) { |
| 727 | - $b = index_boucle($p); |
|
| 728 | - if (empty($p->boucles[$b]->primary)) { |
|
| 729 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | - erreur_squelette($msg, $p); |
|
| 731 | - } else { |
|
| 732 | - $key = $p->boucles[$b]->primary; |
|
| 733 | - $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | - $desc = $p->boucles[$b]->show; |
|
| 735 | - $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 727 | + $b = index_boucle($p); |
|
| 728 | + if (empty($p->boucles[$b]->primary)) { |
|
| 729 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | + erreur_squelette($msg, $p); |
|
| 731 | + } else { |
|
| 732 | + $key = $p->boucles[$b]->primary; |
|
| 733 | + $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | + $desc = $p->boucles[$b]->show; |
|
| 735 | + $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 736 | 736 | |
| 737 | - // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | - $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 737 | + // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | + $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 739 | 739 | |
| 740 | - if (isset($desc['field']['id_parent'])) { |
|
| 741 | - $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | - } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | - $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | - } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | - $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | - } else { |
|
| 747 | - $parent = "''"; |
|
| 748 | - } |
|
| 740 | + if (isset($desc['field']['id_parent'])) { |
|
| 741 | + $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | + } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | + $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | + } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | + $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | + } else { |
|
| 747 | + $parent = "''"; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | - } |
|
| 750 | + $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - $p->interdire_scripts = false; |
|
| 753 | + $p->interdire_scripts = false; |
|
| 754 | 754 | |
| 755 | - return $p; |
|
| 755 | + return $p; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -793,46 +793,46 @@ discard block |
||
| 793 | 793 | **/ |
| 794 | 794 | function balise_INTRODUCTION_dist($p) { |
| 795 | 795 | |
| 796 | - $type_objet = $p->type_requete; |
|
| 797 | - $cle_objet = id_table_objet($type_objet); |
|
| 798 | - $_id_objet = champ_sql($cle_objet, $p); |
|
| 799 | - |
|
| 800 | - // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 801 | - // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 802 | - $_introduction_longueur = 'null'; |
|
| 803 | - $_ligne = 'array('; |
|
| 804 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 805 | - if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 806 | - if (isset($desc['field']['descriptif'])) { |
|
| 807 | - $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 808 | - } |
|
| 809 | - if (isset($desc['field']['texte'])) { |
|
| 810 | - $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 811 | - } |
|
| 812 | - if (isset($desc['field']['chapo'])) { |
|
| 813 | - $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 814 | - } |
|
| 815 | - if (isset($desc['introduction_longueur'])) { |
|
| 816 | - $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 817 | - } |
|
| 818 | - } |
|
| 819 | - $_ligne .= ')'; |
|
| 820 | - |
|
| 821 | - // Récupérer la longueur et la suite passés en paramètres |
|
| 822 | - $_longueur_ou_suite = 'null'; |
|
| 823 | - if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 824 | - $_longueur_ou_suite = $v1; |
|
| 825 | - } |
|
| 826 | - $_suite = 'null'; |
|
| 827 | - if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 828 | - $_suite = $v2; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - $p->code = "generer_objet_introduction($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 832 | - |
|
| 833 | - #$p->interdire_scripts = true; |
|
| 834 | - $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 835 | - return $p; |
|
| 796 | + $type_objet = $p->type_requete; |
|
| 797 | + $cle_objet = id_table_objet($type_objet); |
|
| 798 | + $_id_objet = champ_sql($cle_objet, $p); |
|
| 799 | + |
|
| 800 | + // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 801 | + // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 802 | + $_introduction_longueur = 'null'; |
|
| 803 | + $_ligne = 'array('; |
|
| 804 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 805 | + if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 806 | + if (isset($desc['field']['descriptif'])) { |
|
| 807 | + $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 808 | + } |
|
| 809 | + if (isset($desc['field']['texte'])) { |
|
| 810 | + $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 811 | + } |
|
| 812 | + if (isset($desc['field']['chapo'])) { |
|
| 813 | + $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 814 | + } |
|
| 815 | + if (isset($desc['introduction_longueur'])) { |
|
| 816 | + $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 817 | + } |
|
| 818 | + } |
|
| 819 | + $_ligne .= ')'; |
|
| 820 | + |
|
| 821 | + // Récupérer la longueur et la suite passés en paramètres |
|
| 822 | + $_longueur_ou_suite = 'null'; |
|
| 823 | + if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 824 | + $_longueur_ou_suite = $v1; |
|
| 825 | + } |
|
| 826 | + $_suite = 'null'; |
|
| 827 | + if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 828 | + $_suite = $v2; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + $p->code = "generer_objet_introduction($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 832 | + |
|
| 833 | + #$p->interdire_scripts = true; |
|
| 834 | + $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 835 | + return $p; |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | |
@@ -852,15 +852,15 @@ discard block |
||
| 852 | 852 | * Pile complétée par le code à générer |
| 853 | 853 | **/ |
| 854 | 854 | function balise_LANG_dist($p) { |
| 855 | - $_lang = champ_sql('lang', $p); |
|
| 856 | - if (!$p->etoile) { |
|
| 857 | - $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 858 | - } else { |
|
| 859 | - $p->code = "spip_htmlentities($_lang)"; |
|
| 860 | - } |
|
| 861 | - $p->interdire_scripts = false; |
|
| 855 | + $_lang = champ_sql('lang', $p); |
|
| 856 | + if (!$p->etoile) { |
|
| 857 | + $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 858 | + } else { |
|
| 859 | + $p->code = "spip_htmlentities($_lang)"; |
|
| 860 | + } |
|
| 861 | + $p->interdire_scripts = false; |
|
| 862 | 862 | |
| 863 | - return $p; |
|
| 863 | + return $p; |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | /** |
@@ -882,45 +882,45 @@ discard block |
||
| 882 | 882 | * Pile complétée par le code à générer |
| 883 | 883 | */ |
| 884 | 884 | function balise_LESAUTEURS_dist($p) { |
| 885 | - // Cherche le champ 'lesauteurs' dans la pile |
|
| 886 | - $_lesauteurs = champ_sql('lesauteurs', $p, ''); |
|
| 887 | - |
|
| 888 | - // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 889 | - // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 890 | - // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 891 | - // (cf extension sites/) |
|
| 892 | - if ($_lesauteurs) { |
|
| 893 | - $p->code = "safehtml($_lesauteurs)"; |
|
| 894 | - // $p->interdire_scripts = true; |
|
| 895 | - } else { |
|
| 896 | - if (!$p->id_boucle) { |
|
| 897 | - $connect = ''; |
|
| 898 | - $objet = 'article'; |
|
| 899 | - $id_table_objet = 'id_article'; |
|
| 900 | - } else { |
|
| 901 | - $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 902 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 903 | - $type_boucle = $p->boucles[$b]->type_requete; |
|
| 904 | - $objet = objet_type($type_boucle); |
|
| 905 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 906 | - } |
|
| 907 | - $c = memoriser_contexte_compil($p); |
|
| 908 | - |
|
| 909 | - $p->code = sprintf( |
|
| 910 | - CODE_RECUPERER_FOND, |
|
| 911 | - "'modeles/lesauteurs'", |
|
| 912 | - "array('objet'=>'" . $objet . |
|
| 913 | - "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 914 | - ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 915 | - ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 916 | - ')', |
|
| 917 | - "'trim'=>true, 'compil'=>array($c)", |
|
| 918 | - _q($connect) |
|
| 919 | - ); |
|
| 920 | - $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - return $p; |
|
| 885 | + // Cherche le champ 'lesauteurs' dans la pile |
|
| 886 | + $_lesauteurs = champ_sql('lesauteurs', $p, ''); |
|
| 887 | + |
|
| 888 | + // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 889 | + // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 890 | + // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 891 | + // (cf extension sites/) |
|
| 892 | + if ($_lesauteurs) { |
|
| 893 | + $p->code = "safehtml($_lesauteurs)"; |
|
| 894 | + // $p->interdire_scripts = true; |
|
| 895 | + } else { |
|
| 896 | + if (!$p->id_boucle) { |
|
| 897 | + $connect = ''; |
|
| 898 | + $objet = 'article'; |
|
| 899 | + $id_table_objet = 'id_article'; |
|
| 900 | + } else { |
|
| 901 | + $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 902 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 903 | + $type_boucle = $p->boucles[$b]->type_requete; |
|
| 904 | + $objet = objet_type($type_boucle); |
|
| 905 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 906 | + } |
|
| 907 | + $c = memoriser_contexte_compil($p); |
|
| 908 | + |
|
| 909 | + $p->code = sprintf( |
|
| 910 | + CODE_RECUPERER_FOND, |
|
| 911 | + "'modeles/lesauteurs'", |
|
| 912 | + "array('objet'=>'" . $objet . |
|
| 913 | + "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 914 | + ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 915 | + ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 916 | + ')', |
|
| 917 | + "'trim'=>true, 'compil'=>array($c)", |
|
| 918 | + _q($connect) |
|
| 919 | + ); |
|
| 920 | + $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + return $p; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -947,76 +947,76 @@ discard block |
||
| 947 | 947 | * Pile complétée par le code à générer |
| 948 | 948 | */ |
| 949 | 949 | function balise_RANG_dist($p) { |
| 950 | - $b = index_boucle($p); |
|
| 951 | - if ($b === '') { |
|
| 952 | - $msg = [ |
|
| 953 | - 'zbug_champ_hors_boucle', |
|
| 954 | - ['champ' => '#RANG'] |
|
| 955 | - ]; |
|
| 956 | - erreur_squelette($msg, $p); |
|
| 957 | - } else { |
|
| 958 | - // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 959 | - // dans la boucle immediatement englobante uniquement |
|
| 960 | - // sinon on compose le champ calcule |
|
| 961 | - $_rang = champ_sql('rang', $p, '', false); |
|
| 962 | - |
|
| 963 | - // si pas trouve de champ sql rang : |
|
| 964 | - if (!$_rang or $_rang == "''") { |
|
| 965 | - $boucle = &$p->boucles[$b]; |
|
| 966 | - |
|
| 967 | - // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 968 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 969 | - $desc = $trouver_table($boucle->id_table); |
|
| 970 | - $_titre = ''; # où extraire le numero ? |
|
| 971 | - |
|
| 972 | - if (isset($desc['titre'])) { |
|
| 973 | - $t = $desc['titre']; |
|
| 974 | - if ( |
|
| 975 | - // Soit on trouve avec la déclaration de la lang AVANT |
|
| 976 | - preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 977 | - // Soit on prend depuis le début |
|
| 978 | - or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | - ) { |
|
| 980 | - $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 981 | - $m = trim($m); |
|
| 982 | - if ($m != "''") { |
|
| 983 | - if (!preg_match(',\W,', $m)) { |
|
| 984 | - $m = $boucle->id_table . ".$m"; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $m .= ' AS titre_rang'; |
|
| 988 | - |
|
| 989 | - $boucle->select[] = $m; |
|
| 990 | - $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 996 | - if (!$_titre) { |
|
| 997 | - $_titre = champ_sql('titre', $p); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1001 | - // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1002 | - $type_boucle = $boucle->type_requete; |
|
| 1003 | - $objet = objet_type($type_boucle); |
|
| 1004 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 1005 | - $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1006 | - $_env = '$Pile[0]'; |
|
| 1007 | - |
|
| 1008 | - if (!$_titre) {$_titre = "''"; |
|
| 1009 | - } |
|
| 1010 | - if (!$_primary) {$_primary = "''"; |
|
| 1011 | - } |
|
| 1012 | - $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - $p->code = $_rang; |
|
| 1016 | - $p->interdire_scripts = false; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - return $p; |
|
| 950 | + $b = index_boucle($p); |
|
| 951 | + if ($b === '') { |
|
| 952 | + $msg = [ |
|
| 953 | + 'zbug_champ_hors_boucle', |
|
| 954 | + ['champ' => '#RANG'] |
|
| 955 | + ]; |
|
| 956 | + erreur_squelette($msg, $p); |
|
| 957 | + } else { |
|
| 958 | + // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 959 | + // dans la boucle immediatement englobante uniquement |
|
| 960 | + // sinon on compose le champ calcule |
|
| 961 | + $_rang = champ_sql('rang', $p, '', false); |
|
| 962 | + |
|
| 963 | + // si pas trouve de champ sql rang : |
|
| 964 | + if (!$_rang or $_rang == "''") { |
|
| 965 | + $boucle = &$p->boucles[$b]; |
|
| 966 | + |
|
| 967 | + // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 968 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 969 | + $desc = $trouver_table($boucle->id_table); |
|
| 970 | + $_titre = ''; # où extraire le numero ? |
|
| 971 | + |
|
| 972 | + if (isset($desc['titre'])) { |
|
| 973 | + $t = $desc['titre']; |
|
| 974 | + if ( |
|
| 975 | + // Soit on trouve avec la déclaration de la lang AVANT |
|
| 976 | + preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 977 | + // Soit on prend depuis le début |
|
| 978 | + or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | + ) { |
|
| 980 | + $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 981 | + $m = trim($m); |
|
| 982 | + if ($m != "''") { |
|
| 983 | + if (!preg_match(',\W,', $m)) { |
|
| 984 | + $m = $boucle->id_table . ".$m"; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $m .= ' AS titre_rang'; |
|
| 988 | + |
|
| 989 | + $boucle->select[] = $m; |
|
| 990 | + $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 996 | + if (!$_titre) { |
|
| 997 | + $_titre = champ_sql('titre', $p); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1001 | + // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1002 | + $type_boucle = $boucle->type_requete; |
|
| 1003 | + $objet = objet_type($type_boucle); |
|
| 1004 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 1005 | + $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1006 | + $_env = '$Pile[0]'; |
|
| 1007 | + |
|
| 1008 | + if (!$_titre) {$_titre = "''"; |
|
| 1009 | + } |
|
| 1010 | + if (!$_primary) {$_primary = "''"; |
|
| 1011 | + } |
|
| 1012 | + $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + $p->code = $_rang; |
|
| 1016 | + $p->interdire_scripts = false; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + return $p; |
|
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | |
@@ -1038,12 +1038,12 @@ discard block |
||
| 1038 | 1038 | * Pile complétée par le code à générer |
| 1039 | 1039 | **/ |
| 1040 | 1040 | function balise_POPULARITE_dist($p) { |
| 1041 | - $_popularite = champ_sql('popularite', $p); |
|
| 1042 | - $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1041 | + $_popularite = champ_sql('popularite', $p); |
|
| 1042 | + $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1043 | 1043 | / max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))"; |
| 1044 | - $p->interdire_scripts = false; |
|
| 1044 | + $p->interdire_scripts = false; |
|
| 1045 | 1045 | |
| 1046 | - return $p; |
|
| 1046 | + return $p; |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1054,8 +1054,8 @@ discard block |
||
| 1054 | 1054 | * l'absence peut-être due à une faute de frappe dans le contexte inclus. |
| 1055 | 1055 | */ |
| 1056 | 1056 | define( |
| 1057 | - 'CODE_PAGINATION', |
|
| 1058 | - '%s($Numrows["%s"]["grand_total"], |
|
| 1057 | + 'CODE_PAGINATION', |
|
| 1058 | + '%s($Numrows["%s"]["grand_total"], |
|
| 1059 | 1059 | %s, |
| 1060 | 1060 | isset($Pile[0][%4$s])?$Pile[0][%4$s]:intval(_request(%4$s)), |
| 1061 | 1061 | %5$s, %6$s, %7$s, %8$s, array(%9$s))' |
@@ -1092,75 +1092,75 @@ discard block |
||
| 1092 | 1092 | * Pile complétée par le code à générer |
| 1093 | 1093 | */ |
| 1094 | 1094 | function balise_PAGINATION_dist($p, $liste = 'true') { |
| 1095 | - $b = index_boucle_mere($p); |
|
| 1096 | - |
|
| 1097 | - // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1098 | - if ($b === '') { |
|
| 1099 | - $msg = [ |
|
| 1100 | - 'zbug_champ_hors_boucle', |
|
| 1101 | - ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1102 | - ]; |
|
| 1103 | - erreur_squelette($msg, $p); |
|
| 1104 | - |
|
| 1105 | - return $p; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1109 | - // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1110 | - if (!$p->boucles[$b]->mode_partie) { |
|
| 1111 | - if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1112 | - $msg = [ |
|
| 1113 | - 'zbug_pagination_sans_critere', |
|
| 1114 | - ['champ' => '#PAGINATION'] |
|
| 1115 | - ]; |
|
| 1116 | - erreur_squelette($msg, $p); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - return $p; |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - // a priori true |
|
| 1123 | - // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1124 | - // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1125 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1126 | - if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1127 | - $key = key($_contexte); |
|
| 1128 | - if (is_numeric($key)) { |
|
| 1129 | - array_shift($_contexte); |
|
| 1130 | - $__modele = interprete_argument_balise(1, $p); |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1135 | - $code_contexte = implode(',', $_contexte); |
|
| 1136 | - } else { |
|
| 1137 | - $code_contexte = ''; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 1141 | - $pas = $p->boucles[$b]->total_parties; |
|
| 1142 | - $f_pagination = chercher_filtre('pagination'); |
|
| 1143 | - $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1144 | - $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1145 | - : ("'debut" . substr($type, 1)); |
|
| 1146 | - |
|
| 1147 | - $p->code = sprintf( |
|
| 1148 | - CODE_PAGINATION, |
|
| 1149 | - $f_pagination, |
|
| 1150 | - $b, |
|
| 1151 | - $type, |
|
| 1152 | - $modif, |
|
| 1153 | - $pas, |
|
| 1154 | - $liste, |
|
| 1155 | - ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1156 | - _q($connect), |
|
| 1157 | - $code_contexte |
|
| 1158 | - ); |
|
| 1159 | - |
|
| 1160 | - $p->boucles[$b]->numrows = true; |
|
| 1161 | - $p->interdire_scripts = false; |
|
| 1162 | - |
|
| 1163 | - return $p; |
|
| 1095 | + $b = index_boucle_mere($p); |
|
| 1096 | + |
|
| 1097 | + // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1098 | + if ($b === '') { |
|
| 1099 | + $msg = [ |
|
| 1100 | + 'zbug_champ_hors_boucle', |
|
| 1101 | + ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1102 | + ]; |
|
| 1103 | + erreur_squelette($msg, $p); |
|
| 1104 | + |
|
| 1105 | + return $p; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1109 | + // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1110 | + if (!$p->boucles[$b]->mode_partie) { |
|
| 1111 | + if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1112 | + $msg = [ |
|
| 1113 | + 'zbug_pagination_sans_critere', |
|
| 1114 | + ['champ' => '#PAGINATION'] |
|
| 1115 | + ]; |
|
| 1116 | + erreur_squelette($msg, $p); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + return $p; |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + // a priori true |
|
| 1123 | + // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1124 | + // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1125 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1126 | + if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1127 | + $key = key($_contexte); |
|
| 1128 | + if (is_numeric($key)) { |
|
| 1129 | + array_shift($_contexte); |
|
| 1130 | + $__modele = interprete_argument_balise(1, $p); |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1135 | + $code_contexte = implode(',', $_contexte); |
|
| 1136 | + } else { |
|
| 1137 | + $code_contexte = ''; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 1141 | + $pas = $p->boucles[$b]->total_parties; |
|
| 1142 | + $f_pagination = chercher_filtre('pagination'); |
|
| 1143 | + $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1144 | + $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1145 | + : ("'debut" . substr($type, 1)); |
|
| 1146 | + |
|
| 1147 | + $p->code = sprintf( |
|
| 1148 | + CODE_PAGINATION, |
|
| 1149 | + $f_pagination, |
|
| 1150 | + $b, |
|
| 1151 | + $type, |
|
| 1152 | + $modif, |
|
| 1153 | + $pas, |
|
| 1154 | + $liste, |
|
| 1155 | + ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1156 | + _q($connect), |
|
| 1157 | + $code_contexte |
|
| 1158 | + ); |
|
| 1159 | + |
|
| 1160 | + $p->boucles[$b]->numrows = true; |
|
| 1161 | + $p->interdire_scripts = false; |
|
| 1162 | + |
|
| 1163 | + return $p; |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | |
@@ -1187,11 +1187,11 @@ discard block |
||
| 1187 | 1187 | * Pile complétée par le code à générer |
| 1188 | 1188 | **/ |
| 1189 | 1189 | function balise_ANCRE_PAGINATION_dist($p) { |
| 1190 | - if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1191 | - return $f($p, $liste = 'false'); |
|
| 1192 | - } else { |
|
| 1193 | - return null; |
|
| 1194 | - } // ou une erreur ? |
|
| 1190 | + if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1191 | + return $f($p, $liste = 'false'); |
|
| 1192 | + } else { |
|
| 1193 | + return null; |
|
| 1194 | + } // ou une erreur ? |
|
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | |
@@ -1212,17 +1212,17 @@ discard block |
||
| 1212 | 1212 | * Pile complétée par le code à générer |
| 1213 | 1213 | **/ |
| 1214 | 1214 | function balise_GRAND_TOTAL_dist($p) { |
| 1215 | - $b = index_boucle_mere($p); |
|
| 1216 | - if ($b === '') { |
|
| 1217 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1218 | - erreur_squelette($msg, $p); |
|
| 1219 | - } else { |
|
| 1220 | - $p->code = "(\$Numrows['$b']['grand_total'] ?? \$Numrows['$b']['total'] ?? 0)"; |
|
| 1221 | - $p->boucles[$b]->numrows = true; |
|
| 1222 | - $p->interdire_scripts = false; |
|
| 1223 | - } |
|
| 1215 | + $b = index_boucle_mere($p); |
|
| 1216 | + if ($b === '') { |
|
| 1217 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1218 | + erreur_squelette($msg, $p); |
|
| 1219 | + } else { |
|
| 1220 | + $p->code = "(\$Numrows['$b']['grand_total'] ?? \$Numrows['$b']['total'] ?? 0)"; |
|
| 1221 | + $p->boucles[$b]->numrows = true; |
|
| 1222 | + $p->interdire_scripts = false; |
|
| 1223 | + } |
|
| 1224 | 1224 | |
| 1225 | - return $p; |
|
| 1225 | + return $p; |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | |
@@ -1250,10 +1250,10 @@ discard block |
||
| 1250 | 1250 | * Pile complétée par le code à générer |
| 1251 | 1251 | **/ |
| 1252 | 1252 | function balise_SELF_dist($p) { |
| 1253 | - $p->code = 'self()'; |
|
| 1254 | - $p->interdire_scripts = false; |
|
| 1253 | + $p->code = 'self()'; |
|
| 1254 | + $p->interdire_scripts = false; |
|
| 1255 | 1255 | |
| 1256 | - return $p; |
|
| 1256 | + return $p; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1280,17 +1280,17 @@ discard block |
||
| 1280 | 1280 | * Pile complétée par le code à générer |
| 1281 | 1281 | **/ |
| 1282 | 1282 | function balise_CHEMIN_dist($p) { |
| 1283 | - $arg = interprete_argument_balise(1, $p); |
|
| 1284 | - if (!$arg) { |
|
| 1285 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1286 | - erreur_squelette($msg, $p); |
|
| 1287 | - } else { |
|
| 1288 | - $p->code = 'find_in_path((string)' . $arg . ')'; |
|
| 1289 | - } |
|
| 1283 | + $arg = interprete_argument_balise(1, $p); |
|
| 1284 | + if (!$arg) { |
|
| 1285 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1286 | + erreur_squelette($msg, $p); |
|
| 1287 | + } else { |
|
| 1288 | + $p->code = 'find_in_path((string)' . $arg . ')'; |
|
| 1289 | + } |
|
| 1290 | 1290 | |
| 1291 | - $p->interdire_scripts = false; |
|
| 1291 | + $p->interdire_scripts = false; |
|
| 1292 | 1292 | |
| 1293 | - return $p; |
|
| 1293 | + return $p; |
|
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | 1296 | /** |
@@ -1315,16 +1315,16 @@ discard block |
||
| 1315 | 1315 | * Pile complétée par le code à générer |
| 1316 | 1316 | **/ |
| 1317 | 1317 | function balise_CHEMIN_IMAGE_dist($p) { |
| 1318 | - $arg = interprete_argument_balise(1, $p); |
|
| 1319 | - if (!$arg) { |
|
| 1320 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1321 | - erreur_squelette($msg, $p); |
|
| 1322 | - } else { |
|
| 1323 | - $p->code = 'chemin_image((string)' . $arg . ')'; |
|
| 1324 | - } |
|
| 1318 | + $arg = interprete_argument_balise(1, $p); |
|
| 1319 | + if (!$arg) { |
|
| 1320 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1321 | + erreur_squelette($msg, $p); |
|
| 1322 | + } else { |
|
| 1323 | + $p->code = 'chemin_image((string)' . $arg . ')'; |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - $p->interdire_scripts = false; |
|
| 1327 | - return $p; |
|
| 1326 | + $p->interdire_scripts = false; |
|
| 1327 | + return $p; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | |
@@ -1362,36 +1362,36 @@ discard block |
||
| 1362 | 1362 | **/ |
| 1363 | 1363 | function balise_ENV_dist($p, $src = null) { |
| 1364 | 1364 | |
| 1365 | - // cle du tableau desiree |
|
| 1366 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1367 | - // valeur par defaut |
|
| 1368 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1365 | + // cle du tableau desiree |
|
| 1366 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1367 | + // valeur par defaut |
|
| 1368 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1369 | 1369 | |
| 1370 | - // $src est un tableau de donnees sources eventuellement transmis |
|
| 1371 | - // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1370 | + // $src est un tableau de donnees sources eventuellement transmis |
|
| 1371 | + // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1372 | 1372 | |
| 1373 | - if (!$_nom) { |
|
| 1374 | - // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1375 | - // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1376 | - if ($src) { |
|
| 1377 | - $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1378 | - } else { |
|
| 1379 | - $p->code = 'serialize($Pile[0]??[])'; |
|
| 1380 | - } |
|
| 1381 | - } else { |
|
| 1382 | - if (!$src) { |
|
| 1383 | - $src = '$Pile[0]??[]'; |
|
| 1384 | - } |
|
| 1385 | - if ($_sinon) { |
|
| 1386 | - $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1387 | - } else { |
|
| 1388 | - $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1389 | - } |
|
| 1390 | - } |
|
| 1373 | + if (!$_nom) { |
|
| 1374 | + // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1375 | + // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1376 | + if ($src) { |
|
| 1377 | + $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1378 | + } else { |
|
| 1379 | + $p->code = 'serialize($Pile[0]??[])'; |
|
| 1380 | + } |
|
| 1381 | + } else { |
|
| 1382 | + if (!$src) { |
|
| 1383 | + $src = '$Pile[0]??[]'; |
|
| 1384 | + } |
|
| 1385 | + if ($_sinon) { |
|
| 1386 | + $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1387 | + } else { |
|
| 1388 | + $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | 1391 | |
| 1392 | - #$p->interdire_scripts = true; |
|
| 1392 | + #$p->interdire_scripts = true; |
|
| 1393 | 1393 | |
| 1394 | - return $p; |
|
| 1394 | + return $p; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | /** |
@@ -1421,16 +1421,16 @@ discard block |
||
| 1421 | 1421 | * Pile completée du code PHP d'exécution de la balise |
| 1422 | 1422 | */ |
| 1423 | 1423 | function balise_CONFIG_dist($p) { |
| 1424 | - if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1425 | - $arg = "''"; |
|
| 1426 | - } |
|
| 1427 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1428 | - $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1424 | + if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1425 | + $arg = "''"; |
|
| 1426 | + } |
|
| 1427 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1428 | + $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1429 | 1429 | |
| 1430 | - $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1431 | - ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1430 | + $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1431 | + ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1432 | 1432 | |
| 1433 | - return $p; |
|
| 1433 | + return $p; |
|
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | 1436 | |
@@ -1453,10 +1453,10 @@ discard block |
||
| 1453 | 1453 | * Pile completée du code PHP d'exécution de la balise |
| 1454 | 1454 | */ |
| 1455 | 1455 | function balise_CONNECT_dist($p) { |
| 1456 | - $p->code = '($connect ? $connect : NULL)'; |
|
| 1457 | - $p->interdire_scripts = false; |
|
| 1456 | + $p->code = '($connect ? $connect : NULL)'; |
|
| 1457 | + $p->interdire_scripts = false; |
|
| 1458 | 1458 | |
| 1459 | - return $p; |
|
| 1459 | + return $p; |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | |
@@ -1484,15 +1484,15 @@ discard block |
||
| 1484 | 1484 | * Pile completée du code PHP d'exécution de la balise |
| 1485 | 1485 | **/ |
| 1486 | 1486 | function balise_SESSION_dist($p) { |
| 1487 | - $p->descr['session'] = true; |
|
| 1487 | + $p->descr['session'] = true; |
|
| 1488 | 1488 | |
| 1489 | - $f = function_exists('balise_ENV') |
|
| 1490 | - ? 'balise_ENV' |
|
| 1491 | - : 'balise_ENV_dist'; |
|
| 1489 | + $f = function_exists('balise_ENV') |
|
| 1490 | + ? 'balise_ENV' |
|
| 1491 | + : 'balise_ENV_dist'; |
|
| 1492 | 1492 | |
| 1493 | - $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1493 | + $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1494 | 1494 | |
| 1495 | - return $p; |
|
| 1495 | + return $p; |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | |
@@ -1515,18 +1515,18 @@ discard block |
||
| 1515 | 1515 | * Pile completée du code PHP d'exécution de la balise |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function balise_SESSION_SET_dist($p) { |
| 1518 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1519 | - $_val = interprete_argument_balise(2, $p); |
|
| 1520 | - if (!$_nom or !$_val) { |
|
| 1521 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1522 | - erreur_squelette($err_b_s_a, $p); |
|
| 1523 | - } else { |
|
| 1524 | - $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1525 | - } |
|
| 1518 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1519 | + $_val = interprete_argument_balise(2, $p); |
|
| 1520 | + if (!$_nom or !$_val) { |
|
| 1521 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1522 | + erreur_squelette($err_b_s_a, $p); |
|
| 1523 | + } else { |
|
| 1524 | + $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1525 | + } |
|
| 1526 | 1526 | |
| 1527 | - $p->interdire_scripts = false; |
|
| 1527 | + $p->interdire_scripts = false; |
|
| 1528 | 1528 | |
| 1529 | - return $p; |
|
| 1529 | + return $p; |
|
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | 1532 | |
@@ -1557,30 +1557,30 @@ discard block |
||
| 1557 | 1557 | * Pile completée du code PHP d'exécution de la balise |
| 1558 | 1558 | **/ |
| 1559 | 1559 | function balise_EVAL_dist($p) { |
| 1560 | - $php = interprete_argument_balise(1, $p); |
|
| 1561 | - if ($php) { |
|
| 1562 | - # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1563 | - # attention au commentaire "// x signes" qui precede |
|
| 1564 | - if ( |
|
| 1565 | - preg_match( |
|
| 1566 | - ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1567 | - $php, |
|
| 1568 | - $r |
|
| 1569 | - ) |
|
| 1570 | - ) { |
|
| 1571 | - $p->code = /* $r[1]. */ |
|
| 1572 | - '(' . $r[2] . ')'; |
|
| 1573 | - } else { |
|
| 1574 | - $p->code = "eval('return '.$php.';')"; |
|
| 1575 | - } |
|
| 1576 | - } else { |
|
| 1577 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1578 | - erreur_squelette($msg, $p); |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - #$p->interdire_scripts = true; |
|
| 1582 | - |
|
| 1583 | - return $p; |
|
| 1560 | + $php = interprete_argument_balise(1, $p); |
|
| 1561 | + if ($php) { |
|
| 1562 | + # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1563 | + # attention au commentaire "// x signes" qui precede |
|
| 1564 | + if ( |
|
| 1565 | + preg_match( |
|
| 1566 | + ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1567 | + $php, |
|
| 1568 | + $r |
|
| 1569 | + ) |
|
| 1570 | + ) { |
|
| 1571 | + $p->code = /* $r[1]. */ |
|
| 1572 | + '(' . $r[2] . ')'; |
|
| 1573 | + } else { |
|
| 1574 | + $p->code = "eval('return '.$php.';')"; |
|
| 1575 | + } |
|
| 1576 | + } else { |
|
| 1577 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1578 | + erreur_squelette($msg, $p); |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + #$p->interdire_scripts = true; |
|
| 1582 | + |
|
| 1583 | + return $p; |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | |
@@ -1610,19 +1610,19 @@ discard block |
||
| 1610 | 1610 | **/ |
| 1611 | 1611 | function balise_CHAMP_SQL_dist($p) { |
| 1612 | 1612 | |
| 1613 | - if ( |
|
| 1614 | - $p->param |
|
| 1615 | - and isset($p->param[0][1][0]) |
|
| 1616 | - and $champ = ($p->param[0][1][0]->texte) |
|
| 1617 | - ) { |
|
| 1618 | - $p->code = champ_sql($champ, $p); |
|
| 1619 | - } else { |
|
| 1620 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1621 | - erreur_squelette($err_b_s_a, $p); |
|
| 1622 | - } |
|
| 1613 | + if ( |
|
| 1614 | + $p->param |
|
| 1615 | + and isset($p->param[0][1][0]) |
|
| 1616 | + and $champ = ($p->param[0][1][0]->texte) |
|
| 1617 | + ) { |
|
| 1618 | + $p->code = champ_sql($champ, $p); |
|
| 1619 | + } else { |
|
| 1620 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1621 | + erreur_squelette($err_b_s_a, $p); |
|
| 1622 | + } |
|
| 1623 | 1623 | |
| 1624 | - #$p->interdire_scripts = true; |
|
| 1625 | - return $p; |
|
| 1624 | + #$p->interdire_scripts = true; |
|
| 1625 | + return $p; |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | /** |
@@ -1648,13 +1648,13 @@ discard block |
||
| 1648 | 1648 | * Pile complétée par le code à générer |
| 1649 | 1649 | **/ |
| 1650 | 1650 | function balise_VAL_dist($p) { |
| 1651 | - $p->code = interprete_argument_balise(1, $p) ?? ''; |
|
| 1652 | - if (!strlen($p->code)) { |
|
| 1653 | - $p->code = "''"; |
|
| 1654 | - } |
|
| 1655 | - $p->interdire_scripts = false; |
|
| 1651 | + $p->code = interprete_argument_balise(1, $p) ?? ''; |
|
| 1652 | + if (!strlen($p->code)) { |
|
| 1653 | + $p->code = "''"; |
|
| 1654 | + } |
|
| 1655 | + $p->interdire_scripts = false; |
|
| 1656 | 1656 | |
| 1657 | - return $p; |
|
| 1657 | + return $p; |
|
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | /** |
@@ -1683,10 +1683,10 @@ discard block |
||
| 1683 | 1683 | * Pile complétée par le code à générer |
| 1684 | 1684 | **/ |
| 1685 | 1685 | function balise_REM_dist($p) { |
| 1686 | - $p->code = "''"; |
|
| 1687 | - $p->interdire_scripts = false; |
|
| 1686 | + $p->code = "''"; |
|
| 1687 | + $p->interdire_scripts = false; |
|
| 1688 | 1688 | |
| 1689 | - return $p; |
|
| 1689 | + return $p; |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | /** |
@@ -1696,10 +1696,10 @@ discard block |
||
| 1696 | 1696 | * @return mixed |
| 1697 | 1697 | */ |
| 1698 | 1698 | function balise_NULL_dist($p) { |
| 1699 | - $p->code = 'null'; |
|
| 1700 | - $p->interdire_scripts = false; |
|
| 1699 | + $p->code = 'null'; |
|
| 1700 | + $p->interdire_scripts = false; |
|
| 1701 | 1701 | |
| 1702 | - return $p; |
|
| 1702 | + return $p; |
|
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | |
@@ -1723,18 +1723,18 @@ discard block |
||
| 1723 | 1723 | **/ |
| 1724 | 1724 | function balise_HTTP_HEADER_dist($p) { |
| 1725 | 1725 | |
| 1726 | - $header = interprete_argument_balise(1, $p); |
|
| 1727 | - if (!$header) { |
|
| 1728 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1729 | - erreur_squelette($err_b_s_a, $p); |
|
| 1730 | - } else { |
|
| 1731 | - $p->code = "'<'.'?php header(' . _q(" |
|
| 1732 | - . $header |
|
| 1733 | - . ") . '); ?'.'>'"; |
|
| 1734 | - } |
|
| 1735 | - $p->interdire_scripts = false; |
|
| 1726 | + $header = interprete_argument_balise(1, $p); |
|
| 1727 | + if (!$header) { |
|
| 1728 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1729 | + erreur_squelette($err_b_s_a, $p); |
|
| 1730 | + } else { |
|
| 1731 | + $p->code = "'<'.'?php header(' . _q(" |
|
| 1732 | + . $header |
|
| 1733 | + . ") . '); ?'.'>'"; |
|
| 1734 | + } |
|
| 1735 | + $p->interdire_scripts = false; |
|
| 1736 | 1736 | |
| 1737 | - return $p; |
|
| 1737 | + return $p; |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | |
@@ -1759,20 +1759,20 @@ discard block |
||
| 1759 | 1759 | * Pile complétée par le code à générer |
| 1760 | 1760 | **/ |
| 1761 | 1761 | function balise_FILTRE_dist($p) { |
| 1762 | - if ($p->param) { |
|
| 1763 | - $args = []; |
|
| 1764 | - foreach ($p->param as $i => $ignore) { |
|
| 1765 | - $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1766 | - } |
|
| 1767 | - $p->code = "'<' . '" |
|
| 1768 | - . '?php header("X-Spip-Filtre: \'.' |
|
| 1769 | - . join('.\'|\'.', $args) |
|
| 1770 | - . " . '\"); ?'.'>'"; |
|
| 1762 | + if ($p->param) { |
|
| 1763 | + $args = []; |
|
| 1764 | + foreach ($p->param as $i => $ignore) { |
|
| 1765 | + $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1766 | + } |
|
| 1767 | + $p->code = "'<' . '" |
|
| 1768 | + . '?php header("X-Spip-Filtre: \'.' |
|
| 1769 | + . join('.\'|\'.', $args) |
|
| 1770 | + . " . '\"); ?'.'>'"; |
|
| 1771 | 1771 | |
| 1772 | - $p->interdire_scripts = false; |
|
| 1772 | + $p->interdire_scripts = false; |
|
| 1773 | 1773 | |
| 1774 | - return $p; |
|
| 1775 | - } |
|
| 1774 | + return $p; |
|
| 1775 | + } |
|
| 1776 | 1776 | } |
| 1777 | 1777 | |
| 1778 | 1778 | |
@@ -1808,55 +1808,55 @@ discard block |
||
| 1808 | 1808 | **/ |
| 1809 | 1809 | function balise_CACHE_dist($p) { |
| 1810 | 1810 | |
| 1811 | - if ($p->param) { |
|
| 1812 | - $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1813 | - |
|
| 1814 | - // noter la duree du cache dans un entete proprietaire |
|
| 1815 | - |
|
| 1816 | - $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1817 | - . $duree |
|
| 1818 | - . '"); ?' . "'.'>'"; |
|
| 1819 | - |
|
| 1820 | - // Remplir le header Cache-Control |
|
| 1821 | - // cas #CACHE{0} |
|
| 1822 | - if ($duree == 0) { |
|
| 1823 | - $code .= ".'<'.'" |
|
| 1824 | - . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1825 | - . "'.'><'.'" |
|
| 1826 | - . '?php header("Pragma: no-cache"); ?' |
|
| 1827 | - . "'.'>'"; |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - // recuperer les parametres suivants |
|
| 1831 | - $i = 1; |
|
| 1832 | - while (isset($p->param[0][++$i])) { |
|
| 1833 | - $pa = ($p->param[0][$i][0]->texte); |
|
| 1834 | - |
|
| 1835 | - if ( |
|
| 1836 | - $pa == 'cache-client' |
|
| 1837 | - and $duree > 0 |
|
| 1838 | - ) { |
|
| 1839 | - $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1840 | - . $duree |
|
| 1841 | - . '"); ?' . "'.'>'"; |
|
| 1842 | - // il semble logique, si on cache-client, de ne pas invalider |
|
| 1843 | - $pa = 'statique'; |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - if ( |
|
| 1847 | - $pa == 'statique' |
|
| 1848 | - and $duree > 0 |
|
| 1849 | - ) { |
|
| 1850 | - $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1851 | - } |
|
| 1852 | - } |
|
| 1853 | - } else { |
|
| 1854 | - $code = "''"; |
|
| 1855 | - } |
|
| 1856 | - $p->code = $code; |
|
| 1857 | - $p->interdire_scripts = false; |
|
| 1858 | - |
|
| 1859 | - return $p; |
|
| 1811 | + if ($p->param) { |
|
| 1812 | + $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1813 | + |
|
| 1814 | + // noter la duree du cache dans un entete proprietaire |
|
| 1815 | + |
|
| 1816 | + $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1817 | + . $duree |
|
| 1818 | + . '"); ?' . "'.'>'"; |
|
| 1819 | + |
|
| 1820 | + // Remplir le header Cache-Control |
|
| 1821 | + // cas #CACHE{0} |
|
| 1822 | + if ($duree == 0) { |
|
| 1823 | + $code .= ".'<'.'" |
|
| 1824 | + . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1825 | + . "'.'><'.'" |
|
| 1826 | + . '?php header("Pragma: no-cache"); ?' |
|
| 1827 | + . "'.'>'"; |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + // recuperer les parametres suivants |
|
| 1831 | + $i = 1; |
|
| 1832 | + while (isset($p->param[0][++$i])) { |
|
| 1833 | + $pa = ($p->param[0][$i][0]->texte); |
|
| 1834 | + |
|
| 1835 | + if ( |
|
| 1836 | + $pa == 'cache-client' |
|
| 1837 | + and $duree > 0 |
|
| 1838 | + ) { |
|
| 1839 | + $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1840 | + . $duree |
|
| 1841 | + . '"); ?' . "'.'>'"; |
|
| 1842 | + // il semble logique, si on cache-client, de ne pas invalider |
|
| 1843 | + $pa = 'statique'; |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + if ( |
|
| 1847 | + $pa == 'statique' |
|
| 1848 | + and $duree > 0 |
|
| 1849 | + ) { |
|
| 1850 | + $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1851 | + } |
|
| 1852 | + } |
|
| 1853 | + } else { |
|
| 1854 | + $code = "''"; |
|
| 1855 | + } |
|
| 1856 | + $p->code = $code; |
|
| 1857 | + $p->interdire_scripts = false; |
|
| 1858 | + |
|
| 1859 | + return $p; |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | |
@@ -1888,13 +1888,13 @@ discard block |
||
| 1888 | 1888 | * Pile complétée par le code à générer |
| 1889 | 1889 | */ |
| 1890 | 1890 | function balise_INSERT_HEAD_dist($p) { |
| 1891 | - $p->code = "'<'.'" |
|
| 1892 | - . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1893 | - . "'.'>'"; |
|
| 1894 | - $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1895 | - $p->interdire_scripts = false; |
|
| 1891 | + $p->code = "'<'.'" |
|
| 1892 | + . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1893 | + . "'.'>'"; |
|
| 1894 | + $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1895 | + $p->interdire_scripts = false; |
|
| 1896 | 1896 | |
| 1897 | - return $p; |
|
| 1897 | + return $p; |
|
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | /** |
@@ -1912,10 +1912,10 @@ discard block |
||
| 1912 | 1912 | * Pile complétée par le code à générer |
| 1913 | 1913 | */ |
| 1914 | 1914 | function balise_INSERT_HEAD_CSS_dist($p) { |
| 1915 | - $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1916 | - $p->interdire_scripts = false; |
|
| 1915 | + $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1916 | + $p->interdire_scripts = false; |
|
| 1917 | 1917 | |
| 1918 | - return $p; |
|
| 1918 | + return $p; |
|
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | /** |
@@ -1930,11 +1930,11 @@ discard block |
||
| 1930 | 1930 | * Pile complétée par le code à générer |
| 1931 | 1931 | **/ |
| 1932 | 1932 | function balise_INCLUDE_dist($p) { |
| 1933 | - if (function_exists('balise_INCLURE')) { |
|
| 1934 | - return balise_INCLURE($p); |
|
| 1935 | - } else { |
|
| 1936 | - return balise_INCLURE_dist($p); |
|
| 1937 | - } |
|
| 1933 | + if (function_exists('balise_INCLURE')) { |
|
| 1934 | + return balise_INCLURE($p); |
|
| 1935 | + } else { |
|
| 1936 | + return balise_INCLURE_dist($p); |
|
| 1937 | + } |
|
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | 1940 | /** |
@@ -1968,66 +1968,66 @@ discard block |
||
| 1968 | 1968 | * Pile complétée par le code à générer |
| 1969 | 1969 | **/ |
| 1970 | 1970 | function balise_INCLURE_dist($p) { |
| 1971 | - $id_boucle = $p->id_boucle; |
|
| 1972 | - // la lang n'est pas passe de facon automatique par argumenter |
|
| 1973 | - // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1974 | - // en option |
|
| 1975 | - |
|
| 1976 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1977 | - |
|
| 1978 | - // erreur de syntaxe = fond absent |
|
| 1979 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1980 | - if (!$_contexte) { |
|
| 1981 | - $contexte = []; |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - if (isset($_contexte['fond'])) { |
|
| 1985 | - $f = $_contexte['fond']; |
|
| 1986 | - // toujours vrai : |
|
| 1987 | - if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1988 | - $f = $r[1]; |
|
| 1989 | - unset($_contexte['fond']); |
|
| 1990 | - } else { |
|
| 1991 | - spip_log('compilation de #INCLURE a revoir'); |
|
| 1992 | - } |
|
| 1993 | - |
|
| 1994 | - // #INCLURE{doublons} |
|
| 1995 | - if (isset($_contexte['doublons'])) { |
|
| 1996 | - $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1997 | - } |
|
| 1998 | - |
|
| 1999 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2000 | - $flag_env = false; |
|
| 2001 | - if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2002 | - $flag_env = true; |
|
| 2003 | - unset($_contexte['env']); |
|
| 2004 | - } |
|
| 2005 | - |
|
| 2006 | - $_options = []; |
|
| 2007 | - if (isset($_contexte['ajax'])) { |
|
| 2008 | - $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2009 | - unset($_contexte['ajax']); |
|
| 2010 | - } |
|
| 2011 | - if ($p->etoile) { |
|
| 2012 | - $_options[] = "'etoile'=>true"; |
|
| 2013 | - } |
|
| 2014 | - $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2015 | - |
|
| 2016 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2017 | - if ($flag_env) { |
|
| 2018 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2019 | - } |
|
| 2020 | - |
|
| 2021 | - $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect') ?? ''"); |
|
| 2022 | - } elseif (!isset($_contexte[1])) { |
|
| 2023 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2024 | - erreur_squelette($msg, $p); |
|
| 2025 | - } else { |
|
| 2026 | - $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2030 | - return $p; |
|
| 1971 | + $id_boucle = $p->id_boucle; |
|
| 1972 | + // la lang n'est pas passe de facon automatique par argumenter |
|
| 1973 | + // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1974 | + // en option |
|
| 1975 | + |
|
| 1976 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1977 | + |
|
| 1978 | + // erreur de syntaxe = fond absent |
|
| 1979 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1980 | + if (!$_contexte) { |
|
| 1981 | + $contexte = []; |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + if (isset($_contexte['fond'])) { |
|
| 1985 | + $f = $_contexte['fond']; |
|
| 1986 | + // toujours vrai : |
|
| 1987 | + if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1988 | + $f = $r[1]; |
|
| 1989 | + unset($_contexte['fond']); |
|
| 1990 | + } else { |
|
| 1991 | + spip_log('compilation de #INCLURE a revoir'); |
|
| 1992 | + } |
|
| 1993 | + |
|
| 1994 | + // #INCLURE{doublons} |
|
| 1995 | + if (isset($_contexte['doublons'])) { |
|
| 1996 | + $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1997 | + } |
|
| 1998 | + |
|
| 1999 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2000 | + $flag_env = false; |
|
| 2001 | + if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2002 | + $flag_env = true; |
|
| 2003 | + unset($_contexte['env']); |
|
| 2004 | + } |
|
| 2005 | + |
|
| 2006 | + $_options = []; |
|
| 2007 | + if (isset($_contexte['ajax'])) { |
|
| 2008 | + $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2009 | + unset($_contexte['ajax']); |
|
| 2010 | + } |
|
| 2011 | + if ($p->etoile) { |
|
| 2012 | + $_options[] = "'etoile'=>true"; |
|
| 2013 | + } |
|
| 2014 | + $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2015 | + |
|
| 2016 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2017 | + if ($flag_env) { |
|
| 2018 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2019 | + } |
|
| 2020 | + |
|
| 2021 | + $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect') ?? ''"); |
|
| 2022 | + } elseif (!isset($_contexte[1])) { |
|
| 2023 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2024 | + erreur_squelette($msg, $p); |
|
| 2025 | + } else { |
|
| 2026 | + $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2030 | + return $p; |
|
| 2031 | 2031 | } |
| 2032 | 2032 | |
| 2033 | 2033 | |
@@ -2055,69 +2055,69 @@ discard block |
||
| 2055 | 2055 | **/ |
| 2056 | 2056 | function balise_MODELE_dist($p) { |
| 2057 | 2057 | |
| 2058 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2059 | - |
|
| 2060 | - // erreur de syntaxe = fond absent |
|
| 2061 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2062 | - if (!$_contexte) { |
|
| 2063 | - $_contexte = []; |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - if (!isset($_contexte[1])) { |
|
| 2067 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2068 | - erreur_squelette($msg, $p); |
|
| 2069 | - } else { |
|
| 2070 | - $nom = $_contexte[1]; |
|
| 2071 | - unset($_contexte[1]); |
|
| 2072 | - |
|
| 2073 | - if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2074 | - $nom = "'modeles/" . substr($nom, 1); |
|
| 2075 | - } else { |
|
| 2076 | - $nom = "'modeles/' . $nom"; |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - $flag_env = false; |
|
| 2080 | - if (isset($_contexte['env'])) { |
|
| 2081 | - $flag_env = true; |
|
| 2082 | - unset($_contexte['env']); |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2086 | - // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2087 | - if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2088 | - $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2089 | - if (!strpos($primary, ',')) { |
|
| 2090 | - $id = champ_sql($primary, $p); |
|
| 2091 | - $_contexte[] = "'$primary'=>" . $id; |
|
| 2092 | - $_contexte[] = "'id'=>" . $id; |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2096 | - $connect = ''; |
|
| 2097 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2098 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - $_options = memoriser_contexte_compil($p); |
|
| 2102 | - $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2103 | - if (isset($_contexte['ajax'])) { |
|
| 2104 | - $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2105 | - unset($_contexte['ajax']); |
|
| 2106 | - } |
|
| 2107 | - |
|
| 2108 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2109 | - if ($flag_env) { |
|
| 2110 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2114 | - |
|
| 2115 | - $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2116 | - |
|
| 2117 | - $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2118 | - } |
|
| 2119 | - |
|
| 2120 | - return $p; |
|
| 2058 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2059 | + |
|
| 2060 | + // erreur de syntaxe = fond absent |
|
| 2061 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2062 | + if (!$_contexte) { |
|
| 2063 | + $_contexte = []; |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + if (!isset($_contexte[1])) { |
|
| 2067 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2068 | + erreur_squelette($msg, $p); |
|
| 2069 | + } else { |
|
| 2070 | + $nom = $_contexte[1]; |
|
| 2071 | + unset($_contexte[1]); |
|
| 2072 | + |
|
| 2073 | + if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2074 | + $nom = "'modeles/" . substr($nom, 1); |
|
| 2075 | + } else { |
|
| 2076 | + $nom = "'modeles/' . $nom"; |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + $flag_env = false; |
|
| 2080 | + if (isset($_contexte['env'])) { |
|
| 2081 | + $flag_env = true; |
|
| 2082 | + unset($_contexte['env']); |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2086 | + // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2087 | + if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2088 | + $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2089 | + if (!strpos($primary, ',')) { |
|
| 2090 | + $id = champ_sql($primary, $p); |
|
| 2091 | + $_contexte[] = "'$primary'=>" . $id; |
|
| 2092 | + $_contexte[] = "'id'=>" . $id; |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2096 | + $connect = ''; |
|
| 2097 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2098 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + $_options = memoriser_contexte_compil($p); |
|
| 2102 | + $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2103 | + if (isset($_contexte['ajax'])) { |
|
| 2104 | + $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2105 | + unset($_contexte['ajax']); |
|
| 2106 | + } |
|
| 2107 | + |
|
| 2108 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2109 | + if ($flag_env) { |
|
| 2110 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2114 | + |
|
| 2115 | + $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2116 | + |
|
| 2117 | + $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + return $p; |
|
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | 2123 | |
@@ -2141,21 +2141,21 @@ discard block |
||
| 2141 | 2141 | * Pile complétée par le code à générer |
| 2142 | 2142 | **/ |
| 2143 | 2143 | function balise_SET_dist($p) { |
| 2144 | - $_nom = interprete_argument_balise(1, $p); |
|
| 2145 | - $_val = interprete_argument_balise(2, $p); |
|
| 2144 | + $_nom = interprete_argument_balise(1, $p); |
|
| 2145 | + $_val = interprete_argument_balise(2, $p); |
|
| 2146 | 2146 | |
| 2147 | - if (!$_nom or !$_val) { |
|
| 2148 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2149 | - erreur_squelette($err_b_s_a, $p); |
|
| 2150 | - } |
|
| 2151 | - // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2152 | - // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2153 | - else { |
|
| 2154 | - $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2155 | - } |
|
| 2147 | + if (!$_nom or !$_val) { |
|
| 2148 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2149 | + erreur_squelette($err_b_s_a, $p); |
|
| 2150 | + } |
|
| 2151 | + // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2152 | + // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2153 | + else { |
|
| 2154 | + $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2155 | + } |
|
| 2156 | 2156 | |
| 2157 | - $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2158 | - return $p; |
|
| 2157 | + $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2158 | + return $p; |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | |
@@ -2185,12 +2185,12 @@ discard block |
||
| 2185 | 2185 | * Pile complétée par le code à générer |
| 2186 | 2186 | **/ |
| 2187 | 2187 | function balise_GET_dist($p) { |
| 2188 | - $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2189 | - if (function_exists('balise_ENV')) { |
|
| 2190 | - return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2191 | - } else { |
|
| 2192 | - return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2193 | - } |
|
| 2188 | + $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2189 | + if (function_exists('balise_ENV')) { |
|
| 2190 | + return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2191 | + } else { |
|
| 2192 | + return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2193 | + } |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | 2196 | |
@@ -2213,22 +2213,22 @@ discard block |
||
| 2213 | 2213 | * Pile complétée par le code à générer |
| 2214 | 2214 | **/ |
| 2215 | 2215 | function balise_DOUBLONS_dist($p) { |
| 2216 | - if ($type = interprete_argument_balise(1, $p)) { |
|
| 2217 | - if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2218 | - $type .= '.' . $famille; |
|
| 2219 | - } |
|
| 2220 | - $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2221 | - if (!$p->etoile) { |
|
| 2222 | - $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2223 | - . $p->code . ')))'; |
|
| 2224 | - } |
|
| 2225 | - } else { |
|
| 2226 | - $p->code = '$doublons'; |
|
| 2227 | - } |
|
| 2216 | + if ($type = interprete_argument_balise(1, $p)) { |
|
| 2217 | + if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2218 | + $type .= '.' . $famille; |
|
| 2219 | + } |
|
| 2220 | + $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2221 | + if (!$p->etoile) { |
|
| 2222 | + $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2223 | + . $p->code . ')))'; |
|
| 2224 | + } |
|
| 2225 | + } else { |
|
| 2226 | + $p->code = '$doublons'; |
|
| 2227 | + } |
|
| 2228 | 2228 | |
| 2229 | - $p->interdire_scripts = false; |
|
| 2229 | + $p->interdire_scripts = false; |
|
| 2230 | 2230 | |
| 2231 | - return $p; |
|
| 2231 | + return $p; |
|
| 2232 | 2232 | } |
| 2233 | 2233 | |
| 2234 | 2234 | |
@@ -2251,18 +2251,18 @@ discard block |
||
| 2251 | 2251 | * Pile complétée par le code à générer |
| 2252 | 2252 | **/ |
| 2253 | 2253 | function balise_PIPELINE_dist($p) { |
| 2254 | - $_pipe = interprete_argument_balise(1, $p); |
|
| 2255 | - if (!$_pipe) { |
|
| 2256 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2257 | - erreur_squelette($err_b_s_a, $p); |
|
| 2258 | - } else { |
|
| 2259 | - $_flux = interprete_argument_balise(2, $p); |
|
| 2260 | - $_flux = $_flux ?: "''"; |
|
| 2261 | - $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2262 | - $p->interdire_scripts = false; |
|
| 2263 | - } |
|
| 2254 | + $_pipe = interprete_argument_balise(1, $p); |
|
| 2255 | + if (!$_pipe) { |
|
| 2256 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2257 | + erreur_squelette($err_b_s_a, $p); |
|
| 2258 | + } else { |
|
| 2259 | + $_flux = interprete_argument_balise(2, $p); |
|
| 2260 | + $_flux = $_flux ?: "''"; |
|
| 2261 | + $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2262 | + $p->interdire_scripts = false; |
|
| 2263 | + } |
|
| 2264 | 2264 | |
| 2265 | - return $p; |
|
| 2265 | + return $p; |
|
| 2266 | 2266 | } |
| 2267 | 2267 | |
| 2268 | 2268 | |
@@ -2287,10 +2287,10 @@ discard block |
||
| 2287 | 2287 | * Pile complétée par le code à générer |
| 2288 | 2288 | **/ |
| 2289 | 2289 | function balise_EDIT_dist($p) { |
| 2290 | - $p->code = "''"; |
|
| 2291 | - $p->interdire_scripts = false; |
|
| 2290 | + $p->code = "''"; |
|
| 2291 | + $p->interdire_scripts = false; |
|
| 2292 | 2292 | |
| 2293 | - return $p; |
|
| 2293 | + return $p; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | |
| 2296 | 2296 | |
@@ -2313,11 +2313,11 @@ discard block |
||
| 2313 | 2313 | * Pile complétée par le code à générer |
| 2314 | 2314 | **/ |
| 2315 | 2315 | function balise_TOTAL_UNIQUE_dist($p) { |
| 2316 | - $_famille = interprete_argument_balise(1, $p); |
|
| 2317 | - $_famille = $_famille ?: "''"; |
|
| 2318 | - $p->code = "unique('', $_famille, true)"; |
|
| 2316 | + $_famille = interprete_argument_balise(1, $p); |
|
| 2317 | + $_famille = $_famille ?: "''"; |
|
| 2318 | + $p->code = "unique('', $_famille, true)"; |
|
| 2319 | 2319 | |
| 2320 | - return $p; |
|
| 2320 | + return $p; |
|
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | 2323 | /** |
@@ -2340,19 +2340,19 @@ discard block |
||
| 2340 | 2340 | * Pile complétée par le code à générer |
| 2341 | 2341 | **/ |
| 2342 | 2342 | function balise_ARRAY_dist($p) { |
| 2343 | - $_code = []; |
|
| 2344 | - $n = 1; |
|
| 2345 | - do { |
|
| 2346 | - $_key = interprete_argument_balise($n++, $p); |
|
| 2347 | - $_val = interprete_argument_balise($n++, $p); |
|
| 2348 | - if ($_key and $_val) { |
|
| 2349 | - $_code[] = "$_key => $_val"; |
|
| 2350 | - } |
|
| 2351 | - } while ($_key && $_val); |
|
| 2352 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2353 | - $p->interdire_scripts = false; |
|
| 2343 | + $_code = []; |
|
| 2344 | + $n = 1; |
|
| 2345 | + do { |
|
| 2346 | + $_key = interprete_argument_balise($n++, $p); |
|
| 2347 | + $_val = interprete_argument_balise($n++, $p); |
|
| 2348 | + if ($_key and $_val) { |
|
| 2349 | + $_code[] = "$_key => $_val"; |
|
| 2350 | + } |
|
| 2351 | + } while ($_key && $_val); |
|
| 2352 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2353 | + $p->interdire_scripts = false; |
|
| 2354 | 2354 | |
| 2355 | - return $p; |
|
| 2355 | + return $p; |
|
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | /** |
@@ -2371,15 +2371,15 @@ discard block |
||
| 2371 | 2371 | * Pile complétée par le code à générer |
| 2372 | 2372 | */ |
| 2373 | 2373 | function balise_LISTE_dist($p) { |
| 2374 | - $_code = []; |
|
| 2375 | - $n = 1; |
|
| 2376 | - while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2377 | - $_code[] = $_val; |
|
| 2378 | - } |
|
| 2379 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2380 | - $p->interdire_scripts = false; |
|
| 2374 | + $_code = []; |
|
| 2375 | + $n = 1; |
|
| 2376 | + while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2377 | + $_code[] = $_val; |
|
| 2378 | + } |
|
| 2379 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2380 | + $p->interdire_scripts = false; |
|
| 2381 | 2381 | |
| 2382 | - return $p; |
|
| 2382 | + return $p; |
|
| 2383 | 2383 | } |
| 2384 | 2384 | |
| 2385 | 2385 | |
@@ -2413,21 +2413,21 @@ discard block |
||
| 2413 | 2413 | * Pile complétée par le code à générer |
| 2414 | 2414 | **/ |
| 2415 | 2415 | function balise_AUTORISER_dist($p) { |
| 2416 | - $_code = []; |
|
| 2417 | - $p->descr['session'] = true; // faire un cache par session |
|
| 2416 | + $_code = []; |
|
| 2417 | + $p->descr['session'] = true; // faire un cache par session |
|
| 2418 | 2418 | |
| 2419 | - $n = 1; |
|
| 2420 | - while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2421 | - $_code[] = $_v; |
|
| 2422 | - } |
|
| 2419 | + $n = 1; |
|
| 2420 | + while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2421 | + $_code[] = $_v; |
|
| 2422 | + } |
|
| 2423 | 2423 | |
| 2424 | - $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2425 | - ', ', |
|
| 2426 | - $_code |
|
| 2427 | - ) . ')?" ":"")'; |
|
| 2428 | - $p->interdire_scripts = false; |
|
| 2424 | + $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2425 | + ', ', |
|
| 2426 | + $_code |
|
| 2427 | + ) . ')?" ":"")'; |
|
| 2428 | + $p->interdire_scripts = false; |
|
| 2429 | 2429 | |
| 2430 | - return $p; |
|
| 2430 | + return $p; |
|
| 2431 | 2431 | } |
| 2432 | 2432 | |
| 2433 | 2433 | |
@@ -2451,15 +2451,15 @@ discard block |
||
| 2451 | 2451 | * Pile complétée par le code à générer |
| 2452 | 2452 | **/ |
| 2453 | 2453 | function balise_PLUGIN_dist($p) { |
| 2454 | - $plugin = interprete_argument_balise(1, $p); |
|
| 2455 | - $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2456 | - $type_info = interprete_argument_balise(2, $p); |
|
| 2457 | - $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2454 | + $plugin = interprete_argument_balise(1, $p); |
|
| 2455 | + $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2456 | + $type_info = interprete_argument_balise(2, $p); |
|
| 2457 | + $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2458 | 2458 | |
| 2459 | - $f = chercher_filtre('info_plugin'); |
|
| 2460 | - $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2459 | + $f = chercher_filtre('info_plugin'); |
|
| 2460 | + $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2461 | 2461 | |
| 2462 | - return $p; |
|
| 2462 | + return $p; |
|
| 2463 | 2463 | } |
| 2464 | 2464 | |
| 2465 | 2465 | /** |
@@ -2480,9 +2480,9 @@ discard block |
||
| 2480 | 2480 | * Pile complétée par le code à générer |
| 2481 | 2481 | **/ |
| 2482 | 2482 | function balise_AIDER_dist($p) { |
| 2483 | - $_motif = interprete_argument_balise(1, $p); |
|
| 2484 | - $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2485 | - return $p; |
|
| 2483 | + $_motif = interprete_argument_balise(1, $p); |
|
| 2484 | + $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2485 | + return $p; |
|
| 2486 | 2486 | } |
| 2487 | 2487 | |
| 2488 | 2488 | /** |
@@ -2508,16 +2508,16 @@ discard block |
||
| 2508 | 2508 | * Pile complétée par le code à générer |
| 2509 | 2509 | **/ |
| 2510 | 2510 | function balise_ACTION_FORMULAIRE($p) { |
| 2511 | - if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2512 | - $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2513 | - } |
|
| 2514 | - if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2515 | - $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2516 | - } |
|
| 2517 | - |
|
| 2518 | - // envoyer le nom du formulaire que l'on traite |
|
| 2519 | - // transmettre les eventuels args de la balise formulaire |
|
| 2520 | - $p->code = " '<span class=\"form-hidden\">' . |
|
| 2511 | + if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2512 | + $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2513 | + } |
|
| 2514 | + if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2515 | + $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2516 | + } |
|
| 2517 | + |
|
| 2518 | + // envoyer le nom du formulaire que l'on traite |
|
| 2519 | + // transmettre les eventuels args de la balise formulaire |
|
| 2520 | + $p->code = " '<span class=\"form-hidden\">' . |
|
| 2521 | 2521 | form_hidden($_url) . |
| 2522 | 2522 | '<input name=\'formulaire_action\' type=\'hidden\' |
| 2523 | 2523 | value=\'' . $_form . '\' />' . |
@@ -2528,9 +2528,9 @@ discard block |
||
| 2528 | 2528 | (\$Pile[0]['_hidden'] ?? '') . |
| 2529 | 2529 | '</span>'"; |
| 2530 | 2530 | |
| 2531 | - $p->interdire_scripts = false; |
|
| 2531 | + $p->interdire_scripts = false; |
|
| 2532 | 2532 | |
| 2533 | - return $p; |
|
| 2533 | + return $p; |
|
| 2534 | 2534 | } |
| 2535 | 2535 | |
| 2536 | 2536 | |
@@ -2571,25 +2571,25 @@ discard block |
||
| 2571 | 2571 | */ |
| 2572 | 2572 | function balise_BOUTON_ACTION_dist($p) { |
| 2573 | 2573 | |
| 2574 | - $args = []; |
|
| 2575 | - for ($k = 1; $k <= 6; $k++) { |
|
| 2576 | - $_a = interprete_argument_balise($k, $p); |
|
| 2577 | - if (!$_a) { |
|
| 2578 | - $_a = "''"; |
|
| 2579 | - } |
|
| 2580 | - $args[] = $_a; |
|
| 2581 | - } |
|
| 2582 | - // supprimer les args vides |
|
| 2583 | - while (end($args) == "''" and count($args) > 2) { |
|
| 2584 | - array_pop($args); |
|
| 2585 | - } |
|
| 2586 | - $args = implode(',', $args); |
|
| 2574 | + $args = []; |
|
| 2575 | + for ($k = 1; $k <= 6; $k++) { |
|
| 2576 | + $_a = interprete_argument_balise($k, $p); |
|
| 2577 | + if (!$_a) { |
|
| 2578 | + $_a = "''"; |
|
| 2579 | + } |
|
| 2580 | + $args[] = $_a; |
|
| 2581 | + } |
|
| 2582 | + // supprimer les args vides |
|
| 2583 | + while (end($args) == "''" and count($args) > 2) { |
|
| 2584 | + array_pop($args); |
|
| 2585 | + } |
|
| 2586 | + $args = implode(',', $args); |
|
| 2587 | 2587 | |
| 2588 | - $bouton_action = chercher_filtre('bouton_action'); |
|
| 2589 | - $p->code = "$bouton_action($args)"; |
|
| 2590 | - $p->interdire_scripts = false; |
|
| 2588 | + $bouton_action = chercher_filtre('bouton_action'); |
|
| 2589 | + $p->code = "$bouton_action($args)"; |
|
| 2590 | + $p->interdire_scripts = false; |
|
| 2591 | 2591 | |
| 2592 | - return $p; |
|
| 2592 | + return $p; |
|
| 2593 | 2593 | } |
| 2594 | 2594 | |
| 2595 | 2595 | |
@@ -2608,10 +2608,10 @@ discard block |
||
| 2608 | 2608 | * Pile complétée par le code à générer |
| 2609 | 2609 | */ |
| 2610 | 2610 | function balise_SLOGAN_SITE_SPIP_dist($p) { |
| 2611 | - $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2611 | + $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2612 | 2612 | |
| 2613 | - #$p->interdire_scripts = true; |
|
| 2614 | - return $p; |
|
| 2613 | + #$p->interdire_scripts = true; |
|
| 2614 | + return $p; |
|
| 2615 | 2615 | } |
| 2616 | 2616 | |
| 2617 | 2617 | |
@@ -2635,10 +2635,10 @@ discard block |
||
| 2635 | 2635 | * Pile complétée par le code à générer |
| 2636 | 2636 | */ |
| 2637 | 2637 | function balise_HTML5_dist($p) { |
| 2638 | - $p->code = html5_permis() ? "' '" : "''"; |
|
| 2639 | - $p->interdire_scripts = false; |
|
| 2638 | + $p->code = html5_permis() ? "' '" : "''"; |
|
| 2639 | + $p->interdire_scripts = false; |
|
| 2640 | 2640 | |
| 2641 | - return $p; |
|
| 2641 | + return $p; |
|
| 2642 | 2642 | } |
| 2643 | 2643 | |
| 2644 | 2644 | |
@@ -2664,58 +2664,58 @@ discard block |
||
| 2664 | 2664 | * Pile complétée par le code à générer |
| 2665 | 2665 | */ |
| 2666 | 2666 | function balise_TRI_dist($p, $liste = 'true') { |
| 2667 | - $b = index_boucle_mere($p); |
|
| 2668 | - // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2669 | - if ($b === '') { |
|
| 2670 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2671 | - erreur_squelette($msg, $p); |
|
| 2672 | - $p->code = "''"; |
|
| 2667 | + $b = index_boucle_mere($p); |
|
| 2668 | + // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2669 | + if ($b === '') { |
|
| 2670 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2671 | + erreur_squelette($msg, $p); |
|
| 2672 | + $p->code = "''"; |
|
| 2673 | 2673 | |
| 2674 | - return $p; |
|
| 2675 | - } |
|
| 2676 | - $boucle = $p->boucles[$b]; |
|
| 2674 | + return $p; |
|
| 2675 | + } |
|
| 2676 | + $boucle = $p->boucles[$b]; |
|
| 2677 | 2677 | |
| 2678 | - // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2679 | - // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2680 | - if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2681 | - $msg = ['zbug_champ_hors_critere', [ |
|
| 2682 | - 'champ' => zbug_presenter_champ($p), |
|
| 2683 | - 'critere' => 'tri' |
|
| 2684 | - ]]; |
|
| 2685 | - erreur_squelette($msg, $p); |
|
| 2686 | - $p->code = "''"; |
|
| 2678 | + // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2679 | + // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2680 | + if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2681 | + $msg = ['zbug_champ_hors_critere', [ |
|
| 2682 | + 'champ' => zbug_presenter_champ($p), |
|
| 2683 | + 'critere' => 'tri' |
|
| 2684 | + ]]; |
|
| 2685 | + erreur_squelette($msg, $p); |
|
| 2686 | + $p->code = "''"; |
|
| 2687 | 2687 | |
| 2688 | - return $p; |
|
| 2689 | - } |
|
| 2688 | + return $p; |
|
| 2689 | + } |
|
| 2690 | 2690 | |
| 2691 | - // Différentes infos relatives au tri présentes dans les modificateurs |
|
| 2692 | - $_tri_nom = $boucle->modificateur['tri_nom'] ; // nom du paramètre définissant le tri |
|
| 2693 | - $_tri_champ = $boucle->modificateur['tri_champ']; // champ actuel utilisé le tri |
|
| 2694 | - $_tri_sens = $boucle->modificateur['tri_sens']; // sens de tri actuel |
|
| 2695 | - $_tri_liste_sens_defaut = $boucle->modificateur['tri_liste_sens_defaut']; // sens par défaut pour chaque champ |
|
| 2691 | + // Différentes infos relatives au tri présentes dans les modificateurs |
|
| 2692 | + $_tri_nom = $boucle->modificateur['tri_nom'] ; // nom du paramètre définissant le tri |
|
| 2693 | + $_tri_champ = $boucle->modificateur['tri_champ']; // champ actuel utilisé le tri |
|
| 2694 | + $_tri_sens = $boucle->modificateur['tri_sens']; // sens de tri actuel |
|
| 2695 | + $_tri_liste_sens_defaut = $boucle->modificateur['tri_liste_sens_defaut']; // sens par défaut pour chaque champ |
|
| 2696 | 2696 | |
| 2697 | - $_champ_ou_sens = interprete_argument_balise(1, $p); |
|
| 2698 | - // si pas de champ, renvoyer le critère de tri actuel |
|
| 2699 | - if (!$_champ_ou_sens) { |
|
| 2700 | - $p->code = $_tri_champ; |
|
| 2697 | + $_champ_ou_sens = interprete_argument_balise(1, $p); |
|
| 2698 | + // si pas de champ, renvoyer le critère de tri actuel |
|
| 2699 | + if (!$_champ_ou_sens) { |
|
| 2700 | + $p->code = $_tri_champ; |
|
| 2701 | 2701 | |
| 2702 | - return $p; |
|
| 2703 | - } |
|
| 2704 | - // forcer la jointure si besoin, et si le champ est statique |
|
| 2705 | - if (preg_match(",^'([\w.]+)'$,i", $_champ_ou_sens, $m)) { |
|
| 2706 | - index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2707 | - } |
|
| 2702 | + return $p; |
|
| 2703 | + } |
|
| 2704 | + // forcer la jointure si besoin, et si le champ est statique |
|
| 2705 | + if (preg_match(",^'([\w.]+)'$,i", $_champ_ou_sens, $m)) { |
|
| 2706 | + index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2707 | + } |
|
| 2708 | 2708 | |
| 2709 | - $_libelle = interprete_argument_balise(2, $p); |
|
| 2710 | - $_libelle = $_libelle ?: $_champ_ou_sens; |
|
| 2709 | + $_libelle = interprete_argument_balise(2, $p); |
|
| 2710 | + $_libelle = $_libelle ?: $_champ_ou_sens; |
|
| 2711 | 2711 | |
| 2712 | - $_class = interprete_argument_balise(3, $p) ?? "''"; |
|
| 2712 | + $_class = interprete_argument_balise(3, $p) ?? "''"; |
|
| 2713 | 2713 | |
| 2714 | - $p->code = "calculer_balise_tri($_champ_ou_sens, $_libelle, $_class, $_tri_nom, $_tri_champ, $_tri_sens, $_tri_liste_sens_defaut)"; |
|
| 2714 | + $p->code = "calculer_balise_tri($_champ_ou_sens, $_libelle, $_class, $_tri_nom, $_tri_champ, $_tri_sens, $_tri_liste_sens_defaut)"; |
|
| 2715 | 2715 | |
| 2716 | - $p->interdire_scripts = false; |
|
| 2716 | + $p->interdire_scripts = false; |
|
| 2717 | 2717 | |
| 2718 | - return $p; |
|
| 2718 | + return $p; |
|
| 2719 | 2719 | } |
| 2720 | 2720 | |
| 2721 | 2721 | |
@@ -2736,21 +2736,21 @@ discard block |
||
| 2736 | 2736 | * Pile complétée par le code à générer |
| 2737 | 2737 | */ |
| 2738 | 2738 | function balise_SAUTER_dist($p) { |
| 2739 | - $id_boucle = $p->id_boucle; |
|
| 2739 | + $id_boucle = $p->id_boucle; |
|
| 2740 | 2740 | |
| 2741 | - if (empty($p->boucles[$id_boucle])) { |
|
| 2742 | - $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2743 | - erreur_squelette($msg, $p); |
|
| 2744 | - } else { |
|
| 2745 | - $_saut = interprete_argument_balise(1, $p); |
|
| 2746 | - $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2747 | - $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2741 | + if (empty($p->boucles[$id_boucle])) { |
|
| 2742 | + $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2743 | + erreur_squelette($msg, $p); |
|
| 2744 | + } else { |
|
| 2745 | + $_saut = interprete_argument_balise(1, $p); |
|
| 2746 | + $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2747 | + $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2748 | 2748 | |
| 2749 | - $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2750 | - } |
|
| 2751 | - $p->interdire_scripts = false; |
|
| 2749 | + $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2750 | + } |
|
| 2751 | + $p->interdire_scripts = false; |
|
| 2752 | 2752 | |
| 2753 | - return $p; |
|
| 2753 | + return $p; |
|
| 2754 | 2754 | } |
| 2755 | 2755 | |
| 2756 | 2756 | |
@@ -2772,22 +2772,22 @@ discard block |
||
| 2772 | 2772 | * Pile complétée par le code à générer |
| 2773 | 2773 | */ |
| 2774 | 2774 | function balise_PUBLIE_dist($p) { |
| 2775 | - if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2776 | - $_type = _q($p->type_requete); |
|
| 2777 | - $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2778 | - } else { |
|
| 2779 | - $_id = interprete_argument_balise(2, $p); |
|
| 2780 | - } |
|
| 2775 | + if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2776 | + $_type = _q($p->type_requete); |
|
| 2777 | + $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2778 | + } else { |
|
| 2779 | + $_id = interprete_argument_balise(2, $p); |
|
| 2780 | + } |
|
| 2781 | 2781 | |
| 2782 | - $connect = ''; |
|
| 2783 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2784 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2785 | - } |
|
| 2782 | + $connect = ''; |
|
| 2783 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2784 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2785 | + } |
|
| 2786 | 2786 | |
| 2787 | - $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2788 | - $p->interdire_scripts = false; |
|
| 2787 | + $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2788 | + $p->interdire_scripts = false; |
|
| 2789 | 2789 | |
| 2790 | - return $p; |
|
| 2790 | + return $p; |
|
| 2791 | 2791 | } |
| 2792 | 2792 | |
| 2793 | 2793 | /** |
@@ -2816,12 +2816,12 @@ discard block |
||
| 2816 | 2816 | * Pile complétée par le code à générer |
| 2817 | 2817 | */ |
| 2818 | 2818 | function balise_PRODUIRE_dist($p) { |
| 2819 | - $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2820 | - $p = $balise_inclure($p); |
|
| 2819 | + $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2820 | + $p = $balise_inclure($p); |
|
| 2821 | 2821 | |
| 2822 | - $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2822 | + $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2823 | 2823 | |
| 2824 | - return $p; |
|
| 2824 | + return $p; |
|
| 2825 | 2825 | } |
| 2826 | 2826 | |
| 2827 | 2827 | /** |
@@ -2840,13 +2840,13 @@ discard block |
||
| 2840 | 2840 | * Pile complétée par le code à générer |
| 2841 | 2841 | */ |
| 2842 | 2842 | function balise_LARGEUR_ECRAN_dist($p) { |
| 2843 | - $_class = interprete_argument_balise(1, $p); |
|
| 2844 | - if (!$_class) { |
|
| 2845 | - $_class = 'null'; |
|
| 2846 | - } |
|
| 2847 | - $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2843 | + $_class = interprete_argument_balise(1, $p); |
|
| 2844 | + if (!$_class) { |
|
| 2845 | + $_class = 'null'; |
|
| 2846 | + } |
|
| 2847 | + $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2848 | 2848 | |
| 2849 | - return $p; |
|
| 2849 | + return $p; |
|
| 2850 | 2850 | } |
| 2851 | 2851 | |
| 2852 | 2852 | |
@@ -2862,14 +2862,14 @@ discard block |
||
| 2862 | 2862 | * Pile complétée par le code à générer |
| 2863 | 2863 | **/ |
| 2864 | 2864 | function balise_CONST_dist($p) { |
| 2865 | - $_const = interprete_argument_balise(1, $p); |
|
| 2866 | - if (!strlen($_const ?? '')) { |
|
| 2867 | - $p->code = "''"; |
|
| 2868 | - } |
|
| 2869 | - else { |
|
| 2870 | - $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2871 | - } |
|
| 2872 | - $p->interdire_scripts = false; |
|
| 2873 | - |
|
| 2874 | - return $p; |
|
| 2865 | + $_const = interprete_argument_balise(1, $p); |
|
| 2866 | + if (!strlen($_const ?? '')) { |
|
| 2867 | + $p->code = "''"; |
|
| 2868 | + } |
|
| 2869 | + else { |
|
| 2870 | + $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2871 | + } |
|
| 2872 | + $p->interdire_scripts = false; |
|
| 2873 | + |
|
| 2874 | + return $p; |
|
| 2875 | 2875 | } |
@@ -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 | /** Début de la partie principale d'une boucle */ |
@@ -64,82 +64,82 @@ discard block |
||
| 64 | 64 | |
| 65 | 65 | function phraser_inclure($texte, $ligne, $result) { |
| 66 | 66 | |
| 67 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | - $match = array_pad($match, 3, null); |
|
| 69 | - $p = strpos($texte, (string) $match[0]); |
|
| 70 | - $debut = substr($texte, 0, $p); |
|
| 71 | - if ($p) { |
|
| 72 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | - } |
|
| 74 | - $ligne += substr_count($debut, "\n"); |
|
| 75 | - $champ = new Inclure(); |
|
| 76 | - $champ->ligne = $ligne; |
|
| 77 | - $ligne += substr_count($match[0], "\n"); |
|
| 78 | - $fichier = $match[2]; |
|
| 79 | - # assurer ici la migration .php3 => .php |
|
| 80 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | - $fichier = $r[1]; |
|
| 83 | - } |
|
| 84 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | - $pos_apres = 0; |
|
| 88 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | - if (!function_exists('normaliser_inclure')) { |
|
| 91 | - include_spip('public/normaliser'); |
|
| 92 | - } |
|
| 93 | - normaliser_inclure($champ); |
|
| 94 | - } |
|
| 95 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | - $result[] = $champ; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 67 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 68 | + $match = array_pad($match, 3, null); |
|
| 69 | + $p = strpos($texte, (string) $match[0]); |
|
| 70 | + $debut = substr($texte, 0, $p); |
|
| 71 | + if ($p) { |
|
| 72 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 73 | + } |
|
| 74 | + $ligne += substr_count($debut, "\n"); |
|
| 75 | + $champ = new Inclure(); |
|
| 76 | + $champ->ligne = $ligne; |
|
| 77 | + $ligne += substr_count($match[0], "\n"); |
|
| 78 | + $fichier = $match[2]; |
|
| 79 | + # assurer ici la migration .php3 => .php |
|
| 80 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 81 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 82 | + $fichier = $r[1]; |
|
| 83 | + } |
|
| 84 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 85 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 86 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 87 | + $pos_apres = 0; |
|
| 88 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 89 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 90 | + if (!function_exists('normaliser_inclure')) { |
|
| 91 | + include_spip('public/normaliser'); |
|
| 92 | + } |
|
| 93 | + normaliser_inclure($champ); |
|
| 94 | + } |
|
| 95 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 96 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 97 | + $result[] = $champ; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | function phraser_polyglotte($texte, $ligne, $result) { |
| 104 | 104 | |
| 105 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | - foreach ($m as $match) { |
|
| 107 | - $p = strpos($texte, (string) $match[0]); |
|
| 108 | - $debut = substr($texte, 0, $p); |
|
| 109 | - if ($p) { |
|
| 110 | - $champ = new Texte(); |
|
| 111 | - $champ->texte = $debut; |
|
| 112 | - $champ->ligne = $ligne; |
|
| 113 | - $result[] = $champ; |
|
| 114 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $champ = new Polyglotte(); |
|
| 118 | - $champ->ligne = $ligne; |
|
| 119 | - $ligne += substr_count($match[0], "\n"); |
|
| 120 | - $lang = ''; |
|
| 121 | - $bloc = $match[1]; |
|
| 122 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | - $trad = $regs[1]; |
|
| 125 | - if ($trad or $lang) { |
|
| 126 | - $champ->traductions[$lang] = $trad; |
|
| 127 | - } |
|
| 128 | - $lang = $regs[2]; |
|
| 129 | - $bloc = $regs[3]; |
|
| 130 | - } |
|
| 131 | - $champ->traductions[$lang] = $bloc; |
|
| 132 | - $result[] = $champ; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if ($texte !== '') { |
|
| 136 | - $champ = new Texte(); |
|
| 137 | - $champ->texte = $texte; |
|
| 138 | - $champ->ligne = $ligne; |
|
| 139 | - $result[] = $champ; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $result; |
|
| 105 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 106 | + foreach ($m as $match) { |
|
| 107 | + $p = strpos($texte, (string) $match[0]); |
|
| 108 | + $debut = substr($texte, 0, $p); |
|
| 109 | + if ($p) { |
|
| 110 | + $champ = new Texte(); |
|
| 111 | + $champ->texte = $debut; |
|
| 112 | + $champ->ligne = $ligne; |
|
| 113 | + $result[] = $champ; |
|
| 114 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $champ = new Polyglotte(); |
|
| 118 | + $champ->ligne = $ligne; |
|
| 119 | + $ligne += substr_count($match[0], "\n"); |
|
| 120 | + $lang = ''; |
|
| 121 | + $bloc = $match[1]; |
|
| 122 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 123 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 124 | + $trad = $regs[1]; |
|
| 125 | + if ($trad or $lang) { |
|
| 126 | + $champ->traductions[$lang] = $trad; |
|
| 127 | + } |
|
| 128 | + $lang = $regs[2]; |
|
| 129 | + $bloc = $regs[3]; |
|
| 130 | + } |
|
| 131 | + $champ->traductions[$lang] = $bloc; |
|
| 132 | + $result[] = $champ; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if ($texte !== '') { |
|
| 136 | + $champ = new Texte(); |
|
| 137 | + $champ->texte = $texte; |
|
| 138 | + $champ->ligne = $ligne; |
|
| 139 | + $result[] = $champ; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $result; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | |
@@ -161,43 +161,43 @@ discard block |
||
| 161 | 161 | * @return array |
| 162 | 162 | **/ |
| 163 | 163 | function phraser_idiomes($texte, $ligne, $result) { |
| 164 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | - $match = array_pad($match, 8, null); |
|
| 166 | - $p = strpos($texte, (string) $match[0]); |
|
| 167 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | - if ($debut) { |
|
| 170 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | - } |
|
| 172 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | - $ligne += substr_count($debut, "\n"); |
|
| 174 | - if ($ko) { |
|
| 175 | - continue; |
|
| 176 | - } // faux idiome |
|
| 177 | - $champ = new Idiome(); |
|
| 178 | - $champ->ligne = $ligne; |
|
| 179 | - $ligne += substr_count($match[0], "\n"); |
|
| 180 | - // Stocker les arguments de la balise de traduction |
|
| 181 | - $args = []; |
|
| 182 | - $largs = $match[5]; |
|
| 183 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | - $largs = substr($largs, strlen($r[0])); |
|
| 186 | - } |
|
| 187 | - $champ->arg = $args; |
|
| 188 | - $champ->nom_champ = strtolower($match[3]); |
|
| 189 | - $champ->module = $match[2]; |
|
| 190 | - // pas d'imbrication pour les filtres sur langue |
|
| 191 | - $pos_apres = 0; |
|
| 192 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | - $result[] = $champ; |
|
| 195 | - } |
|
| 196 | - if ($texte !== '') { |
|
| 197 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $result; |
|
| 164 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 165 | + $match = array_pad($match, 8, null); |
|
| 166 | + $p = strpos($texte, (string) $match[0]); |
|
| 167 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 168 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 169 | + if ($debut) { |
|
| 170 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 171 | + } |
|
| 172 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 173 | + $ligne += substr_count($debut, "\n"); |
|
| 174 | + if ($ko) { |
|
| 175 | + continue; |
|
| 176 | + } // faux idiome |
|
| 177 | + $champ = new Idiome(); |
|
| 178 | + $champ->ligne = $ligne; |
|
| 179 | + $ligne += substr_count($match[0], "\n"); |
|
| 180 | + // Stocker les arguments de la balise de traduction |
|
| 181 | + $args = []; |
|
| 182 | + $largs = $match[5]; |
|
| 183 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 184 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 185 | + $largs = substr($largs, strlen($r[0])); |
|
| 186 | + } |
|
| 187 | + $champ->arg = $args; |
|
| 188 | + $champ->nom_champ = strtolower($match[3]); |
|
| 189 | + $champ->module = $match[2]; |
|
| 190 | + // pas d'imbrication pour les filtres sur langue |
|
| 191 | + $pos_apres = 0; |
|
| 192 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 193 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 194 | + $result[] = $champ; |
|
| 195 | + } |
|
| 196 | + if ($texte !== '') { |
|
| 197 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $result; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -215,47 +215,47 @@ discard block |
||
| 215 | 215 | * @return array |
| 216 | 216 | **/ |
| 217 | 217 | function phraser_champs($texte, $ligne, $result) { |
| 218 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | - $p = strpos($texte, (string) $match[0]); |
|
| 220 | - // texte après la balise |
|
| 221 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | - |
|
| 223 | - $debut = substr($texte, 0, $p); |
|
| 224 | - if ($p) { |
|
| 225 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | - } |
|
| 227 | - $ligne += substr_count($debut, "\n"); |
|
| 228 | - $champ = new Champ(); |
|
| 229 | - $champ->ligne = $ligne; |
|
| 230 | - $ligne += substr_count($match[0], "\n"); |
|
| 231 | - $champ->nom_boucle = $match[2]; |
|
| 232 | - $champ->nom_champ = $match[3]; |
|
| 233 | - $champ->etoile = $match[5]; |
|
| 234 | - |
|
| 235 | - if ($suite and $suite[0] == '{') { |
|
| 236 | - phraser_arg($suite, '', [], $champ); |
|
| 237 | - // ce ltrim est une ereur de conception |
|
| 238 | - // mais on le conserve par souci de compatibilite |
|
| 239 | - $texte = ltrim($suite); |
|
| 240 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 218 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 219 | + $p = strpos($texte, (string) $match[0]); |
|
| 220 | + // texte après la balise |
|
| 221 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 222 | + |
|
| 223 | + $debut = substr($texte, 0, $p); |
|
| 224 | + if ($p) { |
|
| 225 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 226 | + } |
|
| 227 | + $ligne += substr_count($debut, "\n"); |
|
| 228 | + $champ = new Champ(); |
|
| 229 | + $champ->ligne = $ligne; |
|
| 230 | + $ligne += substr_count($match[0], "\n"); |
|
| 231 | + $champ->nom_boucle = $match[2]; |
|
| 232 | + $champ->nom_champ = $match[3]; |
|
| 233 | + $champ->etoile = $match[5]; |
|
| 234 | + |
|
| 235 | + if ($suite and $suite[0] == '{') { |
|
| 236 | + phraser_arg($suite, '', [], $champ); |
|
| 237 | + // ce ltrim est une ereur de conception |
|
| 238 | + // mais on le conserve par souci de compatibilite |
|
| 239 | + $texte = ltrim($suite); |
|
| 240 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 241 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 242 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 243 | 243 | if ($n = (strlen($suite) - strlen($texte))) { |
| 244 | 244 | $champ->apres = array(new Texte); |
| 245 | 245 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 246 | 246 | } |
| 247 | 247 | */ |
| 248 | - } else { |
|
| 249 | - $texte = $suite; |
|
| 250 | - } |
|
| 251 | - phraser_vieux($champ); |
|
| 252 | - $result[] = $champ; |
|
| 253 | - } |
|
| 254 | - if ($texte !== '') { |
|
| 255 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $result; |
|
| 248 | + } else { |
|
| 249 | + $texte = $suite; |
|
| 250 | + } |
|
| 251 | + phraser_vieux($champ); |
|
| 252 | + $result[] = $champ; |
|
| 253 | + } |
|
| 254 | + if ($texte !== '') { |
|
| 255 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $result; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // Gestion des imbrications: |
@@ -264,15 +264,15 @@ discard block |
||
| 264 | 264 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 265 | 265 | |
| 266 | 266 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 267 | - if ($texte === '') { |
|
| 268 | - return $result; |
|
| 269 | - } |
|
| 270 | - $sep = '##'; |
|
| 271 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | - $sep .= '#'; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 267 | + if ($texte === '') { |
|
| 268 | + return $result; |
|
| 269 | + } |
|
| 270 | + $sep = '##'; |
|
| 271 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 272 | + $sep .= '#'; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 276 | 276 | } |
| 277 | 277 | |
| 278 | 278 | /** |
@@ -291,275 +291,275 @@ discard block |
||
| 291 | 291 | * @return array |
| 292 | 292 | */ |
| 293 | 293 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 294 | - $length = strlen($texte); |
|
| 295 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | - $pos_debut++; |
|
| 297 | - } |
|
| 298 | - while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | - $st = substr($texte, $pos_debut); |
|
| 301 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | - $pos_debut = $length - strlen($st); |
|
| 303 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | - $pos_debut++; |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - return $result; |
|
| 294 | + $length = strlen($texte); |
|
| 295 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 296 | + $pos_debut++; |
|
| 297 | + } |
|
| 298 | + while (($pos_debut < $length) && strpos($fin, $texte[$pos_debut]) === false) { |
|
| 299 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 300 | + $st = substr($texte, $pos_debut); |
|
| 301 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 302 | + $pos_debut = $length - strlen($st); |
|
| 303 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | + $pos_debut++; |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + return $result; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 312 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | - $suite = ltrim($match[2]); |
|
| 314 | - $fonc = trim($match[1]); |
|
| 315 | - if ($fonc && $fonc[0] == '|') { |
|
| 316 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | - } |
|
| 318 | - $res = [$fonc]; |
|
| 319 | - $err_f = ''; |
|
| 320 | - // cas du filtre sans argument ou du critere / |
|
| 321 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | - if (!$match[1]) { |
|
| 324 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | - $texte = ''; |
|
| 327 | - } else { |
|
| 328 | - $texte = $suite; |
|
| 329 | - } |
|
| 330 | - if ($err_f) { |
|
| 331 | - $pointeur_champ->param = false; |
|
| 332 | - } elseif ($fonc !== '') { |
|
| 333 | - $pointeur_champ->param[] = $res; |
|
| 334 | - } |
|
| 335 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | - |
|
| 338 | - return $result; |
|
| 339 | - } |
|
| 340 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | - $collecte = []; |
|
| 342 | - while ($args && $args[0] != '}') { |
|
| 343 | - if ($args[0] == '"') { |
|
| 344 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | - } elseif ($args[0] == "'") { |
|
| 346 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | - } else { |
|
| 348 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | - $champ = new Texte(); |
|
| 353 | - $champ->apres = $champ->avant = $args = ''; |
|
| 354 | - break; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - $arg = $regs[2]; |
|
| 358 | - if (trim($regs[1])) { |
|
| 359 | - $champ = new Texte(); |
|
| 360 | - $champ->texte = $arg; |
|
| 361 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | - $result[] = $champ; |
|
| 363 | - $collecte[] = $champ; |
|
| 364 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | - } else { |
|
| 366 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | - // 0 est un aveu d'impuissance. A completer |
|
| 368 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | - |
|
| 370 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | - $collecte = array_merge($collecte, $arg); |
|
| 372 | - $result = array_merge($result, $arg); |
|
| 373 | - } else { |
|
| 374 | - $n = strpos($args, (string) $r[0]); |
|
| 375 | - $pred = substr($args, 0, $n); |
|
| 376 | - $par = ',}'; |
|
| 377 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | - $pred = $m[1]; |
|
| 379 | - $par = ')'; |
|
| 380 | - } |
|
| 381 | - if ($pred) { |
|
| 382 | - $champ = new Texte(); |
|
| 383 | - $champ->texte = $pred; |
|
| 384 | - $champ->apres = $champ->avant = ''; |
|
| 385 | - $result[] = $champ; |
|
| 386 | - $collecte[] = $champ; |
|
| 387 | - } |
|
| 388 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | - $champ = new Champ(); |
|
| 390 | - $champ->nom_boucle = $r[2]; |
|
| 391 | - $champ->nom_champ = $r[3]; |
|
| 392 | - $champ->etoile = $r[5]; |
|
| 393 | - $next = $r[6]; |
|
| 394 | - while ($next == '{') { |
|
| 395 | - phraser_arg($rec, $sep, [], $champ); |
|
| 396 | - $args = ltrim($rec); |
|
| 397 | - $next = $args[0] ?? ''; |
|
| 398 | - } |
|
| 399 | - while ($next == '|') { |
|
| 400 | - $pos_apres = 0; |
|
| 401 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | - $args = substr($rec, $pos_apres); |
|
| 403 | - $next = $args[0] ?? ''; |
|
| 404 | - } |
|
| 405 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | - if ($champ->param === false) { |
|
| 407 | - $err_f = true; |
|
| 408 | - } else { |
|
| 409 | - phraser_vieux($champ); |
|
| 410 | - } |
|
| 411 | - if ($par == ')') { |
|
| 412 | - $args = substr($args, 1); |
|
| 413 | - } |
|
| 414 | - $collecte[] = $champ; |
|
| 415 | - $result[] = $champ; |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | - $args = ltrim(substr($args, 1)); |
|
| 420 | - if ($collecte) { |
|
| 421 | - $res[] = $collecte; |
|
| 422 | - $collecte = []; |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - if ($collecte) { |
|
| 427 | - $res[] = $collecte; |
|
| 428 | - $collecte = []; |
|
| 429 | - } |
|
| 430 | - $texte = substr($args, 1); |
|
| 431 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | - // propager les erreurs, et ignorer les param vides |
|
| 433 | - if ($pointeur_champ->param !== false) { |
|
| 434 | - if ($err_f) { |
|
| 435 | - $pointeur_champ->param = false; |
|
| 436 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | - $pointeur_champ->param[] = $res; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | - |
|
| 443 | - return $result; |
|
| 312 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 313 | + $suite = ltrim($match[2]); |
|
| 314 | + $fonc = trim($match[1]); |
|
| 315 | + if ($fonc && $fonc[0] == '|') { |
|
| 316 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 317 | + } |
|
| 318 | + $res = [$fonc]; |
|
| 319 | + $err_f = ''; |
|
| 320 | + // cas du filtre sans argument ou du critere / |
|
| 321 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 322 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 323 | + if (!$match[1]) { |
|
| 324 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 325 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 326 | + $texte = ''; |
|
| 327 | + } else { |
|
| 328 | + $texte = $suite; |
|
| 329 | + } |
|
| 330 | + if ($err_f) { |
|
| 331 | + $pointeur_champ->param = false; |
|
| 332 | + } elseif ($fonc !== '') { |
|
| 333 | + $pointeur_champ->param[] = $res; |
|
| 334 | + } |
|
| 335 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 336 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 337 | + |
|
| 338 | + return $result; |
|
| 339 | + } |
|
| 340 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 341 | + $collecte = []; |
|
| 342 | + while ($args && $args[0] != '}') { |
|
| 343 | + if ($args[0] == '"') { |
|
| 344 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 345 | + } elseif ($args[0] == "'") { |
|
| 346 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 347 | + } else { |
|
| 348 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 349 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 350 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 351 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 352 | + $champ = new Texte(); |
|
| 353 | + $champ->apres = $champ->avant = $args = ''; |
|
| 354 | + break; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + $arg = $regs[2]; |
|
| 358 | + if (trim($regs[1])) { |
|
| 359 | + $champ = new Texte(); |
|
| 360 | + $champ->texte = $arg; |
|
| 361 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 362 | + $result[] = $champ; |
|
| 363 | + $collecte[] = $champ; |
|
| 364 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 365 | + } else { |
|
| 366 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 367 | + // 0 est un aveu d'impuissance. A completer |
|
| 368 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 369 | + |
|
| 370 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 371 | + $collecte = array_merge($collecte, $arg); |
|
| 372 | + $result = array_merge($result, $arg); |
|
| 373 | + } else { |
|
| 374 | + $n = strpos($args, (string) $r[0]); |
|
| 375 | + $pred = substr($args, 0, $n); |
|
| 376 | + $par = ',}'; |
|
| 377 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 378 | + $pred = $m[1]; |
|
| 379 | + $par = ')'; |
|
| 380 | + } |
|
| 381 | + if ($pred) { |
|
| 382 | + $champ = new Texte(); |
|
| 383 | + $champ->texte = $pred; |
|
| 384 | + $champ->apres = $champ->avant = ''; |
|
| 385 | + $result[] = $champ; |
|
| 386 | + $collecte[] = $champ; |
|
| 387 | + } |
|
| 388 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 389 | + $champ = new Champ(); |
|
| 390 | + $champ->nom_boucle = $r[2]; |
|
| 391 | + $champ->nom_champ = $r[3]; |
|
| 392 | + $champ->etoile = $r[5]; |
|
| 393 | + $next = $r[6]; |
|
| 394 | + while ($next == '{') { |
|
| 395 | + phraser_arg($rec, $sep, [], $champ); |
|
| 396 | + $args = ltrim($rec); |
|
| 397 | + $next = $args[0] ?? ''; |
|
| 398 | + } |
|
| 399 | + while ($next == '|') { |
|
| 400 | + $pos_apres = 0; |
|
| 401 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 402 | + $args = substr($rec, $pos_apres); |
|
| 403 | + $next = $args[0] ?? ''; |
|
| 404 | + } |
|
| 405 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 406 | + if ($champ->param === false) { |
|
| 407 | + $err_f = true; |
|
| 408 | + } else { |
|
| 409 | + phraser_vieux($champ); |
|
| 410 | + } |
|
| 411 | + if ($par == ')') { |
|
| 412 | + $args = substr($args, 1); |
|
| 413 | + } |
|
| 414 | + $collecte[] = $champ; |
|
| 415 | + $result[] = $champ; |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 419 | + $args = ltrim(substr($args, 1)); |
|
| 420 | + if ($collecte) { |
|
| 421 | + $res[] = $collecte; |
|
| 422 | + $collecte = []; |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + if ($collecte) { |
|
| 427 | + $res[] = $collecte; |
|
| 428 | + $collecte = []; |
|
| 429 | + } |
|
| 430 | + $texte = substr($args, 1); |
|
| 431 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 432 | + // propager les erreurs, et ignorer les param vides |
|
| 433 | + if ($pointeur_champ->param !== false) { |
|
| 434 | + if ($err_f) { |
|
| 435 | + $pointeur_champ->param = false; |
|
| 436 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 437 | + $pointeur_champ->param[] = $res; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 441 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 442 | + |
|
| 443 | + return $result; |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | |
| 447 | 447 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 448 | - $res = []; |
|
| 449 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | - break; |
|
| 452 | - } |
|
| 453 | - $debut = substr($texte, 0, $p); |
|
| 454 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | - if ($p) { |
|
| 456 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | - } |
|
| 458 | - $ligne += substr_count($debut, "\n"); |
|
| 459 | - $res[] = $nested[$m[1]]; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 448 | + $res = []; |
|
| 449 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 450 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 451 | + break; |
|
| 452 | + } |
|
| 453 | + $debut = substr($texte, 0, $p); |
|
| 454 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 455 | + if ($p) { |
|
| 456 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 457 | + } |
|
| 458 | + $ligne += substr_count($debut, "\n"); |
|
| 459 | + $res[] = $nested[$m[1]]; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 463 | 463 | } |
| 464 | 464 | |
| 465 | 465 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 466 | - $i = 0; // en fait count($result) |
|
| 467 | - $x = ''; |
|
| 468 | - |
|
| 469 | - while (true) { |
|
| 470 | - $j = $i; |
|
| 471 | - $n = $ligne; |
|
| 472 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | - $p = strpos($texte, (string) $match[0]); |
|
| 474 | - $debut = substr($texte, 0, $p); |
|
| 475 | - if ($p) { |
|
| 476 | - $result[$i] = $debut; |
|
| 477 | - $i++; |
|
| 478 | - } |
|
| 479 | - $nom = $match[4]; |
|
| 480 | - $champ = new Champ(); |
|
| 481 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | - $champ->nom_boucle = $match[3]; |
|
| 484 | - $champ->nom_champ = $nom; |
|
| 485 | - $champ->etoile = $match[6]; |
|
| 486 | - // phraser_args indiquera ou commence apres |
|
| 487 | - $pos_apres = 0; |
|
| 488 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | - phraser_vieux($champ); |
|
| 490 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | - if (!empty($debut)) { |
|
| 493 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | - } |
|
| 495 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | - |
|
| 497 | - // reinjecter la boucle si c'en est une |
|
| 498 | - phraser_boucle_placeholder($champ); |
|
| 499 | - |
|
| 500 | - $result[$i] = $champ; |
|
| 501 | - $i++; |
|
| 502 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | - } |
|
| 504 | - if ($texte !== '') { |
|
| 505 | - $result[$i] = $texte; |
|
| 506 | - $i++; |
|
| 507 | - } |
|
| 508 | - $x = ''; |
|
| 509 | - |
|
| 510 | - while ($j < $i) { |
|
| 511 | - $z = $result[$j]; |
|
| 512 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | - if (is_object($z)) { |
|
| 514 | - $x .= "%$sep$j@"; |
|
| 515 | - } else { |
|
| 516 | - $x .= $z; |
|
| 517 | - } |
|
| 518 | - $j++; |
|
| 519 | - } |
|
| 520 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | - $texte = $x; |
|
| 522 | - } else { |
|
| 523 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | - } |
|
| 525 | - } |
|
| 466 | + $i = 0; // en fait count($result) |
|
| 467 | + $x = ''; |
|
| 468 | + |
|
| 469 | + while (true) { |
|
| 470 | + $j = $i; |
|
| 471 | + $n = $ligne; |
|
| 472 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 473 | + $p = strpos($texte, (string) $match[0]); |
|
| 474 | + $debut = substr($texte, 0, $p); |
|
| 475 | + if ($p) { |
|
| 476 | + $result[$i] = $debut; |
|
| 477 | + $i++; |
|
| 478 | + } |
|
| 479 | + $nom = $match[4]; |
|
| 480 | + $champ = new Champ(); |
|
| 481 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 482 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 483 | + $champ->nom_boucle = $match[3]; |
|
| 484 | + $champ->nom_champ = $nom; |
|
| 485 | + $champ->etoile = $match[6]; |
|
| 486 | + // phraser_args indiquera ou commence apres |
|
| 487 | + $pos_apres = 0; |
|
| 488 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 489 | + phraser_vieux($champ); |
|
| 490 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 491 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 492 | + if (!empty($debut)) { |
|
| 493 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 494 | + } |
|
| 495 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 496 | + |
|
| 497 | + // reinjecter la boucle si c'en est une |
|
| 498 | + phraser_boucle_placeholder($champ); |
|
| 499 | + |
|
| 500 | + $result[$i] = $champ; |
|
| 501 | + $i++; |
|
| 502 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 503 | + } |
|
| 504 | + if ($texte !== '') { |
|
| 505 | + $result[$i] = $texte; |
|
| 506 | + $i++; |
|
| 507 | + } |
|
| 508 | + $x = ''; |
|
| 509 | + |
|
| 510 | + while ($j < $i) { |
|
| 511 | + $z = $result[$j]; |
|
| 512 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 513 | + if (is_object($z)) { |
|
| 514 | + $x .= "%$sep$j@"; |
|
| 515 | + } else { |
|
| 516 | + $x .= $z; |
|
| 517 | + } |
|
| 518 | + $j++; |
|
| 519 | + } |
|
| 520 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 521 | + $texte = $x; |
|
| 522 | + } else { |
|
| 523 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 524 | + } |
|
| 525 | + } |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | function phraser_vieux(&$champ) { |
| 529 | - $nom = $champ->nom_champ; |
|
| 530 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | - include_spip('public/normaliser'); |
|
| 533 | - } |
|
| 534 | - phraser_vieux_emb($champ); |
|
| 535 | - } elseif ($nom == 'EXPOSER') { |
|
| 536 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | - include_spip('public/normaliser'); |
|
| 538 | - } |
|
| 539 | - phraser_vieux_exposer($champ); |
|
| 540 | - } elseif ($champ->param) { |
|
| 541 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | - include_spip('public/normaliser'); |
|
| 544 | - } |
|
| 545 | - phraser_vieux_recherche($champ); |
|
| 546 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | - include_spip('public/normaliser'); |
|
| 549 | - } |
|
| 550 | - phraser_vieux_logos($champ); |
|
| 551 | - } elseif ($nom == 'MODELE') { |
|
| 552 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | - include_spip('public/normaliser'); |
|
| 554 | - } |
|
| 555 | - phraser_vieux_modele($champ); |
|
| 556 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | - include_spip('public/normaliser'); |
|
| 559 | - } |
|
| 560 | - phraser_vieux_inclu($champ); |
|
| 561 | - } |
|
| 562 | - } |
|
| 529 | + $nom = $champ->nom_champ; |
|
| 530 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 531 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 532 | + include_spip('public/normaliser'); |
|
| 533 | + } |
|
| 534 | + phraser_vieux_emb($champ); |
|
| 535 | + } elseif ($nom == 'EXPOSER') { |
|
| 536 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 537 | + include_spip('public/normaliser'); |
|
| 538 | + } |
|
| 539 | + phraser_vieux_exposer($champ); |
|
| 540 | + } elseif ($champ->param) { |
|
| 541 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 542 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 543 | + include_spip('public/normaliser'); |
|
| 544 | + } |
|
| 545 | + phraser_vieux_recherche($champ); |
|
| 546 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 547 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 548 | + include_spip('public/normaliser'); |
|
| 549 | + } |
|
| 550 | + phraser_vieux_logos($champ); |
|
| 551 | + } elseif ($nom == 'MODELE') { |
|
| 552 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 553 | + include_spip('public/normaliser'); |
|
| 554 | + } |
|
| 555 | + phraser_vieux_modele($champ); |
|
| 556 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 557 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 558 | + include_spip('public/normaliser'); |
|
| 559 | + } |
|
| 560 | + phraser_vieux_inclu($champ); |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | 563 | } |
| 564 | 564 | |
| 565 | 565 | |
@@ -587,200 +587,200 @@ discard block |
||
| 587 | 587 | **/ |
| 588 | 588 | function phraser_criteres($params, &$result) { |
| 589 | 589 | |
| 590 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | - $args = []; |
|
| 592 | - $type = $result->type_requete; |
|
| 593 | - $doublons = []; |
|
| 594 | - foreach ($params as $v) { |
|
| 595 | - $var = $v[1][0]; |
|
| 596 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | - // plus d'un argument et pas le critere IN: |
|
| 599 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | - if ( |
|
| 601 | - $var->type != 'texte' |
|
| 602 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | - ) { |
|
| 604 | - $op = ','; |
|
| 605 | - $not = false; |
|
| 606 | - $cond = false; |
|
| 607 | - } else { |
|
| 608 | - // Le debut du premier argument est l'operateur |
|
| 609 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | - $op = $m[2]; |
|
| 611 | - $not = (bool) $m[1]; |
|
| 612 | - $cond = $m[3]; |
|
| 613 | - // virer le premier argument, |
|
| 614 | - // et mettre son reliquat eventuel |
|
| 615 | - // Recopier pour ne pas alterer le texte source |
|
| 616 | - // utile au debusqueur |
|
| 617 | - if ($m[4]) { |
|
| 618 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | - $c = null; |
|
| 621 | - eval('$c = ' . $m[4] . ';'); |
|
| 622 | - if (isset($c)) { |
|
| 623 | - $m[4] = $c; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - $texte = new Texte(); |
|
| 627 | - $texte->texte = $m[4]; |
|
| 628 | - $v[1][0] = $texte; |
|
| 629 | - } else { |
|
| 630 | - array_shift($v[1]); |
|
| 631 | - } |
|
| 632 | - } |
|
| 633 | - array_shift($v); // $v[O] est vide |
|
| 634 | - $crit = new Critere(); |
|
| 635 | - $crit->op = $op; |
|
| 636 | - $crit->not = $not; |
|
| 637 | - $crit->cond = $cond; |
|
| 638 | - $crit->exclus = ''; |
|
| 639 | - $crit->param = $v; |
|
| 640 | - $args[] = $crit; |
|
| 641 | - } else { |
|
| 642 | - if ($var->type != 'texte') { |
|
| 643 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | - // erreur ou critere infixe "/" |
|
| 645 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | - $err_ci = [ |
|
| 647 | - 'zbug_critere_inconnu', |
|
| 648 | - ['critere' => $var->nom_champ] |
|
| 649 | - ]; |
|
| 650 | - erreur_squelette($err_ci, $result); |
|
| 651 | - } else { |
|
| 652 | - $crit = new Critere(); |
|
| 653 | - $crit->op = '/'; |
|
| 654 | - $crit->not = false; |
|
| 655 | - $crit->exclus = ''; |
|
| 656 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | - $args[] = $crit; |
|
| 658 | - } |
|
| 659 | - } else { |
|
| 660 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | - // les separateurs |
|
| 662 | - if ($var->apres) { |
|
| 663 | - $result->separateur[] = $param; |
|
| 664 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | - $result->modificateur['tout'] = true; |
|
| 666 | - } elseif ($param == 'plat') { |
|
| 667 | - $result->modificateur['plat'] = true; |
|
| 668 | - } |
|
| 669 | - |
|
| 670 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | - // ceux-ci pour avoir la rubrique mere... |
|
| 673 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | - // traités normalement. |
|
| 675 | - elseif ( |
|
| 676 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | - ) { |
|
| 680 | - $result->modificateur['tout'] = true; |
|
| 681 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | - // rien a faire sur {id_rubrique} tout seul |
|
| 683 | - } else { |
|
| 684 | - // pas d'emplacement statique, faut un dynamique |
|
| 685 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | - // cette variable sera inseree dans le code |
|
| 688 | - // et son nom sert d'indicateur des maintenant |
|
| 689 | - $result->doublons = '$doublons_index'; |
|
| 690 | - if ($param == 'unique') { |
|
| 691 | - $param = 'doublons'; |
|
| 692 | - } |
|
| 693 | - } elseif ($param == 'recherche') { |
|
| 694 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | - $result->hash = ' '; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | - } elseif ( |
|
| 701 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | - ) { |
|
| 704 | - $a2 = trim($m[8]); |
|
| 705 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | - $a2 = substr($a2, 1, -1); |
|
| 707 | - } |
|
| 708 | - $crit = phraser_critere_infixe( |
|
| 709 | - $m[2], |
|
| 710 | - $a2, |
|
| 711 | - $v, |
|
| 712 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | - $m[6], |
|
| 714 | - $m[5] |
|
| 715 | - ); |
|
| 716 | - $crit->exclus = $m[1]; |
|
| 717 | - } elseif ( |
|
| 718 | - preg_match('/^([!]?)\s*(' . |
|
| 719 | - CHAMP_SQL_PLUS_FONC . |
|
| 720 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | - ) { |
|
| 722 | - // contient aussi les comparaisons implicites ! |
|
| 723 | - // Comme ci-dessus: |
|
| 724 | - // le premier arg contient l'operateur |
|
| 725 | - array_shift($v); |
|
| 726 | - if ($m[6]) { |
|
| 727 | - $v[0][0] = new Texte(); |
|
| 728 | - $v[0][0]->texte = $m[6]; |
|
| 729 | - } else { |
|
| 730 | - array_shift($v[0]); |
|
| 731 | - if (!$v[0]) { |
|
| 732 | - array_shift($v); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - $crit = new Critere(); |
|
| 736 | - $crit->op = $m[2]; |
|
| 737 | - $crit->param = $v; |
|
| 738 | - $crit->not = (bool) $m[1]; |
|
| 739 | - $crit->cond = $m[5]; |
|
| 740 | - } else { |
|
| 741 | - $err_ci = [ |
|
| 742 | - 'zbug_critere_inconnu', |
|
| 743 | - ['critere' => $param] |
|
| 744 | - ]; |
|
| 745 | - erreur_squelette($err_ci, $result); |
|
| 746 | - } |
|
| 747 | - |
|
| 748 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | - $args[] = $crit; |
|
| 750 | - } else { |
|
| 751 | - $doublons[] = $crit; |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - } |
|
| 757 | - |
|
| 758 | - // les doublons non nies doivent etre le dernier critere |
|
| 759 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | - // cf critere_doublon |
|
| 761 | - if ($doublons) { |
|
| 762 | - $args = [...$args, ...$doublons]; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | - if (!$err_ci) { |
|
| 767 | - $result->criteres = $args; |
|
| 768 | - } |
|
| 590 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 591 | + $args = []; |
|
| 592 | + $type = $result->type_requete; |
|
| 593 | + $doublons = []; |
|
| 594 | + foreach ($params as $v) { |
|
| 595 | + $var = $v[1][0]; |
|
| 596 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 597 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 598 | + // plus d'un argument et pas le critere IN: |
|
| 599 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 600 | + if ( |
|
| 601 | + $var->type != 'texte' |
|
| 602 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 603 | + ) { |
|
| 604 | + $op = ','; |
|
| 605 | + $not = false; |
|
| 606 | + $cond = false; |
|
| 607 | + } else { |
|
| 608 | + // Le debut du premier argument est l'operateur |
|
| 609 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 610 | + $op = $m[2]; |
|
| 611 | + $not = (bool) $m[1]; |
|
| 612 | + $cond = $m[3]; |
|
| 613 | + // virer le premier argument, |
|
| 614 | + // et mettre son reliquat eventuel |
|
| 615 | + // Recopier pour ne pas alterer le texte source |
|
| 616 | + // utile au debusqueur |
|
| 617 | + if ($m[4]) { |
|
| 618 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 619 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 620 | + $c = null; |
|
| 621 | + eval('$c = ' . $m[4] . ';'); |
|
| 622 | + if (isset($c)) { |
|
| 623 | + $m[4] = $c; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + $texte = new Texte(); |
|
| 627 | + $texte->texte = $m[4]; |
|
| 628 | + $v[1][0] = $texte; |
|
| 629 | + } else { |
|
| 630 | + array_shift($v[1]); |
|
| 631 | + } |
|
| 632 | + } |
|
| 633 | + array_shift($v); // $v[O] est vide |
|
| 634 | + $crit = new Critere(); |
|
| 635 | + $crit->op = $op; |
|
| 636 | + $crit->not = $not; |
|
| 637 | + $crit->cond = $cond; |
|
| 638 | + $crit->exclus = ''; |
|
| 639 | + $crit->param = $v; |
|
| 640 | + $args[] = $crit; |
|
| 641 | + } else { |
|
| 642 | + if ($var->type != 'texte') { |
|
| 643 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 644 | + // erreur ou critere infixe "/" |
|
| 645 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 646 | + $err_ci = [ |
|
| 647 | + 'zbug_critere_inconnu', |
|
| 648 | + ['critere' => $var->nom_champ] |
|
| 649 | + ]; |
|
| 650 | + erreur_squelette($err_ci, $result); |
|
| 651 | + } else { |
|
| 652 | + $crit = new Critere(); |
|
| 653 | + $crit->op = '/'; |
|
| 654 | + $crit->not = false; |
|
| 655 | + $crit->exclus = ''; |
|
| 656 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 657 | + $args[] = $crit; |
|
| 658 | + } |
|
| 659 | + } else { |
|
| 660 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 661 | + // les separateurs |
|
| 662 | + if ($var->apres) { |
|
| 663 | + $result->separateur[] = $param; |
|
| 664 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 665 | + $result->modificateur['tout'] = true; |
|
| 666 | + } elseif ($param == 'plat') { |
|
| 667 | + $result->modificateur['plat'] = true; |
|
| 668 | + } |
|
| 669 | + |
|
| 670 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 671 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 672 | + // ceux-ci pour avoir la rubrique mere... |
|
| 673 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 674 | + // traités normalement. |
|
| 675 | + elseif ( |
|
| 676 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 677 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 678 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 679 | + ) { |
|
| 680 | + $result->modificateur['tout'] = true; |
|
| 681 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 682 | + // rien a faire sur {id_rubrique} tout seul |
|
| 683 | + } else { |
|
| 684 | + // pas d'emplacement statique, faut un dynamique |
|
| 685 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 686 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 687 | + // cette variable sera inseree dans le code |
|
| 688 | + // et son nom sert d'indicateur des maintenant |
|
| 689 | + $result->doublons = '$doublons_index'; |
|
| 690 | + if ($param == 'unique') { |
|
| 691 | + $param = 'doublons'; |
|
| 692 | + } |
|
| 693 | + } elseif ($param == 'recherche') { |
|
| 694 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 695 | + $result->hash = ' '; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 699 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 700 | + } elseif ( |
|
| 701 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 702 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 703 | + ) { |
|
| 704 | + $a2 = trim($m[8]); |
|
| 705 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 706 | + $a2 = substr($a2, 1, -1); |
|
| 707 | + } |
|
| 708 | + $crit = phraser_critere_infixe( |
|
| 709 | + $m[2], |
|
| 710 | + $a2, |
|
| 711 | + $v, |
|
| 712 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 713 | + $m[6], |
|
| 714 | + $m[5] |
|
| 715 | + ); |
|
| 716 | + $crit->exclus = $m[1]; |
|
| 717 | + } elseif ( |
|
| 718 | + preg_match('/^([!]?)\s*(' . |
|
| 719 | + CHAMP_SQL_PLUS_FONC . |
|
| 720 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 721 | + ) { |
|
| 722 | + // contient aussi les comparaisons implicites ! |
|
| 723 | + // Comme ci-dessus: |
|
| 724 | + // le premier arg contient l'operateur |
|
| 725 | + array_shift($v); |
|
| 726 | + if ($m[6]) { |
|
| 727 | + $v[0][0] = new Texte(); |
|
| 728 | + $v[0][0]->texte = $m[6]; |
|
| 729 | + } else { |
|
| 730 | + array_shift($v[0]); |
|
| 731 | + if (!$v[0]) { |
|
| 732 | + array_shift($v); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + $crit = new Critere(); |
|
| 736 | + $crit->op = $m[2]; |
|
| 737 | + $crit->param = $v; |
|
| 738 | + $crit->not = (bool) $m[1]; |
|
| 739 | + $crit->cond = $m[5]; |
|
| 740 | + } else { |
|
| 741 | + $err_ci = [ |
|
| 742 | + 'zbug_critere_inconnu', |
|
| 743 | + ['critere' => $param] |
|
| 744 | + ]; |
|
| 745 | + erreur_squelette($err_ci, $result); |
|
| 746 | + } |
|
| 747 | + |
|
| 748 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 749 | + $args[] = $crit; |
|
| 750 | + } else { |
|
| 751 | + $doublons[] = $crit; |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + } |
|
| 757 | + |
|
| 758 | + // les doublons non nies doivent etre le dernier critere |
|
| 759 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 760 | + // cf critere_doublon |
|
| 761 | + if ($doublons) { |
|
| 762 | + $args = [...$args, ...$doublons]; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 766 | + if (!$err_ci) { |
|
| 767 | + $result->criteres = $args; |
|
| 768 | + } |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 772 | - $args[0] = new Texte(); |
|
| 773 | - $args[0]->texte = $arg1; |
|
| 774 | - $args[0] = [$args[0]]; |
|
| 775 | - $args[1][0] = new Texte(); |
|
| 776 | - $args[1][0]->texte = $arg2; |
|
| 777 | - $crit = new Critere(); |
|
| 778 | - $crit->op = $op; |
|
| 779 | - $crit->not = $not; |
|
| 780 | - $crit->cond = $cond; |
|
| 781 | - $crit->param = $args; |
|
| 782 | - |
|
| 783 | - return $crit; |
|
| 772 | + $args[0] = new Texte(); |
|
| 773 | + $args[0]->texte = $arg1; |
|
| 774 | + $args[0] = [$args[0]]; |
|
| 775 | + $args[1][0] = new Texte(); |
|
| 776 | + $args[1][0]->texte = $arg2; |
|
| 777 | + $crit = new Critere(); |
|
| 778 | + $crit->op = $op; |
|
| 779 | + $crit->not = $not; |
|
| 780 | + $crit->cond = $cond; |
|
| 781 | + $crit->param = $args; |
|
| 782 | + |
|
| 783 | + return $crit; |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | /** |
@@ -791,12 +791,12 @@ discard block |
||
| 791 | 791 | * @return int |
| 792 | 792 | */ |
| 793 | 793 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 794 | - if (is_null($fin)) { |
|
| 795 | - return substr_count($texte, "\n", $debut); |
|
| 796 | - } |
|
| 797 | - else { |
|
| 798 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | - } |
|
| 794 | + if (is_null($fin)) { |
|
| 795 | + return substr_count($texte, "\n", $debut); |
|
| 796 | + } |
|
| 797 | + else { |
|
| 798 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 799 | + } |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | |
@@ -812,87 +812,87 @@ discard block |
||
| 812 | 812 | * @return array|null |
| 813 | 813 | */ |
| 814 | 814 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 815 | - $premiere_boucle = null; |
|
| 816 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | - |
|
| 818 | - $current_pos = $pos_debut_texte; |
|
| 819 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | - $current_pos = $pos_boucle + 1; |
|
| 821 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | - |
|
| 823 | - $id_boucle = ''; |
|
| 824 | - if ($pos_parent !== false) { |
|
| 825 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | - } |
|
| 827 | - if ( |
|
| 828 | - $pos_parent === false |
|
| 829 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | - ) { |
|
| 831 | - $result = new Boucle(); |
|
| 832 | - $result->id_parent = $id_parent; |
|
| 833 | - $result->descr = $descr; |
|
| 834 | - |
|
| 835 | - // un id_boucle pour l'affichage de l'erreur |
|
| 836 | - if (!strlen($id_boucle)) { |
|
| 837 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | - } |
|
| 839 | - $result->id_boucle = $id_boucle; |
|
| 840 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | - erreur_squelette($err_b, $result); |
|
| 842 | - |
|
| 843 | - continue; |
|
| 844 | - } |
|
| 845 | - else { |
|
| 846 | - $boucle = [ |
|
| 847 | - 'id_boucle' => $id_boucle, |
|
| 848 | - 'id_boucle_err' => $id_boucle, |
|
| 849 | - 'debut_boucle' => $pos_boucle, |
|
| 850 | - 'pos_boucle' => $pos_boucle, |
|
| 851 | - 'pos_parent' => $pos_parent, |
|
| 852 | - 'pos_precond' => false, |
|
| 853 | - 'pos_precond_inside' => false, |
|
| 854 | - 'pos_preaff' => false, |
|
| 855 | - 'pos_preaff_inside' => false, |
|
| 856 | - ]; |
|
| 857 | - |
|
| 858 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | - if (!strlen($id_boucle)) { |
|
| 860 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | - if ( |
|
| 867 | - $pos_precond !== false |
|
| 868 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | - ) { |
|
| 870 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | - $boucle['pos_precond'] = $pos_precond; |
|
| 872 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | - } |
|
| 874 | - |
|
| 875 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | - if ( |
|
| 878 | - $pos_preaff !== false |
|
| 879 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | - ) { |
|
| 881 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | - } |
|
| 885 | - if (!strlen($id_boucle)) { |
|
| 886 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | - } |
|
| 888 | - |
|
| 889 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | - $premiere_boucle = $boucle; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - } |
|
| 894 | - |
|
| 895 | - return $premiere_boucle; |
|
| 815 | + $premiere_boucle = null; |
|
| 816 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 817 | + |
|
| 818 | + $current_pos = $pos_debut_texte; |
|
| 819 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 820 | + $current_pos = $pos_boucle + 1; |
|
| 821 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 822 | + |
|
| 823 | + $id_boucle = ''; |
|
| 824 | + if ($pos_parent !== false) { |
|
| 825 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 826 | + } |
|
| 827 | + if ( |
|
| 828 | + $pos_parent === false |
|
| 829 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 830 | + ) { |
|
| 831 | + $result = new Boucle(); |
|
| 832 | + $result->id_parent = $id_parent; |
|
| 833 | + $result->descr = $descr; |
|
| 834 | + |
|
| 835 | + // un id_boucle pour l'affichage de l'erreur |
|
| 836 | + if (!strlen($id_boucle)) { |
|
| 837 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 838 | + } |
|
| 839 | + $result->id_boucle = $id_boucle; |
|
| 840 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 841 | + erreur_squelette($err_b, $result); |
|
| 842 | + |
|
| 843 | + continue; |
|
| 844 | + } |
|
| 845 | + else { |
|
| 846 | + $boucle = [ |
|
| 847 | + 'id_boucle' => $id_boucle, |
|
| 848 | + 'id_boucle_err' => $id_boucle, |
|
| 849 | + 'debut_boucle' => $pos_boucle, |
|
| 850 | + 'pos_boucle' => $pos_boucle, |
|
| 851 | + 'pos_parent' => $pos_parent, |
|
| 852 | + 'pos_precond' => false, |
|
| 853 | + 'pos_precond_inside' => false, |
|
| 854 | + 'pos_preaff' => false, |
|
| 855 | + 'pos_preaff_inside' => false, |
|
| 856 | + ]; |
|
| 857 | + |
|
| 858 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 859 | + if (!strlen($id_boucle)) { |
|
| 860 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 864 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 865 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 866 | + if ( |
|
| 867 | + $pos_precond !== false |
|
| 868 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 869 | + ) { |
|
| 870 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 871 | + $boucle['pos_precond'] = $pos_precond; |
|
| 872 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 873 | + } |
|
| 874 | + |
|
| 875 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 876 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 877 | + if ( |
|
| 878 | + $pos_preaff !== false |
|
| 879 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 880 | + ) { |
|
| 881 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 882 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 883 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 884 | + } |
|
| 885 | + if (!strlen($id_boucle)) { |
|
| 886 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 887 | + } |
|
| 888 | + |
|
| 889 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 890 | + $premiere_boucle = $boucle; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + } |
|
| 894 | + |
|
| 895 | + return $premiere_boucle; |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -907,68 +907,68 @@ discard block |
||
| 907 | 907 | * @return mixed |
| 908 | 908 | */ |
| 909 | 909 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 910 | - $id_boucle = $boucle['id_boucle']; |
|
| 911 | - $pos_courante = $pos_debut_texte; |
|
| 912 | - |
|
| 913 | - $boucle['pos_postcond'] = false; |
|
| 914 | - $boucle['pos_postcond_inside'] = false; |
|
| 915 | - $boucle['pos_altern'] = false; |
|
| 916 | - $boucle['pos_altern_inside'] = false; |
|
| 917 | - $boucle['pos_postaff'] = false; |
|
| 918 | - $boucle['pos_postaff_inside'] = false; |
|
| 919 | - |
|
| 920 | - $pos_anonyme_next = null; |
|
| 921 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | - if (!strlen($id_boucle)) { |
|
| 923 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - // |
|
| 927 | - // 1. Recuperer la partie conditionnelle apres |
|
| 928 | - // |
|
| 929 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | - if ( |
|
| 932 | - $pos_apres !== false |
|
| 933 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | - ) { |
|
| 935 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | - $pos_apres += strlen($apres_boucle); |
|
| 937 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | - $pos_courante = $pos_apres ; |
|
| 939 | - } |
|
| 940 | - |
|
| 941 | - // |
|
| 942 | - // 2. Récuperer la partie alternative apres |
|
| 943 | - // |
|
| 944 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | - if ( |
|
| 947 | - $pos_altern !== false |
|
| 948 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | - ) { |
|
| 950 | - $boucle['pos_altern'] = $pos_altern; |
|
| 951 | - $pos_altern += strlen($altern_boucle); |
|
| 952 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | - $pos_courante = $pos_altern; |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - // |
|
| 957 | - // 3. Recuperer la partie footer non alternative |
|
| 958 | - // |
|
| 959 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | - if ( |
|
| 962 | - $pos_postaff !== false |
|
| 963 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | - ) { |
|
| 965 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | - $pos_postaff += strlen($postaff_boucle); |
|
| 967 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | - $pos_courante = $pos_postaff ; |
|
| 969 | - } |
|
| 970 | - |
|
| 971 | - return $boucle; |
|
| 910 | + $id_boucle = $boucle['id_boucle']; |
|
| 911 | + $pos_courante = $pos_debut_texte; |
|
| 912 | + |
|
| 913 | + $boucle['pos_postcond'] = false; |
|
| 914 | + $boucle['pos_postcond_inside'] = false; |
|
| 915 | + $boucle['pos_altern'] = false; |
|
| 916 | + $boucle['pos_altern_inside'] = false; |
|
| 917 | + $boucle['pos_postaff'] = false; |
|
| 918 | + $boucle['pos_postaff_inside'] = false; |
|
| 919 | + |
|
| 920 | + $pos_anonyme_next = null; |
|
| 921 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 922 | + if (!strlen($id_boucle)) { |
|
| 923 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + // |
|
| 927 | + // 1. Recuperer la partie conditionnelle apres |
|
| 928 | + // |
|
| 929 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 930 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 931 | + if ( |
|
| 932 | + $pos_apres !== false |
|
| 933 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 934 | + ) { |
|
| 935 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 936 | + $pos_apres += strlen($apres_boucle); |
|
| 937 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 938 | + $pos_courante = $pos_apres ; |
|
| 939 | + } |
|
| 940 | + |
|
| 941 | + // |
|
| 942 | + // 2. Récuperer la partie alternative apres |
|
| 943 | + // |
|
| 944 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 945 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 946 | + if ( |
|
| 947 | + $pos_altern !== false |
|
| 948 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 949 | + ) { |
|
| 950 | + $boucle['pos_altern'] = $pos_altern; |
|
| 951 | + $pos_altern += strlen($altern_boucle); |
|
| 952 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 953 | + $pos_courante = $pos_altern; |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + // |
|
| 957 | + // 3. Recuperer la partie footer non alternative |
|
| 958 | + // |
|
| 959 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 960 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 961 | + if ( |
|
| 962 | + $pos_postaff !== false |
|
| 963 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 964 | + ) { |
|
| 965 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 966 | + $pos_postaff += strlen($postaff_boucle); |
|
| 967 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 968 | + $pos_courante = $pos_postaff ; |
|
| 969 | + } |
|
| 970 | + |
|
| 971 | + return $boucle; |
|
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | |
@@ -978,21 +978,21 @@ discard block |
||
| 978 | 978 | * @param null|object $boucle |
| 979 | 979 | */ |
| 980 | 980 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 981 | - static $boucles_connues = []; |
|
| 982 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | - } |
|
| 986 | - else { |
|
| 987 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | - $placeholder = $champ->nom_champ; |
|
| 989 | - $id = reset($champ->param[0][1]); |
|
| 990 | - $id = $id->texte; |
|
| 991 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 981 | + static $boucles_connues = []; |
|
| 982 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 983 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 984 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 985 | + } |
|
| 986 | + else { |
|
| 987 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 988 | + $placeholder = $champ->nom_champ; |
|
| 989 | + $id = reset($champ->param[0][1]); |
|
| 990 | + $id = $id->texte; |
|
| 991 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 992 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | 996 | } |
| 997 | 997 | |
| 998 | 998 | |
@@ -1005,274 +1005,274 @@ discard block |
||
| 1005 | 1005 | * @return string |
| 1006 | 1006 | */ |
| 1007 | 1007 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1008 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | - //memoriser la boucle a reinjecter |
|
| 1010 | - $id_boucle = "$id_boucle"; |
|
| 1011 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | - return $placeholder; |
|
| 1008 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1009 | + //memoriser la boucle a reinjecter |
|
| 1010 | + $id_boucle = "$id_boucle"; |
|
| 1011 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1012 | + return $placeholder; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1016 | 1016 | |
| 1017 | - $all_res = []; |
|
| 1018 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | - if (is_null($boucle_placeholder)) { |
|
| 1020 | - do { |
|
| 1021 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | - $pos_debut_texte = 0; |
|
| 1027 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | - $result = new Boucle(); |
|
| 1030 | - $result->id_parent = $id_parent; |
|
| 1031 | - $result->descr = $descr; |
|
| 1032 | - |
|
| 1033 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | - $pos_parent = $boucle['pos_parent']; |
|
| 1035 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | - |
|
| 1037 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | - |
|
| 1039 | - // boucle anonyme ? |
|
| 1040 | - if (!strlen($id_boucle)) { |
|
| 1041 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - $pos_debut_boucle = $pos_courante; |
|
| 1045 | - |
|
| 1046 | - $pos_milieu = $pos_parent; |
|
| 1047 | - |
|
| 1048 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | - if ($boucle['pos_precond'] !== false) { |
|
| 1050 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | - |
|
| 1052 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | - $end_preaff = $pos_debut_boucle; |
|
| 1060 | - |
|
| 1061 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - $result->id_boucle = $id_boucle; |
|
| 1067 | - |
|
| 1068 | - if ( |
|
| 1069 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | - or $pos_match > $pos_milieu |
|
| 1072 | - ) { |
|
| 1073 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | - erreur_squelette($err_b, $result); |
|
| 1075 | - |
|
| 1076 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | - continue; |
|
| 1079 | - } |
|
| 1080 | - |
|
| 1081 | - $result->type_requete = $match[0]; |
|
| 1082 | - $pos_milieu += strlen($match[0]); |
|
| 1083 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | - |
|
| 1085 | - $type = $match[1]; |
|
| 1086 | - $jointures = trim($match[2]); |
|
| 1087 | - $table_optionnelle = ($match[3]); |
|
| 1088 | - if ($jointures) { |
|
| 1089 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | - // ou elles seront completees des jointures declarees |
|
| 1091 | - $result->jointures_explicites = $jointures; |
|
| 1092 | - } |
|
| 1093 | - |
|
| 1094 | - if ($table_optionnelle) { |
|
| 1095 | - $result->table_optionnelle = $type; |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | - // Resultat mis dans result->param |
|
| 1100 | - $pos_fin_criteres = $pos_milieu; |
|
| 1101 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | - |
|
| 1103 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | - // pour l'instant on met le source (chaine) : |
|
| 1105 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | - $pos_milieu = $pos_fin_criteres; |
|
| 1109 | - |
|
| 1110 | - // |
|
| 1111 | - // Recuperer la fin : |
|
| 1112 | - // |
|
| 1113 | - if ($texte[$pos_milieu] === '/') { |
|
| 1114 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | - $pos_courante += 2; |
|
| 1116 | - $result->milieu = ''; |
|
| 1117 | - } else { |
|
| 1118 | - $pos_milieu += 1; |
|
| 1119 | - |
|
| 1120 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | - if ($pos_fin === false) { |
|
| 1123 | - $err_b = [ |
|
| 1124 | - 'zbug_erreur_boucle_fermant', |
|
| 1125 | - ['id' => $id_boucle] |
|
| 1126 | - ]; |
|
| 1127 | - erreur_squelette($err_b, $result); |
|
| 1128 | - $pos_courante += strlen($fin_boucle); |
|
| 1129 | - } |
|
| 1130 | - else { |
|
| 1131 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | - $search_from = $pos_milieu; |
|
| 1135 | - $nb_open = 1; |
|
| 1136 | - $nb_close = 1; |
|
| 1137 | - $maxiter = 0; |
|
| 1138 | - do { |
|
| 1139 | - while ( |
|
| 1140 | - $nb_close < $nb_open |
|
| 1141 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | - ) { |
|
| 1143 | - $nb_close++; |
|
| 1144 | - $pos_fin = $p; |
|
| 1145 | - } |
|
| 1146 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | - if ($nb_close < $nb_open) { |
|
| 1148 | - break; |
|
| 1149 | - } |
|
| 1150 | - while ( |
|
| 1151 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | - and $p < $pos_fin |
|
| 1153 | - ) { |
|
| 1154 | - $nb_open++; |
|
| 1155 | - $search_from = $p + 1; |
|
| 1156 | - } |
|
| 1157 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | - |
|
| 1159 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | - } |
|
| 1161 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | - |
|
| 1167 | - // |
|
| 1168 | - // 1. Partie conditionnelle apres ? |
|
| 1169 | - // |
|
| 1170 | - if ($boucle['pos_postcond']) { |
|
| 1171 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | - } |
|
| 1175 | - |
|
| 1176 | - |
|
| 1177 | - // |
|
| 1178 | - // 2. Partie alternative apres ? |
|
| 1179 | - // |
|
| 1180 | - $ligne_altern = $ligne_suite; |
|
| 1181 | - if ($boucle['pos_altern']) { |
|
| 1182 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | - } |
|
| 1186 | - |
|
| 1187 | - // |
|
| 1188 | - // 3. Partie footer non alternative ? |
|
| 1189 | - // |
|
| 1190 | - $ligne_postaff = $ligne_suite; |
|
| 1191 | - if ($boucle['pos_postaff']) { |
|
| 1192 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | - } |
|
| 1196 | - |
|
| 1197 | - $result->ligne = $ligne_preaff; |
|
| 1198 | - |
|
| 1199 | - if ($p = strpos($type, ':')) { |
|
| 1200 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | - $type = substr($type, $p + 1); |
|
| 1202 | - } |
|
| 1203 | - $soustype = strtolower($type); |
|
| 1204 | - |
|
| 1205 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | - $soustype = $type; |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - $result->type_requete = $soustype; |
|
| 1210 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | - if (!is_array($result->param)) { |
|
| 1212 | - $err_b = true; |
|
| 1213 | - } else { |
|
| 1214 | - phraser_criteres($result->param, $result); |
|
| 1215 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | - $args = $result->param; |
|
| 1218 | - array_unshift( |
|
| 1219 | - $args, |
|
| 1220 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | - ); |
|
| 1222 | - $result->param = $args; |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1225 | - |
|
| 1226 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | - if (empty($boucles[$id_boucle])) { |
|
| 1232 | - $boucles[$id_boucle] = null; |
|
| 1233 | - } |
|
| 1234 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | - |
|
| 1240 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | - if ($err_b) { |
|
| 1242 | - $result->type_requete = false; |
|
| 1243 | - } |
|
| 1244 | - |
|
| 1245 | - // Verifier qu'il n'y a pas double definition |
|
| 1246 | - // apres analyse des sous-parties (pas avant). |
|
| 1247 | - if (!empty($boucles[$id_boucle])) { |
|
| 1248 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | - $err_b_d = [ |
|
| 1250 | - 'zbug_erreur_boucle_double', |
|
| 1251 | - ['id' => $id_boucle] |
|
| 1252 | - ]; |
|
| 1253 | - erreur_squelette($err_b_d, $result); |
|
| 1254 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | - } |
|
| 1257 | - } else { |
|
| 1258 | - $boucles[$id_boucle] = $result; |
|
| 1259 | - } |
|
| 1260 | - |
|
| 1261 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | - |
|
| 1267 | - // phraser la partie avant le debut de la boucle |
|
| 1268 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | - |
|
| 1271 | - $ligne_debut_texte = $ligne_suite; |
|
| 1272 | - $pos_debut_texte = $pos_courante; |
|
| 1273 | - } |
|
| 1274 | - |
|
| 1275 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | - |
|
| 1277 | - return $all_res; |
|
| 1017 | + $all_res = []; |
|
| 1018 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1019 | + if (is_null($boucle_placeholder)) { |
|
| 1020 | + do { |
|
| 1021 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1022 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1026 | + $pos_debut_texte = 0; |
|
| 1027 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1028 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1029 | + $result = new Boucle(); |
|
| 1030 | + $result->id_parent = $id_parent; |
|
| 1031 | + $result->descr = $descr; |
|
| 1032 | + |
|
| 1033 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1034 | + $pos_parent = $boucle['pos_parent']; |
|
| 1035 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1036 | + |
|
| 1037 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1038 | + |
|
| 1039 | + // boucle anonyme ? |
|
| 1040 | + if (!strlen($id_boucle)) { |
|
| 1041 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + $pos_debut_boucle = $pos_courante; |
|
| 1045 | + |
|
| 1046 | + $pos_milieu = $pos_parent; |
|
| 1047 | + |
|
| 1048 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1049 | + if ($boucle['pos_precond'] !== false) { |
|
| 1050 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1051 | + |
|
| 1052 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1053 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1054 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1058 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1059 | + $end_preaff = $pos_debut_boucle; |
|
| 1060 | + |
|
| 1061 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1062 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1063 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + $result->id_boucle = $id_boucle; |
|
| 1067 | + |
|
| 1068 | + if ( |
|
| 1069 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1070 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1071 | + or $pos_match > $pos_milieu |
|
| 1072 | + ) { |
|
| 1073 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1074 | + erreur_squelette($err_b, $result); |
|
| 1075 | + |
|
| 1076 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1077 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1078 | + continue; |
|
| 1079 | + } |
|
| 1080 | + |
|
| 1081 | + $result->type_requete = $match[0]; |
|
| 1082 | + $pos_milieu += strlen($match[0]); |
|
| 1083 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1084 | + |
|
| 1085 | + $type = $match[1]; |
|
| 1086 | + $jointures = trim($match[2]); |
|
| 1087 | + $table_optionnelle = ($match[3]); |
|
| 1088 | + if ($jointures) { |
|
| 1089 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1090 | + // ou elles seront completees des jointures declarees |
|
| 1091 | + $result->jointures_explicites = $jointures; |
|
| 1092 | + } |
|
| 1093 | + |
|
| 1094 | + if ($table_optionnelle) { |
|
| 1095 | + $result->table_optionnelle = $type; |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1099 | + // Resultat mis dans result->param |
|
| 1100 | + $pos_fin_criteres = $pos_milieu; |
|
| 1101 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1102 | + |
|
| 1103 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1104 | + // pour l'instant on met le source (chaine) : |
|
| 1105 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1106 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1107 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1108 | + $pos_milieu = $pos_fin_criteres; |
|
| 1109 | + |
|
| 1110 | + // |
|
| 1111 | + // Recuperer la fin : |
|
| 1112 | + // |
|
| 1113 | + if ($texte[$pos_milieu] === '/') { |
|
| 1114 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1115 | + $pos_courante += 2; |
|
| 1116 | + $result->milieu = ''; |
|
| 1117 | + } else { |
|
| 1118 | + $pos_milieu += 1; |
|
| 1119 | + |
|
| 1120 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1121 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1122 | + if ($pos_fin === false) { |
|
| 1123 | + $err_b = [ |
|
| 1124 | + 'zbug_erreur_boucle_fermant', |
|
| 1125 | + ['id' => $id_boucle] |
|
| 1126 | + ]; |
|
| 1127 | + erreur_squelette($err_b, $result); |
|
| 1128 | + $pos_courante += strlen($fin_boucle); |
|
| 1129 | + } |
|
| 1130 | + else { |
|
| 1131 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1132 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1133 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1134 | + $search_from = $pos_milieu; |
|
| 1135 | + $nb_open = 1; |
|
| 1136 | + $nb_close = 1; |
|
| 1137 | + $maxiter = 0; |
|
| 1138 | + do { |
|
| 1139 | + while ( |
|
| 1140 | + $nb_close < $nb_open |
|
| 1141 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1142 | + ) { |
|
| 1143 | + $nb_close++; |
|
| 1144 | + $pos_fin = $p; |
|
| 1145 | + } |
|
| 1146 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1147 | + if ($nb_close < $nb_open) { |
|
| 1148 | + break; |
|
| 1149 | + } |
|
| 1150 | + while ( |
|
| 1151 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1152 | + and $p < $pos_fin |
|
| 1153 | + ) { |
|
| 1154 | + $nb_open++; |
|
| 1155 | + $search_from = $p + 1; |
|
| 1156 | + } |
|
| 1157 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1158 | + |
|
| 1159 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1160 | + } |
|
| 1161 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1165 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1166 | + |
|
| 1167 | + // |
|
| 1168 | + // 1. Partie conditionnelle apres ? |
|
| 1169 | + // |
|
| 1170 | + if ($boucle['pos_postcond']) { |
|
| 1171 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1172 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1173 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1174 | + } |
|
| 1175 | + |
|
| 1176 | + |
|
| 1177 | + // |
|
| 1178 | + // 2. Partie alternative apres ? |
|
| 1179 | + // |
|
| 1180 | + $ligne_altern = $ligne_suite; |
|
| 1181 | + if ($boucle['pos_altern']) { |
|
| 1182 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1183 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1184 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1185 | + } |
|
| 1186 | + |
|
| 1187 | + // |
|
| 1188 | + // 3. Partie footer non alternative ? |
|
| 1189 | + // |
|
| 1190 | + $ligne_postaff = $ligne_suite; |
|
| 1191 | + if ($boucle['pos_postaff']) { |
|
| 1192 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1193 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1194 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1195 | + } |
|
| 1196 | + |
|
| 1197 | + $result->ligne = $ligne_preaff; |
|
| 1198 | + |
|
| 1199 | + if ($p = strpos($type, ':')) { |
|
| 1200 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1201 | + $type = substr($type, $p + 1); |
|
| 1202 | + } |
|
| 1203 | + $soustype = strtolower($type); |
|
| 1204 | + |
|
| 1205 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1206 | + $soustype = $type; |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + $result->type_requete = $soustype; |
|
| 1210 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1211 | + if (!is_array($result->param)) { |
|
| 1212 | + $err_b = true; |
|
| 1213 | + } else { |
|
| 1214 | + phraser_criteres($result->param, $result); |
|
| 1215 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1216 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1217 | + $args = $result->param; |
|
| 1218 | + array_unshift( |
|
| 1219 | + $args, |
|
| 1220 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1221 | + ); |
|
| 1222 | + $result->param = $args; |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | + |
|
| 1226 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1227 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1228 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1229 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1230 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1231 | + if (empty($boucles[$id_boucle])) { |
|
| 1232 | + $boucles[$id_boucle] = null; |
|
| 1233 | + } |
|
| 1234 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1235 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1236 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1237 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1238 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1239 | + |
|
| 1240 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1241 | + if ($err_b) { |
|
| 1242 | + $result->type_requete = false; |
|
| 1243 | + } |
|
| 1244 | + |
|
| 1245 | + // Verifier qu'il n'y a pas double definition |
|
| 1246 | + // apres analyse des sous-parties (pas avant). |
|
| 1247 | + if (!empty($boucles[$id_boucle])) { |
|
| 1248 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1249 | + $err_b_d = [ |
|
| 1250 | + 'zbug_erreur_boucle_double', |
|
| 1251 | + ['id' => $id_boucle] |
|
| 1252 | + ]; |
|
| 1253 | + erreur_squelette($err_b_d, $result); |
|
| 1254 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1255 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1256 | + } |
|
| 1257 | + } else { |
|
| 1258 | + $boucles[$id_boucle] = $result; |
|
| 1259 | + } |
|
| 1260 | + |
|
| 1261 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1262 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1263 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1264 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1265 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1266 | + |
|
| 1267 | + // phraser la partie avant le debut de la boucle |
|
| 1268 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1269 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1270 | + |
|
| 1271 | + $ligne_debut_texte = $ligne_suite; |
|
| 1272 | + $pos_debut_texte = $pos_courante; |
|
| 1273 | + } |
|
| 1274 | + |
|
| 1275 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1276 | + |
|
| 1277 | + return $all_res; |
|
| 1278 | 1278 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -23,322 +23,322 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | class ValidateurXML { |
| 25 | 25 | |
| 26 | - public function validerElement($phraseur, $name, $attrs) { |
|
| 27 | - if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 28 | - if ($p = strpos($name, ':')) { |
|
| 29 | - $name = substr($name, $p + 1); |
|
| 30 | - $p = isset($this->dtc->elements[$name]); |
|
| 31 | - } |
|
| 32 | - if (!$p) { |
|
| 33 | - coordonnees_erreur($this, " <b>$name</b> : " |
|
| 34 | - . _T('zxml_inconnu_balise')); |
|
| 35 | - |
|
| 36 | - return; |
|
| 37 | - } |
|
| 38 | - } |
|
| 39 | - // controler les filles illegitimes, ca suffit |
|
| 40 | - $depth = $this->depth; |
|
| 41 | - $ouvrant = $this->ouvrant; |
|
| 42 | - #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 43 | - if (isset($ouvrant[$depth])) { |
|
| 44 | - if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 45 | - $pere = $r[1]; |
|
| 46 | - #spip_log("pere $pere"); |
|
| 47 | - if (isset($this->dtc->elements[$pere])) { |
|
| 48 | - $fils = $this->dtc->elements[$pere]; |
|
| 49 | - #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 50 | - if (!($p = @in_array($name, $fils))) { |
|
| 51 | - if ($p = strpos($name, ':')) { |
|
| 52 | - $p = substr($name, $p + 1); |
|
| 53 | - $p = @in_array($p, $fils); |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - if (!$p) { |
|
| 57 | - $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 58 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 59 | - . _T('zxml_non_fils') |
|
| 60 | - . ' <b>' |
|
| 61 | - . $pere |
|
| 62 | - . '</b>' |
|
| 63 | - . (!$bons_peres ? '' |
|
| 64 | - : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | - } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 66 | - $frat = substr($depth, 2); |
|
| 67 | - if (!isset($this->fratrie[$frat])) { |
|
| 68 | - $this->fratrie[$frat] = ''; |
|
| 69 | - } |
|
| 70 | - $this->fratrie[$frat] .= "$name "; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - // Init de la suite des balises a memoriser si regle difficile |
|
| 76 | - if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 77 | - $this->fratrie[$depth] = ''; |
|
| 78 | - } |
|
| 79 | - if (isset($this->dtc->attributs[$name])) { |
|
| 80 | - foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 81 | - if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 82 | - coordonnees_erreur($this, " <b>$n</b>" |
|
| 83 | - . ' : ' |
|
| 84 | - . _T('zxml_obligatoire_attribut') |
|
| 85 | - . " <b>$name</b>"); |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - } |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 92 | - // Si la balise est inconnue, eviter d'insister |
|
| 93 | - if (!isset($this->dtc->attributs[$bal])) { |
|
| 94 | - return; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $a = $this->dtc->attributs[$bal]; |
|
| 98 | - if (!isset($a[$name])) { |
|
| 99 | - $bons = join(', ', array_keys($a)); |
|
| 100 | - if ($bons) { |
|
| 101 | - $bons = " title=' " . |
|
| 102 | - _T('zxml_connus_attributs') . |
|
| 103 | - ' : ' . |
|
| 104 | - $bons . |
|
| 105 | - "'"; |
|
| 106 | - } |
|
| 107 | - $bons .= " style='font-weight: bold'"; |
|
| 108 | - coordonnees_erreur($this, " <b>$name</b> " |
|
| 109 | - . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 110 | - . " <a$bons>$bal</a> (" |
|
| 111 | - . _T('zxml_survoler') |
|
| 112 | - . ')'); |
|
| 113 | - } else { |
|
| 114 | - $type = $a[$name][0]; |
|
| 115 | - if (!preg_match('/^\w+$/', $type)) { |
|
| 116 | - $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 117 | - } else { |
|
| 118 | - if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 119 | - $this->$f($phraseur, $name, $val, $bal); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - # else spip_log("$type type d'attribut inconnu"); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 127 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 131 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 135 | - if (isset($this->ids[$val])) { |
|
| 136 | - [$l, $c] = $this->ids[$val]; |
|
| 137 | - coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 138 | - . _T('zxml_valeur_attribut') |
|
| 139 | - . " <b>$name</b> " |
|
| 140 | - . _T('zxml_de') |
|
| 141 | - . " <b>$bal</b> " |
|
| 142 | - . _T('zxml_vu') |
|
| 143 | - . " (L$l,C$c)"); |
|
| 144 | - } else { |
|
| 145 | - $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 146 | - $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 151 | - $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 155 | - $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 159 | - if (!preg_match($motif, $val)) { |
|
| 160 | - coordonnees_erreur($this, "<b>$val</b> " |
|
| 161 | - . _T('zxml_valeur_attribut') |
|
| 162 | - . " <b>$name</b> " |
|
| 163 | - . _T('zxml_de') |
|
| 164 | - . " <b>$bal</b> " |
|
| 165 | - . _T('zxml_non_conforme') |
|
| 166 | - . '</p><p>' |
|
| 167 | - . '<b>' . $motif . '</b>'); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - public function valider_idref($nom, $ligne, $col) { |
|
| 172 | - if (!isset($this->ids[$nom])) { |
|
| 173 | - $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - public function valider_passe2() { |
|
| 178 | - if (!$this->err) { |
|
| 179 | - foreach ($this->idrefs as $idref) { |
|
| 180 | - [$nom, $ligne, $col] = $idref; |
|
| 181 | - $this->valider_idref($nom, $ligne, $col); |
|
| 182 | - } |
|
| 183 | - foreach ($this->idrefss as $idref) { |
|
| 184 | - [$noms, $ligne, $col] = $idref; |
|
| 185 | - foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 186 | - $this->valider_idref($nom, $ligne, $col); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - public function debutElement($phraseur, $name, $attrs) { |
|
| 193 | - if ($this->dtc->elements) { |
|
| 194 | - $this->validerElement($phraseur, $name, $attrs); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if ($f = $this->process['debut']) { |
|
| 198 | - $f($this, $name, $attrs); |
|
| 199 | - } |
|
| 200 | - $depth = $this->depth; |
|
| 201 | - $this->debuts[$depth] = strlen($this->res); |
|
| 202 | - foreach ($attrs as $k => $v) { |
|
| 203 | - $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - public function finElement($phraseur, $name) { |
|
| 208 | - $depth = $this->depth; |
|
| 209 | - $contenu = $this->contenu; |
|
| 210 | - |
|
| 211 | - $n = strlen($this->res); |
|
| 212 | - $c = strlen(trim($contenu[$depth])); |
|
| 213 | - $k = $this->debuts[$depth]; |
|
| 214 | - |
|
| 215 | - $regle = $this->dtc->regles[$name] ?? false; |
|
| 216 | - $vide = ($regle == 'EMPTY'); |
|
| 217 | - // controler que les balises devant etre vides le sont |
|
| 218 | - if ($vide) { |
|
| 219 | - if ($n <> ($k + $c)) { |
|
| 220 | - coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 221 | - } |
|
| 222 | - // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 223 | - } elseif ($regle and ($regle != '*')) { |
|
| 224 | - if ($regle == '+') { |
|
| 225 | - // iteration de disjonction non vide: 1 balise au - |
|
| 226 | - if ($n == $k) { |
|
| 227 | - coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 228 | - . _T('zxml_vide_balise')); |
|
| 229 | - } |
|
| 230 | - } else { |
|
| 231 | - $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 232 | - if (is_null($f) or !preg_match($regle, $f)) { |
|
| 233 | - coordonnees_erreur( |
|
| 234 | - $this, |
|
| 235 | - " <p>\n<b>$name</b> " |
|
| 236 | - . _T('zxml_succession_fils_incorrecte') |
|
| 237 | - . ' : <b>' |
|
| 238 | - . $f |
|
| 239 | - . '</b>' |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - if ($f = $this->process['fin']) { |
|
| 245 | - $f($this, $name, $vide); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function textElement($phraseur, $data) { |
|
| 250 | - if (trim($data)) { |
|
| 251 | - $d = $this->depth; |
|
| 252 | - $d = $this->ouvrant[$d]; |
|
| 253 | - preg_match('/^\s*(\S+)/', $d, $m); |
|
| 254 | - if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 255 | - coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 256 | - . _T('zxml_nonvide_balise')); // message a affiner |
|
| 257 | - } |
|
| 258 | - } |
|
| 259 | - if ($f = $this->process['text']) { |
|
| 260 | - $f($this, $data); |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - public function piElement($phraseur, $target, $data) { |
|
| 265 | - if ($f = $this->process['pi']) { |
|
| 266 | - $f($this, $target, $data); |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Denonciation des entitees XML inconnues |
|
| 271 | - // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 272 | - // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 273 | - // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 274 | - // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 275 | - // le source de la page laisse legitimement supposer. |
|
| 276 | - |
|
| 277 | - public function defaultElement($phraseur, $data) { |
|
| 278 | - if ( |
|
| 279 | - !preg_match('/^<!--/', $data) |
|
| 280 | - and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 281 | - ) { |
|
| 282 | - foreach ($r as $m) { |
|
| 283 | - [$t, $e] = $m; |
|
| 284 | - if (!isset($this->dtc->entites[$e])) { |
|
| 285 | - coordonnees_erreur($this, " <b>$e</b> " |
|
| 286 | - . _T('zxml_inconnu_entite') |
|
| 287 | - . ' '); |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 292 | - $f($this, $data); |
|
| 293 | - } |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - public function phraserTout($phraseur, $data) { |
|
| 297 | - xml_parsestring($this, $data); |
|
| 298 | - |
|
| 299 | - if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 300 | - $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 301 | - } else { |
|
| 302 | - $this->valider_passe2(); |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Constructeur |
|
| 308 | - * |
|
| 309 | - * @param array $process ? |
|
| 310 | - **/ |
|
| 311 | - public function __construct($process = []) { |
|
| 312 | - if (is_array($process)) { |
|
| 313 | - $this->process = $process; |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - public $ids = []; |
|
| 318 | - public $idrefs = []; |
|
| 319 | - public $idrefss = []; |
|
| 320 | - public $debuts = []; |
|
| 321 | - public $fratrie = []; |
|
| 322 | - |
|
| 323 | - public $dtc = null; |
|
| 324 | - public $sax = null; |
|
| 325 | - public $depth = ''; |
|
| 326 | - public $entete = ''; |
|
| 327 | - public $page = ''; |
|
| 328 | - public $res = ''; |
|
| 329 | - public array $err = []; |
|
| 330 | - public array $contenu = []; |
|
| 331 | - public array $versions = []; |
|
| 332 | - |
|
| 333 | - public array $ouvrant = []; |
|
| 334 | - public array $reperes = []; |
|
| 335 | - public array $process = [ |
|
| 336 | - 'debut' => 'xml_debutElement', |
|
| 337 | - 'fin' => 'xml_finElement', |
|
| 338 | - 'text' => 'xml_textElement', |
|
| 339 | - 'pi' => 'xml_piElement', |
|
| 340 | - 'default' => 'xml_defaultElement' |
|
| 341 | - ]; |
|
| 26 | + public function validerElement($phraseur, $name, $attrs) { |
|
| 27 | + if (!($p = isset($this->dtc->elements[$name]))) { |
|
| 28 | + if ($p = strpos($name, ':')) { |
|
| 29 | + $name = substr($name, $p + 1); |
|
| 30 | + $p = isset($this->dtc->elements[$name]); |
|
| 31 | + } |
|
| 32 | + if (!$p) { |
|
| 33 | + coordonnees_erreur($this, " <b>$name</b> : " |
|
| 34 | + . _T('zxml_inconnu_balise')); |
|
| 35 | + |
|
| 36 | + return; |
|
| 37 | + } |
|
| 38 | + } |
|
| 39 | + // controler les filles illegitimes, ca suffit |
|
| 40 | + $depth = $this->depth; |
|
| 41 | + $ouvrant = $this->ouvrant; |
|
| 42 | + #spip_log("trouve $name apres " . $ouvrant[$depth]); |
|
| 43 | + if (isset($ouvrant[$depth])) { |
|
| 44 | + if (preg_match('/^\s*(\w+)/', $ouvrant[$depth], $r)) { |
|
| 45 | + $pere = $r[1]; |
|
| 46 | + #spip_log("pere $pere"); |
|
| 47 | + if (isset($this->dtc->elements[$pere])) { |
|
| 48 | + $fils = $this->dtc->elements[$pere]; |
|
| 49 | + #spip_log("rejeton $name fils " . @join(',',$fils)); |
|
| 50 | + if (!($p = @in_array($name, $fils))) { |
|
| 51 | + if ($p = strpos($name, ':')) { |
|
| 52 | + $p = substr($name, $p + 1); |
|
| 53 | + $p = @in_array($p, $fils); |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + if (!$p) { |
|
| 57 | + $bons_peres = @join('</b>, <b>', $this->dtc->peres[$name]); |
|
| 58 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 59 | + . _T('zxml_non_fils') |
|
| 60 | + . ' <b>' |
|
| 61 | + . $pere |
|
| 62 | + . '</b>' |
|
| 63 | + . (!$bons_peres ? '' |
|
| 64 | + : ('<p style="font-size: 80%"> ' . _T('zxml_mais_de') . ' <b>' . $bons_peres . '</b></p>'))); |
|
| 65 | + } elseif ($this->dtc->regles[$pere][0] == '/') { |
|
| 66 | + $frat = substr($depth, 2); |
|
| 67 | + if (!isset($this->fratrie[$frat])) { |
|
| 68 | + $this->fratrie[$frat] = ''; |
|
| 69 | + } |
|
| 70 | + $this->fratrie[$frat] .= "$name "; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + // Init de la suite des balises a memoriser si regle difficile |
|
| 76 | + if ($this->dtc->regles[$name] and $this->dtc->regles[$name][0] == '/') { |
|
| 77 | + $this->fratrie[$depth] = ''; |
|
| 78 | + } |
|
| 79 | + if (isset($this->dtc->attributs[$name])) { |
|
| 80 | + foreach ($this->dtc->attributs[$name] as $n => $v) { |
|
| 81 | + if (($v[1] == '#REQUIRED') and (!isset($attrs[$n]))) { |
|
| 82 | + coordonnees_erreur($this, " <b>$n</b>" |
|
| 83 | + . ' : ' |
|
| 84 | + . _T('zxml_obligatoire_attribut') |
|
| 85 | + . " <b>$name</b>"); |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + } |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + public function validerAttribut($phraseur, $name, $val, $bal) { |
|
| 92 | + // Si la balise est inconnue, eviter d'insister |
|
| 93 | + if (!isset($this->dtc->attributs[$bal])) { |
|
| 94 | + return; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $a = $this->dtc->attributs[$bal]; |
|
| 98 | + if (!isset($a[$name])) { |
|
| 99 | + $bons = join(', ', array_keys($a)); |
|
| 100 | + if ($bons) { |
|
| 101 | + $bons = " title=' " . |
|
| 102 | + _T('zxml_connus_attributs') . |
|
| 103 | + ' : ' . |
|
| 104 | + $bons . |
|
| 105 | + "'"; |
|
| 106 | + } |
|
| 107 | + $bons .= " style='font-weight: bold'"; |
|
| 108 | + coordonnees_erreur($this, " <b>$name</b> " |
|
| 109 | + . _T('zxml_inconnu_attribut') . ' ' . _T('zxml_de') |
|
| 110 | + . " <a$bons>$bal</a> (" |
|
| 111 | + . _T('zxml_survoler') |
|
| 112 | + . ')'); |
|
| 113 | + } else { |
|
| 114 | + $type = $a[$name][0]; |
|
| 115 | + if (!preg_match('/^\w+$/', $type)) { |
|
| 116 | + $this->valider_motif($phraseur, $name, $val, $bal, $type); |
|
| 117 | + } else { |
|
| 118 | + if (method_exists($this, $f = 'validerAttribut_' . $type)) { |
|
| 119 | + $this->$f($phraseur, $name, $val, $bal); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + # else spip_log("$type type d'attribut inconnu"); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + public function validerAttribut_NMTOKEN($phraseur, $name, $val, $bal) { |
|
| 127 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKEN); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + public function validerAttribut_NMTOKENS($phraseur, $name, $val, $bal) { |
|
| 131 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_NMTOKENS); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + public function validerAttribut_ID($phraseur, $name, $val, $bal) { |
|
| 135 | + if (isset($this->ids[$val])) { |
|
| 136 | + [$l, $c] = $this->ids[$val]; |
|
| 137 | + coordonnees_erreur($this, " <p><b>$val</b> " |
|
| 138 | + . _T('zxml_valeur_attribut') |
|
| 139 | + . " <b>$name</b> " |
|
| 140 | + . _T('zxml_de') |
|
| 141 | + . " <b>$bal</b> " |
|
| 142 | + . _T('zxml_vu') |
|
| 143 | + . " (L$l,C$c)"); |
|
| 144 | + } else { |
|
| 145 | + $this->valider_motif($phraseur, $name, $val, $bal, _REGEXP_ID); |
|
| 146 | + $this->ids[$val] = [xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function validerAttribut_IDREF($phraseur, $name, $val, $bal) { |
|
| 151 | + $this->idrefs[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + public function validerAttribut_IDREFS($phraseur, $name, $val, $bal) { |
|
| 155 | + $this->idrefss[] = [$val, xml_get_current_line_number($phraseur), xml_get_current_column_number($phraseur)]; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + public function valider_motif($phraseur, $name, $val, $bal, $motif) { |
|
| 159 | + if (!preg_match($motif, $val)) { |
|
| 160 | + coordonnees_erreur($this, "<b>$val</b> " |
|
| 161 | + . _T('zxml_valeur_attribut') |
|
| 162 | + . " <b>$name</b> " |
|
| 163 | + . _T('zxml_de') |
|
| 164 | + . " <b>$bal</b> " |
|
| 165 | + . _T('zxml_non_conforme') |
|
| 166 | + . '</p><p>' |
|
| 167 | + . '<b>' . $motif . '</b>'); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + public function valider_idref($nom, $ligne, $col) { |
|
| 172 | + if (!isset($this->ids[$nom])) { |
|
| 173 | + $this->err[] = [" <p><b>$nom</b> " . _T('zxml_inconnu_id'), $ligne, $col]; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + public function valider_passe2() { |
|
| 178 | + if (!$this->err) { |
|
| 179 | + foreach ($this->idrefs as $idref) { |
|
| 180 | + [$nom, $ligne, $col] = $idref; |
|
| 181 | + $this->valider_idref($nom, $ligne, $col); |
|
| 182 | + } |
|
| 183 | + foreach ($this->idrefss as $idref) { |
|
| 184 | + [$noms, $ligne, $col] = $idref; |
|
| 185 | + foreach (preg_split('/\s+/', $noms) as $nom) { |
|
| 186 | + $this->valider_idref($nom, $ligne, $col); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + public function debutElement($phraseur, $name, $attrs) { |
|
| 193 | + if ($this->dtc->elements) { |
|
| 194 | + $this->validerElement($phraseur, $name, $attrs); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if ($f = $this->process['debut']) { |
|
| 198 | + $f($this, $name, $attrs); |
|
| 199 | + } |
|
| 200 | + $depth = $this->depth; |
|
| 201 | + $this->debuts[$depth] = strlen($this->res); |
|
| 202 | + foreach ($attrs as $k => $v) { |
|
| 203 | + $this->validerAttribut($phraseur, $k, $v, $name); |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + public function finElement($phraseur, $name) { |
|
| 208 | + $depth = $this->depth; |
|
| 209 | + $contenu = $this->contenu; |
|
| 210 | + |
|
| 211 | + $n = strlen($this->res); |
|
| 212 | + $c = strlen(trim($contenu[$depth])); |
|
| 213 | + $k = $this->debuts[$depth]; |
|
| 214 | + |
|
| 215 | + $regle = $this->dtc->regles[$name] ?? false; |
|
| 216 | + $vide = ($regle == 'EMPTY'); |
|
| 217 | + // controler que les balises devant etre vides le sont |
|
| 218 | + if ($vide) { |
|
| 219 | + if ($n <> ($k + $c)) { |
|
| 220 | + coordonnees_erreur($this, " <p><b>$name</b> " . _T('zxml_nonvide_balise')); |
|
| 221 | + } |
|
| 222 | + // pour les regles PCDATA ou iteration de disjonction, tout est fait |
|
| 223 | + } elseif ($regle and ($regle != '*')) { |
|
| 224 | + if ($regle == '+') { |
|
| 225 | + // iteration de disjonction non vide: 1 balise au - |
|
| 226 | + if ($n == $k) { |
|
| 227 | + coordonnees_erreur($this, "<p>\n<b>$name</b> " |
|
| 228 | + . _T('zxml_vide_balise')); |
|
| 229 | + } |
|
| 230 | + } else { |
|
| 231 | + $f = $this->fratrie[substr($depth, 2)] ?? null; |
|
| 232 | + if (is_null($f) or !preg_match($regle, $f)) { |
|
| 233 | + coordonnees_erreur( |
|
| 234 | + $this, |
|
| 235 | + " <p>\n<b>$name</b> " |
|
| 236 | + . _T('zxml_succession_fils_incorrecte') |
|
| 237 | + . ' : <b>' |
|
| 238 | + . $f |
|
| 239 | + . '</b>' |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + if ($f = $this->process['fin']) { |
|
| 245 | + $f($this, $name, $vide); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function textElement($phraseur, $data) { |
|
| 250 | + if (trim($data)) { |
|
| 251 | + $d = $this->depth; |
|
| 252 | + $d = $this->ouvrant[$d]; |
|
| 253 | + preg_match('/^\s*(\S+)/', $d, $m); |
|
| 254 | + if (isset($this->dtc->pcdata[$m[1]]) and ($this->dtc->pcdata[$m[1]])) { |
|
| 255 | + coordonnees_erreur($this, ' <p><b>' . $m[1] . '</b> ' |
|
| 256 | + . _T('zxml_nonvide_balise')); // message a affiner |
|
| 257 | + } |
|
| 258 | + } |
|
| 259 | + if ($f = $this->process['text']) { |
|
| 260 | + $f($this, $data); |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + public function piElement($phraseur, $target, $data) { |
|
| 265 | + if ($f = $this->process['pi']) { |
|
| 266 | + $f($this, $target, $data); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Denonciation des entitees XML inconnues |
|
| 271 | + // Pour contourner le bug de conception de SAX qui ne signale pas si elles |
|
| 272 | + // sont dans un attribut, les entites les plus frequentes ont ete |
|
| 273 | + // transcodees au prealable (sauf & < > " que SAX traite correctement). |
|
| 274 | + // On ne les verra donc pas passer a cette etape, contrairement a ce que |
|
| 275 | + // le source de la page laisse legitimement supposer. |
|
| 276 | + |
|
| 277 | + public function defaultElement($phraseur, $data) { |
|
| 278 | + if ( |
|
| 279 | + !preg_match('/^<!--/', $data) |
|
| 280 | + and (preg_match_all('/&([^;]*)?/', $data, $r, PREG_SET_ORDER)) |
|
| 281 | + ) { |
|
| 282 | + foreach ($r as $m) { |
|
| 283 | + [$t, $e] = $m; |
|
| 284 | + if (!isset($this->dtc->entites[$e])) { |
|
| 285 | + coordonnees_erreur($this, " <b>$e</b> " |
|
| 286 | + . _T('zxml_inconnu_entite') |
|
| 287 | + . ' '); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + if (isset($this->process['default']) and ($f = $this->process['default'])) { |
|
| 292 | + $f($this, $data); |
|
| 293 | + } |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + public function phraserTout($phraseur, $data) { |
|
| 297 | + xml_parsestring($this, $data); |
|
| 298 | + |
|
| 299 | + if (!$this->dtc or preg_match(',^' . _MESSAGE_DOCTYPE . ',', $data)) { |
|
| 300 | + $this->err[] = ['DOCTYPE ?', 0, 0]; |
|
| 301 | + } else { |
|
| 302 | + $this->valider_passe2(); |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Constructeur |
|
| 308 | + * |
|
| 309 | + * @param array $process ? |
|
| 310 | + **/ |
|
| 311 | + public function __construct($process = []) { |
|
| 312 | + if (is_array($process)) { |
|
| 313 | + $this->process = $process; |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + public $ids = []; |
|
| 318 | + public $idrefs = []; |
|
| 319 | + public $idrefss = []; |
|
| 320 | + public $debuts = []; |
|
| 321 | + public $fratrie = []; |
|
| 322 | + |
|
| 323 | + public $dtc = null; |
|
| 324 | + public $sax = null; |
|
| 325 | + public $depth = ''; |
|
| 326 | + public $entete = ''; |
|
| 327 | + public $page = ''; |
|
| 328 | + public $res = ''; |
|
| 329 | + public array $err = []; |
|
| 330 | + public array $contenu = []; |
|
| 331 | + public array $versions = []; |
|
| 332 | + |
|
| 333 | + public array $ouvrant = []; |
|
| 334 | + public array $reperes = []; |
|
| 335 | + public array $process = [ |
|
| 336 | + 'debut' => 'xml_debutElement', |
|
| 337 | + 'fin' => 'xml_finElement', |
|
| 338 | + 'text' => 'xml_textElement', |
|
| 339 | + 'pi' => 'xml_piElement', |
|
| 340 | + 'default' => 'xml_defaultElement' |
|
| 341 | + ]; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | |
@@ -348,8 +348,8 @@ discard block |
||
| 348 | 348 | * |
| 349 | 349 | **/ |
| 350 | 350 | function xml_valider_dist($page, $apply = false, $process = false, $doctype = '', $charset = null) { |
| 351 | - $f = new ValidateurXML($process); |
|
| 352 | - $sax = charger_fonction('sax', 'xml'); |
|
| 351 | + $f = new ValidateurXML($process); |
|
| 352 | + $sax = charger_fonction('sax', 'xml'); |
|
| 353 | 353 | |
| 354 | - return $sax($page, $apply, $f, $doctype, $charset); |
|
| 354 | + return $sax($page, $apply, $f, $doctype, $charset); |
|
| 355 | 355 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Formulaires |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/filtres'); |
@@ -35,22 +35,22 @@ discard block |
||
| 35 | 35 | * Saisie protégée |
| 36 | 36 | **/ |
| 37 | 37 | function protege_champ($texte) { |
| 38 | - if (is_array($texte)) { |
|
| 39 | - return array_map('protege_champ', $texte); |
|
| 40 | - } elseif ($texte === null) { |
|
| 41 | - return $texte; |
|
| 42 | - } elseif (is_bool($texte)) { |
|
| 43 | - return $texte ? '1' : ''; |
|
| 44 | - } elseif (is_string($texte) and $texte) { |
|
| 45 | - if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) { |
|
| 46 | - // ne pas corrompre une valeur serialize |
|
| 47 | - return $texte; |
|
| 48 | - } elseif (strpbrk($texte, "&\"'<>") !== false) { |
|
| 49 | - return spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $texte; |
|
| 38 | + if (is_array($texte)) { |
|
| 39 | + return array_map('protege_champ', $texte); |
|
| 40 | + } elseif ($texte === null) { |
|
| 41 | + return $texte; |
|
| 42 | + } elseif (is_bool($texte)) { |
|
| 43 | + return $texte ? '1' : ''; |
|
| 44 | + } elseif (is_string($texte) and $texte) { |
|
| 45 | + if (preg_match(',^[abis]:\d+[:;],', $texte) and @unserialize($texte) !== false) { |
|
| 46 | + // ne pas corrompre une valeur serialize |
|
| 47 | + return $texte; |
|
| 48 | + } elseif (strpbrk($texte, "&\"'<>") !== false) { |
|
| 49 | + return spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $texte; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * - false : pas de squelette trouvé |
| 65 | 65 | **/ |
| 66 | 66 | function existe_formulaire($form) { |
| 67 | - if (substr($form, 0, 11) == 'FORMULAIRE_') { |
|
| 68 | - $form = strtolower(substr($form, 11)); |
|
| 69 | - } else { |
|
| 70 | - $form = strtolower($form); |
|
| 71 | - } |
|
| 67 | + if (substr($form, 0, 11) == 'FORMULAIRE_') { |
|
| 68 | + $form = strtolower(substr($form, 11)); |
|
| 69 | + } else { |
|
| 70 | + $form = strtolower($form); |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - if (!$form) { |
|
| 74 | - return ''; |
|
| 75 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 73 | + if (!$form) { |
|
| 74 | + return ''; |
|
| 75 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 76 | 76 | |
| 77 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 77 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -83,31 +83,31 @@ discard block |
||
| 83 | 83 | * @return false|array |
| 84 | 84 | */ |
| 85 | 85 | function test_formulaire_inclus_par_modele() { |
| 86 | - $trace = debug_backtrace(0, 20); |
|
| 87 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 88 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 89 | - |
|
| 90 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 91 | - if ( |
|
| 92 | - function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | - and $form = arguments_balise_dyn_depuis_modele(null, 'read') |
|
| 94 | - ) { |
|
| 95 | - if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 96 | - $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 97 | - if ($trace[$k]['args'][0] === $form) { |
|
| 98 | - return $trace[$k]['args']; |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 104 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 105 | - if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 106 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 107 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 108 | - return $trace[$k - 1]['args'][1]['args']; |
|
| 109 | - } |
|
| 110 | - return false; |
|
| 86 | + $trace = debug_backtrace(0, 20); |
|
| 87 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 88 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 89 | + |
|
| 90 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 91 | + if ( |
|
| 92 | + function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | + and $form = arguments_balise_dyn_depuis_modele(null, 'read') |
|
| 94 | + ) { |
|
| 95 | + if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 96 | + $k = array_search('balise_formulaire__dyn', $trace_fonctions); |
|
| 97 | + if ($trace[$k]['args'][0] === $form) { |
|
| 98 | + return $trace[$k]['args']; |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 104 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 105 | + if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 106 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 107 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 108 | + return $trace[$k - 1]['args'][1]['args']; |
|
| 109 | + } |
|
| 110 | + return false; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -122,19 +122,19 @@ discard block |
||
| 122 | 122 | **/ |
| 123 | 123 | function balise_FORMULAIRE__dist($p) { |
| 124 | 124 | |
| 125 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 126 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 127 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 128 | - $p->code = "''"; |
|
| 129 | - $p->interdire_scripts = false; |
|
| 125 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 126 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 127 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 128 | + $p->code = "''"; |
|
| 129 | + $p->interdire_scripts = false; |
|
| 130 | 130 | |
| 131 | - return $p; |
|
| 132 | - } |
|
| 131 | + return $p; |
|
| 132 | + } |
|
| 133 | 133 | |
| 134 | - // sinon renvoyer un code php dynamique |
|
| 135 | - $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 134 | + // sinon renvoyer un code php dynamique |
|
| 135 | + $p = calculer_balise_dynamique($p, $p->nom_champ, []); |
|
| 136 | 136 | |
| 137 | - return $p; |
|
| 137 | + return $p; |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -154,17 +154,17 @@ discard block |
||
| 154 | 154 | * - string : texte à afficher directement |
| 155 | 155 | */ |
| 156 | 156 | function balise_FORMULAIRE__dyn($form, ...$args) { |
| 157 | - $form = existe_formulaire($form); |
|
| 158 | - if (!$form) { |
|
| 159 | - return ''; |
|
| 160 | - } |
|
| 157 | + $form = existe_formulaire($form); |
|
| 158 | + if (!$form) { |
|
| 159 | + return ''; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 163 | - if (!is_array($contexte)) { |
|
| 164 | - return $contexte; |
|
| 165 | - } |
|
| 162 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 163 | + if (!is_array($contexte)) { |
|
| 164 | + return $contexte; |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - return ["formulaires/$form", 3600, $contexte]; |
|
| 167 | + return ["formulaires/$form", 3600, $contexte]; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -179,85 +179,85 @@ discard block |
||
| 179 | 179 | * string: Formulaire non applicable (message d’explication) |
| 180 | 180 | **/ |
| 181 | 181 | function balise_FORMULAIRE__contexte($form, $args) { |
| 182 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 183 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 184 | - // si poste, on recupere les erreurs |
|
| 185 | - |
|
| 186 | - $je_suis_poste = false; |
|
| 187 | - if ( |
|
| 188 | - $post_form = _request('formulaire_action') |
|
| 189 | - and $post_form == $form |
|
| 190 | - and $p = _request('formulaire_action_args') |
|
| 191 | - and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 192 | - ) { |
|
| 193 | - // enlever le faux attribut de langue masque |
|
| 194 | - array_shift($p); |
|
| 195 | - if (formulaire__identifier($form, $args, $p)) { |
|
| 196 | - $je_suis_poste = true; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - $editable = true; |
|
| 201 | - $erreurs = $post = []; |
|
| 202 | - if ($je_suis_poste) { |
|
| 203 | - $post = traiter_formulaires_dynamiques(true); |
|
| 204 | - $e = "erreurs_$form"; |
|
| 205 | - $erreurs = $post[$e] ?? []; |
|
| 206 | - $editable = "editable_$form"; |
|
| 207 | - $editable = (!isset($post[$e])) |
|
| 208 | - || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 209 | - || (isset($post[$editable]) && $post[$editable]); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 213 | - |
|
| 214 | - // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 215 | - // C'est plus fort qu'editable qui est gere par le squelette |
|
| 216 | - // Idealement $valeur doit etre alors un message explicatif. |
|
| 217 | - if (!is_array($valeurs)) { |
|
| 218 | - return is_string($valeurs) ? $valeurs : ''; |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 222 | - // ou une action vide si elle ne sert pas |
|
| 223 | - $action = $valeurs['action'] ?? self('&', true); |
|
| 224 | - // bug IEx : si action finit par / |
|
| 225 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 226 | - if (substr($action, -1) == '/') { |
|
| 227 | - // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 228 | - $action .= '#'; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // recuperer la saisie en cours si erreurs |
|
| 232 | - // seulement si c'est ce formulaire qui est poste |
|
| 233 | - // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 234 | - $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 235 | - foreach (array_keys($valeurs) as $champ) { |
|
| 236 | - if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 237 | - if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 238 | - $valeurs[$champ] = $v; |
|
| 239 | - } |
|
| 240 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 241 | - if ($action) { |
|
| 242 | - $action = parametre_url($action, $champ, ''); |
|
| 243 | - } |
|
| 244 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 245 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - if ($action) { |
|
| 250 | - // nettoyer l'url |
|
| 251 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 252 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 253 | - $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * @deprecated 4.0 |
|
| 258 | - * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide |
|
| 259 | - */ |
|
| 260 | - /* |
|
| 182 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 183 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 184 | + // si poste, on recupere les erreurs |
|
| 185 | + |
|
| 186 | + $je_suis_poste = false; |
|
| 187 | + if ( |
|
| 188 | + $post_form = _request('formulaire_action') |
|
| 189 | + and $post_form == $form |
|
| 190 | + and $p = _request('formulaire_action_args') |
|
| 191 | + and is_array($p = decoder_contexte_ajax($p, $post_form)) |
|
| 192 | + ) { |
|
| 193 | + // enlever le faux attribut de langue masque |
|
| 194 | + array_shift($p); |
|
| 195 | + if (formulaire__identifier($form, $args, $p)) { |
|
| 196 | + $je_suis_poste = true; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + $editable = true; |
|
| 201 | + $erreurs = $post = []; |
|
| 202 | + if ($je_suis_poste) { |
|
| 203 | + $post = traiter_formulaires_dynamiques(true); |
|
| 204 | + $e = "erreurs_$form"; |
|
| 205 | + $erreurs = $post[$e] ?? []; |
|
| 206 | + $editable = "editable_$form"; |
|
| 207 | + $editable = (!isset($post[$e])) |
|
| 208 | + || (is_countable($erreurs) ? count($erreurs) : 0) |
|
| 209 | + || (isset($post[$editable]) && $post[$editable]); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $valeurs = formulaire__charger($form, $args, $je_suis_poste); |
|
| 213 | + |
|
| 214 | + // si $valeurs n'est pas un tableau, le formulaire n'est pas applicable |
|
| 215 | + // C'est plus fort qu'editable qui est gere par le squelette |
|
| 216 | + // Idealement $valeur doit etre alors un message explicatif. |
|
| 217 | + if (!is_array($valeurs)) { |
|
| 218 | + return is_string($valeurs) ? $valeurs : ''; |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // charger peut passer une action si le formulaire ne tourne pas sur self() |
|
| 222 | + // ou une action vide si elle ne sert pas |
|
| 223 | + $action = $valeurs['action'] ?? self('&', true); |
|
| 224 | + // bug IEx : si action finit par / |
|
| 225 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 226 | + if (substr($action, -1) == '/') { |
|
| 227 | + // on ajoute une ancre pour feinter IE, au pire ca tue l'ancre qui finit par un / |
|
| 228 | + $action .= '#'; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // recuperer la saisie en cours si erreurs |
|
| 232 | + // seulement si c'est ce formulaire qui est poste |
|
| 233 | + // ou si on le demande explicitement par le parametre _forcer_request = true |
|
| 234 | + $dispo = ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])); |
|
| 235 | + foreach (array_keys($valeurs) as $champ) { |
|
| 236 | + if ($champ[0] !== '_' and !in_array($champ, ['message_ok', 'message_erreur', 'editable'])) { |
|
| 237 | + if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 238 | + $valeurs[$champ] = $v; |
|
| 239 | + } |
|
| 240 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 241 | + if ($action) { |
|
| 242 | + $action = parametre_url($action, $champ, ''); |
|
| 243 | + } |
|
| 244 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 245 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + if ($action) { |
|
| 250 | + // nettoyer l'url |
|
| 251 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 252 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 253 | + $action = parametre_url($action, 'formulaire_action_sign', ''); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * @deprecated 4.0 |
|
| 258 | + * servait pour poster sur les actions de type editer_xxx() qui ne prenaient pas d'argument autrement que par _request('arg') et pour lesquelles il fallait donc passer un hash valide |
|
| 259 | + */ |
|
| 260 | + /* |
|
| 261 | 261 | if (isset($valeurs['_action'])) { |
| 262 | 262 | $securiser_action = charger_fonction('securiser_action', 'inc'); |
| 263 | 263 | $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
@@ -267,59 +267,59 @@ discard block |
||
| 267 | 267 | } |
| 268 | 268 | */ |
| 269 | 269 | |
| 270 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 271 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 272 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 273 | - |
|
| 274 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 275 | - $valeurs['erreurs'] = $erreurs; |
|
| 276 | - $valeurs['action'] = $action; |
|
| 277 | - $valeurs['form'] = $form; |
|
| 278 | - |
|
| 279 | - $valeurs['formulaire_sign'] = ''; |
|
| 280 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 281 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 282 | - $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 283 | - $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - if (!isset($valeurs['id'])) { |
|
| 287 | - $valeurs['id'] = 'new'; |
|
| 288 | - } |
|
| 289 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 290 | - if (!isset($valeurs['editable'])) { |
|
| 291 | - $valeurs['editable'] = $editable; |
|
| 292 | - } |
|
| 293 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 294 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 295 | - |
|
| 296 | - if ($je_suis_poste) { |
|
| 297 | - $valeurs['message_erreur'] = ''; |
|
| 298 | - if (isset($erreurs['message_erreur'])) { |
|
| 299 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $valeurs['message_ok'] = ''; |
|
| 303 | - if (isset($post["message_ok_$form"])) { |
|
| 304 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 305 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 306 | - $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 310 | - // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 311 | - // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 312 | - if (html5_permis()) { |
|
| 313 | - foreach ($erreurs as $k => $v) { |
|
| 314 | - if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
|
| 315 | - // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 316 | - $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - return $valeurs; |
|
| 270 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 271 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 272 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 273 | + |
|
| 274 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 275 | + $valeurs['erreurs'] = $erreurs; |
|
| 276 | + $valeurs['action'] = $action; |
|
| 277 | + $valeurs['form'] = $form; |
|
| 278 | + |
|
| 279 | + $valeurs['formulaire_sign'] = ''; |
|
| 280 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 281 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 282 | + $secu = $securiser_action($valeurs['form'], $valeurs['formulaire_args'], '', -1); |
|
| 283 | + $valeurs['formulaire_sign'] = $secu['hash']; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + if (!isset($valeurs['id'])) { |
|
| 287 | + $valeurs['id'] = 'new'; |
|
| 288 | + } |
|
| 289 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 290 | + if (!isset($valeurs['editable'])) { |
|
| 291 | + $valeurs['editable'] = $editable; |
|
| 292 | + } |
|
| 293 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 294 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 295 | + |
|
| 296 | + if ($je_suis_poste) { |
|
| 297 | + $valeurs['message_erreur'] = ''; |
|
| 298 | + if (isset($erreurs['message_erreur'])) { |
|
| 299 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $valeurs['message_ok'] = ''; |
|
| 303 | + if (isset($post["message_ok_$form"])) { |
|
| 304 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 305 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 306 | + $valeurs['message_ok'] = $erreurs['message_ok']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // accessibilite : encapsuler toutes les erreurs dans un role='alert' |
|
| 310 | + // uniquement si c'est une string et au premier niveau (on ne touche pas au tableaux) |
|
| 311 | + // et si $k ne commence pas par un _ (c'est bien une vrai erreur sur un vrai champ) |
|
| 312 | + if (html5_permis()) { |
|
| 313 | + foreach ($erreurs as $k => $v) { |
|
| 314 | + if (is_string($v) and strlen(trim($v)) and strpos($k, '_') !== 0) { |
|
| 315 | + // on encapsule dans un span car ces messages sont en general simple, juste du texte, et deja dans un span dans le form |
|
| 316 | + $valeurs['erreurs'][$k] = "<span role='alert'>" . $erreurs[$k] . '</span>'; |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + return $valeurs; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -331,51 +331,51 @@ discard block |
||
| 331 | 331 | * @return array |
| 332 | 332 | */ |
| 333 | 333 | function formulaire__charger($form, $args, $poste) { |
| 334 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 335 | - $valeurs = $charger_valeurs(...$args); |
|
| 336 | - } else { |
|
| 337 | - $valeurs = []; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $valeurs = pipeline( |
|
| 341 | - 'formulaire_charger', |
|
| 342 | - [ |
|
| 343 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 344 | - 'data' => $valeurs |
|
| 345 | - ] |
|
| 346 | - ); |
|
| 347 | - |
|
| 348 | - // prise en charge CVT multi etape |
|
| 349 | - if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 350 | - include_spip('inc/cvt_multietapes'); |
|
| 351 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 352 | - ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 353 | - $valeurs |
|
| 354 | - ); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 358 | - if (is_array($valeurs)) { |
|
| 359 | - if (!isset($valeurs['_pipelines'])) { |
|
| 360 | - $valeurs['_pipelines'] = []; |
|
| 361 | - } |
|
| 362 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 363 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 364 | - if (isset($valeurs['_pipeline'])) { |
|
| 365 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 366 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 367 | - |
|
| 368 | - $pipelines = [$pipe => $args]; |
|
| 369 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 373 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 374 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 375 | - $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - return $valeurs; |
|
| 334 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form", true)) { |
|
| 335 | + $valeurs = $charger_valeurs(...$args); |
|
| 336 | + } else { |
|
| 337 | + $valeurs = []; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $valeurs = pipeline( |
|
| 341 | + 'formulaire_charger', |
|
| 342 | + [ |
|
| 343 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 344 | + 'data' => $valeurs |
|
| 345 | + ] |
|
| 346 | + ); |
|
| 347 | + |
|
| 348 | + // prise en charge CVT multi etape |
|
| 349 | + if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 350 | + include_spip('inc/cvt_multietapes'); |
|
| 351 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 352 | + ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste], |
|
| 353 | + $valeurs |
|
| 354 | + ); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 358 | + if (is_array($valeurs)) { |
|
| 359 | + if (!isset($valeurs['_pipelines'])) { |
|
| 360 | + $valeurs['_pipelines'] = []; |
|
| 361 | + } |
|
| 362 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 363 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 364 | + if (isset($valeurs['_pipeline'])) { |
|
| 365 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 366 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : []; |
|
| 367 | + |
|
| 368 | + $pipelines = [$pipe => $args]; |
|
| 369 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 373 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 374 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 375 | + $valeurs['_pipelines']['formulaire_fond'] = ['form' => $form, 'args' => $args, 'je_suis_poste' => $poste]; |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + return $valeurs; |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -394,9 +394,9 @@ discard block |
||
| 394 | 394 | * @return bool |
| 395 | 395 | */ |
| 396 | 396 | function formulaire__identifier($form, $args, $p) { |
| 397 | - if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 398 | - return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 399 | - } |
|
| 397 | + if ($identifier_args = charger_fonction('identifier', "formulaires/$form", true)) { |
|
| 398 | + return $identifier_args(...$args) === $identifier_args(...$p); |
|
| 399 | + } |
|
| 400 | 400 | |
| 401 | - return $args === $p; |
|
| 401 | + return $args === $p; |
|
| 402 | 402 | } |