@@ -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 | - list($methode, $q, $preg) = expression_recherche($recherche, $options); |
|
| 55 | + list($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 | - list($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 | - list($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 | - list($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 | + list($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 | + list($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 | + list($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 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $_id_table = reset($_id_table); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | + $requete['SELECT'][] = 't.'.$_id_table; |
|
| 71 | 71 | $a = []; |
| 72 | 72 | // Recherche fulltext |
| 73 | 73 | foreach ($champs as $champ => $poids) { |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | $champ = "t.$champ"; |
| 79 | 79 | } |
| 80 | 80 | $requete['SELECT'][] = $champ; |
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | + $a[] = $champ.' '.$methode.' '.$q; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | if ($a) { |
| 85 | 85 | $requete['WHERE'][] = join(' OR ', $a); |
| 86 | 86 | } |
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table).' AS t'; |
|
| 88 | 88 | |
| 89 | 89 | $results = []; |
| 90 | 90 | |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | ); |
| 253 | 253 | } // cas table de liaison generique spip_xxx_yyy |
| 254 | 254 | elseif ( |
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 255 | + $t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur) |
|
| 257 | 257 | ) { |
| 258 | 258 | $s = sql_select( |
| 259 | 259 | "$cle_depart,$cle_arrivee", |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | } |
| 293 | 293 | if (isset($joint['champs']) and $joint['champs']) { |
| 294 | 294 | foreach ($joint['champs'] as $c => $val) { |
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 295 | + $results[$id]['champs'][$table_liee.'.'.$c] = $val; |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | if (isset($joint['matches']) and $joint['matches']) { |
| 299 | 299 | foreach ($joint['matches'] as $c => $val) { |
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 300 | + $results[$id]['matches'][$table_liee.'.'.$c] = $val; |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 47 | - . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | - . $texte |
|
| 49 | - . '?' . '>'; |
|
| 46 | + $texte = '<' . "?php\n" |
|
| 47 | + . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
|
| 48 | + . $texte |
|
| 49 | + . '?' . '>'; |
|
| 50 | 50 | |
| 51 | - ecrire_fichier($nom, $texte); |
|
| 51 | + ecrire_fichier($nom, $texte); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | * |
| 78 | 78 | **/ |
| 79 | 79 | function install_connexion($adr, $port, $login, $pass, $base, $type, $pref, $ldap = '', $charset = '') { |
| 80 | - $adr = addcslashes($adr, "'\\"); |
|
| 81 | - $port = addcslashes($port, "'\\"); |
|
| 82 | - $login = addcslashes($login, "'\\"); |
|
| 83 | - $pass = addcslashes($pass, "'\\"); |
|
| 84 | - $base = addcslashes($base, "'\\"); |
|
| 85 | - $type = addcslashes($type, "'\\"); |
|
| 86 | - $pref = addcslashes($pref, "'\\"); |
|
| 87 | - $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | - $charset = addcslashes($charset, "'\\"); |
|
| 89 | - |
|
| 90 | - return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | - . 'spip_connect_db(' |
|
| 92 | - . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | - . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 80 | + $adr = addcslashes($adr, "'\\"); |
|
| 81 | + $port = addcslashes($port, "'\\"); |
|
| 82 | + $login = addcslashes($login, "'\\"); |
|
| 83 | + $pass = addcslashes($pass, "'\\"); |
|
| 84 | + $base = addcslashes($base, "'\\"); |
|
| 85 | + $type = addcslashes($type, "'\\"); |
|
| 86 | + $pref = addcslashes($pref, "'\\"); |
|
| 87 | + $ldap = addcslashes($ldap, "'\\"); |
|
| 88 | + $charset = addcslashes($charset, "'\\"); |
|
| 89 | + |
|
| 90 | + return "\$GLOBALS['spip_connect_version'] = 0.8;\n" |
|
| 91 | + . 'spip_connect_db(' |
|
| 92 | + . "'$adr','$port','$login','$pass','$base'" |
|
| 93 | + . ",'$type', '$pref','$ldap','$charset');\n"; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -106,26 +106,26 @@ discard block |
||
| 106 | 106 | * Tableau des informations sur la connexion |
| 107 | 107 | **/ |
| 108 | 108 | function analyse_fichier_connection($file) { |
| 109 | - $s = @join('', file($file)); |
|
| 110 | - if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | - array_shift($regs); |
|
| 112 | - |
|
| 113 | - return $regs; |
|
| 114 | - } else { |
|
| 115 | - $ar = '\s*\'([^\']*)\''; |
|
| 116 | - $r = '\s*,' . $ar; |
|
| 117 | - $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | - if (preg_match($r, $s, $regs)) { |
|
| 119 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 120 | - array_shift($regs); |
|
| 121 | - array_shift($regs); |
|
| 122 | - |
|
| 123 | - return $regs; |
|
| 124 | - } |
|
| 125 | - } |
|
| 126 | - spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | - |
|
| 128 | - return []; |
|
| 109 | + $s = @join('', file($file)); |
|
| 110 | + if (preg_match("#mysql_connect\([\"'](.*)[\"'],[\"'](.*)[\"'],[\"'](.*)[\"']\)#", $s, $regs)) { |
|
| 111 | + array_shift($regs); |
|
| 112 | + |
|
| 113 | + return $regs; |
|
| 114 | + } else { |
|
| 115 | + $ar = '\s*\'([^\']*)\''; |
|
| 116 | + $r = '\s*,' . $ar; |
|
| 117 | + $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
|
| 118 | + if (preg_match($r, $s, $regs)) { |
|
| 119 | + $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 120 | + array_shift($regs); |
|
| 121 | + array_shift($regs); |
|
| 122 | + |
|
| 123 | + return $regs; |
|
| 124 | + } |
|
| 125 | + } |
|
| 126 | + spip_log("$file n'est pas un fichier de connexion"); |
|
| 127 | + |
|
| 128 | + return []; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | * Liste des noms de connecteurs |
| 143 | 143 | **/ |
| 144 | 144 | function bases_referencees($exclu = '') { |
| 145 | - $tables = []; |
|
| 146 | - foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | - if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | - $tables[] = basename($f, '.php'); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $tables; |
|
| 145 | + $tables = []; |
|
| 146 | + foreach (preg_files(_DIR_CONNECT, '.php$') as $f) { |
|
| 147 | + if ($f != $exclu and analyse_fichier_connection($f)) { |
|
| 148 | + $tables[] = basename($f, '.php'); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $tables; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
| 156 | 156 | function install_mode_appel($server_db, $tout = true) { |
| 157 | - return ($server_db != 'mysql') ? '' |
|
| 158 | - : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | - . test_sql_mode_mysql($server_db)); |
|
| 157 | + return ($server_db != 'mysql') ? '' |
|
| 158 | + : (($tout ? test_rappel_nom_base_mysql($server_db) : '') |
|
| 159 | + . test_sql_mode_mysql($server_db)); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | // |
@@ -164,52 +164,52 @@ discard block |
||
| 164 | 164 | // (sert a l'etape 1 de l'installation) |
| 165 | 165 | // https://code.spip.net/@tester_compatibilite_hebergement |
| 166 | 166 | function tester_compatibilite_hebergement() { |
| 167 | - $err = []; |
|
| 168 | - |
|
| 169 | - $p = phpversion(); |
|
| 170 | - if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | - $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 175 | - if ($err) { |
|
| 176 | - die("<div class='error'>" |
|
| 177 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 178 | - . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // Il faut une base de donnees tout de meme ... |
|
| 182 | - $serveurs = install_select_serveur(); |
|
| 183 | - if (!$serveurs) { |
|
| 184 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 185 | - . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 186 | - . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 187 | - . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - // et il faut preg |
|
| 191 | - if (!function_exists('preg_match_all')) { |
|
| 192 | - $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | - . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - // et surtout pas ce mbstring.overload |
|
| 197 | - if ($a = @ini_get('mbstring.func_overload')) { |
|
| 198 | - $err[] = _T('install_extension_mbstring') |
|
| 199 | - . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - if ($err) { |
|
| 203 | - echo "<div class='error'>" |
|
| 204 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | - foreach ($err as $e) { |
|
| 206 | - echo "<li><strong>$e</strong></li>\n"; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 210 | - # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 211 | - echo "</ul></div>\n"; |
|
| 212 | - } |
|
| 167 | + $err = []; |
|
| 168 | + |
|
| 169 | + $p = phpversion(); |
|
| 170 | + if (version_compare($p, _PHP_MIN, '<')) { |
|
| 171 | + $err[] = _T('install_php_version', ['version' => $p, 'minimum' => _PHP_MIN]); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // Si on n'a pas la bonne version de PHP, c'est la fin |
|
| 175 | + if ($err) { |
|
| 176 | + die("<div class='error'>" |
|
| 177 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 178 | + . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // Il faut une base de donnees tout de meme ... |
|
| 182 | + $serveurs = install_select_serveur(); |
|
| 183 | + if (!$serveurs) { |
|
| 184 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 185 | + . " <a href='http://www.php.net/mysql'>MYSQL</a>" |
|
| 186 | + . "| <a href='http://www.php.net/pgsql'>PostgreSQL</a>" |
|
| 187 | + . "| <a href='http://www.php.net/sqlite'>SQLite</a>"; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + // et il faut preg |
|
| 191 | + if (!function_exists('preg_match_all')) { |
|
| 192 | + $err[] = _T('install_extension_php_obligatoire') |
|
| 193 | + . " <a href='http://se.php.net/pcre'>PCRE</a>"; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + // et surtout pas ce mbstring.overload |
|
| 197 | + if ($a = @ini_get('mbstring.func_overload')) { |
|
| 198 | + $err[] = _T('install_extension_mbstring') |
|
| 199 | + . "mbstring.func_overload=$a - <a href='http://www.php.net/mb_string'>mb_string</a>.<br /><small>"; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + if ($err) { |
|
| 203 | + echo "<div class='error'>" |
|
| 204 | + . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 205 | + foreach ($err as $e) { |
|
| 206 | + echo "<li><strong>$e</strong></li>\n"; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + # a priori ici on pourrait die(), mais il faut laisser la possibilite |
|
| 210 | + # de forcer malgre tout (pour tester, ou si bug de detection) |
|
| 211 | + echo "</ul></div>\n"; |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -219,24 +219,24 @@ discard block |
||
| 219 | 219 | * @note superflu ?? |
| 220 | 220 | */ |
| 221 | 221 | function login_hebergeur() { |
| 222 | - $base_hebergeur = 'localhost'; # par defaut |
|
| 222 | + $base_hebergeur = 'localhost'; # par defaut |
|
| 223 | 223 | |
| 224 | - // Free |
|
| 225 | - if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 226 | - $base_hebergeur = 'sql.free.fr'; |
|
| 227 | - $login_hebergeur = $regs[1]; |
|
| 228 | - } else { |
|
| 229 | - $login_hebergeur = ''; |
|
| 230 | - } |
|
| 224 | + // Free |
|
| 225 | + if (preg_match(',(.*)\.free\.fr$,', $_SERVER['SERVER_NAME'], $regs)) { |
|
| 226 | + $base_hebergeur = 'sql.free.fr'; |
|
| 227 | + $login_hebergeur = $regs[1]; |
|
| 228 | + } else { |
|
| 229 | + $login_hebergeur = ''; |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - return [$base_hebergeur, $login_hebergeur]; |
|
| 232 | + return [$base_hebergeur, $login_hebergeur]; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | |
| 236 | 236 | // https://code.spip.net/@info_etape |
| 237 | 237 | function info_etape($titre, $complement = '') { |
| 238 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 239 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 238 | + return '<h2>' . $titre . "</h2>\n" . |
|
| 239 | + ($complement ? '' . $complement . "\n" : ''); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -246,156 +246,156 @@ discard block |
||
| 246 | 246 | * @return string Code HTML du bouton |
| 247 | 247 | **/ |
| 248 | 248 | function bouton_suivant($code = '') { |
| 249 | - if ($code == '') { |
|
| 250 | - $code = _T('bouton_suivant'); |
|
| 251 | - } |
|
| 252 | - static $suivant = 0; |
|
| 253 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | - $suivant += 1; |
|
| 255 | - |
|
| 256 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | - $code . |
|
| 258 | - " >>\" /></p>\n"; |
|
| 249 | + if ($code == '') { |
|
| 250 | + $code = _T('bouton_suivant'); |
|
| 251 | + } |
|
| 252 | + static $suivant = 0; |
|
| 253 | + $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | + $suivant += 1; |
|
| 255 | + |
|
| 256 | + return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | + $code . |
|
| 258 | + " >>\" /></p>\n"; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // https://code.spip.net/@info_progression_etape |
| 262 | 262 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 263 | - //$en_cours = _request('etape')?_request('etape'):""; |
|
| 264 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 265 | - $debut = 1; |
|
| 266 | - $etat = 'ok'; |
|
| 267 | - $last = count($liste); |
|
| 263 | + //$en_cours = _request('etape')?_request('etape'):""; |
|
| 264 | + $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 265 | + $debut = 1; |
|
| 266 | + $etat = 'ok'; |
|
| 267 | + $last = count($liste); |
|
| 268 | 268 | // $texte_etat = array('ok'=>'OK','encours'=>_T('en_cours'),'todo'=>_T('todo')); |
| 269 | 269 | |
| 270 | - $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 271 | - $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 272 | - $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 273 | - $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 270 | + $intitule_etat['etape_'][1] = typo(_T('info_connexion_base_donnee')); |
|
| 271 | + $intitule_etat['etape_'][2] = typo(_T('menu_aide_installation_choix_base')); |
|
| 272 | + $intitule_etat['etape_'][3] = typo(_T('info_informations_personnelles')); |
|
| 273 | + $intitule_etat['etape_'][4] = typo(_T('info_derniere_etape')); |
|
| 274 | 274 | |
| 275 | - $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 276 | - $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 277 | - $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 278 | - $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 279 | - $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 275 | + $intitule_etat['etape_ldap'][1] = typo(_T('titre_connexion_ldap')); |
|
| 276 | + $intitule_etat['etape_ldap'][2] = typo(_T('titre_connexion_ldap')); |
|
| 277 | + $intitule_etat['etape_ldap'][3] = typo(_T('info_chemin_acces_1')); |
|
| 278 | + $intitule_etat['etape_ldap'][4] = typo(_T('info_reglage_ldap')); |
|
| 279 | + $intitule_etat['etape_ldap'][5] = typo(_T('info_ldap_ok')); |
|
| 280 | 280 | |
| 281 | 281 | // $aff_etapes = "<span id='etapes'>"; |
| 282 | 282 | |
| 283 | - $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 284 | - |
|
| 285 | - foreach ($liste as $etape => $fichier) { |
|
| 286 | - if ($debut < $last) { |
|
| 287 | - if ($debut == $en_cours && $erreur) { |
|
| 288 | - $class = 'on erreur'; |
|
| 289 | - } else { |
|
| 290 | - if ($debut == $en_cours) { |
|
| 291 | - $class = 'on'; |
|
| 292 | - } else { |
|
| 293 | - if ($debut > $en_cours) { |
|
| 294 | - $class = 'prochains'; |
|
| 295 | - } else { |
|
| 296 | - $class = 'valides'; |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 302 | - $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 303 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 304 | - $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 305 | - $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 306 | - $aff_etapes .= '</div></li>'; |
|
| 307 | - } |
|
| 308 | - $debut++; |
|
| 309 | - } |
|
| 310 | - $aff_etapes .= '</ul>'; |
|
| 311 | - $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 312 | - |
|
| 313 | - return $aff_etapes; |
|
| 283 | + $aff_etapes = "<ul id='infos_etapes' class='infos_$phase$en_cours'>"; |
|
| 284 | + |
|
| 285 | + foreach ($liste as $etape => $fichier) { |
|
| 286 | + if ($debut < $last) { |
|
| 287 | + if ($debut == $en_cours && $erreur) { |
|
| 288 | + $class = 'on erreur'; |
|
| 289 | + } else { |
|
| 290 | + if ($debut == $en_cours) { |
|
| 291 | + $class = 'on'; |
|
| 292 | + } else { |
|
| 293 | + if ($debut > $en_cours) { |
|
| 294 | + $class = 'prochains'; |
|
| 295 | + } else { |
|
| 296 | + $class = 'valides'; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + $aff_etapes .= "<li class='$class'><div class='fond'>"; |
|
| 302 | + $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
|
| 303 | + $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 304 | + $aff_etapes .= $intitule_etat["$phase"][$debut]; |
|
| 305 | + $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
|
| 306 | + $aff_etapes .= '</div></li>'; |
|
| 307 | + } |
|
| 308 | + $debut++; |
|
| 309 | + } |
|
| 310 | + $aff_etapes .= '</ul>'; |
|
| 311 | + $aff_etapes .= "<br class='nettoyeur' />\n"; |
|
| 312 | + |
|
| 313 | + return $aff_etapes; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | |
| 317 | 317 | // https://code.spip.net/@fieldset |
| 318 | 318 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 319 | - return "<fieldset>\n" . |
|
| 320 | - $avant . |
|
| 321 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 322 | - fieldset_champs($champs) . |
|
| 323 | - $apres . |
|
| 324 | - "</fieldset>\n"; |
|
| 319 | + return "<fieldset>\n" . |
|
| 320 | + $avant . |
|
| 321 | + ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 322 | + fieldset_champs($champs) . |
|
| 323 | + $apres . |
|
| 324 | + "</fieldset>\n"; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | function fieldset_champs($champs = []) { |
| 328 | - $fieldset = ''; |
|
| 329 | - foreach ($champs as $nom => $contenu) { |
|
| 330 | - $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 331 | - $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 332 | - if (isset($contenu['alternatives'])) { |
|
| 333 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 334 | - foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 335 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 336 | - "' id='$nom-$valeur' value='$valeur'" |
|
| 337 | - . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 338 | - . "/>\n"; |
|
| 339 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 340 | - } |
|
| 341 | - $fieldset .= "<br />\n"; |
|
| 342 | - } else { |
|
| 343 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 344 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 345 | - . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 346 | - . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 347 | - . " />\n"; |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return $fieldset; |
|
| 328 | + $fieldset = ''; |
|
| 329 | + foreach ($champs as $nom => $contenu) { |
|
| 330 | + $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
|
| 331 | + $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
|
| 332 | + if (isset($contenu['alternatives'])) { |
|
| 333 | + $fieldset .= $contenu['label'] . "\n"; |
|
| 334 | + foreach ($contenu['alternatives'] as $valeur => $label) { |
|
| 335 | + $fieldset .= "<input type='radio' name='" . $nom . |
|
| 336 | + "' id='$nom-$valeur' value='$valeur'" |
|
| 337 | + . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
|
| 338 | + . "/>\n"; |
|
| 339 | + $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 340 | + } |
|
| 341 | + $fieldset .= "<br />\n"; |
|
| 342 | + } else { |
|
| 343 | + $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 344 | + $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 345 | + . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
|
| 346 | + . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
|
| 347 | + . " />\n"; |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return $fieldset; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | function install_select_serveur() { |
| 355 | - $options = []; |
|
| 356 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 357 | - $d = opendir($dir); |
|
| 358 | - if (!$d) { |
|
| 359 | - return []; |
|
| 360 | - } |
|
| 361 | - while (($f = readdir($d)) !== false) { |
|
| 362 | - if ( |
|
| 363 | - (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 364 | - and is_readable($f = $dir . $f) |
|
| 365 | - ) { |
|
| 366 | - require_once($f); |
|
| 367 | - $s = $s[1]; |
|
| 368 | - $v = 'spip_versions_' . $s; |
|
| 369 | - if (function_exists($v) and $v()) { |
|
| 370 | - $titre = _T("install_select_type_$s"); |
|
| 371 | - // proposer mysql par defaut si dispo |
|
| 372 | - $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 373 | - $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 374 | - . "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>'; |
|
| 375 | - } else { |
|
| 376 | - spip_log("$s: portage indisponible"); |
|
| 377 | - } |
|
| 378 | - } |
|
| 379 | - } |
|
| 380 | - sort($options); |
|
| 381 | - |
|
| 382 | - return $options; |
|
| 355 | + $options = []; |
|
| 356 | + $dir = _DIR_RESTREINT . 'req/'; |
|
| 357 | + $d = opendir($dir); |
|
| 358 | + if (!$d) { |
|
| 359 | + return []; |
|
| 360 | + } |
|
| 361 | + while (($f = readdir($d)) !== false) { |
|
| 362 | + if ( |
|
| 363 | + (preg_match('/^(.*)[.]php$/', $f, $s)) |
|
| 364 | + and is_readable($f = $dir . $f) |
|
| 365 | + ) { |
|
| 366 | + require_once($f); |
|
| 367 | + $s = $s[1]; |
|
| 368 | + $v = 'spip_versions_' . $s; |
|
| 369 | + if (function_exists($v) and $v()) { |
|
| 370 | + $titre = _T("install_select_type_$s"); |
|
| 371 | + // proposer mysql par defaut si dispo |
|
| 372 | + $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
|
| 373 | + $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
|
| 374 | + . "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>'; |
|
| 375 | + } else { |
|
| 376 | + spip_log("$s: portage indisponible"); |
|
| 377 | + } |
|
| 378 | + } |
|
| 379 | + } |
|
| 380 | + sort($options); |
|
| 381 | + |
|
| 382 | + return $options; |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | // https://code.spip.net/@install_connexion_form |
| 386 | 386 | function install_connexion_form($db, $login, $pass, $predef, $hidden, $etape, $jquery = true) { |
| 387 | - $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 388 | - |
|
| 389 | - return generer_form_ecrire('install', ( |
|
| 390 | - "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 391 | - . $hidden |
|
| 392 | - . (_request('echec') ? |
|
| 393 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 395 | - : '') |
|
| 396 | - |
|
| 397 | - . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 398 | - . http_script(' |
|
| 387 | + $server_db = (is_string($predef[0])) ? $predef[0] : ''; |
|
| 388 | + |
|
| 389 | + return generer_form_ecrire('install', ( |
|
| 390 | + "\n<input type='hidden' name='etape' value='$etape' />" |
|
| 391 | + . $hidden |
|
| 392 | + . (_request('echec') ? |
|
| 393 | + ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | + '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 395 | + : '') |
|
| 396 | + |
|
| 397 | + . ($jquery ? http_script('', 'jquery.js') : '') |
|
| 398 | + . http_script(' |
|
| 399 | 399 | jQuery(function($) { |
| 400 | 400 | $details_db = $("#install_adresse_base_hebergeur,#install_login_base_hebergeur,#install_pass_base_hebergeur"); |
| 401 | 401 | $("input[type=hidden][name=server_db]").each(function(){ |
@@ -428,70 +428,70 @@ discard block |
||
| 428 | 428 | }); |
| 429 | 429 | });') |
| 430 | 430 | |
| 431 | - . ($server_db |
|
| 432 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 433 | - . (($predef[0]) |
|
| 434 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 435 | - : '') |
|
| 436 | - : ('<fieldset><legend>' |
|
| 437 | - . _T('install_select_type_db') |
|
| 438 | - . '</legend>' |
|
| 439 | - . '<p class="explication">' |
|
| 440 | - . _T('install_types_db_connus') |
|
| 441 | - // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 442 | - // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 443 | - . '</p>' |
|
| 444 | - . "\n<div class='p'>\n<ul>\n" |
|
| 445 | - . join("\n", install_select_serveur()) |
|
| 446 | - . "\n</ul>\n</div></fieldset>") |
|
| 447 | - ) |
|
| 448 | - . '<div id="install_adresse_base_hebergeur">' |
|
| 449 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 450 | - . ($predef[1] |
|
| 451 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 452 | - : fieldset( |
|
| 453 | - _T('entree_base_donnee_1'), |
|
| 454 | - [ |
|
| 455 | - 'adresse_db' => [ |
|
| 456 | - 'label' => $db[1], |
|
| 457 | - 'valeur' => $db[0] |
|
| 458 | - ], |
|
| 459 | - ] |
|
| 460 | - ) |
|
| 461 | - ) |
|
| 462 | - . '</div>' |
|
| 463 | - |
|
| 464 | - . '<div id="install_login_base_hebergeur">' |
|
| 465 | - . ($predef[2] |
|
| 466 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 467 | - : fieldset( |
|
| 468 | - _T('entree_login_connexion_1'), |
|
| 469 | - [ |
|
| 470 | - 'login_db' => [ |
|
| 471 | - 'label' => $login[1], |
|
| 472 | - 'valeur' => $login[0] |
|
| 473 | - ], |
|
| 474 | - ] |
|
| 475 | - ) |
|
| 476 | - ) |
|
| 477 | - . '</div>' |
|
| 478 | - |
|
| 479 | - . '<div id="install_pass_base_hebergeur">' |
|
| 480 | - . ($predef[3] |
|
| 481 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 482 | - : fieldset( |
|
| 483 | - _T('entree_mot_passe_1'), |
|
| 484 | - [ |
|
| 485 | - 'pass_db' => [ |
|
| 486 | - 'label' => $pass[1], |
|
| 487 | - 'valeur' => $pass[0] |
|
| 488 | - ], |
|
| 489 | - ] |
|
| 490 | - ) |
|
| 491 | - ) |
|
| 492 | - . '</div>' |
|
| 493 | - |
|
| 494 | - . bouton_suivant())); |
|
| 431 | + . ($server_db |
|
| 432 | + ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 433 | + . (($predef[0]) |
|
| 434 | + ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 435 | + : '') |
|
| 436 | + : ('<fieldset><legend>' |
|
| 437 | + . _T('install_select_type_db') |
|
| 438 | + . '</legend>' |
|
| 439 | + . '<p class="explication">' |
|
| 440 | + . _T('install_types_db_connus') |
|
| 441 | + // Passer l'avertissement SQLIte en commentaire, on pourra facilement le supprimer par la suite sans changer les traductions. |
|
| 442 | + // . "<br /><small>(". _T('install_types_db_connus_avertissement') .')</small>' |
|
| 443 | + . '</p>' |
|
| 444 | + . "\n<div class='p'>\n<ul>\n" |
|
| 445 | + . join("\n", install_select_serveur()) |
|
| 446 | + . "\n</ul>\n</div></fieldset>") |
|
| 447 | + ) |
|
| 448 | + . '<div id="install_adresse_base_hebergeur">' |
|
| 449 | + . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 450 | + . ($predef[1] |
|
| 451 | + ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 452 | + : fieldset( |
|
| 453 | + _T('entree_base_donnee_1'), |
|
| 454 | + [ |
|
| 455 | + 'adresse_db' => [ |
|
| 456 | + 'label' => $db[1], |
|
| 457 | + 'valeur' => $db[0] |
|
| 458 | + ], |
|
| 459 | + ] |
|
| 460 | + ) |
|
| 461 | + ) |
|
| 462 | + . '</div>' |
|
| 463 | + |
|
| 464 | + . '<div id="install_login_base_hebergeur">' |
|
| 465 | + . ($predef[2] |
|
| 466 | + ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 467 | + : fieldset( |
|
| 468 | + _T('entree_login_connexion_1'), |
|
| 469 | + [ |
|
| 470 | + 'login_db' => [ |
|
| 471 | + 'label' => $login[1], |
|
| 472 | + 'valeur' => $login[0] |
|
| 473 | + ], |
|
| 474 | + ] |
|
| 475 | + ) |
|
| 476 | + ) |
|
| 477 | + . '</div>' |
|
| 478 | + |
|
| 479 | + . '<div id="install_pass_base_hebergeur">' |
|
| 480 | + . ($predef[3] |
|
| 481 | + ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 482 | + : fieldset( |
|
| 483 | + _T('entree_mot_passe_1'), |
|
| 484 | + [ |
|
| 485 | + 'pass_db' => [ |
|
| 486 | + 'label' => $pass[1], |
|
| 487 | + 'valeur' => $pass[0] |
|
| 488 | + ], |
|
| 489 | + ] |
|
| 490 | + ) |
|
| 491 | + ) |
|
| 492 | + . '</div>' |
|
| 493 | + |
|
| 494 | + . bouton_suivant())); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | // 4 valeurs qu'on reconduit d'un script a l'autre |
@@ -499,76 +499,76 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | // https://code.spip.net/@predef_ou_cache |
| 501 | 501 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 502 | - return ((defined('_INSTALL_HOST_DB')) |
|
| 503 | - ? '' |
|
| 504 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 505 | - ) |
|
| 506 | - . ((defined('_INSTALL_USER_DB')) |
|
| 507 | - ? '' |
|
| 508 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 509 | - ) |
|
| 510 | - . ((defined('_INSTALL_PASS_DB')) |
|
| 511 | - ? '' |
|
| 512 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 513 | - ) |
|
| 514 | - |
|
| 515 | - . ((defined('_INSTALL_SERVER_DB')) |
|
| 516 | - ? '' |
|
| 517 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 518 | - ); |
|
| 502 | + return ((defined('_INSTALL_HOST_DB')) |
|
| 503 | + ? '' |
|
| 504 | + : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 505 | + ) |
|
| 506 | + . ((defined('_INSTALL_USER_DB')) |
|
| 507 | + ? '' |
|
| 508 | + : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 509 | + ) |
|
| 510 | + . ((defined('_INSTALL_PASS_DB')) |
|
| 511 | + ? '' |
|
| 512 | + : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 513 | + ) |
|
| 514 | + |
|
| 515 | + . ((defined('_INSTALL_SERVER_DB')) |
|
| 516 | + ? '' |
|
| 517 | + : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 518 | + ); |
|
| 519 | 519 | } |
| 520 | 520 | |
| 521 | 521 | // presentation des bases existantes |
| 522 | 522 | |
| 523 | 523 | // https://code.spip.net/@install_etape_liste_bases |
| 524 | 524 | function install_etape_liste_bases($server_db, $login_db, $disabled = []) { |
| 525 | - $bases = $checked = []; |
|
| 526 | - $noms = sql_listdbs($server_db); |
|
| 527 | - if (!$noms) { |
|
| 528 | - return ''; |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - foreach ($noms as $nom) { |
|
| 532 | - $id = spip_htmlspecialchars($nom); |
|
| 533 | - $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 534 | - $base = ' name="choix_db" value="' |
|
| 535 | - . $nom |
|
| 536 | - . '"' |
|
| 537 | - . $dis |
|
| 538 | - . " type='radio' id='$id'"; |
|
| 539 | - $label = "<label for='$id'>" |
|
| 540 | - . ($dis ? "<i>$nom</i>" : $nom) |
|
| 541 | - . '</label>'; |
|
| 542 | - |
|
| 543 | - if ( |
|
| 544 | - !$checked and !$dis and |
|
| 545 | - (($nom == $login_db) or |
|
| 546 | - ($GLOBALS['table_prefix'] == $nom)) |
|
| 547 | - ) { |
|
| 548 | - $checked = "<input$base checked='checked' />\n$label"; |
|
| 549 | - } else { |
|
| 550 | - $bases[] = "<input$base />\n$label"; |
|
| 551 | - } |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if (!$bases && !$checked) { |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - if ($checked) { |
|
| 559 | - array_unshift($bases, $checked); |
|
| 560 | - $checked = true; |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - return [$checked, $bases]; |
|
| 525 | + $bases = $checked = []; |
|
| 526 | + $noms = sql_listdbs($server_db); |
|
| 527 | + if (!$noms) { |
|
| 528 | + return ''; |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + foreach ($noms as $nom) { |
|
| 532 | + $id = spip_htmlspecialchars($nom); |
|
| 533 | + $dis = in_array($nom, $disabled) ? " disabled='disabled'" : ''; |
|
| 534 | + $base = ' name="choix_db" value="' |
|
| 535 | + . $nom |
|
| 536 | + . '"' |
|
| 537 | + . $dis |
|
| 538 | + . " type='radio' id='$id'"; |
|
| 539 | + $label = "<label for='$id'>" |
|
| 540 | + . ($dis ? "<i>$nom</i>" : $nom) |
|
| 541 | + . '</label>'; |
|
| 542 | + |
|
| 543 | + if ( |
|
| 544 | + !$checked and !$dis and |
|
| 545 | + (($nom == $login_db) or |
|
| 546 | + ($GLOBALS['table_prefix'] == $nom)) |
|
| 547 | + ) { |
|
| 548 | + $checked = "<input$base checked='checked' />\n$label"; |
|
| 549 | + } else { |
|
| 550 | + $bases[] = "<input$base />\n$label"; |
|
| 551 | + } |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if (!$bases && !$checked) { |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + if ($checked) { |
|
| 559 | + array_unshift($bases, $checked); |
|
| 560 | + $checked = true; |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + return [$checked, $bases]; |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | function install_propager($hidden) { |
| 567 | - $res = ''; |
|
| 568 | - foreach ($hidden as $k) { |
|
| 569 | - $v = spip_htmlentities(_request($k)); |
|
| 570 | - $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 571 | - } |
|
| 567 | + $res = ''; |
|
| 568 | + foreach ($hidden as $k) { |
|
| 569 | + $v = spip_htmlentities(_request($k)); |
|
| 570 | + $res .= "<input type='hidden' name='$k' value='$v' />"; |
|
| 571 | + } |
|
| 572 | 572 | |
| 573 | - return $res; |
|
| 573 | + return $res; |
|
| 574 | 574 | } |
@@ -43,10 +43,10 @@ discard block |
||
| 43 | 43 | * @return void |
| 44 | 44 | **/ |
| 45 | 45 | function install_fichier_connexion($nom, $texte) { |
| 46 | - $texte = '<' . "?php\n" |
|
| 46 | + $texte = '<'."?php\n" |
|
| 47 | 47 | . "if (!defined(\"_ECRIRE_INC_VERSION\")) return;\n" |
| 48 | 48 | . $texte |
| 49 | - . '?' . '>'; |
|
| 49 | + . '?'.'>'; |
|
| 50 | 50 | |
| 51 | 51 | ecrire_fichier($nom, $texte); |
| 52 | 52 | } |
@@ -113,10 +113,10 @@ discard block |
||
| 113 | 113 | return $regs; |
| 114 | 114 | } else { |
| 115 | 115 | $ar = '\s*\'([^\']*)\''; |
| 116 | - $r = '\s*,' . $ar; |
|
| 116 | + $r = '\s*,'.$ar; |
|
| 117 | 117 | $r = "#spip_connect_db[(]$ar$r$r$r$r(?:$r(?:$r(?:$r(?:$r)?)?)?)?#"; |
| 118 | 118 | if (preg_match($r, $s, $regs)) { |
| 119 | - $regs[2] = $regs[1] . (!$regs[2] ? '' : ':' . $regs[2] . ';'); |
|
| 119 | + $regs[2] = $regs[1].(!$regs[2] ? '' : ':'.$regs[2].';'); |
|
| 120 | 120 | array_shift($regs); |
| 121 | 121 | array_shift($regs); |
| 122 | 122 | |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | // Si on n'a pas la bonne version de PHP, c'est la fin |
| 175 | 175 | if ($err) { |
| 176 | 176 | die("<div class='error'>" |
| 177 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>" |
|
| 177 | + . '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>" |
|
| 178 | 178 | . "<li><strong>{$err[0]}</strong></li>\n</ul></div>"); |
| 179 | 179 | } |
| 180 | 180 | |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | if ($err) { |
| 203 | 203 | echo "<div class='error'>" |
| 204 | - . '<h3>' . _T('avis_attention') . '</h3><p>' . _T('install_echec_annonce') . "</p><ul class='spip'>"; |
|
| 204 | + . '<h3>'._T('avis_attention').'</h3><p>'._T('install_echec_annonce')."</p><ul class='spip'>"; |
|
| 205 | 205 | foreach ($err as $e) { |
| 206 | 206 | echo "<li><strong>$e</strong></li>\n"; |
| 207 | 207 | } |
@@ -235,8 +235,8 @@ discard block |
||
| 235 | 235 | |
| 236 | 236 | // https://code.spip.net/@info_etape |
| 237 | 237 | function info_etape($titre, $complement = '') { |
| 238 | - return '<h2>' . $titre . "</h2>\n" . |
|
| 239 | - ($complement ? '' . $complement . "\n" : ''); |
|
| 238 | + return '<h2>'.$titre."</h2>\n". |
|
| 239 | + ($complement ? ''.$complement."\n" : ''); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -250,18 +250,18 @@ discard block |
||
| 250 | 250 | $code = _T('bouton_suivant'); |
| 251 | 251 | } |
| 252 | 252 | static $suivant = 0; |
| 253 | - $id = 'suivant' . (($suivant > 0) ? strval($suivant) : ''); |
|
| 253 | + $id = 'suivant'.(($suivant > 0) ? strval($suivant) : ''); |
|
| 254 | 254 | $suivant += 1; |
| 255 | 255 | |
| 256 | - return "\n<p class='boutons suivant'><input id='" . $id . "' type='submit'\nvalue=\"" . |
|
| 257 | - $code . |
|
| 256 | + return "\n<p class='boutons suivant'><input id='".$id."' type='submit'\nvalue=\"". |
|
| 257 | + $code. |
|
| 258 | 258 | " >>\" /></p>\n"; |
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | // https://code.spip.net/@info_progression_etape |
| 262 | 262 | function info_progression_etape($en_cours, $phase, $dir, $erreur = false) { |
| 263 | 263 | //$en_cours = _request('etape')?_request('etape'):""; |
| 264 | - $liste = find_all_in_path($dir, $phase . '(([0-9])+|fin)[.]php$'); |
|
| 264 | + $liste = find_all_in_path($dir, $phase.'(([0-9])+|fin)[.]php$'); |
|
| 265 | 265 | $debut = 1; |
| 266 | 266 | $etat = 'ok'; |
| 267 | 267 | $last = count($liste); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | |
| 301 | 301 | $aff_etapes .= "<li class='$class'><div class='fond'>"; |
| 302 | 302 | $aff_etapes .= ($debut == $en_cours) ? '<strong>' : ''; |
| 303 | - $aff_etapes .= '<em>' . _T('etape') . " </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 303 | + $aff_etapes .= '<em>'._T('etape')." </em><span class='numero_etape'>$debut</span><em> : </em>"; |
|
| 304 | 304 | $aff_etapes .= $intitule_etat["$phase"][$debut]; |
| 305 | 305 | $aff_etapes .= ($debut == $en_cours) ? '</strong>' : ''; |
| 306 | 306 | $aff_etapes .= '</div></li>'; |
@@ -316,11 +316,11 @@ discard block |
||
| 316 | 316 | |
| 317 | 317 | // https://code.spip.net/@fieldset |
| 318 | 318 | function fieldset($legend, $champs = [], $apres = '', $avant = '') { |
| 319 | - return "<fieldset>\n" . |
|
| 320 | - $avant . |
|
| 321 | - ($legend ? '<legend>' . $legend . "</legend>\n" : '') . |
|
| 322 | - fieldset_champs($champs) . |
|
| 323 | - $apres . |
|
| 319 | + return "<fieldset>\n". |
|
| 320 | + $avant. |
|
| 321 | + ($legend ? '<legend>'.$legend."</legend>\n" : ''). |
|
| 322 | + fieldset_champs($champs). |
|
| 323 | + $apres. |
|
| 324 | 324 | "</fieldset>\n"; |
| 325 | 325 | } |
| 326 | 326 | |
@@ -330,18 +330,18 @@ discard block |
||
| 330 | 330 | $type = isset($contenu['hidden']) ? 'hidden' : (preg_match(',^pass,', $nom) ? 'password' : 'text'); |
| 331 | 331 | $class = isset($contenu['hidden']) ? '' : "class='formo' size='40' "; |
| 332 | 332 | if (isset($contenu['alternatives'])) { |
| 333 | - $fieldset .= $contenu['label'] . "\n"; |
|
| 333 | + $fieldset .= $contenu['label']."\n"; |
|
| 334 | 334 | foreach ($contenu['alternatives'] as $valeur => $label) { |
| 335 | - $fieldset .= "<input type='radio' name='" . $nom . |
|
| 335 | + $fieldset .= "<input type='radio' name='".$nom. |
|
| 336 | 336 | "' id='$nom-$valeur' value='$valeur'" |
| 337 | 337 | . (($valeur == $contenu['valeur']) ? "\nchecked='checked'" : '') |
| 338 | 338 | . "/>\n"; |
| 339 | - $fieldset .= "<label for='$nom-$valeur'>" . $label . "</label>\n"; |
|
| 339 | + $fieldset .= "<label for='$nom-$valeur'>".$label."</label>\n"; |
|
| 340 | 340 | } |
| 341 | 341 | $fieldset .= "<br />\n"; |
| 342 | 342 | } else { |
| 343 | - $fieldset .= "<label for='" . $nom . "'>" . $contenu['label'] . "</label>\n"; |
|
| 344 | - $fieldset .= '<input ' . $class . "type='" . $type . "' id='" . $nom . "' name='" . $nom . "'\nvalue='" . $contenu['valeur'] . "'" |
|
| 343 | + $fieldset .= "<label for='".$nom."'>".$contenu['label']."</label>\n"; |
|
| 344 | + $fieldset .= '<input '.$class."type='".$type."' id='".$nom."' name='".$nom."'\nvalue='".$contenu['valeur']."'" |
|
| 345 | 345 | . (preg_match(',^(pass|login),', $nom) ? " autocomplete='off'" : '') |
| 346 | 346 | . ((isset($contenu['required']) and $contenu['required']) ? " required='required'" : '') |
| 347 | 347 | . " />\n"; |
@@ -353,7 +353,7 @@ discard block |
||
| 353 | 353 | |
| 354 | 354 | function install_select_serveur() { |
| 355 | 355 | $options = []; |
| 356 | - $dir = _DIR_RESTREINT . 'req/'; |
|
| 356 | + $dir = _DIR_RESTREINT.'req/'; |
|
| 357 | 357 | $d = opendir($dir); |
| 358 | 358 | if (!$d) { |
| 359 | 359 | return []; |
@@ -361,17 +361,17 @@ discard block |
||
| 361 | 361 | while (($f = readdir($d)) !== false) { |
| 362 | 362 | if ( |
| 363 | 363 | (preg_match('/^(.*)[.]php$/', $f, $s)) |
| 364 | - and is_readable($f = $dir . $f) |
|
| 364 | + and is_readable($f = $dir.$f) |
|
| 365 | 365 | ) { |
| 366 | 366 | require_once($f); |
| 367 | 367 | $s = $s[1]; |
| 368 | - $v = 'spip_versions_' . $s; |
|
| 368 | + $v = 'spip_versions_'.$s; |
|
| 369 | 369 | if (function_exists($v) and $v()) { |
| 370 | 370 | $titre = _T("install_select_type_$s"); |
| 371 | 371 | // proposer mysql par defaut si dispo |
| 372 | 372 | $checked = ($s == 'mysql' ? " checked='checked'" : ''); |
| 373 | 373 | $options[$s] = "<li><input type='radio' id='$s' value='$s' name='server_db'$checked>" |
| 374 | - . "<label for='$s'>" . ($titre ? $titre : $s) . '</label></li>'; |
|
| 374 | + . "<label for='$s'>".($titre ? $titre : $s).'</label></li>'; |
|
| 375 | 375 | } else { |
| 376 | 376 | spip_log("$s: portage indisponible"); |
| 377 | 377 | } |
@@ -390,8 +390,8 @@ discard block |
||
| 390 | 390 | "\n<input type='hidden' name='etape' value='$etape' />" |
| 391 | 391 | . $hidden |
| 392 | 392 | . (_request('echec') ? |
| 393 | - ('<p><b>' . _T('avis_connexion_echec_1') . |
|
| 394 | - '</b></p><p>' . _T('avis_connexion_echec_2') . "</p><p style='font-size: small;'>" . _T('avis_connexion_echec_3') . '</p>') |
|
| 393 | + ('<p><b>'._T('avis_connexion_echec_1'). |
|
| 394 | + '</b></p><p>'._T('avis_connexion_echec_2')."</p><p style='font-size: small;'>"._T('avis_connexion_echec_3').'</p>') |
|
| 395 | 395 | : '') |
| 396 | 396 | |
| 397 | 397 | . ($jquery ? http_script('', 'jquery.js') : '') |
@@ -429,9 +429,9 @@ discard block |
||
| 429 | 429 | });') |
| 430 | 430 | |
| 431 | 431 | . ($server_db |
| 432 | - ? '<input type="hidden" name="server_db" value="' . $server_db . '" />' |
|
| 432 | + ? '<input type="hidden" name="server_db" value="'.$server_db.'" />' |
|
| 433 | 433 | . (($predef[0]) |
| 434 | - ? ('<h3>' . _T('install_serveur_hebergeur') . '</h3>') |
|
| 434 | + ? ('<h3>'._T('install_serveur_hebergeur').'</h3>') |
|
| 435 | 435 | : '') |
| 436 | 436 | : ('<fieldset><legend>' |
| 437 | 437 | . _T('install_select_type_db') |
@@ -446,9 +446,9 @@ discard block |
||
| 446 | 446 | . "\n</ul>\n</div></fieldset>") |
| 447 | 447 | ) |
| 448 | 448 | . '<div id="install_adresse_base_hebergeur">' |
| 449 | - . '<p>' . _T('texte_connexion_mysql') . '</p>' |
|
| 449 | + . '<p>'._T('texte_connexion_mysql').'</p>' |
|
| 450 | 450 | . ($predef[1] |
| 451 | - ? '<h3>' . _T('install_adresse_base_hebergeur') . '</h3>' |
|
| 451 | + ? '<h3>'._T('install_adresse_base_hebergeur').'</h3>' |
|
| 452 | 452 | : fieldset( |
| 453 | 453 | _T('entree_base_donnee_1'), |
| 454 | 454 | [ |
@@ -463,7 +463,7 @@ discard block |
||
| 463 | 463 | |
| 464 | 464 | . '<div id="install_login_base_hebergeur">' |
| 465 | 465 | . ($predef[2] |
| 466 | - ? '<h3>' . _T('install_login_base_hebergeur') . '</h3>' |
|
| 466 | + ? '<h3>'._T('install_login_base_hebergeur').'</h3>' |
|
| 467 | 467 | : fieldset( |
| 468 | 468 | _T('entree_login_connexion_1'), |
| 469 | 469 | [ |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | |
| 479 | 479 | . '<div id="install_pass_base_hebergeur">' |
| 480 | 480 | . ($predef[3] |
| 481 | - ? '<h3>' . _T('install_pass_base_hebergeur') . '</h3>' |
|
| 481 | + ? '<h3>'._T('install_pass_base_hebergeur').'</h3>' |
|
| 482 | 482 | : fieldset( |
| 483 | 483 | _T('entree_mot_passe_1'), |
| 484 | 484 | [ |
@@ -501,20 +501,20 @@ discard block |
||
| 501 | 501 | function predef_ou_cache($adresse_db, $login_db, $pass_db, $server_db) { |
| 502 | 502 | return ((defined('_INSTALL_HOST_DB')) |
| 503 | 503 | ? '' |
| 504 | - : "\n<input type='hidden' name='adresse_db' value=\"" . spip_htmlspecialchars($adresse_db) . '" />' |
|
| 504 | + : "\n<input type='hidden' name='adresse_db' value=\"".spip_htmlspecialchars($adresse_db).'" />' |
|
| 505 | 505 | ) |
| 506 | 506 | . ((defined('_INSTALL_USER_DB')) |
| 507 | 507 | ? '' |
| 508 | - : "\n<input type='hidden' name='login_db' value=\"" . spip_htmlspecialchars($login_db) . '" />' |
|
| 508 | + : "\n<input type='hidden' name='login_db' value=\"".spip_htmlspecialchars($login_db).'" />' |
|
| 509 | 509 | ) |
| 510 | 510 | . ((defined('_INSTALL_PASS_DB')) |
| 511 | 511 | ? '' |
| 512 | - : "\n<input type='hidden' name='pass_db' value=\"" . spip_htmlspecialchars($pass_db) . '" />' |
|
| 512 | + : "\n<input type='hidden' name='pass_db' value=\"".spip_htmlspecialchars($pass_db).'" />' |
|
| 513 | 513 | ) |
| 514 | 514 | |
| 515 | 515 | . ((defined('_INSTALL_SERVER_DB')) |
| 516 | 516 | ? '' |
| 517 | - : "\n<input type='hidden' name='server_db' value=\"" . spip_htmlspecialchars($server_db) . '" />' |
|
| 517 | + : "\n<input type='hidden' name='server_db' value=\"".spip_htmlspecialchars($server_db).'" />' |
|
| 518 | 518 | ); |
| 519 | 519 | } |
| 520 | 520 | |
@@ -11,71 +11,71 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/boutons'); |
| 18 | 18 | include_spip('base/objets'); |
| 19 | 19 | |
| 20 | 20 | function inc_icone_renommer_dist($fond, $fonction) { |
| 21 | - $size = 24; |
|
| 22 | - if ( |
|
| 23 | - preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match) |
|
| 24 | - and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1])) |
|
| 25 | - ) { |
|
| 26 | - if (isset($match[1]) and $match[1]) { |
|
| 27 | - $size = $match[1]; |
|
| 28 | - } |
|
| 29 | - $type = substr($fond, 0, -strlen($match[0])); |
|
| 30 | - if (!isset($match[2]) or !$match[2]) { |
|
| 31 | - $fond .= '.png'; |
|
| 32 | - } |
|
| 33 | - } else { |
|
| 34 | - $type = $fond; |
|
| 35 | - $fond .= '.png'; |
|
| 36 | - } |
|
| 21 | + $size = 24; |
|
| 22 | + if ( |
|
| 23 | + preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match) |
|
| 24 | + and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1])) |
|
| 25 | + ) { |
|
| 26 | + if (isset($match[1]) and $match[1]) { |
|
| 27 | + $size = $match[1]; |
|
| 28 | + } |
|
| 29 | + $type = substr($fond, 0, -strlen($match[0])); |
|
| 30 | + if (!isset($match[2]) or !$match[2]) { |
|
| 31 | + $fond .= '.png'; |
|
| 32 | + } |
|
| 33 | + } else { |
|
| 34 | + $type = $fond; |
|
| 35 | + $fond .= '.png'; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $rtl = false; |
|
| 39 | - if (preg_match(',[-_]rtl$,i', $type, $match)) { |
|
| 40 | - $rtl = true; |
|
| 41 | - $type = substr($type, 0, -strlen($match[0])); |
|
| 42 | - } |
|
| 38 | + $rtl = false; |
|
| 39 | + if (preg_match(',[-_]rtl$,i', $type, $match)) { |
|
| 40 | + $rtl = true; |
|
| 41 | + $type = substr($type, 0, -strlen($match[0])); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // objet_type garde invariant tout ce qui ne commence par par id_, spip_ |
|
| 45 | - // et ne finit pas par un s, sauf si c'est une exception declaree |
|
| 46 | - $type = objet_type($type, false); |
|
| 44 | + // objet_type garde invariant tout ce qui ne commence par par id_, spip_ |
|
| 45 | + // et ne finit pas par un s, sauf si c'est une exception declaree |
|
| 46 | + $type = objet_type($type, false); |
|
| 47 | 47 | |
| 48 | - $dir = 'images/'; |
|
| 49 | - $f = "$type-$size.png"; |
|
| 50 | - if ($icone = find_in_theme($dir . $f)) { |
|
| 51 | - $dir = dirname($icone); |
|
| 52 | - $fond = $icone; |
|
| 48 | + $dir = 'images/'; |
|
| 49 | + $f = "$type-$size.png"; |
|
| 50 | + if ($icone = find_in_theme($dir . $f)) { |
|
| 51 | + $dir = dirname($icone); |
|
| 52 | + $fond = $icone; |
|
| 53 | 53 | |
| 54 | - if ( |
|
| 55 | - $rtl |
|
| 56 | - and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 57 | - and file_exists($fr) |
|
| 58 | - ) { |
|
| 59 | - $fond = $fr; |
|
| 60 | - } |
|
| 54 | + if ( |
|
| 55 | + $rtl |
|
| 56 | + and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 57 | + and file_exists($fr) |
|
| 58 | + ) { |
|
| 59 | + $fond = $fr; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $action = $fonction; |
|
| 63 | - if ($action == 'supprimer.gif') { |
|
| 64 | - $action = 'del'; |
|
| 65 | - } elseif ($action == 'creer.gif') { |
|
| 66 | - $action = 'new'; |
|
| 67 | - } elseif ($action == 'edit.gif') { |
|
| 68 | - $action = 'edit'; |
|
| 69 | - } |
|
| 62 | + $action = $fonction; |
|
| 63 | + if ($action == 'supprimer.gif') { |
|
| 64 | + $action = 'del'; |
|
| 65 | + } elseif ($action == 'creer.gif') { |
|
| 66 | + $action = 'new'; |
|
| 67 | + } elseif ($action == 'edit.gif') { |
|
| 68 | + $action = 'edit'; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $fonction = ''; |
|
| 72 | - if (in_array($action, ['add','del', 'new', 'edit', 'config'])) { |
|
| 73 | - $fonction = $action; |
|
| 74 | - } |
|
| 71 | + $fonction = ''; |
|
| 72 | + if (in_array($action, ['add','del', 'new', 'edit', 'config'])) { |
|
| 73 | + $fonction = $action; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // c'est bon ! |
|
| 77 | - return [$fond, $fonction]; |
|
| 78 | - } |
|
| 76 | + // c'est bon ! |
|
| 77 | + return [$fond, $fonction]; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return [$fond, $fonction]; |
|
| 80 | + return [$fond, $fonction]; |
|
| 81 | 81 | } |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $dir = 'images/'; |
| 49 | 49 | $f = "$type-$size.png"; |
| 50 | - if ($icone = find_in_theme($dir . $f)) { |
|
| 50 | + if ($icone = find_in_theme($dir.$f)) { |
|
| 51 | 51 | $dir = dirname($icone); |
| 52 | 52 | $fond = $icone; |
| 53 | 53 | |
| 54 | 54 | if ( |
| 55 | 55 | $rtl |
| 56 | - and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 56 | + and $fr = $dir.'/'.str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 57 | 57 | and file_exists($fr) |
| 58 | 58 | ) { |
| 59 | 59 | $fond = $fr; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $fonction = ''; |
| 72 | - if (in_array($action, ['add','del', 'new', 'edit', 'config'])) { |
|
| 72 | + if (in_array($action, ['add', 'del', 'new', 'edit', 'config'])) { |
|
| 73 | 73 | $fonction = $action; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -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 | include_spip('inc/autoriser'); |
@@ -30,80 +30,80 @@ discard block |
||
| 30 | 30 | * Un tableau des sous rubriques |
| 31 | 31 | */ |
| 32 | 32 | function enfant_rub($collection, $debut = 0, $limite = 500) { |
| 33 | - $voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non'); |
|
| 34 | - $logo = ''; |
|
| 35 | - |
|
| 36 | - if ($voir_logo) { |
|
| 37 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 38 | - include_spip('inc/filtres_images_mini'); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - $res = []; |
|
| 42 | - |
|
| 43 | - $result = sql_select( |
|
| 44 | - 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 45 | - 'spip_rubriques', |
|
| 46 | - 'id_parent=' . intval($collection), |
|
| 47 | - '', |
|
| 48 | - '0+titre,titre', |
|
| 49 | - "$debut,$limite" |
|
| 50 | - ); |
|
| 51 | - while ($row = sql_fetch($result)) { |
|
| 52 | - $id_rubrique = $row['id_rubrique']; |
|
| 53 | - $id_parent = $row['id_parent']; |
|
| 54 | - // pour etre sur de passer par tous les traitements |
|
| 55 | - $titre = generer_info_entite($id_rubrique, 'rubrique', 'titre'); |
|
| 56 | - if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 57 | - $rang = "<span class='rang'>$rang.</span> "; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 61 | - $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 62 | - |
|
| 63 | - changer_typo($row['lang']); |
|
| 64 | - $lang_dir = lang_dir($row['lang']); |
|
| 65 | - $descriptif = propre($row['descriptif']); |
|
| 66 | - |
|
| 67 | - if ($voir_logo) { |
|
| 68 | - if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) { |
|
| 69 | - list($fid, $dir, $nom, $format) = $logo; |
|
| 70 | - $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 71 | - if ($logo) { |
|
| 72 | - $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : |
|
| 78 | - http_img_pack( |
|
| 79 | - 'auteur-0minirezo-16.png', |
|
| 80 | - '', |
|
| 81 | - " width='16' height='16'", |
|
| 82 | - _T('image_administrer_rubrique') |
|
| 83 | - )) . |
|
| 84 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 85 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 86 | - " href='" . |
|
| 87 | - generer_url_entite($id_rubrique, 'rubrique') . |
|
| 88 | - "'><span class='titre'>" . |
|
| 89 | - $rang . $titre |
|
| 90 | - . '</span>' |
|
| 91 | - . (is_string($logo) ? $logo : '') |
|
| 92 | - . '</a>'; |
|
| 93 | - |
|
| 94 | - $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 95 | - . (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>") |
|
| 96 | - ; |
|
| 97 | - |
|
| 98 | - $res[] = |
|
| 99 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 100 | - $les_sous_enfants . |
|
| 101 | - fin_cadre_sous_rub(true); |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 106 | - return $res; |
|
| 33 | + $voir_logo = (isset($GLOBALS['meta']['image_process']) and $GLOBALS['meta']['image_process'] != 'non'); |
|
| 34 | + $logo = ''; |
|
| 35 | + |
|
| 36 | + if ($voir_logo) { |
|
| 37 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 38 | + include_spip('inc/filtres_images_mini'); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + $res = []; |
|
| 42 | + |
|
| 43 | + $result = sql_select( |
|
| 44 | + 'id_rubrique, id_parent, titre, descriptif, lang', |
|
| 45 | + 'spip_rubriques', |
|
| 46 | + 'id_parent=' . intval($collection), |
|
| 47 | + '', |
|
| 48 | + '0+titre,titre', |
|
| 49 | + "$debut,$limite" |
|
| 50 | + ); |
|
| 51 | + while ($row = sql_fetch($result)) { |
|
| 52 | + $id_rubrique = $row['id_rubrique']; |
|
| 53 | + $id_parent = $row['id_parent']; |
|
| 54 | + // pour etre sur de passer par tous les traitements |
|
| 55 | + $titre = generer_info_entite($id_rubrique, 'rubrique', 'titre'); |
|
| 56 | + if ('' !== ($rang = recuperer_numero($row['titre']))) { |
|
| 57 | + $rang = "<span class='rang'>$rang.</span> "; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (autoriser('voir', 'rubrique', $id_rubrique)) { |
|
| 61 | + $les_sous_enfants = sous_enfant_rub($id_rubrique); |
|
| 62 | + |
|
| 63 | + changer_typo($row['lang']); |
|
| 64 | + $lang_dir = lang_dir($row['lang']); |
|
| 65 | + $descriptif = propre($row['descriptif']); |
|
| 66 | + |
|
| 67 | + if ($voir_logo) { |
|
| 68 | + if ($logo = $chercher_logo($id_rubrique, 'id_rubrique', 'on')) { |
|
| 69 | + list($fid, $dir, $nom, $format) = $logo; |
|
| 70 | + $logo = image_recadre_avec_fallback("<img src='$fid' alt='' />", 70, 70); |
|
| 71 | + if ($logo) { |
|
| 72 | + $logo = wrap(inserer_attribut($logo, 'class', 'logo'), '<span class="logo-carre">'); |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : |
|
| 78 | + http_img_pack( |
|
| 79 | + 'auteur-0minirezo-16.png', |
|
| 80 | + '', |
|
| 81 | + " width='16' height='16'", |
|
| 82 | + _T('image_administrer_rubrique') |
|
| 83 | + )) . |
|
| 84 | + " <a class='titremlien' dir='$lang_dir'" . |
|
| 85 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 86 | + " href='" . |
|
| 87 | + generer_url_entite($id_rubrique, 'rubrique') . |
|
| 88 | + "'><span class='titre'>" . |
|
| 89 | + $rang . $titre |
|
| 90 | + . '</span>' |
|
| 91 | + . (is_string($logo) ? $logo : '') |
|
| 92 | + . '</a>'; |
|
| 93 | + |
|
| 94 | + $titre = bouton_block_depliable($lib_bouton, $les_sous_enfants ? false : -1, "enfants$id_rubrique") |
|
| 95 | + . (!$descriptif ? '' : "\n<div class='descriptif'>$descriptif</div>") |
|
| 96 | + ; |
|
| 97 | + |
|
| 98 | + $res[] = |
|
| 99 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 100 | + $les_sous_enfants . |
|
| 101 | + fin_cadre_sous_rub(true); |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + changer_typo($GLOBALS['spip_lang']); # remettre la typo de l'interface pour la suite |
|
| 106 | + return $res; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -116,71 +116,71 @@ discard block |
||
| 116 | 116 | * Le contenu du bloc dépliable |
| 117 | 117 | */ |
| 118 | 118 | function sous_enfant_rub($collection2) { |
| 119 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2)); |
|
| 120 | - |
|
| 121 | - $retour = ''; |
|
| 122 | - $pagination = ''; |
|
| 123 | - $debut = 0; |
|
| 124 | - $limite = 500; |
|
| 125 | - |
|
| 126 | - /** |
|
| 127 | - * On ne va afficher que 500 résultats max |
|
| 128 | - * Si > 500 on affiche une pagination |
|
| 129 | - */ |
|
| 130 | - if ($nb > $limite) { |
|
| 131 | - $debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut; |
|
| 132 | - $pagination = chercher_filtre('pagination'); |
|
| 133 | - $pagination = '<p class="pagination">' . $pagination( |
|
| 134 | - $nb, |
|
| 135 | - '_rubrique' . $collection2, |
|
| 136 | - $debut, |
|
| 137 | - $limite, |
|
| 138 | - true, |
|
| 139 | - 'prive' |
|
| 140 | - ) . '</p>'; |
|
| 141 | - $limite = $debut + $limite; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - $result = sql_select( |
|
| 145 | - 'id_rubrique, id_parent, titre, lang', |
|
| 146 | - 'spip_rubriques', |
|
| 147 | - 'id_parent=' . intval($collection2), |
|
| 148 | - '', |
|
| 149 | - '0+titre,titre', |
|
| 150 | - "$debut,$limite" |
|
| 151 | - ); |
|
| 152 | - |
|
| 153 | - while ($row = sql_fetch($result)) { |
|
| 154 | - $id_rubrique2 = $row['id_rubrique']; |
|
| 155 | - $titre2 = generer_info_entite( |
|
| 156 | - $id_rubrique2, |
|
| 157 | - 'rubrique', |
|
| 158 | - 'titre' |
|
| 159 | - ); // pour etre sur de passer par tous les traitements |
|
| 160 | - if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 161 | - $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - changer_typo($row['lang']); |
|
| 165 | - $lang_dir = lang_dir($row['lang']); |
|
| 166 | - if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 167 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite( |
|
| 168 | - $id_rubrique2, |
|
| 169 | - 'rubrique' |
|
| 170 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - $retour = $pagination . $retour . $pagination; |
|
| 175 | - |
|
| 176 | - if (!$retour) { |
|
| 177 | - return ''; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2") |
|
| 181 | - . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 182 | - . $retour |
|
| 183 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 119 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2)); |
|
| 120 | + |
|
| 121 | + $retour = ''; |
|
| 122 | + $pagination = ''; |
|
| 123 | + $debut = 0; |
|
| 124 | + $limite = 500; |
|
| 125 | + |
|
| 126 | + /** |
|
| 127 | + * On ne va afficher que 500 résultats max |
|
| 128 | + * Si > 500 on affiche une pagination |
|
| 129 | + */ |
|
| 130 | + if ($nb > $limite) { |
|
| 131 | + $debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut; |
|
| 132 | + $pagination = chercher_filtre('pagination'); |
|
| 133 | + $pagination = '<p class="pagination">' . $pagination( |
|
| 134 | + $nb, |
|
| 135 | + '_rubrique' . $collection2, |
|
| 136 | + $debut, |
|
| 137 | + $limite, |
|
| 138 | + true, |
|
| 139 | + 'prive' |
|
| 140 | + ) . '</p>'; |
|
| 141 | + $limite = $debut + $limite; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + $result = sql_select( |
|
| 145 | + 'id_rubrique, id_parent, titre, lang', |
|
| 146 | + 'spip_rubriques', |
|
| 147 | + 'id_parent=' . intval($collection2), |
|
| 148 | + '', |
|
| 149 | + '0+titre,titre', |
|
| 150 | + "$debut,$limite" |
|
| 151 | + ); |
|
| 152 | + |
|
| 153 | + while ($row = sql_fetch($result)) { |
|
| 154 | + $id_rubrique2 = $row['id_rubrique']; |
|
| 155 | + $titre2 = generer_info_entite( |
|
| 156 | + $id_rubrique2, |
|
| 157 | + 'rubrique', |
|
| 158 | + 'titre' |
|
| 159 | + ); // pour etre sur de passer par tous les traitements |
|
| 160 | + if ('' !== ($rang2 = recuperer_numero($row['titre']))) { |
|
| 161 | + $rang2 = "<span class='rang'>$rang2.</span> "; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + changer_typo($row['lang']); |
|
| 165 | + $lang_dir = lang_dir($row['lang']); |
|
| 166 | + if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
|
| 167 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite( |
|
| 168 | + $id_rubrique2, |
|
| 169 | + 'rubrique' |
|
| 170 | + ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + $retour = $pagination . $retour . $pagination; |
|
| 175 | + |
|
| 176 | + if (!$retour) { |
|
| 177 | + return ''; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2") |
|
| 181 | + . "\n<ul class='liste-items sous-sous-rub'>\n" |
|
| 182 | + . $retour |
|
| 183 | + . "</ul>\n" . fin_block() . "\n\n"; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -195,44 +195,44 @@ discard block |
||
| 195 | 195 | * Le contenu textuel affiché, la liste des sous rubriques |
| 196 | 196 | */ |
| 197 | 197 | function afficher_enfant_rub($id_rubrique = 0) { |
| 198 | - $pagination = ''; |
|
| 199 | - $debut = 0; |
|
| 200 | - $limite = 500; |
|
| 201 | - |
|
| 202 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique)); |
|
| 203 | - |
|
| 204 | - if ($nb > $limite) { |
|
| 205 | - $debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut; |
|
| 206 | - $pagination = chercher_filtre('pagination'); |
|
| 207 | - $pagination = '<br class="nettoyeur"><p class="pagination">' . |
|
| 208 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 209 | - '</p>'; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 213 | - |
|
| 214 | - if (!$n = count($les_enfants)) { |
|
| 215 | - return ''; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($n == 1) { |
|
| 219 | - $les_enfants = reset($les_enfants); |
|
| 220 | - $les_enfants2 = ''; |
|
| 221 | - } else { |
|
| 222 | - $n = ceil($n / 2); |
|
| 223 | - $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 224 | - $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $res = |
|
| 228 | - $pagination |
|
| 229 | - . "<div class='gauche'>" |
|
| 230 | - . $les_enfants |
|
| 231 | - . '</div>' |
|
| 232 | - . "<div class='droite'>" |
|
| 233 | - . $les_enfants2 |
|
| 234 | - . '</div>' |
|
| 235 | - . $pagination; |
|
| 236 | - |
|
| 237 | - return $res; |
|
| 198 | + $pagination = ''; |
|
| 199 | + $debut = 0; |
|
| 200 | + $limite = 500; |
|
| 201 | + |
|
| 202 | + $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique)); |
|
| 203 | + |
|
| 204 | + if ($nb > $limite) { |
|
| 205 | + $debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut; |
|
| 206 | + $pagination = chercher_filtre('pagination'); |
|
| 207 | + $pagination = '<br class="nettoyeur"><p class="pagination">' . |
|
| 208 | + $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 209 | + '</p>'; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $les_enfants = enfant_rub($id_rubrique, $debut, $limite); |
|
| 213 | + |
|
| 214 | + if (!$n = count($les_enfants)) { |
|
| 215 | + return ''; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($n == 1) { |
|
| 219 | + $les_enfants = reset($les_enfants); |
|
| 220 | + $les_enfants2 = ''; |
|
| 221 | + } else { |
|
| 222 | + $n = ceil($n / 2); |
|
| 223 | + $les_enfants2 = implode('', array_slice($les_enfants, $n)); |
|
| 224 | + $les_enfants = implode('', array_slice($les_enfants, 0, $n)); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $res = |
|
| 228 | + $pagination |
|
| 229 | + . "<div class='gauche'>" |
|
| 230 | + . $les_enfants |
|
| 231 | + . '</div>' |
|
| 232 | + . "<div class='droite'>" |
|
| 233 | + . $les_enfants2 |
|
| 234 | + . '</div>' |
|
| 235 | + . $pagination; |
|
| 236 | + |
|
| 237 | + return $res; |
|
| 238 | 238 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | $result = sql_select( |
| 44 | 44 | 'id_rubrique, id_parent, titre, descriptif, lang', |
| 45 | 45 | 'spip_rubriques', |
| 46 | - 'id_parent=' . intval($collection), |
|
| 46 | + 'id_parent='.intval($collection), |
|
| 47 | 47 | '', |
| 48 | 48 | '0+titre,titre', |
| 49 | 49 | "$debut,$limite" |
@@ -74,19 +74,18 @@ discard block |
||
| 74 | 74 | } |
| 75 | 75 | } |
| 76 | 76 | |
| 77 | - $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : |
|
| 78 | - http_img_pack( |
|
| 77 | + $lib_bouton = (!acces_restreint_rubrique($id_rubrique) ? '' : http_img_pack( |
|
| 79 | 78 | 'auteur-0minirezo-16.png', |
| 80 | 79 | '', |
| 81 | 80 | " width='16' height='16'", |
| 82 | 81 | _T('image_administrer_rubrique') |
| 83 | - )) . |
|
| 84 | - " <a class='titremlien' dir='$lang_dir'" . |
|
| 85 | - ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='" . $row['lang'] . "'" : '') . |
|
| 86 | - " href='" . |
|
| 87 | - generer_url_entite($id_rubrique, 'rubrique') . |
|
| 88 | - "'><span class='titre'>" . |
|
| 89 | - $rang . $titre |
|
| 82 | + )). |
|
| 83 | + " <a class='titremlien' dir='$lang_dir'". |
|
| 84 | + ($row['lang'] !== $GLOBALS['spip_lang'] ? " hreflang='".$row['lang']."'" : ''). |
|
| 85 | + " href='". |
|
| 86 | + generer_url_entite($id_rubrique, 'rubrique'). |
|
| 87 | + "'><span class='titre'>". |
|
| 88 | + $rang.$titre |
|
| 90 | 89 | . '</span>' |
| 91 | 90 | . (is_string($logo) ? $logo : '') |
| 92 | 91 | . '</a>'; |
@@ -96,8 +95,8 @@ discard block |
||
| 96 | 95 | ; |
| 97 | 96 | |
| 98 | 97 | $res[] = |
| 99 | - debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre) . |
|
| 100 | - $les_sous_enfants . |
|
| 98 | + debut_cadre_sous_rub(($id_parent ? 'rubrique-24.png' : 'secteur-24.png'), true, '', $titre). |
|
| 99 | + $les_sous_enfants. |
|
| 101 | 100 | fin_cadre_sous_rub(true); |
| 102 | 101 | } |
| 103 | 102 | } |
@@ -116,7 +115,7 @@ discard block |
||
| 116 | 115 | * Le contenu du bloc dépliable |
| 117 | 116 | */ |
| 118 | 117 | function sous_enfant_rub($collection2) { |
| 119 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($collection2)); |
|
| 118 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.intval($collection2)); |
|
| 120 | 119 | |
| 121 | 120 | $retour = ''; |
| 122 | 121 | $pagination = ''; |
@@ -128,23 +127,23 @@ discard block |
||
| 128 | 127 | * Si > 500 on affiche une pagination |
| 129 | 128 | */ |
| 130 | 129 | if ($nb > $limite) { |
| 131 | - $debut = _request('debut_rubrique' . $collection2) ? _request('debut_rubrique' . $collection2) : $debut; |
|
| 130 | + $debut = _request('debut_rubrique'.$collection2) ? _request('debut_rubrique'.$collection2) : $debut; |
|
| 132 | 131 | $pagination = chercher_filtre('pagination'); |
| 133 | - $pagination = '<p class="pagination">' . $pagination( |
|
| 132 | + $pagination = '<p class="pagination">'.$pagination( |
|
| 134 | 133 | $nb, |
| 135 | - '_rubrique' . $collection2, |
|
| 134 | + '_rubrique'.$collection2, |
|
| 136 | 135 | $debut, |
| 137 | 136 | $limite, |
| 138 | 137 | true, |
| 139 | 138 | 'prive' |
| 140 | - ) . '</p>'; |
|
| 139 | + ).'</p>'; |
|
| 141 | 140 | $limite = $debut + $limite; |
| 142 | 141 | } |
| 143 | 142 | |
| 144 | 143 | $result = sql_select( |
| 145 | 144 | 'id_rubrique, id_parent, titre, lang', |
| 146 | 145 | 'spip_rubriques', |
| 147 | - 'id_parent=' . intval($collection2), |
|
| 146 | + 'id_parent='.intval($collection2), |
|
| 148 | 147 | '', |
| 149 | 148 | '0+titre,titre', |
| 150 | 149 | "$debut,$limite" |
@@ -164,14 +163,14 @@ discard block |
||
| 164 | 163 | changer_typo($row['lang']); |
| 165 | 164 | $lang_dir = lang_dir($row['lang']); |
| 166 | 165 | if (autoriser('voir', 'rubrique', $id_rubrique2)) { |
| 167 | - $retour .= "\n<li class='item' dir='$lang_dir'><a href='" . generer_url_entite( |
|
| 166 | + $retour .= "\n<li class='item' dir='$lang_dir'><a href='".generer_url_entite( |
|
| 168 | 167 | $id_rubrique2, |
| 169 | 168 | 'rubrique' |
| 170 | - ) . "'>" . $rang2 . $titre2 . "</a></li>\n"; |
|
| 169 | + )."'>".$rang2.$titre2."</a></li>\n"; |
|
| 171 | 170 | } |
| 172 | 171 | } |
| 173 | 172 | |
| 174 | - $retour = $pagination . $retour . $pagination; |
|
| 173 | + $retour = $pagination.$retour.$pagination; |
|
| 175 | 174 | |
| 176 | 175 | if (!$retour) { |
| 177 | 176 | return ''; |
@@ -180,7 +179,7 @@ discard block |
||
| 180 | 179 | return debut_block_depliable($debut > 0 ? true : false, "enfants$collection2") |
| 181 | 180 | . "\n<ul class='liste-items sous-sous-rub'>\n" |
| 182 | 181 | . $retour |
| 183 | - . "</ul>\n" . fin_block() . "\n\n"; |
|
| 182 | + . "</ul>\n".fin_block()."\n\n"; |
|
| 184 | 183 | } |
| 185 | 184 | |
| 186 | 185 | /** |
@@ -199,13 +198,13 @@ discard block |
||
| 199 | 198 | $debut = 0; |
| 200 | 199 | $limite = 500; |
| 201 | 200 | |
| 202 | - $nb = sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique)); |
|
| 201 | + $nb = sql_countsel('spip_rubriques', 'id_parent='.intval($id_rubrique)); |
|
| 203 | 202 | |
| 204 | 203 | if ($nb > $limite) { |
| 205 | - $debut = _request('debut_rubrique' . $id_rubrique) ? _request('debut_rubrique' . $id_rubrique) : $debut; |
|
| 204 | + $debut = _request('debut_rubrique'.$id_rubrique) ? _request('debut_rubrique'.$id_rubrique) : $debut; |
|
| 206 | 205 | $pagination = chercher_filtre('pagination'); |
| 207 | - $pagination = '<br class="nettoyeur"><p class="pagination">' . |
|
| 208 | - $pagination($nb, '_rubrique' . $id_rubrique, $debut, $limite, true, 'prive') . |
|
| 206 | + $pagination = '<br class="nettoyeur"><p class="pagination">'. |
|
| 207 | + $pagination($nb, '_rubrique'.$id_rubrique, $debut, $limite, true, 'prive'). |
|
| 209 | 208 | '</p>'; |
| 210 | 209 | } |
| 211 | 210 | |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | // securité |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // se faciliter la lecture du charset |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 43 | 43 | **/ |
| 44 | 44 | function load_charset($charset = 'AUTO') { |
| 45 | - if ($charset == 'AUTO') { |
|
| 46 | - $charset = $GLOBALS['meta']['charset']; |
|
| 47 | - } |
|
| 48 | - $charset = trim(strtolower($charset)); |
|
| 49 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | - return $charset; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($charset == 'utf-8') { |
|
| 54 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | - |
|
| 56 | - return $charset; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Quelques synonymes |
|
| 60 | - if ($charset == '') { |
|
| 61 | - $charset = 'iso-8859-1'; |
|
| 62 | - } else { |
|
| 63 | - if ($charset == 'windows-1250') { |
|
| 64 | - $charset = 'cp1250'; |
|
| 65 | - } else { |
|
| 66 | - if ($charset == 'windows-1251') { |
|
| 67 | - $charset = 'cp1251'; |
|
| 68 | - } else { |
|
| 69 | - if ($charset == 'windows-1256') { |
|
| 70 | - $charset = 'cp1256'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | - return $charset; |
|
| 78 | - } else { |
|
| 79 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | - |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 45 | + if ($charset == 'AUTO') { |
|
| 46 | + $charset = $GLOBALS['meta']['charset']; |
|
| 47 | + } |
|
| 48 | + $charset = trim(strtolower($charset)); |
|
| 49 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | + return $charset; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($charset == 'utf-8') { |
|
| 54 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | + |
|
| 56 | + return $charset; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Quelques synonymes |
|
| 60 | + if ($charset == '') { |
|
| 61 | + $charset = 'iso-8859-1'; |
|
| 62 | + } else { |
|
| 63 | + if ($charset == 'windows-1250') { |
|
| 64 | + $charset = 'cp1250'; |
|
| 65 | + } else { |
|
| 66 | + if ($charset == 'windows-1251') { |
|
| 67 | + $charset = 'cp1251'; |
|
| 68 | + } else { |
|
| 69 | + if ($charset == 'windows-1256') { |
|
| 70 | + $charset = 'cp1256'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | + return $charset; |
|
| 78 | + } else { |
|
| 79 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | + |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * true si toutes les fonctions mb nécessaires sont présentes |
| 92 | 92 | **/ |
| 93 | 93 | function init_mb_string() { |
| 94 | - static $mb; |
|
| 95 | - |
|
| 96 | - // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | - // et que le charset interne est connu de mb_string |
|
| 98 | - if (!$mb) { |
|
| 99 | - if ( |
|
| 100 | - function_exists('mb_internal_encoding') |
|
| 101 | - and function_exists('mb_detect_order') |
|
| 102 | - and function_exists('mb_substr') |
|
| 103 | - and function_exists('mb_strlen') |
|
| 104 | - and function_exists('mb_strtolower') |
|
| 105 | - and function_exists('mb_strtoupper') |
|
| 106 | - and function_exists('mb_encode_mimeheader') |
|
| 107 | - and function_exists('mb_encode_numericentity') |
|
| 108 | - and function_exists('mb_decode_numericentity') |
|
| 109 | - and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | - ) { |
|
| 111 | - mb_internal_encoding('utf-8'); |
|
| 112 | - $mb = 1; |
|
| 113 | - } else { |
|
| 114 | - $mb = -1; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return ($mb == 1); |
|
| 94 | + static $mb; |
|
| 95 | + |
|
| 96 | + // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | + // et que le charset interne est connu de mb_string |
|
| 98 | + if (!$mb) { |
|
| 99 | + if ( |
|
| 100 | + function_exists('mb_internal_encoding') |
|
| 101 | + and function_exists('mb_detect_order') |
|
| 102 | + and function_exists('mb_substr') |
|
| 103 | + and function_exists('mb_strlen') |
|
| 104 | + and function_exists('mb_strtolower') |
|
| 105 | + and function_exists('mb_strtoupper') |
|
| 106 | + and function_exists('mb_encode_mimeheader') |
|
| 107 | + and function_exists('mb_encode_numericentity') |
|
| 108 | + and function_exists('mb_decode_numericentity') |
|
| 109 | + and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | + ) { |
|
| 111 | + mb_internal_encoding('utf-8'); |
|
| 112 | + $mb = 1; |
|
| 113 | + } else { |
|
| 114 | + $mb = -1; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return ($mb == 1); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -130,21 +130,21 @@ discard block |
||
| 130 | 130 | * true si iconv fonctionne correctement |
| 131 | 131 | **/ |
| 132 | 132 | function test_iconv() { |
| 133 | - static $iconv_ok; |
|
| 134 | - |
|
| 135 | - if (!$iconv_ok) { |
|
| 136 | - if (!function_exists('iconv')) { |
|
| 137 | - $iconv_ok = -1; |
|
| 138 | - } else { |
|
| 139 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | - $iconv_ok = 1; |
|
| 141 | - } else { |
|
| 142 | - $iconv_ok = -1; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ($iconv_ok == 1); |
|
| 133 | + static $iconv_ok; |
|
| 134 | + |
|
| 135 | + if (!$iconv_ok) { |
|
| 136 | + if (!function_exists('iconv')) { |
|
| 137 | + $iconv_ok = -1; |
|
| 138 | + } else { |
|
| 139 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | + $iconv_ok = 1; |
|
| 141 | + } else { |
|
| 142 | + $iconv_ok = -1; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ($iconv_ok == 1); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -157,18 +157,18 @@ discard block |
||
| 157 | 157 | * true si PCRE supporte l'UTF-8 correctement |
| 158 | 158 | **/ |
| 159 | 159 | function test_pcre_unicode() { |
| 160 | - static $pcre_ok = 0; |
|
| 161 | - |
|
| 162 | - if (!$pcre_ok) { |
|
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | - if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | - $pcre_ok = 1; |
|
| 166 | - } else { |
|
| 167 | - $pcre_ok = -1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $pcre_ok == 1; |
|
| 160 | + static $pcre_ok = 0; |
|
| 161 | + |
|
| 162 | + if (!$pcre_ok) { |
|
| 163 | + $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | + if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | + $pcre_ok = 1; |
|
| 166 | + } else { |
|
| 167 | + $pcre_ok = -1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $pcre_ok == 1; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -184,22 +184,22 @@ discard block |
||
| 184 | 184 | * Plage de caractères |
| 185 | 185 | **/ |
| 186 | 186 | function pcre_lettres_unicode() { |
| 187 | - static $plage_unicode; |
|
| 188 | - |
|
| 189 | - if (!$plage_unicode) { |
|
| 190 | - if (test_pcre_unicode()) { |
|
| 191 | - // cf. http://www.unicode.org/charts/ |
|
| 192 | - $plage_unicode = '\w' // iso-latin |
|
| 193 | - . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | - . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | - ; |
|
| 196 | - } else { |
|
| 197 | - // fallback a trois sous |
|
| 198 | - $plage_unicode = '\w'; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $plage_unicode; |
|
| 187 | + static $plage_unicode; |
|
| 188 | + |
|
| 189 | + if (!$plage_unicode) { |
|
| 190 | + if (test_pcre_unicode()) { |
|
| 191 | + // cf. http://www.unicode.org/charts/ |
|
| 192 | + $plage_unicode = '\w' // iso-latin |
|
| 193 | + . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | + . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | + ; |
|
| 196 | + } else { |
|
| 197 | + // fallback a trois sous |
|
| 198 | + $plage_unicode = '\w'; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $plage_unicode; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * Plage de caractères |
| 218 | 218 | **/ |
| 219 | 219 | function plage_punct_unicode() { |
| 220 | - return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 220 | + return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -237,75 +237,75 @@ discard block |
||
| 237 | 237 | * Texte corrigé |
| 238 | 238 | **/ |
| 239 | 239 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 240 | - static $trans; |
|
| 241 | - |
|
| 242 | - if (is_array($texte)) { |
|
| 243 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ($charset == 'AUTO') { |
|
| 247 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | - } |
|
| 249 | - if ($charset == 'utf-8') { |
|
| 250 | - $p = chr(194); |
|
| 251 | - if (strpos($texte, $p) == false) { |
|
| 252 | - return $texte; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - if ($charset == 'iso-8859-1') { |
|
| 256 | - $p = ''; |
|
| 257 | - } else { |
|
| 258 | - return $texte; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | - $trans[$charset][$charset_cible] = [ |
|
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 296 | - ]; |
|
| 297 | - if ($charset_cible != 'unicode') { |
|
| 298 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return @str_replace( |
|
| 305 | - array_keys($trans[$charset][$charset_cible]), |
|
| 306 | - array_values($trans[$charset][$charset_cible]), |
|
| 307 | - $texte |
|
| 308 | - ); |
|
| 240 | + static $trans; |
|
| 241 | + |
|
| 242 | + if (is_array($texte)) { |
|
| 243 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ($charset == 'AUTO') { |
|
| 247 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | + } |
|
| 249 | + if ($charset == 'utf-8') { |
|
| 250 | + $p = chr(194); |
|
| 251 | + if (strpos($texte, $p) == false) { |
|
| 252 | + return $texte; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + if ($charset == 'iso-8859-1') { |
|
| 256 | + $p = ''; |
|
| 257 | + } else { |
|
| 258 | + return $texte; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | + $trans[$charset][$charset_cible] = [ |
|
| 264 | + $p . chr(128) => '€', |
|
| 265 | + $p . chr(129) => ' ', # pas affecte |
|
| 266 | + $p . chr(130) => '‚', |
|
| 267 | + $p . chr(131) => 'ƒ', |
|
| 268 | + $p . chr(132) => '„', |
|
| 269 | + $p . chr(133) => '…', |
|
| 270 | + $p . chr(134) => '†', |
|
| 271 | + $p . chr(135) => '‡', |
|
| 272 | + $p . chr(136) => 'ˆ', |
|
| 273 | + $p . chr(137) => '‰', |
|
| 274 | + $p . chr(138) => 'Š', |
|
| 275 | + $p . chr(139) => '‹', |
|
| 276 | + $p . chr(140) => 'Œ', |
|
| 277 | + $p . chr(141) => ' ', # pas affecte |
|
| 278 | + $p . chr(142) => 'Ž', |
|
| 279 | + $p . chr(143) => ' ', # pas affecte |
|
| 280 | + $p . chr(144) => ' ', # pas affecte |
|
| 281 | + $p . chr(145) => '‘', |
|
| 282 | + $p . chr(146) => '’', |
|
| 283 | + $p . chr(147) => '“', |
|
| 284 | + $p . chr(148) => '”', |
|
| 285 | + $p . chr(149) => '•', |
|
| 286 | + $p . chr(150) => '–', |
|
| 287 | + $p . chr(151) => '—', |
|
| 288 | + $p . chr(152) => '˜', |
|
| 289 | + $p . chr(153) => '™', |
|
| 290 | + $p . chr(154) => 'š', |
|
| 291 | + $p . chr(155) => '›', |
|
| 292 | + $p . chr(156) => 'œ', |
|
| 293 | + $p . chr(157) => ' ', # pas affecte |
|
| 294 | + $p . chr(158) => 'ž', |
|
| 295 | + $p . chr(159) => 'Ÿ', |
|
| 296 | + ]; |
|
| 297 | + if ($charset_cible != 'unicode') { |
|
| 298 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return @str_replace( |
|
| 305 | + array_keys($trans[$charset][$charset_cible]), |
|
| 306 | + array_values($trans[$charset][$charset_cible]), |
|
| 307 | + $texte |
|
| 308 | + ); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -322,26 +322,26 @@ discard block |
||
| 322 | 322 | * Texte converti |
| 323 | 323 | **/ |
| 324 | 324 | function html2unicode($texte, $secure = false) { |
| 325 | - if (strpos($texte, '&') === false) { |
|
| 326 | - return $texte; |
|
| 327 | - } |
|
| 328 | - static $trans = []; |
|
| 329 | - if (!$trans) { |
|
| 330 | - load_charset('html'); |
|
| 331 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | - $trans["&$key;"] = $val; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ($secure) { |
|
| 337 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | - } else { |
|
| 339 | - return str_replace( |
|
| 340 | - ['&', '"', '<', '>'], |
|
| 341 | - ['&', '"', '<', '>'], |
|
| 342 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | - ); |
|
| 344 | - } |
|
| 325 | + if (strpos($texte, '&') === false) { |
|
| 326 | + return $texte; |
|
| 327 | + } |
|
| 328 | + static $trans = []; |
|
| 329 | + if (!$trans) { |
|
| 330 | + load_charset('html'); |
|
| 331 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | + $trans["&$key;"] = $val; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ($secure) { |
|
| 337 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | + } else { |
|
| 339 | + return str_replace( |
|
| 340 | + ['&', '"', '<', '>'], |
|
| 341 | + ['&', '"', '<', '>'], |
|
| 342 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -356,16 +356,16 @@ discard block |
||
| 356 | 356 | * Texte converti |
| 357 | 357 | **/ |
| 358 | 358 | function mathml2unicode($texte) { |
| 359 | - static $trans; |
|
| 360 | - if (!$trans) { |
|
| 361 | - load_charset('mathml'); |
|
| 359 | + static $trans; |
|
| 360 | + if (!$trans) { |
|
| 361 | + load_charset('mathml'); |
|
| 362 | 362 | |
| 363 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | - $trans["&$key;"] = $val; |
|
| 365 | - } |
|
| 366 | - } |
|
| 363 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | + $trans["&$key;"] = $val; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 368 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -387,75 +387,75 @@ discard block |
||
| 387 | 387 | * Texte converti en unicode |
| 388 | 388 | **/ |
| 389 | 389 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 390 | - static $trans; |
|
| 391 | - |
|
| 392 | - if ($charset == 'AUTO') { |
|
| 393 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($charset == '') { |
|
| 397 | - $charset = 'iso-8859-1'; |
|
| 398 | - } |
|
| 399 | - $charset = strtolower($charset); |
|
| 400 | - |
|
| 401 | - switch ($charset) { |
|
| 402 | - case 'utf-8': |
|
| 403 | - case 'utf8': |
|
| 404 | - return utf_8_to_unicode($texte); |
|
| 405 | - |
|
| 406 | - case 'iso-8859-1': |
|
| 407 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | - // pas de break; ici, on suit sur default: |
|
| 409 | - |
|
| 410 | - default: |
|
| 411 | - // mbstring presente ? |
|
| 412 | - if (init_mb_string()) { |
|
| 413 | - $order = mb_detect_order(); |
|
| 414 | - try { |
|
| 415 | - # mb_string connait-il $charset? |
|
| 416 | - if ($order and mb_detect_order($charset)) { |
|
| 417 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | - if ($s && $s != $texte) { |
|
| 419 | - return utf_8_to_unicode($s); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } catch (\Error $e) { |
|
| 423 | - // Le charset n'existe probablement pas |
|
| 424 | - } finally { |
|
| 425 | - mb_detect_order($order); # remettre comme precedemment |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | - if (!isset($trans[$charset])) { |
|
| 431 | - if ( |
|
| 432 | - $cset = load_charset($charset) |
|
| 433 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | - ) { |
|
| 435 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - if (isset($trans[$charset]) and count($trans[$charset])) { |
|
| 441 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | - // surtout en utf-8, gere ci-dessus) |
|
| 447 | - if (test_iconv()) { |
|
| 448 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | - if ($s) { |
|
| 450 | - return utf_32_to_unicode($s); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // Au pire ne rien faire |
|
| 455 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | - |
|
| 457 | - return $texte; |
|
| 458 | - } |
|
| 390 | + static $trans; |
|
| 391 | + |
|
| 392 | + if ($charset == 'AUTO') { |
|
| 393 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($charset == '') { |
|
| 397 | + $charset = 'iso-8859-1'; |
|
| 398 | + } |
|
| 399 | + $charset = strtolower($charset); |
|
| 400 | + |
|
| 401 | + switch ($charset) { |
|
| 402 | + case 'utf-8': |
|
| 403 | + case 'utf8': |
|
| 404 | + return utf_8_to_unicode($texte); |
|
| 405 | + |
|
| 406 | + case 'iso-8859-1': |
|
| 407 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | + // pas de break; ici, on suit sur default: |
|
| 409 | + |
|
| 410 | + default: |
|
| 411 | + // mbstring presente ? |
|
| 412 | + if (init_mb_string()) { |
|
| 413 | + $order = mb_detect_order(); |
|
| 414 | + try { |
|
| 415 | + # mb_string connait-il $charset? |
|
| 416 | + if ($order and mb_detect_order($charset)) { |
|
| 417 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | + if ($s && $s != $texte) { |
|
| 419 | + return utf_8_to_unicode($s); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } catch (\Error $e) { |
|
| 423 | + // Le charset n'existe probablement pas |
|
| 424 | + } finally { |
|
| 425 | + mb_detect_order($order); # remettre comme precedemment |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | + if (!isset($trans[$charset])) { |
|
| 431 | + if ( |
|
| 432 | + $cset = load_charset($charset) |
|
| 433 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | + ) { |
|
| 435 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + if (isset($trans[$charset]) and count($trans[$charset])) { |
|
| 441 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | + // surtout en utf-8, gere ci-dessus) |
|
| 447 | + if (test_iconv()) { |
|
| 448 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | + if ($s) { |
|
| 450 | + return utf_32_to_unicode($s); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // Au pire ne rien faire |
|
| 455 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | + |
|
| 457 | + return $texte; |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -474,44 +474,44 @@ discard block |
||
| 474 | 474 | * Texte transformé dans le charset souhaité |
| 475 | 475 | **/ |
| 476 | 476 | function unicode2charset($texte, $charset = 'AUTO') { |
| 477 | - static $CHARSET_REVERSE = []; |
|
| 478 | - static $trans = []; |
|
| 479 | - |
|
| 480 | - if ($charset == 'AUTO') { |
|
| 481 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - switch ($charset) { |
|
| 485 | - case 'utf-8': |
|
| 486 | - return unicode_to_utf_8($texte); |
|
| 487 | - break; |
|
| 488 | - |
|
| 489 | - default: |
|
| 490 | - $charset = load_charset($charset); |
|
| 491 | - |
|
| 492 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if (!isset($trans[$charset])) { |
|
| 497 | - $trans[$charset] = []; |
|
| 498 | - $t = &$trans[$charset]; |
|
| 499 | - for ($e = 128; $e < 255; $e++) { |
|
| 500 | - $h = dechex($e); |
|
| 501 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | - } else { |
|
| 506 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | - |
|
| 513 | - return $texte; |
|
| 514 | - } |
|
| 477 | + static $CHARSET_REVERSE = []; |
|
| 478 | + static $trans = []; |
|
| 479 | + |
|
| 480 | + if ($charset == 'AUTO') { |
|
| 481 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + switch ($charset) { |
|
| 485 | + case 'utf-8': |
|
| 486 | + return unicode_to_utf_8($texte); |
|
| 487 | + break; |
|
| 488 | + |
|
| 489 | + default: |
|
| 490 | + $charset = load_charset($charset); |
|
| 491 | + |
|
| 492 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if (!isset($trans[$charset])) { |
|
| 497 | + $trans[$charset] = []; |
|
| 498 | + $t = &$trans[$charset]; |
|
| 499 | + for ($e = 128; $e < 255; $e++) { |
|
| 500 | + $h = dechex($e); |
|
| 501 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | + } else { |
|
| 506 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | + |
|
| 513 | + return $texte; |
|
| 514 | + } |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
@@ -529,39 +529,39 @@ discard block |
||
| 529 | 529 | * Texte transformé dans le charset site |
| 530 | 530 | **/ |
| 531 | 531 | function importer_charset($texte, $charset = 'AUTO') { |
| 532 | - static $trans = []; |
|
| 533 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 534 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 535 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 536 | - if (init_mb_string()) { |
|
| 537 | - if ( |
|
| 538 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 539 | - and mb_detect_order($charset) |
|
| 540 | - ) { |
|
| 541 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 542 | - } |
|
| 543 | - mb_detect_order($order); # remettre comme precedemment |
|
| 544 | - return $s; |
|
| 545 | - } |
|
| 546 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 547 | - if (!isset($trans[$charset])) { |
|
| 548 | - if ( |
|
| 549 | - $cset = load_charset($charset) |
|
| 550 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 551 | - ) { |
|
| 552 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 553 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 554 | - } |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - if (count($trans[$charset])) { |
|
| 558 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - return $texte; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 532 | + static $trans = []; |
|
| 533 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 534 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 535 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 536 | + if (init_mb_string()) { |
|
| 537 | + if ( |
|
| 538 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 539 | + and mb_detect_order($charset) |
|
| 540 | + ) { |
|
| 541 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 542 | + } |
|
| 543 | + mb_detect_order($order); # remettre comme precedemment |
|
| 544 | + return $s; |
|
| 545 | + } |
|
| 546 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 547 | + if (!isset($trans[$charset])) { |
|
| 548 | + if ( |
|
| 549 | + $cset = load_charset($charset) |
|
| 550 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 551 | + ) { |
|
| 552 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 553 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 554 | + } |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + if (count($trans[$charset])) { |
|
| 558 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + return $texte; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -577,92 +577,92 @@ discard block |
||
| 577 | 577 | **/ |
| 578 | 578 | function utf_8_to_unicode($source) { |
| 579 | 579 | |
| 580 | - // mb_string : methode rapide |
|
| 581 | - if (init_mb_string()) { |
|
| 582 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 583 | - |
|
| 584 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - // Sinon methode pas a pas |
|
| 588 | - static $decrement; |
|
| 589 | - static $shift; |
|
| 590 | - |
|
| 591 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 592 | - if (!is_array($decrement)) { |
|
| 593 | - // array used to figure what number to decrement from character order value |
|
| 594 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 595 | - $decrement[4] = 240; |
|
| 596 | - $decrement[3] = 224; |
|
| 597 | - $decrement[2] = 192; |
|
| 598 | - $decrement[1] = 0; |
|
| 599 | - // the number of bits to shift each charNum by |
|
| 600 | - $shift[1][0] = 0; |
|
| 601 | - $shift[2][0] = 6; |
|
| 602 | - $shift[2][1] = 0; |
|
| 603 | - $shift[3][0] = 12; |
|
| 604 | - $shift[3][1] = 6; |
|
| 605 | - $shift[3][2] = 0; |
|
| 606 | - $shift[4][0] = 18; |
|
| 607 | - $shift[4][1] = 12; |
|
| 608 | - $shift[4][2] = 6; |
|
| 609 | - $shift[4][3] = 0; |
|
| 610 | - } |
|
| 611 | - |
|
| 612 | - $pos = 0; |
|
| 613 | - $len = strlen($source); |
|
| 614 | - $encodedString = ''; |
|
| 615 | - while ($pos < $len) { |
|
| 616 | - $char = ''; |
|
| 617 | - $ischar = false; |
|
| 618 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 619 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 620 | - // 4 chars representing one unicode character |
|
| 621 | - $thisLetter = substr($source, $pos, 4); |
|
| 622 | - $pos += 4; |
|
| 623 | - } else { |
|
| 624 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 625 | - // 3 chars representing one unicode character |
|
| 626 | - $thisLetter = substr($source, $pos, 3); |
|
| 627 | - $pos += 3; |
|
| 628 | - } else { |
|
| 629 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 630 | - // 2 chars representing one unicode character |
|
| 631 | - $thisLetter = substr($source, $pos, 2); |
|
| 632 | - $pos += 2; |
|
| 633 | - } else { |
|
| 634 | - // 1 char (lower ascii) |
|
| 635 | - $thisLetter = substr($source, $pos, 1); |
|
| 636 | - $pos += 1; |
|
| 637 | - $char = $thisLetter; |
|
| 638 | - $ischar = true; |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if ($ischar) { |
|
| 644 | - $encodedString .= $char; |
|
| 645 | - } else { // process the string representing the letter to a unicode entity |
|
| 646 | - $thisLen = strlen($thisLetter); |
|
| 647 | - $thisPos = 0; |
|
| 648 | - $decimalCode = 0; |
|
| 649 | - while ($thisPos < $thisLen) { |
|
| 650 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 651 | - if ($thisPos == 0) { |
|
| 652 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 653 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 654 | - } else { |
|
| 655 | - $charNum = intval($thisCharOrd - 128); |
|
| 656 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 657 | - } |
|
| 658 | - $thisPos++; |
|
| 659 | - } |
|
| 660 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 661 | - $encodedString .= $encodedLetter; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - return $encodedString; |
|
| 580 | + // mb_string : methode rapide |
|
| 581 | + if (init_mb_string()) { |
|
| 582 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 583 | + |
|
| 584 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + // Sinon methode pas a pas |
|
| 588 | + static $decrement; |
|
| 589 | + static $shift; |
|
| 590 | + |
|
| 591 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 592 | + if (!is_array($decrement)) { |
|
| 593 | + // array used to figure what number to decrement from character order value |
|
| 594 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 595 | + $decrement[4] = 240; |
|
| 596 | + $decrement[3] = 224; |
|
| 597 | + $decrement[2] = 192; |
|
| 598 | + $decrement[1] = 0; |
|
| 599 | + // the number of bits to shift each charNum by |
|
| 600 | + $shift[1][0] = 0; |
|
| 601 | + $shift[2][0] = 6; |
|
| 602 | + $shift[2][1] = 0; |
|
| 603 | + $shift[3][0] = 12; |
|
| 604 | + $shift[3][1] = 6; |
|
| 605 | + $shift[3][2] = 0; |
|
| 606 | + $shift[4][0] = 18; |
|
| 607 | + $shift[4][1] = 12; |
|
| 608 | + $shift[4][2] = 6; |
|
| 609 | + $shift[4][3] = 0; |
|
| 610 | + } |
|
| 611 | + |
|
| 612 | + $pos = 0; |
|
| 613 | + $len = strlen($source); |
|
| 614 | + $encodedString = ''; |
|
| 615 | + while ($pos < $len) { |
|
| 616 | + $char = ''; |
|
| 617 | + $ischar = false; |
|
| 618 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 619 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 620 | + // 4 chars representing one unicode character |
|
| 621 | + $thisLetter = substr($source, $pos, 4); |
|
| 622 | + $pos += 4; |
|
| 623 | + } else { |
|
| 624 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 625 | + // 3 chars representing one unicode character |
|
| 626 | + $thisLetter = substr($source, $pos, 3); |
|
| 627 | + $pos += 3; |
|
| 628 | + } else { |
|
| 629 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 630 | + // 2 chars representing one unicode character |
|
| 631 | + $thisLetter = substr($source, $pos, 2); |
|
| 632 | + $pos += 2; |
|
| 633 | + } else { |
|
| 634 | + // 1 char (lower ascii) |
|
| 635 | + $thisLetter = substr($source, $pos, 1); |
|
| 636 | + $pos += 1; |
|
| 637 | + $char = $thisLetter; |
|
| 638 | + $ischar = true; |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if ($ischar) { |
|
| 644 | + $encodedString .= $char; |
|
| 645 | + } else { // process the string representing the letter to a unicode entity |
|
| 646 | + $thisLen = strlen($thisLetter); |
|
| 647 | + $thisPos = 0; |
|
| 648 | + $decimalCode = 0; |
|
| 649 | + while ($thisPos < $thisLen) { |
|
| 650 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 651 | + if ($thisPos == 0) { |
|
| 652 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 653 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 654 | + } else { |
|
| 655 | + $charNum = intval($thisCharOrd - 128); |
|
| 656 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 657 | + } |
|
| 658 | + $thisPos++; |
|
| 659 | + } |
|
| 660 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 661 | + $encodedString .= $encodedLetter; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + return $encodedString; |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -681,32 +681,32 @@ discard block |
||
| 681 | 681 | **/ |
| 682 | 682 | function utf_32_to_unicode($source) { |
| 683 | 683 | |
| 684 | - // mb_string : methode rapide |
|
| 685 | - if (init_mb_string()) { |
|
| 686 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 687 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 688 | - |
|
| 689 | - return str_replace(chr(0), '', $source); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - // Sinon methode lente |
|
| 693 | - $texte = ''; |
|
| 694 | - while ($source) { |
|
| 695 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 696 | - $source = substr($source, 1024); |
|
| 697 | - foreach ($words as $word) { |
|
| 698 | - if ($word < 128) { |
|
| 699 | - $texte .= chr($word); |
|
| 700 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 701 | - else { |
|
| 702 | - if ($word != 65279) { |
|
| 703 | - $texte .= '&#' . $word . ';'; |
|
| 704 | - } |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - return $texte; |
|
| 684 | + // mb_string : methode rapide |
|
| 685 | + if (init_mb_string()) { |
|
| 686 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 687 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 688 | + |
|
| 689 | + return str_replace(chr(0), '', $source); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + // Sinon methode lente |
|
| 693 | + $texte = ''; |
|
| 694 | + while ($source) { |
|
| 695 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 696 | + $source = substr($source, 1024); |
|
| 697 | + foreach ($words as $word) { |
|
| 698 | + if ($word < 128) { |
|
| 699 | + $texte .= chr($word); |
|
| 700 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 701 | + else { |
|
| 702 | + if ($word != 65279) { |
|
| 703 | + $texte .= '&#' . $word . ';'; |
|
| 704 | + } |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + return $texte; |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | |
@@ -723,21 +723,21 @@ discard block |
||
| 723 | 723 | * Caractère utf8 si trouvé, '' sinon |
| 724 | 724 | **/ |
| 725 | 725 | function caractere_utf_8($num) { |
| 726 | - $num = intval($num); |
|
| 727 | - if ($num < 128) { |
|
| 728 | - return chr($num); |
|
| 729 | - } |
|
| 730 | - if ($num < 2048) { |
|
| 731 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 732 | - } |
|
| 733 | - if ($num < 65536) { |
|
| 734 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 735 | - } |
|
| 736 | - if ($num < 1114112) { |
|
| 737 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - return ''; |
|
| 726 | + $num = intval($num); |
|
| 727 | + if ($num < 128) { |
|
| 728 | + return chr($num); |
|
| 729 | + } |
|
| 730 | + if ($num < 2048) { |
|
| 731 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 732 | + } |
|
| 733 | + if ($num < 65536) { |
|
| 734 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 735 | + } |
|
| 736 | + if ($num < 1114112) { |
|
| 737 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + return ''; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | /** |
@@ -750,42 +750,42 @@ discard block |
||
| 750 | 750 | **/ |
| 751 | 751 | function unicode_to_utf_8($texte) { |
| 752 | 752 | |
| 753 | - // 1. Entites € et suivantes |
|
| 754 | - $vu = []; |
|
| 755 | - if ( |
|
| 756 | - preg_match_all( |
|
| 757 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 758 | - $texte, |
|
| 759 | - $regs, |
|
| 760 | - PREG_SET_ORDER |
|
| 761 | - ) |
|
| 762 | - ) { |
|
| 763 | - foreach ($regs as $reg) { |
|
| 764 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 765 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 766 | - } |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 770 | - |
|
| 771 | - // 2. Entites > ÿ |
|
| 772 | - //$vu = array(); |
|
| 773 | - if ( |
|
| 774 | - preg_match_all( |
|
| 775 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 776 | - $texte, |
|
| 777 | - $regs, |
|
| 778 | - PREG_SET_ORDER |
|
| 779 | - ) |
|
| 780 | - ) { |
|
| 781 | - foreach ($regs as $reg) { |
|
| 782 | - if (!isset($vu[$reg[0]])) { |
|
| 783 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 784 | - } |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - |
|
| 788 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 753 | + // 1. Entites € et suivantes |
|
| 754 | + $vu = []; |
|
| 755 | + if ( |
|
| 756 | + preg_match_all( |
|
| 757 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 758 | + $texte, |
|
| 759 | + $regs, |
|
| 760 | + PREG_SET_ORDER |
|
| 761 | + ) |
|
| 762 | + ) { |
|
| 763 | + foreach ($regs as $reg) { |
|
| 764 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 765 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 766 | + } |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 770 | + |
|
| 771 | + // 2. Entites > ÿ |
|
| 772 | + //$vu = array(); |
|
| 773 | + if ( |
|
| 774 | + preg_match_all( |
|
| 775 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 776 | + $texte, |
|
| 777 | + $regs, |
|
| 778 | + PREG_SET_ORDER |
|
| 779 | + ) |
|
| 780 | + ) { |
|
| 781 | + foreach ($regs as $reg) { |
|
| 782 | + if (!isset($vu[$reg[0]])) { |
|
| 783 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 784 | + } |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + |
|
| 788 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -797,15 +797,15 @@ discard block |
||
| 797 | 797 | * Texte converti |
| 798 | 798 | **/ |
| 799 | 799 | function unicode_to_javascript($texte) { |
| 800 | - $vu = []; |
|
| 801 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 802 | - $num = $regs[1]; |
|
| 803 | - $vu[$num] = true; |
|
| 804 | - $s = '\u' . sprintf('%04x', $num); |
|
| 805 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - return $texte; |
|
| 800 | + $vu = []; |
|
| 801 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 802 | + $num = $regs[1]; |
|
| 803 | + $vu[$num] = true; |
|
| 804 | + $s = '\u' . sprintf('%04x', $num); |
|
| 805 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + return $texte; |
|
| 809 | 809 | } |
| 810 | 810 | |
| 811 | 811 | /** |
@@ -817,11 +817,11 @@ discard block |
||
| 817 | 817 | * Texte converti |
| 818 | 818 | **/ |
| 819 | 819 | function javascript_to_unicode($texte) { |
| 820 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 821 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 822 | - } |
|
| 820 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 821 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 822 | + } |
|
| 823 | 823 | |
| 824 | - return $texte; |
|
| 824 | + return $texte; |
|
| 825 | 825 | } |
| 826 | 826 | |
| 827 | 827 | /** |
@@ -833,11 +833,11 @@ discard block |
||
| 833 | 833 | * Texte converti |
| 834 | 834 | **/ |
| 835 | 835 | function javascript_to_binary($texte) { |
| 836 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 837 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 838 | - } |
|
| 836 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 837 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 838 | + } |
|
| 839 | 839 | |
| 840 | - return $texte; |
|
| 840 | + return $texte; |
|
| 841 | 841 | } |
| 842 | 842 | |
| 843 | 843 | |
@@ -855,26 +855,26 @@ discard block |
||
| 855 | 855 | * @return string |
| 856 | 856 | */ |
| 857 | 857 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') { |
| 858 | - static $trans = []; |
|
| 859 | - if ($charset == 'AUTO') { |
|
| 860 | - $charset = $GLOBALS['meta']['charset']; |
|
| 861 | - } |
|
| 862 | - if (!strlen($texte)) { |
|
| 863 | - return $texte; |
|
| 864 | - } |
|
| 865 | - |
|
| 866 | - $table_translit = 'translit' . $complexe; |
|
| 867 | - |
|
| 868 | - // 2. Translitterer grace a la table predefinie |
|
| 869 | - if (!isset($trans[$complexe])) { |
|
| 870 | - $trans[$complexe] = []; |
|
| 871 | - load_charset($table_translit); |
|
| 872 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 873 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 874 | - } |
|
| 875 | - } |
|
| 876 | - |
|
| 877 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 858 | + static $trans = []; |
|
| 859 | + if ($charset == 'AUTO') { |
|
| 860 | + $charset = $GLOBALS['meta']['charset']; |
|
| 861 | + } |
|
| 862 | + if (!strlen($texte)) { |
|
| 863 | + return $texte; |
|
| 864 | + } |
|
| 865 | + |
|
| 866 | + $table_translit = 'translit' . $complexe; |
|
| 867 | + |
|
| 868 | + // 2. Translitterer grace a la table predefinie |
|
| 869 | + if (!isset($trans[$complexe])) { |
|
| 870 | + $trans[$complexe] = []; |
|
| 871 | + load_charset($table_translit); |
|
| 872 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 873 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 874 | + } |
|
| 875 | + } |
|
| 876 | + |
|
| 877 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 878 | 878 | } |
| 879 | 879 | |
| 880 | 880 | /** |
@@ -897,14 +897,14 @@ discard block |
||
| 897 | 897 | * @return string |
| 898 | 898 | */ |
| 899 | 899 | function translitteration($texte, $charset = 'AUTO', $complexe = '') { |
| 900 | - // 0. Supprimer les caracteres illegaux |
|
| 901 | - include_spip('inc/filtres'); |
|
| 902 | - $texte = corriger_caracteres($texte); |
|
| 900 | + // 0. Supprimer les caracteres illegaux |
|
| 901 | + include_spip('inc/filtres'); |
|
| 902 | + $texte = corriger_caracteres($texte); |
|
| 903 | 903 | |
| 904 | - // 1. Passer le charset et les é en utf-8 |
|
| 905 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true))); |
|
| 904 | + // 1. Passer le charset et les é en utf-8 |
|
| 905 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset, true))); |
|
| 906 | 906 | |
| 907 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 907 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -919,19 +919,19 @@ discard block |
||
| 919 | 919 | * @return string |
| 920 | 920 | */ |
| 921 | 921 | function translitteration_complexe($texte, $chiffres = false) { |
| 922 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | - |
|
| 924 | - if ($chiffres) { |
|
| 925 | - $texte = preg_replace_callback( |
|
| 926 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 927 | - function ($m) { |
|
| 928 | - return translitteration_chiffree($m[0]); |
|
| 929 | - }, |
|
| 930 | - $texte |
|
| 931 | - ); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - return $texte; |
|
| 922 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | + |
|
| 924 | + if ($chiffres) { |
|
| 925 | + $texte = preg_replace_callback( |
|
| 926 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 927 | + function ($m) { |
|
| 928 | + return translitteration_chiffree($m[0]); |
|
| 929 | + }, |
|
| 930 | + $texte |
|
| 931 | + ); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + return $texte; |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | /** |
@@ -943,7 +943,7 @@ discard block |
||
| 943 | 943 | * @return string |
| 944 | 944 | */ |
| 945 | 945 | function translitteration_chiffree($car) { |
| 946 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 946 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 947 | 947 | } |
| 948 | 948 | |
| 949 | 949 | |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | * true s'il a un BOM |
| 957 | 957 | **/ |
| 958 | 958 | function bom_utf8($texte) { |
| 959 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 959 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | /** |
@@ -973,21 +973,21 @@ discard block |
||
| 973 | 973 | * true si c'est le cas |
| 974 | 974 | **/ |
| 975 | 975 | function is_utf8($string) { |
| 976 | - return !strlen( |
|
| 977 | - preg_replace( |
|
| 978 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 979 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 980 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 981 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 982 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 983 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 984 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 985 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 986 | - . ',sS', |
|
| 987 | - '', |
|
| 988 | - $string |
|
| 989 | - ) |
|
| 990 | - ); |
|
| 976 | + return !strlen( |
|
| 977 | + preg_replace( |
|
| 978 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 979 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 980 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 981 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 982 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 983 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 984 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 985 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 986 | + . ',sS', |
|
| 987 | + '', |
|
| 988 | + $string |
|
| 989 | + ) |
|
| 990 | + ); |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | /** |
@@ -999,13 +999,13 @@ discard block |
||
| 999 | 999 | * true si c'est le cas |
| 1000 | 1000 | **/ |
| 1001 | 1001 | function is_ascii($string) { |
| 1002 | - return !strlen( |
|
| 1003 | - preg_replace( |
|
| 1004 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1005 | - '', |
|
| 1006 | - $string |
|
| 1007 | - ) |
|
| 1008 | - ); |
|
| 1002 | + return !strlen( |
|
| 1003 | + preg_replace( |
|
| 1004 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1005 | + '', |
|
| 1006 | + $string |
|
| 1007 | + ) |
|
| 1008 | + ); |
|
| 1009 | 1009 | } |
| 1010 | 1010 | |
| 1011 | 1011 | /** |
@@ -1024,53 +1024,53 @@ discard block |
||
| 1024 | 1024 | **/ |
| 1025 | 1025 | function transcoder_page($texte, $headers = '') { |
| 1026 | 1026 | |
| 1027 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1028 | - if (is_ascii($texte)) { |
|
| 1029 | - #spip_log('charset: ascii'); |
|
| 1030 | - return $texte; |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - if (bom_utf8($texte)) { |
|
| 1034 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1035 | - $charset = 'utf-8'; |
|
| 1036 | - $texte = substr($texte, 3); |
|
| 1037 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1038 | - // charset precise par le contenu (xml) |
|
| 1039 | - $charset = trim(strtolower($regs[1])); |
|
| 1040 | - } elseif ( |
|
| 1041 | - // charset precise par le contenu (html) |
|
| 1042 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1043 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1044 | - and false === strpos($regs[2], '#') |
|
| 1045 | - and $tmp = trim(strtolower($regs[2])) |
|
| 1046 | - ) { |
|
| 1047 | - $charset = $tmp; |
|
| 1048 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1049 | - // charset de la reponse http |
|
| 1050 | - $charset = trim(strtolower($regs[1])); |
|
| 1051 | - } else { |
|
| 1052 | - $charset = ''; |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - |
|
| 1056 | - // normaliser les noms du shif-jis japonais |
|
| 1057 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1058 | - $charset = 'shift-jis'; |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - if ($charset) { |
|
| 1062 | - spip_log("charset: $charset"); |
|
| 1063 | - } else { |
|
| 1064 | - // valeur par defaut |
|
| 1065 | - if (is_utf8($texte)) { |
|
| 1066 | - $charset = 'utf-8'; |
|
| 1067 | - } else { |
|
| 1068 | - $charset = 'iso-8859-1'; |
|
| 1069 | - } |
|
| 1070 | - spip_log("charset probable: $charset"); |
|
| 1071 | - } |
|
| 1072 | - |
|
| 1073 | - return importer_charset($texte, $charset); |
|
| 1027 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1028 | + if (is_ascii($texte)) { |
|
| 1029 | + #spip_log('charset: ascii'); |
|
| 1030 | + return $texte; |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + if (bom_utf8($texte)) { |
|
| 1034 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1035 | + $charset = 'utf-8'; |
|
| 1036 | + $texte = substr($texte, 3); |
|
| 1037 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1038 | + // charset precise par le contenu (xml) |
|
| 1039 | + $charset = trim(strtolower($regs[1])); |
|
| 1040 | + } elseif ( |
|
| 1041 | + // charset precise par le contenu (html) |
|
| 1042 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1043 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1044 | + and false === strpos($regs[2], '#') |
|
| 1045 | + and $tmp = trim(strtolower($regs[2])) |
|
| 1046 | + ) { |
|
| 1047 | + $charset = $tmp; |
|
| 1048 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1049 | + // charset de la reponse http |
|
| 1050 | + $charset = trim(strtolower($regs[1])); |
|
| 1051 | + } else { |
|
| 1052 | + $charset = ''; |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + |
|
| 1056 | + // normaliser les noms du shif-jis japonais |
|
| 1057 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1058 | + $charset = 'shift-jis'; |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + if ($charset) { |
|
| 1062 | + spip_log("charset: $charset"); |
|
| 1063 | + } else { |
|
| 1064 | + // valeur par defaut |
|
| 1065 | + if (is_utf8($texte)) { |
|
| 1066 | + $charset = 'utf-8'; |
|
| 1067 | + } else { |
|
| 1068 | + $charset = 'iso-8859-1'; |
|
| 1069 | + } |
|
| 1070 | + spip_log("charset probable: $charset"); |
|
| 1071 | + } |
|
| 1072 | + |
|
| 1073 | + return importer_charset($texte, $charset); |
|
| 1074 | 1074 | } |
| 1075 | 1075 | |
| 1076 | 1076 | |
@@ -1094,26 +1094,26 @@ discard block |
||
| 1094 | 1094 | * Le texte coupé |
| 1095 | 1095 | **/ |
| 1096 | 1096 | function spip_substr($c, $start = 0, $length = null) { |
| 1097 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1098 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1099 | - if ($length) { |
|
| 1100 | - return substr($c, $start, $length); |
|
| 1101 | - } else { |
|
| 1102 | - substr($c, $start); |
|
| 1103 | - } |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1107 | - if (init_mb_string()) { |
|
| 1108 | - if ($length) { |
|
| 1109 | - return mb_substr($c, $start, $length); |
|
| 1110 | - } else { |
|
| 1111 | - return mb_substr($c, $start); |
|
| 1112 | - } |
|
| 1113 | - } |
|
| 1114 | - |
|
| 1115 | - // Version manuelle (cf. ci-dessous) |
|
| 1116 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1097 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1098 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1099 | + if ($length) { |
|
| 1100 | + return substr($c, $start, $length); |
|
| 1101 | + } else { |
|
| 1102 | + substr($c, $start); |
|
| 1103 | + } |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1107 | + if (init_mb_string()) { |
|
| 1108 | + if ($length) { |
|
| 1109 | + return mb_substr($c, $start, $length); |
|
| 1110 | + } else { |
|
| 1111 | + return mb_substr($c, $start); |
|
| 1112 | + } |
|
| 1113 | + } |
|
| 1114 | + |
|
| 1115 | + // Version manuelle (cf. ci-dessous) |
|
| 1116 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1117 | 1117 | } |
| 1118 | 1118 | |
| 1119 | 1119 | |
@@ -1132,40 +1132,40 @@ discard block |
||
| 1132 | 1132 | **/ |
| 1133 | 1133 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1134 | 1134 | |
| 1135 | - // Cas pathologique |
|
| 1136 | - if ($length === 0) { |
|
| 1137 | - return ''; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - // S'il y a un demarrage, on se positionne |
|
| 1141 | - if ($start > 0) { |
|
| 1142 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1143 | - } elseif ($start < 0) { |
|
| 1144 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - if (!$length) { |
|
| 1148 | - return $c; |
|
| 1149 | - } |
|
| 1150 | - |
|
| 1151 | - if ($length > 0) { |
|
| 1152 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1153 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1154 | - $n = 0; |
|
| 1155 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1156 | - ; |
|
| 1157 | - } |
|
| 1158 | - $c = substr($c, 0, $n * $length); |
|
| 1159 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1160 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1161 | - $c = substr($c, 0, $length - $l); |
|
| 1162 | - } |
|
| 1163 | - |
|
| 1164 | - return $c; |
|
| 1165 | - } |
|
| 1166 | - |
|
| 1167 | - // $length < 0 |
|
| 1168 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1135 | + // Cas pathologique |
|
| 1136 | + if ($length === 0) { |
|
| 1137 | + return ''; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + // S'il y a un demarrage, on se positionne |
|
| 1141 | + if ($start > 0) { |
|
| 1142 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1143 | + } elseif ($start < 0) { |
|
| 1144 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + if (!$length) { |
|
| 1148 | + return $c; |
|
| 1149 | + } |
|
| 1150 | + |
|
| 1151 | + if ($length > 0) { |
|
| 1152 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1153 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1154 | + $n = 0; |
|
| 1155 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1156 | + ; |
|
| 1157 | + } |
|
| 1158 | + $c = substr($c, 0, $n * $length); |
|
| 1159 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1160 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1161 | + $c = substr($c, 0, $length - $l); |
|
| 1162 | + } |
|
| 1163 | + |
|
| 1164 | + return $c; |
|
| 1165 | + } |
|
| 1166 | + |
|
| 1167 | + // $length < 0 |
|
| 1168 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1169 | 1169 | } |
| 1170 | 1170 | |
| 1171 | 1171 | /** |
@@ -1179,14 +1179,14 @@ discard block |
||
| 1179 | 1179 | * La chaîne avec une majuscule sur le premier mot |
| 1180 | 1180 | */ |
| 1181 | 1181 | function spip_ucfirst($c) { |
| 1182 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1183 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1184 | - return ucfirst($c); |
|
| 1185 | - } |
|
| 1182 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1183 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1184 | + return ucfirst($c); |
|
| 1185 | + } |
|
| 1186 | 1186 | |
| 1187 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1187 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1188 | 1188 | |
| 1189 | - return $lettre1 . spip_substr($c, 1); |
|
| 1189 | + return $lettre1 . spip_substr($c, 1); |
|
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | /** |
@@ -1200,12 +1200,12 @@ discard block |
||
| 1200 | 1200 | * La chaîne en minuscules |
| 1201 | 1201 | */ |
| 1202 | 1202 | function spip_strtolower($c) { |
| 1203 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1204 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1205 | - return strtolower($c); |
|
| 1206 | - } |
|
| 1203 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1204 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1205 | + return strtolower($c); |
|
| 1206 | + } |
|
| 1207 | 1207 | |
| 1208 | - return mb_strtolower($c); |
|
| 1208 | + return mb_strtolower($c); |
|
| 1209 | 1209 | } |
| 1210 | 1210 | |
| 1211 | 1211 | /** |
@@ -1219,23 +1219,23 @@ discard block |
||
| 1219 | 1219 | * Longueur de la chaîne |
| 1220 | 1220 | */ |
| 1221 | 1221 | function spip_strlen($c) { |
| 1222 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1223 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1224 | - |
|
| 1225 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1226 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1227 | - return strlen($c); |
|
| 1228 | - } |
|
| 1229 | - |
|
| 1230 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1231 | - if (init_mb_string()) { |
|
| 1232 | - return mb_strlen($c); |
|
| 1233 | - } |
|
| 1234 | - |
|
| 1235 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1236 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1237 | - // de caracteres utf-8 (11......) |
|
| 1238 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1222 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1223 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1224 | + |
|
| 1225 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1226 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1227 | + return strlen($c); |
|
| 1228 | + } |
|
| 1229 | + |
|
| 1230 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1231 | + if (init_mb_string()) { |
|
| 1232 | + return mb_strlen($c); |
|
| 1233 | + } |
|
| 1234 | + |
|
| 1235 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1236 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1237 | + // de caracteres utf-8 (11......) |
|
| 1238 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1239 | 1239 | } |
| 1240 | 1240 | |
| 1241 | 1241 | // Initialisation |
@@ -1245,16 +1245,16 @@ discard block |
||
| 1245 | 1245 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1246 | 1246 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1247 | 1247 | if ( |
| 1248 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 1249 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1248 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 1249 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1250 | 1250 | ) { |
| 1251 | - include_spip('inc/meta'); |
|
| 1252 | - ecrire_meta( |
|
| 1253 | - 'pcre_u', |
|
| 1254 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1255 | - and test_pcre_unicode()) |
|
| 1256 | - ? 'u' : '' |
|
| 1257 | - ); |
|
| 1251 | + include_spip('inc/meta'); |
|
| 1252 | + ecrire_meta( |
|
| 1253 | + 'pcre_u', |
|
| 1254 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1255 | + and test_pcre_unicode()) |
|
| 1256 | + ? 'u' : '' |
|
| 1257 | + ); |
|
| 1258 | 1258 | } |
| 1259 | 1259 | |
| 1260 | 1260 | |
@@ -1270,17 +1270,17 @@ discard block |
||
| 1270 | 1270 | * en unicode : 💩 |
| 1271 | 1271 | */ |
| 1272 | 1272 | function utf8_noplanes($x) { |
| 1273 | - $regexp_utf8_4bytes = '/( |
|
| 1273 | + $regexp_utf8_4bytes = '/( |
|
| 1274 | 1274 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1275 | 1275 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1276 | 1276 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1277 | 1277 | )/xS'; |
| 1278 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1279 | - foreach ($z[0] as $k) { |
|
| 1280 | - $ku = utf_8_to_unicode($k); |
|
| 1281 | - $x = str_replace($k, $ku, $x); |
|
| 1282 | - } |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - return $x; |
|
| 1278 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1279 | + foreach ($z[0] as $k) { |
|
| 1280 | + $ku = utf_8_to_unicode($k); |
|
| 1281 | + $x = str_replace($k, $ku, $x); |
|
| 1282 | + } |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + return $x; |
|
| 1286 | 1286 | } |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | } |
| 74 | 74 | } |
| 75 | 75 | |
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 76 | + if (find_in_path($charset.'.php', 'charsets/', true)) { |
|
| 77 | 77 | return $charset; |
| 78 | 78 | } else { |
| 79 | 79 | spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | static $pcre_ok = 0; |
| 161 | 161 | |
| 162 | 162 | if (!$pcre_ok) { |
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 163 | + $s = ' '.chr(195).chr(169).'t'.chr(195).chr(169).' '; |
|
| 164 | 164 | if (preg_match(',\W...\W,u', $s)) { |
| 165 | 165 | $pcre_ok = 1; |
| 166 | 166 | } else { |
@@ -261,38 +261,38 @@ discard block |
||
| 261 | 261 | |
| 262 | 262 | if (!isset($trans[$charset][$charset_cible])) { |
| 263 | 263 | $trans[$charset][$charset_cible] = [ |
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 264 | + $p.chr(128) => '€', |
|
| 265 | + $p.chr(129) => ' ', # pas affecte |
|
| 266 | + $p.chr(130) => '‚', |
|
| 267 | + $p.chr(131) => 'ƒ', |
|
| 268 | + $p.chr(132) => '„', |
|
| 269 | + $p.chr(133) => '…', |
|
| 270 | + $p.chr(134) => '†', |
|
| 271 | + $p.chr(135) => '‡', |
|
| 272 | + $p.chr(136) => 'ˆ', |
|
| 273 | + $p.chr(137) => '‰', |
|
| 274 | + $p.chr(138) => 'Š', |
|
| 275 | + $p.chr(139) => '‹', |
|
| 276 | + $p.chr(140) => 'Œ', |
|
| 277 | + $p.chr(141) => ' ', # pas affecte |
|
| 278 | + $p.chr(142) => 'Ž', |
|
| 279 | + $p.chr(143) => ' ', # pas affecte |
|
| 280 | + $p.chr(144) => ' ', # pas affecte |
|
| 281 | + $p.chr(145) => '‘', |
|
| 282 | + $p.chr(146) => '’', |
|
| 283 | + $p.chr(147) => '“', |
|
| 284 | + $p.chr(148) => '”', |
|
| 285 | + $p.chr(149) => '•', |
|
| 286 | + $p.chr(150) => '–', |
|
| 287 | + $p.chr(151) => '—', |
|
| 288 | + $p.chr(152) => '˜', |
|
| 289 | + $p.chr(153) => '™', |
|
| 290 | + $p.chr(154) => 'š', |
|
| 291 | + $p.chr(155) => '›', |
|
| 292 | + $p.chr(156) => 'œ', |
|
| 293 | + $p.chr(157) => ' ', # pas affecte |
|
| 294 | + $p.chr(158) => 'ž', |
|
| 295 | + $p.chr(159) => 'Ÿ', |
|
| 296 | 296 | ]; |
| 297 | 297 | if ($charset_cible != 'unicode') { |
| 298 | 298 | foreach ($trans[$charset][$charset_cible] as $k => $c) { |
@@ -433,7 +433,7 @@ discard block |
||
| 433 | 433 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 434 | 434 | ) { |
| 435 | 435 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 436 | + $trans[$charset][chr($key)] = '&#'.$val.';'; |
|
| 437 | 437 | } |
| 438 | 438 | } |
| 439 | 439 | } |
@@ -500,11 +500,11 @@ discard block |
||
| 500 | 500 | $h = dechex($e); |
| 501 | 501 | if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
| 502 | 502 | $s = $CHARSET_REVERSE[$charset][$e]; |
| 503 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 503 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($s); |
|
| 504 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($s); |
|
| 505 | 505 | } else { |
| 506 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 506 | + $t['&#'.$e.';'] = $t['�'.$e.';'] = $t['�'.$e.';'] = chr($e); |
|
| 507 | + $t['&#x'.$h.';'] = $t['�'.$h.';'] = $t['�'.$h.';'] = chr($e); |
|
| 508 | 508 | } |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | and is_array($GLOBALS['CHARSET'][$cset]) |
| 551 | 551 | ) { |
| 552 | 552 | foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
| 553 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 553 | + $trans[$charset][chr($key)] = unicode2charset('&#'.$val.';'); |
|
| 554 | 554 | } |
| 555 | 555 | } |
| 556 | 556 | } |
@@ -657,7 +657,7 @@ discard block |
||
| 657 | 657 | } |
| 658 | 658 | $thisPos++; |
| 659 | 659 | } |
| 660 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 660 | + $encodedLetter = '&#'.preg_replace('/^0+/', '', $decimalCode).';'; |
|
| 661 | 661 | $encodedString .= $encodedLetter; |
| 662 | 662 | } |
| 663 | 663 | } |
@@ -700,7 +700,7 @@ discard block |
||
| 700 | 700 | } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
| 701 | 701 | else { |
| 702 | 702 | if ($word != 65279) { |
| 703 | - $texte .= '&#' . $word . ';'; |
|
| 703 | + $texte .= '&#'.$word.';'; |
|
| 704 | 704 | } |
| 705 | 705 | } |
| 706 | 706 | } |
@@ -728,13 +728,13 @@ discard block |
||
| 728 | 728 | return chr($num); |
| 729 | 729 | } |
| 730 | 730 | if ($num < 2048) { |
| 731 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 731 | + return chr(($num >> 6) + 192).chr(($num & 63) + 128); |
|
| 732 | 732 | } |
| 733 | 733 | if ($num < 65536) { |
| 734 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 734 | + return chr(($num >> 12) + 224).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 735 | 735 | } |
| 736 | 736 | if ($num < 1114112) { |
| 737 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 737 | + return chr(($num >> 18) + 240).chr((($num >> 12) & 63) + 128).chr((($num >> 6) & 63) + 128).chr(($num & 63) + 128); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | return ''; |
@@ -801,7 +801,7 @@ discard block |
||
| 801 | 801 | while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
| 802 | 802 | $num = $regs[1]; |
| 803 | 803 | $vu[$num] = true; |
| 804 | - $s = '\u' . sprintf('%04x', $num); |
|
| 804 | + $s = '\u'.sprintf('%04x', $num); |
|
| 805 | 805 | $texte = str_replace($regs[0], $s, $texte); |
| 806 | 806 | } |
| 807 | 807 | |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | **/ |
| 819 | 819 | function javascript_to_unicode($texte) { |
| 820 | 820 | while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
| 821 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 821 | + $texte = str_replace($regs[0], '&#'.hexdec($regs[1]).';', $texte); |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | return $texte; |
@@ -863,7 +863,7 @@ discard block |
||
| 863 | 863 | return $texte; |
| 864 | 864 | } |
| 865 | 865 | |
| 866 | - $table_translit = 'translit' . $complexe; |
|
| 866 | + $table_translit = 'translit'.$complexe; |
|
| 867 | 867 | |
| 868 | 868 | // 2. Translitterer grace a la table predefinie |
| 869 | 869 | if (!isset($trans[$complexe])) { |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | if ($chiffres) { |
| 925 | 925 | $texte = preg_replace_callback( |
| 926 | 926 | "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
| 927 | - function ($m) { |
|
| 927 | + function($m) { |
|
| 928 | 928 | return translitteration_chiffree($m[0]); |
| 929 | 929 | }, |
| 930 | 930 | $texte |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | * true s'il a un BOM |
| 957 | 957 | **/ |
| 958 | 958 | function bom_utf8($texte) { |
| 959 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 959 | + return (substr($texte, 0, 3) == chr(0xEF).chr(0xBB).chr(0xBF)); |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | /** |
@@ -1152,7 +1152,7 @@ discard block |
||
| 1152 | 1152 | // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
| 1153 | 1153 | // (un caractere utf-8 prenant au maximum n bytes) |
| 1154 | 1154 | $n = 0; |
| 1155 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | + while (preg_match(',[\x80-\xBF]{'.(++$n).'},', $c)) { |
|
| 1156 | 1156 | ; |
| 1157 | 1157 | } |
| 1158 | 1158 | $c = substr($c, 0, $n * $length); |
@@ -1186,7 +1186,7 @@ discard block |
||
| 1186 | 1186 | |
| 1187 | 1187 | $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
| 1188 | 1188 | |
| 1189 | - return $lettre1 . spip_substr($c, 1); |
|
| 1189 | + return $lettre1.spip_substr($c, 1); |
|
| 1190 | 1190 | } |
| 1191 | 1191 | |
| 1192 | 1192 | /** |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Presentation |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/presentation_mini'); |
@@ -32,141 +32,141 @@ discard block |
||
| 32 | 32 | |
| 33 | 33 | // https://code.spip.net/@debut_cadre |
| 34 | 34 | function debut_cadre($style, $icone = '', $fonction = '', $titre = '', $id = '', $class = '', $padding = true) { |
| 35 | - $style_mapping = [ |
|
| 36 | - 'r' => 'simple', |
|
| 37 | - 'e' => 'raccourcis', |
|
| 38 | - 'couleur' => 'basic highlight', |
|
| 39 | - 'couleur-foncee' => 'basic highlight', |
|
| 40 | - 'trait-couleur' => 'important', |
|
| 41 | - 'alerte' => 'notice', |
|
| 42 | - 'info' => 'info', |
|
| 43 | - 'sous_rub' => 'simple sous-rub' |
|
| 44 | - ]; |
|
| 45 | - $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
|
| 46 | - $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple'; |
|
| 47 | - $class = $c . ($class ? " $class" : ''); |
|
| 48 | - if (!$padding) { |
|
| 49 | - $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - //($id?"id='$id' ":"") |
|
| 53 | - if (strlen($icone) > 1) { |
|
| 54 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 55 | - list($fond, $fonction) = $icone_renommer($icone, $fonction); |
|
| 56 | - } |
|
| 57 | - $size = 24; |
|
| 58 | - if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) { |
|
| 59 | - $size = $match[1]; |
|
| 60 | - } |
|
| 61 | - if ($fonction) { |
|
| 62 | - // 2 images pour composer l'icone : le fond (article) en background, |
|
| 63 | - // la fonction (new) en image |
|
| 64 | - $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 65 | - http_style_background($fond, 'no-repeat center center', $size)); |
|
| 66 | - } else { |
|
| 67 | - $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
|
| 68 | - } |
|
| 69 | - $titre = $icone . $titre; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id); |
|
| 35 | + $style_mapping = [ |
|
| 36 | + 'r' => 'simple', |
|
| 37 | + 'e' => 'raccourcis', |
|
| 38 | + 'couleur' => 'basic highlight', |
|
| 39 | + 'couleur-foncee' => 'basic highlight', |
|
| 40 | + 'trait-couleur' => 'important', |
|
| 41 | + 'alerte' => 'notice', |
|
| 42 | + 'info' => 'info', |
|
| 43 | + 'sous_rub' => 'simple sous-rub' |
|
| 44 | + ]; |
|
| 45 | + $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
|
| 46 | + $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple'; |
|
| 47 | + $class = $c . ($class ? " $class" : ''); |
|
| 48 | + if (!$padding) { |
|
| 49 | + $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + //($id?"id='$id' ":"") |
|
| 53 | + if (strlen($icone) > 1) { |
|
| 54 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 55 | + list($fond, $fonction) = $icone_renommer($icone, $fonction); |
|
| 56 | + } |
|
| 57 | + $size = 24; |
|
| 58 | + if (preg_match('/-([0-9]{1,3})[.](gif|png)$/i', $fond, $match)) { |
|
| 59 | + $size = $match[1]; |
|
| 60 | + } |
|
| 61 | + if ($fonction) { |
|
| 62 | + // 2 images pour composer l'icone : le fond (article) en background, |
|
| 63 | + // la fonction (new) en image |
|
| 64 | + $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 65 | + http_style_background($fond, 'no-repeat center center', $size)); |
|
| 66 | + } else { |
|
| 67 | + $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
|
| 68 | + } |
|
| 69 | + $titre = $icone . $titre; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // https://code.spip.net/@fin_cadre |
| 76 | 76 | function fin_cadre() { |
| 77 | - return boite_fermer(); |
|
| 77 | + return boite_fermer(); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
| 81 | 81 | function debut_cadre_relief( |
| 82 | - $icone = '', |
|
| 83 | - $dummy = '', |
|
| 84 | - $fonction = '', |
|
| 85 | - $titre = '', |
|
| 86 | - $id = '', |
|
| 87 | - $class = '' |
|
| 82 | + $icone = '', |
|
| 83 | + $dummy = '', |
|
| 84 | + $fonction = '', |
|
| 85 | + $titre = '', |
|
| 86 | + $id = '', |
|
| 87 | + $class = '' |
|
| 88 | 88 | ) { |
| 89 | - return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 89 | + return debut_cadre('r', $icone, $fonction, $titre, $id, $class); |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | function fin_cadre_relief() { |
| 93 | - return fin_cadre('r'); |
|
| 93 | + return fin_cadre('r'); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | function debut_cadre_enfonce( |
| 97 | - $icone = '', |
|
| 98 | - $dummy = '', |
|
| 99 | - $fonction = '', |
|
| 100 | - $titre = '', |
|
| 101 | - $id = '', |
|
| 102 | - $class = '' |
|
| 97 | + $icone = '', |
|
| 98 | + $dummy = '', |
|
| 99 | + $fonction = '', |
|
| 100 | + $titre = '', |
|
| 101 | + $id = '', |
|
| 102 | + $class = '' |
|
| 103 | 103 | ) { |
| 104 | - return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 104 | + return debut_cadre('e', $icone, $fonction, $titre, $id, $class); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | function fin_cadre_enfonce() { |
| 108 | - return fin_cadre('e'); |
|
| 108 | + return fin_cadre('e'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | function debut_cadre_sous_rub( |
| 112 | - $icone = '', |
|
| 113 | - $dummy = '', |
|
| 114 | - $fonction = '', |
|
| 115 | - $titre = '', |
|
| 116 | - $id = '', |
|
| 117 | - $class = '' |
|
| 112 | + $icone = '', |
|
| 113 | + $dummy = '', |
|
| 114 | + $fonction = '', |
|
| 115 | + $titre = '', |
|
| 116 | + $id = '', |
|
| 117 | + $class = '' |
|
| 118 | 118 | ) { |
| 119 | - return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 119 | + return debut_cadre('sous_rub', $icone, $fonction, $titre, $id, $class); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | function fin_cadre_sous_rub() { |
| 123 | - return fin_cadre('sous_rub'); |
|
| 123 | + return fin_cadre('sous_rub'); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | function debut_cadre_couleur( |
| 127 | - $icone = '', |
|
| 128 | - $dummy = '', |
|
| 129 | - $fonction = '', |
|
| 130 | - $titre = '', |
|
| 131 | - $id = '', |
|
| 132 | - $class = '' |
|
| 127 | + $icone = '', |
|
| 128 | + $dummy = '', |
|
| 129 | + $fonction = '', |
|
| 130 | + $titre = '', |
|
| 131 | + $id = '', |
|
| 132 | + $class = '' |
|
| 133 | 133 | ) { |
| 134 | - return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 134 | + return debut_cadre('couleur', $icone, $fonction, $titre, $id, $class); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | function fin_cadre_couleur() { |
| 138 | - return fin_cadre('couleur'); |
|
| 138 | + return fin_cadre('couleur'); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function debut_cadre_trait_couleur( |
| 142 | - $icone = '', |
|
| 143 | - $dummy = '', |
|
| 144 | - $fonction = '', |
|
| 145 | - $titre = '', |
|
| 146 | - $id = '', |
|
| 147 | - $class = '' |
|
| 142 | + $icone = '', |
|
| 143 | + $dummy = '', |
|
| 144 | + $fonction = '', |
|
| 145 | + $titre = '', |
|
| 146 | + $id = '', |
|
| 147 | + $class = '' |
|
| 148 | 148 | ) { |
| 149 | - return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 149 | + return debut_cadre('trait-couleur', $icone, $fonction, $titre, $id, $class); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | function fin_cadre_trait_couleur() { |
| 153 | - return fin_cadre('trait-couleur'); |
|
| 153 | + return fin_cadre('trait-couleur'); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | function debut_boite_alerte() { |
| 157 | - return debut_cadre('alerte', '', '', '', '', ''); |
|
| 157 | + return debut_cadre('alerte', '', '', '', '', ''); |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | function fin_boite_alerte() { |
| 161 | - return fin_cadre('alerte'); |
|
| 161 | + return fin_cadre('alerte'); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | function debut_boite_info() { |
| 165 | - return debut_cadre('info', '', '', '', '', ''); |
|
| 165 | + return debut_cadre('info', '', '', '', '', ''); |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | function fin_boite_info() { |
| 169 | - return fin_cadre('info'); |
|
| 169 | + return fin_cadre('info'); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -177,18 +177,18 @@ discard block |
||
| 177 | 177 | * @return string Code PHP. |
| 178 | 178 | **/ |
| 179 | 179 | function gros_titre( |
| 180 | - $titre, |
|
| 181 | - $ze_logo = '' |
|
| 180 | + $titre, |
|
| 181 | + $ze_logo = '' |
|
| 182 | 182 | ) { |
| 183 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 183 | + return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // La boite des raccourcis |
| 187 | 187 | // Se place a droite si l'ecran est en mode panoramique. |
| 188 | 188 | // https://code.spip.net/@bloc_des_raccourcis |
| 189 | 189 | function bloc_des_raccourcis($bloc) { |
| 190 | - return creer_colonne_droite() |
|
| 191 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 190 | + return creer_colonne_droite() |
|
| 191 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // |
@@ -199,20 +199,20 @@ discard block |
||
| 199 | 199 | // https://code.spip.net/@debut_onglet |
| 200 | 200 | // @param string $sous_classe prend la valeur second pour definir les onglet de deuxieme niveau |
| 201 | 201 | function debut_onglet($classe = 'barre_onglet') { |
| 202 | - return "<div class = '$classe clearfix'><ul>\n"; |
|
| 202 | + return "<div class = '$classe clearfix'><ul>\n"; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // https://code.spip.net/@fin_onglet |
| 206 | 206 | function fin_onglet() { |
| 207 | - return "</ul></div>\n"; |
|
| 207 | + return "</ul></div>\n"; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | // https://code.spip.net/@onglet |
| 211 | 211 | function onglet($texte, $lien, $onglet_ref, $onglet, $icone = '') { |
| 212 | - return '<li>' |
|
| 213 | - . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 214 | - . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 215 | - . '</li>'; |
|
| 212 | + return '<li>' |
|
| 213 | + . ($icone ? http_img_pack($icone, '', " class='cadre-icone'") : '') |
|
| 214 | + . lien_ou_expose($lien, $texte, $onglet == $onglet_ref) |
|
| 215 | + . '</li>'; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -244,14 +244,14 @@ discard block |
||
| 244 | 244 | * Code HTML du lien |
| 245 | 245 | **/ |
| 246 | 246 | function icone_verticale($texte, $lien, $fond, $fonction = '', $align = '', $javascript = '') { |
| 247 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 248 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 249 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 250 | - list($x, $lien, $atts, $texte) = $r; |
|
| 251 | - $javascript .= $atts; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 247 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 248 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 249 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 250 | + list($x, $lien, $atts, $texte) = $r; |
|
| 251 | + $javascript .= $atts; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align", $javascript); |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | /** |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | * Code HTML du lien |
| 277 | 277 | **/ |
| 278 | 278 | function icone_horizontale($texte, $lien, $fond, $fonction = '', $dummy = '', $javascript = '') { |
| 279 | - $retour = ''; |
|
| 280 | - // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 281 | - // (il faudrait fusionner avec le cas $javascript) |
|
| 282 | - if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 283 | - list($x, $lien, $atts, $texte) = $r; |
|
| 284 | - $javascript .= $atts; |
|
| 285 | - } |
|
| 279 | + $retour = ''; |
|
| 280 | + // cas d'ajax_action_auteur: faut defaire le boulot |
|
| 281 | + // (il faudrait fusionner avec le cas $javascript) |
|
| 282 | + if (preg_match(",^<a\shref='([^']*)'([^>]*)>(.*)</a>$,i", $lien, $r)) { |
|
| 283 | + list($x, $lien, $atts, $texte) = $r; |
|
| 284 | + $javascript .= $atts; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript); |
|
| 287 | + $retour = icone_base($lien, $texte, $fond, $fonction, 'horizontale', $javascript); |
|
| 288 | 288 | |
| 289 | - return $retour; |
|
| 289 | + return $retour; |
|
| 290 | 290 | } |
@@ -44,9 +44,9 @@ discard block |
||
| 44 | 44 | ]; |
| 45 | 45 | $style_titre_mapping = ['couleur' => 'topper', 'trait-couleur' => 'section']; |
| 46 | 46 | $c = isset($style_mapping[$style]) ? $style_mapping[$style] : 'simple'; |
| 47 | - $class = $c . ($class ? " $class" : ''); |
|
| 47 | + $class = $c.($class ? " $class" : ''); |
|
| 48 | 48 | if (!$padding) { |
| 49 | - $class .= ($class ? ' ' : '') . 'no-padding'; |
|
| 49 | + $class .= ($class ? ' ' : '').'no-padding'; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | //($id?"id='$id' ":"") |
@@ -61,12 +61,12 @@ discard block |
||
| 61 | 61 | if ($fonction) { |
| 62 | 62 | // 2 images pour composer l'icone : le fond (article) en background, |
| 63 | 63 | // la fonction (new) en image |
| 64 | - $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n" . |
|
| 64 | + $icone = http_img_pack($fonction, '', "class='cadre-icone' width='$size' height='$size'\n". |
|
| 65 | 65 | http_style_background($fond, 'no-repeat center center', $size)); |
| 66 | 66 | } else { |
| 67 | 67 | $icone = http_img_pack($fond, '', "class='cadre-icone' width='$size' height='$size'"); |
| 68 | 68 | } |
| 69 | - $titre = $icone . $titre; |
|
| 69 | + $titre = $icone.$titre; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | return boite_ouvrir($titre, $class, isset($style_titre_mapping[$style]) ? $style_titre_mapping[$style] : '', $id); |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $titre, |
| 181 | 181 | $ze_logo = '' |
| 182 | 182 | ) { |
| 183 | - return "<h1 class = 'grostitre'>" . $ze_logo . ' ' . typo($titre) . "</h1>\n"; |
|
| 183 | + return "<h1 class = 'grostitre'>".$ze_logo.' '.typo($titre)."</h1>\n"; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // La boite des raccourcis |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | // https://code.spip.net/@bloc_des_raccourcis |
| 189 | 189 | function bloc_des_raccourcis($bloc) { |
| 190 | 190 | return creer_colonne_droite() |
| 191 | - . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis') . $bloc . boite_fermer(); |
|
| 191 | + . boite_ouvrir(_T('titre_cadre_raccourcis'), 'raccourcis').$bloc.boite_fermer(); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | // |
@@ -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 | include_spip('inc/rechercher'); |
| 24 | 24 | if (!defined('_DELAI_CACHE_resultats')) { |
| 25 | - define('_DELAI_CACHE_resultats', 600); |
|
| 25 | + define('_DELAI_CACHE_resultats', 600); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -49,127 +49,127 @@ discard block |
||
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | 51 | function inc_prepare_recherche_dist( |
| 52 | - $recherche, |
|
| 53 | - $table = 'articles', |
|
| 54 | - $cond = false, |
|
| 55 | - $serveur = '', |
|
| 56 | - $modificateurs = [], |
|
| 57 | - $primary = '' |
|
| 52 | + $recherche, |
|
| 53 | + $table = 'articles', |
|
| 54 | + $cond = false, |
|
| 55 | + $serveur = '', |
|
| 56 | + $modificateurs = [], |
|
| 57 | + $primary = '' |
|
| 58 | 58 | ) { |
| 59 | - static $cache = []; |
|
| 60 | - $delai_fraicheur = min( |
|
| 61 | - _DELAI_CACHE_resultats, |
|
| 62 | - time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0) |
|
| 63 | - ); |
|
| 64 | - |
|
| 65 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 66 | - // ca permet de faire des inclure simple. |
|
| 67 | - if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 68 | - $recherche = $GLOBALS['recherche']; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // traiter le cas {recherche?} |
|
| 72 | - if ($cond and !strlen($recherche)) { |
|
| 73 | - return [ |
|
| 74 | - '0 as points' /* as points */, /* where */ |
|
| 75 | - '' |
|
| 76 | - ]; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - |
|
| 80 | - $rechercher = false; |
|
| 81 | - |
|
| 82 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 83 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 84 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 85 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 86 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 87 | - $row = sql_fetsel( |
|
| 88 | - 'recherche', |
|
| 89 | - 'spip_resultats AS resultats', |
|
| 90 | - $where . " AND $where_resultat_recent", |
|
| 91 | - '', |
|
| 92 | - '', |
|
| 93 | - '0,1' |
|
| 94 | - ); |
|
| 95 | - if ( |
|
| 96 | - !$row |
|
| 97 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 98 | - ) { |
|
| 99 | - $rechercher = true; |
|
| 100 | - } |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 104 | - if ($rechercher) { |
|
| 105 | - //$tables = liste_des_champs(); |
|
| 106 | - $x = objet_type($table); |
|
| 107 | - $points = recherche_en_base( |
|
| 108 | - $recherche, |
|
| 109 | - $x, |
|
| 110 | - [ |
|
| 111 | - 'score' => true, |
|
| 112 | - 'toutvoir' => true, |
|
| 113 | - 'jointures' => true |
|
| 114 | - ], |
|
| 115 | - $serveur |
|
| 116 | - ); |
|
| 117 | - // pas de résultat, pas de point |
|
| 118 | - $points = isset($points[$x]) ? $points[$x] : []; |
|
| 119 | - |
|
| 120 | - // permettre aux plugins de modifier le resultat |
|
| 121 | - $points = pipeline('prepare_recherche', [ |
|
| 122 | - 'args' => [ |
|
| 123 | - 'type' => $x, |
|
| 124 | - 'recherche' => $recherche, |
|
| 125 | - 'serveur' => $serveur, |
|
| 126 | - 'modificateurs' => $modificateurs |
|
| 127 | - ], |
|
| 128 | - 'data' => $points |
|
| 129 | - ]); |
|
| 130 | - |
|
| 131 | - // supprimer les anciens resultats de cette recherche |
|
| 132 | - // et les resultats trop vieux avec une marge |
|
| 133 | - // pas de AS resultats dans un delete (mysql) |
|
| 134 | - $whered = str_replace( |
|
| 135 | - ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 136 | - ['recherche', 'table_objet', 'serveur'], |
|
| 137 | - $where |
|
| 138 | - ); |
|
| 139 | - |
|
| 140 | - sql_delete( |
|
| 141 | - 'spip_resultats', |
|
| 142 | - "NOT($where_resultat_recent) OR ($whered)" |
|
| 143 | - ); |
|
| 144 | - |
|
| 145 | - // inserer les resultats dans la table de cache des resultats |
|
| 146 | - if (count($points)) { |
|
| 147 | - $tab_couples = []; |
|
| 148 | - foreach ($points as $id => $p) { |
|
| 149 | - $tab_couples[] = [ |
|
| 150 | - 'recherche' => $hash, |
|
| 151 | - 'id' => $id, |
|
| 152 | - 'points' => $p['score'], |
|
| 153 | - 'table_objet' => $table, |
|
| 154 | - 'serveur' => $hash_serv, |
|
| 155 | - ]; |
|
| 156 | - } |
|
| 157 | - sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 162 | - if (!$serveur) { |
|
| 163 | - $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 164 | - } else { |
|
| 165 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 166 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 167 | - } |
|
| 168 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return $cache[$serveur][$table][$recherche]; |
|
| 59 | + static $cache = []; |
|
| 60 | + $delai_fraicheur = min( |
|
| 61 | + _DELAI_CACHE_resultats, |
|
| 62 | + time() - (isset($GLOBALS['meta']['derniere_modif']) ? $GLOBALS['meta']['derniere_modif'] : 0) |
|
| 63 | + ); |
|
| 64 | + |
|
| 65 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 66 | + // ca permet de faire des inclure simple. |
|
| 67 | + if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 68 | + $recherche = $GLOBALS['recherche']; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // traiter le cas {recherche?} |
|
| 72 | + if ($cond and !strlen($recherche)) { |
|
| 73 | + return [ |
|
| 74 | + '0 as points' /* as points */, /* where */ |
|
| 75 | + '' |
|
| 76 | + ]; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + |
|
| 80 | + $rechercher = false; |
|
| 81 | + |
|
| 82 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 83 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 84 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 85 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 86 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 87 | + $row = sql_fetsel( |
|
| 88 | + 'recherche', |
|
| 89 | + 'spip_resultats AS resultats', |
|
| 90 | + $where . " AND $where_resultat_recent", |
|
| 91 | + '', |
|
| 92 | + '', |
|
| 93 | + '0,1' |
|
| 94 | + ); |
|
| 95 | + if ( |
|
| 96 | + !$row |
|
| 97 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 98 | + ) { |
|
| 99 | + $rechercher = true; |
|
| 100 | + } |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 104 | + if ($rechercher) { |
|
| 105 | + //$tables = liste_des_champs(); |
|
| 106 | + $x = objet_type($table); |
|
| 107 | + $points = recherche_en_base( |
|
| 108 | + $recherche, |
|
| 109 | + $x, |
|
| 110 | + [ |
|
| 111 | + 'score' => true, |
|
| 112 | + 'toutvoir' => true, |
|
| 113 | + 'jointures' => true |
|
| 114 | + ], |
|
| 115 | + $serveur |
|
| 116 | + ); |
|
| 117 | + // pas de résultat, pas de point |
|
| 118 | + $points = isset($points[$x]) ? $points[$x] : []; |
|
| 119 | + |
|
| 120 | + // permettre aux plugins de modifier le resultat |
|
| 121 | + $points = pipeline('prepare_recherche', [ |
|
| 122 | + 'args' => [ |
|
| 123 | + 'type' => $x, |
|
| 124 | + 'recherche' => $recherche, |
|
| 125 | + 'serveur' => $serveur, |
|
| 126 | + 'modificateurs' => $modificateurs |
|
| 127 | + ], |
|
| 128 | + 'data' => $points |
|
| 129 | + ]); |
|
| 130 | + |
|
| 131 | + // supprimer les anciens resultats de cette recherche |
|
| 132 | + // et les resultats trop vieux avec une marge |
|
| 133 | + // pas de AS resultats dans un delete (mysql) |
|
| 134 | + $whered = str_replace( |
|
| 135 | + ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 136 | + ['recherche', 'table_objet', 'serveur'], |
|
| 137 | + $where |
|
| 138 | + ); |
|
| 139 | + |
|
| 140 | + sql_delete( |
|
| 141 | + 'spip_resultats', |
|
| 142 | + "NOT($where_resultat_recent) OR ($whered)" |
|
| 143 | + ); |
|
| 144 | + |
|
| 145 | + // inserer les resultats dans la table de cache des resultats |
|
| 146 | + if (count($points)) { |
|
| 147 | + $tab_couples = []; |
|
| 148 | + foreach ($points as $id => $p) { |
|
| 149 | + $tab_couples[] = [ |
|
| 150 | + 'recherche' => $hash, |
|
| 151 | + 'id' => $id, |
|
| 152 | + 'points' => $p['score'], |
|
| 153 | + 'table_objet' => $table, |
|
| 154 | + 'serveur' => $hash_serv, |
|
| 155 | + ]; |
|
| 156 | + } |
|
| 157 | + sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 162 | + if (!$serveur) { |
|
| 163 | + $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 164 | + } else { |
|
| 165 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 166 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 167 | + } |
|
| 168 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return $cache[$serveur][$table][$recherche]; |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | |
@@ -185,22 +185,22 @@ discard block |
||
| 185 | 185 | * @return array |
| 186 | 186 | */ |
| 187 | 187 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 188 | - # calculer le {id_article IN()} et le {... as points} |
|
| 189 | - if (!count($rows)) { |
|
| 190 | - return ["''", '0=1']; |
|
| 191 | - } else { |
|
| 192 | - $listes_ids = []; |
|
| 193 | - $select = '0'; |
|
| 194 | - foreach ($rows as $r) { |
|
| 195 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - foreach ($listes_ids as $p => $ids) { |
|
| 199 | - $select .= "+$p*(" . |
|
| 200 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 201 | - . ') '; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 205 | - } |
|
| 188 | + # calculer le {id_article IN()} et le {... as points} |
|
| 189 | + if (!count($rows)) { |
|
| 190 | + return ["''", '0=1']; |
|
| 191 | + } else { |
|
| 192 | + $listes_ids = []; |
|
| 193 | + $select = '0'; |
|
| 194 | + foreach ($rows as $r) { |
|
| 195 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + foreach ($listes_ids as $p => $ids) { |
|
| 199 | + $select .= "+$p*(" . |
|
| 200 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 201 | + . ') '; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 205 | + } |
|
| 206 | 206 | } |
@@ -82,12 +82,12 @@ discard block |
||
| 82 | 82 | $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
| 83 | 83 | if (!isset($cache[$serveur][$table][$recherche])) { |
| 84 | 84 | $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
| 85 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 86 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 85 | + $hash = substr(md5($recherche.$table), 0, 16); |
|
| 86 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
|
| 87 | 87 | $row = sql_fetsel( |
| 88 | 88 | 'recherche', |
| 89 | 89 | 'spip_resultats AS resultats', |
| 90 | - $where . " AND $where_resultat_recent", |
|
| 90 | + $where." AND $where_resultat_recent", |
|
| 91 | 91 | '', |
| 92 | 92 | '', |
| 93 | 93 | '0,1' |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | foreach ($listes_ids as $p => $ids) { |
| 199 | - $select .= "+$p*(" . |
|
| 199 | + $select .= "+$p*(". |
|
| 200 | 200 | sql_in("$table.$primary", $ids, '', $serveur) |
| 201 | 201 | . ') '; |
| 202 | 202 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/charsets'); |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function exporter_csv_champ($champ) { |
| 35 | - #$champ = str_replace("\r", "\n", $champ); |
|
| 36 | - #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 37 | - #$champ = str_replace("\n", ", ", $champ); |
|
| 38 | - $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 39 | - $champ = str_replace('"', '""', $champ); |
|
| 35 | + #$champ = str_replace("\r", "\n", $champ); |
|
| 36 | + #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 37 | + #$champ = str_replace("\n", ", ", $champ); |
|
| 38 | + $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 39 | + $champ = str_replace('"', '""', $champ); |
|
| 40 | 40 | |
| 41 | - return '"' . $champ . '"'; |
|
| 41 | + return '"' . $champ . '"'; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | 57 | function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, $callback = null) { |
| 58 | - if ($callback) { |
|
| 59 | - $ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset); |
|
| 60 | - } |
|
| 61 | - $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 62 | - if ($importer_charset) { |
|
| 63 | - $output = str_replace('’', '\'', $output); |
|
| 64 | - $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 65 | - } |
|
| 66 | - return $output; |
|
| 58 | + if ($callback) { |
|
| 59 | + $ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset); |
|
| 60 | + } |
|
| 61 | + $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 62 | + if ($importer_charset) { |
|
| 63 | + $output = str_replace('’', '\'', $output); |
|
| 64 | + $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 65 | + } |
|
| 66 | + return $output; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | 77 | function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) { |
| 78 | - return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 78 | + return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -101,101 +101,101 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function inc_exporter_csv_dist($titre, $resource, $options = []) { |
| 103 | 103 | |
| 104 | - // support ancienne syntaxe |
|
| 105 | - // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 106 | - if (is_string($options)) { |
|
| 107 | - $args = func_get_args(); |
|
| 108 | - $options = []; |
|
| 109 | - foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 110 | - if (!empty($args[$k])) { |
|
| 111 | - $options[$option] = $args[$k]; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $default_options = [ |
|
| 117 | - 'delim' => ', ', |
|
| 118 | - 'entetes' => null, |
|
| 119 | - 'envoyer' => true, |
|
| 120 | - 'charset' => null, |
|
| 121 | - 'callback' => null, |
|
| 122 | - ]; |
|
| 123 | - $options = array_merge($default_options, $options); |
|
| 124 | - |
|
| 125 | - $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre)))); |
|
| 126 | - |
|
| 127 | - if ($options['delim'] == 'TAB') { |
|
| 128 | - $options['delim'] = "\t"; |
|
| 129 | - } |
|
| 130 | - if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 131 | - $options['delim'] = ','; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $charset = $GLOBALS['meta']['charset']; |
|
| 135 | - $importer_charset = null; |
|
| 136 | - if ($options['delim'] == ',') { |
|
| 137 | - $extension = 'csv'; |
|
| 138 | - } else { |
|
| 139 | - $extension = 'xls'; |
|
| 140 | - # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 141 | - $charset = 'iso-8859-1'; |
|
| 142 | - } |
|
| 143 | - // mais si une option charset est explicite, elle a la priorite |
|
| 144 | - if (!empty($options['charset'])) { |
|
| 145 | - $charset = $options['charset']; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset); |
|
| 149 | - |
|
| 150 | - $filename = "$filename.$extension"; |
|
| 151 | - |
|
| 152 | - $output = ''; |
|
| 153 | - $nb = 0; |
|
| 154 | - if (!empty($options['entetes']) and is_array($options['entetes'])) { |
|
| 155 | - $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 156 | - } |
|
| 157 | - // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 158 | - $nb++; |
|
| 159 | - |
|
| 160 | - if ($options['envoyer']) { |
|
| 161 | - $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 162 | - header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 163 | - header("Content-Disposition: $disposition; filename=$filename"); |
|
| 164 | - |
|
| 165 | - // Vider tous les tampons |
|
| 166 | - $level = @ob_get_level(); |
|
| 167 | - while ($level--) { |
|
| 168 | - @ob_end_flush(); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 173 | - // sinon on ecrit directement sur stdout |
|
| 174 | - if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
|
| 175 | - $fichier = 'php://output'; |
|
| 176 | - } |
|
| 177 | - else { |
|
| 178 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $fp = fopen($fichier, 'w'); |
|
| 182 | - $length = fwrite($fp, $output); |
|
| 183 | - |
|
| 184 | - while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 185 | - $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 186 | - $length += fwrite($fp, $output); |
|
| 187 | - $nb++; |
|
| 188 | - } |
|
| 189 | - fclose($fp); |
|
| 190 | - |
|
| 191 | - if ($options['envoyer']) { |
|
| 192 | - if ($options['envoyer'] === 'attachment') { |
|
| 193 | - header("Content-Length: $length"); |
|
| 194 | - readfile($fichier); |
|
| 195 | - } |
|
| 196 | - // si on a envoye inline, c'est deja tout bon |
|
| 197 | - exit; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $fichier; |
|
| 104 | + // support ancienne syntaxe |
|
| 105 | + // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 106 | + if (is_string($options)) { |
|
| 107 | + $args = func_get_args(); |
|
| 108 | + $options = []; |
|
| 109 | + foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 110 | + if (!empty($args[$k])) { |
|
| 111 | + $options[$option] = $args[$k]; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $default_options = [ |
|
| 117 | + 'delim' => ', ', |
|
| 118 | + 'entetes' => null, |
|
| 119 | + 'envoyer' => true, |
|
| 120 | + 'charset' => null, |
|
| 121 | + 'callback' => null, |
|
| 122 | + ]; |
|
| 123 | + $options = array_merge($default_options, $options); |
|
| 124 | + |
|
| 125 | + $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre)))); |
|
| 126 | + |
|
| 127 | + if ($options['delim'] == 'TAB') { |
|
| 128 | + $options['delim'] = "\t"; |
|
| 129 | + } |
|
| 130 | + if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 131 | + $options['delim'] = ','; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $charset = $GLOBALS['meta']['charset']; |
|
| 135 | + $importer_charset = null; |
|
| 136 | + if ($options['delim'] == ',') { |
|
| 137 | + $extension = 'csv'; |
|
| 138 | + } else { |
|
| 139 | + $extension = 'xls'; |
|
| 140 | + # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 141 | + $charset = 'iso-8859-1'; |
|
| 142 | + } |
|
| 143 | + // mais si une option charset est explicite, elle a la priorite |
|
| 144 | + if (!empty($options['charset'])) { |
|
| 145 | + $charset = $options['charset']; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset); |
|
| 149 | + |
|
| 150 | + $filename = "$filename.$extension"; |
|
| 151 | + |
|
| 152 | + $output = ''; |
|
| 153 | + $nb = 0; |
|
| 154 | + if (!empty($options['entetes']) and is_array($options['entetes'])) { |
|
| 155 | + $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 156 | + } |
|
| 157 | + // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 158 | + $nb++; |
|
| 159 | + |
|
| 160 | + if ($options['envoyer']) { |
|
| 161 | + $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 162 | + header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 163 | + header("Content-Disposition: $disposition; filename=$filename"); |
|
| 164 | + |
|
| 165 | + // Vider tous les tampons |
|
| 166 | + $level = @ob_get_level(); |
|
| 167 | + while ($level--) { |
|
| 168 | + @ob_end_flush(); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 173 | + // sinon on ecrit directement sur stdout |
|
| 174 | + if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
|
| 175 | + $fichier = 'php://output'; |
|
| 176 | + } |
|
| 177 | + else { |
|
| 178 | + $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $fp = fopen($fichier, 'w'); |
|
| 182 | + $length = fwrite($fp, $output); |
|
| 183 | + |
|
| 184 | + while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 185 | + $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 186 | + $length += fwrite($fp, $output); |
|
| 187 | + $nb++; |
|
| 188 | + } |
|
| 189 | + fclose($fp); |
|
| 190 | + |
|
| 191 | + if ($options['envoyer']) { |
|
| 192 | + if ($options['envoyer'] === 'attachment') { |
|
| 193 | + header("Content-Length: $length"); |
|
| 194 | + readfile($fichier); |
|
| 195 | + } |
|
| 196 | + // si on a envoye inline, c'est deja tout bon |
|
| 197 | + exit; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $fichier; |
|
| 201 | 201 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
| 39 | 39 | $champ = str_replace('"', '""', $champ); |
| 40 | 40 | |
| 41 | - return '"' . $champ . '"'; |
|
| 41 | + return '"'.$champ.'"'; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | if ($callback) { |
| 59 | 59 | $ligne = call_user_func($callback, $nb, $ligne, $delim, $importer_charset); |
| 60 | 60 | } |
| 61 | - $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 61 | + $output = join($delim, array_map('exporter_csv_champ', $ligne))."\r\n"; |
|
| 62 | 62 | if ($importer_charset) { |
| 63 | 63 | $output = str_replace('’', '\'', $output); |
| 64 | 64 | $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $fichier = 'php://output'; |
| 176 | 176 | } |
| 177 | 177 | else { |
| 178 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 178 | + $fichier = sous_repertoire(_DIR_CACHE, 'export').$filename; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $fp = fopen($fichier, 'w'); |
@@ -173,8 +173,7 @@ |
||
| 173 | 173 | // sinon on ecrit directement sur stdout |
| 174 | 174 | if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
| 175 | 175 | $fichier = 'php://output'; |
| 176 | - } |
|
| 177 | - else { |
|
| 176 | + } else { |
|
| 178 | 177 | $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
| 179 | 178 | } |
| 180 | 179 | |
@@ -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 | defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext'); |
@@ -35,22 +35,22 @@ discard block |
||
| 35 | 35 | * @return array Couples (type d'objet => Couples (champ => score)) |
| 36 | 36 | */ |
| 37 | 37 | function liste_des_champs() { |
| 38 | - static $liste = null; |
|
| 39 | - if (is_null($liste)) { |
|
| 40 | - $liste = []; |
|
| 41 | - // recuperer les tables_objets_sql declarees |
|
| 42 | - include_spip('base/objets'); |
|
| 43 | - $tables_objets = lister_tables_objets_sql(); |
|
| 44 | - foreach ($tables_objets as $t => $infos) { |
|
| 45 | - if ($infos['rechercher_champs']) { |
|
| 46 | - $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - // puis passer dans le pipeline |
|
| 50 | - $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $liste; |
|
| 38 | + static $liste = null; |
|
| 39 | + if (is_null($liste)) { |
|
| 40 | + $liste = []; |
|
| 41 | + // recuperer les tables_objets_sql declarees |
|
| 42 | + include_spip('base/objets'); |
|
| 43 | + $tables_objets = lister_tables_objets_sql(); |
|
| 44 | + foreach ($tables_objets as $t => $infos) { |
|
| 45 | + if ($infos['rechercher_champs']) { |
|
| 46 | + $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + // puis passer dans le pipeline |
|
| 50 | + $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $liste; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -58,176 +58,176 @@ discard block |
||
| 58 | 58 | // en ne regardant que le titre ou le nom |
| 59 | 59 | // https://code.spip.net/@liste_des_jointures |
| 60 | 60 | function liste_des_jointures() { |
| 61 | - static $liste = null; |
|
| 62 | - if (is_null($liste)) { |
|
| 63 | - $liste = []; |
|
| 64 | - // recuperer les tables_objets_sql declarees |
|
| 65 | - include_spip('base/objets'); |
|
| 66 | - $tables_objets = lister_tables_objets_sql(); |
|
| 67 | - foreach ($tables_objets as $t => $infos) { |
|
| 68 | - if ($infos['rechercher_jointures']) { |
|
| 69 | - $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - // puis passer dans le pipeline |
|
| 73 | - $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - return $liste; |
|
| 61 | + static $liste = null; |
|
| 62 | + if (is_null($liste)) { |
|
| 63 | + $liste = []; |
|
| 64 | + // recuperer les tables_objets_sql declarees |
|
| 65 | + include_spip('base/objets'); |
|
| 66 | + $tables_objets = lister_tables_objets_sql(); |
|
| 67 | + foreach ($tables_objets as $t => $infos) { |
|
| 68 | + if ($infos['rechercher_jointures']) { |
|
| 69 | + $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + // puis passer dans le pipeline |
|
| 73 | + $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + return $liste; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | function expression_recherche($recherche, $options) { |
| 80 | - // ne calculer qu'une seule fois l'expression par hit |
|
| 81 | - // (meme si utilisee dans plusieurs boucles) |
|
| 82 | - static $expression = []; |
|
| 83 | - $key = serialize([$recherche, $options['preg_flags']]); |
|
| 84 | - if (isset($expression[$key])) { |
|
| 85 | - return $expression[$key]; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 89 | - if ($u and strpos($options['preg_flags'], $u) === false) { |
|
| 90 | - $options['preg_flags'] .= $u; |
|
| 91 | - } |
|
| 92 | - include_spip('inc/charsets'); |
|
| 93 | - $recherche = trim($recherche); |
|
| 94 | - |
|
| 95 | - // retirer les + de +truc et les * de truc* |
|
| 96 | - $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 97 | - $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 98 | - |
|
| 99 | - $is_preg = false; |
|
| 100 | - if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 101 | - // c'est une preg |
|
| 102 | - $recherche_trans = translitteration($recherche); |
|
| 103 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 104 | - $is_preg = true; |
|
| 105 | - } else { |
|
| 106 | - // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 107 | - // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 108 | - // 'une', 'des' ...) |
|
| 109 | - |
|
| 110 | - // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 111 | - $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 112 | - |
|
| 113 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 114 | - // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 115 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 116 | - foreach ($matches as $match) { |
|
| 117 | - $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 118 | - $word = trim($word, '"'); |
|
| 119 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 124 | - $is_preg = true; |
|
| 125 | - |
|
| 126 | - $recherche_inter = '|'; |
|
| 127 | - $recherche_mots = explode(' ', $recherche_mod); |
|
| 128 | - $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 129 | - $petits_mots = true; |
|
| 130 | - foreach ($recherche_mots as $mot) { |
|
| 131 | - if (strlen($mot) >= $min_long) { |
|
| 132 | - // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 133 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 134 | - $petits_mots = false; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 138 | - |
|
| 139 | - // mais on cherche quand même l'expression complète, même si elle |
|
| 140 | - // comporte des mots de moins de quatre lettres |
|
| 141 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 142 | - if (!$recherche or $petits_mots) { |
|
| 143 | - $recherche = preg_quote($recherche_org); |
|
| 144 | - } |
|
| 145 | - $recherche_trans = translitteration($recherche); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 152 | - // ou si l'expression reguliere est invalide |
|
| 153 | - if ( |
|
| 154 | - !$is_preg |
|
| 155 | - or (@preg_match($preg, '') === false) |
|
| 156 | - ) { |
|
| 157 | - $methode = 'LIKE'; |
|
| 158 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 159 | - |
|
| 160 | - // echapper les % et _ |
|
| 161 | - $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 162 | - |
|
| 163 | - // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 164 | - $recherche = preg_quote($recherche, '/'); |
|
| 165 | - $recherche_trans = translitteration($recherche); |
|
| 166 | - $recherche_mod = $recherche_trans; |
|
| 167 | - |
|
| 168 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 169 | - // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 170 | - // corriger le like dans le $q |
|
| 171 | - if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 172 | - foreach ($matches as $match) { |
|
| 173 | - $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 174 | - $word = trim($word, '"'); |
|
| 175 | - $q = str_replace($match, $word, $q); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - // corriger la regexp |
|
| 179 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 180 | - foreach ($matches as $match) { |
|
| 181 | - $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 182 | - $word = trim($word, '"'); |
|
| 183 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - $q = sql_quote( |
|
| 187 | - '%' |
|
| 188 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 189 | - . '%' |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 193 | - } else { |
|
| 194 | - $methode = 'REGEXP'; |
|
| 195 | - $q = sql_quote(trim($recherche, '/')); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 199 | - // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 200 | - $q_t = $q; |
|
| 201 | - for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 202 | - $char = spip_substr($q, $i, 1); |
|
| 203 | - if ( |
|
| 204 | - !is_ascii($char) |
|
| 205 | - and $char_t = translitteration($char) |
|
| 206 | - and $char_t !== $char |
|
| 207 | - ) { |
|
| 208 | - // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 209 | - // mais c'est un pis aller cf #4354 |
|
| 210 | - $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $q = $q_t; |
|
| 215 | - |
|
| 216 | - // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 217 | - // les plus frequents qui peuvent etre accentues |
|
| 218 | - // (oui c'est tres dicustable...) |
|
| 219 | - if ( |
|
| 220 | - isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type']) |
|
| 221 | - and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0 |
|
| 222 | - ) { |
|
| 223 | - $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 224 | - // si il reste au moins un char significatif... |
|
| 225 | - if (preg_match(",[^'%_.],", $q_t)) { |
|
| 226 | - $q = $q_t; |
|
| 227 | - } |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $expression[$key] = [$methode, $q, $preg]; |
|
| 80 | + // ne calculer qu'une seule fois l'expression par hit |
|
| 81 | + // (meme si utilisee dans plusieurs boucles) |
|
| 82 | + static $expression = []; |
|
| 83 | + $key = serialize([$recherche, $options['preg_flags']]); |
|
| 84 | + if (isset($expression[$key])) { |
|
| 85 | + return $expression[$key]; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 89 | + if ($u and strpos($options['preg_flags'], $u) === false) { |
|
| 90 | + $options['preg_flags'] .= $u; |
|
| 91 | + } |
|
| 92 | + include_spip('inc/charsets'); |
|
| 93 | + $recherche = trim($recherche); |
|
| 94 | + |
|
| 95 | + // retirer les + de +truc et les * de truc* |
|
| 96 | + $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 97 | + $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 98 | + |
|
| 99 | + $is_preg = false; |
|
| 100 | + if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 101 | + // c'est une preg |
|
| 102 | + $recherche_trans = translitteration($recherche); |
|
| 103 | + $preg = $recherche_trans . $options['preg_flags']; |
|
| 104 | + $is_preg = true; |
|
| 105 | + } else { |
|
| 106 | + // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 107 | + // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 108 | + // 'une', 'des' ...) |
|
| 109 | + |
|
| 110 | + // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 111 | + $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 112 | + |
|
| 113 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 114 | + // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 115 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 116 | + foreach ($matches as $match) { |
|
| 117 | + $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 118 | + $word = trim($word, '"'); |
|
| 119 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 124 | + $is_preg = true; |
|
| 125 | + |
|
| 126 | + $recherche_inter = '|'; |
|
| 127 | + $recherche_mots = explode(' ', $recherche_mod); |
|
| 128 | + $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 129 | + $petits_mots = true; |
|
| 130 | + foreach ($recherche_mots as $mot) { |
|
| 131 | + if (strlen($mot) >= $min_long) { |
|
| 132 | + // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 133 | + $recherche_inter .= preg_quote($mot) . ' '; |
|
| 134 | + $petits_mots = false; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 138 | + |
|
| 139 | + // mais on cherche quand même l'expression complète, même si elle |
|
| 140 | + // comporte des mots de moins de quatre lettres |
|
| 141 | + $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 142 | + if (!$recherche or $petits_mots) { |
|
| 143 | + $recherche = preg_quote($recherche_org); |
|
| 144 | + } |
|
| 145 | + $recherche_trans = translitteration($recherche); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 152 | + // ou si l'expression reguliere est invalide |
|
| 153 | + if ( |
|
| 154 | + !$is_preg |
|
| 155 | + or (@preg_match($preg, '') === false) |
|
| 156 | + ) { |
|
| 157 | + $methode = 'LIKE'; |
|
| 158 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 159 | + |
|
| 160 | + // echapper les % et _ |
|
| 161 | + $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 162 | + |
|
| 163 | + // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 164 | + $recherche = preg_quote($recherche, '/'); |
|
| 165 | + $recherche_trans = translitteration($recherche); |
|
| 166 | + $recherche_mod = $recherche_trans; |
|
| 167 | + |
|
| 168 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 169 | + // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 170 | + // corriger le like dans le $q |
|
| 171 | + if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 172 | + foreach ($matches as $match) { |
|
| 173 | + $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 174 | + $word = trim($word, '"'); |
|
| 175 | + $q = str_replace($match, $word, $q); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + // corriger la regexp |
|
| 179 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 180 | + foreach ($matches as $match) { |
|
| 181 | + $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 182 | + $word = trim($word, '"'); |
|
| 183 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + $q = sql_quote( |
|
| 187 | + '%' |
|
| 188 | + . preg_replace(',\s+,' . $u, '%', $q) |
|
| 189 | + . '%' |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 193 | + } else { |
|
| 194 | + $methode = 'REGEXP'; |
|
| 195 | + $q = sql_quote(trim($recherche, '/')); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 199 | + // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 200 | + $q_t = $q; |
|
| 201 | + for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 202 | + $char = spip_substr($q, $i, 1); |
|
| 203 | + if ( |
|
| 204 | + !is_ascii($char) |
|
| 205 | + and $char_t = translitteration($char) |
|
| 206 | + and $char_t !== $char |
|
| 207 | + ) { |
|
| 208 | + // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 209 | + // mais c'est un pis aller cf #4354 |
|
| 210 | + $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $q = $q_t; |
|
| 215 | + |
|
| 216 | + // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 217 | + // les plus frequents qui peuvent etre accentues |
|
| 218 | + // (oui c'est tres dicustable...) |
|
| 219 | + if ( |
|
| 220 | + isset($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type']) |
|
| 221 | + and strncmp($GLOBALS['connexions'][$options['serveur'] ? $options['serveur'] : 0]['type'], 'sqlite', 6) == 0 |
|
| 222 | + ) { |
|
| 223 | + $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 224 | + // si il reste au moins un char significatif... |
|
| 225 | + if (preg_match(",[^'%_.],", $q_t)) { |
|
| 226 | + $q = $q_t; |
|
| 227 | + } |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $expression[$key] = [$methode, $q, $preg]; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | |
@@ -254,143 +254,143 @@ discard block |
||
| 254 | 254 | * @return array |
| 255 | 255 | */ |
| 256 | 256 | function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') { |
| 257 | - include_spip('base/abstract_sql'); |
|
| 258 | - |
|
| 259 | - if (!is_array($tables)) { |
|
| 260 | - $liste = liste_des_champs(); |
|
| 261 | - |
|
| 262 | - if ( |
|
| 263 | - is_string($tables) |
|
| 264 | - and $tables != '' |
|
| 265 | - ) { |
|
| 266 | - $toutes = []; |
|
| 267 | - foreach (explode(',', $tables) as $t) { |
|
| 268 | - $t = trim($t); |
|
| 269 | - if (isset($liste[$t])) { |
|
| 270 | - $toutes[$t] = $liste[$t]; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - $tables = $toutes; |
|
| 274 | - unset($toutes); |
|
| 275 | - } else { |
|
| 276 | - $tables = $liste; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - |
|
| 280 | - if (!strlen($recherche) or !count($tables)) { |
|
| 281 | - return []; |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - include_spip('inc/autoriser'); |
|
| 285 | - |
|
| 286 | - // options par defaut |
|
| 287 | - $options = array_merge( |
|
| 288 | - [ |
|
| 289 | - 'preg_flags' => 'UimsS', |
|
| 290 | - 'toutvoir' => false, |
|
| 291 | - 'champs' => false, |
|
| 292 | - 'score' => false, |
|
| 293 | - 'matches' => false, |
|
| 294 | - 'jointures' => false, |
|
| 295 | - 'serveur' => $serveur |
|
| 296 | - ], |
|
| 297 | - $options |
|
| 298 | - ); |
|
| 299 | - |
|
| 300 | - $results = []; |
|
| 301 | - |
|
| 302 | - // Utiliser l'iterateur (DATA:recherche) |
|
| 303 | - // pour recuperer les couples (id_objet, score) |
|
| 304 | - // Le resultat est au format { |
|
| 305 | - // id1 = { 'score' => x, attrs => { } }, |
|
| 306 | - // id2 = { 'score' => x, attrs => { } }, |
|
| 307 | - // } |
|
| 308 | - |
|
| 309 | - include_spip('inc/recherche_to_array'); |
|
| 310 | - |
|
| 311 | - foreach ($tables as $table => $champs) { |
|
| 312 | - # lock via memoization, si dispo |
|
| 313 | - if (function_exists('cache_lock')) { |
|
| 314 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - spip_timer('rech'); |
|
| 318 | - |
|
| 319 | - # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 320 | - $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 321 | - $results[$table] = $to_array( |
|
| 322 | - $recherche, |
|
| 323 | - array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 324 | - ); |
|
| 325 | - ##var_dump($results[$table]); |
|
| 326 | - |
|
| 327 | - |
|
| 328 | - spip_log( |
|
| 329 | - "recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'), |
|
| 330 | - 'recherche' |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - if (isset($lock)) { |
|
| 334 | - cache_unlock($lock); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - return $results; |
|
| 257 | + include_spip('base/abstract_sql'); |
|
| 258 | + |
|
| 259 | + if (!is_array($tables)) { |
|
| 260 | + $liste = liste_des_champs(); |
|
| 261 | + |
|
| 262 | + if ( |
|
| 263 | + is_string($tables) |
|
| 264 | + and $tables != '' |
|
| 265 | + ) { |
|
| 266 | + $toutes = []; |
|
| 267 | + foreach (explode(',', $tables) as $t) { |
|
| 268 | + $t = trim($t); |
|
| 269 | + if (isset($liste[$t])) { |
|
| 270 | + $toutes[$t] = $liste[$t]; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + $tables = $toutes; |
|
| 274 | + unset($toutes); |
|
| 275 | + } else { |
|
| 276 | + $tables = $liste; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + |
|
| 280 | + if (!strlen($recherche) or !count($tables)) { |
|
| 281 | + return []; |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + include_spip('inc/autoriser'); |
|
| 285 | + |
|
| 286 | + // options par defaut |
|
| 287 | + $options = array_merge( |
|
| 288 | + [ |
|
| 289 | + 'preg_flags' => 'UimsS', |
|
| 290 | + 'toutvoir' => false, |
|
| 291 | + 'champs' => false, |
|
| 292 | + 'score' => false, |
|
| 293 | + 'matches' => false, |
|
| 294 | + 'jointures' => false, |
|
| 295 | + 'serveur' => $serveur |
|
| 296 | + ], |
|
| 297 | + $options |
|
| 298 | + ); |
|
| 299 | + |
|
| 300 | + $results = []; |
|
| 301 | + |
|
| 302 | + // Utiliser l'iterateur (DATA:recherche) |
|
| 303 | + // pour recuperer les couples (id_objet, score) |
|
| 304 | + // Le resultat est au format { |
|
| 305 | + // id1 = { 'score' => x, attrs => { } }, |
|
| 306 | + // id2 = { 'score' => x, attrs => { } }, |
|
| 307 | + // } |
|
| 308 | + |
|
| 309 | + include_spip('inc/recherche_to_array'); |
|
| 310 | + |
|
| 311 | + foreach ($tables as $table => $champs) { |
|
| 312 | + # lock via memoization, si dispo |
|
| 313 | + if (function_exists('cache_lock')) { |
|
| 314 | + cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + spip_timer('rech'); |
|
| 318 | + |
|
| 319 | + # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 320 | + $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 321 | + $results[$table] = $to_array( |
|
| 322 | + $recherche, |
|
| 323 | + array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 324 | + ); |
|
| 325 | + ##var_dump($results[$table]); |
|
| 326 | + |
|
| 327 | + |
|
| 328 | + spip_log( |
|
| 329 | + "recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'), |
|
| 330 | + 'recherche' |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + if (isset($lock)) { |
|
| 334 | + cache_unlock($lock); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + return $results; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
| 342 | 342 | // Effectue une recherche sur toutes les tables de la base de donnees |
| 343 | 343 | // https://code.spip.net/@remplace_en_base |
| 344 | 344 | function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) { |
| 345 | - include_spip('inc/modifier'); |
|
| 346 | - |
|
| 347 | - // options par defaut |
|
| 348 | - $options = array_merge( |
|
| 349 | - [ |
|
| 350 | - 'preg_flags' => 'UimsS', |
|
| 351 | - 'toutmodifier' => false |
|
| 352 | - ], |
|
| 353 | - $options |
|
| 354 | - ); |
|
| 355 | - $options['champs'] = true; |
|
| 356 | - |
|
| 357 | - |
|
| 358 | - if (!is_array($tables)) { |
|
| 359 | - $tables = liste_des_champs(); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - $results = recherche_en_base($recherche, $tables, $options); |
|
| 363 | - |
|
| 364 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 365 | - |
|
| 366 | - foreach ($results as $table => $r) { |
|
| 367 | - $_id_table = id_table_objet($table); |
|
| 368 | - foreach ($r as $id => $x) { |
|
| 369 | - if ( |
|
| 370 | - $options['toutmodifier'] |
|
| 371 | - or autoriser('modifier', $table, $id) |
|
| 372 | - ) { |
|
| 373 | - $modifs = []; |
|
| 374 | - foreach ($x['champs'] as $key => $val) { |
|
| 375 | - if ($key == $_id_table) { |
|
| 376 | - continue; |
|
| 377 | - } |
|
| 378 | - $repl = preg_replace($preg, $remplace, $val); |
|
| 379 | - if ($repl <> $val) { |
|
| 380 | - $modifs[$key] = $repl; |
|
| 381 | - } |
|
| 382 | - } |
|
| 383 | - if ($modifs) { |
|
| 384 | - objet_modifier_champs( |
|
| 385 | - $table, |
|
| 386 | - $id, |
|
| 387 | - [ |
|
| 388 | - 'champs' => array_keys($modifs), |
|
| 389 | - ], |
|
| 390 | - $modifs |
|
| 391 | - ); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - } |
|
| 345 | + include_spip('inc/modifier'); |
|
| 346 | + |
|
| 347 | + // options par defaut |
|
| 348 | + $options = array_merge( |
|
| 349 | + [ |
|
| 350 | + 'preg_flags' => 'UimsS', |
|
| 351 | + 'toutmodifier' => false |
|
| 352 | + ], |
|
| 353 | + $options |
|
| 354 | + ); |
|
| 355 | + $options['champs'] = true; |
|
| 356 | + |
|
| 357 | + |
|
| 358 | + if (!is_array($tables)) { |
|
| 359 | + $tables = liste_des_champs(); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + $results = recherche_en_base($recherche, $tables, $options); |
|
| 363 | + |
|
| 364 | + $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 365 | + |
|
| 366 | + foreach ($results as $table => $r) { |
|
| 367 | + $_id_table = id_table_objet($table); |
|
| 368 | + foreach ($r as $id => $x) { |
|
| 369 | + if ( |
|
| 370 | + $options['toutmodifier'] |
|
| 371 | + or autoriser('modifier', $table, $id) |
|
| 372 | + ) { |
|
| 373 | + $modifs = []; |
|
| 374 | + foreach ($x['champs'] as $key => $val) { |
|
| 375 | + if ($key == $_id_table) { |
|
| 376 | + continue; |
|
| 377 | + } |
|
| 378 | + $repl = preg_replace($preg, $remplace, $val); |
|
| 379 | + if ($repl <> $val) { |
|
| 380 | + $modifs[$key] = $repl; |
|
| 381 | + } |
|
| 382 | + } |
|
| 383 | + if ($modifs) { |
|
| 384 | + objet_modifier_champs( |
|
| 385 | + $table, |
|
| 386 | + $id, |
|
| 387 | + [ |
|
| 388 | + 'champs' => array_keys($modifs), |
|
| 389 | + ], |
|
| 390 | + $modifs |
|
| 391 | + ); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | 396 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
| 101 | 101 | // c'est une preg |
| 102 | 102 | $recherche_trans = translitteration($recherche); |
| 103 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | + $preg = $recherche_trans.$options['preg_flags']; |
|
| 104 | 104 | $is_preg = true; |
| 105 | 105 | } else { |
| 106 | 106 | // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | } |
| 121 | 121 | } |
| 122 | 122 | |
| 123 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | + if (preg_match(',\s+,'.$u, $recherche_mod)) { |
|
| 124 | 124 | $is_preg = true; |
| 125 | 125 | |
| 126 | 126 | $recherche_inter = '|'; |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | foreach ($recherche_mots as $mot) { |
| 131 | 131 | if (strlen($mot) >= $min_long) { |
| 132 | 132 | // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
| 133 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | + $recherche_inter .= preg_quote($mot).' '; |
|
| 134 | 134 | $petits_mots = false; |
| 135 | 135 | } |
| 136 | 136 | } |
@@ -138,14 +138,14 @@ discard block |
||
| 138 | 138 | |
| 139 | 139 | // mais on cherche quand même l'expression complète, même si elle |
| 140 | 140 | // comporte des mots de moins de quatre lettres |
| 141 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | + $recherche = trim(preg_replace(',\s+,'.$u, '|', $recherche_inter), '|'); |
|
| 142 | 142 | if (!$recherche or $petits_mots) { |
| 143 | 143 | $recherche = preg_quote($recherche_org); |
| 144 | 144 | } |
| 145 | 145 | $recherche_trans = translitteration($recherche); |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | + $preg = '/'.str_replace('/', '\\/', $recherche_trans).'/'.$options['preg_flags']; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | } |
| 186 | 186 | $q = sql_quote( |
| 187 | 187 | '%' |
| 188 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | + . preg_replace(',\s+,'.$u, '%', $q) |
|
| 189 | 189 | . '%' |
| 190 | 190 | ); |
| 191 | 191 | |
| 192 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | + $preg = '/'.preg_replace(',\s+,'.$u, '.+', trim($recherche_mod)).'/'.$options['preg_flags']; |
|
| 193 | 193 | } else { |
| 194 | 194 | $methode = 'REGEXP'; |
| 195 | 195 | $q = sql_quote(trim($recherche, '/')); |
@@ -311,7 +311,7 @@ discard block |
||
| 311 | 311 | foreach ($tables as $table => $champs) { |
| 312 | 312 | # lock via memoization, si dispo |
| 313 | 313 | if (function_exists('cache_lock')) { |
| 314 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | + cache_lock($lock = _RECHERCHE_LOCK_KEY.' '.$table.' '.$recherche); |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | spip_timer('rech'); |
@@ -326,7 +326,7 @@ discard block |
||
| 326 | 326 | |
| 327 | 327 | |
| 328 | 328 | spip_log( |
| 329 | - "recherche $table ($recherche) : " . count($results[$table]) . ' resultats ' . spip_timer('rech'), |
|
| 329 | + "recherche $table ($recherche) : ".count($results[$table]).' resultats '.spip_timer('rech'), |
|
| 330 | 330 | 'recherche' |
| 331 | 331 | ); |
| 332 | 332 | |
@@ -361,7 +361,7 @@ discard block |
||
| 361 | 361 | |
| 362 | 362 | $results = recherche_en_base($recherche, $tables, $options); |
| 363 | 363 | |
| 364 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 364 | + $preg = '/'.str_replace('/', '\\/', $recherche).'/'.$options['preg_flags']; |
|
| 365 | 365 | |
| 366 | 366 | foreach ($results as $table => $r) { |
| 367 | 367 | $_id_table = id_table_objet($table); |