@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Inscription |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,70 +39,70 @@ discard block |
||
| 39 | 39 | * @return array|string |
| 40 | 40 | */ |
| 41 | 41 | function action_inscrire_auteur_dist($statut, $mail_complet, $nom, $options = []) { |
| 42 | - if (!is_array($options)) { |
|
| 43 | - $options = ['id' => $options]; |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - if (function_exists('test_inscription')) { |
|
| 47 | - $f = 'test_inscription'; |
|
| 48 | - } else { |
|
| 49 | - $f = 'test_inscription_dist'; |
|
| 50 | - } |
|
| 51 | - $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 52 | - |
|
| 53 | - // erreur ? |
|
| 54 | - if (!is_array($desc)) { |
|
| 55 | - return _T($desc); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - include_spip('base/abstract_sql'); |
|
| 59 | - $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 60 | - // erreur ? |
|
| 61 | - if (!$res) { |
|
| 62 | - return _T('titre_probleme_technique'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - $row = sql_fetch($res); |
|
| 66 | - sql_free($res); |
|
| 67 | - if ($row) { |
|
| 68 | - if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 69 | - $desc['id_auteur'] = $row['id_auteur']; |
|
| 70 | - $desc = inscription_nouveau($desc); |
|
| 71 | - } else { |
|
| 72 | - $desc = $row; |
|
| 73 | - } |
|
| 74 | - } else // s'il n'existe pas deja, creer les identifiants |
|
| 75 | - { |
|
| 76 | - $desc = inscription_nouveau($desc); |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // erreur ? |
|
| 80 | - if (!is_array($desc)) { |
|
| 81 | - return $desc; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 86 | - $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 87 | - |
|
| 88 | - // attribuer un jeton pour confirmation par clic sur un lien |
|
| 89 | - $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 90 | - |
|
| 91 | - // charger de suite cette fonction, pour ses utilitaires |
|
| 92 | - $envoyer_inscription = charger_fonction('envoyer_inscription', ''); |
|
| 93 | - [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 94 | - |
|
| 95 | - $notifications = charger_fonction('notifications', 'inc'); |
|
| 96 | - notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 97 | - |
|
| 98 | - // Notifications |
|
| 99 | - $notifications( |
|
| 100 | - 'inscription', |
|
| 101 | - $desc['id_auteur'], |
|
| 102 | - ['nom' => $desc['nom'], 'email' => $desc['email']] |
|
| 103 | - ); |
|
| 104 | - |
|
| 105 | - return $desc; |
|
| 42 | + if (!is_array($options)) { |
|
| 43 | + $options = ['id' => $options]; |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + if (function_exists('test_inscription')) { |
|
| 47 | + $f = 'test_inscription'; |
|
| 48 | + } else { |
|
| 49 | + $f = 'test_inscription_dist'; |
|
| 50 | + } |
|
| 51 | + $desc = $f($statut, $mail_complet, $nom, $options); |
|
| 52 | + |
|
| 53 | + // erreur ? |
|
| 54 | + if (!is_array($desc)) { |
|
| 55 | + return _T($desc); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + include_spip('base/abstract_sql'); |
|
| 59 | + $res = sql_select('statut, id_auteur, login, email, nom', 'spip_auteurs', 'email=' . sql_quote($desc['email'])); |
|
| 60 | + // erreur ? |
|
| 61 | + if (!$res) { |
|
| 62 | + return _T('titre_probleme_technique'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + $row = sql_fetch($res); |
|
| 66 | + sql_free($res); |
|
| 67 | + if ($row) { |
|
| 68 | + if (isset($options['force_nouveau']) and $options['force_nouveau'] == true) { |
|
| 69 | + $desc['id_auteur'] = $row['id_auteur']; |
|
| 70 | + $desc = inscription_nouveau($desc); |
|
| 71 | + } else { |
|
| 72 | + $desc = $row; |
|
| 73 | + } |
|
| 74 | + } else // s'il n'existe pas deja, creer les identifiants |
|
| 75 | + { |
|
| 76 | + $desc = inscription_nouveau($desc); |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // erreur ? |
|
| 80 | + if (!is_array($desc)) { |
|
| 81 | + return $desc; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + // generer le mot de passe (ou le refaire si compte inutilise) |
|
| 86 | + $desc['pass'] = creer_pass_pour_auteur($desc['id_auteur']); |
|
| 87 | + |
|
| 88 | + // attribuer un jeton pour confirmation par clic sur un lien |
|
| 89 | + $desc['jeton'] = auteur_attribuer_jeton($desc['id_auteur']); |
|
| 90 | + |
|
| 91 | + // charger de suite cette fonction, pour ses utilitaires |
|
| 92 | + $envoyer_inscription = charger_fonction('envoyer_inscription', ''); |
|
| 93 | + [$sujet, $msg, $from, $head] = $envoyer_inscription($desc, $nom, $statut, $options); |
|
| 94 | + |
|
| 95 | + $notifications = charger_fonction('notifications', 'inc'); |
|
| 96 | + notifications_envoyer_mails($mail_complet, $msg, $sujet, $from, $head); |
|
| 97 | + |
|
| 98 | + // Notifications |
|
| 99 | + $notifications( |
|
| 100 | + 'inscription', |
|
| 101 | + $desc['id_auteur'], |
|
| 102 | + ['nom' => $desc['nom'], 'email' => $desc['email']] |
|
| 103 | + ); |
|
| 104 | + |
|
| 105 | + return $desc; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | |
@@ -125,23 +125,23 @@ discard block |
||
| 125 | 125 | * |
| 126 | 126 | */ |
| 127 | 127 | function test_inscription_dist($statut, $mail, $nom, $options) { |
| 128 | - include_spip('inc/filtres'); |
|
| 129 | - if (!$r = email_valide($mail)) { |
|
| 130 | - return 'info_email_invalide'; |
|
| 131 | - } |
|
| 132 | - $nom = trim(corriger_caracteres($nom)); |
|
| 133 | - $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut]; |
|
| 134 | - if (isset($options['login'])) { |
|
| 135 | - $login = trim(corriger_caracteres($options['login'])); |
|
| 136 | - if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 137 | - $res['login'] = $login; |
|
| 138 | - } |
|
| 139 | - } |
|
| 140 | - if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 141 | - return 'ecrire:info_login_trop_court'; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $res; |
|
| 128 | + include_spip('inc/filtres'); |
|
| 129 | + if (!$r = email_valide($mail)) { |
|
| 130 | + return 'info_email_invalide'; |
|
| 131 | + } |
|
| 132 | + $nom = trim(corriger_caracteres($nom)); |
|
| 133 | + $res = ['email' => $r, 'nom' => $nom, 'prefs' => $statut]; |
|
| 134 | + if (isset($options['login'])) { |
|
| 135 | + $login = trim(corriger_caracteres($options['login'])); |
|
| 136 | + if ((strlen($login) >= _LOGIN_TROP_COURT) and (strlen($nom) <= 64)) { |
|
| 137 | + $res['login'] = $login; |
|
| 138 | + } |
|
| 139 | + } |
|
| 140 | + if (!isset($res['login']) and ((strlen($nom) < _LOGIN_TROP_COURT) or (strlen($nom) > 64))) { |
|
| 141 | + return 'ecrire:info_login_trop_court'; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $res; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -154,33 +154,33 @@ discard block |
||
| 154 | 154 | * @return mixed|string |
| 155 | 155 | */ |
| 156 | 156 | function inscription_nouveau($desc) { |
| 157 | - if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 158 | - $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 159 | - } |
|
| 157 | + if (!isset($desc['login']) or !strlen($desc['login'])) { |
|
| 158 | + $desc['login'] = test_login($desc['nom'], $desc['email']); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - $desc['statut'] = 'nouveau'; |
|
| 162 | - include_spip('action/editer_auteur'); |
|
| 163 | - if (isset($desc['id_auteur'])) { |
|
| 164 | - $id_auteur = $desc['id_auteur']; |
|
| 165 | - } else { |
|
| 166 | - $id_auteur = auteur_inserer(); |
|
| 167 | - } |
|
| 161 | + $desc['statut'] = 'nouveau'; |
|
| 162 | + include_spip('action/editer_auteur'); |
|
| 163 | + if (isset($desc['id_auteur'])) { |
|
| 164 | + $id_auteur = $desc['id_auteur']; |
|
| 165 | + } else { |
|
| 166 | + $id_auteur = auteur_inserer(); |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - if (!$id_auteur) { |
|
| 170 | - return _T('titre_probleme_technique'); |
|
| 171 | - } |
|
| 169 | + if (!$id_auteur) { |
|
| 170 | + return _T('titre_probleme_technique'); |
|
| 171 | + } |
|
| 172 | 172 | |
| 173 | - $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 173 | + $desc['lang'] = $GLOBALS['spip_lang']; |
|
| 174 | 174 | |
| 175 | - include_spip('inc/autoriser'); |
|
| 176 | - // lever l'autorisation pour pouvoir modifier le statut |
|
| 177 | - autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 178 | - auteur_modifier($id_auteur, $desc); |
|
| 179 | - autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 175 | + include_spip('inc/autoriser'); |
|
| 176 | + // lever l'autorisation pour pouvoir modifier le statut |
|
| 177 | + autoriser_exception('modifier', 'auteur', $id_auteur); |
|
| 178 | + auteur_modifier($id_auteur, $desc); |
|
| 179 | + autoriser_exception('modifier', 'auteur', $id_auteur, false); |
|
| 180 | 180 | |
| 181 | - $desc['id_auteur'] = $id_auteur; |
|
| 181 | + $desc['id_auteur'] = $id_auteur; |
|
| 182 | 182 | |
| 183 | - return $desc; |
|
| 183 | + return $desc; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -197,27 +197,27 @@ discard block |
||
| 197 | 197 | * @return string |
| 198 | 198 | */ |
| 199 | 199 | function test_login($nom, $mail) { |
| 200 | - include_spip('inc/charsets'); |
|
| 201 | - $nom = strtolower(translitteration($nom)); |
|
| 202 | - $login_base = preg_replace('/[^\w\d_]/', '_', $nom); |
|
| 203 | - |
|
| 204 | - // il faut eviter que le login soit vraiment trop court |
|
| 205 | - if (strlen($login_base) < 3) { |
|
| 206 | - $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 207 | - $login_base = preg_replace('/[^\w\d]/', '_', $mail); |
|
| 208 | - } |
|
| 209 | - if (strlen($login_base) < 3) { |
|
| 210 | - $login_base = 'user'; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $login = $login_base; |
|
| 214 | - |
|
| 215 | - for ($i = 1;; $i++) { |
|
| 216 | - if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 217 | - return $login; |
|
| 218 | - } |
|
| 219 | - $login = $login_base . $i; |
|
| 220 | - } |
|
| 200 | + include_spip('inc/charsets'); |
|
| 201 | + $nom = strtolower(translitteration($nom)); |
|
| 202 | + $login_base = preg_replace('/[^\w\d_]/', '_', $nom); |
|
| 203 | + |
|
| 204 | + // il faut eviter que le login soit vraiment trop court |
|
| 205 | + if (strlen($login_base) < 3) { |
|
| 206 | + $mail = strtolower(translitteration(preg_replace('/@.*/', '', $mail))); |
|
| 207 | + $login_base = preg_replace('/[^\w\d]/', '_', $mail); |
|
| 208 | + } |
|
| 209 | + if (strlen($login_base) < 3) { |
|
| 210 | + $login_base = 'user'; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $login = $login_base; |
|
| 214 | + |
|
| 215 | + for ($i = 1;; $i++) { |
|
| 216 | + if (!sql_countsel('spip_auteurs', "login='$login'")) { |
|
| 217 | + return $login; |
|
| 218 | + } |
|
| 219 | + $login = $login_base . $i; |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -235,26 +235,26 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | function envoyer_inscription_dist($desc, $nom, $mode, $options = []) { |
| 237 | 237 | |
| 238 | - $contexte = array_merge($desc, $options); |
|
| 239 | - $contexte['nom'] = $nom; |
|
| 240 | - $contexte['mode'] = $mode; |
|
| 241 | - $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 242 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 243 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 244 | - // S'il y a l'option redirect, on l'ajoute directement ici |
|
| 245 | - if (isset($options['redirect'])) { |
|
| 246 | - $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - $modele_mail = 'modeles/mail_inscription'; |
|
| 250 | - if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 251 | - $modele_mail = $options['modele_mail']; |
|
| 252 | - } |
|
| 253 | - $message = recuperer_fond($modele_mail, $contexte); |
|
| 254 | - $from = ($options['from'] ?? null); |
|
| 255 | - $head = null; |
|
| 256 | - |
|
| 257 | - return ['', $message, $from, $head]; |
|
| 238 | + $contexte = array_merge($desc, $options); |
|
| 239 | + $contexte['nom'] = $nom; |
|
| 240 | + $contexte['mode'] = $mode; |
|
| 241 | + $contexte['url_confirm'] = generer_url_action('confirmer_inscription', '', true, true); |
|
| 242 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'email', $desc['email']); |
|
| 243 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'jeton', $desc['jeton']); |
|
| 244 | + // S'il y a l'option redirect, on l'ajoute directement ici |
|
| 245 | + if (isset($options['redirect'])) { |
|
| 246 | + $contexte['url_confirm'] = parametre_url($contexte['url_confirm'], 'redirect', $options['redirect']); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + $modele_mail = 'modeles/mail_inscription'; |
|
| 250 | + if (isset($options['modele_mail']) and $options['modele_mail']) { |
|
| 251 | + $modele_mail = $options['modele_mail']; |
|
| 252 | + } |
|
| 253 | + $message = recuperer_fond($modele_mail, $contexte); |
|
| 254 | + $from = ($options['from'] ?? null); |
|
| 255 | + $head = null; |
|
| 256 | + |
|
| 257 | + return ['', $message, $from, $head]; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -265,12 +265,12 @@ discard block |
||
| 265 | 265 | * @return string |
| 266 | 266 | */ |
| 267 | 267 | function creer_pass_pour_auteur($id_auteur) { |
| 268 | - include_spip('inc/acces'); |
|
| 269 | - $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur); |
|
| 270 | - include_spip('action/editer_auteur'); |
|
| 271 | - auteur_instituer($id_auteur, ['pass' => $pass]); |
|
| 268 | + include_spip('inc/acces'); |
|
| 269 | + $pass = creer_pass_aleatoire(max(_PASS_LONGUEUR_MINI, 16), $id_auteur); |
|
| 270 | + include_spip('action/editer_auteur'); |
|
| 271 | + auteur_instituer($id_auteur, ['pass' => $pass]); |
|
| 272 | 272 | |
| 273 | - return $pass; |
|
| 273 | + return $pass; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -283,17 +283,17 @@ discard block |
||
| 283 | 283 | * @return string |
| 284 | 284 | */ |
| 285 | 285 | function tester_statut_inscription($statut_tmp, $id) { |
| 286 | - include_spip('inc/autoriser'); |
|
| 287 | - if ($statut_tmp) { |
|
| 288 | - return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 289 | - } elseif ( |
|
| 290 | - autoriser('inscrireauteur', $statut_tmp = '1comite', $id) |
|
| 291 | - or autoriser('inscrireauteur', $statut_tmp = '6forum', $id) |
|
| 292 | - ) { |
|
| 293 | - return $statut_tmp; |
|
| 294 | - } |
|
| 295 | - |
|
| 296 | - return ''; |
|
| 286 | + include_spip('inc/autoriser'); |
|
| 287 | + if ($statut_tmp) { |
|
| 288 | + return autoriser('inscrireauteur', $statut_tmp, $id) ? $statut_tmp : ''; |
|
| 289 | + } elseif ( |
|
| 290 | + autoriser('inscrireauteur', $statut_tmp = '1comite', $id) |
|
| 291 | + or autoriser('inscrireauteur', $statut_tmp = '6forum', $id) |
|
| 292 | + ) { |
|
| 293 | + return $statut_tmp; |
|
| 294 | + } |
|
| 295 | + |
|
| 296 | + return ''; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
@@ -307,35 +307,35 @@ discard block |
||
| 307 | 307 | * @return array |
| 308 | 308 | */ |
| 309 | 309 | function confirmer_statut_inscription($auteur) { |
| 310 | - // securite |
|
| 311 | - if ($auteur['statut'] != 'nouveau') { |
|
| 312 | - return $auteur; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $s = $auteur['prefs']; |
|
| 316 | - // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 317 | - if (!preg_match(',^\w+$,', $s)) { |
|
| 318 | - $s = '6forum'; |
|
| 319 | - } |
|
| 320 | - include_spip('inc/autoriser'); |
|
| 321 | - if (!autoriser('inscrireauteur', $s)) { |
|
| 322 | - return $auteur; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - include_spip('inc/autoriser'); |
|
| 326 | - // accorder l'autorisation de modif du statut auteur |
|
| 327 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 328 | - include_spip('action/editer_auteur'); |
|
| 329 | - // changer le statut |
|
| 330 | - auteur_modifier($auteur['id_auteur'], ['statut' => $s]); |
|
| 331 | - unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 332 | - // lever l'autorisation de modif du statut auteur |
|
| 333 | - autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 334 | - |
|
| 335 | - // mettre a jour le statut |
|
| 336 | - $auteur['statut'] = $s; |
|
| 337 | - |
|
| 338 | - return $auteur; |
|
| 310 | + // securite |
|
| 311 | + if ($auteur['statut'] != 'nouveau') { |
|
| 312 | + return $auteur; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $s = $auteur['prefs']; |
|
| 316 | + // securite, au cas ou prefs aurait ete corrompu (ou deja ecrase par un tableau serialize) |
|
| 317 | + if (!preg_match(',^\w+$,', $s)) { |
|
| 318 | + $s = '6forum'; |
|
| 319 | + } |
|
| 320 | + include_spip('inc/autoriser'); |
|
| 321 | + if (!autoriser('inscrireauteur', $s)) { |
|
| 322 | + return $auteur; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + include_spip('inc/autoriser'); |
|
| 326 | + // accorder l'autorisation de modif du statut auteur |
|
| 327 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur']); |
|
| 328 | + include_spip('action/editer_auteur'); |
|
| 329 | + // changer le statut |
|
| 330 | + auteur_modifier($auteur['id_auteur'], ['statut' => $s]); |
|
| 331 | + unset($_COOKIE['spip_session']); // forcer la maj de la session |
|
| 332 | + // lever l'autorisation de modif du statut auteur |
|
| 333 | + autoriser_exception('modifier', 'auteur', $auteur['id_auteur'], false); |
|
| 334 | + |
|
| 335 | + // mettre a jour le statut |
|
| 336 | + $auteur['statut'] = $s; |
|
| 337 | + |
|
| 338 | + return $auteur; |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -347,14 +347,14 @@ discard block |
||
| 347 | 347 | * @return string |
| 348 | 348 | */ |
| 349 | 349 | function auteur_attribuer_jeton($id_auteur) { |
| 350 | - include_spip('inc/acces'); |
|
| 351 | - // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 352 | - do { |
|
| 353 | - $jeton = creer_uniqid(); |
|
| 354 | - sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton], 'id_auteur=' . intval($id_auteur)); |
|
| 355 | - } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton)) > 1); |
|
| 356 | - |
|
| 357 | - return $jeton; |
|
| 350 | + include_spip('inc/acces'); |
|
| 351 | + // s'assurer de l'unicite du jeton pour le couple (email,cookie) |
|
| 352 | + do { |
|
| 353 | + $jeton = creer_uniqid(); |
|
| 354 | + sql_updateq('spip_auteurs', ['cookie_oubli' => $jeton], 'id_auteur=' . intval($id_auteur)); |
|
| 355 | + } while (sql_countsel('spip_auteurs', 'cookie_oubli=' . sql_quote($jeton)) > 1); |
|
| 356 | + |
|
| 357 | + return $jeton; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -364,15 +364,15 @@ discard block |
||
| 364 | 364 | * @return array|bool |
| 365 | 365 | */ |
| 366 | 366 | function auteur_verifier_jeton($jeton) { |
| 367 | - // refuser un jeton corrompu |
|
| 368 | - if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 369 | - return false; |
|
| 370 | - } |
|
| 367 | + // refuser un jeton corrompu |
|
| 368 | + if (preg_match(',[^0-9a-f.],i', $jeton)) { |
|
| 369 | + return false; |
|
| 370 | + } |
|
| 371 | 371 | |
| 372 | - // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
|
| 373 | - $desc = sql_fetsel('*', 'spip_auteurs', 'cookie_oubli=' . sql_quote($jeton, '', 'string')); |
|
| 372 | + // on peut tomber sur un jeton compose uniquement de chiffres, il faut forcer le $type pour sql_quote pour eviter de planter |
|
| 373 | + $desc = sql_fetsel('*', 'spip_auteurs', 'cookie_oubli=' . sql_quote($jeton, '', 'string')); |
|
| 374 | 374 | |
| 375 | - return $desc; |
|
| 375 | + return $desc; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -382,5 +382,5 @@ discard block |
||
| 382 | 382 | * @return bool |
| 383 | 383 | */ |
| 384 | 384 | function auteur_effacer_jeton($id_auteur) { |
| 385 | - return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 385 | + return sql_updateq('spip_auteurs', ['cookie_oubli' => ''], 'id_auteur=' . intval($id_auteur)); |
|
| 386 | 386 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 50 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @return void|array |
| 66 | 66 | **/ |
| 67 | 67 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 68 | - $not = $crit->not; |
|
| 69 | - $boucle = &$boucles[$idb]; |
|
| 70 | - $id = $boucle->primary; |
|
| 71 | - |
|
| 72 | - if ($not or !$id) { |
|
| 73 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | - } |
|
| 75 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 68 | + $not = $crit->not; |
|
| 69 | + $boucle = &$boucles[$idb]; |
|
| 70 | + $id = $boucle->primary; |
|
| 71 | + |
|
| 72 | + if ($not or !$id) { |
|
| 73 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | + } |
|
| 75 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -93,73 +93,73 @@ discard block |
||
| 93 | 93 | * @return void|array |
| 94 | 94 | **/ |
| 95 | 95 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 96 | - $boucle = &$boucles[$idb]; |
|
| 97 | - $primary = $boucle->primary; |
|
| 98 | - |
|
| 99 | - // la table nécessite une clé primaire, non composée |
|
| 100 | - if (!$primary or strpos($primary, ',')) { |
|
| 101 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | - |
|
| 106 | - // le doublon s'applique sur un type de boucle (article) |
|
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | - |
|
| 109 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | - // on obtient $nom = "'article' . 'nom'" |
|
| 111 | - if (isset($crit->param[0])) { |
|
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | - |
|
| 119 | - // on crée un sql_in avec la clé primaire de la table |
|
| 120 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | - // $doublons et son index, ici $nom |
|
| 122 | - |
|
| 123 | - // debut du code "sql_in('articles.id_article', " |
|
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | - |
|
| 129 | - // le debut complet du code des doublons |
|
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | - |
|
| 132 | - // nom du doublon "('article' . 'nom')]" |
|
| 133 | - $fin_doub = "($nom)]"; |
|
| 134 | - |
|
| 135 | - // si on trouve un autre critère doublon, |
|
| 136 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | - foreach ($boucle->where as $k => $w) { |
|
| 138 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | - // fusionner le sql_in (du where) |
|
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | - $x = strpos($boucle->hash, $init_comment); |
|
| 143 | - $len = strlen($init_comment); |
|
| 144 | - $boucle->hash = |
|
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | - |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | - |
|
| 154 | - // déclarer le doublon s'il n'existe pas encore |
|
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | - # {!doublons A}{doublons B} |
|
| 161 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 96 | + $boucle = &$boucles[$idb]; |
|
| 97 | + $primary = $boucle->primary; |
|
| 98 | + |
|
| 99 | + // la table nécessite une clé primaire, non composée |
|
| 100 | + if (!$primary or strpos($primary, ',')) { |
|
| 101 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | + |
|
| 106 | + // le doublon s'applique sur un type de boucle (article) |
|
| 107 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + |
|
| 109 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | + // on obtient $nom = "'article' . 'nom'" |
|
| 111 | + if (isset($crit->param[0])) { |
|
| 112 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | + |
|
| 119 | + // on crée un sql_in avec la clé primaire de la table |
|
| 120 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | + // $doublons et son index, ici $nom |
|
| 122 | + |
|
| 123 | + // debut du code "sql_in('articles.id_article', " |
|
| 124 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + |
|
| 129 | + // le debut complet du code des doublons |
|
| 130 | + $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + |
|
| 132 | + // nom du doublon "('article' . 'nom')]" |
|
| 133 | + $fin_doub = "($nom)]"; |
|
| 134 | + |
|
| 135 | + // si on trouve un autre critère doublon, |
|
| 136 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | + foreach ($boucle->where as $k => $w) { |
|
| 138 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | + // fusionner le sql_in (du where) |
|
| 140 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | + $x = strpos($boucle->hash, $init_comment); |
|
| 143 | + $len = strlen($init_comment); |
|
| 144 | + $boucle->hash = |
|
| 145 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + |
|
| 154 | + // déclarer le doublon s'il n'existe pas encore |
|
| 155 | + $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | + # {!doublons A}{doublons B} |
|
| 161 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | **/ |
| 182 | 182 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 183 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | - $param = 'oui'; |
|
| 185 | - } |
|
| 186 | - if ($crit->not) { |
|
| 187 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | - } |
|
| 189 | - $boucle = &$boucles[$idb]; |
|
| 190 | - $boucle->lang_select = $param; |
|
| 183 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | + $param = 'oui'; |
|
| 185 | + } |
|
| 186 | + if ($crit->not) { |
|
| 187 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | + } |
|
| 189 | + $boucle = &$boucles[$idb]; |
|
| 190 | + $boucle->lang_select = $param; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * @return void |
| 210 | 210 | **/ |
| 211 | 211 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 212 | - [$un, $deux] = $crit->param; |
|
| 213 | - $un = $un[0]->texte; |
|
| 214 | - $deux = $deux[0]->texte; |
|
| 215 | - if ($deux) { |
|
| 216 | - $boucles[$idb]->limit = |
|
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | - } else { |
|
| 219 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | - } |
|
| 212 | + [$un, $deux] = $crit->param; |
|
| 213 | + $un = $un[0]->texte; |
|
| 214 | + $deux = $deux[0]->texte; |
|
| 215 | + if ($deux) { |
|
| 216 | + $boucles[$idb]->limit = |
|
| 217 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + } else { |
|
| 219 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -251,58 +251,58 @@ discard block |
||
| 251 | 251 | **/ |
| 252 | 252 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 253 | 253 | |
| 254 | - $boucle = &$boucles[$idb]; |
|
| 255 | - // definition de la taille de la page |
|
| 256 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | - |
|
| 259 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | - } else { |
|
| 262 | - $r = intval($r[2]); |
|
| 263 | - $pas = strval($r ?: 10); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Calcul du nommage de la pagination si il existe. |
|
| 267 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | - $type = "'$idb'"; |
|
| 270 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | - // Syntaxe {pagination 20, nom} |
|
| 272 | - if (isset($crit->param[0][1])) { |
|
| 273 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | - elseif (isset($crit->param[1][0])) { |
|
| 276 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | - $partie = |
|
| 282 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | - . "\t}\n" |
|
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | - |
|
| 290 | - $boucle->hash .= ' |
|
| 254 | + $boucle = &$boucles[$idb]; |
|
| 255 | + // definition de la taille de la page |
|
| 256 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | + |
|
| 259 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | + } else { |
|
| 262 | + $r = intval($r[2]); |
|
| 263 | + $pas = strval($r ?: 10); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Calcul du nommage de la pagination si il existe. |
|
| 267 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | + $type = "'$idb'"; |
|
| 270 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | + // Syntaxe {pagination 20, nom} |
|
| 272 | + if (isset($crit->param[0][1])) { |
|
| 273 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | + elseif (isset($crit->param[1][0])) { |
|
| 276 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | + $partie = |
|
| 282 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | + . "\t}\n" |
|
| 288 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + |
|
| 290 | + $boucle->hash .= ' |
|
| 291 | 291 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 292 | 292 | |
| 293 | - $boucle->total_parties = $pas; |
|
| 294 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | - // sauf si pas de primaire, ou si primaire composee |
|
| 297 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | - if ( |
|
| 300 | - $boucle->primary |
|
| 301 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | - and !in_array($t, $boucle->select) |
|
| 303 | - ) { |
|
| 304 | - $boucle->select[] = $t; |
|
| 305 | - } |
|
| 293 | + $boucle->total_parties = $pas; |
|
| 294 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | + // sauf si pas de primaire, ou si primaire composee |
|
| 297 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + if ( |
|
| 300 | + $boucle->primary |
|
| 301 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | + and !in_array($t, $boucle->select) |
|
| 303 | + ) { |
|
| 304 | + $boucle->select[] = $t; |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | **/ |
| 325 | 325 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 326 | 326 | |
| 327 | - $boucle = &$boucles[$idb]; |
|
| 327 | + $boucle = &$boucles[$idb]; |
|
| 328 | 328 | |
| 329 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 329 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | 331 | |
| 332 | - return; |
|
| 333 | - } |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if (isset($crit->param[0])) { |
|
| 336 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | - } else { |
|
| 338 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | - } |
|
| 335 | + if (isset($crit->param[0])) { |
|
| 336 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | + } else { |
|
| 338 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | - $boucle->hash .= ' |
|
| 341 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | + $boucle->hash .= ' |
|
| 343 | 343 | // RECHERCHE' |
| 344 | - . ($crit->cond ? ' |
|
| 344 | + . ($crit->cond ? ' |
|
| 345 | 345 | if (!strlen(' . $quoi . ')){ |
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | 347 | } else' : '') . ' |
@@ -352,21 +352,21 @@ discard block |
||
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | - $boucle->select[] = $t; |
|
| 358 | - } # pour postgres, neuneu ici |
|
| 359 | - // jointure uniquement sur le serveur principal |
|
| 360 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | - if (!$boucle->sql_serveur) { |
|
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | - } |
|
| 365 | - $boucle->select[] = '$rech_select'; |
|
| 366 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | - |
|
| 368 | - // et la recherche trouve |
|
| 369 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 355 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | + $boucle->select[] = $t; |
|
| 358 | + } # pour postgres, neuneu ici |
|
| 359 | + // jointure uniquement sur le serveur principal |
|
| 360 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | + if (!$boucle->sql_serveur) { |
|
| 362 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | + } |
|
| 365 | + $boucle->select[] = '$rech_select'; |
|
| 366 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | + |
|
| 368 | + // et la recherche trouve |
|
| 369 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * @return void |
| 384 | 384 | **/ |
| 385 | 385 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 386 | - $boucle = &$boucles[$idb]; |
|
| 387 | - $prim = $boucle->primary; |
|
| 388 | - $table = $boucle->id_table; |
|
| 389 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | - $boucle->where[] = |
|
| 392 | - [ |
|
| 393 | - "'OR'", |
|
| 394 | - [ |
|
| 395 | - "'AND'", |
|
| 396 | - ["'='", "'$table.id_trad'", 0], |
|
| 397 | - ["'='", "'$table.$prim'", $dprim] |
|
| 398 | - ], |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'>'", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.id_trad'", $arg] |
|
| 403 | - ] |
|
| 404 | - ]; |
|
| 386 | + $boucle = &$boucles[$idb]; |
|
| 387 | + $prim = $boucle->primary; |
|
| 388 | + $table = $boucle->id_table; |
|
| 389 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | + $boucle->where[] = |
|
| 392 | + [ |
|
| 393 | + "'OR'", |
|
| 394 | + [ |
|
| 395 | + "'AND'", |
|
| 396 | + ["'='", "'$table.id_trad'", 0], |
|
| 397 | + ["'='", "'$table.$prim'", $dprim] |
|
| 398 | + ], |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'>'", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.id_trad'", $arg] |
|
| 403 | + ] |
|
| 404 | + ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @return void |
| 420 | 420 | **/ |
| 421 | 421 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 422 | - $boucle = &$boucles[$idb]; |
|
| 423 | - $prim = $boucle->primary; |
|
| 424 | - $table = $boucle->id_table; |
|
| 425 | - |
|
| 426 | - $c = |
|
| 427 | - [ |
|
| 428 | - "'OR'", |
|
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | - ]; |
|
| 432 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 422 | + $boucle = &$boucles[$idb]; |
|
| 423 | + $prim = $boucle->primary; |
|
| 424 | + $table = $boucle->id_table; |
|
| 425 | + |
|
| 426 | + $c = |
|
| 427 | + [ |
|
| 428 | + "'OR'", |
|
| 429 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | + ]; |
|
| 432 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | **/ |
| 447 | 447 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 448 | 448 | |
| 449 | - $boucle = &$boucles[$idb]; |
|
| 450 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | - |
|
| 454 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | - else { |
|
| 458 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | - } |
|
| 449 | + $boucle = &$boucles[$idb]; |
|
| 450 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + |
|
| 454 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | + else { |
|
| 458 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -487,37 +487,37 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 489 | 489 | |
| 490 | - $not = $crit->not; |
|
| 491 | - $boucle = &$boucles[$idb]; |
|
| 492 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | - if (isset($crit->param[0])) { |
|
| 494 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | - // sinon on le prend chez une boucle parente |
|
| 496 | - } else { |
|
| 497 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - //Trouver une jointure |
|
| 501 | - $champ = 'id_rubrique'; |
|
| 502 | - $desc = $boucle->show; |
|
| 503 | - //Seulement si necessaire |
|
| 504 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | - $decompose = decompose_champ_id_objet($champ); |
|
| 510 | - $champ = array_shift($decompose); |
|
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - $cle = $boucle->id_table; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 490 | + $not = $crit->not; |
|
| 491 | + $boucle = &$boucles[$idb]; |
|
| 492 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | + if (isset($crit->param[0])) { |
|
| 494 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | + // sinon on le prend chez une boucle parente |
|
| 496 | + } else { |
|
| 497 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + //Trouver une jointure |
|
| 501 | + $champ = 'id_rubrique'; |
|
| 502 | + $desc = $boucle->show; |
|
| 503 | + //Seulement si necessaire |
|
| 504 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | + $decompose = decompose_champ_id_objet($champ); |
|
| 510 | + $champ = array_shift($decompose); |
|
| 511 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $cle = $boucle->id_table; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 535 | 535 | |
| 536 | - $boucle = &$boucles[$idb]; |
|
| 537 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | - $serveur = $boucle->sql_serveur; |
|
| 536 | + $boucle = &$boucles[$idb]; |
|
| 537 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | + $serveur = $boucle->sql_serveur; |
|
| 539 | 539 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 540 | + $c = "sql_in('" . |
|
| 541 | + $boucle->id_table . '.' . $boucle->primary |
|
| 542 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | 543 | |
| 544 | - $boucle->where[] = $c; |
|
| 544 | + $boucle->where[] = $c; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -563,31 +563,31 @@ discard block |
||
| 563 | 563 | * @return void|array |
| 564 | 564 | **/ |
| 565 | 565 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 566 | - if ($t = isset($crit->param[0])) { |
|
| 567 | - $t = $crit->param[0]; |
|
| 568 | - if ($t[0]->type == 'texte') { |
|
| 569 | - $t = $t[0]->texte; |
|
| 570 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | - $t = table_objet_sql($r[1]); |
|
| 572 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | - if ($t) { |
|
| 574 | - $t .= '.' . $r[2]; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $t = '".' |
|
| 579 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | - . '."'; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - if ($t) { |
|
| 584 | - $boucles[$idb]->group[] = $t; |
|
| 585 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | - $boucles[$idb]->select[] = $t; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | - } |
|
| 566 | + if ($t = isset($crit->param[0])) { |
|
| 567 | + $t = $crit->param[0]; |
|
| 568 | + if ($t[0]->type == 'texte') { |
|
| 569 | + $t = $t[0]->texte; |
|
| 570 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | + $t = table_objet_sql($r[1]); |
|
| 572 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | + if ($t) { |
|
| 574 | + $t .= '.' . $r[2]; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } else { |
|
| 578 | + $t = '".' |
|
| 579 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | + . '."'; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + if ($t) { |
|
| 584 | + $boucles[$idb]->group[] = $t; |
|
| 585 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | + $boucles[$idb]->select[] = $t; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @return void |
| 608 | 608 | **/ |
| 609 | 609 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 610 | - $boucles[$idb]->group = []; |
|
| 610 | + $boucles[$idb]->group = []; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -644,44 +644,44 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 647 | - if (isset($crit->param[0])) { |
|
| 648 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | - $boucle = $boucles[$idb]; |
|
| 650 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | - if ( |
|
| 656 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | - ) { |
|
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | - } else { |
|
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | - } |
|
| 647 | + if (isset($crit->param[0])) { |
|
| 648 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | + $boucle = $boucles[$idb]; |
|
| 650 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | + if ( |
|
| 656 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | + ) { |
|
| 659 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + } else { |
|
| 661 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | + } |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | - $boucle = $boucles[$idb]; |
|
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 673 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | - if (!$desc) { |
|
| 675 | - $desc = $boucle->show['field']; |
|
| 676 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | - } |
|
| 679 | - if ($desc) { |
|
| 680 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | - } |
|
| 682 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | - |
|
| 684 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 670 | + $boucle = $boucles[$idb]; |
|
| 671 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | + $var = '$champs_' . $idb; |
|
| 673 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | + if (!$desc) { |
|
| 675 | + $desc = $boucle->show['field']; |
|
| 676 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | + } |
|
| 679 | + if ($desc) { |
|
| 680 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | + } |
|
| 682 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | + |
|
| 684 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 721 | 721 | */ |
| 722 | 722 | function critere_par_dist($idb, &$boucles, $crit) { |
| 723 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 723 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -742,93 +742,93 @@ discard block |
||
| 742 | 742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 743 | 743 | */ |
| 744 | 744 | function critere_parinverse($idb, &$boucles, $crit) { |
| 745 | - $boucle = &$boucles[$idb]; |
|
| 746 | - |
|
| 747 | - $sens = $collecte = ''; |
|
| 748 | - if ($crit->not) { |
|
| 749 | - $sens = " . ' DESC'"; |
|
| 750 | - } |
|
| 751 | - if (isset($boucle->modificateur['collate'])) { |
|
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // Pour chaque paramètre du critère |
|
| 756 | - foreach ($crit->param as $tri) { |
|
| 757 | - $order = $fct = ''; |
|
| 758 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | - if ($tri[0]->type != 'texte') { |
|
| 760 | - // calculer le order dynamique qui verifie les champs |
|
| 761 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | - } |
|
| 765 | - // tris textuels {par titre} |
|
| 766 | - else { |
|
| 767 | - $par = array_shift($tri); |
|
| 768 | - $par = $par->texte; |
|
| 769 | - |
|
| 770 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | - $expression = trim($m[1]); |
|
| 773 | - $champ = trim($m[2]); |
|
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | - } else { |
|
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | - // {par FONCTION(champ)} |
|
| 783 | - if (isset($match) and count($match) > 2) { |
|
| 784 | - $par = substr($match[2], 1, -1); |
|
| 785 | - $fct = $match[1]; |
|
| 786 | - } |
|
| 787 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | - if ($par == 'hasard') { |
|
| 789 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | - } else { |
|
| 793 | - // cas général {par champ}, {par table.champ}, ... |
|
| 794 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // on ne sait pas traiter… |
|
| 799 | - else { |
|
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | - if (is_array($order)) { |
|
| 805 | - return $order; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | - $t = $m[1]; |
|
| 811 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | - $boucle->select[] = $t; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - $sens = ''; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($fct) { |
|
| 819 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | - } else { |
|
| 822 | - $order = "'$fct(' . $order . ')'"; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $t = $order . $collecte . $sens; |
|
| 826 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | - $t = $r[1] . $r[2]; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $boucle->order[] = $t; |
|
| 831 | - } |
|
| 745 | + $boucle = &$boucles[$idb]; |
|
| 746 | + |
|
| 747 | + $sens = $collecte = ''; |
|
| 748 | + if ($crit->not) { |
|
| 749 | + $sens = " . ' DESC'"; |
|
| 750 | + } |
|
| 751 | + if (isset($boucle->modificateur['collate'])) { |
|
| 752 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // Pour chaque paramètre du critère |
|
| 756 | + foreach ($crit->param as $tri) { |
|
| 757 | + $order = $fct = ''; |
|
| 758 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | + if ($tri[0]->type != 'texte') { |
|
| 760 | + // calculer le order dynamique qui verifie les champs |
|
| 761 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | + } |
|
| 765 | + // tris textuels {par titre} |
|
| 766 | + else { |
|
| 767 | + $par = array_shift($tri); |
|
| 768 | + $par = $par->texte; |
|
| 769 | + |
|
| 770 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | + $expression = trim($m[1]); |
|
| 773 | + $champ = trim($m[2]); |
|
| 774 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | + } else { |
|
| 777 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | + // {par FONCTION(champ)} |
|
| 783 | + if (isset($match) and count($match) > 2) { |
|
| 784 | + $par = substr($match[2], 1, -1); |
|
| 785 | + $fct = $match[1]; |
|
| 786 | + } |
|
| 787 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | + if ($par == 'hasard') { |
|
| 789 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | + } else { |
|
| 793 | + // cas général {par champ}, {par table.champ}, ... |
|
| 794 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // on ne sait pas traiter… |
|
| 799 | + else { |
|
| 800 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | + if (is_array($order)) { |
|
| 805 | + return $order; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | + $t = $m[1]; |
|
| 811 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | + $boucle->select[] = $t; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + $sens = ''; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($fct) { |
|
| 819 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | + } else { |
|
| 822 | + $order = "'$fct(' . $order . ')'"; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $t = $order . $collecte . $sens; |
|
| 826 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | + $t = $r[1] . $r[2]; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $boucle->order[] = $t; |
|
| 831 | + } |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -842,13 +842,13 @@ discard block |
||
| 842 | 842 | * @return string Clause pour le Order by |
| 843 | 843 | */ |
| 844 | 844 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 845 | - $boucle = &$boucles[$idb]; |
|
| 846 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | - $parha = 'rand() AS hasard'; |
|
| 848 | - if (!in_array($parha, $boucle->select)) { |
|
| 849 | - $boucle->select[] = $parha; |
|
| 850 | - } |
|
| 851 | - return "'hasard'"; |
|
| 845 | + $boucle = &$boucles[$idb]; |
|
| 846 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | + $parha = 'rand() AS hasard'; |
|
| 848 | + if (!in_array($parha, $boucle->select)) { |
|
| 849 | + $boucle->select[] = $parha; |
|
| 850 | + } |
|
| 851 | + return "'hasard'"; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -872,24 +872,24 @@ discard block |
||
| 872 | 872 | * @return string|array Clause pour le Order by (array si erreur) |
| 873 | 873 | */ |
| 874 | 874 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | - if (is_array($_champ)) { |
|
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | - } |
|
| 879 | - $boucle = &$boucles[$idb]; |
|
| 880 | - $texte = '0+' . $_champ; |
|
| 881 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | - if ($suite !== "''") { |
|
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | - } |
|
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | - |
|
| 888 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | - $orderassinum = trim($orderassinum, "'"); |
|
| 890 | - |
|
| 891 | - $order = "'$orderassinum, $asnum'"; |
|
| 892 | - return $order; |
|
| 875 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | + if (is_array($_champ)) { |
|
| 877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | + } |
|
| 879 | + $boucle = &$boucles[$idb]; |
|
| 880 | + $texte = '0+' . $_champ; |
|
| 881 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | + if ($suite !== "''") { |
|
| 883 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | + } |
|
| 885 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + |
|
| 888 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | + $orderassinum = trim($orderassinum, "'"); |
|
| 890 | + |
|
| 891 | + $order = "'$orderassinum, $asnum'"; |
|
| 892 | + return $order; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -910,35 +910,35 @@ discard block |
||
| 910 | 910 | * @return string|array Clause pour le Order by (array si erreur) |
| 911 | 911 | */ |
| 912 | 912 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | - if (is_array($_champ)) { |
|
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | - } |
|
| 917 | - $boucle = &$boucles[$idb]; |
|
| 918 | - $texte = '0+' . $_champ; |
|
| 919 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | - if ($suite !== "''") { |
|
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $as = false; |
|
| 925 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | - foreach ($boucle->select as $s) { |
|
| 927 | - if (strpos($s, $select) === 0) { |
|
| 928 | - $as = trim(substr($s, strlen($select))); |
|
| 929 | - if (!preg_match(',\W,', $as)) { |
|
| 930 | - break; |
|
| 931 | - } |
|
| 932 | - $as = false; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if (!$as) { |
|
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 939 | - } |
|
| 940 | - $order = "'$as'"; |
|
| 941 | - return $order; |
|
| 913 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | + if (is_array($_champ)) { |
|
| 915 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + } |
|
| 917 | + $boucle = &$boucles[$idb]; |
|
| 918 | + $texte = '0+' . $_champ; |
|
| 919 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | + if ($suite !== "''") { |
|
| 921 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $as = false; |
|
| 925 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | + foreach ($boucle->select as $s) { |
|
| 927 | + if (strpos($s, $select) === 0) { |
|
| 928 | + $as = trim(substr($s, strlen($select))); |
|
| 929 | + if (!preg_match(',\W,', $as)) { |
|
| 930 | + break; |
|
| 931 | + } |
|
| 932 | + $as = false; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + if (!$as) { |
|
| 937 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | + $boucle->select[] = $select . $as; |
|
| 939 | + } |
|
| 940 | + $order = "'$as'"; |
|
| 941 | + return $order; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @return string|array Clause pour le Order by (array si erreur) |
| 959 | 959 | */ |
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | - if (is_array($_champ)) { |
|
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | - } |
|
| 965 | - $boucle = &$boucles[$idb]; |
|
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | - $order = "'multi'"; |
|
| 968 | - return $order; |
|
| 961 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | + if (is_array($_champ)) { |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | + } |
|
| 965 | + $boucle = &$boucles[$idb]; |
|
| 966 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | + $order = "'multi'"; |
|
| 968 | + return $order; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,56 +984,56 @@ discard block |
||
| 984 | 984 | * @return array|string |
| 985 | 985 | */ |
| 986 | 986 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 987 | - $boucle = &$boucles[$idb]; |
|
| 988 | - $desc = $boucle->show; |
|
| 989 | - |
|
| 990 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | - if (isset($desc['field'][$par])) { |
|
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 993 | - } |
|
| 994 | - // le champ est peut être une jointure |
|
| 995 | - else { |
|
| 996 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | - $champ = $par; |
|
| 998 | - |
|
| 999 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | - [, $table, $champ] = $r; |
|
| 1005 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | - $table = table_objet_sql($table); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | - } elseif ( |
|
| 1015 | - $boucle->jointures_explicites |
|
| 1016 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | - ) { |
|
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1019 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1021 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | - } elseif ( |
|
| 1023 | - $table_alias |
|
| 1024 | - and isset($boucle->from[$table_alias]) |
|
| 1025 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | - ) { |
|
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | - } elseif ($table) { |
|
| 1029 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | - } else { |
|
| 1032 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $raw ? $par : "'$par'"; |
|
| 987 | + $boucle = &$boucles[$idb]; |
|
| 988 | + $desc = $boucle->show; |
|
| 989 | + |
|
| 990 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | + if (isset($desc['field'][$par])) { |
|
| 992 | + $par = $boucle->id_table . '.' . $par; |
|
| 993 | + } |
|
| 994 | + // le champ est peut être une jointure |
|
| 995 | + else { |
|
| 996 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | + $champ = $par; |
|
| 998 | + |
|
| 999 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | + [, $table, $champ] = $r; |
|
| 1005 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | + $table = table_objet_sql($table); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | + } elseif ( |
|
| 1015 | + $boucle->jointures_explicites |
|
| 1016 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | + ) { |
|
| 1018 | + $par = $alias . '.' . $champ; |
|
| 1019 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | + $par = $alias . '.' . $champ; |
|
| 1021 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | + } elseif ( |
|
| 1023 | + $table_alias |
|
| 1024 | + and isset($boucle->from[$table_alias]) |
|
| 1025 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | + ) { |
|
| 1027 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | + } elseif ($table) { |
|
| 1029 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | + } else { |
|
| 1032 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $raw ? $par : "'$par'"; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1047,11 +1047,11 @@ discard block |
||
| 1047 | 1047 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1048 | 1048 | */ |
| 1049 | 1049 | function critere_par_joint($table, $champ, &$boucle) { |
| 1050 | - $t = array_search($table, $boucle->from); |
|
| 1051 | - if (!$t) { |
|
| 1052 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | - } |
|
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1050 | + $t = array_search($table, $boucle->from); |
|
| 1051 | + if (!$t) { |
|
| 1052 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | + } |
|
| 1054 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1076,33 +1076,33 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1078 | 1078 | |
| 1079 | - $boucle = &$boucles[$idb]; |
|
| 1080 | - // Classement par ordre inverse |
|
| 1081 | - if ($crit->not) { |
|
| 1082 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | - } else { |
|
| 1084 | - $order = "' DESC'"; |
|
| 1085 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | - if (isset($crit->param[0])) { |
|
| 1087 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | - $order = "(($critere)?' DESC':'')"; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | - if (!$n) { |
|
| 1093 | - if (isset($boucle->default_order[0])) { |
|
| 1094 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | - } else { |
|
| 1096 | - $boucle->default_order[] = ' DESC'; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1102 | - } |
|
| 1103 | - $boucle->order[$n - 1] = $t; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1079 | + $boucle = &$boucles[$idb]; |
|
| 1080 | + // Classement par ordre inverse |
|
| 1081 | + if ($crit->not) { |
|
| 1082 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | + } else { |
|
| 1084 | + $order = "' DESC'"; |
|
| 1085 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | + if (isset($crit->param[0])) { |
|
| 1087 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | + $order = "(($critere)?' DESC':'')"; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | + if (!$n) { |
|
| 1093 | + if (isset($boucle->default_order[0])) { |
|
| 1094 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | + } else { |
|
| 1096 | + $boucle->default_order[] = ' DESC'; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | + $t = $r[1] . $r[2]; |
|
| 1102 | + } |
|
| 1103 | + $boucle->order[$n - 1] = $t; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1113,137 +1113,137 @@ discard block |
||
| 1113 | 1113 | * @return void|array |
| 1114 | 1114 | */ |
| 1115 | 1115 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1116 | - $boucle = &$boucles[$idb]; |
|
| 1116 | + $boucle = &$boucles[$idb]; |
|
| 1117 | 1117 | |
| 1118 | - $sens = $collecte = ''; |
|
| 1119 | - if ($crit->not) { |
|
| 1120 | - $sens = " . ' DESC'"; |
|
| 1121 | - } |
|
| 1118 | + $sens = $collecte = ''; |
|
| 1119 | + if ($crit->not) { |
|
| 1120 | + $sens = " . ' DESC'"; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - $crit2 = clone $crit; |
|
| 1124 | - $crit2->not = false; |
|
| 1125 | - $crit2->param = [reset($crit->param)]; |
|
| 1126 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1123 | + $crit2 = clone $crit; |
|
| 1124 | + $crit2->not = false; |
|
| 1125 | + $crit2->param = [reset($crit->param)]; |
|
| 1126 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1127 | 1127 | |
| 1128 | - // erreur ? |
|
| 1129 | - if (is_array($res)) { |
|
| 1130 | - return $res; |
|
| 1131 | - } |
|
| 1128 | + // erreur ? |
|
| 1129 | + if (is_array($res)) { |
|
| 1130 | + return $res; |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - $_order = array_pop($boucle->order); |
|
| 1133 | + $_order = array_pop($boucle->order); |
|
| 1134 | 1134 | |
| 1135 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1135 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | 1140 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1141 | - $params = $crit->param; |
|
| 1142 | - |
|
| 1143 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - $boucle = &$boucles[$idb]; |
|
| 1148 | - $parent = $boucle->id_parent; |
|
| 1149 | - $fields = $boucle->show['field']; |
|
| 1150 | - |
|
| 1151 | - $date = array_shift($params); |
|
| 1152 | - $type = array_shift($params); |
|
| 1153 | - |
|
| 1154 | - // la valeur $type doit etre connue a la compilation |
|
| 1155 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | - |
|
| 1158 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | - $date = $date[0]->texte; |
|
| 1164 | - if (!isset($fields[$date])) { |
|
| 1165 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | - } |
|
| 1167 | - } else { |
|
| 1168 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | - $noms = array_keys($fields); |
|
| 1170 | - $defaut = $noms[0]; |
|
| 1171 | - $noms = join(' ', $noms); |
|
| 1172 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | - } |
|
| 1176 | - $annee = $params ? array_shift($params) : ''; |
|
| 1177 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | - ') ? $x : date("Y"))'; |
|
| 1180 | - |
|
| 1181 | - $mois = $params ? array_shift($params) : ''; |
|
| 1182 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | - ') ? $x : date("m"))'; |
|
| 1185 | - |
|
| 1186 | - $jour = $params ? array_shift($params) : ''; |
|
| 1187 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | - ') ? $x : date("d"))'; |
|
| 1190 | - |
|
| 1191 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | - ') ? $x : date("Y"))'; |
|
| 1195 | - |
|
| 1196 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | - ') ? $x : date("m"))'; |
|
| 1200 | - |
|
| 1201 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | - ') ? $x : date("d"))'; |
|
| 1205 | - |
|
| 1206 | - $date = $boucle->id_table . ".$date"; |
|
| 1207 | - |
|
| 1208 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | - if ($type == 'jour') { |
|
| 1210 | - $boucle->where[] = [ |
|
| 1211 | - "'='", |
|
| 1212 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | - ]; |
|
| 1215 | - } elseif ($type == 'mois') { |
|
| 1216 | - $boucle->where[] = [ |
|
| 1217 | - "'='", |
|
| 1218 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | - ]; |
|
| 1221 | - } elseif ($type == 'semaine') { |
|
| 1222 | - $boucle->where[] = [ |
|
| 1223 | - "'AND'", |
|
| 1224 | - [ |
|
| 1225 | - "'>='", |
|
| 1226 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | - ], |
|
| 1229 | - [ |
|
| 1230 | - "'<='", |
|
| 1231 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | - ] |
|
| 1234 | - ]; |
|
| 1235 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | - $boucle->where[] = [ |
|
| 1237 | - "'AND'", |
|
| 1238 | - [ |
|
| 1239 | - "'>='", |
|
| 1240 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | - ], |
|
| 1243 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | - ]; |
|
| 1245 | - } |
|
| 1246 | - // sinon on prend tout |
|
| 1141 | + $params = $crit->param; |
|
| 1142 | + |
|
| 1143 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + $boucle = &$boucles[$idb]; |
|
| 1148 | + $parent = $boucle->id_parent; |
|
| 1149 | + $fields = $boucle->show['field']; |
|
| 1150 | + |
|
| 1151 | + $date = array_shift($params); |
|
| 1152 | + $type = array_shift($params); |
|
| 1153 | + |
|
| 1154 | + // la valeur $type doit etre connue a la compilation |
|
| 1155 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | + |
|
| 1158 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | + $date = $date[0]->texte; |
|
| 1164 | + if (!isset($fields[$date])) { |
|
| 1165 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | + } |
|
| 1167 | + } else { |
|
| 1168 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | + $noms = array_keys($fields); |
|
| 1170 | + $defaut = $noms[0]; |
|
| 1171 | + $noms = join(' ', $noms); |
|
| 1172 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | + } |
|
| 1176 | + $annee = $params ? array_shift($params) : ''; |
|
| 1177 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + ') ? $x : date("Y"))'; |
|
| 1180 | + |
|
| 1181 | + $mois = $params ? array_shift($params) : ''; |
|
| 1182 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + ') ? $x : date("m"))'; |
|
| 1185 | + |
|
| 1186 | + $jour = $params ? array_shift($params) : ''; |
|
| 1187 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + ') ? $x : date("d"))'; |
|
| 1190 | + |
|
| 1191 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + ') ? $x : date("Y"))'; |
|
| 1195 | + |
|
| 1196 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + ') ? $x : date("m"))'; |
|
| 1200 | + |
|
| 1201 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + ') ? $x : date("d"))'; |
|
| 1205 | + |
|
| 1206 | + $date = $boucle->id_table . ".$date"; |
|
| 1207 | + |
|
| 1208 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | + if ($type == 'jour') { |
|
| 1210 | + $boucle->where[] = [ |
|
| 1211 | + "'='", |
|
| 1212 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | + ]; |
|
| 1215 | + } elseif ($type == 'mois') { |
|
| 1216 | + $boucle->where[] = [ |
|
| 1217 | + "'='", |
|
| 1218 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | + ]; |
|
| 1221 | + } elseif ($type == 'semaine') { |
|
| 1222 | + $boucle->where[] = [ |
|
| 1223 | + "'AND'", |
|
| 1224 | + [ |
|
| 1225 | + "'>='", |
|
| 1226 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | + ], |
|
| 1229 | + [ |
|
| 1230 | + "'<='", |
|
| 1231 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | + ] |
|
| 1234 | + ]; |
|
| 1235 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | + $boucle->where[] = [ |
|
| 1237 | + "'AND'", |
|
| 1238 | + [ |
|
| 1239 | + "'>='", |
|
| 1240 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | + ], |
|
| 1243 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | + ]; |
|
| 1245 | + } |
|
| 1246 | + // sinon on prend tout |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | |
@@ -1268,33 +1268,33 @@ discard block |
||
| 1268 | 1268 | * @return void |
| 1269 | 1269 | **/ |
| 1270 | 1270 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1271 | - $boucle = &$boucles[$idb]; |
|
| 1272 | - $a1 = $crit->param[0]; |
|
| 1273 | - $a2 = $crit->param[1]; |
|
| 1274 | - $op = $crit->op; |
|
| 1275 | - |
|
| 1276 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | - |
|
| 1279 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | - } else { |
|
| 1282 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | - $mode = (($op == '/') ? '/' : |
|
| 1287 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | - $boucle->limit = |
|
| 1291 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | - . ".','." |
|
| 1293 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | - } else { |
|
| 1295 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | - } |
|
| 1297 | - } |
|
| 1271 | + $boucle = &$boucles[$idb]; |
|
| 1272 | + $a1 = $crit->param[0]; |
|
| 1273 | + $a2 = $crit->param[1]; |
|
| 1274 | + $op = $crit->op; |
|
| 1275 | + |
|
| 1276 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | + |
|
| 1279 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | + } else { |
|
| 1282 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | + $mode = (($op == '/') ? '/' : |
|
| 1287 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | + $boucle->limit = |
|
| 1291 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | + . ".','." |
|
| 1293 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | + } else { |
|
| 1295 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | + } |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1322,63 +1322,63 @@ discard block |
||
| 1322 | 1322 | * @return void |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1325 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | - |
|
| 1327 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | - // {1/3} |
|
| 1331 | - if ($op1 == '/') { |
|
| 1332 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | - "($total_parties ? $total_parties : 1)"; |
|
| 1335 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | - } else { |
|
| 1338 | - // cas {n-1,x} |
|
| 1339 | - if ($op1 == '-') { |
|
| 1340 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - // cas {x,n-1} |
|
| 1344 | - if ($op2 == '-') { |
|
| 1345 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | - ($total_parties . ' - 1')); |
|
| 1348 | - } else { |
|
| 1349 | - // {x,1} ou {pagination} |
|
| 1350 | - $fin = '$debut_boucle' |
|
| 1351 | - . (is_numeric($total_parties) ? |
|
| 1352 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | - ('+' . $total_parties . ' - 1')); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | - if ($op1 == 'p') { |
|
| 1358 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - // Notes : |
|
| 1365 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | - |
|
| 1370 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | - . "\n\tif (\$debut_boucle>0" |
|
| 1377 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | - |
|
| 1381 | - $boucles[$id_boucle]->partie = " |
|
| 1325 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | + |
|
| 1327 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | + // {1/3} |
|
| 1331 | + if ($op1 == '/') { |
|
| 1332 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | + "($total_parties ? $total_parties : 1)"; |
|
| 1335 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | + } else { |
|
| 1338 | + // cas {n-1,x} |
|
| 1339 | + if ($op1 == '-') { |
|
| 1340 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + // cas {x,n-1} |
|
| 1344 | + if ($op2 == '-') { |
|
| 1345 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | + ($total_parties . ' - 1')); |
|
| 1348 | + } else { |
|
| 1349 | + // {x,1} ou {pagination} |
|
| 1350 | + $fin = '$debut_boucle' |
|
| 1351 | + . (is_numeric($total_parties) ? |
|
| 1352 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | + ('+' . $total_parties . ' - 1')); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | + if ($op1 == 'p') { |
|
| 1358 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + // Notes : |
|
| 1365 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | + |
|
| 1370 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | + . "\n\tif (\$debut_boucle>0" |
|
| 1377 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | + |
|
| 1381 | + $boucles[$id_boucle]->partie = " |
|
| 1382 | 1382 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1383 | 1383 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1384 | 1384 | } |
@@ -1395,26 +1395,26 @@ discard block |
||
| 1395 | 1395 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1396 | 1396 | **/ |
| 1397 | 1397 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1398 | - if ($param[0]->type != 'texte') { |
|
| 1399 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | - if (isset($param[1]->texte)) { |
|
| 1401 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | - |
|
| 1403 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | - } else { |
|
| 1405 | - return ["intval($a1)", 0]; |
|
| 1406 | - } |
|
| 1407 | - } else { |
|
| 1408 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | - $a1 = $m[1]; |
|
| 1410 | - if (empty($m[3])) { |
|
| 1411 | - return [$a1, 0]; |
|
| 1412 | - } elseif (!empty($m[4])) { |
|
| 1413 | - return [$a1, $m[4]]; |
|
| 1414 | - } else { |
|
| 1415 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | - } |
|
| 1417 | - } |
|
| 1398 | + if ($param[0]->type != 'texte') { |
|
| 1399 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | + if (isset($param[1]->texte)) { |
|
| 1401 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | + |
|
| 1403 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | + } else { |
|
| 1405 | + return ["intval($a1)", 0]; |
|
| 1406 | + } |
|
| 1407 | + } else { |
|
| 1408 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | + $a1 = $m[1]; |
|
| 1410 | + if (empty($m[3])) { |
|
| 1411 | + return [$a1, 0]; |
|
| 1412 | + } elseif (!empty($m[4])) { |
|
| 1413 | + return [$a1, $m[4]]; |
|
| 1414 | + } else { |
|
| 1415 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | + } |
|
| 1417 | + } |
|
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | |
@@ -1441,47 +1441,47 @@ discard block |
||
| 1441 | 1441 | * array : Erreur sur un des critères |
| 1442 | 1442 | **/ |
| 1443 | 1443 | function calculer_criteres($idb, &$boucles) { |
| 1444 | - $msg = ''; |
|
| 1445 | - $boucle = $boucles[$idb]; |
|
| 1446 | - $table = strtoupper($boucle->type_requete); |
|
| 1447 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | - |
|
| 1449 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | - if (!is_array($boucle->criteres)) { |
|
| 1452 | - return []; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - foreach ($boucle->criteres as $crit) { |
|
| 1456 | - $critere = $crit->op; |
|
| 1457 | - // critere personnalise ? |
|
| 1458 | - if ( |
|
| 1459 | - (!$serveur or |
|
| 1460 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | - and (!function_exists($f = $f . '_dist')) |
|
| 1462 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | - ) |
|
| 1465 | - ) |
|
| 1466 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1470 | - ) { |
|
| 1471 | - // fonction critere standard |
|
| 1472 | - $f = $defaut; |
|
| 1473 | - } |
|
| 1474 | - // compile le critere |
|
| 1475 | - $res = $f($idb, $boucles, $crit); |
|
| 1476 | - |
|
| 1477 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | - if (is_array($res)) { |
|
| 1479 | - $msg = $res; |
|
| 1480 | - erreur_squelette($msg, $boucle); |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - return $msg; |
|
| 1444 | + $msg = ''; |
|
| 1445 | + $boucle = $boucles[$idb]; |
|
| 1446 | + $table = strtoupper($boucle->type_requete); |
|
| 1447 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | + |
|
| 1449 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | + if (!is_array($boucle->criteres)) { |
|
| 1452 | + return []; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + foreach ($boucle->criteres as $crit) { |
|
| 1456 | + $critere = $crit->op; |
|
| 1457 | + // critere personnalise ? |
|
| 1458 | + if ( |
|
| 1459 | + (!$serveur or |
|
| 1460 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | + and (!function_exists($f = $f . '_dist')) |
|
| 1462 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | + and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + ) |
|
| 1465 | + ) |
|
| 1466 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | + and (!function_exists($f = $f . '_dist')) |
|
| 1468 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | + and (!function_exists($f = $f . '_dist')) |
|
| 1470 | + ) { |
|
| 1471 | + // fonction critere standard |
|
| 1472 | + $f = $defaut; |
|
| 1473 | + } |
|
| 1474 | + // compile le critere |
|
| 1475 | + $res = $f($idb, $boucles, $crit); |
|
| 1476 | + |
|
| 1477 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | + if (is_array($res)) { |
|
| 1479 | + $msg = $res; |
|
| 1480 | + erreur_squelette($msg, $boucle); |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + return $msg; |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
@@ -1496,11 +1496,11 @@ discard block |
||
| 1496 | 1496 | * @return string Code compilé rééchappé |
| 1497 | 1497 | */ |
| 1498 | 1498 | function kwote($lisp, $serveur = '', $type = '') { |
| 1499 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | - } else { |
|
| 1502 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | - } |
|
| 1499 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | + } else { |
|
| 1502 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | + } |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | |
@@ -1519,81 +1519,81 @@ discard block |
||
| 1519 | 1519 | * @return void|array |
| 1520 | 1520 | **/ |
| 1521 | 1521 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1522 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | - if (!$r) { |
|
| 1524 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1525 | - } |
|
| 1526 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | - |
|
| 1528 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | - |
|
| 1530 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | - $where = $in; |
|
| 1532 | - if ($crit->cond) { |
|
| 1533 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - if ($crit->exclus) { |
|
| 1540 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | - $where = ["'NOT'", $where]; |
|
| 1542 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | - { |
|
| 1545 | - $where = [ |
|
| 1546 | - "'NOT'", |
|
| 1547 | - [ |
|
| 1548 | - "'IN'", |
|
| 1549 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | - ] |
|
| 1552 | - ]; |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - $boucles[$idb]->where[] = $where; |
|
| 1557 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | - } |
|
| 1522 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | + if (!$r) { |
|
| 1524 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1525 | + } |
|
| 1526 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | + |
|
| 1528 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | + |
|
| 1530 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | + $where = $in; |
|
| 1532 | + if ($crit->cond) { |
|
| 1533 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + if ($crit->exclus) { |
|
| 1540 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | + $where = ["'NOT'", $where]; |
|
| 1542 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | + { |
|
| 1545 | + $where = [ |
|
| 1546 | + "'NOT'", |
|
| 1547 | + [ |
|
| 1548 | + "'IN'", |
|
| 1549 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | + ] |
|
| 1552 | + ]; |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + $boucles[$idb]->where[] = $where; |
|
| 1557 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | + } |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1563 | - static $num = []; |
|
| 1564 | - $descr = $boucles[$idb]->descr; |
|
| 1565 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | - |
|
| 1567 | - $var = '$in' . $cpt++; |
|
| 1568 | - $x = "\n\t$var = array();"; |
|
| 1569 | - foreach ($val as $k => $v) { |
|
| 1570 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | - // optimiser le traitement des constantes |
|
| 1572 | - if (is_numeric($r[2])) { |
|
| 1573 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | - } else { |
|
| 1575 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | - } |
|
| 1577 | - } else { |
|
| 1578 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - $boucles[$idb]->in .= $x; |
|
| 1587 | - |
|
| 1588 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | - if (!$crit2) { |
|
| 1593 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1563 | + static $num = []; |
|
| 1564 | + $descr = $boucles[$idb]->descr; |
|
| 1565 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | + |
|
| 1567 | + $var = '$in' . $cpt++; |
|
| 1568 | + $x = "\n\t$var = array();"; |
|
| 1569 | + foreach ($val as $k => $v) { |
|
| 1570 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | + // optimiser le traitement des constantes |
|
| 1572 | + if (is_numeric($r[2])) { |
|
| 1573 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | + } else { |
|
| 1575 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | + } |
|
| 1577 | + } else { |
|
| 1578 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + $boucles[$idb]->in .= $x; |
|
| 1587 | + |
|
| 1588 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | + if (!$crit2) { |
|
| 1593 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | /** |
@@ -1609,22 +1609,22 @@ discard block |
||
| 1609 | 1609 | * @return void |
| 1610 | 1610 | */ |
| 1611 | 1611 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1612 | - $boucle = &$boucles[$idb]; |
|
| 1613 | - if (isset($crit->param[0])) { |
|
| 1614 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | - } else { |
|
| 1616 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - if ($crit->cond) { |
|
| 1620 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - if ($crit->not) { |
|
| 1624 | - $_where = "array('NOT',$_where)"; |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - $boucle->where[] = $_where; |
|
| 1612 | + $boucle = &$boucles[$idb]; |
|
| 1613 | + if (isset($crit->param[0])) { |
|
| 1614 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | + } else { |
|
| 1616 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + if ($crit->cond) { |
|
| 1620 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + if ($crit->not) { |
|
| 1624 | + $_where = "array('NOT',$_where)"; |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + $boucle->where[] = $_where; |
|
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | /** |
@@ -1652,31 +1652,31 @@ discard block |
||
| 1652 | 1652 | * @return void |
| 1653 | 1653 | */ |
| 1654 | 1654 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1655 | - /** @var Boucle $boucle */ |
|
| 1656 | - $boucle = $boucles[$idb]; |
|
| 1657 | - |
|
| 1658 | - $champs = lister_champs_id_conditionnel( |
|
| 1659 | - $boucle->show['table'], |
|
| 1660 | - $boucle->show, |
|
| 1661 | - $boucle->sql_serveur |
|
| 1662 | - ); |
|
| 1663 | - |
|
| 1664 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | - } |
|
| 1668 | - // nous aider en mode debug. |
|
| 1669 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | - $boucle->modificateur['id_'] = $champs; |
|
| 1671 | - |
|
| 1672 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | - foreach ($champs as $champ) { |
|
| 1674 | - $critere_id_table = new Critere(); |
|
| 1675 | - $critere_id_table->op = $champ; |
|
| 1676 | - $critere_id_table->cond = '?'; |
|
| 1677 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | - } |
|
| 1655 | + /** @var Boucle $boucle */ |
|
| 1656 | + $boucle = $boucles[$idb]; |
|
| 1657 | + |
|
| 1658 | + $champs = lister_champs_id_conditionnel( |
|
| 1659 | + $boucle->show['table'], |
|
| 1660 | + $boucle->show, |
|
| 1661 | + $boucle->sql_serveur |
|
| 1662 | + ); |
|
| 1663 | + |
|
| 1664 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | + } |
|
| 1668 | + // nous aider en mode debug. |
|
| 1669 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | + $boucle->modificateur['id_'] = $champs; |
|
| 1671 | + |
|
| 1672 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | + foreach ($champs as $champ) { |
|
| 1674 | + $critere_id_table = new Critere(); |
|
| 1675 | + $critere_id_table->op = $champ; |
|
| 1676 | + $critere_id_table->cond = '?'; |
|
| 1677 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | + } |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | /** |
@@ -1696,75 +1696,75 @@ discard block |
||
| 1696 | 1696 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1697 | 1697 | */ |
| 1698 | 1698 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1699 | - // calculer la description de la table |
|
| 1700 | - if (!is_array($desc)) { |
|
| 1701 | - $desc = description_table($table, $serveur); |
|
| 1702 | - } |
|
| 1703 | - if (!$desc) { |
|
| 1704 | - return []; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - // Les champs id_xx de la table demandée |
|
| 1708 | - $champs = array_filter( |
|
| 1709 | - array_keys($desc['field']), |
|
| 1710 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | - ); |
|
| 1712 | - |
|
| 1713 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | - if ( |
|
| 1715 | - in_array('id_rubrique', $champs) |
|
| 1716 | - and !in_array('id_secteur', $champs) |
|
| 1717 | - ) { |
|
| 1718 | - $champs[] = 'id_secteur'; |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | - if ($serveur) { |
|
| 1723 | - return $champs; |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - $primary = false; |
|
| 1727 | - $associable = false; |
|
| 1728 | - include_spip('action/editer_liens'); |
|
| 1729 | - |
|
| 1730 | - if (isset($desc['type'])) { |
|
| 1731 | - $primary = id_table_objet($desc['type']); |
|
| 1732 | - $associable = objet_associable($desc['type']); |
|
| 1733 | - } |
|
| 1734 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | - $associable = true; |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - // liste de toutes les tables principales, sauf la notre |
|
| 1739 | - $tables = lister_tables_objets_sql(); |
|
| 1740 | - unset($tables[$table]); |
|
| 1741 | - |
|
| 1742 | - foreach ($tables as $_table => $_desc) { |
|
| 1743 | - if ( |
|
| 1744 | - $associable |
|
| 1745 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | - or objet_associable($_desc['type']) |
|
| 1747 | - ) { |
|
| 1748 | - $champs[] = id_table_objet($_table); |
|
| 1749 | - } |
|
| 1750 | - } |
|
| 1751 | - $champs = array_values(array_unique($champs)); |
|
| 1752 | - |
|
| 1753 | - // Exclusions de certains id |
|
| 1754 | - $exclusions = pipeline( |
|
| 1755 | - 'exclure_id_conditionnel', |
|
| 1756 | - [ |
|
| 1757 | - 'args' => [ |
|
| 1758 | - 'table' => $table, |
|
| 1759 | - 'id_table_objet' => $primary, |
|
| 1760 | - 'associable' => $associable, |
|
| 1761 | - ], |
|
| 1762 | - 'data' => [], |
|
| 1763 | - ] |
|
| 1764 | - ); |
|
| 1765 | - $champs = array_diff($champs, $exclusions); |
|
| 1766 | - |
|
| 1767 | - return $champs; |
|
| 1699 | + // calculer la description de la table |
|
| 1700 | + if (!is_array($desc)) { |
|
| 1701 | + $desc = description_table($table, $serveur); |
|
| 1702 | + } |
|
| 1703 | + if (!$desc) { |
|
| 1704 | + return []; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + // Les champs id_xx de la table demandée |
|
| 1708 | + $champs = array_filter( |
|
| 1709 | + array_keys($desc['field']), |
|
| 1710 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | + ); |
|
| 1712 | + |
|
| 1713 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | + if ( |
|
| 1715 | + in_array('id_rubrique', $champs) |
|
| 1716 | + and !in_array('id_secteur', $champs) |
|
| 1717 | + ) { |
|
| 1718 | + $champs[] = 'id_secteur'; |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | + if ($serveur) { |
|
| 1723 | + return $champs; |
|
| 1724 | + } |
|
| 1725 | + |
|
| 1726 | + $primary = false; |
|
| 1727 | + $associable = false; |
|
| 1728 | + include_spip('action/editer_liens'); |
|
| 1729 | + |
|
| 1730 | + if (isset($desc['type'])) { |
|
| 1731 | + $primary = id_table_objet($desc['type']); |
|
| 1732 | + $associable = objet_associable($desc['type']); |
|
| 1733 | + } |
|
| 1734 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | + $associable = true; |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + // liste de toutes les tables principales, sauf la notre |
|
| 1739 | + $tables = lister_tables_objets_sql(); |
|
| 1740 | + unset($tables[$table]); |
|
| 1741 | + |
|
| 1742 | + foreach ($tables as $_table => $_desc) { |
|
| 1743 | + if ( |
|
| 1744 | + $associable |
|
| 1745 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | + or objet_associable($_desc['type']) |
|
| 1747 | + ) { |
|
| 1748 | + $champs[] = id_table_objet($_table); |
|
| 1749 | + } |
|
| 1750 | + } |
|
| 1751 | + $champs = array_values(array_unique($champs)); |
|
| 1752 | + |
|
| 1753 | + // Exclusions de certains id |
|
| 1754 | + $exclusions = pipeline( |
|
| 1755 | + 'exclure_id_conditionnel', |
|
| 1756 | + [ |
|
| 1757 | + 'args' => [ |
|
| 1758 | + 'table' => $table, |
|
| 1759 | + 'id_table_objet' => $primary, |
|
| 1760 | + 'associable' => $associable, |
|
| 1761 | + ], |
|
| 1762 | + 'data' => [], |
|
| 1763 | + ] |
|
| 1764 | + ); |
|
| 1765 | + $champs = array_diff($champs, $exclusions); |
|
| 1766 | + |
|
| 1767 | + return $champs; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1819,27 +1819,27 @@ discard block |
||
| 1819 | 1819 | * @return void |
| 1820 | 1820 | */ |
| 1821 | 1821 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1822 | - $boucle = &$boucles[$idb]; |
|
| 1823 | - |
|
| 1824 | - // definition du champ par defaut |
|
| 1825 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | - $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | - |
|
| 1832 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | - |
|
| 1834 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | - |
|
| 1837 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1840 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1841 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1842 | - $boucle->hash .= " |
|
| 1822 | + $boucle = &$boucles[$idb]; |
|
| 1823 | + |
|
| 1824 | + // definition du champ par defaut |
|
| 1825 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | + $_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | + |
|
| 1832 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | + |
|
| 1834 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | + |
|
| 1837 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1840 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1841 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1842 | + $boucle->hash .= " |
|
| 1843 | 1843 | \$senstri = ''; |
| 1844 | 1844 | \$tri = $_tri; |
| 1845 | 1845 | if (\$tri){ |
@@ -1847,8 +1847,8 @@ discard block |
||
| 1847 | 1847 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1848 | 1848 | }; |
| 1849 | 1849 | "; |
| 1850 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1851 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1850 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1851 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | # Criteres de comparaison |
@@ -1865,20 +1865,20 @@ discard block |
||
| 1865 | 1865 | * @return void|array |
| 1866 | 1866 | **/ |
| 1867 | 1867 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1868 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1869 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1870 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1871 | - } |
|
| 1872 | - |
|
| 1873 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1874 | - if (!$r) { |
|
| 1875 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1876 | - # if (!$crit->cond) { |
|
| 1877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1878 | - # } |
|
| 1879 | - } else { |
|
| 1880 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1881 | - } |
|
| 1868 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1869 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1870 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1871 | + } |
|
| 1872 | + |
|
| 1873 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1874 | + if (!$r) { |
|
| 1875 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1876 | + # if (!$crit->cond) { |
|
| 1877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1878 | + # } |
|
| 1879 | + } else { |
|
| 1880 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1881 | + } |
|
| 1882 | 1882 | } |
| 1883 | 1883 | |
| 1884 | 1884 | |
@@ -1898,62 +1898,62 @@ discard block |
||
| 1898 | 1898 | * @return void |
| 1899 | 1899 | **/ |
| 1900 | 1900 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1901 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1902 | - |
|
| 1903 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1904 | - |
|
| 1905 | - // inserer la negation (cf !...) |
|
| 1906 | - |
|
| 1907 | - if ($crit->not) { |
|
| 1908 | - $where = ["'NOT'", $where]; |
|
| 1909 | - } |
|
| 1910 | - if ($crit->exclus) { |
|
| 1911 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1912 | - $where = ["'NOT'", $where]; |
|
| 1913 | - } else { |
|
| 1914 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1915 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1916 | - $where = [ |
|
| 1917 | - "'NOT'", |
|
| 1918 | - [ |
|
| 1919 | - "'IN'", |
|
| 1920 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1922 | - ] |
|
| 1923 | - ]; |
|
| 1924 | - } |
|
| 1925 | - } |
|
| 1926 | - |
|
| 1927 | - // inserer la condition (cf {lang?}) |
|
| 1928 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1929 | - if ($crit->cond) { |
|
| 1930 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1931 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1932 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1933 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - |
|
| 1937 | - if ($op === '=' and !$crit->not) { |
|
| 1938 | - $where = [ |
|
| 1939 | - "'?'", |
|
| 1940 | - "(is_array($pred))", |
|
| 1941 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1942 | - $where |
|
| 1943 | - ]; |
|
| 1944 | - } |
|
| 1945 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1946 | - if ($where_complement) { |
|
| 1947 | - // condition annexe du type "AND (objet='article')" |
|
| 1948 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1949 | - } |
|
| 1950 | - } |
|
| 1951 | - |
|
| 1952 | - $boucles[$idb]->where[] = $where; |
|
| 1953 | - if ($where_complement) { |
|
| 1954 | - // condition annexe du type "AND (objet='article')" |
|
| 1955 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1956 | - } |
|
| 1901 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1902 | + |
|
| 1903 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1904 | + |
|
| 1905 | + // inserer la negation (cf !...) |
|
| 1906 | + |
|
| 1907 | + if ($crit->not) { |
|
| 1908 | + $where = ["'NOT'", $where]; |
|
| 1909 | + } |
|
| 1910 | + if ($crit->exclus) { |
|
| 1911 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1912 | + $where = ["'NOT'", $where]; |
|
| 1913 | + } else { |
|
| 1914 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1915 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1916 | + $where = [ |
|
| 1917 | + "'NOT'", |
|
| 1918 | + [ |
|
| 1919 | + "'IN'", |
|
| 1920 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1921 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1922 | + ] |
|
| 1923 | + ]; |
|
| 1924 | + } |
|
| 1925 | + } |
|
| 1926 | + |
|
| 1927 | + // inserer la condition (cf {lang?}) |
|
| 1928 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1929 | + if ($crit->cond) { |
|
| 1930 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1931 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1932 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1933 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + if ($op === '=' and !$crit->not) { |
|
| 1938 | + $where = [ |
|
| 1939 | + "'?'", |
|
| 1940 | + "(is_array($pred))", |
|
| 1941 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1942 | + $where |
|
| 1943 | + ]; |
|
| 1944 | + } |
|
| 1945 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1946 | + if ($where_complement) { |
|
| 1947 | + // condition annexe du type "AND (objet='article')" |
|
| 1948 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1949 | + } |
|
| 1950 | + } |
|
| 1951 | + |
|
| 1952 | + $boucles[$idb]->where[] = $where; |
|
| 1953 | + if ($where_complement) { |
|
| 1954 | + // condition annexe du type "AND (objet='article')" |
|
| 1955 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1956 | + } |
|
| 1957 | 1957 | } |
| 1958 | 1958 | |
| 1959 | 1959 | |
@@ -1994,165 +1994,165 @@ discard block |
||
| 1994 | 1994 | **/ |
| 1995 | 1995 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1996 | 1996 | |
| 1997 | - $boucle = &$boucles[$idb]; |
|
| 1998 | - $type = $boucle->type_requete; |
|
| 1999 | - $table = $boucle->id_table ?? ''; |
|
| 2000 | - $desc = $boucle->show; |
|
| 2001 | - $col_vraie = null; |
|
| 2002 | - |
|
| 2003 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2004 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2005 | - |
|
| 2006 | - $col_alias = $col; |
|
| 2007 | - $where_complement = false; |
|
| 2008 | - |
|
| 2009 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2010 | - if ($col == 'id_enfant') { |
|
| 2011 | - $col = $boucle->primary; |
|
| 2012 | - } |
|
| 2013 | - |
|
| 2014 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2015 | - if ( |
|
| 2016 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2017 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | - ) { |
|
| 2019 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2020 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2021 | - else { |
|
| 2022 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2023 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2024 | - } |
|
| 2025 | - |
|
| 2026 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2027 | - // sauf si exception declaree : sauter cette etape |
|
| 2028 | - else { |
|
| 2029 | - if ( |
|
| 2030 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2031 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2032 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2033 | - ) { |
|
| 2034 | - $e = decompose_champ_id_objet($col); |
|
| 2035 | - $col = array_shift($e); |
|
| 2036 | - $where_complement = primary_doublee($e, $table); |
|
| 2037 | - } // Cas particulier : expressions de date |
|
| 2038 | - else { |
|
| 2039 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2040 | - [$col, $col_vraie] = $c; |
|
| 2041 | - $table = ''; |
|
| 2042 | - } // table explicitée {mots.titre} |
|
| 2043 | - else { |
|
| 2044 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2045 | - [, $table, $col] = $r; |
|
| 2046 | - $col_alias = $col; |
|
| 2047 | - |
|
| 2048 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2049 | - if ( |
|
| 2050 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2051 | - and isset($desc['field'][$col]) |
|
| 2052 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2053 | - ) { |
|
| 2054 | - $table = $cle; |
|
| 2055 | - } else { |
|
| 2056 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2057 | - } |
|
| 2058 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2059 | - if (!$table) { |
|
| 2060 | - return ''; |
|
| 2061 | - } |
|
| 2062 | - } |
|
| 2063 | - // si le champ n'est pas trouvé dans la table, |
|
| 2064 | - // on cherche si une jointure peut l'obtenir |
|
| 2065 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2066 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2067 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2068 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2069 | - } |
|
| 2070 | - else { |
|
| 2071 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2072 | - if (!$r) { |
|
| 2073 | - return ''; |
|
| 2074 | - } |
|
| 2075 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2076 | - } |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - } |
|
| 2081 | - } |
|
| 2082 | - |
|
| 2083 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2084 | - // Dans tous les cas, |
|
| 2085 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2086 | - // et passer dans sql_quote avec le type si connu |
|
| 2087 | - // et int sinon si la valeur est numerique |
|
| 2088 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2089 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2090 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2091 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2092 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2093 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2094 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2095 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2096 | - } |
|
| 2097 | - // sinon expliciter les |
|
| 2098 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2099 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2100 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2101 | - // sans toucher aux |
|
| 2102 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2103 | - // sql_quote(truc,'','varchar') |
|
| 2104 | - elseif ( |
|
| 2105 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2106 | - // si pas deja un type |
|
| 2107 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2108 | - ) { |
|
| 2109 | - $r = $r[1] |
|
| 2110 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2111 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2112 | - $val[0] = "sql_quote($r)"; |
|
| 2113 | - } |
|
| 2114 | - elseif ( |
|
| 2115 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2116 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2117 | - ) { |
|
| 2118 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2119 | - } |
|
| 2120 | - } |
|
| 2121 | - |
|
| 2122 | - if ( |
|
| 2123 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2124 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2125 | - ) { |
|
| 2126 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2127 | - } |
|
| 2128 | - |
|
| 2129 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2130 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2131 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2132 | - if ($table === $boucle->id_table) { |
|
| 2133 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2134 | - if ($col_alias != $col_vraie) { |
|
| 2135 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2136 | - } |
|
| 2137 | - } |
|
| 2138 | - |
|
| 2139 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2140 | - if ($table) { |
|
| 2141 | - if ($col[0] == '`') { |
|
| 2142 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2143 | - } else { |
|
| 2144 | - $arg = "$table.$col"; |
|
| 2145 | - } |
|
| 2146 | - } else { |
|
| 2147 | - $arg = $col; |
|
| 2148 | - } |
|
| 2149 | - |
|
| 2150 | - // inserer la fonction SQL |
|
| 2151 | - if ($fct) { |
|
| 2152 | - $arg = "$fct($arg$args_sql)"; |
|
| 2153 | - } |
|
| 2154 | - |
|
| 2155 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 1997 | + $boucle = &$boucles[$idb]; |
|
| 1998 | + $type = $boucle->type_requete; |
|
| 1999 | + $table = $boucle->id_table ?? ''; |
|
| 2000 | + $desc = $boucle->show; |
|
| 2001 | + $col_vraie = null; |
|
| 2002 | + |
|
| 2003 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2004 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2005 | + |
|
| 2006 | + $col_alias = $col; |
|
| 2007 | + $where_complement = false; |
|
| 2008 | + |
|
| 2009 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2010 | + if ($col == 'id_enfant') { |
|
| 2011 | + $col = $boucle->primary; |
|
| 2012 | + } |
|
| 2013 | + |
|
| 2014 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2015 | + if ( |
|
| 2016 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2017 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | + ) { |
|
| 2019 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2020 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2021 | + else { |
|
| 2022 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2023 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2024 | + } |
|
| 2025 | + |
|
| 2026 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2027 | + // sauf si exception declaree : sauter cette etape |
|
| 2028 | + else { |
|
| 2029 | + if ( |
|
| 2030 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2031 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2032 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2033 | + ) { |
|
| 2034 | + $e = decompose_champ_id_objet($col); |
|
| 2035 | + $col = array_shift($e); |
|
| 2036 | + $where_complement = primary_doublee($e, $table); |
|
| 2037 | + } // Cas particulier : expressions de date |
|
| 2038 | + else { |
|
| 2039 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2040 | + [$col, $col_vraie] = $c; |
|
| 2041 | + $table = ''; |
|
| 2042 | + } // table explicitée {mots.titre} |
|
| 2043 | + else { |
|
| 2044 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2045 | + [, $table, $col] = $r; |
|
| 2046 | + $col_alias = $col; |
|
| 2047 | + |
|
| 2048 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2049 | + if ( |
|
| 2050 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2051 | + and isset($desc['field'][$col]) |
|
| 2052 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2053 | + ) { |
|
| 2054 | + $table = $cle; |
|
| 2055 | + } else { |
|
| 2056 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2057 | + } |
|
| 2058 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2059 | + if (!$table) { |
|
| 2060 | + return ''; |
|
| 2061 | + } |
|
| 2062 | + } |
|
| 2063 | + // si le champ n'est pas trouvé dans la table, |
|
| 2064 | + // on cherche si une jointure peut l'obtenir |
|
| 2065 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2066 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2067 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2068 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2069 | + } |
|
| 2070 | + else { |
|
| 2071 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2072 | + if (!$r) { |
|
| 2073 | + return ''; |
|
| 2074 | + } |
|
| 2075 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2076 | + } |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + } |
|
| 2081 | + } |
|
| 2082 | + |
|
| 2083 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2084 | + // Dans tous les cas, |
|
| 2085 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2086 | + // et passer dans sql_quote avec le type si connu |
|
| 2087 | + // et int sinon si la valeur est numerique |
|
| 2088 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2089 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2090 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2091 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2092 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2093 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2094 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2095 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2096 | + } |
|
| 2097 | + // sinon expliciter les |
|
| 2098 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2099 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2100 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2101 | + // sans toucher aux |
|
| 2102 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2103 | + // sql_quote(truc,'','varchar') |
|
| 2104 | + elseif ( |
|
| 2105 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2106 | + // si pas deja un type |
|
| 2107 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2108 | + ) { |
|
| 2109 | + $r = $r[1] |
|
| 2110 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2111 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2112 | + $val[0] = "sql_quote($r)"; |
|
| 2113 | + } |
|
| 2114 | + elseif ( |
|
| 2115 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2116 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2117 | + ) { |
|
| 2118 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2119 | + } |
|
| 2120 | + } |
|
| 2121 | + |
|
| 2122 | + if ( |
|
| 2123 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2124 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2125 | + ) { |
|
| 2126 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2127 | + } |
|
| 2128 | + |
|
| 2129 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2130 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2131 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2132 | + if ($table === $boucle->id_table) { |
|
| 2133 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2134 | + if ($col_alias != $col_vraie) { |
|
| 2135 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2136 | + } |
|
| 2137 | + } |
|
| 2138 | + |
|
| 2139 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2140 | + if ($table) { |
|
| 2141 | + if ($col[0] == '`') { |
|
| 2142 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2143 | + } else { |
|
| 2144 | + $arg = "$table.$col"; |
|
| 2145 | + } |
|
| 2146 | + } else { |
|
| 2147 | + $arg = $col; |
|
| 2148 | + } |
|
| 2149 | + |
|
| 2150 | + // inserer la fonction SQL |
|
| 2151 | + if ($fct) { |
|
| 2152 | + $arg = "$fct($arg$args_sql)"; |
|
| 2153 | + } |
|
| 2154 | + |
|
| 2155 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2156 | 2156 | } |
| 2157 | 2157 | |
| 2158 | 2158 | |
@@ -2181,77 +2181,77 @@ discard block |
||
| 2181 | 2181 | **/ |
| 2182 | 2182 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2183 | 2183 | |
| 2184 | - $where = ''; |
|
| 2185 | - |
|
| 2186 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2187 | - // gestion par les plugins des jointures tordues |
|
| 2188 | - // pas automatiques mais necessaires |
|
| 2189 | - $table_sql = table_objet_sql($table); |
|
| 2190 | - if ( |
|
| 2191 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2192 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | - and |
|
| 2194 | - ( |
|
| 2195 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2196 | - or |
|
| 2197 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2198 | - ) |
|
| 2199 | - ) { |
|
| 2200 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2201 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2202 | - |
|
| 2203 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2204 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2205 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2206 | - [$t, $col] = $t[$col]; |
|
| 2207 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2208 | - [$calculer_critere_externe] = $index; |
|
| 2209 | - $t = $table; |
|
| 2210 | - } else { |
|
| 2211 | - $t = ''; |
|
| 2212 | - } // jointure non declaree. La trouver. |
|
| 2213 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2214 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2215 | - } else { |
|
| 2216 | - $t = ''; |
|
| 2217 | - } // jointure non declaree. La trouver. |
|
| 2218 | - |
|
| 2219 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2220 | - |
|
| 2221 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2222 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2223 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2224 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2225 | - $table = ''; |
|
| 2226 | - if ($boucle->jointures_explicites) { |
|
| 2227 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2228 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2229 | - } |
|
| 2230 | - |
|
| 2231 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2232 | - if (!$table) { |
|
| 2233 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2234 | - } |
|
| 2235 | - |
|
| 2236 | - if (!$table) { |
|
| 2237 | - return ''; |
|
| 2238 | - } |
|
| 2239 | - |
|
| 2240 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2241 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2242 | - |
|
| 2243 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2244 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2245 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2246 | - $e = decompose_champ_id_objet($col); |
|
| 2247 | - $col = array_shift($e); |
|
| 2248 | - $where = primary_doublee($e, $table); |
|
| 2249 | - } else { |
|
| 2250 | - $col = reset($cle); |
|
| 2251 | - } |
|
| 2252 | - } |
|
| 2253 | - |
|
| 2254 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2184 | + $where = ''; |
|
| 2185 | + |
|
| 2186 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2187 | + // gestion par les plugins des jointures tordues |
|
| 2188 | + // pas automatiques mais necessaires |
|
| 2189 | + $table_sql = table_objet_sql($table); |
|
| 2190 | + if ( |
|
| 2191 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2192 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | + and |
|
| 2194 | + ( |
|
| 2195 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2196 | + or |
|
| 2197 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2198 | + ) |
|
| 2199 | + ) { |
|
| 2200 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2201 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2202 | + |
|
| 2203 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2204 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2205 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2206 | + [$t, $col] = $t[$col]; |
|
| 2207 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2208 | + [$calculer_critere_externe] = $index; |
|
| 2209 | + $t = $table; |
|
| 2210 | + } else { |
|
| 2211 | + $t = ''; |
|
| 2212 | + } // jointure non declaree. La trouver. |
|
| 2213 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2214 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2215 | + } else { |
|
| 2216 | + $t = ''; |
|
| 2217 | + } // jointure non declaree. La trouver. |
|
| 2218 | + |
|
| 2219 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2220 | + |
|
| 2221 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2222 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2223 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2224 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2225 | + $table = ''; |
|
| 2226 | + if ($boucle->jointures_explicites) { |
|
| 2227 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2228 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2229 | + } |
|
| 2230 | + |
|
| 2231 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2232 | + if (!$table) { |
|
| 2233 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2234 | + } |
|
| 2235 | + |
|
| 2236 | + if (!$table) { |
|
| 2237 | + return ''; |
|
| 2238 | + } |
|
| 2239 | + |
|
| 2240 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2241 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2242 | + |
|
| 2243 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2244 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2245 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2246 | + $e = decompose_champ_id_objet($col); |
|
| 2247 | + $col = array_shift($e); |
|
| 2248 | + $where = primary_doublee($e, $table); |
|
| 2249 | + } else { |
|
| 2250 | + $col = reset($cle); |
|
| 2251 | + } |
|
| 2252 | + } |
|
| 2253 | + |
|
| 2254 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2255 | 2255 | } |
| 2256 | 2256 | |
| 2257 | 2257 | |
@@ -2272,10 +2272,10 @@ discard block |
||
| 2272 | 2272 | * - valeur |
| 2273 | 2273 | **/ |
| 2274 | 2274 | function primary_doublee($decompose, $table) { |
| 2275 | - $e1 = reset($decompose); |
|
| 2276 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2275 | + $e1 = reset($decompose); |
|
| 2276 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2277 | 2277 | |
| 2278 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2278 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2279 | 2279 | } |
| 2280 | 2280 | |
| 2281 | 2281 | /** |
@@ -2306,57 +2306,57 @@ discard block |
||
| 2306 | 2306 | * Vide sinon. |
| 2307 | 2307 | */ |
| 2308 | 2308 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2309 | - // si on demande un truc du genre spip_mots |
|
| 2310 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2311 | - // et qu'on est la |
|
| 2312 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2313 | - if ( |
|
| 2314 | - $checkarrivee |
|
| 2315 | - and is_string($checkarrivee) |
|
| 2316 | - and $a = table_objet($checkarrivee) |
|
| 2317 | - and in_array($a . '_liens', $joints) |
|
| 2318 | - ) { |
|
| 2319 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2320 | - return $res; |
|
| 2321 | - } |
|
| 2322 | - } |
|
| 2323 | - foreach ($joints as $joint) { |
|
| 2324 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2325 | - // alias de table dans le from |
|
| 2326 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2327 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2328 | - $cols = $arrivee[2]; |
|
| 2329 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2330 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2331 | - array_pop($cols); |
|
| 2332 | - } |
|
| 2333 | - if ($t) { |
|
| 2334 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2335 | - $joindre = false; |
|
| 2336 | - foreach ($cols as $col) { |
|
| 2337 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2338 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2339 | - $joindre = true; |
|
| 2340 | - } else { |
|
| 2341 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2342 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2343 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2344 | - $joindre = true; |
|
| 2345 | - } |
|
| 2346 | - } |
|
| 2347 | - } |
|
| 2348 | - if (!$joindre) { |
|
| 2349 | - return $t; |
|
| 2350 | - } |
|
| 2351 | - } |
|
| 2352 | - array_pop($arrivee); |
|
| 2353 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2354 | - return $res; |
|
| 2355 | - } |
|
| 2356 | - } |
|
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - return ''; |
|
| 2309 | + // si on demande un truc du genre spip_mots |
|
| 2310 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2311 | + // et qu'on est la |
|
| 2312 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2313 | + if ( |
|
| 2314 | + $checkarrivee |
|
| 2315 | + and is_string($checkarrivee) |
|
| 2316 | + and $a = table_objet($checkarrivee) |
|
| 2317 | + and in_array($a . '_liens', $joints) |
|
| 2318 | + ) { |
|
| 2319 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2320 | + return $res; |
|
| 2321 | + } |
|
| 2322 | + } |
|
| 2323 | + foreach ($joints as $joint) { |
|
| 2324 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2325 | + // alias de table dans le from |
|
| 2326 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2327 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2328 | + $cols = $arrivee[2]; |
|
| 2329 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2330 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2331 | + array_pop($cols); |
|
| 2332 | + } |
|
| 2333 | + if ($t) { |
|
| 2334 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2335 | + $joindre = false; |
|
| 2336 | + foreach ($cols as $col) { |
|
| 2337 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2338 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2339 | + $joindre = true; |
|
| 2340 | + } else { |
|
| 2341 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2342 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2343 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2344 | + $joindre = true; |
|
| 2345 | + } |
|
| 2346 | + } |
|
| 2347 | + } |
|
| 2348 | + if (!$joindre) { |
|
| 2349 | + return $t; |
|
| 2350 | + } |
|
| 2351 | + } |
|
| 2352 | + array_pop($arrivee); |
|
| 2353 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2354 | + return $res; |
|
| 2355 | + } |
|
| 2356 | + } |
|
| 2357 | + } |
|
| 2358 | + |
|
| 2359 | + return ''; |
|
| 2360 | 2360 | } |
| 2361 | 2361 | |
| 2362 | 2362 | /** |
@@ -2382,35 +2382,35 @@ discard block |
||
| 2382 | 2382 | * Alias de la table de jointure (Lx) |
| 2383 | 2383 | */ |
| 2384 | 2384 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2385 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2386 | - |
|
| 2387 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2388 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2389 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2390 | - |
|
| 2391 | - if (!$intermediaire or !$arrivee) { |
|
| 2392 | - return ''; |
|
| 2393 | - } |
|
| 2394 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2395 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2396 | - |
|
| 2397 | - $res = fabrique_jointures( |
|
| 2398 | - $boucle, |
|
| 2399 | - [ |
|
| 2400 | - [ |
|
| 2401 | - $boucle->id_table, |
|
| 2402 | - $intermediaire, |
|
| 2403 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2404 | - ], |
|
| 2405 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2406 | - ], |
|
| 2407 | - $cond, |
|
| 2408 | - $desc, |
|
| 2409 | - $boucle->id_table, |
|
| 2410 | - [$col] |
|
| 2411 | - ); |
|
| 2412 | - |
|
| 2413 | - return $res; |
|
| 2385 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2386 | + |
|
| 2387 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2388 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2389 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2390 | + |
|
| 2391 | + if (!$intermediaire or !$arrivee) { |
|
| 2392 | + return ''; |
|
| 2393 | + } |
|
| 2394 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2395 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2396 | + |
|
| 2397 | + $res = fabrique_jointures( |
|
| 2398 | + $boucle, |
|
| 2399 | + [ |
|
| 2400 | + [ |
|
| 2401 | + $boucle->id_table, |
|
| 2402 | + $intermediaire, |
|
| 2403 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2404 | + ], |
|
| 2405 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2406 | + ], |
|
| 2407 | + $cond, |
|
| 2408 | + $desc, |
|
| 2409 | + $boucle->id_table, |
|
| 2410 | + [$col] |
|
| 2411 | + ); |
|
| 2412 | + |
|
| 2413 | + return $res; |
|
| 2414 | 2414 | } |
| 2415 | 2415 | |
| 2416 | 2416 | |
@@ -2427,17 +2427,17 @@ discard block |
||
| 2427 | 2427 | * false sinon. |
| 2428 | 2428 | **/ |
| 2429 | 2429 | function trouver_champ($champ, $where) { |
| 2430 | - if (!is_array($where)) { |
|
| 2431 | - return preg_match($champ, $where); |
|
| 2432 | - } else { |
|
| 2433 | - foreach ($where as $clause) { |
|
| 2434 | - if (trouver_champ($champ, $clause)) { |
|
| 2435 | - return true; |
|
| 2436 | - } |
|
| 2437 | - } |
|
| 2438 | - |
|
| 2439 | - return false; |
|
| 2440 | - } |
|
| 2430 | + if (!is_array($where)) { |
|
| 2431 | + return preg_match($champ, $where); |
|
| 2432 | + } else { |
|
| 2433 | + foreach ($where as $clause) { |
|
| 2434 | + if (trouver_champ($champ, $clause)) { |
|
| 2435 | + return true; |
|
| 2436 | + } |
|
| 2437 | + } |
|
| 2438 | + |
|
| 2439 | + return false; |
|
| 2440 | + } |
|
| 2441 | 2441 | } |
| 2442 | 2442 | |
| 2443 | 2443 | |
@@ -2463,129 +2463,129 @@ discard block |
||
| 2463 | 2463 | * - string $args_sql Suite des arguments du critère. ? |
| 2464 | 2464 | **/ |
| 2465 | 2465 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2466 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2467 | - if (count($crit->param) == 0) { |
|
| 2468 | - $op = '='; |
|
| 2469 | - $col = $val = $crit->op; |
|
| 2470 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2471 | - $val = $r[2]; |
|
| 2472 | - } |
|
| 2473 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2474 | - if ($val == 'lang') { |
|
| 2475 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2476 | - } else { |
|
| 2477 | - $defaut = null; |
|
| 2478 | - if ($val == 'id_parent') { |
|
| 2479 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2480 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2481 | - // pour eviter l'erreur SQL |
|
| 2482 | - $val = $boucles[$idb]->primary; |
|
| 2483 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2484 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2485 | - } elseif ($val == 'id_enfant') { |
|
| 2486 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2487 | - // de la boucle superieure |
|
| 2488 | - $val = 'id_parent'; |
|
| 2489 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2490 | - // un critere conditionnel sur date est traite a part |
|
| 2491 | - // car la date est mise d'office par SPIP, |
|
| 2492 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2493 | - } |
|
| 2494 | - |
|
| 2495 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2496 | - $val = [kwote($val)]; |
|
| 2497 | - } |
|
| 2498 | - } else { |
|
| 2499 | - // comparaison explicite |
|
| 2500 | - // le phraseur impose que le premier param soit du texte |
|
| 2501 | - $params = $crit->param; |
|
| 2502 | - $op = $crit->op; |
|
| 2503 | - if ($op == '==') { |
|
| 2504 | - $op = 'REGEXP'; |
|
| 2505 | - } |
|
| 2506 | - $col = array_shift($params); |
|
| 2507 | - $col = $col[0]->texte; |
|
| 2508 | - |
|
| 2509 | - $val = []; |
|
| 2510 | - $parent = $boucles[$idb]->id_parent; |
|
| 2511 | - |
|
| 2512 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2513 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2514 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2515 | - if ( |
|
| 2516 | - count($params) == 1 |
|
| 2517 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2518 | - and $params[0][0]->type == 'texte' |
|
| 2519 | - and $params[0][2]->type == 'texte' |
|
| 2520 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2521 | - and (($p == "'") or ($p == '"')) |
|
| 2522 | - and $params[0][1]->type == 'champ' |
|
| 2523 | - ) { |
|
| 2524 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2525 | - } else { |
|
| 2526 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2527 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2528 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2529 | - $val[] = $a; |
|
| 2530 | - } else { |
|
| 2531 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2532 | - } // toujours quoter en char ici |
|
| 2533 | - } |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - |
|
| 2537 | - $fct = $args_sql = ''; |
|
| 2538 | - // fonction SQL ? |
|
| 2539 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2540 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2541 | - $fct = $m[1]; |
|
| 2542 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2543 | - $col = $a[1]; |
|
| 2544 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2545 | - $col = $m[1]; |
|
| 2546 | - $args_sql = $m[2]; |
|
| 2547 | - } |
|
| 2548 | - $args_sql .= $a[2]; |
|
| 2549 | - } |
|
| 2550 | - |
|
| 2551 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2466 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2467 | + if (count($crit->param) == 0) { |
|
| 2468 | + $op = '='; |
|
| 2469 | + $col = $val = $crit->op; |
|
| 2470 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2471 | + $val = $r[2]; |
|
| 2472 | + } |
|
| 2473 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2474 | + if ($val == 'lang') { |
|
| 2475 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2476 | + } else { |
|
| 2477 | + $defaut = null; |
|
| 2478 | + if ($val == 'id_parent') { |
|
| 2479 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2480 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2481 | + // pour eviter l'erreur SQL |
|
| 2482 | + $val = $boucles[$idb]->primary; |
|
| 2483 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2484 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2485 | + } elseif ($val == 'id_enfant') { |
|
| 2486 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2487 | + // de la boucle superieure |
|
| 2488 | + $val = 'id_parent'; |
|
| 2489 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2490 | + // un critere conditionnel sur date est traite a part |
|
| 2491 | + // car la date est mise d'office par SPIP, |
|
| 2492 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2493 | + } |
|
| 2494 | + |
|
| 2495 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2496 | + $val = [kwote($val)]; |
|
| 2497 | + } |
|
| 2498 | + } else { |
|
| 2499 | + // comparaison explicite |
|
| 2500 | + // le phraseur impose que le premier param soit du texte |
|
| 2501 | + $params = $crit->param; |
|
| 2502 | + $op = $crit->op; |
|
| 2503 | + if ($op == '==') { |
|
| 2504 | + $op = 'REGEXP'; |
|
| 2505 | + } |
|
| 2506 | + $col = array_shift($params); |
|
| 2507 | + $col = $col[0]->texte; |
|
| 2508 | + |
|
| 2509 | + $val = []; |
|
| 2510 | + $parent = $boucles[$idb]->id_parent; |
|
| 2511 | + |
|
| 2512 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2513 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2514 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2515 | + if ( |
|
| 2516 | + count($params) == 1 |
|
| 2517 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2518 | + and $params[0][0]->type == 'texte' |
|
| 2519 | + and $params[0][2]->type == 'texte' |
|
| 2520 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2521 | + and (($p == "'") or ($p == '"')) |
|
| 2522 | + and $params[0][1]->type == 'champ' |
|
| 2523 | + ) { |
|
| 2524 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2525 | + } else { |
|
| 2526 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2527 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2528 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2529 | + $val[] = $a; |
|
| 2530 | + } else { |
|
| 2531 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2532 | + } // toujours quoter en char ici |
|
| 2533 | + } |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + |
|
| 2537 | + $fct = $args_sql = ''; |
|
| 2538 | + // fonction SQL ? |
|
| 2539 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2540 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2541 | + $fct = $m[1]; |
|
| 2542 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2543 | + $col = $a[1]; |
|
| 2544 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2545 | + $col = $m[1]; |
|
| 2546 | + $args_sql = $m[2]; |
|
| 2547 | + } |
|
| 2548 | + $args_sql .= $a[2]; |
|
| 2549 | + } |
|
| 2550 | + |
|
| 2551 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2552 | 2552 | } |
| 2553 | 2553 | |
| 2554 | 2554 | // compatibilite ancienne version |
| 2555 | 2555 | |
| 2556 | 2556 | function calculer_vieux_in($params) { |
| 2557 | - $deb = $params[0][0]; |
|
| 2558 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2559 | - $last = $params[$k]; |
|
| 2560 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2561 | - $last = $last[$j]; |
|
| 2562 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2563 | - |
|
| 2564 | - if ( |
|
| 2565 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2566 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2567 | - ) { |
|
| 2568 | - return $params; |
|
| 2569 | - } |
|
| 2570 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2571 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2572 | - $last = $params[$k][$j]; |
|
| 2573 | - $n = strlen($last->texte); |
|
| 2574 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2575 | - $newp = []; |
|
| 2576 | - foreach ($params as $v) { |
|
| 2577 | - if ($v[0]->type != 'texte') { |
|
| 2578 | - $newp[] = $v; |
|
| 2579 | - } else { |
|
| 2580 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2581 | - $t = new Texte(); |
|
| 2582 | - $t->texte = $x; |
|
| 2583 | - $newp[] = [$t]; |
|
| 2584 | - } |
|
| 2585 | - } |
|
| 2586 | - } |
|
| 2587 | - |
|
| 2588 | - return $newp; |
|
| 2557 | + $deb = $params[0][0]; |
|
| 2558 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2559 | + $last = $params[$k]; |
|
| 2560 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2561 | + $last = $last[$j]; |
|
| 2562 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2563 | + |
|
| 2564 | + if ( |
|
| 2565 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2566 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2567 | + ) { |
|
| 2568 | + return $params; |
|
| 2569 | + } |
|
| 2570 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2571 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2572 | + $last = $params[$k][$j]; |
|
| 2573 | + $n = strlen($last->texte); |
|
| 2574 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2575 | + $newp = []; |
|
| 2576 | + foreach ($params as $v) { |
|
| 2577 | + if ($v[0]->type != 'texte') { |
|
| 2578 | + $newp[] = $v; |
|
| 2579 | + } else { |
|
| 2580 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2581 | + $t = new Texte(); |
|
| 2582 | + $t->texte = $x; |
|
| 2583 | + $newp[] = [$t]; |
|
| 2584 | + } |
|
| 2585 | + } |
|
| 2586 | + } |
|
| 2587 | + |
|
| 2588 | + return $newp; |
|
| 2589 | 2589 | } |
| 2590 | 2590 | |
| 2591 | 2591 | /** |
@@ -2604,89 +2604,89 @@ discard block |
||
| 2604 | 2604 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2605 | 2605 | **/ |
| 2606 | 2606 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2607 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2608 | - return ''; |
|
| 2609 | - } |
|
| 2610 | - |
|
| 2611 | - $boucle = $boucles[$idb]; |
|
| 2612 | - $table = $boucle->show; |
|
| 2613 | - |
|
| 2614 | - // si c'est une colonne de la table, ne rien faire |
|
| 2615 | - if (isset($table['field'][$col])) { |
|
| 2616 | - return ''; |
|
| 2617 | - } |
|
| 2618 | - |
|
| 2619 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2620 | - return ''; |
|
| 2621 | - } |
|
| 2622 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2623 | - |
|
| 2624 | - $col = $regs[1]; |
|
| 2625 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2626 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2627 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2628 | - |
|
| 2629 | - if (isset($table['field']["date$suite"])) { |
|
| 2630 | - $date_orig = 'date' . $suite; |
|
| 2631 | - } else { |
|
| 2632 | - $date_orig = substr($suite, 1); |
|
| 2633 | - } |
|
| 2634 | - $pred = $date_orig; |
|
| 2635 | - } else { |
|
| 2636 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2637 | - $pred = 'date'; |
|
| 2638 | - } |
|
| 2639 | - } |
|
| 2640 | - |
|
| 2641 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2643 | - ") . '\""; |
|
| 2644 | - |
|
| 2645 | - $col_vraie = $date_orig; |
|
| 2646 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2647 | - |
|
| 2648 | - switch ($col) { |
|
| 2649 | - case 'date': |
|
| 2650 | - $col = $date_orig; |
|
| 2651 | - break; |
|
| 2652 | - case 'jour': |
|
| 2653 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2654 | - break; |
|
| 2655 | - case 'mois': |
|
| 2656 | - $col = "MONTH($date_orig)"; |
|
| 2657 | - break; |
|
| 2658 | - case 'annee': |
|
| 2659 | - $col = "YEAR($date_orig)"; |
|
| 2660 | - break; |
|
| 2661 | - case 'heure': |
|
| 2662 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2663 | - break; |
|
| 2664 | - case 'age': |
|
| 2665 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2666 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2667 | - break; |
|
| 2668 | - case 'age_relatif': |
|
| 2669 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2670 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | - break; |
|
| 2672 | - case 'jour_relatif': |
|
| 2673 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | - break; |
|
| 2676 | - case 'mois_relatif': |
|
| 2677 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | - break; |
|
| 2682 | - case 'annee_relatif': |
|
| 2683 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | - $date_orig . ')'; |
|
| 2685 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | - break; |
|
| 2687 | - } |
|
| 2688 | - |
|
| 2689 | - return [$col, $col_vraie]; |
|
| 2607 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2608 | + return ''; |
|
| 2609 | + } |
|
| 2610 | + |
|
| 2611 | + $boucle = $boucles[$idb]; |
|
| 2612 | + $table = $boucle->show; |
|
| 2613 | + |
|
| 2614 | + // si c'est une colonne de la table, ne rien faire |
|
| 2615 | + if (isset($table['field'][$col])) { |
|
| 2616 | + return ''; |
|
| 2617 | + } |
|
| 2618 | + |
|
| 2619 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2620 | + return ''; |
|
| 2621 | + } |
|
| 2622 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2623 | + |
|
| 2624 | + $col = $regs[1]; |
|
| 2625 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2626 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2627 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2628 | + |
|
| 2629 | + if (isset($table['field']["date$suite"])) { |
|
| 2630 | + $date_orig = 'date' . $suite; |
|
| 2631 | + } else { |
|
| 2632 | + $date_orig = substr($suite, 1); |
|
| 2633 | + } |
|
| 2634 | + $pred = $date_orig; |
|
| 2635 | + } else { |
|
| 2636 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2637 | + $pred = 'date'; |
|
| 2638 | + } |
|
| 2639 | + } |
|
| 2640 | + |
|
| 2641 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2642 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2643 | + ") . '\""; |
|
| 2644 | + |
|
| 2645 | + $col_vraie = $date_orig; |
|
| 2646 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2647 | + |
|
| 2648 | + switch ($col) { |
|
| 2649 | + case 'date': |
|
| 2650 | + $col = $date_orig; |
|
| 2651 | + break; |
|
| 2652 | + case 'jour': |
|
| 2653 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2654 | + break; |
|
| 2655 | + case 'mois': |
|
| 2656 | + $col = "MONTH($date_orig)"; |
|
| 2657 | + break; |
|
| 2658 | + case 'annee': |
|
| 2659 | + $col = "YEAR($date_orig)"; |
|
| 2660 | + break; |
|
| 2661 | + case 'heure': |
|
| 2662 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2663 | + break; |
|
| 2664 | + case 'age': |
|
| 2665 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2666 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2667 | + break; |
|
| 2668 | + case 'age_relatif': |
|
| 2669 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2670 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2671 | + break; |
|
| 2672 | + case 'jour_relatif': |
|
| 2673 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2674 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2675 | + break; |
|
| 2676 | + case 'mois_relatif': |
|
| 2677 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2678 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2679 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2680 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2681 | + break; |
|
| 2682 | + case 'annee_relatif': |
|
| 2683 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2684 | + $date_orig . ')'; |
|
| 2685 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2686 | + break; |
|
| 2687 | + } |
|
| 2688 | + |
|
| 2689 | + return [$col, $col_vraie]; |
|
| 2690 | 2690 | } |
| 2691 | 2691 | |
| 2692 | 2692 | /** |
@@ -2705,16 +2705,16 @@ discard block |
||
| 2705 | 2705 | * de colonne SQL et une date. |
| 2706 | 2706 | **/ |
| 2707 | 2707 | function calculer_param_date($date_compare, $date_orig) { |
| 2708 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2709 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2710 | - $date_compare = '\'$x\''; |
|
| 2711 | - } else { |
|
| 2712 | - $init = $date_compare; |
|
| 2713 | - } |
|
| 2714 | - |
|
| 2715 | - return |
|
| 2716 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2717 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2708 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2709 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2710 | + $date_compare = '\'$x\''; |
|
| 2711 | + } else { |
|
| 2712 | + $init = $date_compare; |
|
| 2713 | + } |
|
| 2714 | + |
|
| 2715 | + return |
|
| 2716 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2717 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2718 | 2718 | } |
| 2719 | 2719 | |
| 2720 | 2720 | /** |
@@ -2732,20 +2732,20 @@ discard block |
||
| 2732 | 2732 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2733 | 2733 | */ |
| 2734 | 2734 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2735 | - $boucle = &$boucles[$idb]; |
|
| 2736 | - |
|
| 2737 | - $args = []; |
|
| 2738 | - foreach ($crit->param as &$param) { |
|
| 2739 | - array_push( |
|
| 2740 | - $args, |
|
| 2741 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2742 | - ); |
|
| 2743 | - } |
|
| 2735 | + $boucle = &$boucles[$idb]; |
|
| 2744 | 2736 | |
| 2745 | - $boucle->hash .= ' |
|
| 2737 | + $args = []; |
|
| 2738 | + foreach ($crit->param as &$param) { |
|
| 2739 | + array_push( |
|
| 2740 | + $args, |
|
| 2741 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2742 | + ); |
|
| 2743 | + } |
|
| 2744 | + |
|
| 2745 | + $boucle->hash .= ' |
|
| 2746 | 2746 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2747 | 2747 | |
| 2748 | - $boucle->hash .= ' |
|
| 2748 | + $boucle->hash .= ' |
|
| 2749 | 2749 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2750 | 2750 | } |
| 2751 | 2751 | |
@@ -2763,8 +2763,8 @@ discard block |
||
| 2763 | 2763 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2764 | 2764 | */ |
| 2765 | 2765 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2766 | - $boucle = &$boucles[$idb]; |
|
| 2767 | - $boucle->hash .= ' |
|
| 2766 | + $boucle = &$boucles[$idb]; |
|
| 2767 | + $boucle->hash .= ' |
|
| 2768 | 2768 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2769 | 2769 | } |
| 2770 | 2770 | |
@@ -2780,12 +2780,12 @@ discard block |
||
| 2780 | 2780 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2781 | 2781 | */ |
| 2782 | 2782 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2783 | - $boucle = &$boucles[$idb]; |
|
| 2784 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2785 | - foreach ($crit->param as $param) { |
|
| 2786 | - $boucle->hash .= ' |
|
| 2783 | + $boucle = &$boucles[$idb]; |
|
| 2784 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2785 | + foreach ($crit->param as $param) { |
|
| 2786 | + $boucle->hash .= ' |
|
| 2787 | 2787 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2788 | - } |
|
| 2788 | + } |
|
| 2789 | 2789 | } |
| 2790 | 2790 | |
| 2791 | 2791 | /** |
@@ -2802,16 +2802,16 @@ discard block |
||
| 2802 | 2802 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2803 | 2803 | */ |
| 2804 | 2804 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2805 | - $boucle = &$boucles[$idb]; |
|
| 2806 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2807 | - foreach ($crit->param as $param) { |
|
| 2808 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2809 | - $param, |
|
| 2810 | - $idb, |
|
| 2811 | - $boucles, |
|
| 2812 | - $boucles[$idb]->id_parent |
|
| 2813 | - ) . ";\n"; |
|
| 2814 | - } |
|
| 2805 | + $boucle = &$boucles[$idb]; |
|
| 2806 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2807 | + foreach ($crit->param as $param) { |
|
| 2808 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2809 | + $param, |
|
| 2810 | + $idb, |
|
| 2811 | + $boucles, |
|
| 2812 | + $boucles[$idb]->id_parent |
|
| 2813 | + ) . ";\n"; |
|
| 2814 | + } |
|
| 2815 | 2815 | } |
| 2816 | 2816 | |
| 2817 | 2817 | /** |
@@ -2836,16 +2836,16 @@ discard block |
||
| 2836 | 2836 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2837 | 2837 | */ |
| 2838 | 2838 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2839 | - $boucle = &$boucles[$idb]; |
|
| 2840 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2841 | - foreach ($crit->param as $param) { |
|
| 2842 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2843 | - $param, |
|
| 2844 | - $idb, |
|
| 2845 | - $boucles, |
|
| 2846 | - $boucles[$idb]->id_parent |
|
| 2847 | - ) . ";\n"; |
|
| 2848 | - } |
|
| 2839 | + $boucle = &$boucles[$idb]; |
|
| 2840 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2841 | + foreach ($crit->param as $param) { |
|
| 2842 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2843 | + $param, |
|
| 2844 | + $idb, |
|
| 2845 | + $boucles, |
|
| 2846 | + $boucles[$idb]->id_parent |
|
| 2847 | + ) . ";\n"; |
|
| 2848 | + } |
|
| 2849 | 2849 | } |
| 2850 | 2850 | |
| 2851 | 2851 | /** |
@@ -2860,11 +2860,11 @@ discard block |
||
| 2860 | 2860 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2861 | 2861 | */ |
| 2862 | 2862 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2863 | - $boucle = &$boucles[$idb]; |
|
| 2864 | - foreach ($crit->param as $param) { |
|
| 2865 | - $boucle->hash .= ' |
|
| 2863 | + $boucle = &$boucles[$idb]; |
|
| 2864 | + foreach ($crit->param as $param) { |
|
| 2865 | + $boucle->hash .= ' |
|
| 2866 | 2866 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2867 | - } |
|
| 2867 | + } |
|
| 2868 | 2868 | } |
| 2869 | 2869 | |
| 2870 | 2870 | |
@@ -2896,20 +2896,20 @@ discard block |
||
| 2896 | 2896 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2897 | 2897 | */ |
| 2898 | 2898 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2899 | - $boucle = &$boucles[$idb]; |
|
| 2900 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2901 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2902 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2903 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2904 | - if ($crit->param) { |
|
| 2905 | - foreach ($crit->param as $param) { |
|
| 2906 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2907 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2908 | - } |
|
| 2909 | - // interdire {si 0} aussi ! |
|
| 2910 | - } else { |
|
| 2911 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2912 | - } |
|
| 2899 | + $boucle = &$boucles[$idb]; |
|
| 2900 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2901 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2902 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2903 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2904 | + if ($crit->param) { |
|
| 2905 | + foreach ($crit->param as $param) { |
|
| 2906 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2907 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2908 | + } |
|
| 2909 | + // interdire {si 0} aussi ! |
|
| 2910 | + } else { |
|
| 2911 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2912 | + } |
|
| 2913 | 2913 | } |
| 2914 | 2914 | |
| 2915 | 2915 | /** |
@@ -2926,8 +2926,8 @@ discard block |
||
| 2926 | 2926 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2927 | 2927 | */ |
| 2928 | 2928 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2929 | - $boucle = &$boucles[$idb]; |
|
| 2930 | - $boucle->hash .= ' |
|
| 2929 | + $boucle = &$boucles[$idb]; |
|
| 2930 | + $boucle->hash .= ' |
|
| 2931 | 2931 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2932 | 2932 | $command[\'sourcemode\'] = \'table\';'; |
| 2933 | 2933 | } |
@@ -2948,27 +2948,27 @@ discard block |
||
| 2948 | 2948 | */ |
| 2949 | 2949 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2950 | 2950 | |
| 2951 | - $not = $crit->not; |
|
| 2952 | - $boucle = &$boucles[$idb]; |
|
| 2953 | - $primary = $boucle->primary; |
|
| 2951 | + $not = $crit->not; |
|
| 2952 | + $boucle = &$boucles[$idb]; |
|
| 2953 | + $primary = $boucle->primary; |
|
| 2954 | 2954 | |
| 2955 | - if (!$primary or strpos($primary, ',')) { |
|
| 2956 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2955 | + if (!$primary or strpos($primary, ',')) { |
|
| 2956 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2957 | 2957 | |
| 2958 | - return; |
|
| 2959 | - } |
|
| 2960 | - $table = $boucle->type_requete; |
|
| 2961 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2958 | + return; |
|
| 2959 | + } |
|
| 2960 | + $table = $boucle->type_requete; |
|
| 2961 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2962 | 2962 | |
| 2963 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2963 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2964 | 2964 | |
| 2965 | - $in = 'IN'; |
|
| 2966 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | - if ($not) { |
|
| 2968 | - $where = ["'NOT'", $where]; |
|
| 2969 | - } |
|
| 2965 | + $in = 'IN'; |
|
| 2966 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2967 | + if ($not) { |
|
| 2968 | + $where = ["'NOT'", $where]; |
|
| 2969 | + } |
|
| 2970 | 2970 | |
| 2971 | - $boucle->where[] = $where; |
|
| 2971 | + $boucle->where[] = $where; |
|
| 2972 | 2972 | } |
| 2973 | 2973 | |
| 2974 | 2974 | /** |
@@ -2984,8 +2984,8 @@ discard block |
||
| 2984 | 2984 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2985 | 2985 | */ |
| 2986 | 2986 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2987 | - $not = $crit->not; |
|
| 2988 | - $crit->not = $not ? false : true; |
|
| 2989 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2990 | - $crit->not = $not; |
|
| 2987 | + $not = $crit->not; |
|
| 2988 | + $crit->not = $not ? false : true; |
|
| 2989 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2990 | + $crit->not = $not; |
|
| 2991 | 2991 | } |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -52,75 +52,75 @@ discard block |
||
| 52 | 52 | * Introduction calculée |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 55 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | - if (strlen($descriptif)) { |
|
| 57 | - return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - // De preference ce qui est marque <intro>...</intro> |
|
| 61 | - $intro = ''; |
|
| 62 | - $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | - while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | - $zone = substr($texte, 0, $fin); |
|
| 65 | - $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | - if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | - $zone = substr($zone, $deb + 7); |
|
| 68 | - } |
|
| 69 | - $intro .= $zone; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | - // qui inclus raccourcis et modeles |
|
| 74 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | - // des surcharges et enrichissement de propre |
|
| 77 | - // couper doit se faire apres propre |
|
| 78 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | - |
|
| 80 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | - // large et en se mefiant des tableaux #1323 |
|
| 82 | - |
|
| 83 | - if (strlen($intro)) { |
|
| 84 | - $texte = $intro; |
|
| 85 | - } else { |
|
| 86 | - if ( |
|
| 87 | - strpos("\n" . $texte, "\n|") === false |
|
| 88 | - and strlen($texte) > 2.5 * $longueur |
|
| 89 | - ) { |
|
| 90 | - if (strpos($texte, '<multi') !== false) { |
|
| 91 | - $texte = extraire_multi($texte); |
|
| 92 | - } |
|
| 93 | - $texte = couper($texte, 2 * $longueur); |
|
| 94 | - } |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // ne pas tenir compte des notes |
|
| 98 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | - $notes('', 'empiler'); |
|
| 100 | - } |
|
| 101 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | - // dans l'introduction. |
|
| 103 | - $texte = supprime_img($texte, ''); |
|
| 104 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | - |
|
| 106 | - if ($notes) { |
|
| 107 | - $notes('', 'depiler'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | - $suite = _INTRODUCTION_SUITE; |
|
| 112 | - } |
|
| 113 | - $texte = couper($texte, $longueur, $suite); |
|
| 114 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | - $texte = typo($texte, true, $connect, []); |
|
| 116 | - |
|
| 117 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | - // une introduction a tojours un <p> |
|
| 119 | - if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - return $texte; |
|
| 55 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 56 | + if (strlen($descriptif)) { |
|
| 57 | + return appliquer_traitement_champ($descriptif, 'introduction', '', [], $connect); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + // De preference ce qui est marque <intro>...</intro> |
|
| 61 | + $intro = ''; |
|
| 62 | + $texte = preg_replace(',(</?)intro>,i', "\\1intro>", $texte); // minuscules |
|
| 63 | + while ($fin = strpos($texte, '</intro>')) { |
|
| 64 | + $zone = substr($texte, 0, $fin); |
|
| 65 | + $texte = substr($texte, $fin + strlen('</intro>')); |
|
| 66 | + if ($deb = strpos($zone, '<intro>') or substr($zone, 0, 7) == '<intro>') { |
|
| 67 | + $zone = substr($zone, $deb + 7); |
|
| 68 | + } |
|
| 69 | + $intro .= $zone; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 73 | + // qui inclus raccourcis et modeles |
|
| 74 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 75 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 76 | + // des surcharges et enrichissement de propre |
|
| 77 | + // couper doit se faire apres propre |
|
| 78 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 79 | + |
|
| 80 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 81 | + // large et en se mefiant des tableaux #1323 |
|
| 82 | + |
|
| 83 | + if (strlen($intro)) { |
|
| 84 | + $texte = $intro; |
|
| 85 | + } else { |
|
| 86 | + if ( |
|
| 87 | + strpos("\n" . $texte, "\n|") === false |
|
| 88 | + and strlen($texte) > 2.5 * $longueur |
|
| 89 | + ) { |
|
| 90 | + if (strpos($texte, '<multi') !== false) { |
|
| 91 | + $texte = extraire_multi($texte); |
|
| 92 | + } |
|
| 93 | + $texte = couper($texte, 2 * $longueur); |
|
| 94 | + } |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // ne pas tenir compte des notes |
|
| 98 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 99 | + $notes('', 'empiler'); |
|
| 100 | + } |
|
| 101 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 102 | + // dans l'introduction. |
|
| 103 | + $texte = supprime_img($texte, ''); |
|
| 104 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', [], $connect); |
|
| 105 | + |
|
| 106 | + if ($notes) { |
|
| 107 | + $notes('', 'depiler'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 111 | + $suite = _INTRODUCTION_SUITE; |
|
| 112 | + } |
|
| 113 | + $texte = couper($texte, $longueur, $suite); |
|
| 114 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 115 | + $texte = typo($texte, true, $connect, []); |
|
| 116 | + |
|
| 117 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 118 | + // une introduction a tojours un <p> |
|
| 119 | + if ($GLOBALS['toujours_paragrapher']) { // Fermer les paragraphes |
|
| 120 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + return $texte; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | |
@@ -155,73 +155,73 @@ discard block |
||
| 155 | 155 | * Code HTML de la pagination |
| 156 | 156 | **/ |
| 157 | 157 | function filtre_pagination_dist( |
| 158 | - $total, |
|
| 159 | - $nom, |
|
| 160 | - $position, |
|
| 161 | - $pas, |
|
| 162 | - $liste = true, |
|
| 163 | - $modele = '', |
|
| 164 | - string $connect = '', |
|
| 165 | - $env = [] |
|
| 158 | + $total, |
|
| 159 | + $nom, |
|
| 160 | + $position, |
|
| 161 | + $pas, |
|
| 162 | + $liste = true, |
|
| 163 | + $modele = '', |
|
| 164 | + string $connect = '', |
|
| 165 | + $env = [] |
|
| 166 | 166 | ) { |
| 167 | - static $ancres = []; |
|
| 168 | - if ($pas < 1) { |
|
| 169 | - return ''; |
|
| 170 | - } |
|
| 171 | - $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | - $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | - |
|
| 174 | - // n'afficher l'ancre qu'une fois |
|
| 175 | - if (!isset($ancres[$ancre])) { |
|
| 176 | - $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | - } else { |
|
| 178 | - $bloc_ancre = ''; |
|
| 179 | - } |
|
| 180 | - // liste = false : on ne veut que l'ancre |
|
| 181 | - if (!$liste) { |
|
| 182 | - return $ancres[$ancre]; |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | - $pagination = [ |
|
| 187 | - 'debut' => $debut, |
|
| 188 | - 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | - 'total' => $total, |
|
| 190 | - 'position' => intval($position), |
|
| 191 | - 'pas' => $pas, |
|
| 192 | - 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | - 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | - 'ancre' => $ancre, |
|
| 195 | - 'bloc_ancre' => $bloc_ancre |
|
| 196 | - ]; |
|
| 197 | - if (is_array($env)) { |
|
| 198 | - $pagination = array_merge($env, $pagination); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // Pas de pagination |
|
| 202 | - if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - if ($modele) { |
|
| 207 | - $pagination['type_pagination'] = $modele; |
|
| 208 | - if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | - $modele = '_' . $modele; |
|
| 210 | - } |
|
| 211 | - else { |
|
| 212 | - $modele = ''; |
|
| 213 | - } |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | - define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | - } |
|
| 219 | - if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | - define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - |
|
| 224 | - return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 167 | + static $ancres = []; |
|
| 168 | + if ($pas < 1) { |
|
| 169 | + return ''; |
|
| 170 | + } |
|
| 171 | + $ancre = 'pagination' . $nom; // #pagination_articles |
|
| 172 | + $debut = 'debut' . $nom; // 'debut_articles' |
|
| 173 | + |
|
| 174 | + // n'afficher l'ancre qu'une fois |
|
| 175 | + if (!isset($ancres[$ancre])) { |
|
| 176 | + $bloc_ancre = $ancres[$ancre] = "<a id='" . $ancre . "' class='pagination_ancre'></a>"; |
|
| 177 | + } else { |
|
| 178 | + $bloc_ancre = ''; |
|
| 179 | + } |
|
| 180 | + // liste = false : on ne veut que l'ancre |
|
| 181 | + if (!$liste) { |
|
| 182 | + return $ancres[$ancre]; |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + $self = (empty($env['self']) ? self() : $env['self']); |
|
| 186 | + $pagination = [ |
|
| 187 | + 'debut' => $debut, |
|
| 188 | + 'url' => parametre_url($self, 'fragment', ''), // nettoyer l'id ahah eventuel |
|
| 189 | + 'total' => $total, |
|
| 190 | + 'position' => intval($position), |
|
| 191 | + 'pas' => $pas, |
|
| 192 | + 'nombre_pages' => floor(($total - 1) / $pas) + 1, |
|
| 193 | + 'page_courante' => floor(intval($position) / $pas) + 1, |
|
| 194 | + 'ancre' => $ancre, |
|
| 195 | + 'bloc_ancre' => $bloc_ancre |
|
| 196 | + ]; |
|
| 197 | + if (is_array($env)) { |
|
| 198 | + $pagination = array_merge($env, $pagination); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // Pas de pagination |
|
| 202 | + if ($pagination['nombre_pages'] <= 1) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + if ($modele) { |
|
| 207 | + $pagination['type_pagination'] = $modele; |
|
| 208 | + if (trouver_fond('pagination_' . $modele, 'modeles')) { |
|
| 209 | + $modele = '_' . $modele; |
|
| 210 | + } |
|
| 211 | + else { |
|
| 212 | + $modele = ''; |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX')) { |
|
| 217 | + define('_PAGINATION_NOMBRE_LIENS_MAX', 10); |
|
| 218 | + } |
|
| 219 | + if (!defined('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE')) { |
|
| 220 | + define('_PAGINATION_NOMBRE_LIENS_MAX_ECRIRE', 5); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + |
|
| 224 | + return recuperer_fond("modeles/pagination$modele", $pagination, ['trim' => true], $connect); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | |
@@ -240,44 +240,44 @@ discard block |
||
| 240 | 240 | * Liste (première page, dernière page). |
| 241 | 241 | **/ |
| 242 | 242 | function filtre_bornes_pagination_dist($courante, $nombre, $max = 10) { |
| 243 | - if ($max <= 0 or $max >= $nombre) { |
|
| 244 | - return [1, $nombre]; |
|
| 245 | - } |
|
| 246 | - if ($max <= 1) { |
|
| 247 | - return [$courante, $courante]; |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | - $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | - $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | - |
|
| 254 | - return [$premiere, $derniere]; |
|
| 243 | + if ($max <= 0 or $max >= $nombre) { |
|
| 244 | + return [1, $nombre]; |
|
| 245 | + } |
|
| 246 | + if ($max <= 1) { |
|
| 247 | + return [$courante, $courante]; |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $premiere = max(1, $courante - floor(($max - 1) / 2)); |
|
| 251 | + $derniere = min($nombre, $premiere + $max - 2); |
|
| 252 | + $premiere = $derniere == $nombre ? $derniere - $max + 1 : $premiere; |
|
| 253 | + |
|
| 254 | + return [$premiere, $derniere]; |
|
| 255 | 255 | } |
| 256 | 256 | |
| 257 | 257 | function filtre_pagination_affiche_texte_lien_page_dist($type_pagination, $numero_page, $rang_item) { |
| 258 | - if ($numero_page === 'tous') { |
|
| 259 | - return '∞'; |
|
| 260 | - } |
|
| 261 | - if ($numero_page === 'prev') { |
|
| 262 | - return '<'; |
|
| 263 | - } |
|
| 264 | - if ($numero_page === 'next') { |
|
| 265 | - return '>'; |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - switch ($type_pagination) { |
|
| 269 | - case 'resultats': |
|
| 270 | - return $rang_item + 1; // 1 11 21 31... |
|
| 271 | - case 'naturel': |
|
| 272 | - return $rang_item ?: 1; // 1 10 20 30... |
|
| 273 | - case 'rang': |
|
| 274 | - return $rang_item; // 0 10 20 30... |
|
| 275 | - |
|
| 276 | - case 'page': |
|
| 277 | - case 'prive': |
|
| 278 | - default: |
|
| 279 | - return $numero_page; // 1 2 3 4 5... |
|
| 280 | - } |
|
| 258 | + if ($numero_page === 'tous') { |
|
| 259 | + return '∞'; |
|
| 260 | + } |
|
| 261 | + if ($numero_page === 'prev') { |
|
| 262 | + return '<'; |
|
| 263 | + } |
|
| 264 | + if ($numero_page === 'next') { |
|
| 265 | + return '>'; |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + switch ($type_pagination) { |
|
| 269 | + case 'resultats': |
|
| 270 | + return $rang_item + 1; // 1 11 21 31... |
|
| 271 | + case 'naturel': |
|
| 272 | + return $rang_item ?: 1; // 1 10 20 30... |
|
| 273 | + case 'rang': |
|
| 274 | + return $rang_item; // 0 10 20 30... |
|
| 275 | + |
|
| 276 | + case 'page': |
|
| 277 | + case 'prive': |
|
| 278 | + default: |
|
| 279 | + return $numero_page; // 1 2 3 4 5... |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /** |
@@ -290,15 +290,15 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function lister_objets_avec_logos($type) { |
| 292 | 292 | |
| 293 | - $objet = objet_type($type); |
|
| 294 | - $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | - if ($ids) { |
|
| 296 | - $ids = array_column($ids, 'id_objet'); |
|
| 297 | - return implode(',', $ids); |
|
| 298 | - } |
|
| 299 | - else { |
|
| 300 | - return '0'; |
|
| 301 | - } |
|
| 293 | + $objet = objet_type($type); |
|
| 294 | + $ids = sql_allfetsel('L.id_objet', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote('logoon') . ' AND L.objet=' . sql_quote($objet)); |
|
| 295 | + if ($ids) { |
|
| 296 | + $ids = array_column($ids, 'id_objet'); |
|
| 297 | + return implode(',', $ids); |
|
| 298 | + } |
|
| 299 | + else { |
|
| 300 | + return '0'; |
|
| 301 | + } |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | |
@@ -314,14 +314,14 @@ discard block |
||
| 314 | 314 | * Code HTML des notes |
| 315 | 315 | **/ |
| 316 | 316 | function calculer_notes() { |
| 317 | - $r = ''; |
|
| 318 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | - $r = $notes([]); |
|
| 320 | - $notes('', 'depiler'); |
|
| 321 | - $notes('', 'empiler'); |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - return $r; |
|
| 317 | + $r = ''; |
|
| 318 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 319 | + $r = $notes([]); |
|
| 320 | + $notes('', 'depiler'); |
|
| 321 | + $notes('', 'empiler'); |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + return $r; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -338,10 +338,10 @@ discard block |
||
| 338 | 338 | * @return string |
| 339 | 339 | */ |
| 340 | 340 | function retrouver_rang_lien($objet_source, $ids, $objet_lie, $idl, $objet_lien) { |
| 341 | - $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | - $res = array_column($res, 'rang_lien', $objet_source); |
|
| 341 | + $res = lister_objets_liens($objet_source, $objet_lie, $idl, $objet_lien); |
|
| 342 | + $res = array_column($res, 'rang_lien', $objet_source); |
|
| 343 | 343 | |
| 344 | - return ($res[$ids] ?? ''); |
|
| 344 | + return ($res[$ids] ?? ''); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -358,19 +358,19 @@ discard block |
||
| 358 | 358 | * @private |
| 359 | 359 | */ |
| 360 | 360 | function lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien) { |
| 361 | - static $liens = []; |
|
| 362 | - if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | - include_spip('action/editer_liens'); |
|
| 364 | - // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | - if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | - } else { |
|
| 368 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | - } |
|
| 373 | - return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 361 | + static $liens = []; |
|
| 362 | + if (!isset($liens["$objet_source-$objet-$id_objet-$objet_lien"])) { |
|
| 363 | + include_spip('action/editer_liens'); |
|
| 364 | + // quand $objet == $objet_lien == $objet_source on reste sur le cas par defaut de $objet_lien == $objet_source |
|
| 365 | + if ($objet_lien == $objet and $objet_lien !== $objet_source) { |
|
| 366 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 367 | + } else { |
|
| 368 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $liens["$objet_source-$objet-$id_objet-$objet_lien"] = $res; |
|
| 372 | + } |
|
| 373 | + return $liens["$objet_source-$objet-$id_objet-$objet_lien"]; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -384,24 +384,24 @@ discard block |
||
| 384 | 384 | * @return int|string |
| 385 | 385 | */ |
| 386 | 386 | function calculer_rang_smart($titre, $objet_source, $id, $env) { |
| 387 | - // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | - // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | - if ( |
|
| 390 | - isset($env['form']) and $env['form'] |
|
| 391 | - and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | - and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | - and $r = objet_associable($env['_objet_lien']) |
|
| 394 | - and [$p, $table_lien] = $r |
|
| 395 | - and lien_triables($table_lien) |
|
| 396 | - and isset($env['objet']) and $env['objet'] |
|
| 397 | - and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | - and $objet_source |
|
| 399 | - and $id = intval($id) |
|
| 400 | - ) { |
|
| 401 | - $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | - return ($rang ?: ''); |
|
| 403 | - } |
|
| 404 | - return recuperer_numero($titre); |
|
| 387 | + // Cas du #RANG utilisé dans #FORMULAIRE_EDITER_LIENS -> attraper le rang du lien |
|
| 388 | + // permet de voir le rang du lien si il y en a un en base, meme avant un squelette xxxx-lies.html ne gerant pas les liens |
|
| 389 | + if ( |
|
| 390 | + isset($env['form']) and $env['form'] |
|
| 391 | + and isset($env['_objet_lien']) and $env['_objet_lien'] |
|
| 392 | + and (function_exists('lien_triables') or include_spip('action/editer_liens')) |
|
| 393 | + and $r = objet_associable($env['_objet_lien']) |
|
| 394 | + and [$p, $table_lien] = $r |
|
| 395 | + and lien_triables($table_lien) |
|
| 396 | + and isset($env['objet']) and $env['objet'] |
|
| 397 | + and isset($env['id_objet']) and $env['id_objet'] |
|
| 398 | + and $objet_source |
|
| 399 | + and $id = intval($id) |
|
| 400 | + ) { |
|
| 401 | + $rang = retrouver_rang_lien($objet_source, $id, $env['objet'], $env['id_objet'], $env['_objet_lien']); |
|
| 402 | + return ($rang ?: ''); |
|
| 403 | + } |
|
| 404 | + return recuperer_numero($titre); |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function tri_protege_champ($t) { |
| 420 | - return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 420 | + return preg_replace(',[^\s\w.+\[\]],', '', $t); |
|
| 421 | 421 | } |
| 422 | 422 | |
| 423 | 423 | /** |
@@ -430,43 +430,43 @@ discard block |
||
| 430 | 430 | * @return string |
| 431 | 431 | */ |
| 432 | 432 | function tri_champ_order($t, $from = null, $senstri = '') { |
| 433 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | - return 'multi'; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - $champ = $t; |
|
| 438 | - |
|
| 439 | - $prefixe = ''; |
|
| 440 | - foreach (['num ', 'sinum '] as $p) { |
|
| 441 | - if (strpos($t, $p) === 0) { |
|
| 442 | - $champ = substr($t, strlen($p)); |
|
| 443 | - $prefixe = $p; |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | - $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | - |
|
| 450 | - if (is_array($from)) { |
|
| 451 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | - foreach ($from as $idt => $table_sql) { |
|
| 453 | - if ( |
|
| 454 | - $desc = $trouver_table($table_sql) |
|
| 455 | - and isset($desc['field'][$champ]) |
|
| 456 | - ) { |
|
| 457 | - $champ = "$idt.$champ"; |
|
| 458 | - break; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - switch ($prefixe) { |
|
| 463 | - case 'num ': |
|
| 464 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | - case 'sinum ': |
|
| 466 | - return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | - default: |
|
| 468 | - return $champ . $senstri; |
|
| 469 | - } |
|
| 433 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 434 | + return 'multi'; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + $champ = $t; |
|
| 438 | + |
|
| 439 | + $prefixe = ''; |
|
| 440 | + foreach (['num ', 'sinum '] as $p) { |
|
| 441 | + if (strpos($t, $p) === 0) { |
|
| 442 | + $champ = substr($t, strlen($p)); |
|
| 443 | + $prefixe = $p; |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + // enlever les autres espaces non evacues par tri_protege_champ |
|
| 448 | + $champ = preg_replace(',\s,', '', $champ); |
|
| 449 | + |
|
| 450 | + if (is_array($from)) { |
|
| 451 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 452 | + foreach ($from as $idt => $table_sql) { |
|
| 453 | + if ( |
|
| 454 | + $desc = $trouver_table($table_sql) |
|
| 455 | + and isset($desc['field'][$champ]) |
|
| 456 | + ) { |
|
| 457 | + $champ = "$idt.$champ"; |
|
| 458 | + break; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + switch ($prefixe) { |
|
| 463 | + case 'num ': |
|
| 464 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}, 0+$champ{$senstri}"; |
|
| 465 | + case 'sinum ': |
|
| 466 | + return "CASE( 0+$champ ) WHEN 0 THEN 1 ELSE 0 END{$senstri}"; |
|
| 467 | + default: |
|
| 468 | + return $champ . $senstri; |
|
| 469 | + } |
|
| 470 | 470 | } |
| 471 | 471 | |
| 472 | 472 | /** |
@@ -480,18 +480,18 @@ discard block |
||
| 480 | 480 | * @return string |
| 481 | 481 | */ |
| 482 | 482 | function tri_champ_select($t) { |
| 483 | - if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | - $t = substr($t, 6); |
|
| 485 | - $t = preg_replace(',\s,', '', $t); |
|
| 486 | - $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | - |
|
| 488 | - return $t; |
|
| 489 | - } |
|
| 490 | - if (trim($t) == 'hasard') { |
|
| 491 | - return 'rand() AS hasard'; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - return "''"; |
|
| 483 | + if (strncmp($t, 'multi ', 6) == 0) { |
|
| 484 | + $t = substr($t, 6); |
|
| 485 | + $t = preg_replace(',\s,', '', $t); |
|
| 486 | + $t = sql_multi($t, $GLOBALS['spip_lang']); |
|
| 487 | + |
|
| 488 | + return $t; |
|
| 489 | + } |
|
| 490 | + if (trim($t) == 'hasard') { |
|
| 491 | + return 'rand() AS hasard'; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + return "''"; |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -503,16 +503,16 @@ discard block |
||
| 503 | 503 | * @return string |
| 504 | 504 | */ |
| 505 | 505 | function formate_liste_critere_par_ordre_liste($valeurs, $serveur = '') { |
| 506 | - if (!is_array($valeurs)) { |
|
| 507 | - return ''; |
|
| 508 | - } |
|
| 509 | - $f = sql_serveur('quote', $serveur, true); |
|
| 510 | - if (!is_string($f) or !$f) { |
|
| 511 | - return ''; |
|
| 512 | - } |
|
| 513 | - $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | - |
|
| 515 | - return $valeurs; |
|
| 506 | + if (!is_array($valeurs)) { |
|
| 507 | + return ''; |
|
| 508 | + } |
|
| 509 | + $f = sql_serveur('quote', $serveur, true); |
|
| 510 | + if (!is_string($f) or !$f) { |
|
| 511 | + return ''; |
|
| 512 | + } |
|
| 513 | + $valeurs = implode(',', array_map($f, array_unique($valeurs))); |
|
| 514 | + |
|
| 515 | + return $valeurs; |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /** |
@@ -535,20 +535,20 @@ discard block |
||
| 535 | 535 | * Valeur $defaut sinon. |
| 536 | 536 | **/ |
| 537 | 537 | function appliquer_filtre_sinon($arg, $filtre, $args, $defaut = '') { |
| 538 | - // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | - // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | - include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | - $args[1] = $args[0]; |
|
| 543 | - $args[0] = $filtre; |
|
| 544 | - return image_graver(image_filtrer($args)); |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - $f = chercher_filtre($filtre); |
|
| 548 | - if (!$f) { |
|
| 549 | - return $defaut; |
|
| 550 | - } |
|
| 551 | - array_shift($args); // enlever $arg |
|
| 552 | - array_shift($args); // enlever $filtre |
|
| 553 | - return $f($arg, ...$args); |
|
| 538 | + // Si c'est un filtre d'image, on utilise image_filtrer() |
|
| 539 | + // Attention : les 2 premiers arguments sont inversés dans ce cas |
|
| 540 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 541 | + include_spip('inc/filtres_images_lib_mini'); |
|
| 542 | + $args[1] = $args[0]; |
|
| 543 | + $args[0] = $filtre; |
|
| 544 | + return image_graver(image_filtrer($args)); |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + $f = chercher_filtre($filtre); |
|
| 548 | + if (!$f) { |
|
| 549 | + return $defaut; |
|
| 550 | + } |
|
| 551 | + array_shift($args); // enlever $arg |
|
| 552 | + array_shift($args); // enlever $filtre |
|
| 553 | + return $f($arg, ...$args); |
|
| 554 | 554 | } |
@@ -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 | |
@@ -34,53 +34,53 @@ discard block |
||
| 34 | 34 | * @package SPIP\Core\Compilateur\AST |
| 35 | 35 | */ |
| 36 | 36 | class Contexte { |
| 37 | - /** |
|
| 38 | - * Description du squelette |
|
| 39 | - * |
|
| 40 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | - * |
|
| 42 | - * Peut contenir les index : |
|
| 43 | - * |
|
| 44 | - * - nom : Nom du fichier de cache |
|
| 45 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | - * - sourcefile : Chemin du squelette |
|
| 47 | - * - squelette : Code du squelette |
|
| 48 | - * - id_mere : Identifiant de la boucle parente |
|
| 49 | - * - documents : Pour embed et img dans les textes |
|
| 50 | - * - session : Pour un cache sessionné par auteur |
|
| 51 | - * - niv : Niveau de tabulation |
|
| 52 | - * |
|
| 53 | - * @var array |
|
| 54 | - */ |
|
| 55 | - public $descr = []; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * Identifiant de la boucle |
|
| 59 | - * |
|
| 60 | - * @var string |
|
| 61 | - */ |
|
| 62 | - public $id_boucle = ''; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Numéro de ligne dans le code source du squelette |
|
| 66 | - * |
|
| 67 | - * @var int |
|
| 68 | - */ |
|
| 69 | - public $ligne = 0; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Langue d'exécution |
|
| 73 | - * |
|
| 74 | - * @var string |
|
| 75 | - */ |
|
| 76 | - public $lang = ''; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Résultat de la compilation: toujours une expression PHP |
|
| 80 | - * |
|
| 81 | - * @var string |
|
| 82 | - */ |
|
| 83 | - public $code = ''; |
|
| 37 | + /** |
|
| 38 | + * Description du squelette |
|
| 39 | + * |
|
| 40 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | + * |
|
| 42 | + * Peut contenir les index : |
|
| 43 | + * |
|
| 44 | + * - nom : Nom du fichier de cache |
|
| 45 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | + * - sourcefile : Chemin du squelette |
|
| 47 | + * - squelette : Code du squelette |
|
| 48 | + * - id_mere : Identifiant de la boucle parente |
|
| 49 | + * - documents : Pour embed et img dans les textes |
|
| 50 | + * - session : Pour un cache sessionné par auteur |
|
| 51 | + * - niv : Niveau de tabulation |
|
| 52 | + * |
|
| 53 | + * @var array |
|
| 54 | + */ |
|
| 55 | + public $descr = []; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * Identifiant de la boucle |
|
| 59 | + * |
|
| 60 | + * @var string |
|
| 61 | + */ |
|
| 62 | + public $id_boucle = ''; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Numéro de ligne dans le code source du squelette |
|
| 66 | + * |
|
| 67 | + * @var int |
|
| 68 | + */ |
|
| 69 | + public $ligne = 0; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Langue d'exécution |
|
| 73 | + * |
|
| 74 | + * @var string |
|
| 75 | + */ |
|
| 76 | + public $lang = ''; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Résultat de la compilation: toujours une expression PHP |
|
| 80 | + * |
|
| 81 | + * @var string |
|
| 82 | + */ |
|
| 83 | + public $code = ''; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -90,44 +90,44 @@ discard block |
||
| 90 | 90 | * @package SPIP\Core\Compilateur\AST |
| 91 | 91 | **/ |
| 92 | 92 | class Texte { |
| 93 | - /** |
|
| 94 | - * Type de noeud |
|
| 95 | - * |
|
| 96 | - * @var string |
|
| 97 | - */ |
|
| 98 | - public $type = 'texte'; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * Le texte |
|
| 102 | - * |
|
| 103 | - * @var string |
|
| 104 | - */ |
|
| 105 | - public $texte; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Contenu avant le texte. |
|
| 109 | - * |
|
| 110 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | - * |
|
| 112 | - * @var string|array |
|
| 113 | - */ |
|
| 114 | - public $avant = ''; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * Contenu après le texte. |
|
| 118 | - * |
|
| 119 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | - * |
|
| 121 | - * @var string|array |
|
| 122 | - */ |
|
| 123 | - public $apres = ''; |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Numéro de ligne dans le code source du squelette |
|
| 127 | - * |
|
| 128 | - * @var int |
|
| 129 | - */ |
|
| 130 | - public $ligne = 0; |
|
| 93 | + /** |
|
| 94 | + * Type de noeud |
|
| 95 | + * |
|
| 96 | + * @var string |
|
| 97 | + */ |
|
| 98 | + public $type = 'texte'; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * Le texte |
|
| 102 | + * |
|
| 103 | + * @var string |
|
| 104 | + */ |
|
| 105 | + public $texte; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Contenu avant le texte. |
|
| 109 | + * |
|
| 110 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 111 | + * |
|
| 112 | + * @var string|array |
|
| 113 | + */ |
|
| 114 | + public $avant = ''; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * Contenu après le texte. |
|
| 118 | + * |
|
| 119 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 120 | + * |
|
| 121 | + * @var string|array |
|
| 122 | + */ |
|
| 123 | + public $apres = ''; |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Numéro de ligne dans le code source du squelette |
|
| 127 | + * |
|
| 128 | + * @var int |
|
| 129 | + */ |
|
| 130 | + public $ligne = 0; |
|
| 131 | 131 | } |
| 132 | 132 | |
| 133 | 133 | /** |
@@ -136,50 +136,50 @@ discard block |
||
| 136 | 136 | * @package SPIP\Core\Compilateur\AST |
| 137 | 137 | **/ |
| 138 | 138 | class Inclure { |
| 139 | - /** |
|
| 140 | - * Type de noeud |
|
| 141 | - * |
|
| 142 | - * @var string |
|
| 143 | - */ |
|
| 144 | - public $type = 'include'; |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * Nom d'un fichier inclu |
|
| 148 | - * |
|
| 149 | - * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | - * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | - * |
|
| 152 | - * @var string|Texte |
|
| 153 | - */ |
|
| 154 | - public $texte; |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Inutilisé, propriété générique de l'AST |
|
| 158 | - * |
|
| 159 | - * @var string|array |
|
| 160 | - */ |
|
| 161 | - public $avant = ''; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Inutilisé, propriété générique de l'AST |
|
| 165 | - * |
|
| 166 | - * @var string|array |
|
| 167 | - */ |
|
| 168 | - public $apres = ''; |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Numéro de ligne dans le code source du squelette |
|
| 172 | - * |
|
| 173 | - * @var int |
|
| 174 | - */ |
|
| 175 | - public $ligne = 0; |
|
| 176 | - |
|
| 177 | - /** |
|
| 178 | - * Valeurs des paramètres |
|
| 179 | - * |
|
| 180 | - * @var array |
|
| 181 | - */ |
|
| 182 | - public $param = []; |
|
| 139 | + /** |
|
| 140 | + * Type de noeud |
|
| 141 | + * |
|
| 142 | + * @var string |
|
| 143 | + */ |
|
| 144 | + public $type = 'include'; |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * Nom d'un fichier inclu |
|
| 148 | + * |
|
| 149 | + * - Objet Texte si inclusion d'un autre squelette |
|
| 150 | + * - chaîne si inclusion d'un fichier PHP directement |
|
| 151 | + * |
|
| 152 | + * @var string|Texte |
|
| 153 | + */ |
|
| 154 | + public $texte; |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Inutilisé, propriété générique de l'AST |
|
| 158 | + * |
|
| 159 | + * @var string|array |
|
| 160 | + */ |
|
| 161 | + public $avant = ''; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Inutilisé, propriété générique de l'AST |
|
| 165 | + * |
|
| 166 | + * @var string|array |
|
| 167 | + */ |
|
| 168 | + public $apres = ''; |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Numéro de ligne dans le code source du squelette |
|
| 172 | + * |
|
| 173 | + * @var int |
|
| 174 | + */ |
|
| 175 | + public $ligne = 0; |
|
| 176 | + |
|
| 177 | + /** |
|
| 178 | + * Valeurs des paramètres |
|
| 179 | + * |
|
| 180 | + * @var array |
|
| 181 | + */ |
|
| 182 | + public $param = []; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
@@ -189,392 +189,392 @@ discard block |
||
| 189 | 189 | * @package SPIP\Core\Compilateur\AST |
| 190 | 190 | **/ |
| 191 | 191 | class Boucle { |
| 192 | - /** |
|
| 193 | - * Type de noeud |
|
| 194 | - * |
|
| 195 | - * @var string |
|
| 196 | - */ |
|
| 197 | - public $type = 'boucle'; |
|
| 198 | - |
|
| 199 | - /** |
|
| 200 | - * Identifiant de la boucle |
|
| 201 | - * |
|
| 202 | - * @var string |
|
| 203 | - */ |
|
| 204 | - public $id_boucle; |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Identifiant de la boucle parente |
|
| 208 | - * |
|
| 209 | - * @var string |
|
| 210 | - */ |
|
| 211 | - public $id_parent = ''; |
|
| 212 | - |
|
| 213 | - /** |
|
| 214 | - * Partie avant toujours affichee |
|
| 215 | - * |
|
| 216 | - * @var string|array |
|
| 217 | - */ |
|
| 218 | - public $preaff = ''; |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * Partie optionnelle avant |
|
| 222 | - * |
|
| 223 | - * @var string|array |
|
| 224 | - */ |
|
| 225 | - public $avant = ''; |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Pour chaque élément |
|
| 229 | - * |
|
| 230 | - * @var string|array |
|
| 231 | - */ |
|
| 232 | - public $milieu = ''; |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Partie optionnelle après |
|
| 236 | - * |
|
| 237 | - * @var string|array |
|
| 238 | - */ |
|
| 239 | - public $apres = ''; |
|
| 240 | - |
|
| 241 | - /** |
|
| 242 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | - * |
|
| 244 | - * @var string|array |
|
| 245 | - */ |
|
| 246 | - public $altern = ''; |
|
| 247 | - |
|
| 248 | - /** |
|
| 249 | - * Partie apres toujours affichee |
|
| 250 | - * |
|
| 251 | - * @var string|array |
|
| 252 | - */ |
|
| 253 | - public $postaff = ''; |
|
| 254 | - |
|
| 255 | - |
|
| 256 | - /** |
|
| 257 | - * La boucle doit-elle sélectionner la langue ? |
|
| 258 | - * |
|
| 259 | - * @var string|null |
|
| 260 | - */ |
|
| 261 | - public $lang_select; |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | - * |
|
| 266 | - * @var string|null |
|
| 267 | - */ |
|
| 268 | - public $type_requete; |
|
| 269 | - |
|
| 270 | - /** |
|
| 271 | - * La table est elle optionnelle ? |
|
| 272 | - * |
|
| 273 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | - * |
|
| 275 | - * @var bool |
|
| 276 | - */ |
|
| 277 | - public $table_optionnelle = false; |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Nom du fichier de connexion |
|
| 281 | - * |
|
| 282 | - * @var string |
|
| 283 | - */ |
|
| 284 | - public $sql_serveur = ''; |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Paramètres de la boucle |
|
| 288 | - * |
|
| 289 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | - * au calcul des critères |
|
| 291 | - * |
|
| 292 | - * @var array |
|
| 293 | - */ |
|
| 294 | - public $param = []; |
|
| 295 | - |
|
| 296 | - /** |
|
| 297 | - * Critères de la boucle |
|
| 298 | - * |
|
| 299 | - * @var Critere[] |
|
| 300 | - */ |
|
| 301 | - public $criteres = []; |
|
| 302 | - |
|
| 303 | - /** |
|
| 304 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | - * |
|
| 306 | - * @var string[] |
|
| 307 | - */ |
|
| 308 | - public $separateur = []; |
|
| 309 | - |
|
| 310 | - /** |
|
| 311 | - * Liste des jointures possibles avec cette table |
|
| 312 | - * |
|
| 313 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | - * des jointures déclarées explicitement sur la boucle |
|
| 315 | - * |
|
| 316 | - * @see base_trouver_table_dist() |
|
| 317 | - * @var array |
|
| 318 | - */ |
|
| 319 | - public $jointures = []; |
|
| 320 | - |
|
| 321 | - /** |
|
| 322 | - * Jointures explicites avec cette table |
|
| 323 | - * |
|
| 324 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | - * à la boucle. |
|
| 327 | - * |
|
| 328 | - * @var string|bool |
|
| 329 | - */ |
|
| 330 | - public $jointures_explicites = false; |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | - * |
|
| 335 | - * @var string|null |
|
| 336 | - */ |
|
| 337 | - public $doublons; |
|
| 338 | - |
|
| 339 | - /** |
|
| 340 | - * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | - * |
|
| 342 | - * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | - * |
|
| 344 | - * @var string |
|
| 345 | - */ |
|
| 346 | - public $partie = ''; |
|
| 347 | - |
|
| 348 | - /** |
|
| 349 | - * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | - * ou de soustractions d'éléments à faire |
|
| 351 | - * |
|
| 352 | - * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | - * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | - * |
|
| 355 | - * @var string |
|
| 356 | - */ |
|
| 357 | - public $total_parties = ''; |
|
| 358 | - |
|
| 359 | - /** |
|
| 360 | - * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | - * |
|
| 362 | - * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | - * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | - * |
|
| 365 | - * @var string |
|
| 366 | - */ |
|
| 367 | - public $mode_partie = ''; |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | - * |
|
| 372 | - * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | - * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | - * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | - * de l'appelant (rec) |
|
| 376 | - * |
|
| 377 | - * @var string |
|
| 378 | - */ |
|
| 379 | - public $externe = ''; |
|
| 380 | - |
|
| 381 | - // champs pour la construction de la requete SQL |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Liste des champs à récupérer par la boucle |
|
| 385 | - * |
|
| 386 | - * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | - * |
|
| 388 | - * @var string[] |
|
| 389 | - */ |
|
| 390 | - public $select = []; |
|
| 391 | - |
|
| 392 | - /** |
|
| 393 | - * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | - * |
|
| 395 | - * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | - * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | - * |
|
| 398 | - * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | - * |
|
| 400 | - * @var string[] |
|
| 401 | - */ |
|
| 402 | - public $from = []; |
|
| 403 | - |
|
| 404 | - /** |
|
| 405 | - * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | - * |
|
| 407 | - * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | - * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | - * |
|
| 410 | - * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | - * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | - * |
|
| 413 | - * @var string[] |
|
| 414 | - */ |
|
| 415 | - public $from_type = []; |
|
| 416 | - |
|
| 417 | - /** |
|
| 418 | - * Liste des conditions WHERE de la boucle |
|
| 419 | - * |
|
| 420 | - * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | - * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | - * |
|
| 423 | - * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | - * |
|
| 425 | - * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | - * chaque élément ajouté directement au where par |
|
| 427 | - * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | - * est une condition AND en plus. |
|
| 429 | - * |
|
| 430 | - * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | - * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | - * $expr = array(operateur, val1, val2) |
|
| 433 | - * |
|
| 434 | - * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | - * à réaliser tel que : |
|
| 436 | - * |
|
| 437 | - * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | - * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | - * suivant cet ordre : "val1 operateur val2". |
|
| 440 | - * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | - * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | - * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | - * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | - * Exemples : |
|
| 445 | - * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | - * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | - * |
|
| 448 | - * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | - * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | - * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | - * |
|
| 452 | - * @var array |
|
| 453 | - */ |
|
| 454 | - public $where = []; |
|
| 455 | - |
|
| 456 | - public $join = []; |
|
| 457 | - public $having = []; |
|
| 458 | - public $limit = ''; |
|
| 459 | - public $group = []; |
|
| 460 | - public $order = []; |
|
| 461 | - public $default_order = []; |
|
| 462 | - public $date = 'date'; |
|
| 463 | - public $hash = ''; |
|
| 464 | - public $in = ''; |
|
| 465 | - public $sous_requete = false; |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | - * |
|
| 470 | - * Il sert à insérer le code calculant une hierarchie |
|
| 471 | - * |
|
| 472 | - * @var string |
|
| 473 | - */ |
|
| 474 | - public $hierarchie = ''; |
|
| 475 | - |
|
| 476 | - // champs pour la construction du corps PHP |
|
| 477 | - |
|
| 478 | - /** |
|
| 479 | - * Description des sources de données de la boucle |
|
| 480 | - * |
|
| 481 | - * Description des données de la boucle issu de trouver_table |
|
| 482 | - * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 483 | - * |
|
| 484 | - * @see base_trouver_table_dist() |
|
| 485 | - * @var array |
|
| 486 | - */ |
|
| 487 | - public $show = []; |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 491 | - * |
|
| 492 | - * @var string |
|
| 493 | - */ |
|
| 494 | - public $id_table; |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 498 | - * |
|
| 499 | - * @var string |
|
| 500 | - */ |
|
| 501 | - public $primary; |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * Code PHP compilé de la boucle |
|
| 505 | - * |
|
| 506 | - * @var string |
|
| 507 | - */ |
|
| 508 | - public $return; |
|
| 509 | - |
|
| 510 | - public $numrows = false; |
|
| 511 | - public $cptrows = false; |
|
| 512 | - |
|
| 513 | - /** |
|
| 514 | - * Description du squelette |
|
| 515 | - * |
|
| 516 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 517 | - * |
|
| 518 | - * Peut contenir les index : |
|
| 519 | - * |
|
| 520 | - * - nom : Nom du fichier de cache |
|
| 521 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 522 | - * - sourcefile : Chemin du squelette |
|
| 523 | - * - squelette : Code du squelette |
|
| 524 | - * - id_mere : Identifiant de la boucle parente |
|
| 525 | - * - documents : Pour embed et img dans les textes |
|
| 526 | - * - session : Pour un cache sessionné par auteur |
|
| 527 | - * - niv : Niveau de tabulation |
|
| 528 | - * |
|
| 529 | - * @var array |
|
| 530 | - */ |
|
| 531 | - public $descr = []; |
|
| 532 | - |
|
| 533 | - /** |
|
| 534 | - * Numéro de ligne dans le code source du squelette |
|
| 535 | - * |
|
| 536 | - * @var int |
|
| 537 | - */ |
|
| 538 | - public $ligne = 0; |
|
| 539 | - |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 543 | - * utilisable par les plugins egalement |
|
| 544 | - * |
|
| 545 | - * @var array<string, mixed> |
|
| 546 | - */ |
|
| 547 | - public $modificateur = []; |
|
| 548 | - |
|
| 549 | - /** |
|
| 550 | - * Type d'itérateur utilisé pour cette boucle |
|
| 551 | - * |
|
| 552 | - * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 553 | - * - 'DATA' pour l'itérateur DATA, ... |
|
| 554 | - * |
|
| 555 | - * @var string |
|
| 556 | - */ |
|
| 557 | - public $iterateur = ''; // type d'iterateur |
|
| 558 | - |
|
| 559 | - /** |
|
| 560 | - * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 561 | - */ |
|
| 562 | - public $debug = []; |
|
| 563 | - |
|
| 564 | - /** |
|
| 565 | - * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 566 | - * notamment si le champ a été trouve dans une boucle parente |
|
| 567 | - * |
|
| 568 | - * Tableau nom du champ => index de boucle |
|
| 569 | - * |
|
| 570 | - * @var array $index_champ |
|
| 571 | - */ |
|
| 572 | - public $index_champ = []; |
|
| 573 | - |
|
| 574 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 575 | - public $tout = false; |
|
| 576 | - public $plat = false; |
|
| 577 | - public $lien = false; |
|
| 192 | + /** |
|
| 193 | + * Type de noeud |
|
| 194 | + * |
|
| 195 | + * @var string |
|
| 196 | + */ |
|
| 197 | + public $type = 'boucle'; |
|
| 198 | + |
|
| 199 | + /** |
|
| 200 | + * Identifiant de la boucle |
|
| 201 | + * |
|
| 202 | + * @var string |
|
| 203 | + */ |
|
| 204 | + public $id_boucle; |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Identifiant de la boucle parente |
|
| 208 | + * |
|
| 209 | + * @var string |
|
| 210 | + */ |
|
| 211 | + public $id_parent = ''; |
|
| 212 | + |
|
| 213 | + /** |
|
| 214 | + * Partie avant toujours affichee |
|
| 215 | + * |
|
| 216 | + * @var string|array |
|
| 217 | + */ |
|
| 218 | + public $preaff = ''; |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * Partie optionnelle avant |
|
| 222 | + * |
|
| 223 | + * @var string|array |
|
| 224 | + */ |
|
| 225 | + public $avant = ''; |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Pour chaque élément |
|
| 229 | + * |
|
| 230 | + * @var string|array |
|
| 231 | + */ |
|
| 232 | + public $milieu = ''; |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Partie optionnelle après |
|
| 236 | + * |
|
| 237 | + * @var string|array |
|
| 238 | + */ |
|
| 239 | + public $apres = ''; |
|
| 240 | + |
|
| 241 | + /** |
|
| 242 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 243 | + * |
|
| 244 | + * @var string|array |
|
| 245 | + */ |
|
| 246 | + public $altern = ''; |
|
| 247 | + |
|
| 248 | + /** |
|
| 249 | + * Partie apres toujours affichee |
|
| 250 | + * |
|
| 251 | + * @var string|array |
|
| 252 | + */ |
|
| 253 | + public $postaff = ''; |
|
| 254 | + |
|
| 255 | + |
|
| 256 | + /** |
|
| 257 | + * La boucle doit-elle sélectionner la langue ? |
|
| 258 | + * |
|
| 259 | + * @var string|null |
|
| 260 | + */ |
|
| 261 | + public $lang_select; |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 265 | + * |
|
| 266 | + * @var string|null |
|
| 267 | + */ |
|
| 268 | + public $type_requete; |
|
| 269 | + |
|
| 270 | + /** |
|
| 271 | + * La table est elle optionnelle ? |
|
| 272 | + * |
|
| 273 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 274 | + * |
|
| 275 | + * @var bool |
|
| 276 | + */ |
|
| 277 | + public $table_optionnelle = false; |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Nom du fichier de connexion |
|
| 281 | + * |
|
| 282 | + * @var string |
|
| 283 | + */ |
|
| 284 | + public $sql_serveur = ''; |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Paramètres de la boucle |
|
| 288 | + * |
|
| 289 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 290 | + * au calcul des critères |
|
| 291 | + * |
|
| 292 | + * @var array |
|
| 293 | + */ |
|
| 294 | + public $param = []; |
|
| 295 | + |
|
| 296 | + /** |
|
| 297 | + * Critères de la boucle |
|
| 298 | + * |
|
| 299 | + * @var Critere[] |
|
| 300 | + */ |
|
| 301 | + public $criteres = []; |
|
| 302 | + |
|
| 303 | + /** |
|
| 304 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 305 | + * |
|
| 306 | + * @var string[] |
|
| 307 | + */ |
|
| 308 | + public $separateur = []; |
|
| 309 | + |
|
| 310 | + /** |
|
| 311 | + * Liste des jointures possibles avec cette table |
|
| 312 | + * |
|
| 313 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 314 | + * des jointures déclarées explicitement sur la boucle |
|
| 315 | + * |
|
| 316 | + * @see base_trouver_table_dist() |
|
| 317 | + * @var array |
|
| 318 | + */ |
|
| 319 | + public $jointures = []; |
|
| 320 | + |
|
| 321 | + /** |
|
| 322 | + * Jointures explicites avec cette table |
|
| 323 | + * |
|
| 324 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 325 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 326 | + * à la boucle. |
|
| 327 | + * |
|
| 328 | + * @var string|bool |
|
| 329 | + */ |
|
| 330 | + public $jointures_explicites = false; |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 334 | + * |
|
| 335 | + * @var string|null |
|
| 336 | + */ |
|
| 337 | + public $doublons; |
|
| 338 | + |
|
| 339 | + /** |
|
| 340 | + * Code PHP ajouté au début de chaque itération de boucle. |
|
| 341 | + * |
|
| 342 | + * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 343 | + * |
|
| 344 | + * @var string |
|
| 345 | + */ |
|
| 346 | + public $partie = ''; |
|
| 347 | + |
|
| 348 | + /** |
|
| 349 | + * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 350 | + * ou de soustractions d'éléments à faire |
|
| 351 | + * |
|
| 352 | + * Dans les critères limitant le nombre d'éléments affichés |
|
| 353 | + * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 354 | + * |
|
| 355 | + * @var string |
|
| 356 | + */ |
|
| 357 | + public $total_parties = ''; |
|
| 358 | + |
|
| 359 | + /** |
|
| 360 | + * Code PHP ajouté avant l'itération de boucle. |
|
| 361 | + * |
|
| 362 | + * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 363 | + * pour initialiser les variables de début et de fin d'itération. |
|
| 364 | + * |
|
| 365 | + * @var string |
|
| 366 | + */ |
|
| 367 | + public $mode_partie = ''; |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 371 | + * |
|
| 372 | + * Si une boucle est appelée de manière récursive quelque part par |
|
| 373 | + * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 374 | + * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 375 | + * de l'appelant (rec) |
|
| 376 | + * |
|
| 377 | + * @var string |
|
| 378 | + */ |
|
| 379 | + public $externe = ''; |
|
| 380 | + |
|
| 381 | + // champs pour la construction de la requete SQL |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Liste des champs à récupérer par la boucle |
|
| 385 | + * |
|
| 386 | + * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 387 | + * |
|
| 388 | + * @var string[] |
|
| 389 | + */ |
|
| 390 | + public $select = []; |
|
| 391 | + |
|
| 392 | + /** |
|
| 393 | + * Liste des alias / tables SQL utilisées dans la boucle |
|
| 394 | + * |
|
| 395 | + * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 396 | + * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 397 | + * |
|
| 398 | + * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 399 | + * |
|
| 400 | + * @var string[] |
|
| 401 | + */ |
|
| 402 | + public $from = []; |
|
| 403 | + |
|
| 404 | + /** |
|
| 405 | + * Liste des alias / type de jointures utilisées dans la boucle |
|
| 406 | + * |
|
| 407 | + * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 408 | + * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 409 | + * |
|
| 410 | + * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 411 | + * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 412 | + * |
|
| 413 | + * @var string[] |
|
| 414 | + */ |
|
| 415 | + public $from_type = []; |
|
| 416 | + |
|
| 417 | + /** |
|
| 418 | + * Liste des conditions WHERE de la boucle |
|
| 419 | + * |
|
| 420 | + * Permet de restreindre les éléments retournés par une boucle |
|
| 421 | + * en fonctions des conditions transmises dans ce tableau. |
|
| 422 | + * |
|
| 423 | + * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 424 | + * |
|
| 425 | + * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 426 | + * chaque élément ajouté directement au where par |
|
| 427 | + * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 428 | + * est une condition AND en plus. |
|
| 429 | + * |
|
| 430 | + * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 431 | + * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 432 | + * $expr = array(operateur, val1, val2) |
|
| 433 | + * |
|
| 434 | + * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 435 | + * à réaliser tel que : |
|
| 436 | + * |
|
| 437 | + * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 438 | + * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 439 | + * suivant cet ordre : "val1 operateur val2". |
|
| 440 | + * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 441 | + * - "'AND'", "'OR'", "'NOT'" : |
|
| 442 | + * dans ce cas val1 et val2 sont également des expressions |
|
| 443 | + * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 444 | + * Exemples : |
|
| 445 | + * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 446 | + * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 447 | + * |
|
| 448 | + * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 449 | + * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 450 | + * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 451 | + * |
|
| 452 | + * @var array |
|
| 453 | + */ |
|
| 454 | + public $where = []; |
|
| 455 | + |
|
| 456 | + public $join = []; |
|
| 457 | + public $having = []; |
|
| 458 | + public $limit = ''; |
|
| 459 | + public $group = []; |
|
| 460 | + public $order = []; |
|
| 461 | + public $default_order = []; |
|
| 462 | + public $date = 'date'; |
|
| 463 | + public $hash = ''; |
|
| 464 | + public $in = ''; |
|
| 465 | + public $sous_requete = false; |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 469 | + * |
|
| 470 | + * Il sert à insérer le code calculant une hierarchie |
|
| 471 | + * |
|
| 472 | + * @var string |
|
| 473 | + */ |
|
| 474 | + public $hierarchie = ''; |
|
| 475 | + |
|
| 476 | + // champs pour la construction du corps PHP |
|
| 477 | + |
|
| 478 | + /** |
|
| 479 | + * Description des sources de données de la boucle |
|
| 480 | + * |
|
| 481 | + * Description des données de la boucle issu de trouver_table |
|
| 482 | + * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 483 | + * |
|
| 484 | + * @see base_trouver_table_dist() |
|
| 485 | + * @var array |
|
| 486 | + */ |
|
| 487 | + public $show = []; |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 491 | + * |
|
| 492 | + * @var string |
|
| 493 | + */ |
|
| 494 | + public $id_table; |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 498 | + * |
|
| 499 | + * @var string |
|
| 500 | + */ |
|
| 501 | + public $primary; |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * Code PHP compilé de la boucle |
|
| 505 | + * |
|
| 506 | + * @var string |
|
| 507 | + */ |
|
| 508 | + public $return; |
|
| 509 | + |
|
| 510 | + public $numrows = false; |
|
| 511 | + public $cptrows = false; |
|
| 512 | + |
|
| 513 | + /** |
|
| 514 | + * Description du squelette |
|
| 515 | + * |
|
| 516 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 517 | + * |
|
| 518 | + * Peut contenir les index : |
|
| 519 | + * |
|
| 520 | + * - nom : Nom du fichier de cache |
|
| 521 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 522 | + * - sourcefile : Chemin du squelette |
|
| 523 | + * - squelette : Code du squelette |
|
| 524 | + * - id_mere : Identifiant de la boucle parente |
|
| 525 | + * - documents : Pour embed et img dans les textes |
|
| 526 | + * - session : Pour un cache sessionné par auteur |
|
| 527 | + * - niv : Niveau de tabulation |
|
| 528 | + * |
|
| 529 | + * @var array |
|
| 530 | + */ |
|
| 531 | + public $descr = []; |
|
| 532 | + |
|
| 533 | + /** |
|
| 534 | + * Numéro de ligne dans le code source du squelette |
|
| 535 | + * |
|
| 536 | + * @var int |
|
| 537 | + */ |
|
| 538 | + public $ligne = 0; |
|
| 539 | + |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 543 | + * utilisable par les plugins egalement |
|
| 544 | + * |
|
| 545 | + * @var array<string, mixed> |
|
| 546 | + */ |
|
| 547 | + public $modificateur = []; |
|
| 548 | + |
|
| 549 | + /** |
|
| 550 | + * Type d'itérateur utilisé pour cette boucle |
|
| 551 | + * |
|
| 552 | + * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 553 | + * - 'DATA' pour l'itérateur DATA, ... |
|
| 554 | + * |
|
| 555 | + * @var string |
|
| 556 | + */ |
|
| 557 | + public $iterateur = ''; // type d'iterateur |
|
| 558 | + |
|
| 559 | + /** |
|
| 560 | + * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 561 | + */ |
|
| 562 | + public $debug = []; |
|
| 563 | + |
|
| 564 | + /** |
|
| 565 | + * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 566 | + * notamment si le champ a été trouve dans une boucle parente |
|
| 567 | + * |
|
| 568 | + * Tableau nom du champ => index de boucle |
|
| 569 | + * |
|
| 570 | + * @var array $index_champ |
|
| 571 | + */ |
|
| 572 | + public $index_champ = []; |
|
| 573 | + |
|
| 574 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 575 | + public $tout = false; |
|
| 576 | + public $plat = false; |
|
| 577 | + public $lien = false; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -585,56 +585,56 @@ discard block |
||
| 585 | 585 | * @package SPIP\Core\Compilateur\AST |
| 586 | 586 | **/ |
| 587 | 587 | class Critere { |
| 588 | - /** |
|
| 589 | - * Type de noeud |
|
| 590 | - * |
|
| 591 | - * @var string |
|
| 592 | - */ |
|
| 593 | - public $type = 'critere'; |
|
| 594 | - |
|
| 595 | - /** |
|
| 596 | - * Opérateur (>, <, >=, IN, ...) |
|
| 597 | - * |
|
| 598 | - * @var null|string |
|
| 599 | - */ |
|
| 600 | - public $op; |
|
| 601 | - |
|
| 602 | - /** |
|
| 603 | - * Présence d'une négation (truc !op valeur) |
|
| 604 | - * |
|
| 605 | - * @var null|string |
|
| 606 | - */ |
|
| 607 | - public $not; |
|
| 608 | - |
|
| 609 | - /** |
|
| 610 | - * Présence d'une exclusion (!truc op valeur) |
|
| 611 | - * |
|
| 612 | - * @var null|string |
|
| 613 | - */ |
|
| 614 | - public $exclus; |
|
| 615 | - |
|
| 616 | - /** |
|
| 617 | - * Présence d'une condition dans le critère (truc ?) |
|
| 618 | - * |
|
| 619 | - * @var bool |
|
| 620 | - */ |
|
| 621 | - public $cond = false; |
|
| 622 | - |
|
| 623 | - /** |
|
| 624 | - * Paramètres du critère |
|
| 625 | - * - $param[0] : élément avant l'opérateur |
|
| 626 | - * - $param[1..n] : éléments après l'opérateur |
|
| 627 | - * |
|
| 628 | - * @var array |
|
| 629 | - */ |
|
| 630 | - public $param = []; |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * Numéro de ligne dans le code source du squelette |
|
| 634 | - * |
|
| 635 | - * @var int |
|
| 636 | - */ |
|
| 637 | - public $ligne = 0; |
|
| 588 | + /** |
|
| 589 | + * Type de noeud |
|
| 590 | + * |
|
| 591 | + * @var string |
|
| 592 | + */ |
|
| 593 | + public $type = 'critere'; |
|
| 594 | + |
|
| 595 | + /** |
|
| 596 | + * Opérateur (>, <, >=, IN, ...) |
|
| 597 | + * |
|
| 598 | + * @var null|string |
|
| 599 | + */ |
|
| 600 | + public $op; |
|
| 601 | + |
|
| 602 | + /** |
|
| 603 | + * Présence d'une négation (truc !op valeur) |
|
| 604 | + * |
|
| 605 | + * @var null|string |
|
| 606 | + */ |
|
| 607 | + public $not; |
|
| 608 | + |
|
| 609 | + /** |
|
| 610 | + * Présence d'une exclusion (!truc op valeur) |
|
| 611 | + * |
|
| 612 | + * @var null|string |
|
| 613 | + */ |
|
| 614 | + public $exclus; |
|
| 615 | + |
|
| 616 | + /** |
|
| 617 | + * Présence d'une condition dans le critère (truc ?) |
|
| 618 | + * |
|
| 619 | + * @var bool |
|
| 620 | + */ |
|
| 621 | + public $cond = false; |
|
| 622 | + |
|
| 623 | + /** |
|
| 624 | + * Paramètres du critère |
|
| 625 | + * - $param[0] : élément avant l'opérateur |
|
| 626 | + * - $param[1..n] : éléments après l'opérateur |
|
| 627 | + * |
|
| 628 | + * @var array |
|
| 629 | + */ |
|
| 630 | + public $param = []; |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * Numéro de ligne dans le code source du squelette |
|
| 634 | + * |
|
| 635 | + * @var int |
|
| 636 | + */ |
|
| 637 | + public $ligne = 0; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | /** |
@@ -643,139 +643,139 @@ discard block |
||
| 643 | 643 | * @package SPIP\Core\Compilateur\AST |
| 644 | 644 | **/ |
| 645 | 645 | class Champ { |
| 646 | - /** |
|
| 647 | - * Type de noeud |
|
| 648 | - * |
|
| 649 | - * @var string |
|
| 650 | - */ |
|
| 651 | - public $type = 'champ'; |
|
| 652 | - |
|
| 653 | - /** |
|
| 654 | - * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 655 | - * |
|
| 656 | - * @var string|null |
|
| 657 | - */ |
|
| 658 | - public $nom_champ; |
|
| 659 | - |
|
| 660 | - /** |
|
| 661 | - * Identifiant de la boucle parente si explicité |
|
| 662 | - * |
|
| 663 | - * @var string|null |
|
| 664 | - */ |
|
| 665 | - public $nom_boucle = ''; |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * Partie optionnelle avant |
|
| 669 | - * |
|
| 670 | - * @var null|string|array |
|
| 671 | - */ |
|
| 672 | - public $avant; |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * Partie optionnelle après |
|
| 676 | - * |
|
| 677 | - * @var null|string|array |
|
| 678 | - */ |
|
| 679 | - public $apres; |
|
| 680 | - |
|
| 681 | - /** |
|
| 682 | - * Étoiles : annuler des automatismes |
|
| 683 | - * |
|
| 684 | - * - '*' annule les filtres automatiques |
|
| 685 | - * - '**' annule en plus les protections de scripts |
|
| 686 | - * |
|
| 687 | - * @var null|string |
|
| 688 | - */ |
|
| 689 | - public $etoile; |
|
| 690 | - |
|
| 691 | - /** |
|
| 692 | - * Arguments et filtres explicites sur la balise |
|
| 693 | - * |
|
| 694 | - * - $param[0] contient les arguments de la balise |
|
| 695 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 696 | - * |
|
| 697 | - * @var array |
|
| 698 | - */ |
|
| 699 | - public $param = []; |
|
| 700 | - |
|
| 701 | - /** |
|
| 702 | - * Source des filtres (compatibilité) (?) |
|
| 703 | - * |
|
| 704 | - * @var array|null |
|
| 705 | - */ |
|
| 706 | - public $fonctions = []; |
|
| 707 | - |
|
| 708 | - /** |
|
| 709 | - * Identifiant de la boucle |
|
| 710 | - * |
|
| 711 | - * @var string |
|
| 712 | - */ |
|
| 713 | - public $id_boucle = ''; |
|
| 714 | - |
|
| 715 | - /** |
|
| 716 | - * AST du squelette, liste de toutes les boucles |
|
| 717 | - * |
|
| 718 | - * @var Boucles[] |
|
| 719 | - */ |
|
| 720 | - public $boucles; |
|
| 721 | - |
|
| 722 | - /** |
|
| 723 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 724 | - * |
|
| 725 | - * @var string|null |
|
| 726 | - */ |
|
| 727 | - public $type_requete; |
|
| 728 | - |
|
| 729 | - /** |
|
| 730 | - * Résultat de la compilation: toujours une expression PHP |
|
| 731 | - * |
|
| 732 | - * @var string |
|
| 733 | - */ |
|
| 734 | - public $code = ''; |
|
| 735 | - |
|
| 736 | - /** |
|
| 737 | - * Interdire les scripts |
|
| 738 | - * |
|
| 739 | - * false si on est sûr de cette balise |
|
| 740 | - * |
|
| 741 | - * @see interdire_scripts() |
|
| 742 | - * @var bool |
|
| 743 | - */ |
|
| 744 | - public $interdire_scripts = true; |
|
| 745 | - |
|
| 746 | - /** |
|
| 747 | - * Description du squelette |
|
| 748 | - * |
|
| 749 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 750 | - * |
|
| 751 | - * Peut contenir les index : |
|
| 752 | - * |
|
| 753 | - * - nom : Nom du fichier de cache |
|
| 754 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 755 | - * - sourcefile : Chemin du squelette |
|
| 756 | - * - squelette : Code du squelette |
|
| 757 | - * - id_mere : Identifiant de la boucle parente |
|
| 758 | - * - documents : Pour embed et img dans les textes |
|
| 759 | - * - session : Pour un cache sessionné par auteur |
|
| 760 | - * - niv : Niveau de tabulation |
|
| 761 | - * |
|
| 762 | - * @var array |
|
| 763 | - */ |
|
| 764 | - public $descr = []; |
|
| 765 | - |
|
| 766 | - /** |
|
| 767 | - * Numéro de ligne dans le code source du squelette |
|
| 768 | - * |
|
| 769 | - * @var int |
|
| 770 | - */ |
|
| 771 | - public $ligne = 0; |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 775 | - * |
|
| 776 | - * @var bool |
|
| 777 | - */ |
|
| 778 | - public $balise_calculee = false; |
|
| 646 | + /** |
|
| 647 | + * Type de noeud |
|
| 648 | + * |
|
| 649 | + * @var string |
|
| 650 | + */ |
|
| 651 | + public $type = 'champ'; |
|
| 652 | + |
|
| 653 | + /** |
|
| 654 | + * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 655 | + * |
|
| 656 | + * @var string|null |
|
| 657 | + */ |
|
| 658 | + public $nom_champ; |
|
| 659 | + |
|
| 660 | + /** |
|
| 661 | + * Identifiant de la boucle parente si explicité |
|
| 662 | + * |
|
| 663 | + * @var string|null |
|
| 664 | + */ |
|
| 665 | + public $nom_boucle = ''; |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * Partie optionnelle avant |
|
| 669 | + * |
|
| 670 | + * @var null|string|array |
|
| 671 | + */ |
|
| 672 | + public $avant; |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * Partie optionnelle après |
|
| 676 | + * |
|
| 677 | + * @var null|string|array |
|
| 678 | + */ |
|
| 679 | + public $apres; |
|
| 680 | + |
|
| 681 | + /** |
|
| 682 | + * Étoiles : annuler des automatismes |
|
| 683 | + * |
|
| 684 | + * - '*' annule les filtres automatiques |
|
| 685 | + * - '**' annule en plus les protections de scripts |
|
| 686 | + * |
|
| 687 | + * @var null|string |
|
| 688 | + */ |
|
| 689 | + public $etoile; |
|
| 690 | + |
|
| 691 | + /** |
|
| 692 | + * Arguments et filtres explicites sur la balise |
|
| 693 | + * |
|
| 694 | + * - $param[0] contient les arguments de la balise |
|
| 695 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 696 | + * |
|
| 697 | + * @var array |
|
| 698 | + */ |
|
| 699 | + public $param = []; |
|
| 700 | + |
|
| 701 | + /** |
|
| 702 | + * Source des filtres (compatibilité) (?) |
|
| 703 | + * |
|
| 704 | + * @var array|null |
|
| 705 | + */ |
|
| 706 | + public $fonctions = []; |
|
| 707 | + |
|
| 708 | + /** |
|
| 709 | + * Identifiant de la boucle |
|
| 710 | + * |
|
| 711 | + * @var string |
|
| 712 | + */ |
|
| 713 | + public $id_boucle = ''; |
|
| 714 | + |
|
| 715 | + /** |
|
| 716 | + * AST du squelette, liste de toutes les boucles |
|
| 717 | + * |
|
| 718 | + * @var Boucles[] |
|
| 719 | + */ |
|
| 720 | + public $boucles; |
|
| 721 | + |
|
| 722 | + /** |
|
| 723 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 724 | + * |
|
| 725 | + * @var string|null |
|
| 726 | + */ |
|
| 727 | + public $type_requete; |
|
| 728 | + |
|
| 729 | + /** |
|
| 730 | + * Résultat de la compilation: toujours une expression PHP |
|
| 731 | + * |
|
| 732 | + * @var string |
|
| 733 | + */ |
|
| 734 | + public $code = ''; |
|
| 735 | + |
|
| 736 | + /** |
|
| 737 | + * Interdire les scripts |
|
| 738 | + * |
|
| 739 | + * false si on est sûr de cette balise |
|
| 740 | + * |
|
| 741 | + * @see interdire_scripts() |
|
| 742 | + * @var bool |
|
| 743 | + */ |
|
| 744 | + public $interdire_scripts = true; |
|
| 745 | + |
|
| 746 | + /** |
|
| 747 | + * Description du squelette |
|
| 748 | + * |
|
| 749 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 750 | + * |
|
| 751 | + * Peut contenir les index : |
|
| 752 | + * |
|
| 753 | + * - nom : Nom du fichier de cache |
|
| 754 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 755 | + * - sourcefile : Chemin du squelette |
|
| 756 | + * - squelette : Code du squelette |
|
| 757 | + * - id_mere : Identifiant de la boucle parente |
|
| 758 | + * - documents : Pour embed et img dans les textes |
|
| 759 | + * - session : Pour un cache sessionné par auteur |
|
| 760 | + * - niv : Niveau de tabulation |
|
| 761 | + * |
|
| 762 | + * @var array |
|
| 763 | + */ |
|
| 764 | + public $descr = []; |
|
| 765 | + |
|
| 766 | + /** |
|
| 767 | + * Numéro de ligne dans le code source du squelette |
|
| 768 | + * |
|
| 769 | + * @var int |
|
| 770 | + */ |
|
| 771 | + public $ligne = 0; |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 775 | + * |
|
| 776 | + * @var bool |
|
| 777 | + */ |
|
| 778 | + public $balise_calculee = false; |
|
| 779 | 779 | } |
| 780 | 780 | |
| 781 | 781 | |
@@ -783,123 +783,123 @@ discard block |
||
| 783 | 783 | * Description d'une chaîne de langue |
| 784 | 784 | **/ |
| 785 | 785 | class Idiome { |
| 786 | - /** |
|
| 787 | - * Type de noeud |
|
| 788 | - * |
|
| 789 | - * @var string |
|
| 790 | - */ |
|
| 791 | - public $type = 'idiome'; |
|
| 792 | - |
|
| 793 | - /** |
|
| 794 | - * Clé de traduction demandée. Exemple 'item_oui' |
|
| 795 | - * |
|
| 796 | - * @var string |
|
| 797 | - */ |
|
| 798 | - public $nom_champ = ''; |
|
| 799 | - |
|
| 800 | - /** |
|
| 801 | - * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 802 | - * |
|
| 803 | - * @var string |
|
| 804 | - */ |
|
| 805 | - public $module = ''; |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * Arguments à passer à la chaîne |
|
| 809 | - * |
|
| 810 | - * @var array |
|
| 811 | - */ |
|
| 812 | - public $arg = []; |
|
| 813 | - |
|
| 814 | - /** |
|
| 815 | - * Filtres à appliquer au résultat |
|
| 816 | - * |
|
| 817 | - * @var array |
|
| 818 | - */ |
|
| 819 | - public $param = []; |
|
| 820 | - |
|
| 821 | - /** |
|
| 822 | - * Source des filtres (compatibilité) (?) |
|
| 823 | - * |
|
| 824 | - * @var array|null |
|
| 825 | - */ |
|
| 826 | - public $fonctions = []; |
|
| 827 | - |
|
| 828 | - /** |
|
| 829 | - * Inutilisé, propriété générique de l'AST |
|
| 830 | - * |
|
| 831 | - * @var string|array |
|
| 832 | - */ |
|
| 833 | - public $avant = ''; |
|
| 834 | - |
|
| 835 | - /** |
|
| 836 | - * Inutilisé, propriété générique de l'AST |
|
| 837 | - * |
|
| 838 | - * @var string|array |
|
| 839 | - */ |
|
| 840 | - public $apres = ''; |
|
| 841 | - |
|
| 842 | - /** |
|
| 843 | - * Identifiant de la boucle |
|
| 844 | - * |
|
| 845 | - * @var string |
|
| 846 | - */ |
|
| 847 | - public $id_boucle = ''; |
|
| 848 | - |
|
| 849 | - /** |
|
| 850 | - * AST du squelette, liste de toutes les boucles |
|
| 851 | - * |
|
| 852 | - * @var Boucles[] |
|
| 853 | - */ |
|
| 854 | - public $boucles; |
|
| 855 | - |
|
| 856 | - /** |
|
| 857 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 858 | - * |
|
| 859 | - * @var string|null |
|
| 860 | - */ |
|
| 861 | - public $type_requete; |
|
| 862 | - |
|
| 863 | - /** |
|
| 864 | - * Résultat de la compilation: toujours une expression PHP |
|
| 865 | - * |
|
| 866 | - * @var string |
|
| 867 | - */ |
|
| 868 | - public $code = ''; |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * Interdire les scripts |
|
| 872 | - * |
|
| 873 | - * @see interdire_scripts() |
|
| 874 | - * @var bool |
|
| 875 | - */ |
|
| 876 | - public $interdire_scripts = false; |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * Description du squelette |
|
| 880 | - * |
|
| 881 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 882 | - * |
|
| 883 | - * Peut contenir les index : |
|
| 884 | - * - nom : Nom du fichier de cache |
|
| 885 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 886 | - * - sourcefile : Chemin du squelette |
|
| 887 | - * - squelette : Code du squelette |
|
| 888 | - * - id_mere : Identifiant de la boucle parente |
|
| 889 | - * - documents : Pour embed et img dans les textes |
|
| 890 | - * - session : Pour un cache sessionné par auteur |
|
| 891 | - * - niv : Niveau de tabulation |
|
| 892 | - * |
|
| 893 | - * @var array |
|
| 894 | - */ |
|
| 895 | - public $descr = []; |
|
| 896 | - |
|
| 897 | - /** |
|
| 898 | - * Numéro de ligne dans le code source du squelette |
|
| 899 | - * |
|
| 900 | - * @var int |
|
| 901 | - */ |
|
| 902 | - public $ligne = 0; |
|
| 786 | + /** |
|
| 787 | + * Type de noeud |
|
| 788 | + * |
|
| 789 | + * @var string |
|
| 790 | + */ |
|
| 791 | + public $type = 'idiome'; |
|
| 792 | + |
|
| 793 | + /** |
|
| 794 | + * Clé de traduction demandée. Exemple 'item_oui' |
|
| 795 | + * |
|
| 796 | + * @var string |
|
| 797 | + */ |
|
| 798 | + public $nom_champ = ''; |
|
| 799 | + |
|
| 800 | + /** |
|
| 801 | + * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 802 | + * |
|
| 803 | + * @var string |
|
| 804 | + */ |
|
| 805 | + public $module = ''; |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * Arguments à passer à la chaîne |
|
| 809 | + * |
|
| 810 | + * @var array |
|
| 811 | + */ |
|
| 812 | + public $arg = []; |
|
| 813 | + |
|
| 814 | + /** |
|
| 815 | + * Filtres à appliquer au résultat |
|
| 816 | + * |
|
| 817 | + * @var array |
|
| 818 | + */ |
|
| 819 | + public $param = []; |
|
| 820 | + |
|
| 821 | + /** |
|
| 822 | + * Source des filtres (compatibilité) (?) |
|
| 823 | + * |
|
| 824 | + * @var array|null |
|
| 825 | + */ |
|
| 826 | + public $fonctions = []; |
|
| 827 | + |
|
| 828 | + /** |
|
| 829 | + * Inutilisé, propriété générique de l'AST |
|
| 830 | + * |
|
| 831 | + * @var string|array |
|
| 832 | + */ |
|
| 833 | + public $avant = ''; |
|
| 834 | + |
|
| 835 | + /** |
|
| 836 | + * Inutilisé, propriété générique de l'AST |
|
| 837 | + * |
|
| 838 | + * @var string|array |
|
| 839 | + */ |
|
| 840 | + public $apres = ''; |
|
| 841 | + |
|
| 842 | + /** |
|
| 843 | + * Identifiant de la boucle |
|
| 844 | + * |
|
| 845 | + * @var string |
|
| 846 | + */ |
|
| 847 | + public $id_boucle = ''; |
|
| 848 | + |
|
| 849 | + /** |
|
| 850 | + * AST du squelette, liste de toutes les boucles |
|
| 851 | + * |
|
| 852 | + * @var Boucles[] |
|
| 853 | + */ |
|
| 854 | + public $boucles; |
|
| 855 | + |
|
| 856 | + /** |
|
| 857 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 858 | + * |
|
| 859 | + * @var string|null |
|
| 860 | + */ |
|
| 861 | + public $type_requete; |
|
| 862 | + |
|
| 863 | + /** |
|
| 864 | + * Résultat de la compilation: toujours une expression PHP |
|
| 865 | + * |
|
| 866 | + * @var string |
|
| 867 | + */ |
|
| 868 | + public $code = ''; |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * Interdire les scripts |
|
| 872 | + * |
|
| 873 | + * @see interdire_scripts() |
|
| 874 | + * @var bool |
|
| 875 | + */ |
|
| 876 | + public $interdire_scripts = false; |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * Description du squelette |
|
| 880 | + * |
|
| 881 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 882 | + * |
|
| 883 | + * Peut contenir les index : |
|
| 884 | + * - nom : Nom du fichier de cache |
|
| 885 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 886 | + * - sourcefile : Chemin du squelette |
|
| 887 | + * - squelette : Code du squelette |
|
| 888 | + * - id_mere : Identifiant de la boucle parente |
|
| 889 | + * - documents : Pour embed et img dans les textes |
|
| 890 | + * - session : Pour un cache sessionné par auteur |
|
| 891 | + * - niv : Niveau de tabulation |
|
| 892 | + * |
|
| 893 | + * @var array |
|
| 894 | + */ |
|
| 895 | + public $descr = []; |
|
| 896 | + |
|
| 897 | + /** |
|
| 898 | + * Numéro de ligne dans le code source du squelette |
|
| 899 | + * |
|
| 900 | + * @var int |
|
| 901 | + */ |
|
| 902 | + public $ligne = 0; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -908,28 +908,28 @@ discard block |
||
| 908 | 908 | * @package SPIP\Core\Compilateur\AST |
| 909 | 909 | **/ |
| 910 | 910 | class Polyglotte { |
| 911 | - /** |
|
| 912 | - * Type de noeud |
|
| 913 | - * |
|
| 914 | - * @var string |
|
| 915 | - */ |
|
| 916 | - public $type = 'polyglotte'; |
|
| 917 | - |
|
| 918 | - /** |
|
| 919 | - * Tableau des traductions possibles classées par langue |
|
| 920 | - * |
|
| 921 | - * Tableau code de langue => texte |
|
| 922 | - * |
|
| 923 | - * @var array |
|
| 924 | - */ |
|
| 925 | - public $traductions = []; |
|
| 926 | - |
|
| 927 | - /** |
|
| 928 | - * Numéro de ligne dans le code source du squelette |
|
| 929 | - * |
|
| 930 | - * @var int |
|
| 931 | - */ |
|
| 932 | - public $ligne = 0; |
|
| 911 | + /** |
|
| 912 | + * Type de noeud |
|
| 913 | + * |
|
| 914 | + * @var string |
|
| 915 | + */ |
|
| 916 | + public $type = 'polyglotte'; |
|
| 917 | + |
|
| 918 | + /** |
|
| 919 | + * Tableau des traductions possibles classées par langue |
|
| 920 | + * |
|
| 921 | + * Tableau code de langue => texte |
|
| 922 | + * |
|
| 923 | + * @var array |
|
| 924 | + */ |
|
| 925 | + public $traductions = []; |
|
| 926 | + |
|
| 927 | + /** |
|
| 928 | + * Numéro de ligne dans le code source du squelette |
|
| 929 | + * |
|
| 930 | + * @var int |
|
| 931 | + */ |
|
| 932 | + public $ligne = 0; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | |
@@ -952,90 +952,90 @@ discard block |
||
| 952 | 952 | */ |
| 953 | 953 | function declarer_interfaces() { |
| 954 | 954 | |
| 955 | - $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 956 | - $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 957 | - $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 958 | - $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 959 | - |
|
| 960 | - // definition des statuts de publication |
|
| 961 | - $GLOBALS['table_statut'] = []; |
|
| 962 | - |
|
| 963 | - // |
|
| 964 | - // tableau des tables de jointures |
|
| 965 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 966 | - $GLOBALS['tables_jointures'] = []; |
|
| 967 | - $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 968 | - |
|
| 969 | - // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 970 | - $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 971 | - |
|
| 972 | - |
|
| 973 | - if (!defined('_TRAITEMENT_TYPO')) { |
|
| 974 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 975 | - } |
|
| 976 | - if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 977 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 978 | - } |
|
| 979 | - if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 980 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 981 | - } |
|
| 982 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 983 | - $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 984 | - $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 985 | - $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 986 | - $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 987 | - $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 988 | - $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 989 | - $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 990 | - $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 991 | - $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 992 | - $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 993 | - $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 994 | - $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 995 | - $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 996 | - $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 997 | - $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 998 | - $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 999 | - $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 1000 | - $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1001 | - $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 1002 | - $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 1003 | - $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1004 | - $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 1005 | - $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 1006 | - |
|
| 1007 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 1008 | - $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 1009 | - // toujours securiser les DATA |
|
| 1010 | - $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 1011 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 1012 | - $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 1013 | - |
|
| 1014 | - |
|
| 1015 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1016 | - $interfaces = pipeline( |
|
| 1017 | - 'declarer_tables_interfaces', |
|
| 1018 | - [ |
|
| 1019 | - 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1020 | - 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1021 | - 'table_date' => $GLOBALS['table_date'], |
|
| 1022 | - 'table_titre' => $GLOBALS['table_titre'], |
|
| 1023 | - 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1024 | - 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1025 | - 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1026 | - 'table_statut' => $GLOBALS['table_statut'], |
|
| 1027 | - ] |
|
| 1028 | - ); |
|
| 1029 | - if ($interfaces) { |
|
| 1030 | - $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1031 | - $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1032 | - $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1033 | - $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1034 | - $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1035 | - $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1036 | - $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1037 | - $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1038 | - } |
|
| 955 | + $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 956 | + $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 957 | + $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 958 | + $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 959 | + |
|
| 960 | + // definition des statuts de publication |
|
| 961 | + $GLOBALS['table_statut'] = []; |
|
| 962 | + |
|
| 963 | + // |
|
| 964 | + // tableau des tables de jointures |
|
| 965 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 966 | + $GLOBALS['tables_jointures'] = []; |
|
| 967 | + $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 968 | + |
|
| 969 | + // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 970 | + $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 971 | + |
|
| 972 | + |
|
| 973 | + if (!defined('_TRAITEMENT_TYPO')) { |
|
| 974 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 975 | + } |
|
| 976 | + if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 977 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 978 | + } |
|
| 979 | + if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 980 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 981 | + } |
|
| 982 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 983 | + $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 984 | + $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 985 | + $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 986 | + $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 987 | + $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 988 | + $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 989 | + $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 990 | + $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 991 | + $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 992 | + $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 993 | + $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 994 | + $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 995 | + $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 996 | + $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 997 | + $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 998 | + $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 999 | + $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 1000 | + $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1001 | + $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 1002 | + $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 1003 | + $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 1004 | + $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 1005 | + $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 1006 | + |
|
| 1007 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 1008 | + $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 1009 | + // toujours securiser les DATA |
|
| 1010 | + $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 1011 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 1012 | + $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 1013 | + |
|
| 1014 | + |
|
| 1015 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 1016 | + $interfaces = pipeline( |
|
| 1017 | + 'declarer_tables_interfaces', |
|
| 1018 | + [ |
|
| 1019 | + 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 1020 | + 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 1021 | + 'table_date' => $GLOBALS['table_date'], |
|
| 1022 | + 'table_titre' => $GLOBALS['table_titre'], |
|
| 1023 | + 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 1024 | + 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 1025 | + 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 1026 | + 'table_statut' => $GLOBALS['table_statut'], |
|
| 1027 | + ] |
|
| 1028 | + ); |
|
| 1029 | + if ($interfaces) { |
|
| 1030 | + $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 1031 | + $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 1032 | + $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 1033 | + $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 1034 | + $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 1035 | + $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 1036 | + $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 1037 | + $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 1038 | + } |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | declarer_interfaces(); |
@@ -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/presentation'); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @uses exec_puce_statut_args() |
| 32 | 32 | **/ |
| 33 | 33 | function exec_puce_statut_dist(): void { |
| 34 | - exec_puce_statut_args(_request('id'), _request('type')); |
|
| 34 | + exec_puce_statut_args(_request('id'), _request('type')); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -50,26 +50,26 @@ discard block |
||
| 50 | 50 | * Type d'objet |
| 51 | 51 | **/ |
| 52 | 52 | function exec_puce_statut_args($id, $type): void { |
| 53 | - $id = intval($id); |
|
| 54 | - if ( |
|
| 55 | - $table_objet_sql = table_objet_sql($type) |
|
| 56 | - and $d = lister_tables_objets_sql($table_objet_sql) |
|
| 57 | - and isset($d['statut_textes_instituer']) |
|
| 58 | - and $d['statut_textes_instituer'] |
|
| 59 | - ) { |
|
| 60 | - $prim = id_table_objet($type); |
|
| 61 | - if (isset($d['field']['id_rubrique'])) { |
|
| 62 | - $select = 'id_rubrique,statut'; |
|
| 63 | - } else { |
|
| 64 | - $select = '0 as id_rubrique,statut'; |
|
| 65 | - } |
|
| 66 | - $r = sql_fetsel($select, $table_objet_sql, "$prim=$id"); |
|
| 67 | - $statut = $r['statut']; |
|
| 68 | - $id_rubrique = $r['id_rubrique']; |
|
| 69 | - } else { |
|
| 70 | - $id_rubrique = $id; |
|
| 71 | - $statut = 'prop'; // arbitraire |
|
| 72 | - } |
|
| 73 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 74 | - ajax_retour($puce_statut($id, $statut, $id_rubrique, $type, true)); |
|
| 53 | + $id = intval($id); |
|
| 54 | + if ( |
|
| 55 | + $table_objet_sql = table_objet_sql($type) |
|
| 56 | + and $d = lister_tables_objets_sql($table_objet_sql) |
|
| 57 | + and isset($d['statut_textes_instituer']) |
|
| 58 | + and $d['statut_textes_instituer'] |
|
| 59 | + ) { |
|
| 60 | + $prim = id_table_objet($type); |
|
| 61 | + if (isset($d['field']['id_rubrique'])) { |
|
| 62 | + $select = 'id_rubrique,statut'; |
|
| 63 | + } else { |
|
| 64 | + $select = '0 as id_rubrique,statut'; |
|
| 65 | + } |
|
| 66 | + $r = sql_fetsel($select, $table_objet_sql, "$prim=$id"); |
|
| 67 | + $statut = $r['statut']; |
|
| 68 | + $id_rubrique = $r['id_rubrique']; |
|
| 69 | + } else { |
|
| 70 | + $id_rubrique = $id; |
|
| 71 | + $statut = 'prop'; // arbitraire |
|
| 72 | + } |
|
| 73 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 74 | + ajax_retour($puce_statut($id, $statut, $id_rubrique, $type, true)); |
|
| 75 | 75 | } |
@@ -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('base/abstract_sql'); |
@@ -35,33 +35,33 @@ discard block |
||
| 35 | 35 | * - une chaîne vide si autorisation à pénétrer dans l'espace privé. |
| 36 | 36 | */ |
| 37 | 37 | function inc_auth_dist() { |
| 38 | - $row = auth_mode(); |
|
| 38 | + $row = auth_mode(); |
|
| 39 | 39 | |
| 40 | - if ($row) { |
|
| 41 | - return auth_init_droits($row); |
|
| 42 | - } |
|
| 40 | + if ($row) { |
|
| 41 | + return auth_init_droits($row); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if (!$GLOBALS['connect_login']) { |
|
| 45 | - return auth_a_loger(); |
|
| 46 | - } |
|
| 44 | + if (!$GLOBALS['connect_login']) { |
|
| 45 | + return auth_a_loger(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 49 | - // C'est soit parce que la base est inutilisable, |
|
| 50 | - // soit parce que la table des auteurs a changee (restauration etc) |
|
| 51 | - // Pas la peine d'insister. |
|
| 52 | - // Renvoyer le nom fautif et une URL de remise a zero |
|
| 48 | + // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 49 | + // C'est soit parce que la base est inutilisable, |
|
| 50 | + // soit parce que la table des auteurs a changee (restauration etc) |
|
| 51 | + // Pas la peine d'insister. |
|
| 52 | + // Renvoyer le nom fautif et une URL de remise a zero |
|
| 53 | 53 | |
| 54 | - if (spip_connect()) { |
|
| 55 | - return [ |
|
| 56 | - 'login' => $GLOBALS['connect_login'], |
|
| 57 | - 'site' => generer_url_public('', 'action=logout&logout=prive') |
|
| 58 | - ]; |
|
| 59 | - } |
|
| 54 | + if (spip_connect()) { |
|
| 55 | + return [ |
|
| 56 | + 'login' => $GLOBALS['connect_login'], |
|
| 57 | + 'site' => generer_url_public('', 'action=logout&logout=prive') |
|
| 58 | + ]; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $n = intval(sql_errno()); |
|
| 62 | - spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 61 | + $n = intval(sql_errno()); |
|
| 62 | + spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 63 | 63 | |
| 64 | - return $n ?: 1; |
|
| 64 | + return $n ?: 1; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -73,39 +73,39 @@ discard block |
||
| 73 | 73 | * @return array|string |
| 74 | 74 | */ |
| 75 | 75 | function auth_echec($raison) { |
| 76 | - include_spip('inc/minipres'); |
|
| 77 | - include_spip('inc/headers'); |
|
| 78 | - // pas authentifie. Pourquoi ? |
|
| 79 | - if (is_string($raison)) { |
|
| 80 | - // redirection vers une page d'authentification |
|
| 81 | - // on ne revient pas de cette fonction |
|
| 82 | - // sauf si pb de header |
|
| 83 | - $raison = redirige_formulaire($raison); |
|
| 84 | - } elseif (is_int($raison)) { |
|
| 85 | - // erreur SQL a afficher |
|
| 86 | - $raison = minipres( |
|
| 87 | - _T('info_travaux_titre'), |
|
| 88 | - _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 89 | - ); |
|
| 90 | - } elseif (@$raison['statut']) { |
|
| 91 | - // un simple visiteur n'a pas acces a l'espace prive |
|
| 92 | - spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 93 | - $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 94 | - } else { |
|
| 95 | - // auteur en fin de droits ... |
|
| 96 | - $h = $raison['site']; |
|
| 97 | - $raison = minipres( |
|
| 98 | - _T('avis_erreur_connexion'), |
|
| 99 | - '<br /><br /><p>' |
|
| 100 | - . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 101 | - . " <a href='$h'>" |
|
| 102 | - . _T('texte_inc_auth_2') |
|
| 103 | - . '</a>' |
|
| 104 | - . _T('texte_inc_auth_3') |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $raison; |
|
| 76 | + include_spip('inc/minipres'); |
|
| 77 | + include_spip('inc/headers'); |
|
| 78 | + // pas authentifie. Pourquoi ? |
|
| 79 | + if (is_string($raison)) { |
|
| 80 | + // redirection vers une page d'authentification |
|
| 81 | + // on ne revient pas de cette fonction |
|
| 82 | + // sauf si pb de header |
|
| 83 | + $raison = redirige_formulaire($raison); |
|
| 84 | + } elseif (is_int($raison)) { |
|
| 85 | + // erreur SQL a afficher |
|
| 86 | + $raison = minipres( |
|
| 87 | + _T('info_travaux_titre'), |
|
| 88 | + _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 89 | + ); |
|
| 90 | + } elseif (@$raison['statut']) { |
|
| 91 | + // un simple visiteur n'a pas acces a l'espace prive |
|
| 92 | + spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 93 | + $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 94 | + } else { |
|
| 95 | + // auteur en fin de droits ... |
|
| 96 | + $h = $raison['site']; |
|
| 97 | + $raison = minipres( |
|
| 98 | + _T('avis_erreur_connexion'), |
|
| 99 | + '<br /><br /><p>' |
|
| 100 | + . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 101 | + . " <a href='$h'>" |
|
| 102 | + . _T('texte_inc_auth_2') |
|
| 103 | + . '</a>' |
|
| 104 | + . _T('texte_inc_auth_3') |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return $raison; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,81 +115,81 @@ discard block |
||
| 115 | 115 | * @return array|bool|string |
| 116 | 116 | */ |
| 117 | 117 | function auth_mode() { |
| 118 | - // |
|
| 119 | - // Initialiser variables (eviter hacks par URL) |
|
| 120 | - // |
|
| 121 | - $GLOBALS['connect_login'] = ''; |
|
| 122 | - $id_auteur = null; |
|
| 123 | - $GLOBALS['auth_can_disconnect'] = false; |
|
| 124 | - |
|
| 125 | - // |
|
| 126 | - // Recuperer les donnees d'identification |
|
| 127 | - // |
|
| 128 | - include_spip('inc/session'); |
|
| 129 | - // Session valide en cours ? |
|
| 130 | - if (isset($_COOKIE['spip_session'])) { |
|
| 131 | - $session = charger_fonction('session', 'inc'); |
|
| 132 | - if ( |
|
| 133 | - $id_auteur = $session() |
|
| 134 | - or $id_auteur === 0 // reprise sur restauration |
|
| 135 | - ) { |
|
| 136 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 137 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 138 | - } else { |
|
| 139 | - unset($_COOKIE['spip_session']); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // Essayer auth http si significatif |
|
| 144 | - // (ignorer les login d'intranet independants de spip) |
|
| 145 | - if (!$GLOBALS['ignore_auth_http']) { |
|
| 146 | - if ( |
|
| 147 | - (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) |
|
| 148 | - and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 149 | - or |
|
| 150 | - // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 151 | - // est indisponible mais tentons quand meme pour |
|
| 152 | - // autocreation via LDAP |
|
| 153 | - (isset($_SERVER['REMOTE_USER']) |
|
| 154 | - and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 155 | - ) { |
|
| 156 | - if (!$id_auteur) { |
|
| 157 | - $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 158 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 159 | - $GLOBALS['visiteur_session'] = $r; |
|
| 160 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 161 | - $id_auteur = $r['id_auteur']; |
|
| 162 | - } else { |
|
| 163 | - // cas de la session en plus de PHP_AUTH |
|
| 164 | - /* if ($id_auteur != $r['id_auteur']){ |
|
| 118 | + // |
|
| 119 | + // Initialiser variables (eviter hacks par URL) |
|
| 120 | + // |
|
| 121 | + $GLOBALS['connect_login'] = ''; |
|
| 122 | + $id_auteur = null; |
|
| 123 | + $GLOBALS['auth_can_disconnect'] = false; |
|
| 124 | + |
|
| 125 | + // |
|
| 126 | + // Recuperer les donnees d'identification |
|
| 127 | + // |
|
| 128 | + include_spip('inc/session'); |
|
| 129 | + // Session valide en cours ? |
|
| 130 | + if (isset($_COOKIE['spip_session'])) { |
|
| 131 | + $session = charger_fonction('session', 'inc'); |
|
| 132 | + if ( |
|
| 133 | + $id_auteur = $session() |
|
| 134 | + or $id_auteur === 0 // reprise sur restauration |
|
| 135 | + ) { |
|
| 136 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 137 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 138 | + } else { |
|
| 139 | + unset($_COOKIE['spip_session']); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // Essayer auth http si significatif |
|
| 144 | + // (ignorer les login d'intranet independants de spip) |
|
| 145 | + if (!$GLOBALS['ignore_auth_http']) { |
|
| 146 | + if ( |
|
| 147 | + (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) |
|
| 148 | + and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 149 | + or |
|
| 150 | + // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 151 | + // est indisponible mais tentons quand meme pour |
|
| 152 | + // autocreation via LDAP |
|
| 153 | + (isset($_SERVER['REMOTE_USER']) |
|
| 154 | + and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 155 | + ) { |
|
| 156 | + if (!$id_auteur) { |
|
| 157 | + $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 158 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 159 | + $GLOBALS['visiteur_session'] = $r; |
|
| 160 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 161 | + $id_auteur = $r['id_auteur']; |
|
| 162 | + } else { |
|
| 163 | + // cas de la session en plus de PHP_AUTH |
|
| 164 | + /* if ($id_auteur != $r['id_auteur']){ |
|
| 165 | 165 | spip_log("vol de session $id_auteur" . join(', ', $r)); |
| 166 | 166 | unset($_COOKIE['spip_session']); |
| 167 | 167 | $id_auteur = ''; |
| 168 | 168 | } */ |
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - // Authentification .htaccess old style, car .htaccess semble |
|
| 172 | - // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 173 | - if (isset($_SERVER['REMOTE_USER'])) { |
|
| 174 | - $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $where = (is_numeric($id_auteur) |
|
| 180 | - /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 181 | - ) ? |
|
| 182 | - "id_auteur=$id_auteur" : |
|
| 183 | - (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text')); |
|
| 184 | - |
|
| 185 | - if (!$where) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Trouver les autres infos dans la table auteurs. |
|
| 190 | - // le champ 'quand' est utilise par l'agenda |
|
| 191 | - |
|
| 192 | - return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + // Authentification .htaccess old style, car .htaccess semble |
|
| 172 | + // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 173 | + if (isset($_SERVER['REMOTE_USER'])) { |
|
| 174 | + $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $where = (is_numeric($id_auteur) |
|
| 180 | + /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 181 | + ) ? |
|
| 182 | + "id_auteur=$id_auteur" : |
|
| 183 | + (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text')); |
|
| 184 | + |
|
| 185 | + if (!$where) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Trouver les autres infos dans la table auteurs. |
|
| 190 | + // le champ 'quand' est utilise par l'agenda |
|
| 191 | + |
|
| 192 | + return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -207,86 +207,86 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | function auth_init_droits($row) { |
| 209 | 209 | |
| 210 | - include_spip('inc/autoriser'); |
|
| 211 | - if (!autoriser('loger', '', 0, $row)) { |
|
| 212 | - return false; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - if ($row['statut'] == 'nouveau') { |
|
| 217 | - include_spip('action/inscrire_auteur'); |
|
| 218 | - $row = confirmer_statut_inscription($row); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 222 | - $GLOBALS['connect_login'] = $row['login']; |
|
| 223 | - $GLOBALS['connect_statut'] = $row['statut']; |
|
| 224 | - |
|
| 225 | - $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 226 | - |
|
| 227 | - // au cas ou : ne pas memoriser les champs sensibles |
|
| 228 | - unset($GLOBALS['visiteur_session']['pass']); |
|
| 229 | - unset($GLOBALS['visiteur_session']['htpass']); |
|
| 230 | - unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 231 | - unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 232 | - unset($GLOBALS['visiteur_session']['ldap_password']); |
|
| 233 | - |
|
| 234 | - // creer la session au besoin |
|
| 235 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 236 | - $session = charger_fonction('session', 'inc'); |
|
| 237 | - $spip_session = $session($row); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 241 | - // car utilisees au retour par auth_loger() |
|
| 242 | - $r = @unserialize($row['prefs']); |
|
| 243 | - $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 244 | - // si prefs pas definies, les definir par defaut |
|
| 245 | - if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 246 | - $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 247 | - $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 248 | - $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 249 | - $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui'; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $GLOBALS['visiteur_session'] = pipeline( |
|
| 253 | - 'preparer_visiteur_session', |
|
| 254 | - ['args' => ['row' => $row], |
|
| 255 | - 'data' => $GLOBALS['visiteur_session']] |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - // Etablir les droits selon le codage attendu |
|
| 259 | - // dans ecrire/index.php ecrire/prive.php |
|
| 260 | - |
|
| 261 | - // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 262 | - // A noter : le premier appel a autoriser() a le bon gout |
|
| 263 | - // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 264 | - // qui ne figure pas dans le fichier de session |
|
| 265 | - |
|
| 266 | - if (!autoriser('ecrire')) { |
|
| 267 | - return $row; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 271 | - |
|
| 272 | - auth_trace($row); |
|
| 273 | - |
|
| 274 | - // Administrateurs |
|
| 275 | - if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 276 | - if ( |
|
| 277 | - isset($GLOBALS['visiteur_session']['restreint']) |
|
| 278 | - and is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 279 | - ) { |
|
| 280 | - $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 281 | - } |
|
| 282 | - if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 283 | - $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 288 | - |
|
| 289 | - return ''; // i.e. pas de pb. |
|
| 210 | + include_spip('inc/autoriser'); |
|
| 211 | + if (!autoriser('loger', '', 0, $row)) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + if ($row['statut'] == 'nouveau') { |
|
| 217 | + include_spip('action/inscrire_auteur'); |
|
| 218 | + $row = confirmer_statut_inscription($row); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 222 | + $GLOBALS['connect_login'] = $row['login']; |
|
| 223 | + $GLOBALS['connect_statut'] = $row['statut']; |
|
| 224 | + |
|
| 225 | + $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 226 | + |
|
| 227 | + // au cas ou : ne pas memoriser les champs sensibles |
|
| 228 | + unset($GLOBALS['visiteur_session']['pass']); |
|
| 229 | + unset($GLOBALS['visiteur_session']['htpass']); |
|
| 230 | + unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 231 | + unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 232 | + unset($GLOBALS['visiteur_session']['ldap_password']); |
|
| 233 | + |
|
| 234 | + // creer la session au besoin |
|
| 235 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 236 | + $session = charger_fonction('session', 'inc'); |
|
| 237 | + $spip_session = $session($row); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 241 | + // car utilisees au retour par auth_loger() |
|
| 242 | + $r = @unserialize($row['prefs']); |
|
| 243 | + $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 244 | + // si prefs pas definies, les definir par defaut |
|
| 245 | + if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 246 | + $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 247 | + $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 248 | + $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 249 | + $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui'; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $GLOBALS['visiteur_session'] = pipeline( |
|
| 253 | + 'preparer_visiteur_session', |
|
| 254 | + ['args' => ['row' => $row], |
|
| 255 | + 'data' => $GLOBALS['visiteur_session']] |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + // Etablir les droits selon le codage attendu |
|
| 259 | + // dans ecrire/index.php ecrire/prive.php |
|
| 260 | + |
|
| 261 | + // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 262 | + // A noter : le premier appel a autoriser() a le bon gout |
|
| 263 | + // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 264 | + // qui ne figure pas dans le fichier de session |
|
| 265 | + |
|
| 266 | + if (!autoriser('ecrire')) { |
|
| 267 | + return $row; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 271 | + |
|
| 272 | + auth_trace($row); |
|
| 273 | + |
|
| 274 | + // Administrateurs |
|
| 275 | + if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 276 | + if ( |
|
| 277 | + isset($GLOBALS['visiteur_session']['restreint']) |
|
| 278 | + and is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 279 | + ) { |
|
| 280 | + $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 281 | + } |
|
| 282 | + if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 283 | + $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 288 | + |
|
| 289 | + return ''; // i.e. pas de pb. |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -295,23 +295,23 @@ discard block |
||
| 295 | 295 | * @return string |
| 296 | 296 | */ |
| 297 | 297 | function auth_a_loger() { |
| 298 | - $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), true); |
|
| 299 | - |
|
| 300 | - // un echec au "bonjour" (login initial) quand le statut est |
|
| 301 | - // inconnu signale sans doute un probleme de cookies |
|
| 302 | - if (isset($_GET['bonjour'])) { |
|
| 303 | - $redirect = parametre_url( |
|
| 304 | - $redirect, |
|
| 305 | - 'var_erreur', |
|
| 306 | - (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 307 | - ? 'cookie' |
|
| 308 | - : 'statut' |
|
| 309 | - ), |
|
| 310 | - '&' |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $redirect; |
|
| 298 | + $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), true); |
|
| 299 | + |
|
| 300 | + // un echec au "bonjour" (login initial) quand le statut est |
|
| 301 | + // inconnu signale sans doute un probleme de cookies |
|
| 302 | + if (isset($_GET['bonjour'])) { |
|
| 303 | + $redirect = parametre_url( |
|
| 304 | + $redirect, |
|
| 305 | + 'var_erreur', |
|
| 306 | + (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 307 | + ? 'cookie' |
|
| 308 | + : 'statut' |
|
| 309 | + ), |
|
| 310 | + '&' |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $redirect; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -323,19 +323,19 @@ discard block |
||
| 323 | 323 | * @param null|string $date |
| 324 | 324 | */ |
| 325 | 325 | function auth_trace($row, $date = null) { |
| 326 | - // Indiquer la connexion. A la minute pres ca suffit. |
|
| 327 | - if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 328 | - $connect_quand = strtotime($connect_quand); |
|
| 329 | - } |
|
| 326 | + // Indiquer la connexion. A la minute pres ca suffit. |
|
| 327 | + if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 328 | + $connect_quand = strtotime($connect_quand); |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - $date ??= date('Y-m-d H:i:s'); |
|
| 331 | + $date ??= date('Y-m-d H:i:s'); |
|
| 332 | 332 | |
| 333 | - if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 334 | - sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 335 | - $row['en_ligne'] = $date; |
|
| 336 | - } |
|
| 333 | + if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 334 | + sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 335 | + $row['en_ligne'] = $date; |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 338 | + pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -361,28 +361,28 @@ discard block |
||
| 361 | 361 | * @return mixed |
| 362 | 362 | */ |
| 363 | 363 | function auth_administrer($fonction, $args, $defaut = false) { |
| 364 | - $auth_methode = array_shift($args); |
|
| 365 | - $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 366 | - if ( |
|
| 367 | - $auth = charger_fonction($auth_methode, 'auth', true) |
|
| 368 | - and function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 369 | - ) { |
|
| 370 | - $res = $f(...$args); |
|
| 371 | - } else { |
|
| 372 | - $res = $defaut; |
|
| 373 | - } |
|
| 374 | - $res = pipeline( |
|
| 375 | - 'auth_administrer', |
|
| 376 | - [ |
|
| 377 | - 'args' => [ |
|
| 378 | - 'fonction' => $fonction, |
|
| 379 | - 'methode' => $auth_methode, |
|
| 380 | - 'args' => $args |
|
| 381 | - ], |
|
| 382 | - 'data' => $res |
|
| 383 | - ] |
|
| 384 | - ); |
|
| 385 | - return $res; |
|
| 364 | + $auth_methode = array_shift($args); |
|
| 365 | + $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 366 | + if ( |
|
| 367 | + $auth = charger_fonction($auth_methode, 'auth', true) |
|
| 368 | + and function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 369 | + ) { |
|
| 370 | + $res = $f(...$args); |
|
| 371 | + } else { |
|
| 372 | + $res = $defaut; |
|
| 373 | + } |
|
| 374 | + $res = pipeline( |
|
| 375 | + 'auth_administrer', |
|
| 376 | + [ |
|
| 377 | + 'args' => [ |
|
| 378 | + 'fonction' => $fonction, |
|
| 379 | + 'methode' => $auth_methode, |
|
| 380 | + 'args' => $args |
|
| 381 | + ], |
|
| 382 | + 'data' => $res |
|
| 383 | + ] |
|
| 384 | + ); |
|
| 385 | + return $res; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -392,11 +392,11 @@ discard block |
||
| 392 | 392 | * @return array |
| 393 | 393 | */ |
| 394 | 394 | function auth_formulaire_login($flux) { |
| 395 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 396 | - $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 397 | - } |
|
| 395 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 396 | + $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - return $flux; |
|
| 399 | + return $flux; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -410,19 +410,19 @@ discard block |
||
| 410 | 410 | * @return string/bool |
| 411 | 411 | */ |
| 412 | 412 | function auth_retrouver_login($login, $serveur = '') { |
| 413 | - if (!spip_connect($serveur)) { |
|
| 414 | - include_spip('inc/minipres'); |
|
| 415 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 416 | - exit; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 420 | - if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 421 | - return $auteur; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return false; |
|
| 413 | + if (!spip_connect($serveur)) { |
|
| 414 | + include_spip('inc/minipres'); |
|
| 415 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 416 | + exit; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 420 | + if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 421 | + return $auteur; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return false; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -437,52 +437,52 @@ discard block |
||
| 437 | 437 | * @return array |
| 438 | 438 | */ |
| 439 | 439 | function auth_informer_login($login, $serveur = '') { |
| 440 | - if ( |
|
| 441 | - !$login |
|
| 442 | - or !$login_base = auth_retrouver_login($login, $serveur) |
|
| 443 | - or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 444 | - ) { |
|
| 445 | - // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 446 | - // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 447 | - include_spip('inc/securiser_action'); |
|
| 448 | - $fauxalea1 = md5('fauxalea' . secret_du_site() . $login . floor(date('U') / 86400)); |
|
| 449 | - $fauxalea2 = md5('fauxalea' . secret_du_site() . $login . ceil(date('U') / 86400)); |
|
| 450 | - |
|
| 451 | - $row = [ |
|
| 452 | - 'login' => $login, |
|
| 453 | - 'cnx' => '0', |
|
| 454 | - 'logo' => '', |
|
| 455 | - 'alea_actuel' => substr_replace($fauxalea1, '.', 24, 0), |
|
| 456 | - 'alea_futur' => substr_replace($fauxalea2, '.', 24, 0) |
|
| 457 | - ]; |
|
| 458 | - |
|
| 459 | - // permettre d'autoriser l'envoi de password non crypte lorsque |
|
| 460 | - // l'auteur n'est pas (encore) declare dans SPIP, par exemple pour les cas |
|
| 461 | - // de premiere authentification via SPIP a une autre application. |
|
| 462 | - if (defined('_AUTORISER_AUTH_FAIBLE') and _AUTORISER_AUTH_FAIBLE) { |
|
| 463 | - $row['alea_actuel'] = ''; |
|
| 464 | - $row['alea_futur'] = ''; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - return $row; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $prefs = @unserialize($row['prefs']); |
|
| 471 | - $infos = [ |
|
| 472 | - 'id_auteur' => $row['id_auteur'], |
|
| 473 | - 'login' => $row['login'], |
|
| 474 | - 'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 475 | - 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 476 | - ]; |
|
| 477 | - |
|
| 478 | - // desactiver le hash md5 si pas auteur spip ? |
|
| 479 | - if ($row['source'] !== 'spip') { |
|
| 480 | - $row['alea_actuel'] = ''; |
|
| 481 | - $row['alea_futur'] = ''; |
|
| 482 | - } |
|
| 483 | - verifier_visiteur(); |
|
| 484 | - |
|
| 485 | - return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 440 | + if ( |
|
| 441 | + !$login |
|
| 442 | + or !$login_base = auth_retrouver_login($login, $serveur) |
|
| 443 | + or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 444 | + ) { |
|
| 445 | + // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 446 | + // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 447 | + include_spip('inc/securiser_action'); |
|
| 448 | + $fauxalea1 = md5('fauxalea' . secret_du_site() . $login . floor(date('U') / 86400)); |
|
| 449 | + $fauxalea2 = md5('fauxalea' . secret_du_site() . $login . ceil(date('U') / 86400)); |
|
| 450 | + |
|
| 451 | + $row = [ |
|
| 452 | + 'login' => $login, |
|
| 453 | + 'cnx' => '0', |
|
| 454 | + 'logo' => '', |
|
| 455 | + 'alea_actuel' => substr_replace($fauxalea1, '.', 24, 0), |
|
| 456 | + 'alea_futur' => substr_replace($fauxalea2, '.', 24, 0) |
|
| 457 | + ]; |
|
| 458 | + |
|
| 459 | + // permettre d'autoriser l'envoi de password non crypte lorsque |
|
| 460 | + // l'auteur n'est pas (encore) declare dans SPIP, par exemple pour les cas |
|
| 461 | + // de premiere authentification via SPIP a une autre application. |
|
| 462 | + if (defined('_AUTORISER_AUTH_FAIBLE') and _AUTORISER_AUTH_FAIBLE) { |
|
| 463 | + $row['alea_actuel'] = ''; |
|
| 464 | + $row['alea_futur'] = ''; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + return $row; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $prefs = @unserialize($row['prefs']); |
|
| 471 | + $infos = [ |
|
| 472 | + 'id_auteur' => $row['id_auteur'], |
|
| 473 | + 'login' => $row['login'], |
|
| 474 | + 'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 475 | + 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 476 | + ]; |
|
| 477 | + |
|
| 478 | + // desactiver le hash md5 si pas auteur spip ? |
|
| 479 | + if ($row['source'] !== 'spip') { |
|
| 480 | + $row['alea_actuel'] = ''; |
|
| 481 | + $row['alea_futur'] = ''; |
|
| 482 | + } |
|
| 483 | + verifier_visiteur(); |
|
| 484 | + |
|
| 485 | + return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | |
@@ -496,21 +496,21 @@ discard block |
||
| 496 | 496 | * @return mixed |
| 497 | 497 | */ |
| 498 | 498 | function auth_identifier_login($login, $password, $serveur = '') { |
| 499 | - $erreur = ''; |
|
| 500 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 501 | - if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 502 | - $auteur = $auth($login, $password, $serveur); |
|
| 503 | - if (is_array($auteur) and count($auteur)) { |
|
| 504 | - spip_log("connexion de $login par methode $methode"); |
|
| 505 | - $auteur['auth'] = $methode; |
|
| 506 | - return $auteur; |
|
| 507 | - } elseif (is_string($auteur)) { |
|
| 508 | - $erreur .= "$auteur "; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return $erreur; |
|
| 499 | + $erreur = ''; |
|
| 500 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 501 | + if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 502 | + $auteur = $auth($login, $password, $serveur); |
|
| 503 | + if (is_array($auteur) and count($auteur)) { |
|
| 504 | + spip_log("connexion de $login par methode $methode"); |
|
| 505 | + $auteur['auth'] = $methode; |
|
| 506 | + return $auteur; |
|
| 507 | + } elseif (is_string($auteur)) { |
|
| 508 | + $erreur .= "$auteur "; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return $erreur; |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -524,8 +524,8 @@ discard block |
||
| 524 | 524 | * @return string |
| 525 | 525 | */ |
| 526 | 526 | function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') { |
| 527 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 528 | - return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 527 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 528 | + return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -539,9 +539,9 @@ discard block |
||
| 539 | 539 | * @return mixed |
| 540 | 540 | */ |
| 541 | 541 | function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') { |
| 542 | - $args = func_get_args(); |
|
| 543 | - $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 544 | - return $auteur; |
|
| 542 | + $args = func_get_args(); |
|
| 543 | + $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 544 | + return $auteur; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -551,29 +551,29 @@ discard block |
||
| 551 | 551 | * @return bool |
| 552 | 552 | */ |
| 553 | 553 | function auth_loger($auteur) { |
| 554 | - if (!is_array($auteur) or !count($auteur)) { |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - // initialiser et poser le cookie de session |
|
| 559 | - unset($_COOKIE['spip_session']); |
|
| 560 | - if (auth_init_droits($auteur) === false) { |
|
| 561 | - return false; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - // initialiser les prefs |
|
| 565 | - $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 566 | - $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 567 | - |
|
| 568 | - sql_updateq( |
|
| 569 | - 'spip_auteurs', |
|
| 570 | - ['prefs' => serialize($p)], |
|
| 571 | - 'id_auteur=' . intval($auteur['id_auteur']) |
|
| 572 | - ); |
|
| 573 | - |
|
| 574 | - // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 575 | - verifier_visiteur(); |
|
| 576 | - return true; |
|
| 554 | + if (!is_array($auteur) or !count($auteur)) { |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + // initialiser et poser le cookie de session |
|
| 559 | + unset($_COOKIE['spip_session']); |
|
| 560 | + if (auth_init_droits($auteur) === false) { |
|
| 561 | + return false; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + // initialiser les prefs |
|
| 565 | + $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 566 | + $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 567 | + |
|
| 568 | + sql_updateq( |
|
| 569 | + 'spip_auteurs', |
|
| 570 | + ['prefs' => serialize($p)], |
|
| 571 | + 'id_auteur=' . intval($auteur['id_auteur']) |
|
| 572 | + ); |
|
| 573 | + |
|
| 574 | + // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 575 | + verifier_visiteur(); |
|
| 576 | + return true; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -583,8 +583,8 @@ discard block |
||
| 583 | 583 | * return void |
| 584 | 584 | **/ |
| 585 | 585 | function auth_deloger() { |
| 586 | - $logout = charger_fonction('logout', 'action'); |
|
| 587 | - $logout(); |
|
| 586 | + $logout = charger_fonction('logout', 'action'); |
|
| 587 | + $logout(); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | * @return bool |
| 599 | 599 | */ |
| 600 | 600 | function auth_autoriser_modifier_login($auth_methode, $serveur = '') { |
| 601 | - $args = func_get_args(); |
|
| 602 | - return auth_administrer('autoriser_modifier_login', $args); |
|
| 601 | + $args = func_get_args(); |
|
| 602 | + return auth_administrer('autoriser_modifier_login', $args); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -614,8 +614,8 @@ discard block |
||
| 614 | 614 | * message d'erreur ou chaine vide si pas d'erreur |
| 615 | 615 | */ |
| 616 | 616 | function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') { |
| 617 | - $args = func_get_args(); |
|
| 618 | - return auth_administrer('verifier_login', $args, ''); |
|
| 617 | + $args = func_get_args(); |
|
| 618 | + return auth_administrer('verifier_login', $args, ''); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -628,8 +628,8 @@ discard block |
||
| 628 | 628 | * @return bool |
| 629 | 629 | */ |
| 630 | 630 | function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') { |
| 631 | - $args = func_get_args(); |
|
| 632 | - return auth_administrer('modifier_login', $args); |
|
| 631 | + $args = func_get_args(); |
|
| 632 | + return auth_administrer('modifier_login', $args); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | * succès ou échec |
| 645 | 645 | */ |
| 646 | 646 | function auth_autoriser_modifier_pass($auth_methode, $serveur = '') { |
| 647 | - $args = func_get_args(); |
|
| 648 | - return auth_administrer('autoriser_modifier_pass', $args); |
|
| 647 | + $args = func_get_args(); |
|
| 648 | + return auth_administrer('autoriser_modifier_pass', $args); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
@@ -661,8 +661,8 @@ discard block |
||
| 661 | 661 | * message d'erreur ou chaine vide si pas d'erreur |
| 662 | 662 | */ |
| 663 | 663 | function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 664 | - $args = func_get_args(); |
|
| 665 | - return auth_administrer('verifier_pass', $args, ''); |
|
| 664 | + $args = func_get_args(); |
|
| 665 | + return auth_administrer('verifier_pass', $args, ''); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -678,8 +678,8 @@ discard block |
||
| 678 | 678 | * succes ou echec |
| 679 | 679 | */ |
| 680 | 680 | function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur = '') { |
| 681 | - $args = func_get_args(); |
|
| 682 | - return auth_administrer('modifier_pass', $args); |
|
| 681 | + $args = func_get_args(); |
|
| 682 | + return auth_administrer('modifier_pass', $args); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
@@ -695,24 +695,24 @@ discard block |
||
| 695 | 695 | * @return void |
| 696 | 696 | */ |
| 697 | 697 | function auth_synchroniser_distant( |
| 698 | - $auth_methode = true, |
|
| 699 | - $id_auteur = 0, |
|
| 700 | - $champs = [], |
|
| 701 | - $options = [], |
|
| 702 | - $serveur = '' |
|
| 698 | + $auth_methode = true, |
|
| 699 | + $id_auteur = 0, |
|
| 700 | + $champs = [], |
|
| 701 | + $options = [], |
|
| 702 | + $serveur = '' |
|
| 703 | 703 | ) { |
| 704 | - $args = func_get_args(); |
|
| 705 | - if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) { |
|
| 706 | - $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 707 | - $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 708 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 709 | - array_shift($args); |
|
| 710 | - array_unshift($args, $methode); |
|
| 711 | - auth_administrer('synchroniser_distant', $args); |
|
| 712 | - } |
|
| 713 | - } else { |
|
| 714 | - auth_administrer('synchroniser_distant', $args); |
|
| 715 | - } |
|
| 704 | + $args = func_get_args(); |
|
| 705 | + if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) { |
|
| 706 | + $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 707 | + $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 708 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 709 | + array_shift($args); |
|
| 710 | + array_unshift($args, $methode); |
|
| 711 | + auth_administrer('synchroniser_distant', $args); |
|
| 712 | + } |
|
| 713 | + } else { |
|
| 714 | + auth_administrer('synchroniser_distant', $args); |
|
| 715 | + } |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | |
@@ -725,45 +725,45 @@ discard block |
||
| 725 | 725 | * @return array|bool |
| 726 | 726 | */ |
| 727 | 727 | function lire_php_auth($login, $pw, $serveur = '') { |
| 728 | - if ( |
|
| 729 | - !$login |
|
| 730 | - or !$login = auth_retrouver_login($login, $serveur) |
|
| 731 | - ) { |
|
| 732 | - return false; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 736 | - |
|
| 737 | - if (!$row) { |
|
| 738 | - if ( |
|
| 739 | - include_spip('inc/auth') |
|
| 740 | - and auth_ldap_connect($serveur) |
|
| 741 | - and $auth_ldap = charger_fonction('ldap', 'auth', true) |
|
| 742 | - ) { |
|
| 743 | - return $auth_ldap($login, $pw, $serveur, true); |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - return false; |
|
| 747 | - } |
|
| 748 | - // su pas de source definie |
|
| 749 | - // ou auth/xxx introuvable, utiliser 'spip' |
|
| 750 | - if ( |
|
| 751 | - !$auth_methode = $row['source'] |
|
| 752 | - or !$auth = charger_fonction($auth_methode, 'auth', true) |
|
| 753 | - ) { |
|
| 754 | - $auth = charger_fonction('spip', 'auth', true); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - $auteur = ''; |
|
| 758 | - if ($auth) { |
|
| 759 | - $auteur = $auth($login, $pw, $serveur, true); |
|
| 760 | - } |
|
| 761 | - // verifier que ce n'est pas un message d'erreur |
|
| 762 | - if (is_array($auteur) and count($auteur)) { |
|
| 763 | - return $auteur; |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - return false; |
|
| 728 | + if ( |
|
| 729 | + !$login |
|
| 730 | + or !$login = auth_retrouver_login($login, $serveur) |
|
| 731 | + ) { |
|
| 732 | + return false; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 736 | + |
|
| 737 | + if (!$row) { |
|
| 738 | + if ( |
|
| 739 | + include_spip('inc/auth') |
|
| 740 | + and auth_ldap_connect($serveur) |
|
| 741 | + and $auth_ldap = charger_fonction('ldap', 'auth', true) |
|
| 742 | + ) { |
|
| 743 | + return $auth_ldap($login, $pw, $serveur, true); |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + return false; |
|
| 747 | + } |
|
| 748 | + // su pas de source definie |
|
| 749 | + // ou auth/xxx introuvable, utiliser 'spip' |
|
| 750 | + if ( |
|
| 751 | + !$auth_methode = $row['source'] |
|
| 752 | + or !$auth = charger_fonction($auth_methode, 'auth', true) |
|
| 753 | + ) { |
|
| 754 | + $auth = charger_fonction('spip', 'auth', true); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + $auteur = ''; |
|
| 758 | + if ($auth) { |
|
| 759 | + $auteur = $auth($login, $pw, $serveur, true); |
|
| 760 | + } |
|
| 761 | + // verifier que ce n'est pas un message d'erreur |
|
| 762 | + if (is_array($auteur) and count($auteur)) { |
|
| 763 | + return $auteur; |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + return false; |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /** |
@@ -779,21 +779,21 @@ discard block |
||
| 779 | 779 | * @param string $lien |
| 780 | 780 | */ |
| 781 | 781 | function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') { |
| 782 | - @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 783 | - @Header('HTTP/1.0 401 Unauthorized'); |
|
| 784 | - $corps = ''; |
|
| 785 | - $public = generer_url_public(); |
|
| 786 | - $ecrire = generer_url_ecrire(); |
|
| 787 | - $retour = $retour ?: _T('icone_retour'); |
|
| 788 | - $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 789 | - if ($url) { |
|
| 790 | - $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - if ($lien) { |
|
| 794 | - $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 795 | - } |
|
| 796 | - include_spip('inc/minipres'); |
|
| 797 | - echo minipres($pb, $corps); |
|
| 798 | - exit; |
|
| 782 | + @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 783 | + @Header('HTTP/1.0 401 Unauthorized'); |
|
| 784 | + $corps = ''; |
|
| 785 | + $public = generer_url_public(); |
|
| 786 | + $ecrire = generer_url_ecrire(); |
|
| 787 | + $retour = $retour ?: _T('icone_retour'); |
|
| 788 | + $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 789 | + if ($url) { |
|
| 790 | + $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + if ($lien) { |
|
| 794 | + $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 795 | + } |
|
| 796 | + include_spip('inc/minipres'); |
|
| 797 | + echo minipres($pb, $corps); |
|
| 798 | + exit; |
|
| 799 | 799 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres'); // par precaution |
| 24 | 24 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | * Le code de la couleur en hexadécimal. |
| 39 | 39 | */ |
| 40 | 40 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 41 | - $red = dechex($red); |
|
| 42 | - $green = dechex($green); |
|
| 43 | - $blue = dechex($blue); |
|
| 44 | - |
|
| 45 | - if (strlen($red) == 1) { |
|
| 46 | - $red = '0' . $red; |
|
| 47 | - } |
|
| 48 | - if (strlen($green) == 1) { |
|
| 49 | - $green = '0' . $green; |
|
| 50 | - } |
|
| 51 | - if (strlen($blue) == 1) { |
|
| 52 | - $blue = '0' . $blue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return "$red$green$blue"; |
|
| 41 | + $red = dechex($red); |
|
| 42 | + $green = dechex($green); |
|
| 43 | + $blue = dechex($blue); |
|
| 44 | + |
|
| 45 | + if (strlen($red) == 1) { |
|
| 46 | + $red = '0' . $red; |
|
| 47 | + } |
|
| 48 | + if (strlen($green) == 1) { |
|
| 49 | + $green = '0' . $green; |
|
| 50 | + } |
|
| 51 | + if (strlen($blue) == 1) { |
|
| 52 | + $blue = '0' . $blue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return "$red$green$blue"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 65 | 65 | */ |
| 66 | 66 | function _couleur_hex_to_dec($couleur) { |
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,59 +120,59 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $H = null; |
|
| 124 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | - $var_G = ($G / 255); |
|
| 126 | - $var_B = ($B / 255); |
|
| 127 | - |
|
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | - |
|
| 132 | - $L = ($var_Max + $var_Min) / 2; |
|
| 133 | - |
|
| 134 | - if ($del_Max == 0) { |
|
| 135 | - //This is a gray, no chroma... |
|
| 136 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | - $S = 0; |
|
| 138 | - } else { |
|
| 139 | - // Chromatic data... |
|
| 140 | - if ($L < 0.5) { |
|
| 141 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | - } else { |
|
| 143 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - |
|
| 150 | - if ($var_R == $var_Max) { |
|
| 151 | - $H = $del_B - $del_G; |
|
| 152 | - } else { |
|
| 153 | - if ($var_G == $var_Max) { |
|
| 154 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | - } else { |
|
| 156 | - if ($var_B == $var_Max) { |
|
| 157 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if ($H < 0) { |
|
| 163 | - $H += 1; |
|
| 164 | - } |
|
| 165 | - if ($H > 1) { |
|
| 166 | - $H -= 1; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ret = []; |
|
| 171 | - $ret['h'] = $H; |
|
| 172 | - $ret['s'] = $S; |
|
| 173 | - $ret['l'] = $L; |
|
| 174 | - |
|
| 175 | - return $ret; |
|
| 123 | + $H = null; |
|
| 124 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | + $var_G = ($G / 255); |
|
| 126 | + $var_B = ($B / 255); |
|
| 127 | + |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | + |
|
| 132 | + $L = ($var_Max + $var_Min) / 2; |
|
| 133 | + |
|
| 134 | + if ($del_Max == 0) { |
|
| 135 | + //This is a gray, no chroma... |
|
| 136 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | + $S = 0; |
|
| 138 | + } else { |
|
| 139 | + // Chromatic data... |
|
| 140 | + if ($L < 0.5) { |
|
| 141 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | + } else { |
|
| 143 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + |
|
| 150 | + if ($var_R == $var_Max) { |
|
| 151 | + $H = $del_B - $del_G; |
|
| 152 | + } else { |
|
| 153 | + if ($var_G == $var_Max) { |
|
| 154 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | + } else { |
|
| 156 | + if ($var_B == $var_Max) { |
|
| 157 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if ($H < 0) { |
|
| 163 | + $H += 1; |
|
| 164 | + } |
|
| 165 | + if ($H > 1) { |
|
| 166 | + $H -= 1; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ret = []; |
|
| 171 | + $ret['h'] = $H; |
|
| 172 | + $ret['s'] = $S; |
|
| 173 | + $ret['l'] = $L; |
|
| 174 | + |
|
| 175 | + return $ret; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -188,52 +188,52 @@ discard block |
||
| 188 | 188 | * @return array |
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | - // helper |
|
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | - if ($vH < 0) { |
|
| 194 | - $vH += 1; |
|
| 195 | - } |
|
| 196 | - if ($vH > 1) { |
|
| 197 | - $vH -= 1; |
|
| 198 | - } |
|
| 199 | - if ((6 * $vH) < 1) { |
|
| 200 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | - } |
|
| 202 | - if ((2 * $vH) < 1) { |
|
| 203 | - return ($v2); |
|
| 204 | - } |
|
| 205 | - if ((3 * $vH) < 2) { |
|
| 206 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return ($v1); |
|
| 210 | - }; |
|
| 211 | - |
|
| 212 | - if ($S == 0) { |
|
| 213 | - // HSV values = 0 -> 1 |
|
| 214 | - $R = $L * 255; |
|
| 215 | - $G = $L * 255; |
|
| 216 | - $B = $L * 255; |
|
| 217 | - } else { |
|
| 218 | - if ($L < 0.5) { |
|
| 219 | - $var_2 = $L * (1 + $S); |
|
| 220 | - } else { |
|
| 221 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $var_1 = 2 * $L - $var_2; |
|
| 225 | - |
|
| 226 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $ret = []; |
|
| 232 | - $ret['r'] = floor($R); |
|
| 233 | - $ret['g'] = floor($G); |
|
| 234 | - $ret['b'] = floor($B); |
|
| 235 | - |
|
| 236 | - return $ret; |
|
| 191 | + // helper |
|
| 192 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | + if ($vH < 0) { |
|
| 194 | + $vH += 1; |
|
| 195 | + } |
|
| 196 | + if ($vH > 1) { |
|
| 197 | + $vH -= 1; |
|
| 198 | + } |
|
| 199 | + if ((6 * $vH) < 1) { |
|
| 200 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | + } |
|
| 202 | + if ((2 * $vH) < 1) { |
|
| 203 | + return ($v2); |
|
| 204 | + } |
|
| 205 | + if ((3 * $vH) < 2) { |
|
| 206 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return ($v1); |
|
| 210 | + }; |
|
| 211 | + |
|
| 212 | + if ($S == 0) { |
|
| 213 | + // HSV values = 0 -> 1 |
|
| 214 | + $R = $L * 255; |
|
| 215 | + $G = $L * 255; |
|
| 216 | + $B = $L * 255; |
|
| 217 | + } else { |
|
| 218 | + if ($L < 0.5) { |
|
| 219 | + $var_2 = $L * (1 + $S); |
|
| 220 | + } else { |
|
| 221 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $var_1 = 2 * $L - $var_2; |
|
| 225 | + |
|
| 226 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $ret = []; |
|
| 232 | + $ret['r'] = floor($R); |
|
| 233 | + $ret['g'] = floor($G); |
|
| 234 | + $ret['b'] = floor($B); |
|
| 235 | + |
|
| 236 | + return $ret; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 252 | 252 | */ |
| 253 | 253 | function statut_effacer_images_temporaires($stat) { |
| 254 | - static $statut = false; // par defaut on grave toute les images |
|
| 255 | - if ($stat === 'get') { |
|
| 256 | - return $statut; |
|
| 257 | - } |
|
| 258 | - $statut = $stat ? true : false; |
|
| 254 | + static $statut = false; // par defaut on grave toute les images |
|
| 255 | + if ($stat === 'get') { |
|
| 256 | + return $statut; |
|
| 257 | + } |
|
| 258 | + $statut = $stat ? true : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -308,243 +308,243 @@ discard block |
||
| 308 | 308 | * - array : tableau décrivant de l'image |
| 309 | 309 | */ |
| 310 | 310 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 311 | - $ret = []; |
|
| 312 | - $f = null; |
|
| 313 | - static $images_recalcul = []; |
|
| 314 | - if (strlen($img) == 0) { |
|
| 315 | - return false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | - if (strlen($source) < 1) { |
|
| 320 | - $source = $img; |
|
| 321 | - $img = "<img src='$source' />"; |
|
| 322 | - } elseif ( |
|
| 323 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | - ) { |
|
| 327 | - # gerer img src="data:....base64" |
|
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | - if (!file_exists($local)) { |
|
| 330 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | - } |
|
| 332 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | - $sanitizer($local); |
|
| 334 | - } |
|
| 335 | - $source = $local; |
|
| 336 | - $img = inserer_attribut($img, 'src', $source); |
|
| 337 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | - $img = inserer_attribut($img, 'width', ''); |
|
| 339 | - $img = inserer_attribut($img, 'height', ''); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // les protocoles web prennent au moins 3 lettres |
|
| 343 | - if (tester_url_absolue($source)) { |
|
| 344 | - include_spip('inc/distant'); |
|
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | - if (!$fichier) { |
|
| 347 | - return ''; |
|
| 348 | - } |
|
| 349 | - if ( |
|
| 350 | - $extension = _image_trouver_extension($fichier) |
|
| 351 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | - ) { |
|
| 353 | - $sanitizer($fichier); |
|
| 354 | - } |
|
| 355 | - } else { |
|
| 356 | - // enlever le timestamp eventuel |
|
| 357 | - if (strpos($source, '?') !== false) { |
|
| 358 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | - } |
|
| 360 | - if ( |
|
| 361 | - strpos($source, '?') !== false |
|
| 362 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | - ) { |
|
| 365 | - $source = $f; |
|
| 366 | - } |
|
| 367 | - $fichier = $source; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $terminaison_dest = ''; |
|
| 371 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ( |
|
| 376 | - $forcer_format !== false |
|
| 377 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | - ) { |
|
| 380 | - $terminaison_dest = $forcer_format; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - if (!$terminaison_dest) { |
|
| 384 | - return false; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | - $fichier_dest = $nom_fichier; |
|
| 389 | - if ( |
|
| 390 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | - or @file_exists($f = $fichier) |
|
| 392 | - ) { |
|
| 393 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | - // au lieu de faire un acces disque sur le fichier |
|
| 395 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | - $date_src = @filemtime($f); |
|
| 397 | - } elseif ( |
|
| 398 | - @file_exists($f = "$fichier.src") |
|
| 399 | - and lire_fichier($f, $valeurs) |
|
| 400 | - and $valeurs = unserialize($valeurs) |
|
| 401 | - and isset($valeurs['hauteur_dest']) |
|
| 402 | - and isset($valeurs['largeur_dest']) |
|
| 403 | - ) { |
|
| 404 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | - $date_src = $valeurs['date']; |
|
| 407 | - } // pas de fichier source par la |
|
| 408 | - else { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - // pas de taille mesurable |
|
| 413 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 414 | - return false; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // les images calculees dependent du chemin du fichier source |
|
| 418 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 419 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 420 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 421 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 422 | - // alors que ca concerne peu de site au final |
|
| 423 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 424 | - $identifiant = $fichier; |
|
| 425 | - |
|
| 426 | - // cas general : |
|
| 427 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 428 | - // cas particulier de reduire : |
|
| 429 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 430 | - $cache = 'cache-gd2'; |
|
| 431 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 432 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 433 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 434 | - $ret['largeur_dest'] = $destWidth; |
|
| 435 | - $ret['hauteur_dest'] = $destHeight; |
|
| 436 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 437 | - $cache = 'cache-vignettes'; |
|
| 438 | - $fichier_dest = basename($fichier_dest); |
|
| 439 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 440 | - // on garde la terminaison initiale car image simplement copiee |
|
| 441 | - // et on postfixe son nom avec un md5 du path |
|
| 442 | - $terminaison_dest = $terminaison; |
|
| 443 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 444 | - } else { |
|
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 446 | - } |
|
| 447 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 448 | - $cache = sous_repertoire($cache, $effet); |
|
| 449 | - } else { |
|
| 450 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 451 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 453 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 457 | - |
|
| 458 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 459 | - |
|
| 460 | - $creer = true; |
|
| 461 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 462 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 463 | - $images_recalcul[$fichier_dest] = true; |
|
| 464 | - } else { |
|
| 465 | - if (@file_exists($f = $fichier_dest)) { |
|
| 466 | - if (filemtime($f) >= $date_src) { |
|
| 467 | - $creer = false; |
|
| 468 | - } |
|
| 469 | - } else { |
|
| 470 | - if ( |
|
| 471 | - @file_exists($f = "$fichier_dest.src") |
|
| 472 | - and lire_fichier($f, $valeurs) |
|
| 473 | - and $valeurs = unserialize($valeurs) |
|
| 474 | - and $valeurs['date'] >= $date_src |
|
| 475 | - ) { |
|
| 476 | - $creer = false; |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - if ($creer) { |
|
| 481 | - if (!@file_exists($fichier)) { |
|
| 482 | - if (!@file_exists("$fichier.src")) { |
|
| 483 | - spip_log("Image absente : $fichier"); |
|
| 484 | - |
|
| 485 | - return false; |
|
| 486 | - } |
|
| 487 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 488 | - reconstruire_image_intermediaire($fichier); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if ($creer) { |
|
| 493 | - spip_log( |
|
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | - $ret['fichier'] = $fichier; |
|
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | - $ret['format_dest'] = $terminaison_dest; |
|
| 506 | - $ret['date_src'] = $date_src; |
|
| 507 | - $ret['creer'] = $creer; |
|
| 508 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | - $ret['tag'] = $img; |
|
| 512 | - if ($fonction_creation) { |
|
| 513 | - $ret['reconstruction'] = $fonction_creation; |
|
| 514 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | - 'args' => [ |
|
| 522 | - 'img' => $img, |
|
| 523 | - 'effet' => $effet, |
|
| 524 | - 'forcer_format' => $forcer_format, |
|
| 525 | - 'fonction_creation' => $fonction_creation, |
|
| 526 | - 'find_in_path' => $find_in_path, |
|
| 527 | - ], |
|
| 528 | - 'data' => $ret |
|
| 529 | - ]); |
|
| 530 | - |
|
| 531 | - // une globale pour le debug en cas de crash memoire |
|
| 532 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | - |
|
| 534 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | - if ($term_fonction === 'svg') { |
|
| 536 | - if ($creer and !$support_svg) { |
|
| 537 | - process_image_svg_identite($ret); |
|
| 538 | - $ret['creer'] = false; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - else { |
|
| 542 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $ret; |
|
| 311 | + $ret = []; |
|
| 312 | + $f = null; |
|
| 313 | + static $images_recalcul = []; |
|
| 314 | + if (strlen($img) == 0) { |
|
| 315 | + return false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | + if (strlen($source) < 1) { |
|
| 320 | + $source = $img; |
|
| 321 | + $img = "<img src='$source' />"; |
|
| 322 | + } elseif ( |
|
| 323 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | + ) { |
|
| 327 | + # gerer img src="data:....base64" |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | + if (!file_exists($local)) { |
|
| 330 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | + } |
|
| 332 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | + $sanitizer($local); |
|
| 334 | + } |
|
| 335 | + $source = $local; |
|
| 336 | + $img = inserer_attribut($img, 'src', $source); |
|
| 337 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | + $img = inserer_attribut($img, 'width', ''); |
|
| 339 | + $img = inserer_attribut($img, 'height', ''); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // les protocoles web prennent au moins 3 lettres |
|
| 343 | + if (tester_url_absolue($source)) { |
|
| 344 | + include_spip('inc/distant'); |
|
| 345 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | + if (!$fichier) { |
|
| 347 | + return ''; |
|
| 348 | + } |
|
| 349 | + if ( |
|
| 350 | + $extension = _image_trouver_extension($fichier) |
|
| 351 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | + ) { |
|
| 353 | + $sanitizer($fichier); |
|
| 354 | + } |
|
| 355 | + } else { |
|
| 356 | + // enlever le timestamp eventuel |
|
| 357 | + if (strpos($source, '?') !== false) { |
|
| 358 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | + } |
|
| 360 | + if ( |
|
| 361 | + strpos($source, '?') !== false |
|
| 362 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | + ) { |
|
| 365 | + $source = $f; |
|
| 366 | + } |
|
| 367 | + $fichier = $source; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $terminaison_dest = ''; |
|
| 371 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ( |
|
| 376 | + $forcer_format !== false |
|
| 377 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | + ) { |
|
| 380 | + $terminaison_dest = $forcer_format; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + if (!$terminaison_dest) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | + $fichier_dest = $nom_fichier; |
|
| 389 | + if ( |
|
| 390 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | + or @file_exists($f = $fichier) |
|
| 392 | + ) { |
|
| 393 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | + // au lieu de faire un acces disque sur le fichier |
|
| 395 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | + $date_src = @filemtime($f); |
|
| 397 | + } elseif ( |
|
| 398 | + @file_exists($f = "$fichier.src") |
|
| 399 | + and lire_fichier($f, $valeurs) |
|
| 400 | + and $valeurs = unserialize($valeurs) |
|
| 401 | + and isset($valeurs['hauteur_dest']) |
|
| 402 | + and isset($valeurs['largeur_dest']) |
|
| 403 | + ) { |
|
| 404 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | + $date_src = $valeurs['date']; |
|
| 407 | + } // pas de fichier source par la |
|
| 408 | + else { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + // pas de taille mesurable |
|
| 413 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // les images calculees dependent du chemin du fichier source |
|
| 418 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 419 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 420 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 421 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 422 | + // alors que ca concerne peu de site au final |
|
| 423 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 424 | + $identifiant = $fichier; |
|
| 425 | + |
|
| 426 | + // cas general : |
|
| 427 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 428 | + // cas particulier de reduire : |
|
| 429 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 430 | + $cache = 'cache-gd2'; |
|
| 431 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 432 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 433 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 434 | + $ret['largeur_dest'] = $destWidth; |
|
| 435 | + $ret['hauteur_dest'] = $destHeight; |
|
| 436 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 437 | + $cache = 'cache-vignettes'; |
|
| 438 | + $fichier_dest = basename($fichier_dest); |
|
| 439 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 440 | + // on garde la terminaison initiale car image simplement copiee |
|
| 441 | + // et on postfixe son nom avec un md5 du path |
|
| 442 | + $terminaison_dest = $terminaison; |
|
| 443 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 444 | + } else { |
|
| 445 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 446 | + } |
|
| 447 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 448 | + $cache = sous_repertoire($cache, $effet); |
|
| 449 | + } else { |
|
| 450 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 451 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 453 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 457 | + |
|
| 458 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 459 | + |
|
| 460 | + $creer = true; |
|
| 461 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 462 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 463 | + $images_recalcul[$fichier_dest] = true; |
|
| 464 | + } else { |
|
| 465 | + if (@file_exists($f = $fichier_dest)) { |
|
| 466 | + if (filemtime($f) >= $date_src) { |
|
| 467 | + $creer = false; |
|
| 468 | + } |
|
| 469 | + } else { |
|
| 470 | + if ( |
|
| 471 | + @file_exists($f = "$fichier_dest.src") |
|
| 472 | + and lire_fichier($f, $valeurs) |
|
| 473 | + and $valeurs = unserialize($valeurs) |
|
| 474 | + and $valeurs['date'] >= $date_src |
|
| 475 | + ) { |
|
| 476 | + $creer = false; |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + if ($creer) { |
|
| 481 | + if (!@file_exists($fichier)) { |
|
| 482 | + if (!@file_exists("$fichier.src")) { |
|
| 483 | + spip_log("Image absente : $fichier"); |
|
| 484 | + |
|
| 485 | + return false; |
|
| 486 | + } |
|
| 487 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 488 | + reconstruire_image_intermediaire($fichier); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if ($creer) { |
|
| 493 | + spip_log( |
|
| 494 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | + 'images' . _LOG_DEBUG |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | + $ret['fichier'] = $fichier; |
|
| 502 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | + $ret['format_dest'] = $terminaison_dest; |
|
| 506 | + $ret['date_src'] = $date_src; |
|
| 507 | + $ret['creer'] = $creer; |
|
| 508 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | + $ret['tag'] = $img; |
|
| 512 | + if ($fonction_creation) { |
|
| 513 | + $ret['reconstruction'] = $fonction_creation; |
|
| 514 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | + 'args' => [ |
|
| 522 | + 'img' => $img, |
|
| 523 | + 'effet' => $effet, |
|
| 524 | + 'forcer_format' => $forcer_format, |
|
| 525 | + 'fonction_creation' => $fonction_creation, |
|
| 526 | + 'find_in_path' => $find_in_path, |
|
| 527 | + ], |
|
| 528 | + 'data' => $ret |
|
| 529 | + ]); |
|
| 530 | + |
|
| 531 | + // une globale pour le debug en cas de crash memoire |
|
| 532 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | + |
|
| 534 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | + if ($term_fonction === 'svg') { |
|
| 536 | + if ($creer and !$support_svg) { |
|
| 537 | + process_image_svg_identite($ret); |
|
| 538 | + $ret['creer'] = false; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + else { |
|
| 542 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $ret; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -553,53 +553,53 @@ discard block |
||
| 553 | 553 | * @return array |
| 554 | 554 | */ |
| 555 | 555 | function _image_extensions_acceptees_en_entree() { |
| 556 | - static $extensions = null; |
|
| 557 | - if (empty($extensions)) { |
|
| 558 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 559 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 560 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 561 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 562 | - $extensions = array_map('trim', $extensions); |
|
| 563 | - $extensions = array_filter($extensions); |
|
| 564 | - $extensions = array_unique($extensions); |
|
| 565 | - if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 566 | - } |
|
| 567 | - } |
|
| 568 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - return $extensions; |
|
| 556 | + static $extensions = null; |
|
| 557 | + if (empty($extensions)) { |
|
| 558 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 559 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 560 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 561 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 562 | + $extensions = array_map('trim', $extensions); |
|
| 563 | + $extensions = array_filter($extensions); |
|
| 564 | + $extensions = array_unique($extensions); |
|
| 565 | + if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 566 | + } |
|
| 567 | + } |
|
| 568 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + return $extensions; |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | /** |
| 575 | 575 | * @return array|string[]|null |
| 576 | 576 | */ |
| 577 | 577 | function _image_extensions_acceptees_en_sortie() { |
| 578 | - static $extensions = null; |
|
| 579 | - if (empty($extensions)) { |
|
| 580 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 581 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 582 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 583 | - $extensions = array_diff($extensions, ['gif']); |
|
| 584 | - } |
|
| 585 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 586 | - $extensions = array_diff($extensions, ['webp']); |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - return $extensions; |
|
| 578 | + static $extensions = null; |
|
| 579 | + if (empty($extensions)) { |
|
| 580 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 581 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 582 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 583 | + $extensions = array_diff($extensions, ['gif']); |
|
| 584 | + } |
|
| 585 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 586 | + $extensions = array_diff($extensions, ['webp']); |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + return $extensions; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | function _image_extension_normalisee($extension) { |
| 594 | - $extension = strtolower($extension); |
|
| 595 | - if ($extension === 'jpeg') { |
|
| 596 | - $extension = 'jpg'; |
|
| 597 | - } |
|
| 598 | - return $extension; |
|
| 594 | + $extension = strtolower($extension); |
|
| 595 | + if ($extension === 'jpeg') { |
|
| 596 | + $extension = 'jpg'; |
|
| 597 | + } |
|
| 598 | + return $extension; |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | function _image_extensions_conservent_transparence() { |
| 602 | - return ['png', 'webp']; |
|
| 602 | + return ['png', 'webp']; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | |
@@ -609,12 +609,12 @@ discard block |
||
| 609 | 609 | * @return string |
| 610 | 610 | */ |
| 611 | 611 | function _image_trouver_extension($path) { |
| 612 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 613 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 614 | - $terminaison = strtolower($regs[1]); |
|
| 615 | - return $terminaison; |
|
| 616 | - } |
|
| 617 | - return ''; |
|
| 612 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 613 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 614 | + $terminaison = strtolower($regs[1]); |
|
| 615 | + return $terminaison; |
|
| 616 | + } |
|
| 617 | + return ''; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -625,33 +625,33 @@ discard block |
||
| 625 | 625 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 626 | 626 | */ |
| 627 | 627 | function _image_trouver_extension_pertinente($path) { |
| 628 | - $path = supprimer_timestamp($path); |
|
| 629 | - $terminaison = _image_trouver_extension($path); |
|
| 630 | - if ($terminaison == 'jpg') { |
|
| 631 | - $terminaison = 'jpeg'; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if (!file_exists($path)) { |
|
| 635 | - return $terminaison; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - if (!$info = @spip_getimagesize($path)) { |
|
| 639 | - return $terminaison; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - if (isset($info['mime'])) { |
|
| 643 | - $mime = $info['mime']; |
|
| 644 | - } |
|
| 645 | - else { |
|
| 646 | - $mime = image_type_to_mime_type($info[2]); |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 650 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 651 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 652 | - $terminaison = $_terminaison; |
|
| 653 | - } |
|
| 654 | - return $terminaison; |
|
| 628 | + $path = supprimer_timestamp($path); |
|
| 629 | + $terminaison = _image_trouver_extension($path); |
|
| 630 | + if ($terminaison == 'jpg') { |
|
| 631 | + $terminaison = 'jpeg'; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if (!file_exists($path)) { |
|
| 635 | + return $terminaison; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + if (!$info = @spip_getimagesize($path)) { |
|
| 639 | + return $terminaison; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + if (isset($info['mime'])) { |
|
| 643 | + $mime = $info['mime']; |
|
| 644 | + } |
|
| 645 | + else { |
|
| 646 | + $mime = image_type_to_mime_type($info[2]); |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 650 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 651 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 652 | + $terminaison = $_terminaison; |
|
| 653 | + } |
|
| 654 | + return $terminaison; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -659,36 +659,36 @@ discard block |
||
| 659 | 659 | * @return string |
| 660 | 660 | */ |
| 661 | 661 | function _image_trouver_extension_depuis_mime($mime) { |
| 662 | - switch (strtolower($mime)) { |
|
| 663 | - case 'image/png': |
|
| 664 | - case 'image/x-png': |
|
| 665 | - $terminaison = 'png'; |
|
| 666 | - break; |
|
| 667 | - |
|
| 668 | - case 'image/jpg': |
|
| 669 | - case 'image/jpeg': |
|
| 670 | - case 'image/pjpeg': |
|
| 671 | - $terminaison = 'jpeg'; |
|
| 672 | - break; |
|
| 673 | - |
|
| 674 | - case 'image/gif': |
|
| 675 | - $terminaison = 'gif'; |
|
| 676 | - break; |
|
| 677 | - |
|
| 678 | - case 'image/webp': |
|
| 679 | - case 'image/x-webp': |
|
| 680 | - $terminaison = 'webp'; |
|
| 681 | - break; |
|
| 682 | - |
|
| 683 | - case 'image/svg+xml': |
|
| 684 | - $terminaison = 'svg'; |
|
| 685 | - break; |
|
| 686 | - |
|
| 687 | - default: |
|
| 688 | - $terminaison = ''; |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - return $terminaison; |
|
| 662 | + switch (strtolower($mime)) { |
|
| 663 | + case 'image/png': |
|
| 664 | + case 'image/x-png': |
|
| 665 | + $terminaison = 'png'; |
|
| 666 | + break; |
|
| 667 | + |
|
| 668 | + case 'image/jpg': |
|
| 669 | + case 'image/jpeg': |
|
| 670 | + case 'image/pjpeg': |
|
| 671 | + $terminaison = 'jpeg'; |
|
| 672 | + break; |
|
| 673 | + |
|
| 674 | + case 'image/gif': |
|
| 675 | + $terminaison = 'gif'; |
|
| 676 | + break; |
|
| 677 | + |
|
| 678 | + case 'image/webp': |
|
| 679 | + case 'image/x-webp': |
|
| 680 | + $terminaison = 'webp'; |
|
| 681 | + break; |
|
| 682 | + |
|
| 683 | + case 'image/svg+xml': |
|
| 684 | + $terminaison = 'svg'; |
|
| 685 | + break; |
|
| 686 | + |
|
| 687 | + default: |
|
| 688 | + $terminaison = ''; |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + return $terminaison; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | |
@@ -708,18 +708,18 @@ discard block |
||
| 708 | 708 | * Une ressource de type Image GD. |
| 709 | 709 | */ |
| 710 | 710 | function _imagecreatefrom_func(string $func, string $filename) { |
| 711 | - if (!function_exists($func)) { |
|
| 712 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 713 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 714 | - return null; |
|
| 715 | - } |
|
| 716 | - $img = @$func($filename); |
|
| 717 | - if (!$img) { |
|
| 718 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 719 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 720 | - $img = imagecreate(10, 10); |
|
| 721 | - } |
|
| 722 | - return $img; |
|
| 711 | + if (!function_exists($func)) { |
|
| 712 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 713 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 714 | + return null; |
|
| 715 | + } |
|
| 716 | + $img = @$func($filename); |
|
| 717 | + if (!$img) { |
|
| 718 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 719 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 720 | + $img = imagecreate(10, 10); |
|
| 721 | + } |
|
| 722 | + return $img; |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | /** |
@@ -735,7 +735,7 @@ discard block |
||
| 735 | 735 | * Une ressource de type Image GD. |
| 736 | 736 | */ |
| 737 | 737 | function _imagecreatefromjpeg($filename) { |
| 738 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 738 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 739 | 739 | } |
| 740 | 740 | |
| 741 | 741 | /** |
@@ -751,7 +751,7 @@ discard block |
||
| 751 | 751 | * Une ressource de type Image GD. |
| 752 | 752 | */ |
| 753 | 753 | function _imagecreatefrompng($filename) { |
| 754 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 754 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | /** |
@@ -767,7 +767,7 @@ discard block |
||
| 767 | 767 | * Une ressource de type Image GD. |
| 768 | 768 | */ |
| 769 | 769 | function _imagecreatefromgif($filename) { |
| 770 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 770 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 771 | 771 | } |
| 772 | 772 | |
| 773 | 773 | |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | * Une ressource de type Image GD. |
| 785 | 785 | */ |
| 786 | 786 | function _imagecreatefromwebp($filename) { |
| 787 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 787 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 788 | 788 | } |
| 789 | 789 | |
| 790 | 790 | /** |
@@ -802,24 +802,24 @@ discard block |
||
| 802 | 802 | * - true si une image est bien retournée. |
| 803 | 803 | */ |
| 804 | 804 | function _image_imagepng($img, $fichier) { |
| 805 | - if (!function_exists('imagepng')) { |
|
| 806 | - return false; |
|
| 807 | - } |
|
| 808 | - $tmp = $fichier . '.tmp'; |
|
| 809 | - $ret = imagepng($img, $tmp); |
|
| 810 | - if (file_exists($tmp)) { |
|
| 811 | - $taille_test = getimagesize($tmp); |
|
| 812 | - if ($taille_test[0] < 1) { |
|
| 813 | - return false; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 817 | - @rename($tmp, $fichier); |
|
| 818 | - |
|
| 819 | - return $ret; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - return false; |
|
| 805 | + if (!function_exists('imagepng')) { |
|
| 806 | + return false; |
|
| 807 | + } |
|
| 808 | + $tmp = $fichier . '.tmp'; |
|
| 809 | + $ret = imagepng($img, $tmp); |
|
| 810 | + if (file_exists($tmp)) { |
|
| 811 | + $taille_test = getimagesize($tmp); |
|
| 812 | + if ($taille_test[0] < 1) { |
|
| 813 | + return false; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 817 | + @rename($tmp, $fichier); |
|
| 818 | + |
|
| 819 | + return $ret; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + return false; |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | /** |
@@ -837,24 +837,24 @@ discard block |
||
| 837 | 837 | * - true si une image est bien retournée. |
| 838 | 838 | */ |
| 839 | 839 | function _image_imagegif($img, $fichier) { |
| 840 | - if (!function_exists('imagegif')) { |
|
| 841 | - return false; |
|
| 842 | - } |
|
| 843 | - $tmp = $fichier . '.tmp'; |
|
| 844 | - $ret = imagegif($img, $tmp); |
|
| 845 | - if (file_exists($tmp)) { |
|
| 846 | - $taille_test = getimagesize($tmp); |
|
| 847 | - if ($taille_test[0] < 1) { |
|
| 848 | - return false; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 852 | - @rename($tmp, $fichier); |
|
| 853 | - |
|
| 854 | - return $ret; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - return false; |
|
| 840 | + if (!function_exists('imagegif')) { |
|
| 841 | + return false; |
|
| 842 | + } |
|
| 843 | + $tmp = $fichier . '.tmp'; |
|
| 844 | + $ret = imagegif($img, $tmp); |
|
| 845 | + if (file_exists($tmp)) { |
|
| 846 | + $taille_test = getimagesize($tmp); |
|
| 847 | + if ($taille_test[0] < 1) { |
|
| 848 | + return false; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 852 | + @rename($tmp, $fichier); |
|
| 853 | + |
|
| 854 | + return $ret; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + return false; |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | /** |
@@ -877,29 +877,29 @@ discard block |
||
| 877 | 877 | * - true si une image est bien retournée. |
| 878 | 878 | */ |
| 879 | 879 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 880 | - if (!function_exists('imagejpeg')) { |
|
| 881 | - return false; |
|
| 882 | - } |
|
| 883 | - $tmp = $fichier . '.tmp'; |
|
| 880 | + if (!function_exists('imagejpeg')) { |
|
| 881 | + return false; |
|
| 882 | + } |
|
| 883 | + $tmp = $fichier . '.tmp'; |
|
| 884 | 884 | |
| 885 | - // Enable interlancing |
|
| 886 | - imageinterlace($img, true); |
|
| 885 | + // Enable interlancing |
|
| 886 | + imageinterlace($img, true); |
|
| 887 | 887 | |
| 888 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 888 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 889 | 889 | |
| 890 | - if (file_exists($tmp)) { |
|
| 891 | - $taille_test = getimagesize($tmp); |
|
| 892 | - if ($taille_test[0] < 1) { |
|
| 893 | - return false; |
|
| 894 | - } |
|
| 890 | + if (file_exists($tmp)) { |
|
| 891 | + $taille_test = getimagesize($tmp); |
|
| 892 | + if ($taille_test[0] < 1) { |
|
| 893 | + return false; |
|
| 894 | + } |
|
| 895 | 895 | |
| 896 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 897 | - @rename($tmp, $fichier); |
|
| 896 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 897 | + @rename($tmp, $fichier); |
|
| 898 | 898 | |
| 899 | - return $ret; |
|
| 900 | - } |
|
| 899 | + return $ret; |
|
| 900 | + } |
|
| 901 | 901 | |
| 902 | - return false; |
|
| 902 | + return false; |
|
| 903 | 903 | } |
| 904 | 904 | |
| 905 | 905 | /** |
@@ -917,9 +917,9 @@ discard block |
||
| 917 | 917 | * true si le fichier a bien été créé ; false sinon. |
| 918 | 918 | */ |
| 919 | 919 | function _image_imageico($img, $fichier) { |
| 920 | - $gd_image_array = [$img]; |
|
| 920 | + $gd_image_array = [$img]; |
|
| 921 | 921 | |
| 922 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 922 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | |
@@ -938,24 +938,24 @@ discard block |
||
| 938 | 938 | * - true si une image est bien retournée. |
| 939 | 939 | */ |
| 940 | 940 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 941 | - if (!function_exists('imagewebp')) { |
|
| 942 | - return false; |
|
| 943 | - } |
|
| 944 | - $tmp = $fichier . '.tmp'; |
|
| 945 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 946 | - if (file_exists($tmp)) { |
|
| 947 | - $taille_test = getimagesize($tmp); |
|
| 948 | - if ($taille_test[0] < 1) { |
|
| 949 | - return false; |
|
| 950 | - } |
|
| 951 | - |
|
| 952 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 953 | - @rename($tmp, $fichier); |
|
| 954 | - |
|
| 955 | - return $ret; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - return false; |
|
| 941 | + if (!function_exists('imagewebp')) { |
|
| 942 | + return false; |
|
| 943 | + } |
|
| 944 | + $tmp = $fichier . '.tmp'; |
|
| 945 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 946 | + if (file_exists($tmp)) { |
|
| 947 | + $taille_test = getimagesize($tmp); |
|
| 948 | + if ($taille_test[0] < 1) { |
|
| 949 | + return false; |
|
| 950 | + } |
|
| 951 | + |
|
| 952 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 953 | + @rename($tmp, $fichier); |
|
| 954 | + |
|
| 955 | + return $ret; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + return false; |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -975,35 +975,35 @@ discard block |
||
| 975 | 975 | */ |
| 976 | 976 | function _image_imagesvg($img, $fichier) { |
| 977 | 977 | |
| 978 | - $tmp = $fichier . '.tmp'; |
|
| 979 | - if (strpos($img, '<') === false) { |
|
| 980 | - $img = supprimer_timestamp($img); |
|
| 981 | - if (!file_exists($img)) { |
|
| 982 | - return false; |
|
| 983 | - } |
|
| 984 | - @copy($img, $tmp); |
|
| 985 | - if (filesize($tmp) == filesize($img)) { |
|
| 986 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 987 | - @rename($tmp, $fichier); |
|
| 988 | - return true; |
|
| 989 | - } |
|
| 990 | - return false; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - file_put_contents($tmp, $img); |
|
| 994 | - if (file_exists($tmp)) { |
|
| 995 | - $taille_test = spip_getimagesize($tmp); |
|
| 996 | - if ($taille_test[0] < 1) { |
|
| 997 | - return false; |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1001 | - @rename($tmp, $fichier); |
|
| 1002 | - |
|
| 1003 | - return true; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - return false; |
|
| 978 | + $tmp = $fichier . '.tmp'; |
|
| 979 | + if (strpos($img, '<') === false) { |
|
| 980 | + $img = supprimer_timestamp($img); |
|
| 981 | + if (!file_exists($img)) { |
|
| 982 | + return false; |
|
| 983 | + } |
|
| 984 | + @copy($img, $tmp); |
|
| 985 | + if (filesize($tmp) == filesize($img)) { |
|
| 986 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 987 | + @rename($tmp, $fichier); |
|
| 988 | + return true; |
|
| 989 | + } |
|
| 990 | + return false; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + file_put_contents($tmp, $img); |
|
| 994 | + if (file_exists($tmp)) { |
|
| 995 | + $taille_test = spip_getimagesize($tmp); |
|
| 996 | + if ($taille_test[0] < 1) { |
|
| 997 | + return false; |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1001 | + @rename($tmp, $fichier); |
|
| 1002 | + |
|
| 1003 | + return true; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + return false; |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | |
@@ -1031,29 +1031,29 @@ discard block |
||
| 1031 | 1031 | * - false sinon. |
| 1032 | 1032 | */ |
| 1033 | 1033 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1034 | - if (is_null($fonction)) { |
|
| 1035 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1036 | - } |
|
| 1037 | - $ret = false; |
|
| 1038 | - #un flag pour reperer les images gravees |
|
| 1039 | - $lock = |
|
| 1040 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1041 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1042 | - if ( |
|
| 1043 | - function_exists($fonction) |
|
| 1044 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1045 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1046 | - && !$lock |
|
| 1047 | - ) { |
|
| 1048 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1049 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1050 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1051 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1052 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - return $ret; |
|
| 1034 | + if (is_null($fonction)) { |
|
| 1035 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1036 | + } |
|
| 1037 | + $ret = false; |
|
| 1038 | + #un flag pour reperer les images gravees |
|
| 1039 | + $lock = |
|
| 1040 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1041 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1042 | + if ( |
|
| 1043 | + function_exists($fonction) |
|
| 1044 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1045 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1046 | + && !$lock |
|
| 1047 | + ) { |
|
| 1048 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1049 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1050 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1051 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1052 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return $ret; |
|
| 1057 | 1057 | } |
| 1058 | 1058 | |
| 1059 | 1059 | /** |
@@ -1066,27 +1066,27 @@ discard block |
||
| 1066 | 1066 | * Chemin vers le fichier manquant |
| 1067 | 1067 | **/ |
| 1068 | 1068 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1069 | - $reconstruire = []; |
|
| 1070 | - $fichier = $fichier_manquant; |
|
| 1071 | - while ( |
|
| 1072 | - strpos($fichier, '://') === false |
|
| 1073 | - and !@file_exists($fichier) |
|
| 1074 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1075 | - and $valeurs = unserialize($source) |
|
| 1076 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1077 | - ) { |
|
| 1078 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1079 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1080 | - } |
|
| 1081 | - while (count($reconstruire)) { |
|
| 1082 | - $r = array_pop($reconstruire); |
|
| 1083 | - $fonction = $r[0]; |
|
| 1084 | - $args = $r[1]; |
|
| 1085 | - $fonction(...$args); |
|
| 1086 | - } |
|
| 1087 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1088 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1089 | - ramasse_miettes($fichier_manquant); |
|
| 1069 | + $reconstruire = []; |
|
| 1070 | + $fichier = $fichier_manquant; |
|
| 1071 | + while ( |
|
| 1072 | + strpos($fichier, '://') === false |
|
| 1073 | + and !@file_exists($fichier) |
|
| 1074 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1075 | + and $valeurs = unserialize($source) |
|
| 1076 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1077 | + ) { |
|
| 1078 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1079 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1080 | + } |
|
| 1081 | + while (count($reconstruire)) { |
|
| 1082 | + $r = array_pop($reconstruire); |
|
| 1083 | + $fonction = $r[0]; |
|
| 1084 | + $args = $r[1]; |
|
| 1085 | + $fonction(...$args); |
|
| 1086 | + } |
|
| 1087 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1088 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1089 | + ramasse_miettes($fichier_manquant); |
|
| 1090 | 1090 | } |
| 1091 | 1091 | |
| 1092 | 1092 | /** |
@@ -1106,28 +1106,28 @@ discard block |
||
| 1106 | 1106 | * Chemin du fichier d'image calculé |
| 1107 | 1107 | **/ |
| 1108 | 1108 | function ramasse_miettes($fichier) { |
| 1109 | - if ( |
|
| 1110 | - strpos($fichier, '://') !== false |
|
| 1111 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1112 | - or !$valeurs = unserialize($source) |
|
| 1113 | - ) { |
|
| 1114 | - return; |
|
| 1115 | - } |
|
| 1116 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1117 | - while ( |
|
| 1118 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1119 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1120 | - and (lire_fichier( |
|
| 1121 | - $src = "$fichier.src", |
|
| 1122 | - $source |
|
| 1123 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1124 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1125 | - ) { |
|
| 1126 | - # on efface le fichier |
|
| 1127 | - spip_unlink($fichier); |
|
| 1128 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1129 | - #spip_unlink($src); |
|
| 1130 | - } |
|
| 1109 | + if ( |
|
| 1110 | + strpos($fichier, '://') !== false |
|
| 1111 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1112 | + or !$valeurs = unserialize($source) |
|
| 1113 | + ) { |
|
| 1114 | + return; |
|
| 1115 | + } |
|
| 1116 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1117 | + while ( |
|
| 1118 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1119 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1120 | + and (lire_fichier( |
|
| 1121 | + $src = "$fichier.src", |
|
| 1122 | + $source |
|
| 1123 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1124 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1125 | + ) { |
|
| 1126 | + # on efface le fichier |
|
| 1127 | + spip_unlink($fichier); |
|
| 1128 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1129 | + #spip_unlink($src); |
|
| 1130 | + } |
|
| 1131 | 1131 | } |
| 1132 | 1132 | |
| 1133 | 1133 | |
@@ -1152,71 +1152,71 @@ discard block |
||
| 1152 | 1152 | * Code HTML de l'image |
| 1153 | 1153 | **/ |
| 1154 | 1154 | function image_graver($img) { |
| 1155 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1156 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1157 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1158 | - |
|
| 1159 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1160 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1161 | - $fichier = substr($fichier, 0, $p); |
|
| 1162 | - } |
|
| 1163 | - if (strlen($fichier) < 1) { |
|
| 1164 | - $fichier = $img; |
|
| 1165 | - } |
|
| 1166 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1167 | - # et qu'il ne s'agit pas d'une URL |
|
| 1168 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1169 | - reconstruire_image_intermediaire($fichier); |
|
| 1170 | - } |
|
| 1171 | - ramasse_miettes($fichier); |
|
| 1172 | - |
|
| 1173 | - // ajouter le timestamp si besoin |
|
| 1174 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1175 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1176 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1177 | - } |
|
| 1178 | - |
|
| 1179 | - return $img; |
|
| 1155 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1156 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1157 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1158 | + |
|
| 1159 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1160 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1161 | + $fichier = substr($fichier, 0, $p); |
|
| 1162 | + } |
|
| 1163 | + if (strlen($fichier) < 1) { |
|
| 1164 | + $fichier = $img; |
|
| 1165 | + } |
|
| 1166 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1167 | + # et qu'il ne s'agit pas d'une URL |
|
| 1168 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1169 | + reconstruire_image_intermediaire($fichier); |
|
| 1170 | + } |
|
| 1171 | + ramasse_miettes($fichier); |
|
| 1172 | + |
|
| 1173 | + // ajouter le timestamp si besoin |
|
| 1174 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1175 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1176 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1177 | + } |
|
| 1178 | + |
|
| 1179 | + return $img; |
|
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | |
| 1183 | 1183 | if (!function_exists('imagepalettetotruecolor')) { |
| 1184 | - /** |
|
| 1185 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1186 | - * |
|
| 1187 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 1188 | - * |
|
| 1189 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1190 | - * |
|
| 1191 | - * @param resource $img |
|
| 1192 | - * @return bool |
|
| 1193 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1194 | - * - false si la transformation ne peut être faite. |
|
| 1195 | - **/ |
|
| 1196 | - function imagepalettetotruecolor(&$img) { |
|
| 1197 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1198 | - return false; |
|
| 1199 | - } elseif (!imageistruecolor($img)) { |
|
| 1200 | - $w = imagesx($img); |
|
| 1201 | - $h = imagesy($img); |
|
| 1202 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 1203 | - //Conserver la transparence si possible |
|
| 1204 | - if (function_exists('ImageCopyResampled')) { |
|
| 1205 | - if (function_exists('imageAntiAlias')) { |
|
| 1206 | - imageAntiAlias($img1, true); |
|
| 1207 | - } |
|
| 1208 | - @imagealphablending($img1, false); |
|
| 1209 | - @imagesavealpha($img1, true); |
|
| 1210 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1211 | - } else { |
|
| 1212 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1213 | - } |
|
| 1214 | - |
|
| 1215 | - $img = $img1; |
|
| 1216 | - } |
|
| 1217 | - |
|
| 1218 | - return true; |
|
| 1219 | - } |
|
| 1184 | + /** |
|
| 1185 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1186 | + * |
|
| 1187 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 1188 | + * |
|
| 1189 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1190 | + * |
|
| 1191 | + * @param resource $img |
|
| 1192 | + * @return bool |
|
| 1193 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1194 | + * - false si la transformation ne peut être faite. |
|
| 1195 | + **/ |
|
| 1196 | + function imagepalettetotruecolor(&$img) { |
|
| 1197 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1198 | + return false; |
|
| 1199 | + } elseif (!imageistruecolor($img)) { |
|
| 1200 | + $w = imagesx($img); |
|
| 1201 | + $h = imagesy($img); |
|
| 1202 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 1203 | + //Conserver la transparence si possible |
|
| 1204 | + if (function_exists('ImageCopyResampled')) { |
|
| 1205 | + if (function_exists('imageAntiAlias')) { |
|
| 1206 | + imageAntiAlias($img1, true); |
|
| 1207 | + } |
|
| 1208 | + @imagealphablending($img1, false); |
|
| 1209 | + @imagesavealpha($img1, true); |
|
| 1210 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1211 | + } else { |
|
| 1212 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1213 | + } |
|
| 1214 | + |
|
| 1215 | + $img = $img1; |
|
| 1216 | + } |
|
| 1217 | + |
|
| 1218 | + return true; |
|
| 1219 | + } |
|
| 1220 | 1220 | } |
| 1221 | 1221 | |
| 1222 | 1222 | /** |
@@ -1243,34 +1243,34 @@ discard block |
||
| 1243 | 1243 | * Code html modifié de la balise. |
| 1244 | 1244 | **/ |
| 1245 | 1245 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1246 | - if ($style === false) { |
|
| 1247 | - $style = extraire_attribut($tag, 'style'); |
|
| 1248 | - } |
|
| 1249 | - |
|
| 1250 | - // enlever le width et height du style |
|
| 1251 | - if ($style) { |
|
| 1252 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1253 | - } |
|
| 1254 | - if ($style and $style[0] === ';') { |
|
| 1255 | - $style = substr($style, 1); |
|
| 1256 | - } |
|
| 1257 | - |
|
| 1258 | - // mettre des attributs de width et height sur les images, |
|
| 1259 | - // ca accelere le rendu du navigateur |
|
| 1260 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1261 | - // quand on a desactive l'affichage des images. |
|
| 1262 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1263 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1264 | - |
|
| 1265 | - // attributs deprecies. Transformer en CSS |
|
| 1266 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1267 | - $style = "margin:${espace}px;" . $style; |
|
| 1268 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1272 | - |
|
| 1273 | - return $tag; |
|
| 1246 | + if ($style === false) { |
|
| 1247 | + $style = extraire_attribut($tag, 'style'); |
|
| 1248 | + } |
|
| 1249 | + |
|
| 1250 | + // enlever le width et height du style |
|
| 1251 | + if ($style) { |
|
| 1252 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1253 | + } |
|
| 1254 | + if ($style and $style[0] === ';') { |
|
| 1255 | + $style = substr($style, 1); |
|
| 1256 | + } |
|
| 1257 | + |
|
| 1258 | + // mettre des attributs de width et height sur les images, |
|
| 1259 | + // ca accelere le rendu du navigateur |
|
| 1260 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1261 | + // quand on a desactive l'affichage des images. |
|
| 1262 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1263 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1264 | + |
|
| 1265 | + // attributs deprecies. Transformer en CSS |
|
| 1266 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1267 | + $style = "margin:${espace}px;" . $style; |
|
| 1268 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1272 | + |
|
| 1273 | + return $tag; |
|
| 1274 | 1274 | } |
| 1275 | 1275 | |
| 1276 | 1276 | |
@@ -1296,72 +1296,72 @@ discard block |
||
| 1296 | 1296 | * Retourne le code HTML de l'image |
| 1297 | 1297 | **/ |
| 1298 | 1298 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1299 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1300 | - |
|
| 1301 | - // fermer les tags img pas bien fermes; |
|
| 1302 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1303 | - |
|
| 1304 | - // le style |
|
| 1305 | - $style = $valeurs['style']; |
|
| 1306 | - if (isset($surcharge['style'])) { |
|
| 1307 | - $style = $surcharge['style']; |
|
| 1308 | - unset($surcharge['style']); |
|
| 1309 | - } |
|
| 1310 | - |
|
| 1311 | - // traiter specifiquement la largeur et la hauteur |
|
| 1312 | - $width = $valeurs['largeur']; |
|
| 1313 | - if (isset($surcharge['width'])) { |
|
| 1314 | - $width = $surcharge['width']; |
|
| 1315 | - unset($surcharge['width']); |
|
| 1316 | - } |
|
| 1317 | - $height = $valeurs['hauteur']; |
|
| 1318 | - if (isset($surcharge['height'])) { |
|
| 1319 | - $height = $surcharge['height']; |
|
| 1320 | - unset($surcharge['height']); |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1324 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1325 | - // on remplace toute les ref a src dans le tag |
|
| 1326 | - $src = extraire_attribut($tag, 'src'); |
|
| 1327 | - if (isset($surcharge['src'])) { |
|
| 1328 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1329 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1330 | - // pas garanti comme methode, mais mieux que rien |
|
| 1331 | - if (strpos($src, '&') !== false) { |
|
| 1332 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1333 | - } |
|
| 1334 | - $src = $surcharge['src']; |
|
| 1335 | - unset($surcharge['src']); |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - $class = $valeurs['class']; |
|
| 1339 | - if (isset($surcharge['class'])) { |
|
| 1340 | - $class = $surcharge['class']; |
|
| 1341 | - unset($surcharge['class']); |
|
| 1342 | - } |
|
| 1343 | - if (is_scalar($class) && strlen($class)) { |
|
| 1344 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1345 | - } |
|
| 1346 | - |
|
| 1347 | - if (count($surcharge)) { |
|
| 1348 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1349 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1350 | - } |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - $tag = pipeline( |
|
| 1354 | - 'image_ecrire_tag_finir', |
|
| 1355 | - [ |
|
| 1356 | - 'args' => [ |
|
| 1357 | - 'valeurs' => $valeurs, |
|
| 1358 | - 'surcharge' => $surcharge, |
|
| 1359 | - ], |
|
| 1360 | - 'data' => $tag |
|
| 1361 | - ] |
|
| 1362 | - ); |
|
| 1363 | - |
|
| 1364 | - return $tag; |
|
| 1299 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1300 | + |
|
| 1301 | + // fermer les tags img pas bien fermes; |
|
| 1302 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1303 | + |
|
| 1304 | + // le style |
|
| 1305 | + $style = $valeurs['style']; |
|
| 1306 | + if (isset($surcharge['style'])) { |
|
| 1307 | + $style = $surcharge['style']; |
|
| 1308 | + unset($surcharge['style']); |
|
| 1309 | + } |
|
| 1310 | + |
|
| 1311 | + // traiter specifiquement la largeur et la hauteur |
|
| 1312 | + $width = $valeurs['largeur']; |
|
| 1313 | + if (isset($surcharge['width'])) { |
|
| 1314 | + $width = $surcharge['width']; |
|
| 1315 | + unset($surcharge['width']); |
|
| 1316 | + } |
|
| 1317 | + $height = $valeurs['hauteur']; |
|
| 1318 | + if (isset($surcharge['height'])) { |
|
| 1319 | + $height = $surcharge['height']; |
|
| 1320 | + unset($surcharge['height']); |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1324 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1325 | + // on remplace toute les ref a src dans le tag |
|
| 1326 | + $src = extraire_attribut($tag, 'src'); |
|
| 1327 | + if (isset($surcharge['src'])) { |
|
| 1328 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1329 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1330 | + // pas garanti comme methode, mais mieux que rien |
|
| 1331 | + if (strpos($src, '&') !== false) { |
|
| 1332 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1333 | + } |
|
| 1334 | + $src = $surcharge['src']; |
|
| 1335 | + unset($surcharge['src']); |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + $class = $valeurs['class']; |
|
| 1339 | + if (isset($surcharge['class'])) { |
|
| 1340 | + $class = $surcharge['class']; |
|
| 1341 | + unset($surcharge['class']); |
|
| 1342 | + } |
|
| 1343 | + if (is_scalar($class) && strlen($class)) { |
|
| 1344 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1345 | + } |
|
| 1346 | + |
|
| 1347 | + if (count($surcharge)) { |
|
| 1348 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1349 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1350 | + } |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + $tag = pipeline( |
|
| 1354 | + 'image_ecrire_tag_finir', |
|
| 1355 | + [ |
|
| 1356 | + 'args' => [ |
|
| 1357 | + 'valeurs' => $valeurs, |
|
| 1358 | + 'surcharge' => $surcharge, |
|
| 1359 | + ], |
|
| 1360 | + 'data' => $tag |
|
| 1361 | + ] |
|
| 1362 | + ); |
|
| 1363 | + |
|
| 1364 | + return $tag; |
|
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | 1367 | /** |
@@ -1384,259 +1384,259 @@ discard block |
||
| 1384 | 1384 | * Description de l'image, sinon null. |
| 1385 | 1385 | **/ |
| 1386 | 1386 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1387 | - $srcHeight = null; |
|
| 1388 | - $retour = []; |
|
| 1389 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1390 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1391 | - $image = $valeurs['fichier']; |
|
| 1392 | - $format = $valeurs['format_source']; |
|
| 1393 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1394 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1395 | - |
|
| 1396 | - $format_sortie = $valeurs['format_dest']; |
|
| 1397 | - |
|
| 1398 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1399 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1403 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1404 | - return; |
|
| 1405 | - } |
|
| 1406 | - $destination = "$destdir/$destfile"; |
|
| 1407 | - |
|
| 1408 | - // calculer la taille |
|
| 1409 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1410 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1411 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1412 | - } |
|
| 1413 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1414 | - $destWidth = $maxWidth; |
|
| 1415 | - $destHeight = $maxHeight; |
|
| 1416 | - } else { |
|
| 1417 | - spip_log("echec $process sur $image"); |
|
| 1418 | - |
|
| 1419 | - return; |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - $vignette = ''; |
|
| 1423 | - |
|
| 1424 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1425 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1426 | - $vignette = $destination . '.' . $format; |
|
| 1427 | - @copy($image, $vignette); |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1431 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1432 | - $format_sortie = 'svg'; |
|
| 1433 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1434 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1435 | - _image_gd_output($svg, $valeurs); |
|
| 1436 | - } |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - // imagemagick en ligne de commande |
|
| 1440 | - elseif ($process == 'convert') { |
|
| 1441 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1442 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1443 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1444 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1445 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1446 | - } |
|
| 1447 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1448 | - $commande = str_replace( |
|
| 1449 | - ['%x', '%y', '%src', '%dest'], |
|
| 1450 | - [ |
|
| 1451 | - $destWidth, |
|
| 1452 | - $destHeight, |
|
| 1453 | - escapeshellcmd($image), |
|
| 1454 | - escapeshellcmd($vignette) |
|
| 1455 | - ], |
|
| 1456 | - _RESIZE_COMMAND |
|
| 1457 | - ); |
|
| 1458 | - spip_log($commande); |
|
| 1459 | - exec($commande); |
|
| 1460 | - if (!@file_exists($vignette)) { |
|
| 1461 | - spip_log("echec convert sur $vignette"); |
|
| 1462 | - |
|
| 1463 | - return; // echec commande |
|
| 1464 | - } |
|
| 1465 | - } |
|
| 1466 | - |
|
| 1467 | - // php5 imagemagick |
|
| 1468 | - elseif ($process == 'imagick') { |
|
| 1469 | - $vignette = "$destination." . $format_sortie; |
|
| 1470 | - |
|
| 1471 | - if (!class_exists(\Imagick::class)) { |
|
| 1472 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1473 | - |
|
| 1474 | - return; |
|
| 1475 | - } |
|
| 1476 | - $imagick = new Imagick(); |
|
| 1477 | - $imagick->readImage($image); |
|
| 1478 | - $imagick->resizeImage( |
|
| 1479 | - $destWidth, |
|
| 1480 | - $destHeight, |
|
| 1481 | - Imagick::FILTER_LANCZOS, |
|
| 1482 | - 1 |
|
| 1483 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1484 | - $imagick->writeImage($vignette); |
|
| 1485 | - |
|
| 1486 | - if (!@file_exists($vignette)) { |
|
| 1487 | - spip_log("echec imagick sur $vignette"); |
|
| 1488 | - |
|
| 1489 | - return; |
|
| 1490 | - } |
|
| 1491 | - } |
|
| 1492 | - |
|
| 1493 | - // netpbm |
|
| 1494 | - elseif ($process == 'netpbm') { |
|
| 1495 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1496 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1497 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1498 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1499 | - return; |
|
| 1500 | - } |
|
| 1501 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1502 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1503 | - if ($format == 'jpg') { |
|
| 1504 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1505 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1506 | - if (!($s = @filesize($vignette))) { |
|
| 1507 | - spip_unlink($vignette); |
|
| 1508 | - } |
|
| 1509 | - if (!@file_exists($vignette)) { |
|
| 1510 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1511 | - |
|
| 1512 | - return; |
|
| 1513 | - } |
|
| 1514 | - } else { |
|
| 1515 | - if ($format == 'gif') { |
|
| 1516 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1517 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1518 | - if (!($s = @filesize($vignette))) { |
|
| 1519 | - spip_unlink($vignette); |
|
| 1520 | - } |
|
| 1521 | - if (!@file_exists($vignette)) { |
|
| 1522 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1523 | - |
|
| 1524 | - return; |
|
| 1525 | - } |
|
| 1526 | - } else { |
|
| 1527 | - if ($format == 'png') { |
|
| 1528 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1529 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1530 | - if (!($s = @filesize($vignette))) { |
|
| 1531 | - spip_unlink($vignette); |
|
| 1532 | - } |
|
| 1533 | - if (!@file_exists($vignette)) { |
|
| 1534 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1535 | - |
|
| 1536 | - return; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1540 | - } |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - // gd ou gd2 |
|
| 1544 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1545 | - if (!function_exists('gd_info')) { |
|
| 1546 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1547 | - |
|
| 1548 | - return; |
|
| 1549 | - } |
|
| 1550 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1551 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1552 | - |
|
| 1553 | - return; |
|
| 1554 | - } |
|
| 1555 | - $destFormat = $format_sortie; |
|
| 1556 | - if (!$destFormat) { |
|
| 1557 | - spip_log("pas de format pour $image"); |
|
| 1558 | - |
|
| 1559 | - return; |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1563 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1564 | - return; |
|
| 1565 | - } |
|
| 1566 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1567 | - if (!$srcImage) { |
|
| 1568 | - spip_log('echec gd1/gd2'); |
|
| 1569 | - |
|
| 1570 | - return; |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - // Initialisation de l'image destination |
|
| 1574 | - $destImage = null; |
|
| 1575 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1576 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1577 | - } |
|
| 1578 | - if (!$destImage) { |
|
| 1579 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1583 | - $ok = false; |
|
| 1584 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1585 | - if ($format == 'gif') { |
|
| 1586 | - // Si un GIF est transparent, |
|
| 1587 | - // fabriquer un PNG transparent |
|
| 1588 | - $transp = imagecolortransparent($srcImage); |
|
| 1589 | - if ($transp > 0) { |
|
| 1590 | - $destFormat = 'png'; |
|
| 1591 | - } |
|
| 1592 | - } |
|
| 1593 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1594 | - // Conserver la transparence |
|
| 1595 | - if (function_exists('imageAntiAlias')) { |
|
| 1596 | - imageAntiAlias($destImage, true); |
|
| 1597 | - } |
|
| 1598 | - @imagealphablending($destImage, false); |
|
| 1599 | - @imagesavealpha($destImage, true); |
|
| 1600 | - } |
|
| 1601 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1602 | - } |
|
| 1603 | - if (!$ok) { |
|
| 1604 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1605 | - } |
|
| 1606 | - |
|
| 1607 | - // Sauvegarde de l'image destination |
|
| 1608 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1609 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1610 | - _image_gd_output($destImage, $valeurs); |
|
| 1611 | - |
|
| 1612 | - if ($srcImage) { |
|
| 1613 | - ImageDestroy($srcImage); |
|
| 1614 | - } |
|
| 1615 | - ImageDestroy($destImage); |
|
| 1616 | - } |
|
| 1617 | - |
|
| 1618 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1619 | - $size = [$destWidth, $destHeight]; |
|
| 1620 | - } |
|
| 1621 | - |
|
| 1622 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1623 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1624 | - if ($size[0] < 1) { |
|
| 1625 | - $size[0] = $destWidth; |
|
| 1626 | - } |
|
| 1627 | - if ($size[1] < 1) { |
|
| 1628 | - $size[1] = $destHeight; |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - $retour['width'] = $largeur = $size[0]; |
|
| 1632 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1633 | - |
|
| 1634 | - $retour['fichier'] = $vignette; |
|
| 1635 | - $retour['format'] = $format; |
|
| 1636 | - $retour['date'] = @filemtime($vignette); |
|
| 1637 | - |
|
| 1638 | - // renvoyer l'image |
|
| 1639 | - return $retour; |
|
| 1387 | + $srcHeight = null; |
|
| 1388 | + $retour = []; |
|
| 1389 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1390 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1391 | + $image = $valeurs['fichier']; |
|
| 1392 | + $format = $valeurs['format_source']; |
|
| 1393 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1394 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1395 | + |
|
| 1396 | + $format_sortie = $valeurs['format_dest']; |
|
| 1397 | + |
|
| 1398 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1399 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1400 | + } |
|
| 1401 | + |
|
| 1402 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1403 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1404 | + return; |
|
| 1405 | + } |
|
| 1406 | + $destination = "$destdir/$destfile"; |
|
| 1407 | + |
|
| 1408 | + // calculer la taille |
|
| 1409 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1410 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1411 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1412 | + } |
|
| 1413 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1414 | + $destWidth = $maxWidth; |
|
| 1415 | + $destHeight = $maxHeight; |
|
| 1416 | + } else { |
|
| 1417 | + spip_log("echec $process sur $image"); |
|
| 1418 | + |
|
| 1419 | + return; |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + $vignette = ''; |
|
| 1423 | + |
|
| 1424 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1425 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1426 | + $vignette = $destination . '.' . $format; |
|
| 1427 | + @copy($image, $vignette); |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1431 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1432 | + $format_sortie = 'svg'; |
|
| 1433 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1434 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1435 | + _image_gd_output($svg, $valeurs); |
|
| 1436 | + } |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + // imagemagick en ligne de commande |
|
| 1440 | + elseif ($process == 'convert') { |
|
| 1441 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1442 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1443 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1444 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1445 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1446 | + } |
|
| 1447 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1448 | + $commande = str_replace( |
|
| 1449 | + ['%x', '%y', '%src', '%dest'], |
|
| 1450 | + [ |
|
| 1451 | + $destWidth, |
|
| 1452 | + $destHeight, |
|
| 1453 | + escapeshellcmd($image), |
|
| 1454 | + escapeshellcmd($vignette) |
|
| 1455 | + ], |
|
| 1456 | + _RESIZE_COMMAND |
|
| 1457 | + ); |
|
| 1458 | + spip_log($commande); |
|
| 1459 | + exec($commande); |
|
| 1460 | + if (!@file_exists($vignette)) { |
|
| 1461 | + spip_log("echec convert sur $vignette"); |
|
| 1462 | + |
|
| 1463 | + return; // echec commande |
|
| 1464 | + } |
|
| 1465 | + } |
|
| 1466 | + |
|
| 1467 | + // php5 imagemagick |
|
| 1468 | + elseif ($process == 'imagick') { |
|
| 1469 | + $vignette = "$destination." . $format_sortie; |
|
| 1470 | + |
|
| 1471 | + if (!class_exists(\Imagick::class)) { |
|
| 1472 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1473 | + |
|
| 1474 | + return; |
|
| 1475 | + } |
|
| 1476 | + $imagick = new Imagick(); |
|
| 1477 | + $imagick->readImage($image); |
|
| 1478 | + $imagick->resizeImage( |
|
| 1479 | + $destWidth, |
|
| 1480 | + $destHeight, |
|
| 1481 | + Imagick::FILTER_LANCZOS, |
|
| 1482 | + 1 |
|
| 1483 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1484 | + $imagick->writeImage($vignette); |
|
| 1485 | + |
|
| 1486 | + if (!@file_exists($vignette)) { |
|
| 1487 | + spip_log("echec imagick sur $vignette"); |
|
| 1488 | + |
|
| 1489 | + return; |
|
| 1490 | + } |
|
| 1491 | + } |
|
| 1492 | + |
|
| 1493 | + // netpbm |
|
| 1494 | + elseif ($process == 'netpbm') { |
|
| 1495 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1496 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1497 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1498 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1499 | + return; |
|
| 1500 | + } |
|
| 1501 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1502 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1503 | + if ($format == 'jpg') { |
|
| 1504 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1505 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1506 | + if (!($s = @filesize($vignette))) { |
|
| 1507 | + spip_unlink($vignette); |
|
| 1508 | + } |
|
| 1509 | + if (!@file_exists($vignette)) { |
|
| 1510 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1511 | + |
|
| 1512 | + return; |
|
| 1513 | + } |
|
| 1514 | + } else { |
|
| 1515 | + if ($format == 'gif') { |
|
| 1516 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1517 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1518 | + if (!($s = @filesize($vignette))) { |
|
| 1519 | + spip_unlink($vignette); |
|
| 1520 | + } |
|
| 1521 | + if (!@file_exists($vignette)) { |
|
| 1522 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1523 | + |
|
| 1524 | + return; |
|
| 1525 | + } |
|
| 1526 | + } else { |
|
| 1527 | + if ($format == 'png') { |
|
| 1528 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1529 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1530 | + if (!($s = @filesize($vignette))) { |
|
| 1531 | + spip_unlink($vignette); |
|
| 1532 | + } |
|
| 1533 | + if (!@file_exists($vignette)) { |
|
| 1534 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1535 | + |
|
| 1536 | + return; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | + } |
|
| 1541 | + } |
|
| 1542 | + |
|
| 1543 | + // gd ou gd2 |
|
| 1544 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1545 | + if (!function_exists('gd_info')) { |
|
| 1546 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1547 | + |
|
| 1548 | + return; |
|
| 1549 | + } |
|
| 1550 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1551 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1552 | + |
|
| 1553 | + return; |
|
| 1554 | + } |
|
| 1555 | + $destFormat = $format_sortie; |
|
| 1556 | + if (!$destFormat) { |
|
| 1557 | + spip_log("pas de format pour $image"); |
|
| 1558 | + |
|
| 1559 | + return; |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1563 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1564 | + return; |
|
| 1565 | + } |
|
| 1566 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1567 | + if (!$srcImage) { |
|
| 1568 | + spip_log('echec gd1/gd2'); |
|
| 1569 | + |
|
| 1570 | + return; |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + // Initialisation de l'image destination |
|
| 1574 | + $destImage = null; |
|
| 1575 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1576 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1577 | + } |
|
| 1578 | + if (!$destImage) { |
|
| 1579 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1580 | + } |
|
| 1581 | + |
|
| 1582 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1583 | + $ok = false; |
|
| 1584 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1585 | + if ($format == 'gif') { |
|
| 1586 | + // Si un GIF est transparent, |
|
| 1587 | + // fabriquer un PNG transparent |
|
| 1588 | + $transp = imagecolortransparent($srcImage); |
|
| 1589 | + if ($transp > 0) { |
|
| 1590 | + $destFormat = 'png'; |
|
| 1591 | + } |
|
| 1592 | + } |
|
| 1593 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1594 | + // Conserver la transparence |
|
| 1595 | + if (function_exists('imageAntiAlias')) { |
|
| 1596 | + imageAntiAlias($destImage, true); |
|
| 1597 | + } |
|
| 1598 | + @imagealphablending($destImage, false); |
|
| 1599 | + @imagesavealpha($destImage, true); |
|
| 1600 | + } |
|
| 1601 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1602 | + } |
|
| 1603 | + if (!$ok) { |
|
| 1604 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1605 | + } |
|
| 1606 | + |
|
| 1607 | + // Sauvegarde de l'image destination |
|
| 1608 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1609 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1610 | + _image_gd_output($destImage, $valeurs); |
|
| 1611 | + |
|
| 1612 | + if ($srcImage) { |
|
| 1613 | + ImageDestroy($srcImage); |
|
| 1614 | + } |
|
| 1615 | + ImageDestroy($destImage); |
|
| 1616 | + } |
|
| 1617 | + |
|
| 1618 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1619 | + $size = [$destWidth, $destHeight]; |
|
| 1620 | + } |
|
| 1621 | + |
|
| 1622 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1623 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1624 | + if ($size[0] < 1) { |
|
| 1625 | + $size[0] = $destWidth; |
|
| 1626 | + } |
|
| 1627 | + if ($size[1] < 1) { |
|
| 1628 | + $size[1] = $destHeight; |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + $retour['width'] = $largeur = $size[0]; |
|
| 1632 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1633 | + |
|
| 1634 | + $retour['fichier'] = $vignette; |
|
| 1635 | + $retour['format'] = $format; |
|
| 1636 | + $retour['date'] = @filemtime($vignette); |
|
| 1637 | + |
|
| 1638 | + // renvoyer l'image |
|
| 1639 | + return $retour; |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | /** |
@@ -1656,25 +1656,25 @@ discard block |
||
| 1656 | 1656 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1657 | 1657 | **/ |
| 1658 | 1658 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1659 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1660 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1661 | - |
|
| 1662 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1663 | - $destWidth = $srcWidth; |
|
| 1664 | - $destHeight = $srcHeight; |
|
| 1665 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1666 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1667 | - $destHeight = $maxHeight; |
|
| 1668 | - } else { |
|
| 1669 | - $destWidth = $maxWidth; |
|
| 1670 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1671 | - } |
|
| 1672 | - |
|
| 1673 | - return [ |
|
| 1674 | - intval(round($destWidth)), |
|
| 1675 | - intval(round($destHeight)), |
|
| 1676 | - max($ratioWidth, $ratioHeight) |
|
| 1677 | - ]; |
|
| 1659 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1660 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1661 | + |
|
| 1662 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1663 | + $destWidth = $srcWidth; |
|
| 1664 | + $destHeight = $srcHeight; |
|
| 1665 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1666 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1667 | + $destHeight = $maxHeight; |
|
| 1668 | + } else { |
|
| 1669 | + $destWidth = $maxWidth; |
|
| 1670 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1671 | + } |
|
| 1672 | + |
|
| 1673 | + return [ |
|
| 1674 | + intval(round($destWidth)), |
|
| 1675 | + intval(round($destHeight)), |
|
| 1676 | + max($ratioWidth, $ratioHeight) |
|
| 1677 | + ]; |
|
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | 1680 | /** |
@@ -1694,25 +1694,25 @@ discard block |
||
| 1694 | 1694 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1695 | 1695 | **/ |
| 1696 | 1696 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1697 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1698 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1699 | - |
|
| 1700 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1701 | - $destWidth = $srcWidth; |
|
| 1702 | - $destHeight = $srcHeight; |
|
| 1703 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1704 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1705 | - $destHeight = $maxHeight; |
|
| 1706 | - } else { |
|
| 1707 | - $destWidth = $maxWidth; |
|
| 1708 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1709 | - } |
|
| 1710 | - |
|
| 1711 | - return [ |
|
| 1712 | - intval(round($destWidth)), |
|
| 1713 | - intval(round($destHeight)), |
|
| 1714 | - min($ratioWidth, $ratioHeight) |
|
| 1715 | - ]; |
|
| 1697 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1698 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1699 | + |
|
| 1700 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1701 | + $destWidth = $srcWidth; |
|
| 1702 | + $destHeight = $srcHeight; |
|
| 1703 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1704 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1705 | + $destHeight = $maxHeight; |
|
| 1706 | + } else { |
|
| 1707 | + $destWidth = $maxWidth; |
|
| 1708 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1709 | + } |
|
| 1710 | + |
|
| 1711 | + return [ |
|
| 1712 | + intval(round($destWidth)), |
|
| 1713 | + intval(round($destHeight)), |
|
| 1714 | + min($ratioWidth, $ratioHeight) |
|
| 1715 | + ]; |
|
| 1716 | 1716 | } |
| 1717 | 1717 | |
| 1718 | 1718 | |
@@ -1725,12 +1725,12 @@ discard block |
||
| 1725 | 1725 | * @return string |
| 1726 | 1726 | */ |
| 1727 | 1727 | function process_image_svg_identite($image) { |
| 1728 | - if ($image['creer']) { |
|
| 1729 | - $source = $image['fichier']; |
|
| 1730 | - _image_gd_output($source, $image); |
|
| 1731 | - } |
|
| 1728 | + if ($image['creer']) { |
|
| 1729 | + $source = $image['fichier']; |
|
| 1730 | + _image_gd_output($source, $image); |
|
| 1731 | + } |
|
| 1732 | 1732 | |
| 1733 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1733 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1734 | 1734 | } |
| 1735 | 1735 | |
| 1736 | 1736 | |
@@ -1763,111 +1763,111 @@ discard block |
||
| 1763 | 1763 | * Code HTML de la balise img produite |
| 1764 | 1764 | **/ |
| 1765 | 1765 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1766 | - $image = false; |
|
| 1767 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1768 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1769 | - } |
|
| 1770 | - # determiner le format de sortie |
|
| 1771 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1772 | - if ($process == 'netpbm') { |
|
| 1773 | - $format_sortie = 'jpg'; |
|
| 1774 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1775 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1776 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1777 | - $gd_formats = formats_image_acceptables(true); |
|
| 1778 | - if ( |
|
| 1779 | - is_array($image) |
|
| 1780 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1781 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1782 | - ) |
|
| 1783 | - ) { |
|
| 1784 | - if ($image['format_source'] == 'jpg') { |
|
| 1785 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1786 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1787 | - { |
|
| 1788 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1789 | - } |
|
| 1790 | - // Choisir le format destination |
|
| 1791 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1792 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1793 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1794 | - # pas *ecrire* |
|
| 1795 | - $format_sortie = ''; |
|
| 1796 | - foreach ($formats_sortie as $fmt) { |
|
| 1797 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1798 | - $format_sortie = $fmt; |
|
| 1799 | - break; |
|
| 1800 | - } |
|
| 1801 | - } |
|
| 1802 | - $image = false; |
|
| 1803 | - } |
|
| 1804 | - } |
|
| 1805 | - |
|
| 1806 | - if (!is_array($image)) { |
|
| 1807 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1808 | - } |
|
| 1809 | - |
|
| 1810 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1811 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1812 | - // on peut resizer en mode html si on dispose des elements |
|
| 1813 | - if ( |
|
| 1814 | - $srcw = extraire_attribut($img, 'width') |
|
| 1815 | - and $srch = extraire_attribut($img, 'height') |
|
| 1816 | - ) { |
|
| 1817 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1818 | - |
|
| 1819 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1820 | - } |
|
| 1821 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1822 | - // sous la forme style='max-width: NNpx;' |
|
| 1823 | - return inserer_attribut( |
|
| 1824 | - $img, |
|
| 1825 | - 'style', |
|
| 1826 | - "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1827 | - ); |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1831 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1832 | - if ($image['creer']) { |
|
| 1833 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1834 | - } |
|
| 1835 | - |
|
| 1836 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1837 | - } |
|
| 1838 | - |
|
| 1839 | - if ($image['creer'] == false && !$force) { |
|
| 1840 | - return _image_ecrire_tag( |
|
| 1841 | - $image, |
|
| 1842 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1843 | - ); |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1847 | - $destWidth = $image['largeur_dest']; |
|
| 1848 | - $destHeight = $image['hauteur_dest']; |
|
| 1849 | - $logo = $image['fichier']; |
|
| 1850 | - $date = $image['date_src']; |
|
| 1851 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1852 | - |
|
| 1853 | - if ($preview && $preview['fichier']) { |
|
| 1854 | - $logo = $preview['fichier']; |
|
| 1855 | - $destWidth = $preview['width']; |
|
| 1856 | - $destHeight = $preview['height']; |
|
| 1857 | - $date = $preview['date']; |
|
| 1858 | - } |
|
| 1859 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1860 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1861 | - // quand on fait supprimer/reuploader un logo |
|
| 1862 | - // (pas de filemtime si SAFE MODE) |
|
| 1863 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1864 | - |
|
| 1865 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1866 | - } |
|
| 1867 | - else { |
|
| 1868 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1869 | - return $img; |
|
| 1870 | - } |
|
| 1766 | + $image = false; |
|
| 1767 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1768 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1769 | + } |
|
| 1770 | + # determiner le format de sortie |
|
| 1771 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1772 | + if ($process == 'netpbm') { |
|
| 1773 | + $format_sortie = 'jpg'; |
|
| 1774 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1775 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1776 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1777 | + $gd_formats = formats_image_acceptables(true); |
|
| 1778 | + if ( |
|
| 1779 | + is_array($image) |
|
| 1780 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1781 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1782 | + ) |
|
| 1783 | + ) { |
|
| 1784 | + if ($image['format_source'] == 'jpg') { |
|
| 1785 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1786 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1787 | + { |
|
| 1788 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1789 | + } |
|
| 1790 | + // Choisir le format destination |
|
| 1791 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1792 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1793 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1794 | + # pas *ecrire* |
|
| 1795 | + $format_sortie = ''; |
|
| 1796 | + foreach ($formats_sortie as $fmt) { |
|
| 1797 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1798 | + $format_sortie = $fmt; |
|
| 1799 | + break; |
|
| 1800 | + } |
|
| 1801 | + } |
|
| 1802 | + $image = false; |
|
| 1803 | + } |
|
| 1804 | + } |
|
| 1805 | + |
|
| 1806 | + if (!is_array($image)) { |
|
| 1807 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1808 | + } |
|
| 1809 | + |
|
| 1810 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1811 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1812 | + // on peut resizer en mode html si on dispose des elements |
|
| 1813 | + if ( |
|
| 1814 | + $srcw = extraire_attribut($img, 'width') |
|
| 1815 | + and $srch = extraire_attribut($img, 'height') |
|
| 1816 | + ) { |
|
| 1817 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1818 | + |
|
| 1819 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1820 | + } |
|
| 1821 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1822 | + // sous la forme style='max-width: NNpx;' |
|
| 1823 | + return inserer_attribut( |
|
| 1824 | + $img, |
|
| 1825 | + 'style', |
|
| 1826 | + "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1827 | + ); |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1831 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1832 | + if ($image['creer']) { |
|
| 1833 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1834 | + } |
|
| 1835 | + |
|
| 1836 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1837 | + } |
|
| 1838 | + |
|
| 1839 | + if ($image['creer'] == false && !$force) { |
|
| 1840 | + return _image_ecrire_tag( |
|
| 1841 | + $image, |
|
| 1842 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1843 | + ); |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1847 | + $destWidth = $image['largeur_dest']; |
|
| 1848 | + $destHeight = $image['hauteur_dest']; |
|
| 1849 | + $logo = $image['fichier']; |
|
| 1850 | + $date = $image['date_src']; |
|
| 1851 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1852 | + |
|
| 1853 | + if ($preview && $preview['fichier']) { |
|
| 1854 | + $logo = $preview['fichier']; |
|
| 1855 | + $destWidth = $preview['width']; |
|
| 1856 | + $destHeight = $preview['height']; |
|
| 1857 | + $date = $preview['date']; |
|
| 1858 | + } |
|
| 1859 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1860 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1861 | + // quand on fait supprimer/reuploader un logo |
|
| 1862 | + // (pas de filemtime si SAFE MODE) |
|
| 1863 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1864 | + |
|
| 1865 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1866 | + } |
|
| 1867 | + else { |
|
| 1868 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1869 | + return $img; |
|
| 1870 | + } |
|
| 1871 | 1871 | } |
| 1872 | 1872 | |
| 1873 | 1873 | /** |
@@ -1881,145 +1881,145 @@ discard block |
||
| 1881 | 1881 | * Class phpthumb_functions |
| 1882 | 1882 | */ |
| 1883 | 1883 | class phpthumb_functions { |
| 1884 | - /** |
|
| 1885 | - * Retourne la couleur d'un pixel dans une image |
|
| 1886 | - * |
|
| 1887 | - * @param resource|GdImage $img |
|
| 1888 | - * @param int $x |
|
| 1889 | - * @param int $y |
|
| 1890 | - * @return array|bool |
|
| 1891 | - */ |
|
| 1892 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1893 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1894 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1895 | - } |
|
| 1896 | - return false; |
|
| 1897 | - } |
|
| 1898 | - |
|
| 1899 | - /** |
|
| 1900 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1901 | - * |
|
| 1902 | - * @param int $number |
|
| 1903 | - * @param int $minbytes |
|
| 1904 | - * @return string |
|
| 1905 | - */ |
|
| 1906 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1907 | - $intstring = ''; |
|
| 1908 | - while ($number > 0) { |
|
| 1909 | - $intstring = $intstring . chr($number & 255); |
|
| 1910 | - $number >>= 8; |
|
| 1911 | - } |
|
| 1912 | - |
|
| 1913 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1914 | - } |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * Transforme une ressource GD en image au format ICO |
|
| 1918 | - * |
|
| 1919 | - * @param array $gd_image_array |
|
| 1920 | - * Tableau de ressources d'images GD |
|
| 1921 | - * @return string |
|
| 1922 | - * Image au format ICO |
|
| 1923 | - */ |
|
| 1924 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1925 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1926 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1927 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1928 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1929 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1930 | - |
|
| 1931 | - $icXOR[$key] = ''; |
|
| 1932 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1933 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1934 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1935 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1936 | - $r = $argb['red']; |
|
| 1937 | - $g = $argb['green']; |
|
| 1938 | - $b = $argb['blue']; |
|
| 1939 | - |
|
| 1940 | - if ($bpp[$key] == 32) { |
|
| 1941 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1942 | - } elseif ($bpp[$key] == 24) { |
|
| 1943 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1944 | - } |
|
| 1945 | - |
|
| 1946 | - if ($a < 128) { |
|
| 1947 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1948 | - } else { |
|
| 1949 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1950 | - } |
|
| 1951 | - } |
|
| 1952 | - // mask bits are 32-bit aligned per scanline |
|
| 1953 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1954 | - $icANDmask[$key][$y] .= '0'; |
|
| 1955 | - } |
|
| 1956 | - } |
|
| 1957 | - $icAND[$key] = ''; |
|
| 1958 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1959 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1960 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1961 | - } |
|
| 1962 | - } |
|
| 1963 | - } |
|
| 1964 | - |
|
| 1965 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1966 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1967 | - |
|
| 1968 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1969 | - $BitmapInfoHeader[$key] = ''; |
|
| 1970 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1971 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1972 | - // The biHeight member specifies the combined |
|
| 1973 | - // height of the XOR and AND masks. |
|
| 1974 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1975 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1976 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1977 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1978 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1979 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1980 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1981 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1982 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1983 | - } |
|
| 1984 | - |
|
| 1985 | - |
|
| 1986 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1987 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1988 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1989 | - |
|
| 1990 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1991 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1992 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1993 | - |
|
| 1994 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1995 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1996 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1997 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1998 | - |
|
| 1999 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 2000 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 2001 | - |
|
| 2002 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 2003 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2004 | - $dwBytesInRes, |
|
| 2005 | - 4 |
|
| 2006 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2007 | - |
|
| 2008 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2009 | - $dwImageOffset, |
|
| 2010 | - 4 |
|
| 2011 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 2012 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2013 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 2014 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 2018 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 2019 | - $icondata .= $icXOR[$key]; |
|
| 2020 | - $icondata .= $icAND[$key]; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - return $icondata; |
|
| 2024 | - } |
|
| 1884 | + /** |
|
| 1885 | + * Retourne la couleur d'un pixel dans une image |
|
| 1886 | + * |
|
| 1887 | + * @param resource|GdImage $img |
|
| 1888 | + * @param int $x |
|
| 1889 | + * @param int $y |
|
| 1890 | + * @return array|bool |
|
| 1891 | + */ |
|
| 1892 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1893 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1894 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1895 | + } |
|
| 1896 | + return false; |
|
| 1897 | + } |
|
| 1898 | + |
|
| 1899 | + /** |
|
| 1900 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1901 | + * |
|
| 1902 | + * @param int $number |
|
| 1903 | + * @param int $minbytes |
|
| 1904 | + * @return string |
|
| 1905 | + */ |
|
| 1906 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1907 | + $intstring = ''; |
|
| 1908 | + while ($number > 0) { |
|
| 1909 | + $intstring = $intstring . chr($number & 255); |
|
| 1910 | + $number >>= 8; |
|
| 1911 | + } |
|
| 1912 | + |
|
| 1913 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1914 | + } |
|
| 1915 | + |
|
| 1916 | + /** |
|
| 1917 | + * Transforme une ressource GD en image au format ICO |
|
| 1918 | + * |
|
| 1919 | + * @param array $gd_image_array |
|
| 1920 | + * Tableau de ressources d'images GD |
|
| 1921 | + * @return string |
|
| 1922 | + * Image au format ICO |
|
| 1923 | + */ |
|
| 1924 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1925 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1926 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1927 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1928 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1929 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1930 | + |
|
| 1931 | + $icXOR[$key] = ''; |
|
| 1932 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1933 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1934 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1935 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1936 | + $r = $argb['red']; |
|
| 1937 | + $g = $argb['green']; |
|
| 1938 | + $b = $argb['blue']; |
|
| 1939 | + |
|
| 1940 | + if ($bpp[$key] == 32) { |
|
| 1941 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1942 | + } elseif ($bpp[$key] == 24) { |
|
| 1943 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1944 | + } |
|
| 1945 | + |
|
| 1946 | + if ($a < 128) { |
|
| 1947 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1948 | + } else { |
|
| 1949 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1950 | + } |
|
| 1951 | + } |
|
| 1952 | + // mask bits are 32-bit aligned per scanline |
|
| 1953 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1954 | + $icANDmask[$key][$y] .= '0'; |
|
| 1955 | + } |
|
| 1956 | + } |
|
| 1957 | + $icAND[$key] = ''; |
|
| 1958 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1959 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1960 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1961 | + } |
|
| 1962 | + } |
|
| 1963 | + } |
|
| 1964 | + |
|
| 1965 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1966 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1967 | + |
|
| 1968 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1969 | + $BitmapInfoHeader[$key] = ''; |
|
| 1970 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1971 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1972 | + // The biHeight member specifies the combined |
|
| 1973 | + // height of the XOR and AND masks. |
|
| 1974 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1975 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1976 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1977 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1978 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1979 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1980 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1981 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1982 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + |
|
| 1986 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1987 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1988 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1989 | + |
|
| 1990 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1991 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1992 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1993 | + |
|
| 1994 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1995 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1996 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1997 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1998 | + |
|
| 1999 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 2000 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 2001 | + |
|
| 2002 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 2003 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2004 | + $dwBytesInRes, |
|
| 2005 | + 4 |
|
| 2006 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2007 | + |
|
| 2008 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2009 | + $dwImageOffset, |
|
| 2010 | + 4 |
|
| 2011 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 2012 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2013 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 2014 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 2018 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 2019 | + $icondata .= $icXOR[$key]; |
|
| 2020 | + $icondata .= $icAND[$key]; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + return $icondata; |
|
| 2024 | + } |
|
| 2025 | 2025 | } |
@@ -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 | /** |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | - public $icone; |
|
| 30 | - |
|
| 31 | - /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** @var array Sous-barre de boutons / onglets */ |
|
| 47 | - public $sousmenu = []; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Définit un bouton |
|
| 51 | - * |
|
| 52 | - * @param string $icone |
|
| 53 | - * L'icone à mettre dans le bouton |
|
| 54 | - * @param string $libelle |
|
| 55 | - * Le nom de l'entrée i18n associé |
|
| 56 | - * @param null|string $url |
|
| 57 | - * L'URL de la page |
|
| 58 | - * @param null|string|array $urlArg |
|
| 59 | - * Arguments supplémentaires de l'URL |
|
| 60 | - * @param null|string $url2 |
|
| 61 | - * URL du javascript |
|
| 62 | - * @param null|mixed $target |
|
| 63 | - * Pour ouvrir une fenêtre à part |
|
| 64 | - */ |
|
| 65 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | - $this->icone = $icone; |
|
| 67 | - $this->libelle = $libelle; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->urlArg = $urlArg; |
|
| 70 | - $this->url2 = $url2; |
|
| 71 | - $this->target = $target; |
|
| 72 | - } |
|
| 28 | + /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | + public $icone; |
|
| 30 | + |
|
| 31 | + /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** @var array Sous-barre de boutons / onglets */ |
|
| 47 | + public $sousmenu = []; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Définit un bouton |
|
| 51 | + * |
|
| 52 | + * @param string $icone |
|
| 53 | + * L'icone à mettre dans le bouton |
|
| 54 | + * @param string $libelle |
|
| 55 | + * Le nom de l'entrée i18n associé |
|
| 56 | + * @param null|string $url |
|
| 57 | + * L'URL de la page |
|
| 58 | + * @param null|string|array $urlArg |
|
| 59 | + * Arguments supplémentaires de l'URL |
|
| 60 | + * @param null|string $url2 |
|
| 61 | + * URL du javascript |
|
| 62 | + * @param null|mixed $target |
|
| 63 | + * Pour ouvrir une fenêtre à part |
|
| 64 | + */ |
|
| 65 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | + $this->icone = $icone; |
|
| 67 | + $this->libelle = $libelle; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->urlArg = $urlArg; |
|
| 70 | + $this->url2 = $url2; |
|
| 71 | + $this->target = $target; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function definir_barre_onglets($script) { |
| 88 | 88 | |
| 89 | - $onglets = []; |
|
| 90 | - $liste_onglets = []; |
|
| 91 | - |
|
| 92 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | - if (function_exists('onglets_plugins')) { |
|
| 94 | - $liste_onglets = onglets_plugins(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - foreach ($liste_onglets as $id => $infos) { |
|
| 99 | - if ( |
|
| 100 | - ($parent = $infos['parent']) |
|
| 101 | - && $parent == $script |
|
| 102 | - && autoriser('onglet', "_$id") |
|
| 103 | - ) { |
|
| 104 | - $onglets[$id] = new Bouton( |
|
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 107 | - (isset($infos['action']) and $infos['action']) |
|
| 108 | - ? generer_url_ecrire( |
|
| 109 | - $infos['action'], |
|
| 110 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | - ) |
|
| 112 | - : null |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 89 | + $onglets = []; |
|
| 90 | + $liste_onglets = []; |
|
| 91 | + |
|
| 92 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | + if (function_exists('onglets_plugins')) { |
|
| 94 | + $liste_onglets = onglets_plugins(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + foreach ($liste_onglets as $id => $infos) { |
|
| 99 | + if ( |
|
| 100 | + ($parent = $infos['parent']) |
|
| 101 | + && $parent == $script |
|
| 102 | + && autoriser('onglet', "_$id") |
|
| 103 | + ) { |
|
| 104 | + $onglets[$id] = new Bouton( |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | + (isset($infos['action']) and $infos['action']) |
|
| 108 | + ? generer_url_ecrire( |
|
| 109 | + $infos['action'], |
|
| 110 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | + ) |
|
| 112 | + : null |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 136 | - include_spip('inc/presentation'); |
|
| 136 | + include_spip('inc/presentation'); |
|
| 137 | 137 | |
| 138 | - $res = ''; |
|
| 138 | + $res = ''; |
|
| 139 | 139 | |
| 140 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | - } |
|
| 140 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 146 | 146 | } |
@@ -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 is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 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 is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 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,43 +474,43 @@ 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 | - |
|
| 488 | - default: |
|
| 489 | - $charset = load_charset($charset); |
|
| 490 | - |
|
| 491 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 492 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if (!isset($trans[$charset])) { |
|
| 496 | - $trans[$charset] = []; |
|
| 497 | - $t = &$trans[$charset]; |
|
| 498 | - for ($e = 128; $e < 255; $e++) { |
|
| 499 | - $h = dechex($e); |
|
| 500 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 501 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 502 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 503 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 504 | - } else { |
|
| 505 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 506 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 511 | - |
|
| 512 | - return $texte; |
|
| 513 | - } |
|
| 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 | + |
|
| 488 | + default: |
|
| 489 | + $charset = load_charset($charset); |
|
| 490 | + |
|
| 491 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 492 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if (!isset($trans[$charset])) { |
|
| 496 | + $trans[$charset] = []; |
|
| 497 | + $t = &$trans[$charset]; |
|
| 498 | + for ($e = 128; $e < 255; $e++) { |
|
| 499 | + $h = dechex($e); |
|
| 500 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 501 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 502 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 503 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 504 | + } else { |
|
| 505 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 506 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 511 | + |
|
| 512 | + return $texte; |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | |
@@ -528,40 +528,40 @@ discard block |
||
| 528 | 528 | * Texte transformé dans le charset site |
| 529 | 529 | **/ |
| 530 | 530 | function importer_charset($texte, $charset = 'AUTO') { |
| 531 | - $s = null; |
|
| 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 (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 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)); |
|
| 531 | + $s = null; |
|
| 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 (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 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 < 1_114_112) { |
|
| 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 < 1_114_112) { |
|
| 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))); |
|
| 904 | + // 1. Passer le charset et les é en utf-8 |
|
| 905 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 906 | 906 | |
| 907 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 907 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | /** |
@@ -919,17 +919,17 @@ discard block |
||
| 919 | 919 | * @return string |
| 920 | 920 | */ |
| 921 | 921 | function translitteration_complexe($texte, $chiffres = false) { |
| 922 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 922 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | 923 | |
| 924 | - if ($chiffres) { |
|
| 925 | - $texte = preg_replace_callback( |
|
| 926 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 927 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 928 | - $texte |
|
| 929 | - ); |
|
| 930 | - } |
|
| 924 | + if ($chiffres) { |
|
| 925 | + $texte = preg_replace_callback( |
|
| 926 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 927 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 928 | + $texte |
|
| 929 | + ); |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | - return $texte; |
|
| 932 | + return $texte; |
|
| 933 | 933 | } |
| 934 | 934 | |
| 935 | 935 | /** |
@@ -941,7 +941,7 @@ discard block |
||
| 941 | 941 | * @return string |
| 942 | 942 | */ |
| 943 | 943 | function translitteration_chiffree($car) { |
| 944 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 944 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | |
@@ -954,7 +954,7 @@ discard block |
||
| 954 | 954 | * true s'il a un BOM |
| 955 | 955 | **/ |
| 956 | 956 | function bom_utf8($texte) { |
| 957 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 957 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -971,21 +971,21 @@ discard block |
||
| 971 | 971 | * true si c'est le cas |
| 972 | 972 | **/ |
| 973 | 973 | function is_utf8($string) { |
| 974 | - return !strlen( |
|
| 975 | - preg_replace( |
|
| 976 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 977 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 978 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 979 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 980 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 981 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 982 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 983 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 984 | - . ',sS', |
|
| 985 | - '', |
|
| 986 | - $string |
|
| 987 | - ) |
|
| 988 | - ); |
|
| 974 | + return !strlen( |
|
| 975 | + preg_replace( |
|
| 976 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 977 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 978 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 979 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 980 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 981 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 982 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 983 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 984 | + . ',sS', |
|
| 985 | + '', |
|
| 986 | + $string |
|
| 987 | + ) |
|
| 988 | + ); |
|
| 989 | 989 | } |
| 990 | 990 | |
| 991 | 991 | /** |
@@ -997,13 +997,13 @@ discard block |
||
| 997 | 997 | * true si c'est le cas |
| 998 | 998 | **/ |
| 999 | 999 | function is_ascii($string) { |
| 1000 | - return !strlen( |
|
| 1001 | - preg_replace( |
|
| 1002 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1003 | - '', |
|
| 1004 | - $string |
|
| 1005 | - ) |
|
| 1006 | - ); |
|
| 1000 | + return !strlen( |
|
| 1001 | + preg_replace( |
|
| 1002 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1003 | + '', |
|
| 1004 | + $string |
|
| 1005 | + ) |
|
| 1006 | + ); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1022,53 +1022,53 @@ discard block |
||
| 1022 | 1022 | **/ |
| 1023 | 1023 | function transcoder_page($texte, $headers = '') { |
| 1024 | 1024 | |
| 1025 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1026 | - if (is_ascii($texte)) { |
|
| 1027 | - #spip_log('charset: ascii'); |
|
| 1028 | - return $texte; |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - if (bom_utf8($texte)) { |
|
| 1032 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1033 | - $charset = 'utf-8'; |
|
| 1034 | - $texte = substr($texte, 3); |
|
| 1035 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1036 | - // charset precise par le contenu (xml) |
|
| 1037 | - $charset = trim(strtolower($regs[1])); |
|
| 1038 | - } elseif ( |
|
| 1039 | - // charset precise par le contenu (html) |
|
| 1040 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1041 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1042 | - and false === strpos($regs[2], '#') |
|
| 1043 | - and $tmp = trim(strtolower($regs[2])) |
|
| 1044 | - ) { |
|
| 1045 | - $charset = $tmp; |
|
| 1046 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1047 | - // charset de la reponse http |
|
| 1048 | - $charset = trim(strtolower($regs[1])); |
|
| 1049 | - } else { |
|
| 1050 | - $charset = ''; |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - |
|
| 1054 | - // normaliser les noms du shif-jis japonais |
|
| 1055 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1056 | - $charset = 'shift-jis'; |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - if ($charset) { |
|
| 1060 | - spip_log("charset: $charset"); |
|
| 1061 | - } else { |
|
| 1062 | - // valeur par defaut |
|
| 1063 | - if (is_utf8($texte)) { |
|
| 1064 | - $charset = 'utf-8'; |
|
| 1065 | - } else { |
|
| 1066 | - $charset = 'iso-8859-1'; |
|
| 1067 | - } |
|
| 1068 | - spip_log("charset probable: $charset"); |
|
| 1069 | - } |
|
| 1070 | - |
|
| 1071 | - return importer_charset($texte, $charset); |
|
| 1025 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1026 | + if (is_ascii($texte)) { |
|
| 1027 | + #spip_log('charset: ascii'); |
|
| 1028 | + return $texte; |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + if (bom_utf8($texte)) { |
|
| 1032 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1033 | + $charset = 'utf-8'; |
|
| 1034 | + $texte = substr($texte, 3); |
|
| 1035 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1036 | + // charset precise par le contenu (xml) |
|
| 1037 | + $charset = trim(strtolower($regs[1])); |
|
| 1038 | + } elseif ( |
|
| 1039 | + // charset precise par le contenu (html) |
|
| 1040 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1041 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1042 | + and false === strpos($regs[2], '#') |
|
| 1043 | + and $tmp = trim(strtolower($regs[2])) |
|
| 1044 | + ) { |
|
| 1045 | + $charset = $tmp; |
|
| 1046 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1047 | + // charset de la reponse http |
|
| 1048 | + $charset = trim(strtolower($regs[1])); |
|
| 1049 | + } else { |
|
| 1050 | + $charset = ''; |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + |
|
| 1054 | + // normaliser les noms du shif-jis japonais |
|
| 1055 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1056 | + $charset = 'shift-jis'; |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + if ($charset) { |
|
| 1060 | + spip_log("charset: $charset"); |
|
| 1061 | + } else { |
|
| 1062 | + // valeur par defaut |
|
| 1063 | + if (is_utf8($texte)) { |
|
| 1064 | + $charset = 'utf-8'; |
|
| 1065 | + } else { |
|
| 1066 | + $charset = 'iso-8859-1'; |
|
| 1067 | + } |
|
| 1068 | + spip_log("charset probable: $charset"); |
|
| 1069 | + } |
|
| 1070 | + |
|
| 1071 | + return importer_charset($texte, $charset); |
|
| 1072 | 1072 | } |
| 1073 | 1073 | |
| 1074 | 1074 | |
@@ -1092,26 +1092,26 @@ discard block |
||
| 1092 | 1092 | * Le texte coupé |
| 1093 | 1093 | **/ |
| 1094 | 1094 | function spip_substr($c, $start = 0, $length = null) { |
| 1095 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1096 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1097 | - if ($length) { |
|
| 1098 | - return substr($c, $start, $length); |
|
| 1099 | - } else { |
|
| 1100 | - return substr($c, $start); |
|
| 1101 | - } |
|
| 1102 | - } |
|
| 1103 | - |
|
| 1104 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1105 | - if (init_mb_string()) { |
|
| 1106 | - if ($length) { |
|
| 1107 | - return mb_substr($c, $start, $length); |
|
| 1108 | - } else { |
|
| 1109 | - return mb_substr($c, $start); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // Version manuelle (cf. ci-dessous) |
|
| 1114 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1095 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1096 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1097 | + if ($length) { |
|
| 1098 | + return substr($c, $start, $length); |
|
| 1099 | + } else { |
|
| 1100 | + return substr($c, $start); |
|
| 1101 | + } |
|
| 1102 | + } |
|
| 1103 | + |
|
| 1104 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1105 | + if (init_mb_string()) { |
|
| 1106 | + if ($length) { |
|
| 1107 | + return mb_substr($c, $start, $length); |
|
| 1108 | + } else { |
|
| 1109 | + return mb_substr($c, $start); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // Version manuelle (cf. ci-dessous) |
|
| 1114 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1130,40 +1130,40 @@ discard block |
||
| 1130 | 1130 | **/ |
| 1131 | 1131 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1132 | 1132 | |
| 1133 | - // Cas pathologique |
|
| 1134 | - if ($length === 0) { |
|
| 1135 | - return ''; |
|
| 1136 | - } |
|
| 1137 | - |
|
| 1138 | - // S'il y a un demarrage, on se positionne |
|
| 1139 | - if ($start > 0) { |
|
| 1140 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1141 | - } elseif ($start < 0) { |
|
| 1142 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1143 | - } |
|
| 1144 | - |
|
| 1145 | - if (!$length) { |
|
| 1146 | - return $c; |
|
| 1147 | - } |
|
| 1148 | - |
|
| 1149 | - if ($length > 0) { |
|
| 1150 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1151 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1152 | - $n = 0; |
|
| 1153 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1154 | - ; |
|
| 1155 | - } |
|
| 1156 | - $c = substr($c, 0, $n * $length); |
|
| 1157 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1158 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1159 | - $c = substr($c, 0, $length - $l); |
|
| 1160 | - } |
|
| 1161 | - |
|
| 1162 | - return $c; |
|
| 1163 | - } |
|
| 1164 | - |
|
| 1165 | - // $length < 0 |
|
| 1166 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1133 | + // Cas pathologique |
|
| 1134 | + if ($length === 0) { |
|
| 1135 | + return ''; |
|
| 1136 | + } |
|
| 1137 | + |
|
| 1138 | + // S'il y a un demarrage, on se positionne |
|
| 1139 | + if ($start > 0) { |
|
| 1140 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1141 | + } elseif ($start < 0) { |
|
| 1142 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1143 | + } |
|
| 1144 | + |
|
| 1145 | + if (!$length) { |
|
| 1146 | + return $c; |
|
| 1147 | + } |
|
| 1148 | + |
|
| 1149 | + if ($length > 0) { |
|
| 1150 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1151 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1152 | + $n = 0; |
|
| 1153 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1154 | + ; |
|
| 1155 | + } |
|
| 1156 | + $c = substr($c, 0, $n * $length); |
|
| 1157 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1158 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1159 | + $c = substr($c, 0, $length - $l); |
|
| 1160 | + } |
|
| 1161 | + |
|
| 1162 | + return $c; |
|
| 1163 | + } |
|
| 1164 | + |
|
| 1165 | + // $length < 0 |
|
| 1166 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | /** |
@@ -1177,14 +1177,14 @@ discard block |
||
| 1177 | 1177 | * La chaîne avec une majuscule sur le premier mot |
| 1178 | 1178 | */ |
| 1179 | 1179 | function spip_ucfirst($c) { |
| 1180 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1181 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1182 | - return ucfirst($c); |
|
| 1183 | - } |
|
| 1180 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1181 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1182 | + return ucfirst($c); |
|
| 1183 | + } |
|
| 1184 | 1184 | |
| 1185 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1185 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1186 | 1186 | |
| 1187 | - return $lettre1 . spip_substr($c, 1); |
|
| 1187 | + return $lettre1 . spip_substr($c, 1); |
|
| 1188 | 1188 | } |
| 1189 | 1189 | |
| 1190 | 1190 | /** |
@@ -1198,12 +1198,12 @@ discard block |
||
| 1198 | 1198 | * La chaîne en minuscules |
| 1199 | 1199 | */ |
| 1200 | 1200 | function spip_strtolower($c) { |
| 1201 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1202 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1203 | - return strtolower($c); |
|
| 1204 | - } |
|
| 1201 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1202 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1203 | + return strtolower($c); |
|
| 1204 | + } |
|
| 1205 | 1205 | |
| 1206 | - return mb_strtolower($c); |
|
| 1206 | + return mb_strtolower($c); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | /** |
@@ -1217,23 +1217,23 @@ discard block |
||
| 1217 | 1217 | * Longueur de la chaîne |
| 1218 | 1218 | */ |
| 1219 | 1219 | function spip_strlen($c) { |
| 1220 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1221 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1222 | - |
|
| 1223 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1224 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1225 | - return strlen($c); |
|
| 1226 | - } |
|
| 1227 | - |
|
| 1228 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1229 | - if (init_mb_string()) { |
|
| 1230 | - return mb_strlen($c); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1234 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1235 | - // de caracteres utf-8 (11......) |
|
| 1236 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1220 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1221 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1222 | + |
|
| 1223 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1224 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1225 | + return strlen($c); |
|
| 1226 | + } |
|
| 1227 | + |
|
| 1228 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1229 | + if (init_mb_string()) { |
|
| 1230 | + return mb_strlen($c); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1234 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1235 | + // de caracteres utf-8 (11......) |
|
| 1236 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | // Initialisation |
@@ -1243,16 +1243,16 @@ discard block |
||
| 1243 | 1243 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1244 | 1244 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1245 | 1245 | if ( |
| 1246 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 1247 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1246 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 1247 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1248 | 1248 | ) { |
| 1249 | - include_spip('inc/meta'); |
|
| 1250 | - ecrire_meta( |
|
| 1251 | - 'pcre_u', |
|
| 1252 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1253 | - and test_pcre_unicode()) |
|
| 1254 | - ? 'u' : '' |
|
| 1255 | - ); |
|
| 1249 | + include_spip('inc/meta'); |
|
| 1250 | + ecrire_meta( |
|
| 1251 | + 'pcre_u', |
|
| 1252 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1253 | + and test_pcre_unicode()) |
|
| 1254 | + ? 'u' : '' |
|
| 1255 | + ); |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | |
@@ -1268,17 +1268,17 @@ discard block |
||
| 1268 | 1268 | * en unicode : 💩 |
| 1269 | 1269 | */ |
| 1270 | 1270 | function utf8_noplanes($x) { |
| 1271 | - $regexp_utf8_4bytes = '/( |
|
| 1271 | + $regexp_utf8_4bytes = '/( |
|
| 1272 | 1272 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1273 | 1273 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1274 | 1274 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1275 | 1275 | )/xS'; |
| 1276 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1277 | - foreach ($z[0] as $k) { |
|
| 1278 | - $ku = utf_8_to_unicode($k); |
|
| 1279 | - $x = str_replace($k, $ku, $x); |
|
| 1280 | - } |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - return $x; |
|
| 1276 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1277 | + foreach ($z[0] as $k) { |
|
| 1278 | + $ku = utf_8_to_unicode($k); |
|
| 1279 | + $x = str_replace($k, $ku, $x); |
|
| 1280 | + } |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + return $x; |
|
| 1284 | 1284 | } |