@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | **/ |
| 31 | 31 | |
| 32 | 32 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 33 | - return; |
|
| 33 | + return; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | // utilise pour le logo du site, donc doit rester ici |
@@ -48,91 +48,91 @@ discard block |
||
| 48 | 48 | * @return array Variables d'environnement pour le fond |
| 49 | 49 | */ |
| 50 | 50 | function formulaires_editer_logo_charger_dist($objet, $id_objet, $retour = '', $options = []) { |
| 51 | - // pas dans une boucle ? formulaire pour le logo du site |
|
| 52 | - // dans ce cas, il faut chercher un 'siteon0.ext' |
|
| 53 | - if (!$objet) { |
|
| 54 | - $objet = 'site'; |
|
| 55 | - } |
|
| 51 | + // pas dans une boucle ? formulaire pour le logo du site |
|
| 52 | + // dans ce cas, il faut chercher un 'siteon0.ext' |
|
| 53 | + if (!$objet) { |
|
| 54 | + $objet = 'site'; |
|
| 55 | + } |
|
| 56 | 56 | |
| 57 | - $objet = objet_type($objet); |
|
| 58 | - $_id_objet = id_table_objet($objet); |
|
| 57 | + $objet = objet_type($objet); |
|
| 58 | + $_id_objet = id_table_objet($objet); |
|
| 59 | 59 | |
| 60 | - if (!is_array($options)) { |
|
| 61 | - $options = unserialize($options); |
|
| 62 | - } |
|
| 63 | - $options = spip_sanitize_from_request($options, '*'); |
|
| 60 | + if (!is_array($options)) { |
|
| 61 | + $options = unserialize($options); |
|
| 62 | + } |
|
| 63 | + $options = spip_sanitize_from_request($options, '*'); |
|
| 64 | 64 | |
| 65 | - if (!isset($options['titre'])) { |
|
| 66 | - $balise_img = chercher_filtre('balise_img'); |
|
| 67 | - $img = $balise_img(chemin_image('image-24.png'), '', 'cadre-icone'); |
|
| 68 | - $libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']); |
|
| 69 | - $libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine'); |
|
| 70 | - if (isset($libelles[$libelle])) { |
|
| 71 | - $libelle = $libelles[$libelle]; |
|
| 72 | - } elseif ($libelle = objet_info($objet, 'texte_logo_objet')) { |
|
| 73 | - $libelle = _T($libelle); |
|
| 74 | - } else { |
|
| 75 | - $libelle = _L('Logo'); |
|
| 76 | - } |
|
| 77 | - switch ($objet) { |
|
| 78 | - case 'article': |
|
| 79 | - $libelle .= ' ' . aider('logoart'); |
|
| 80 | - break; |
|
| 81 | - case 'breve': |
|
| 82 | - $libelle .= ' ' . aider('breveslogo'); |
|
| 83 | - break; |
|
| 84 | - case 'rubrique': |
|
| 85 | - $libelle .= ' ' . aider('rublogo'); |
|
| 86 | - break; |
|
| 87 | - default: |
|
| 88 | - break; |
|
| 89 | - } |
|
| 65 | + if (!isset($options['titre'])) { |
|
| 66 | + $balise_img = chercher_filtre('balise_img'); |
|
| 67 | + $img = $balise_img(chemin_image('image-24.png'), '', 'cadre-icone'); |
|
| 68 | + $libelles = pipeline('libeller_logo', $GLOBALS['logo_libelles']); |
|
| 69 | + $libelle = (($id_objet or $objet != 'rubrique') ? $objet : 'racine'); |
|
| 70 | + if (isset($libelles[$libelle])) { |
|
| 71 | + $libelle = $libelles[$libelle]; |
|
| 72 | + } elseif ($libelle = objet_info($objet, 'texte_logo_objet')) { |
|
| 73 | + $libelle = _T($libelle); |
|
| 74 | + } else { |
|
| 75 | + $libelle = _L('Logo'); |
|
| 76 | + } |
|
| 77 | + switch ($objet) { |
|
| 78 | + case 'article': |
|
| 79 | + $libelle .= ' ' . aider('logoart'); |
|
| 80 | + break; |
|
| 81 | + case 'breve': |
|
| 82 | + $libelle .= ' ' . aider('breveslogo'); |
|
| 83 | + break; |
|
| 84 | + case 'rubrique': |
|
| 85 | + $libelle .= ' ' . aider('rublogo'); |
|
| 86 | + break; |
|
| 87 | + default: |
|
| 88 | + break; |
|
| 89 | + } |
|
| 90 | 90 | |
| 91 | - $options['titre'] = $img . $libelle; |
|
| 92 | - } |
|
| 93 | - if (!isset($options['editable'])) { |
|
| 94 | - include_spip('inc/autoriser'); |
|
| 95 | - $options['editable'] = autoriser('iconifier', $objet, $id_objet); |
|
| 96 | - } |
|
| 91 | + $options['titre'] = $img . $libelle; |
|
| 92 | + } |
|
| 93 | + if (!isset($options['editable'])) { |
|
| 94 | + include_spip('inc/autoriser'); |
|
| 95 | + $options['editable'] = autoriser('iconifier', $objet, $id_objet); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - $res = [ |
|
| 99 | - 'editable' => ($GLOBALS['meta']['activer_logos'] == 'oui' ? ' ' : '') && (!isset($options['editable']) or $options['editable']), |
|
| 100 | - 'logo_survol' => ($GLOBALS['meta']['activer_logos_survol'] == 'oui' ? ' ' : ''), |
|
| 101 | - 'objet' => $objet, |
|
| 102 | - 'id_objet' => $id_objet, |
|
| 103 | - '_options' => $options, |
|
| 104 | - '_show_upload_off' => '', |
|
| 105 | - ]; |
|
| 98 | + $res = [ |
|
| 99 | + 'editable' => ($GLOBALS['meta']['activer_logos'] == 'oui' ? ' ' : '') && (!isset($options['editable']) or $options['editable']), |
|
| 100 | + 'logo_survol' => ($GLOBALS['meta']['activer_logos_survol'] == 'oui' ? ' ' : ''), |
|
| 101 | + 'objet' => $objet, |
|
| 102 | + 'id_objet' => $id_objet, |
|
| 103 | + '_options' => $options, |
|
| 104 | + '_show_upload_off' => '', |
|
| 105 | + ]; |
|
| 106 | 106 | |
| 107 | - // rechercher le logo de l'objet |
|
| 108 | - // la fonction prend un parametre '_id_objet' etrange : |
|
| 109 | - // le nom de la cle primaire (et non le nom de la table) |
|
| 110 | - // ou directement le nom du raccourcis a chercher |
|
| 111 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 112 | - $etats = $res['logo_survol'] ? ['on', 'off'] : ['on']; |
|
| 113 | - foreach ($etats as $etat) { |
|
| 114 | - $logo = $chercher_logo($id_objet, $_id_objet, $etat); |
|
| 115 | - if ($logo) { |
|
| 116 | - $res['logo_' . $etat] = $logo[0]; |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - // pas de logo_on -> pas de formulaire pour le survol |
|
| 120 | - if (!isset($res['logo_on'])) { |
|
| 121 | - $res['logo_survol'] = ''; |
|
| 122 | - } elseif (!isset($res['logo_off']) and _request('logo_up')) { |
|
| 123 | - $res['_show_upload_off'] = ' '; |
|
| 124 | - } |
|
| 107 | + // rechercher le logo de l'objet |
|
| 108 | + // la fonction prend un parametre '_id_objet' etrange : |
|
| 109 | + // le nom de la cle primaire (et non le nom de la table) |
|
| 110 | + // ou directement le nom du raccourcis a chercher |
|
| 111 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 112 | + $etats = $res['logo_survol'] ? ['on', 'off'] : ['on']; |
|
| 113 | + foreach ($etats as $etat) { |
|
| 114 | + $logo = $chercher_logo($id_objet, $_id_objet, $etat); |
|
| 115 | + if ($logo) { |
|
| 116 | + $res['logo_' . $etat] = $logo[0]; |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + // pas de logo_on -> pas de formulaire pour le survol |
|
| 120 | + if (!isset($res['logo_on'])) { |
|
| 121 | + $res['logo_survol'] = ''; |
|
| 122 | + } elseif (!isset($res['logo_off']) and _request('logo_up')) { |
|
| 123 | + $res['_show_upload_off'] = ' '; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - // si le logo n'est pas editable et qu'il n'y en a pas, on affiche pas du tout le formulaire |
|
| 127 | - if ( |
|
| 128 | - !$res['editable'] |
|
| 129 | - and !isset($res['logo_off']) |
|
| 130 | - and !isset($res['logo_on']) |
|
| 131 | - ) { |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 126 | + // si le logo n'est pas editable et qu'il n'y en a pas, on affiche pas du tout le formulaire |
|
| 127 | + if ( |
|
| 128 | + !$res['editable'] |
|
| 129 | + and !isset($res['logo_off']) |
|
| 130 | + and !isset($res['logo_on']) |
|
| 131 | + ) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - return $res; |
|
| 135 | + return $res; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | * @return string Hash du formulaire |
| 147 | 147 | */ |
| 148 | 148 | function formulaires_editer_logo_identifier_dist($objet, $id_objet, $retour = '', $options = []) { |
| 149 | - return serialize([$objet, $id_objet]); |
|
| 149 | + return serialize([$objet, $id_objet]); |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | /** |
@@ -162,31 +162,31 @@ discard block |
||
| 162 | 162 | * @return array Erreurs du formulaire |
| 163 | 163 | */ |
| 164 | 164 | function formulaires_editer_logo_verifier_dist($objet, $id_objet, $retour = '', $options = []) { |
| 165 | - $erreurs = []; |
|
| 166 | - // verifier les extensions |
|
| 167 | - $sources = formulaire_editer_logo_get_sources(); |
|
| 168 | - include_spip('action/editer_logo'); |
|
| 169 | - $extensions_possibles = $GLOBALS['formats_logos']; |
|
| 170 | - if (in_array('jpg', $extensions_possibles)) { |
|
| 171 | - $extensions_possibles[] = 'jpeg'; |
|
| 172 | - } |
|
| 173 | - foreach ($sources as $etat => $file) { |
|
| 174 | - // seulement si une reception correcte a eu lieu |
|
| 175 | - if ($file and $file['error'] == 0) { |
|
| 176 | - if ( |
|
| 177 | - !in_array( |
|
| 178 | - strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)), |
|
| 179 | - $extensions_possibles |
|
| 180 | - ) |
|
| 181 | - ) { |
|
| 182 | - $erreurs['logo_' . $etat] = _L('Extension non reconnue'); |
|
| 183 | - } |
|
| 184 | - } elseif ($file and $file['error'] != 0 and isset($file['msg'])) { |
|
| 185 | - $erreurs['message_erreur'] = $file['msg']; |
|
| 186 | - } |
|
| 187 | - } |
|
| 165 | + $erreurs = []; |
|
| 166 | + // verifier les extensions |
|
| 167 | + $sources = formulaire_editer_logo_get_sources(); |
|
| 168 | + include_spip('action/editer_logo'); |
|
| 169 | + $extensions_possibles = $GLOBALS['formats_logos']; |
|
| 170 | + if (in_array('jpg', $extensions_possibles)) { |
|
| 171 | + $extensions_possibles[] = 'jpeg'; |
|
| 172 | + } |
|
| 173 | + foreach ($sources as $etat => $file) { |
|
| 174 | + // seulement si une reception correcte a eu lieu |
|
| 175 | + if ($file and $file['error'] == 0) { |
|
| 176 | + if ( |
|
| 177 | + !in_array( |
|
| 178 | + strtolower(pathinfo($file['name'], PATHINFO_EXTENSION)), |
|
| 179 | + $extensions_possibles |
|
| 180 | + ) |
|
| 181 | + ) { |
|
| 182 | + $erreurs['logo_' . $etat] = _L('Extension non reconnue'); |
|
| 183 | + } |
|
| 184 | + } elseif ($file and $file['error'] != 0 and isset($file['msg'])) { |
|
| 185 | + $erreurs['message_erreur'] = $file['msg']; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | 188 | |
| 189 | - return $erreurs; |
|
| 189 | + return $erreurs; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | /** |
@@ -202,47 +202,47 @@ discard block |
||
| 202 | 202 | * @return array Retour des traitements |
| 203 | 203 | */ |
| 204 | 204 | function formulaires_editer_logo_traiter_dist($objet, $id_objet, $retour = '', $options = []) { |
| 205 | - $res = ['editable' => ' ']; |
|
| 205 | + $res = ['editable' => ' ']; |
|
| 206 | 206 | |
| 207 | - // pas dans une boucle ? formulaire pour le logo du site |
|
| 208 | - // dans ce cas, il faut chercher un 'siteon0.ext' |
|
| 209 | - if (!$objet) { |
|
| 210 | - $objet = 'site'; |
|
| 211 | - } |
|
| 207 | + // pas dans une boucle ? formulaire pour le logo du site |
|
| 208 | + // dans ce cas, il faut chercher un 'siteon0.ext' |
|
| 209 | + if (!$objet) { |
|
| 210 | + $objet = 'site'; |
|
| 211 | + } |
|
| 212 | 212 | |
| 213 | - include_spip('action/editer_logo'); |
|
| 213 | + include_spip('action/editer_logo'); |
|
| 214 | 214 | |
| 215 | - // effectuer la suppression si demandee d'un logo |
|
| 216 | - $on = _request('supprimer_logo_on'); |
|
| 217 | - if ($on or _request('supprimer_logo_off')) { |
|
| 218 | - logo_supprimer($objet, $id_objet, $on ? 'on' : 'off'); |
|
| 219 | - $res['message_ok'] = ''; // pas besoin de message : la validation est visuelle |
|
| 220 | - set_request('logo_up', ' '); |
|
| 221 | - } // sinon supprimer ancien logo puis copier le nouveau |
|
| 222 | - else { |
|
| 223 | - $sources = formulaire_editer_logo_get_sources(); |
|
| 224 | - foreach ($sources as $etat => $file) { |
|
| 225 | - if ($file and $file['error'] == 0) { |
|
| 226 | - if ($err = logo_modifier($objet, $id_objet, $etat, $file)) { |
|
| 227 | - $res['message_erreur'] = $err; |
|
| 228 | - } else { |
|
| 229 | - $res['message_ok'] = ''; |
|
| 230 | - } // pas besoin de message : la validation est visuelle |
|
| 231 | - set_request('logo_up', ' '); |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 215 | + // effectuer la suppression si demandee d'un logo |
|
| 216 | + $on = _request('supprimer_logo_on'); |
|
| 217 | + if ($on or _request('supprimer_logo_off')) { |
|
| 218 | + logo_supprimer($objet, $id_objet, $on ? 'on' : 'off'); |
|
| 219 | + $res['message_ok'] = ''; // pas besoin de message : la validation est visuelle |
|
| 220 | + set_request('logo_up', ' '); |
|
| 221 | + } // sinon supprimer ancien logo puis copier le nouveau |
|
| 222 | + else { |
|
| 223 | + $sources = formulaire_editer_logo_get_sources(); |
|
| 224 | + foreach ($sources as $etat => $file) { |
|
| 225 | + if ($file and $file['error'] == 0) { |
|
| 226 | + if ($err = logo_modifier($objet, $id_objet, $etat, $file)) { |
|
| 227 | + $res['message_erreur'] = $err; |
|
| 228 | + } else { |
|
| 229 | + $res['message_ok'] = ''; |
|
| 230 | + } // pas besoin de message : la validation est visuelle |
|
| 231 | + set_request('logo_up', ' '); |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | 235 | |
| 236 | - // Invalider les caches de l'objet |
|
| 237 | - include_spip('inc/invalideur'); |
|
| 238 | - suivre_invalideur("id='$objet/$id_objet'"); |
|
| 236 | + // Invalider les caches de l'objet |
|
| 237 | + include_spip('inc/invalideur'); |
|
| 238 | + suivre_invalideur("id='$objet/$id_objet'"); |
|
| 239 | 239 | |
| 240 | 240 | |
| 241 | - if ($retour) { |
|
| 242 | - $res['redirect'] = $retour; |
|
| 243 | - } |
|
| 241 | + if ($retour) { |
|
| 242 | + $res['redirect'] = $retour; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return $res; |
|
| 245 | + return $res; |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -254,29 +254,29 @@ discard block |
||
| 254 | 254 | * Sources des fichiers dans les clés `on` ou `off` |
| 255 | 255 | */ |
| 256 | 256 | function formulaire_editer_logo_get_sources() { |
| 257 | - if (!$_FILES) { |
|
| 258 | - $_FILES = $GLOBALS['HTTP_POST_FILES'] ?? []; |
|
| 259 | - } |
|
| 260 | - if (!is_array($_FILES)) { |
|
| 261 | - return []; |
|
| 262 | - } |
|
| 257 | + if (!$_FILES) { |
|
| 258 | + $_FILES = $GLOBALS['HTTP_POST_FILES'] ?? []; |
|
| 259 | + } |
|
| 260 | + if (!is_array($_FILES)) { |
|
| 261 | + return []; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - include_spip('inc/documents'); |
|
| 265 | - $sources = []; |
|
| 266 | - foreach (['on', 'off'] as $etat) { |
|
| 267 | - $logo = 'logo_' . $etat; |
|
| 268 | - if (isset($_FILES[$logo])) { |
|
| 269 | - if ($_FILES[$logo]['error'] == 0) { |
|
| 270 | - $sources[$etat] = $_FILES[$logo]; |
|
| 271 | - } elseif ($_FILES[$logo]['error'] != 0) { |
|
| 272 | - $msg = check_upload_error($_FILES[$logo]['error'], false, true); |
|
| 273 | - if ($msg and is_string($msg)) { |
|
| 274 | - $sources[$etat] = $_FILES[$logo]; |
|
| 275 | - $sources[$etat]['msg'] = $msg; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 264 | + include_spip('inc/documents'); |
|
| 265 | + $sources = []; |
|
| 266 | + foreach (['on', 'off'] as $etat) { |
|
| 267 | + $logo = 'logo_' . $etat; |
|
| 268 | + if (isset($_FILES[$logo])) { |
|
| 269 | + if ($_FILES[$logo]['error'] == 0) { |
|
| 270 | + $sources[$etat] = $_FILES[$logo]; |
|
| 271 | + } elseif ($_FILES[$logo]['error'] != 0) { |
|
| 272 | + $msg = check_upload_error($_FILES[$logo]['error'], false, true); |
|
| 273 | + if ($msg and is_string($msg)) { |
|
| 274 | + $sources[$etat] = $_FILES[$logo]; |
|
| 275 | + $sources[$etat]['msg'] = $msg; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - return $sources; |
|
| 281 | + return $sources; |
|
| 282 | 282 | } |
@@ -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 | /** |
@@ -71,22 +71,22 @@ discard block |
||
| 71 | 71 | */ |
| 72 | 72 | function auth_controler_password_auteur_connecte(string $password): bool { |
| 73 | 73 | |
| 74 | - if ( |
|
| 75 | - empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 76 | - or empty($GLOBALS['visiteur_session']['login']) |
|
| 77 | - ) { |
|
| 78 | - return false; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true); |
|
| 82 | - if ( |
|
| 83 | - is_array($auth) |
|
| 84 | - and $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur'] |
|
| 85 | - ) { |
|
| 86 | - return true; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return false; |
|
| 74 | + if ( |
|
| 75 | + empty($GLOBALS['visiteur_session']['id_auteur']) |
|
| 76 | + or empty($GLOBALS['visiteur_session']['login']) |
|
| 77 | + ) { |
|
| 78 | + return false; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $auth = auth_identifier_login($GLOBALS['visiteur_session']['login'], $password, '', true); |
|
| 82 | + if ( |
|
| 83 | + is_array($auth) |
|
| 84 | + and $auth['id_auteur'] == $GLOBALS['visiteur_session']['id_auteur'] |
|
| 85 | + ) { |
|
| 86 | + return true; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return false; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /** |
@@ -98,39 +98,39 @@ discard block |
||
| 98 | 98 | * @return array|string |
| 99 | 99 | */ |
| 100 | 100 | function auth_echec($raison) { |
| 101 | - include_spip('inc/minipres'); |
|
| 102 | - include_spip('inc/headers'); |
|
| 103 | - // pas authentifie. Pourquoi ? |
|
| 104 | - if (is_string($raison)) { |
|
| 105 | - // redirection vers une page d'authentification |
|
| 106 | - // on ne revient pas de cette fonction |
|
| 107 | - // sauf si pb de header |
|
| 108 | - $raison = redirige_formulaire($raison); |
|
| 109 | - } elseif (is_int($raison)) { |
|
| 110 | - // erreur SQL a afficher |
|
| 111 | - $raison = minipres( |
|
| 112 | - _T('info_travaux_titre'), |
|
| 113 | - _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 114 | - ); |
|
| 115 | - } elseif (@$raison['statut']) { |
|
| 116 | - // un simple visiteur n'a pas acces a l'espace prive |
|
| 117 | - spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 118 | - $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 119 | - } else { |
|
| 120 | - // auteur en fin de droits ... |
|
| 121 | - $h = $raison['site']; |
|
| 122 | - $raison = minipres( |
|
| 123 | - _T('avis_erreur_connexion'), |
|
| 124 | - '<br /><br /><p>' |
|
| 125 | - . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 126 | - . " <a href='$h'>" |
|
| 127 | - . _T('texte_inc_auth_2') |
|
| 128 | - . '</a>' |
|
| 129 | - . _T('texte_inc_auth_3') |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - return $raison; |
|
| 101 | + include_spip('inc/minipres'); |
|
| 102 | + include_spip('inc/headers'); |
|
| 103 | + // pas authentifie. Pourquoi ? |
|
| 104 | + if (is_string($raison)) { |
|
| 105 | + // redirection vers une page d'authentification |
|
| 106 | + // on ne revient pas de cette fonction |
|
| 107 | + // sauf si pb de header |
|
| 108 | + $raison = redirige_formulaire($raison); |
|
| 109 | + } elseif (is_int($raison)) { |
|
| 110 | + // erreur SQL a afficher |
|
| 111 | + $raison = minipres( |
|
| 112 | + _T('info_travaux_titre'), |
|
| 113 | + _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 114 | + ); |
|
| 115 | + } elseif (@$raison['statut']) { |
|
| 116 | + // un simple visiteur n'a pas acces a l'espace prive |
|
| 117 | + spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 118 | + $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 119 | + } else { |
|
| 120 | + // auteur en fin de droits ... |
|
| 121 | + $h = $raison['site']; |
|
| 122 | + $raison = minipres( |
|
| 123 | + _T('avis_erreur_connexion'), |
|
| 124 | + '<br /><br /><p>' |
|
| 125 | + . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 126 | + . " <a href='$h'>" |
|
| 127 | + . _T('texte_inc_auth_2') |
|
| 128 | + . '</a>' |
|
| 129 | + . _T('texte_inc_auth_3') |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + return $raison; |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -140,81 +140,81 @@ discard block |
||
| 140 | 140 | * @return array|bool|string |
| 141 | 141 | */ |
| 142 | 142 | function auth_mode() { |
| 143 | - // |
|
| 144 | - // Initialiser variables (eviter hacks par URL) |
|
| 145 | - // |
|
| 146 | - $GLOBALS['connect_login'] = ''; |
|
| 147 | - $id_auteur = null; |
|
| 148 | - $GLOBALS['auth_can_disconnect'] = false; |
|
| 149 | - |
|
| 150 | - // |
|
| 151 | - // Recuperer les donnees d'identification |
|
| 152 | - // |
|
| 153 | - include_spip('inc/session'); |
|
| 154 | - // Session valide en cours ? |
|
| 155 | - if (isset($_COOKIE['spip_session'])) { |
|
| 156 | - $session = charger_fonction('session', 'inc'); |
|
| 157 | - if ( |
|
| 158 | - $id_auteur = $session() |
|
| 159 | - or $id_auteur === 0 // reprise sur restauration |
|
| 160 | - ) { |
|
| 161 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 162 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 163 | - } else { |
|
| 164 | - unset($_COOKIE['spip_session']); |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - // Essayer auth http si significatif |
|
| 169 | - // (ignorer les login d'intranet independants de spip) |
|
| 170 | - if (!$GLOBALS['ignore_auth_http']) { |
|
| 171 | - if ( |
|
| 172 | - (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) |
|
| 173 | - and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 174 | - or |
|
| 175 | - // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 176 | - // est indisponible mais tentons quand meme pour |
|
| 177 | - // autocreation via LDAP |
|
| 178 | - (isset($_SERVER['REMOTE_USER']) |
|
| 179 | - and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 180 | - ) { |
|
| 181 | - if (!$id_auteur) { |
|
| 182 | - $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 183 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 184 | - $GLOBALS['visiteur_session'] = $r; |
|
| 185 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 186 | - $id_auteur = $r['id_auteur']; |
|
| 187 | - } else { |
|
| 188 | - // cas de la session en plus de PHP_AUTH |
|
| 189 | - /* if ($id_auteur != $r['id_auteur']){ |
|
| 143 | + // |
|
| 144 | + // Initialiser variables (eviter hacks par URL) |
|
| 145 | + // |
|
| 146 | + $GLOBALS['connect_login'] = ''; |
|
| 147 | + $id_auteur = null; |
|
| 148 | + $GLOBALS['auth_can_disconnect'] = false; |
|
| 149 | + |
|
| 150 | + // |
|
| 151 | + // Recuperer les donnees d'identification |
|
| 152 | + // |
|
| 153 | + include_spip('inc/session'); |
|
| 154 | + // Session valide en cours ? |
|
| 155 | + if (isset($_COOKIE['spip_session'])) { |
|
| 156 | + $session = charger_fonction('session', 'inc'); |
|
| 157 | + if ( |
|
| 158 | + $id_auteur = $session() |
|
| 159 | + or $id_auteur === 0 // reprise sur restauration |
|
| 160 | + ) { |
|
| 161 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 162 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 163 | + } else { |
|
| 164 | + unset($_COOKIE['spip_session']); |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + // Essayer auth http si significatif |
|
| 169 | + // (ignorer les login d'intranet independants de spip) |
|
| 170 | + if (!$GLOBALS['ignore_auth_http']) { |
|
| 171 | + if ( |
|
| 172 | + (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) |
|
| 173 | + and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 174 | + or |
|
| 175 | + // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 176 | + // est indisponible mais tentons quand meme pour |
|
| 177 | + // autocreation via LDAP |
|
| 178 | + (isset($_SERVER['REMOTE_USER']) |
|
| 179 | + and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 180 | + ) { |
|
| 181 | + if (!$id_auteur) { |
|
| 182 | + $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 183 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 184 | + $GLOBALS['visiteur_session'] = $r; |
|
| 185 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 186 | + $id_auteur = $r['id_auteur']; |
|
| 187 | + } else { |
|
| 188 | + // cas de la session en plus de PHP_AUTH |
|
| 189 | + /* if ($id_auteur != $r['id_auteur']){ |
|
| 190 | 190 | spip_log("vol de session $id_auteur" . join(', ', $r)); |
| 191 | 191 | unset($_COOKIE['spip_session']); |
| 192 | 192 | $id_auteur = ''; |
| 193 | 193 | } */ |
| 194 | - } |
|
| 195 | - } else { |
|
| 196 | - // Authentification .htaccess old style, car .htaccess semble |
|
| 197 | - // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 198 | - if (isset($_SERVER['REMOTE_USER'])) { |
|
| 199 | - $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $where = (is_numeric($id_auteur) |
|
| 205 | - /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 206 | - ) ? |
|
| 207 | - "id_auteur=$id_auteur" : |
|
| 208 | - (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text')); |
|
| 209 | - |
|
| 210 | - if (!$where) { |
|
| 211 | - return ''; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - // Trouver les autres infos dans la table auteurs. |
|
| 215 | - // le champ 'quand' est utilise par l'agenda |
|
| 216 | - |
|
| 217 | - return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 194 | + } |
|
| 195 | + } else { |
|
| 196 | + // Authentification .htaccess old style, car .htaccess semble |
|
| 197 | + // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 198 | + if (isset($_SERVER['REMOTE_USER'])) { |
|
| 199 | + $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $where = (is_numeric($id_auteur) |
|
| 205 | + /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 206 | + ) ? |
|
| 207 | + "id_auteur=$id_auteur" : |
|
| 208 | + (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text')); |
|
| 209 | + |
|
| 210 | + if (!$where) { |
|
| 211 | + return ''; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + // Trouver les autres infos dans la table auteurs. |
|
| 215 | + // le champ 'quand' est utilise par l'agenda |
|
| 216 | + |
|
| 217 | + return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -232,86 +232,86 @@ discard block |
||
| 232 | 232 | */ |
| 233 | 233 | function auth_init_droits($row) { |
| 234 | 234 | |
| 235 | - include_spip('inc/autoriser'); |
|
| 236 | - if (!autoriser('loger', '', 0, $row)) { |
|
| 237 | - return false; |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - |
|
| 241 | - if ($row['statut'] == 'nouveau') { |
|
| 242 | - include_spip('action/inscrire_auteur'); |
|
| 243 | - $row = confirmer_statut_inscription($row); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 247 | - $GLOBALS['connect_login'] = $row['login']; |
|
| 248 | - $GLOBALS['connect_statut'] = $row['statut']; |
|
| 249 | - |
|
| 250 | - $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 251 | - |
|
| 252 | - // au cas ou : ne pas memoriser les champs sensibles |
|
| 253 | - unset($GLOBALS['visiteur_session']['pass']); |
|
| 254 | - unset($GLOBALS['visiteur_session']['htpass']); |
|
| 255 | - unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 256 | - unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 257 | - unset($GLOBALS['visiteur_session']['ldap_password']); |
|
| 258 | - |
|
| 259 | - // creer la session au besoin |
|
| 260 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 261 | - $session = charger_fonction('session', 'inc'); |
|
| 262 | - $spip_session = $session($row); |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 266 | - // car utilisees au retour par auth_loger() |
|
| 267 | - $r = @unserialize($row['prefs']); |
|
| 268 | - $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 269 | - // si prefs pas definies, les definir par defaut |
|
| 270 | - if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 271 | - $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 272 | - $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 273 | - $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 274 | - $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui'; |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $GLOBALS['visiteur_session'] = pipeline( |
|
| 278 | - 'preparer_visiteur_session', |
|
| 279 | - ['args' => ['row' => $row], |
|
| 280 | - 'data' => $GLOBALS['visiteur_session']] |
|
| 281 | - ); |
|
| 282 | - |
|
| 283 | - // Etablir les droits selon le codage attendu |
|
| 284 | - // dans ecrire/index.php ecrire/prive.php |
|
| 285 | - |
|
| 286 | - // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 287 | - // A noter : le premier appel a autoriser() a le bon gout |
|
| 288 | - // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 289 | - // qui ne figure pas dans le fichier de session |
|
| 290 | - |
|
| 291 | - if (!autoriser('ecrire')) { |
|
| 292 | - return $row; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 296 | - |
|
| 297 | - auth_trace($row); |
|
| 298 | - |
|
| 299 | - // Administrateurs |
|
| 300 | - if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 301 | - if ( |
|
| 302 | - isset($GLOBALS['visiteur_session']['restreint']) |
|
| 303 | - and is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 304 | - ) { |
|
| 305 | - $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 306 | - } |
|
| 307 | - if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 308 | - $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 313 | - |
|
| 314 | - return ''; // i.e. pas de pb. |
|
| 235 | + include_spip('inc/autoriser'); |
|
| 236 | + if (!autoriser('loger', '', 0, $row)) { |
|
| 237 | + return false; |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + |
|
| 241 | + if ($row['statut'] == 'nouveau') { |
|
| 242 | + include_spip('action/inscrire_auteur'); |
|
| 243 | + $row = confirmer_statut_inscription($row); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 247 | + $GLOBALS['connect_login'] = $row['login']; |
|
| 248 | + $GLOBALS['connect_statut'] = $row['statut']; |
|
| 249 | + |
|
| 250 | + $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 251 | + |
|
| 252 | + // au cas ou : ne pas memoriser les champs sensibles |
|
| 253 | + unset($GLOBALS['visiteur_session']['pass']); |
|
| 254 | + unset($GLOBALS['visiteur_session']['htpass']); |
|
| 255 | + unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 256 | + unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 257 | + unset($GLOBALS['visiteur_session']['ldap_password']); |
|
| 258 | + |
|
| 259 | + // creer la session au besoin |
|
| 260 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 261 | + $session = charger_fonction('session', 'inc'); |
|
| 262 | + $spip_session = $session($row); |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 266 | + // car utilisees au retour par auth_loger() |
|
| 267 | + $r = @unserialize($row['prefs']); |
|
| 268 | + $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 269 | + // si prefs pas definies, les definir par defaut |
|
| 270 | + if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 271 | + $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 272 | + $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 273 | + $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 274 | + $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui'; |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $GLOBALS['visiteur_session'] = pipeline( |
|
| 278 | + 'preparer_visiteur_session', |
|
| 279 | + ['args' => ['row' => $row], |
|
| 280 | + 'data' => $GLOBALS['visiteur_session']] |
|
| 281 | + ); |
|
| 282 | + |
|
| 283 | + // Etablir les droits selon le codage attendu |
|
| 284 | + // dans ecrire/index.php ecrire/prive.php |
|
| 285 | + |
|
| 286 | + // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 287 | + // A noter : le premier appel a autoriser() a le bon gout |
|
| 288 | + // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 289 | + // qui ne figure pas dans le fichier de session |
|
| 290 | + |
|
| 291 | + if (!autoriser('ecrire')) { |
|
| 292 | + return $row; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 296 | + |
|
| 297 | + auth_trace($row); |
|
| 298 | + |
|
| 299 | + // Administrateurs |
|
| 300 | + if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 301 | + if ( |
|
| 302 | + isset($GLOBALS['visiteur_session']['restreint']) |
|
| 303 | + and is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 304 | + ) { |
|
| 305 | + $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 306 | + } |
|
| 307 | + if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 308 | + $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 313 | + |
|
| 314 | + return ''; // i.e. pas de pb. |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -320,23 +320,23 @@ discard block |
||
| 320 | 320 | * @return string |
| 321 | 321 | */ |
| 322 | 322 | function auth_a_loger() { |
| 323 | - $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), true); |
|
| 324 | - |
|
| 325 | - // un echec au "bonjour" (login initial) quand le statut est |
|
| 326 | - // inconnu signale sans doute un probleme de cookies |
|
| 327 | - if (isset($_GET['bonjour'])) { |
|
| 328 | - $redirect = parametre_url( |
|
| 329 | - $redirect, |
|
| 330 | - 'var_erreur', |
|
| 331 | - (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 332 | - ? 'cookie' |
|
| 333 | - : 'statut' |
|
| 334 | - ), |
|
| 335 | - '&' |
|
| 336 | - ); |
|
| 337 | - } |
|
| 338 | - |
|
| 339 | - return $redirect; |
|
| 323 | + $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), true); |
|
| 324 | + |
|
| 325 | + // un echec au "bonjour" (login initial) quand le statut est |
|
| 326 | + // inconnu signale sans doute un probleme de cookies |
|
| 327 | + if (isset($_GET['bonjour'])) { |
|
| 328 | + $redirect = parametre_url( |
|
| 329 | + $redirect, |
|
| 330 | + 'var_erreur', |
|
| 331 | + (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 332 | + ? 'cookie' |
|
| 333 | + : 'statut' |
|
| 334 | + ), |
|
| 335 | + '&' |
|
| 336 | + ); |
|
| 337 | + } |
|
| 338 | + |
|
| 339 | + return $redirect; |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -348,19 +348,19 @@ discard block |
||
| 348 | 348 | * @param null|string $date |
| 349 | 349 | */ |
| 350 | 350 | function auth_trace($row, $date = null) { |
| 351 | - // Indiquer la connexion. A la minute pres ca suffit. |
|
| 352 | - if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 353 | - $connect_quand = strtotime($connect_quand); |
|
| 354 | - } |
|
| 351 | + // Indiquer la connexion. A la minute pres ca suffit. |
|
| 352 | + if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 353 | + $connect_quand = strtotime($connect_quand); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - $date ??= date('Y-m-d H:i:s'); |
|
| 356 | + $date ??= date('Y-m-d H:i:s'); |
|
| 357 | 357 | |
| 358 | - if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 359 | - sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 360 | - $row['en_ligne'] = $date; |
|
| 361 | - } |
|
| 358 | + if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 359 | + sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 360 | + $row['en_ligne'] = $date; |
|
| 361 | + } |
|
| 362 | 362 | |
| 363 | - pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 363 | + pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
@@ -386,28 +386,28 @@ discard block |
||
| 386 | 386 | * @return mixed |
| 387 | 387 | */ |
| 388 | 388 | function auth_administrer($fonction, $args, $defaut = false) { |
| 389 | - $auth_methode = array_shift($args); |
|
| 390 | - $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 391 | - if ( |
|
| 392 | - $auth = charger_fonction($auth_methode, 'auth', true) |
|
| 393 | - and function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 394 | - ) { |
|
| 395 | - $res = $f(...$args); |
|
| 396 | - } else { |
|
| 397 | - $res = $defaut; |
|
| 398 | - } |
|
| 399 | - $res = pipeline( |
|
| 400 | - 'auth_administrer', |
|
| 401 | - [ |
|
| 402 | - 'args' => [ |
|
| 403 | - 'fonction' => $fonction, |
|
| 404 | - 'methode' => $auth_methode, |
|
| 405 | - 'args' => $args |
|
| 406 | - ], |
|
| 407 | - 'data' => $res |
|
| 408 | - ] |
|
| 409 | - ); |
|
| 410 | - return $res; |
|
| 389 | + $auth_methode = array_shift($args); |
|
| 390 | + $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 391 | + if ( |
|
| 392 | + $auth = charger_fonction($auth_methode, 'auth', true) |
|
| 393 | + and function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 394 | + ) { |
|
| 395 | + $res = $f(...$args); |
|
| 396 | + } else { |
|
| 397 | + $res = $defaut; |
|
| 398 | + } |
|
| 399 | + $res = pipeline( |
|
| 400 | + 'auth_administrer', |
|
| 401 | + [ |
|
| 402 | + 'args' => [ |
|
| 403 | + 'fonction' => $fonction, |
|
| 404 | + 'methode' => $auth_methode, |
|
| 405 | + 'args' => $args |
|
| 406 | + ], |
|
| 407 | + 'data' => $res |
|
| 408 | + ] |
|
| 409 | + ); |
|
| 410 | + return $res; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | /** |
@@ -417,11 +417,11 @@ discard block |
||
| 417 | 417 | * @return array |
| 418 | 418 | */ |
| 419 | 419 | function auth_formulaire_login($flux) { |
| 420 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 421 | - $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 422 | - } |
|
| 420 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 421 | + $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 422 | + } |
|
| 423 | 423 | |
| 424 | - return $flux; |
|
| 424 | + return $flux; |
|
| 425 | 425 | } |
| 426 | 426 | |
| 427 | 427 | |
@@ -435,19 +435,19 @@ discard block |
||
| 435 | 435 | * @return string/bool |
| 436 | 436 | */ |
| 437 | 437 | function auth_retrouver_login($login, $serveur = '') { |
| 438 | - if (!spip_connect($serveur)) { |
|
| 439 | - include_spip('inc/minipres'); |
|
| 440 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 441 | - exit; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 445 | - if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 446 | - return $auteur; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - return false; |
|
| 438 | + if (!spip_connect($serveur)) { |
|
| 439 | + include_spip('inc/minipres'); |
|
| 440 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 441 | + exit; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 445 | + if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 446 | + return $auteur; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + return false; |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | /** |
@@ -462,34 +462,34 @@ discard block |
||
| 462 | 462 | * @return array |
| 463 | 463 | */ |
| 464 | 464 | function auth_informer_login($login, $serveur = '') { |
| 465 | - if ( |
|
| 466 | - !$login |
|
| 467 | - or !$login_base = auth_retrouver_login($login, $serveur) |
|
| 468 | - or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 469 | - ) { |
|
| 470 | - // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 471 | - // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 472 | - |
|
| 473 | - $row = [ |
|
| 474 | - 'login' => $login, |
|
| 475 | - 'cnx' => '0', |
|
| 476 | - 'logo' => '', |
|
| 477 | - ]; |
|
| 478 | - |
|
| 479 | - return $row; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - $prefs = @unserialize($row['prefs']); |
|
| 483 | - $infos = [ |
|
| 484 | - 'id_auteur' => $row['id_auteur'], |
|
| 485 | - 'login' => $row['login'], |
|
| 486 | - 'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 487 | - 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 488 | - ]; |
|
| 489 | - |
|
| 490 | - verifier_visiteur(); |
|
| 491 | - |
|
| 492 | - return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 465 | + if ( |
|
| 466 | + !$login |
|
| 467 | + or !$login_base = auth_retrouver_login($login, $serveur) |
|
| 468 | + or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 469 | + ) { |
|
| 470 | + // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 471 | + // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 472 | + |
|
| 473 | + $row = [ |
|
| 474 | + 'login' => $login, |
|
| 475 | + 'cnx' => '0', |
|
| 476 | + 'logo' => '', |
|
| 477 | + ]; |
|
| 478 | + |
|
| 479 | + return $row; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + $prefs = @unserialize($row['prefs']); |
|
| 483 | + $infos = [ |
|
| 484 | + 'id_auteur' => $row['id_auteur'], |
|
| 485 | + 'login' => $row['login'], |
|
| 486 | + 'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 487 | + 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 488 | + ]; |
|
| 489 | + |
|
| 490 | + verifier_visiteur(); |
|
| 491 | + |
|
| 492 | + return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | |
@@ -503,21 +503,21 @@ discard block |
||
| 503 | 503 | * @return mixed |
| 504 | 504 | */ |
| 505 | 505 | function auth_identifier_login($login, $password, $serveur = '', bool $phpauth = false) { |
| 506 | - $erreur = ''; |
|
| 507 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 508 | - if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 509 | - $auteur = $auth($login, $password, $serveur, $phpauth); |
|
| 510 | - if (is_array($auteur) and count($auteur)) { |
|
| 511 | - spip_log("connexion de $login par methode $methode"); |
|
| 512 | - $auteur['auth'] = $methode; |
|
| 513 | - return $auteur; |
|
| 514 | - } elseif (is_string($auteur)) { |
|
| 515 | - $erreur .= "$auteur "; |
|
| 516 | - } |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - return $erreur; |
|
| 506 | + $erreur = ''; |
|
| 507 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 508 | + if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 509 | + $auteur = $auth($login, $password, $serveur, $phpauth); |
|
| 510 | + if (is_array($auteur) and count($auteur)) { |
|
| 511 | + spip_log("connexion de $login par methode $methode"); |
|
| 512 | + $auteur['auth'] = $methode; |
|
| 513 | + return $auteur; |
|
| 514 | + } elseif (is_string($auteur)) { |
|
| 515 | + $erreur .= "$auteur "; |
|
| 516 | + } |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + return $erreur; |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -531,8 +531,8 @@ discard block |
||
| 531 | 531 | * @return string |
| 532 | 532 | */ |
| 533 | 533 | function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') { |
| 534 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 535 | - return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 534 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 535 | + return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 536 | 536 | } |
| 537 | 537 | |
| 538 | 538 | /** |
@@ -546,9 +546,9 @@ discard block |
||
| 546 | 546 | * @return mixed |
| 547 | 547 | */ |
| 548 | 548 | function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') { |
| 549 | - $args = func_get_args(); |
|
| 550 | - $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 551 | - return $auteur; |
|
| 549 | + $args = func_get_args(); |
|
| 550 | + $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 551 | + return $auteur; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -558,29 +558,29 @@ discard block |
||
| 558 | 558 | * @return bool |
| 559 | 559 | */ |
| 560 | 560 | function auth_loger($auteur) { |
| 561 | - if (!is_array($auteur) or !count($auteur)) { |
|
| 562 | - return false; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // initialiser et poser le cookie de session |
|
| 566 | - unset($_COOKIE['spip_session']); |
|
| 567 | - if (auth_init_droits($auteur) === false) { |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // initialiser les prefs |
|
| 572 | - $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 573 | - $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 574 | - |
|
| 575 | - sql_updateq( |
|
| 576 | - 'spip_auteurs', |
|
| 577 | - ['prefs' => serialize($p)], |
|
| 578 | - 'id_auteur=' . intval($auteur['id_auteur']) |
|
| 579 | - ); |
|
| 580 | - |
|
| 581 | - // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 582 | - verifier_visiteur(); |
|
| 583 | - return true; |
|
| 561 | + if (!is_array($auteur) or !count($auteur)) { |
|
| 562 | + return false; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // initialiser et poser le cookie de session |
|
| 566 | + unset($_COOKIE['spip_session']); |
|
| 567 | + if (auth_init_droits($auteur) === false) { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // initialiser les prefs |
|
| 572 | + $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 573 | + $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 574 | + |
|
| 575 | + sql_updateq( |
|
| 576 | + 'spip_auteurs', |
|
| 577 | + ['prefs' => serialize($p)], |
|
| 578 | + 'id_auteur=' . intval($auteur['id_auteur']) |
|
| 579 | + ); |
|
| 580 | + |
|
| 581 | + // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 582 | + verifier_visiteur(); |
|
| 583 | + return true; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * return void |
| 591 | 591 | **/ |
| 592 | 592 | function auth_deloger() { |
| 593 | - $logout = charger_fonction('logout', 'action'); |
|
| 594 | - $logout(); |
|
| 593 | + $logout = charger_fonction('logout', 'action'); |
|
| 594 | + $logout(); |
|
| 595 | 595 | } |
| 596 | 596 | |
| 597 | 597 | /** |
@@ -605,8 +605,8 @@ discard block |
||
| 605 | 605 | * @return bool |
| 606 | 606 | */ |
| 607 | 607 | function auth_autoriser_modifier_login($auth_methode, $serveur = '') { |
| 608 | - $args = func_get_args(); |
|
| 609 | - return auth_administrer('autoriser_modifier_login', $args); |
|
| 608 | + $args = func_get_args(); |
|
| 609 | + return auth_administrer('autoriser_modifier_login', $args); |
|
| 610 | 610 | } |
| 611 | 611 | |
| 612 | 612 | /** |
@@ -621,8 +621,8 @@ discard block |
||
| 621 | 621 | * message d'erreur ou chaine vide si pas d'erreur |
| 622 | 622 | */ |
| 623 | 623 | function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') { |
| 624 | - $args = func_get_args(); |
|
| 625 | - return auth_administrer('verifier_login', $args, ''); |
|
| 624 | + $args = func_get_args(); |
|
| 625 | + return auth_administrer('verifier_login', $args, ''); |
|
| 626 | 626 | } |
| 627 | 627 | |
| 628 | 628 | /** |
@@ -635,8 +635,8 @@ discard block |
||
| 635 | 635 | * @return bool |
| 636 | 636 | */ |
| 637 | 637 | function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') { |
| 638 | - $args = func_get_args(); |
|
| 639 | - return auth_administrer('modifier_login', $args); |
|
| 638 | + $args = func_get_args(); |
|
| 639 | + return auth_administrer('modifier_login', $args); |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | /** |
@@ -651,8 +651,8 @@ discard block |
||
| 651 | 651 | * succès ou échec |
| 652 | 652 | */ |
| 653 | 653 | function auth_autoriser_modifier_pass($auth_methode, $serveur = '') { |
| 654 | - $args = func_get_args(); |
|
| 655 | - return auth_administrer('autoriser_modifier_pass', $args); |
|
| 654 | + $args = func_get_args(); |
|
| 655 | + return auth_administrer('autoriser_modifier_pass', $args); |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -668,8 +668,8 @@ discard block |
||
| 668 | 668 | * message d'erreur ou chaine vide si pas d'erreur |
| 669 | 669 | */ |
| 670 | 670 | function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 671 | - $args = func_get_args(); |
|
| 672 | - return auth_administrer('verifier_pass', $args, ''); |
|
| 671 | + $args = func_get_args(); |
|
| 672 | + return auth_administrer('verifier_pass', $args, ''); |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | /** |
@@ -685,8 +685,8 @@ discard block |
||
| 685 | 685 | * succes ou echec |
| 686 | 686 | */ |
| 687 | 687 | function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur = '') { |
| 688 | - $args = func_get_args(); |
|
| 689 | - return auth_administrer('modifier_pass', $args); |
|
| 688 | + $args = func_get_args(); |
|
| 689 | + return auth_administrer('modifier_pass', $args); |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | /** |
@@ -702,24 +702,24 @@ discard block |
||
| 702 | 702 | * @return void |
| 703 | 703 | */ |
| 704 | 704 | function auth_synchroniser_distant( |
| 705 | - $auth_methode = true, |
|
| 706 | - $id_auteur = 0, |
|
| 707 | - $champs = [], |
|
| 708 | - $options = [], |
|
| 709 | - $serveur = '' |
|
| 705 | + $auth_methode = true, |
|
| 706 | + $id_auteur = 0, |
|
| 707 | + $champs = [], |
|
| 708 | + $options = [], |
|
| 709 | + $serveur = '' |
|
| 710 | 710 | ) { |
| 711 | - $args = func_get_args(); |
|
| 712 | - if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) { |
|
| 713 | - $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 714 | - $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 715 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 716 | - array_shift($args); |
|
| 717 | - array_unshift($args, $methode); |
|
| 718 | - auth_administrer('synchroniser_distant', $args); |
|
| 719 | - } |
|
| 720 | - } else { |
|
| 721 | - auth_administrer('synchroniser_distant', $args); |
|
| 722 | - } |
|
| 711 | + $args = func_get_args(); |
|
| 712 | + if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) { |
|
| 713 | + $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 714 | + $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 715 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 716 | + array_shift($args); |
|
| 717 | + array_unshift($args, $methode); |
|
| 718 | + auth_administrer('synchroniser_distant', $args); |
|
| 719 | + } |
|
| 720 | + } else { |
|
| 721 | + auth_administrer('synchroniser_distant', $args); |
|
| 722 | + } |
|
| 723 | 723 | } |
| 724 | 724 | |
| 725 | 725 | |
@@ -732,45 +732,45 @@ discard block |
||
| 732 | 732 | * @return array|bool |
| 733 | 733 | */ |
| 734 | 734 | function lire_php_auth($login, $pw, $serveur = '') { |
| 735 | - if ( |
|
| 736 | - !$login |
|
| 737 | - or !$login = auth_retrouver_login($login, $serveur) |
|
| 738 | - ) { |
|
| 739 | - return false; |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 743 | - |
|
| 744 | - if (!$row) { |
|
| 745 | - if ( |
|
| 746 | - include_spip('inc/auth') |
|
| 747 | - and auth_ldap_connect($serveur) |
|
| 748 | - and $auth_ldap = charger_fonction('ldap', 'auth', true) |
|
| 749 | - ) { |
|
| 750 | - return $auth_ldap($login, $pw, $serveur, true); |
|
| 751 | - } |
|
| 752 | - |
|
| 753 | - return false; |
|
| 754 | - } |
|
| 755 | - // su pas de source definie |
|
| 756 | - // ou auth/xxx introuvable, utiliser 'spip' |
|
| 757 | - if ( |
|
| 758 | - !$auth_methode = $row['source'] |
|
| 759 | - or !$auth = charger_fonction($auth_methode, 'auth', true) |
|
| 760 | - ) { |
|
| 761 | - $auth = charger_fonction('spip', 'auth', true); |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - $auteur = ''; |
|
| 765 | - if ($auth) { |
|
| 766 | - $auteur = $auth($login, $pw, $serveur, true); |
|
| 767 | - } |
|
| 768 | - // verifier que ce n'est pas un message d'erreur |
|
| 769 | - if (is_array($auteur) and count($auteur)) { |
|
| 770 | - return $auteur; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - return false; |
|
| 735 | + if ( |
|
| 736 | + !$login |
|
| 737 | + or !$login = auth_retrouver_login($login, $serveur) |
|
| 738 | + ) { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 743 | + |
|
| 744 | + if (!$row) { |
|
| 745 | + if ( |
|
| 746 | + include_spip('inc/auth') |
|
| 747 | + and auth_ldap_connect($serveur) |
|
| 748 | + and $auth_ldap = charger_fonction('ldap', 'auth', true) |
|
| 749 | + ) { |
|
| 750 | + return $auth_ldap($login, $pw, $serveur, true); |
|
| 751 | + } |
|
| 752 | + |
|
| 753 | + return false; |
|
| 754 | + } |
|
| 755 | + // su pas de source definie |
|
| 756 | + // ou auth/xxx introuvable, utiliser 'spip' |
|
| 757 | + if ( |
|
| 758 | + !$auth_methode = $row['source'] |
|
| 759 | + or !$auth = charger_fonction($auth_methode, 'auth', true) |
|
| 760 | + ) { |
|
| 761 | + $auth = charger_fonction('spip', 'auth', true); |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + $auteur = ''; |
|
| 765 | + if ($auth) { |
|
| 766 | + $auteur = $auth($login, $pw, $serveur, true); |
|
| 767 | + } |
|
| 768 | + // verifier que ce n'est pas un message d'erreur |
|
| 769 | + if (is_array($auteur) and count($auteur)) { |
|
| 770 | + return $auteur; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + return false; |
|
| 774 | 774 | } |
| 775 | 775 | |
| 776 | 776 | /** |
@@ -786,21 +786,21 @@ discard block |
||
| 786 | 786 | * @param string $lien |
| 787 | 787 | */ |
| 788 | 788 | function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') { |
| 789 | - @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 790 | - @Header('HTTP/1.0 401 Unauthorized'); |
|
| 791 | - $corps = ''; |
|
| 792 | - $public = generer_url_public(); |
|
| 793 | - $ecrire = generer_url_ecrire(); |
|
| 794 | - $retour = $retour ?: _T('icone_retour'); |
|
| 795 | - $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 796 | - if ($url) { |
|
| 797 | - $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 798 | - } |
|
| 799 | - |
|
| 800 | - if ($lien) { |
|
| 801 | - $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 802 | - } |
|
| 803 | - include_spip('inc/minipres'); |
|
| 804 | - echo minipres($pb, $corps); |
|
| 805 | - exit; |
|
| 789 | + @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 790 | + @Header('HTTP/1.0 401 Unauthorized'); |
|
| 791 | + $corps = ''; |
|
| 792 | + $public = generer_url_public(); |
|
| 793 | + $ecrire = generer_url_ecrire(); |
|
| 794 | + $retour = $retour ?: _T('icone_retour'); |
|
| 795 | + $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 796 | + if ($url) { |
|
| 797 | + $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 798 | + } |
|
| 799 | + |
|
| 800 | + if ($lien) { |
|
| 801 | + $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 802 | + } |
|
| 803 | + include_spip('inc/minipres'); |
|
| 804 | + echo minipres($pb, $corps); |
|
| 805 | + exit; |
|
| 806 | 806 | } |
@@ -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,54 +553,54 @@ 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 | - if (in_array('jpg', $extensions)) { |
|
| 565 | - $extensions[] = 'jpeg'; |
|
| 566 | - } |
|
| 567 | - $extensions = array_unique($extensions); |
|
| 568 | - } |
|
| 569 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - 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 | + if (in_array('jpg', $extensions)) { |
|
| 565 | + $extensions[] = 'jpeg'; |
|
| 566 | + } |
|
| 567 | + $extensions = array_unique($extensions); |
|
| 568 | + } |
|
| 569 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $extensions; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
| 576 | 576 | * @return array|string[]|null |
| 577 | 577 | */ |
| 578 | 578 | function _image_extensions_acceptees_en_sortie() { |
| 579 | - static $extensions = null; |
|
| 580 | - if (empty($extensions)) { |
|
| 581 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 582 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 583 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 584 | - $extensions = array_diff($extensions, ['gif']); |
|
| 585 | - } |
|
| 586 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 587 | - $extensions = array_diff($extensions, ['webp']); |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $extensions; |
|
| 579 | + static $extensions = null; |
|
| 580 | + if (empty($extensions)) { |
|
| 581 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 582 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 583 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 584 | + $extensions = array_diff($extensions, ['gif']); |
|
| 585 | + } |
|
| 586 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 587 | + $extensions = array_diff($extensions, ['webp']); |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $extensions; |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | function _image_extension_normalisee($extension) { |
| 595 | - $extension = strtolower($extension); |
|
| 596 | - if ($extension === 'jpeg') { |
|
| 597 | - $extension = 'jpg'; |
|
| 598 | - } |
|
| 599 | - return $extension; |
|
| 595 | + $extension = strtolower($extension); |
|
| 596 | + if ($extension === 'jpeg') { |
|
| 597 | + $extension = 'jpg'; |
|
| 598 | + } |
|
| 599 | + return $extension; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | function _image_extensions_conservent_transparence() { |
| 603 | - return ['png', 'webp']; |
|
| 603 | + return ['png', 'webp']; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -610,12 +610,12 @@ discard block |
||
| 610 | 610 | * @return string |
| 611 | 611 | */ |
| 612 | 612 | function _image_trouver_extension($path) { |
| 613 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 614 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 615 | - $terminaison = strtolower($regs[1]); |
|
| 616 | - return $terminaison; |
|
| 617 | - } |
|
| 618 | - return ''; |
|
| 613 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 614 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 615 | + $terminaison = strtolower($regs[1]); |
|
| 616 | + return $terminaison; |
|
| 617 | + } |
|
| 618 | + return ''; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -626,33 +626,33 @@ discard block |
||
| 626 | 626 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 627 | 627 | */ |
| 628 | 628 | function _image_trouver_extension_pertinente($path) { |
| 629 | - $path = supprimer_timestamp($path); |
|
| 630 | - $terminaison = _image_trouver_extension($path); |
|
| 631 | - if ($terminaison == 'jpg') { |
|
| 632 | - $terminaison = 'jpeg'; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - if (!file_exists($path)) { |
|
| 636 | - return $terminaison; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - if (!$info = @spip_getimagesize($path)) { |
|
| 640 | - return $terminaison; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if (isset($info['mime'])) { |
|
| 644 | - $mime = $info['mime']; |
|
| 645 | - } |
|
| 646 | - else { |
|
| 647 | - $mime = image_type_to_mime_type($info[2]); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 651 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 652 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 653 | - $terminaison = $_terminaison; |
|
| 654 | - } |
|
| 655 | - return $terminaison; |
|
| 629 | + $path = supprimer_timestamp($path); |
|
| 630 | + $terminaison = _image_trouver_extension($path); |
|
| 631 | + if ($terminaison == 'jpg') { |
|
| 632 | + $terminaison = 'jpeg'; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + if (!file_exists($path)) { |
|
| 636 | + return $terminaison; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + if (!$info = @spip_getimagesize($path)) { |
|
| 640 | + return $terminaison; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if (isset($info['mime'])) { |
|
| 644 | + $mime = $info['mime']; |
|
| 645 | + } |
|
| 646 | + else { |
|
| 647 | + $mime = image_type_to_mime_type($info[2]); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 651 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 652 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 653 | + $terminaison = $_terminaison; |
|
| 654 | + } |
|
| 655 | + return $terminaison; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -660,36 +660,36 @@ discard block |
||
| 660 | 660 | * @return string |
| 661 | 661 | */ |
| 662 | 662 | function _image_trouver_extension_depuis_mime($mime) { |
| 663 | - switch (strtolower($mime)) { |
|
| 664 | - case 'image/png': |
|
| 665 | - case 'image/x-png': |
|
| 666 | - $terminaison = 'png'; |
|
| 667 | - break; |
|
| 668 | - |
|
| 669 | - case 'image/jpg': |
|
| 670 | - case 'image/jpeg': |
|
| 671 | - case 'image/pjpeg': |
|
| 672 | - $terminaison = 'jpeg'; |
|
| 673 | - break; |
|
| 674 | - |
|
| 675 | - case 'image/gif': |
|
| 676 | - $terminaison = 'gif'; |
|
| 677 | - break; |
|
| 678 | - |
|
| 679 | - case 'image/webp': |
|
| 680 | - case 'image/x-webp': |
|
| 681 | - $terminaison = 'webp'; |
|
| 682 | - break; |
|
| 683 | - |
|
| 684 | - case 'image/svg+xml': |
|
| 685 | - $terminaison = 'svg'; |
|
| 686 | - break; |
|
| 687 | - |
|
| 688 | - default: |
|
| 689 | - $terminaison = ''; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - return $terminaison; |
|
| 663 | + switch (strtolower($mime)) { |
|
| 664 | + case 'image/png': |
|
| 665 | + case 'image/x-png': |
|
| 666 | + $terminaison = 'png'; |
|
| 667 | + break; |
|
| 668 | + |
|
| 669 | + case 'image/jpg': |
|
| 670 | + case 'image/jpeg': |
|
| 671 | + case 'image/pjpeg': |
|
| 672 | + $terminaison = 'jpeg'; |
|
| 673 | + break; |
|
| 674 | + |
|
| 675 | + case 'image/gif': |
|
| 676 | + $terminaison = 'gif'; |
|
| 677 | + break; |
|
| 678 | + |
|
| 679 | + case 'image/webp': |
|
| 680 | + case 'image/x-webp': |
|
| 681 | + $terminaison = 'webp'; |
|
| 682 | + break; |
|
| 683 | + |
|
| 684 | + case 'image/svg+xml': |
|
| 685 | + $terminaison = 'svg'; |
|
| 686 | + break; |
|
| 687 | + |
|
| 688 | + default: |
|
| 689 | + $terminaison = ''; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + return $terminaison; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | |
@@ -709,18 +709,18 @@ discard block |
||
| 709 | 709 | * Une ressource de type Image GD. |
| 710 | 710 | */ |
| 711 | 711 | function _imagecreatefrom_func(string $func, string $filename) { |
| 712 | - if (!function_exists($func)) { |
|
| 713 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 714 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 715 | - return null; |
|
| 716 | - } |
|
| 717 | - $img = @$func($filename); |
|
| 718 | - if (!$img) { |
|
| 719 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 720 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 721 | - $img = imagecreate(10, 10); |
|
| 722 | - } |
|
| 723 | - return $img; |
|
| 712 | + if (!function_exists($func)) { |
|
| 713 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 714 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 715 | + return null; |
|
| 716 | + } |
|
| 717 | + $img = @$func($filename); |
|
| 718 | + if (!$img) { |
|
| 719 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 720 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 721 | + $img = imagecreate(10, 10); |
|
| 722 | + } |
|
| 723 | + return $img; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | * Une ressource de type Image GD. |
| 737 | 737 | */ |
| 738 | 738 | function _imagecreatefromjpeg($filename) { |
| 739 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 739 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | * Une ressource de type Image GD. |
| 753 | 753 | */ |
| 754 | 754 | function _imagecreatefrompng($filename) { |
| 755 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 755 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | /** |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | * Une ressource de type Image GD. |
| 769 | 769 | */ |
| 770 | 770 | function _imagecreatefromgif($filename) { |
| 771 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 771 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | * Une ressource de type Image GD. |
| 786 | 786 | */ |
| 787 | 787 | function _imagecreatefromwebp($filename) { |
| 788 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 788 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -803,24 +803,24 @@ discard block |
||
| 803 | 803 | * - true si une image est bien retournée. |
| 804 | 804 | */ |
| 805 | 805 | function _image_imagepng($img, $fichier) { |
| 806 | - if (!function_exists('imagepng')) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - $tmp = $fichier . '.tmp'; |
|
| 810 | - $ret = imagepng($img, $tmp); |
|
| 811 | - if (file_exists($tmp)) { |
|
| 812 | - $taille_test = getimagesize($tmp); |
|
| 813 | - if ($taille_test[0] < 1) { |
|
| 814 | - return false; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 818 | - @rename($tmp, $fichier); |
|
| 819 | - |
|
| 820 | - return $ret; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - return false; |
|
| 806 | + if (!function_exists('imagepng')) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + $tmp = $fichier . '.tmp'; |
|
| 810 | + $ret = imagepng($img, $tmp); |
|
| 811 | + if (file_exists($tmp)) { |
|
| 812 | + $taille_test = getimagesize($tmp); |
|
| 813 | + if ($taille_test[0] < 1) { |
|
| 814 | + return false; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 818 | + @rename($tmp, $fichier); |
|
| 819 | + |
|
| 820 | + return $ret; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + return false; |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
@@ -838,24 +838,24 @@ discard block |
||
| 838 | 838 | * - true si une image est bien retournée. |
| 839 | 839 | */ |
| 840 | 840 | function _image_imagegif($img, $fichier) { |
| 841 | - if (!function_exists('imagegif')) { |
|
| 842 | - return false; |
|
| 843 | - } |
|
| 844 | - $tmp = $fichier . '.tmp'; |
|
| 845 | - $ret = imagegif($img, $tmp); |
|
| 846 | - if (file_exists($tmp)) { |
|
| 847 | - $taille_test = getimagesize($tmp); |
|
| 848 | - if ($taille_test[0] < 1) { |
|
| 849 | - return false; |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 853 | - @rename($tmp, $fichier); |
|
| 854 | - |
|
| 855 | - return $ret; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return false; |
|
| 841 | + if (!function_exists('imagegif')) { |
|
| 842 | + return false; |
|
| 843 | + } |
|
| 844 | + $tmp = $fichier . '.tmp'; |
|
| 845 | + $ret = imagegif($img, $tmp); |
|
| 846 | + if (file_exists($tmp)) { |
|
| 847 | + $taille_test = getimagesize($tmp); |
|
| 848 | + if ($taille_test[0] < 1) { |
|
| 849 | + return false; |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 853 | + @rename($tmp, $fichier); |
|
| 854 | + |
|
| 855 | + return $ret; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return false; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
@@ -878,29 +878,29 @@ discard block |
||
| 878 | 878 | * - true si une image est bien retournée. |
| 879 | 879 | */ |
| 880 | 880 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 881 | - if (!function_exists('imagejpeg')) { |
|
| 882 | - return false; |
|
| 883 | - } |
|
| 884 | - $tmp = $fichier . '.tmp'; |
|
| 881 | + if (!function_exists('imagejpeg')) { |
|
| 882 | + return false; |
|
| 883 | + } |
|
| 884 | + $tmp = $fichier . '.tmp'; |
|
| 885 | 885 | |
| 886 | - // Enable interlancing |
|
| 887 | - imageinterlace($img, true); |
|
| 886 | + // Enable interlancing |
|
| 887 | + imageinterlace($img, true); |
|
| 888 | 888 | |
| 889 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 889 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 890 | 890 | |
| 891 | - if (file_exists($tmp)) { |
|
| 892 | - $taille_test = getimagesize($tmp); |
|
| 893 | - if ($taille_test[0] < 1) { |
|
| 894 | - return false; |
|
| 895 | - } |
|
| 891 | + if (file_exists($tmp)) { |
|
| 892 | + $taille_test = getimagesize($tmp); |
|
| 893 | + if ($taille_test[0] < 1) { |
|
| 894 | + return false; |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 898 | - @rename($tmp, $fichier); |
|
| 897 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 898 | + @rename($tmp, $fichier); |
|
| 899 | 899 | |
| 900 | - return $ret; |
|
| 901 | - } |
|
| 900 | + return $ret; |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | - return false; |
|
| 903 | + return false; |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -918,9 +918,9 @@ discard block |
||
| 918 | 918 | * true si le fichier a bien été créé ; false sinon. |
| 919 | 919 | */ |
| 920 | 920 | function _image_imageico($img, $fichier) { |
| 921 | - $gd_image_array = [$img]; |
|
| 921 | + $gd_image_array = [$img]; |
|
| 922 | 922 | |
| 923 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 923 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -939,24 +939,24 @@ discard block |
||
| 939 | 939 | * - true si une image est bien retournée. |
| 940 | 940 | */ |
| 941 | 941 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 942 | - if (!function_exists('imagewebp')) { |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 945 | - $tmp = $fichier . '.tmp'; |
|
| 946 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 947 | - if (file_exists($tmp)) { |
|
| 948 | - $taille_test = getimagesize($tmp); |
|
| 949 | - if ($taille_test[0] < 1) { |
|
| 950 | - return false; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 954 | - @rename($tmp, $fichier); |
|
| 955 | - |
|
| 956 | - return $ret; |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - return false; |
|
| 942 | + if (!function_exists('imagewebp')) { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | + $tmp = $fichier . '.tmp'; |
|
| 946 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 947 | + if (file_exists($tmp)) { |
|
| 948 | + $taille_test = getimagesize($tmp); |
|
| 949 | + if ($taille_test[0] < 1) { |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 954 | + @rename($tmp, $fichier); |
|
| 955 | + |
|
| 956 | + return $ret; |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + return false; |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | /** |
@@ -976,35 +976,35 @@ discard block |
||
| 976 | 976 | */ |
| 977 | 977 | function _image_imagesvg($img, $fichier) { |
| 978 | 978 | |
| 979 | - $tmp = $fichier . '.tmp'; |
|
| 980 | - if (strpos($img, '<') === false) { |
|
| 981 | - $img = supprimer_timestamp($img); |
|
| 982 | - if (!file_exists($img)) { |
|
| 983 | - return false; |
|
| 984 | - } |
|
| 985 | - @copy($img, $tmp); |
|
| 986 | - if (filesize($tmp) == filesize($img)) { |
|
| 987 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 988 | - @rename($tmp, $fichier); |
|
| 989 | - return true; |
|
| 990 | - } |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - file_put_contents($tmp, $img); |
|
| 995 | - if (file_exists($tmp)) { |
|
| 996 | - $taille_test = spip_getimagesize($tmp); |
|
| 997 | - if ($taille_test[0] < 1) { |
|
| 998 | - return false; |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1002 | - @rename($tmp, $fichier); |
|
| 1003 | - |
|
| 1004 | - return true; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - return false; |
|
| 979 | + $tmp = $fichier . '.tmp'; |
|
| 980 | + if (strpos($img, '<') === false) { |
|
| 981 | + $img = supprimer_timestamp($img); |
|
| 982 | + if (!file_exists($img)) { |
|
| 983 | + return false; |
|
| 984 | + } |
|
| 985 | + @copy($img, $tmp); |
|
| 986 | + if (filesize($tmp) == filesize($img)) { |
|
| 987 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 988 | + @rename($tmp, $fichier); |
|
| 989 | + return true; |
|
| 990 | + } |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + file_put_contents($tmp, $img); |
|
| 995 | + if (file_exists($tmp)) { |
|
| 996 | + $taille_test = spip_getimagesize($tmp); |
|
| 997 | + if ($taille_test[0] < 1) { |
|
| 998 | + return false; |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1002 | + @rename($tmp, $fichier); |
|
| 1003 | + |
|
| 1004 | + return true; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + return false; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | |
@@ -1032,31 +1032,31 @@ discard block |
||
| 1032 | 1032 | * - false sinon. |
| 1033 | 1033 | */ |
| 1034 | 1034 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1035 | - if (is_null($fonction)) { |
|
| 1036 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1037 | - } |
|
| 1038 | - $ret = false; |
|
| 1039 | - #un flag pour reperer les images gravees |
|
| 1040 | - $lock = ( |
|
| 1041 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1042 | - or |
|
| 1043 | - (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1044 | - ); |
|
| 1045 | - if ( |
|
| 1046 | - function_exists($fonction) |
|
| 1047 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1048 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1049 | - && !$lock |
|
| 1050 | - ) { |
|
| 1051 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1052 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1053 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1054 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1055 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1056 | - } |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - return $ret; |
|
| 1035 | + if (is_null($fonction)) { |
|
| 1036 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1037 | + } |
|
| 1038 | + $ret = false; |
|
| 1039 | + #un flag pour reperer les images gravees |
|
| 1040 | + $lock = ( |
|
| 1041 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1042 | + or |
|
| 1043 | + (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1044 | + ); |
|
| 1045 | + if ( |
|
| 1046 | + function_exists($fonction) |
|
| 1047 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1048 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1049 | + && !$lock |
|
| 1050 | + ) { |
|
| 1051 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1052 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1053 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1054 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1055 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1056 | + } |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + return $ret; |
|
| 1060 | 1060 | } |
| 1061 | 1061 | |
| 1062 | 1062 | /** |
@@ -1069,27 +1069,27 @@ discard block |
||
| 1069 | 1069 | * Chemin vers le fichier manquant |
| 1070 | 1070 | **/ |
| 1071 | 1071 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1072 | - $reconstruire = []; |
|
| 1073 | - $fichier = $fichier_manquant; |
|
| 1074 | - while ( |
|
| 1075 | - strpos($fichier, '://') === false |
|
| 1076 | - and !@file_exists($fichier) |
|
| 1077 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1078 | - and $valeurs = unserialize($source) |
|
| 1079 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1080 | - ) { |
|
| 1081 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1082 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1083 | - } |
|
| 1084 | - while (count($reconstruire)) { |
|
| 1085 | - $r = array_pop($reconstruire); |
|
| 1086 | - $fonction = $r[0]; |
|
| 1087 | - $args = $r[1]; |
|
| 1088 | - $fonction(...$args); |
|
| 1089 | - } |
|
| 1090 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1091 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1092 | - ramasse_miettes($fichier_manquant); |
|
| 1072 | + $reconstruire = []; |
|
| 1073 | + $fichier = $fichier_manquant; |
|
| 1074 | + while ( |
|
| 1075 | + strpos($fichier, '://') === false |
|
| 1076 | + and !@file_exists($fichier) |
|
| 1077 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1078 | + and $valeurs = unserialize($source) |
|
| 1079 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1080 | + ) { |
|
| 1081 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1082 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1083 | + } |
|
| 1084 | + while (count($reconstruire)) { |
|
| 1085 | + $r = array_pop($reconstruire); |
|
| 1086 | + $fonction = $r[0]; |
|
| 1087 | + $args = $r[1]; |
|
| 1088 | + $fonction(...$args); |
|
| 1089 | + } |
|
| 1090 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1091 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1092 | + ramasse_miettes($fichier_manquant); |
|
| 1093 | 1093 | } |
| 1094 | 1094 | |
| 1095 | 1095 | /** |
@@ -1109,28 +1109,28 @@ discard block |
||
| 1109 | 1109 | * Chemin du fichier d'image calculé |
| 1110 | 1110 | **/ |
| 1111 | 1111 | function ramasse_miettes($fichier) { |
| 1112 | - if ( |
|
| 1113 | - strpos($fichier, '://') !== false |
|
| 1114 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1115 | - or !$valeurs = unserialize($source) |
|
| 1116 | - ) { |
|
| 1117 | - return; |
|
| 1118 | - } |
|
| 1119 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1120 | - while ( |
|
| 1121 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1122 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1123 | - and (lire_fichier( |
|
| 1124 | - $src = "$fichier.src", |
|
| 1125 | - $source |
|
| 1126 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1127 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1128 | - ) { |
|
| 1129 | - # on efface le fichier |
|
| 1130 | - spip_unlink($fichier); |
|
| 1131 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1132 | - #spip_unlink($src); |
|
| 1133 | - } |
|
| 1112 | + if ( |
|
| 1113 | + strpos($fichier, '://') !== false |
|
| 1114 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1115 | + or !$valeurs = unserialize($source) |
|
| 1116 | + ) { |
|
| 1117 | + return; |
|
| 1118 | + } |
|
| 1119 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1120 | + while ( |
|
| 1121 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1122 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1123 | + and (lire_fichier( |
|
| 1124 | + $src = "$fichier.src", |
|
| 1125 | + $source |
|
| 1126 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1127 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1128 | + ) { |
|
| 1129 | + # on efface le fichier |
|
| 1130 | + spip_unlink($fichier); |
|
| 1131 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1132 | + #spip_unlink($src); |
|
| 1133 | + } |
|
| 1134 | 1134 | } |
| 1135 | 1135 | |
| 1136 | 1136 | |
@@ -1155,31 +1155,31 @@ discard block |
||
| 1155 | 1155 | * Code HTML de l'image |
| 1156 | 1156 | **/ |
| 1157 | 1157 | function image_graver($img) { |
| 1158 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1159 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1160 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1161 | - |
|
| 1162 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1163 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1164 | - $fichier = substr($fichier, 0, $p); |
|
| 1165 | - } |
|
| 1166 | - if (strlen($fichier) < 1) { |
|
| 1167 | - $fichier = $img; |
|
| 1168 | - } |
|
| 1169 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1170 | - # et qu'il ne s'agit pas d'une URL |
|
| 1171 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1172 | - reconstruire_image_intermediaire($fichier); |
|
| 1173 | - } |
|
| 1174 | - ramasse_miettes($fichier); |
|
| 1175 | - |
|
| 1176 | - // ajouter le timestamp si besoin |
|
| 1177 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1178 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1179 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1180 | - } |
|
| 1181 | - |
|
| 1182 | - return $img; |
|
| 1158 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1159 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1160 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1161 | + |
|
| 1162 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1163 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1164 | + $fichier = substr($fichier, 0, $p); |
|
| 1165 | + } |
|
| 1166 | + if (strlen($fichier) < 1) { |
|
| 1167 | + $fichier = $img; |
|
| 1168 | + } |
|
| 1169 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1170 | + # et qu'il ne s'agit pas d'une URL |
|
| 1171 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1172 | + reconstruire_image_intermediaire($fichier); |
|
| 1173 | + } |
|
| 1174 | + ramasse_miettes($fichier); |
|
| 1175 | + |
|
| 1176 | + // ajouter le timestamp si besoin |
|
| 1177 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1178 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1179 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1180 | + } |
|
| 1181 | + |
|
| 1182 | + return $img; |
|
| 1183 | 1183 | } |
| 1184 | 1184 | |
| 1185 | 1185 | /** |
@@ -1206,34 +1206,34 @@ discard block |
||
| 1206 | 1206 | * Code html modifié de la balise. |
| 1207 | 1207 | **/ |
| 1208 | 1208 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1209 | - if ($style === false) { |
|
| 1210 | - $style = extraire_attribut($tag, 'style'); |
|
| 1211 | - } |
|
| 1212 | - |
|
| 1213 | - // enlever le width et height du style |
|
| 1214 | - if ($style) { |
|
| 1215 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1216 | - } |
|
| 1217 | - if ($style and $style[0] === ';') { |
|
| 1218 | - $style = substr($style, 1); |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - // mettre des attributs de width et height sur les images, |
|
| 1222 | - // ca accelere le rendu du navigateur |
|
| 1223 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1224 | - // quand on a desactive l'affichage des images. |
|
| 1225 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1226 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1227 | - |
|
| 1228 | - // attributs deprecies. Transformer en CSS |
|
| 1229 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1230 | - $style = "margin:${espace}px;" . $style; |
|
| 1231 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1235 | - |
|
| 1236 | - return $tag; |
|
| 1209 | + if ($style === false) { |
|
| 1210 | + $style = extraire_attribut($tag, 'style'); |
|
| 1211 | + } |
|
| 1212 | + |
|
| 1213 | + // enlever le width et height du style |
|
| 1214 | + if ($style) { |
|
| 1215 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1216 | + } |
|
| 1217 | + if ($style and $style[0] === ';') { |
|
| 1218 | + $style = substr($style, 1); |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + // mettre des attributs de width et height sur les images, |
|
| 1222 | + // ca accelere le rendu du navigateur |
|
| 1223 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1224 | + // quand on a desactive l'affichage des images. |
|
| 1225 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1226 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1227 | + |
|
| 1228 | + // attributs deprecies. Transformer en CSS |
|
| 1229 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1230 | + $style = "margin:${espace}px;" . $style; |
|
| 1231 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1235 | + |
|
| 1236 | + return $tag; |
|
| 1237 | 1237 | } |
| 1238 | 1238 | |
| 1239 | 1239 | |
@@ -1259,72 +1259,72 @@ discard block |
||
| 1259 | 1259 | * Retourne le code HTML de l'image |
| 1260 | 1260 | **/ |
| 1261 | 1261 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1262 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1263 | - |
|
| 1264 | - // fermer les tags img pas bien fermes; |
|
| 1265 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1266 | - |
|
| 1267 | - // le style |
|
| 1268 | - $style = $valeurs['style']; |
|
| 1269 | - if (isset($surcharge['style'])) { |
|
| 1270 | - $style = $surcharge['style']; |
|
| 1271 | - unset($surcharge['style']); |
|
| 1272 | - } |
|
| 1273 | - |
|
| 1274 | - // traiter specifiquement la largeur et la hauteur |
|
| 1275 | - $width = $valeurs['largeur']; |
|
| 1276 | - if (isset($surcharge['width'])) { |
|
| 1277 | - $width = $surcharge['width']; |
|
| 1278 | - unset($surcharge['width']); |
|
| 1279 | - } |
|
| 1280 | - $height = $valeurs['hauteur']; |
|
| 1281 | - if (isset($surcharge['height'])) { |
|
| 1282 | - $height = $surcharge['height']; |
|
| 1283 | - unset($surcharge['height']); |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1287 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1288 | - // on remplace toute les ref a src dans le tag |
|
| 1289 | - $src = extraire_attribut($tag, 'src'); |
|
| 1290 | - if (isset($surcharge['src'])) { |
|
| 1291 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1292 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1293 | - // pas garanti comme methode, mais mieux que rien |
|
| 1294 | - if (strpos($src, '&') !== false) { |
|
| 1295 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1296 | - } |
|
| 1297 | - $src = $surcharge['src']; |
|
| 1298 | - unset($surcharge['src']); |
|
| 1299 | - } |
|
| 1300 | - |
|
| 1301 | - $class = $valeurs['class']; |
|
| 1302 | - if (isset($surcharge['class'])) { |
|
| 1303 | - $class = $surcharge['class']; |
|
| 1304 | - unset($surcharge['class']); |
|
| 1305 | - } |
|
| 1306 | - if (is_scalar($class) && strlen($class)) { |
|
| 1307 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - if (count($surcharge)) { |
|
| 1311 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1312 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1313 | - } |
|
| 1314 | - } |
|
| 1315 | - |
|
| 1316 | - $tag = pipeline( |
|
| 1317 | - 'image_ecrire_tag_finir', |
|
| 1318 | - [ |
|
| 1319 | - 'args' => [ |
|
| 1320 | - 'valeurs' => $valeurs, |
|
| 1321 | - 'surcharge' => $surcharge, |
|
| 1322 | - ], |
|
| 1323 | - 'data' => $tag |
|
| 1324 | - ] |
|
| 1325 | - ); |
|
| 1326 | - |
|
| 1327 | - return $tag; |
|
| 1262 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1263 | + |
|
| 1264 | + // fermer les tags img pas bien fermes; |
|
| 1265 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1266 | + |
|
| 1267 | + // le style |
|
| 1268 | + $style = $valeurs['style']; |
|
| 1269 | + if (isset($surcharge['style'])) { |
|
| 1270 | + $style = $surcharge['style']; |
|
| 1271 | + unset($surcharge['style']); |
|
| 1272 | + } |
|
| 1273 | + |
|
| 1274 | + // traiter specifiquement la largeur et la hauteur |
|
| 1275 | + $width = $valeurs['largeur']; |
|
| 1276 | + if (isset($surcharge['width'])) { |
|
| 1277 | + $width = $surcharge['width']; |
|
| 1278 | + unset($surcharge['width']); |
|
| 1279 | + } |
|
| 1280 | + $height = $valeurs['hauteur']; |
|
| 1281 | + if (isset($surcharge['height'])) { |
|
| 1282 | + $height = $surcharge['height']; |
|
| 1283 | + unset($surcharge['height']); |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1287 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1288 | + // on remplace toute les ref a src dans le tag |
|
| 1289 | + $src = extraire_attribut($tag, 'src'); |
|
| 1290 | + if (isset($surcharge['src'])) { |
|
| 1291 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1292 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1293 | + // pas garanti comme methode, mais mieux que rien |
|
| 1294 | + if (strpos($src, '&') !== false) { |
|
| 1295 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1296 | + } |
|
| 1297 | + $src = $surcharge['src']; |
|
| 1298 | + unset($surcharge['src']); |
|
| 1299 | + } |
|
| 1300 | + |
|
| 1301 | + $class = $valeurs['class']; |
|
| 1302 | + if (isset($surcharge['class'])) { |
|
| 1303 | + $class = $surcharge['class']; |
|
| 1304 | + unset($surcharge['class']); |
|
| 1305 | + } |
|
| 1306 | + if (is_scalar($class) && strlen($class)) { |
|
| 1307 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + if (count($surcharge)) { |
|
| 1311 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1312 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1313 | + } |
|
| 1314 | + } |
|
| 1315 | + |
|
| 1316 | + $tag = pipeline( |
|
| 1317 | + 'image_ecrire_tag_finir', |
|
| 1318 | + [ |
|
| 1319 | + 'args' => [ |
|
| 1320 | + 'valeurs' => $valeurs, |
|
| 1321 | + 'surcharge' => $surcharge, |
|
| 1322 | + ], |
|
| 1323 | + 'data' => $tag |
|
| 1324 | + ] |
|
| 1325 | + ); |
|
| 1326 | + |
|
| 1327 | + return $tag; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | /** |
@@ -1347,268 +1347,268 @@ discard block |
||
| 1347 | 1347 | * Description de l'image, sinon null. |
| 1348 | 1348 | **/ |
| 1349 | 1349 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1350 | - $srcHeight = null; |
|
| 1351 | - $retour = []; |
|
| 1352 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1353 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1354 | - $image = $valeurs['fichier']; |
|
| 1355 | - $format = $valeurs['format_source']; |
|
| 1356 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1357 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1358 | - |
|
| 1359 | - $format_sortie = $valeurs['format_dest']; |
|
| 1360 | - |
|
| 1361 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1362 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1363 | - } |
|
| 1364 | - |
|
| 1365 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1366 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1367 | - return; |
|
| 1368 | - } |
|
| 1369 | - $destination = "$destdir/$destfile"; |
|
| 1370 | - |
|
| 1371 | - // calculer la taille |
|
| 1372 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1373 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1374 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1375 | - } |
|
| 1376 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1377 | - $destWidth = $maxWidth; |
|
| 1378 | - $destHeight = $maxHeight; |
|
| 1379 | - } else { |
|
| 1380 | - spip_log("echec $process sur $image"); |
|
| 1381 | - |
|
| 1382 | - return; |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - $vignette = ''; |
|
| 1386 | - |
|
| 1387 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1388 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1389 | - $vignette = $destination . '.' . $format; |
|
| 1390 | - @copy($image, $vignette); |
|
| 1391 | - } |
|
| 1392 | - |
|
| 1393 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1394 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1395 | - $format_sortie = 'svg'; |
|
| 1396 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1397 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1398 | - _image_gd_output($svg, $valeurs); |
|
| 1399 | - } |
|
| 1400 | - } |
|
| 1401 | - |
|
| 1402 | - // imagemagick en ligne de commande |
|
| 1403 | - elseif ($process == 'convert') { |
|
| 1404 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1405 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1406 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1407 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1408 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1409 | - } |
|
| 1410 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1411 | - $commande = str_replace( |
|
| 1412 | - ['%x', '%y', '%src', '%dest'], |
|
| 1413 | - [ |
|
| 1414 | - $destWidth, |
|
| 1415 | - $destHeight, |
|
| 1416 | - escapeshellcmd($image), |
|
| 1417 | - escapeshellcmd($vignette) |
|
| 1418 | - ], |
|
| 1419 | - _RESIZE_COMMAND |
|
| 1420 | - ); |
|
| 1421 | - spip_log($commande); |
|
| 1422 | - exec($commande); |
|
| 1423 | - if (!@file_exists($vignette)) { |
|
| 1424 | - spip_log("echec convert sur $vignette"); |
|
| 1425 | - |
|
| 1426 | - return; // echec commande |
|
| 1427 | - } |
|
| 1428 | - } |
|
| 1429 | - |
|
| 1430 | - // php5 imagemagick |
|
| 1431 | - elseif ($process == 'imagick') { |
|
| 1432 | - |
|
| 1433 | - if (!class_exists(\Imagick::class)) { |
|
| 1434 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1435 | - |
|
| 1436 | - return; |
|
| 1437 | - } |
|
| 1438 | - |
|
| 1439 | - // chemin compatible Windows |
|
| 1440 | - $output = realpath(dirname($destination)); |
|
| 1441 | - if (!$output) { |
|
| 1442 | - return; |
|
| 1443 | - } |
|
| 1444 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1445 | - |
|
| 1446 | - $imagick = new Imagick(); |
|
| 1447 | - $imagick->readImage(realpath($image)); |
|
| 1448 | - $imagick->resizeImage( |
|
| 1449 | - $destWidth, |
|
| 1450 | - $destHeight, |
|
| 1451 | - Imagick::FILTER_LANCZOS, |
|
| 1452 | - 1 |
|
| 1453 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1454 | - $imagick->writeImage($vignette); |
|
| 1455 | - |
|
| 1456 | - if (!@file_exists($vignette)) { |
|
| 1457 | - spip_log("echec imagick sur $vignette"); |
|
| 1458 | - |
|
| 1459 | - return; |
|
| 1460 | - } |
|
| 1461 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1462 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1463 | - } |
|
| 1464 | - |
|
| 1465 | - // netpbm |
|
| 1466 | - elseif ($process == 'netpbm') { |
|
| 1467 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1468 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1469 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1470 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1471 | - return; |
|
| 1472 | - } |
|
| 1473 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1474 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1475 | - if ($format == 'jpg') { |
|
| 1476 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1477 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1478 | - if (!($s = @filesize($vignette))) { |
|
| 1479 | - spip_unlink($vignette); |
|
| 1480 | - } |
|
| 1481 | - if (!@file_exists($vignette)) { |
|
| 1482 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1483 | - |
|
| 1484 | - return; |
|
| 1485 | - } |
|
| 1486 | - } else { |
|
| 1487 | - if ($format == 'gif') { |
|
| 1488 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1489 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1490 | - if (!($s = @filesize($vignette))) { |
|
| 1491 | - spip_unlink($vignette); |
|
| 1492 | - } |
|
| 1493 | - if (!@file_exists($vignette)) { |
|
| 1494 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1495 | - |
|
| 1496 | - return; |
|
| 1497 | - } |
|
| 1498 | - } else { |
|
| 1499 | - if ($format == 'png') { |
|
| 1500 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1501 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1502 | - if (!($s = @filesize($vignette))) { |
|
| 1503 | - spip_unlink($vignette); |
|
| 1504 | - } |
|
| 1505 | - if (!@file_exists($vignette)) { |
|
| 1506 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1507 | - |
|
| 1508 | - return; |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - } |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - |
|
| 1515 | - // gd ou gd2 |
|
| 1516 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1517 | - if (!function_exists('gd_info')) { |
|
| 1518 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1519 | - |
|
| 1520 | - return; |
|
| 1521 | - } |
|
| 1522 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1523 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1524 | - |
|
| 1525 | - return; |
|
| 1526 | - } |
|
| 1527 | - $destFormat = $format_sortie; |
|
| 1528 | - if (!$destFormat) { |
|
| 1529 | - spip_log("pas de format pour $image"); |
|
| 1530 | - |
|
| 1531 | - return; |
|
| 1532 | - } |
|
| 1533 | - |
|
| 1534 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1535 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1536 | - return; |
|
| 1537 | - } |
|
| 1538 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1539 | - if (!$srcImage) { |
|
| 1540 | - spip_log('echec gd1/gd2'); |
|
| 1541 | - |
|
| 1542 | - return; |
|
| 1543 | - } |
|
| 1544 | - |
|
| 1545 | - // Initialisation de l'image destination |
|
| 1546 | - $destImage = null; |
|
| 1547 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1548 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1549 | - } |
|
| 1550 | - if (!$destImage) { |
|
| 1551 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1552 | - } |
|
| 1553 | - |
|
| 1554 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1555 | - $ok = false; |
|
| 1556 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1557 | - if ($format == 'gif') { |
|
| 1558 | - // Si un GIF est transparent, |
|
| 1559 | - // fabriquer un PNG transparent |
|
| 1560 | - $transp = imagecolortransparent($srcImage); |
|
| 1561 | - if ($transp > 0) { |
|
| 1562 | - $destFormat = 'png'; |
|
| 1563 | - } |
|
| 1564 | - } |
|
| 1565 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1566 | - // Conserver la transparence |
|
| 1567 | - if (function_exists('imageAntiAlias')) { |
|
| 1568 | - imageAntiAlias($destImage, true); |
|
| 1569 | - } |
|
| 1570 | - @imagealphablending($destImage, false); |
|
| 1571 | - @imagesavealpha($destImage, true); |
|
| 1572 | - } |
|
| 1573 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1574 | - } |
|
| 1575 | - if (!$ok) { |
|
| 1576 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1577 | - } |
|
| 1578 | - |
|
| 1579 | - // Sauvegarde de l'image destination |
|
| 1580 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1581 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1582 | - _image_gd_output($destImage, $valeurs); |
|
| 1583 | - |
|
| 1584 | - if ($srcImage) { |
|
| 1585 | - ImageDestroy($srcImage); |
|
| 1586 | - } |
|
| 1587 | - ImageDestroy($destImage); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1591 | - $size = [$destWidth, $destHeight]; |
|
| 1592 | - } |
|
| 1593 | - |
|
| 1594 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1595 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1596 | - if ($size[0] < 1) { |
|
| 1597 | - $size[0] = $destWidth; |
|
| 1598 | - } |
|
| 1599 | - if ($size[1] < 1) { |
|
| 1600 | - $size[1] = $destHeight; |
|
| 1601 | - } |
|
| 1602 | - |
|
| 1603 | - $retour['width'] = $largeur = $size[0]; |
|
| 1604 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1605 | - |
|
| 1606 | - $retour['fichier'] = $vignette; |
|
| 1607 | - $retour['format'] = $format; |
|
| 1608 | - $retour['date'] = @filemtime($vignette); |
|
| 1609 | - |
|
| 1610 | - // renvoyer l'image |
|
| 1611 | - return $retour; |
|
| 1350 | + $srcHeight = null; |
|
| 1351 | + $retour = []; |
|
| 1352 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1353 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1354 | + $image = $valeurs['fichier']; |
|
| 1355 | + $format = $valeurs['format_source']; |
|
| 1356 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1357 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1358 | + |
|
| 1359 | + $format_sortie = $valeurs['format_dest']; |
|
| 1360 | + |
|
| 1361 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1362 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1363 | + } |
|
| 1364 | + |
|
| 1365 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1366 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1367 | + return; |
|
| 1368 | + } |
|
| 1369 | + $destination = "$destdir/$destfile"; |
|
| 1370 | + |
|
| 1371 | + // calculer la taille |
|
| 1372 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1373 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1374 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1375 | + } |
|
| 1376 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1377 | + $destWidth = $maxWidth; |
|
| 1378 | + $destHeight = $maxHeight; |
|
| 1379 | + } else { |
|
| 1380 | + spip_log("echec $process sur $image"); |
|
| 1381 | + |
|
| 1382 | + return; |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + $vignette = ''; |
|
| 1386 | + |
|
| 1387 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1388 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1389 | + $vignette = $destination . '.' . $format; |
|
| 1390 | + @copy($image, $vignette); |
|
| 1391 | + } |
|
| 1392 | + |
|
| 1393 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1394 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1395 | + $format_sortie = 'svg'; |
|
| 1396 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1397 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1398 | + _image_gd_output($svg, $valeurs); |
|
| 1399 | + } |
|
| 1400 | + } |
|
| 1401 | + |
|
| 1402 | + // imagemagick en ligne de commande |
|
| 1403 | + elseif ($process == 'convert') { |
|
| 1404 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1405 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1406 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1407 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1408 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1409 | + } |
|
| 1410 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1411 | + $commande = str_replace( |
|
| 1412 | + ['%x', '%y', '%src', '%dest'], |
|
| 1413 | + [ |
|
| 1414 | + $destWidth, |
|
| 1415 | + $destHeight, |
|
| 1416 | + escapeshellcmd($image), |
|
| 1417 | + escapeshellcmd($vignette) |
|
| 1418 | + ], |
|
| 1419 | + _RESIZE_COMMAND |
|
| 1420 | + ); |
|
| 1421 | + spip_log($commande); |
|
| 1422 | + exec($commande); |
|
| 1423 | + if (!@file_exists($vignette)) { |
|
| 1424 | + spip_log("echec convert sur $vignette"); |
|
| 1425 | + |
|
| 1426 | + return; // echec commande |
|
| 1427 | + } |
|
| 1428 | + } |
|
| 1429 | + |
|
| 1430 | + // php5 imagemagick |
|
| 1431 | + elseif ($process == 'imagick') { |
|
| 1432 | + |
|
| 1433 | + if (!class_exists(\Imagick::class)) { |
|
| 1434 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1435 | + |
|
| 1436 | + return; |
|
| 1437 | + } |
|
| 1438 | + |
|
| 1439 | + // chemin compatible Windows |
|
| 1440 | + $output = realpath(dirname($destination)); |
|
| 1441 | + if (!$output) { |
|
| 1442 | + return; |
|
| 1443 | + } |
|
| 1444 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1445 | + |
|
| 1446 | + $imagick = new Imagick(); |
|
| 1447 | + $imagick->readImage(realpath($image)); |
|
| 1448 | + $imagick->resizeImage( |
|
| 1449 | + $destWidth, |
|
| 1450 | + $destHeight, |
|
| 1451 | + Imagick::FILTER_LANCZOS, |
|
| 1452 | + 1 |
|
| 1453 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1454 | + $imagick->writeImage($vignette); |
|
| 1455 | + |
|
| 1456 | + if (!@file_exists($vignette)) { |
|
| 1457 | + spip_log("echec imagick sur $vignette"); |
|
| 1458 | + |
|
| 1459 | + return; |
|
| 1460 | + } |
|
| 1461 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1462 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1463 | + } |
|
| 1464 | + |
|
| 1465 | + // netpbm |
|
| 1466 | + elseif ($process == 'netpbm') { |
|
| 1467 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1468 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1469 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1470 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1471 | + return; |
|
| 1472 | + } |
|
| 1473 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1474 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1475 | + if ($format == 'jpg') { |
|
| 1476 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1477 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1478 | + if (!($s = @filesize($vignette))) { |
|
| 1479 | + spip_unlink($vignette); |
|
| 1480 | + } |
|
| 1481 | + if (!@file_exists($vignette)) { |
|
| 1482 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1483 | + |
|
| 1484 | + return; |
|
| 1485 | + } |
|
| 1486 | + } else { |
|
| 1487 | + if ($format == 'gif') { |
|
| 1488 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1489 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1490 | + if (!($s = @filesize($vignette))) { |
|
| 1491 | + spip_unlink($vignette); |
|
| 1492 | + } |
|
| 1493 | + if (!@file_exists($vignette)) { |
|
| 1494 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1495 | + |
|
| 1496 | + return; |
|
| 1497 | + } |
|
| 1498 | + } else { |
|
| 1499 | + if ($format == 'png') { |
|
| 1500 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1501 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1502 | + if (!($s = @filesize($vignette))) { |
|
| 1503 | + spip_unlink($vignette); |
|
| 1504 | + } |
|
| 1505 | + if (!@file_exists($vignette)) { |
|
| 1506 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1507 | + |
|
| 1508 | + return; |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + } |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + |
|
| 1515 | + // gd ou gd2 |
|
| 1516 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1517 | + if (!function_exists('gd_info')) { |
|
| 1518 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1519 | + |
|
| 1520 | + return; |
|
| 1521 | + } |
|
| 1522 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1523 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1524 | + |
|
| 1525 | + return; |
|
| 1526 | + } |
|
| 1527 | + $destFormat = $format_sortie; |
|
| 1528 | + if (!$destFormat) { |
|
| 1529 | + spip_log("pas de format pour $image"); |
|
| 1530 | + |
|
| 1531 | + return; |
|
| 1532 | + } |
|
| 1533 | + |
|
| 1534 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1535 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1536 | + return; |
|
| 1537 | + } |
|
| 1538 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1539 | + if (!$srcImage) { |
|
| 1540 | + spip_log('echec gd1/gd2'); |
|
| 1541 | + |
|
| 1542 | + return; |
|
| 1543 | + } |
|
| 1544 | + |
|
| 1545 | + // Initialisation de l'image destination |
|
| 1546 | + $destImage = null; |
|
| 1547 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1548 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1549 | + } |
|
| 1550 | + if (!$destImage) { |
|
| 1551 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1552 | + } |
|
| 1553 | + |
|
| 1554 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1555 | + $ok = false; |
|
| 1556 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1557 | + if ($format == 'gif') { |
|
| 1558 | + // Si un GIF est transparent, |
|
| 1559 | + // fabriquer un PNG transparent |
|
| 1560 | + $transp = imagecolortransparent($srcImage); |
|
| 1561 | + if ($transp > 0) { |
|
| 1562 | + $destFormat = 'png'; |
|
| 1563 | + } |
|
| 1564 | + } |
|
| 1565 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1566 | + // Conserver la transparence |
|
| 1567 | + if (function_exists('imageAntiAlias')) { |
|
| 1568 | + imageAntiAlias($destImage, true); |
|
| 1569 | + } |
|
| 1570 | + @imagealphablending($destImage, false); |
|
| 1571 | + @imagesavealpha($destImage, true); |
|
| 1572 | + } |
|
| 1573 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1574 | + } |
|
| 1575 | + if (!$ok) { |
|
| 1576 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1577 | + } |
|
| 1578 | + |
|
| 1579 | + // Sauvegarde de l'image destination |
|
| 1580 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1581 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1582 | + _image_gd_output($destImage, $valeurs); |
|
| 1583 | + |
|
| 1584 | + if ($srcImage) { |
|
| 1585 | + ImageDestroy($srcImage); |
|
| 1586 | + } |
|
| 1587 | + ImageDestroy($destImage); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1591 | + $size = [$destWidth, $destHeight]; |
|
| 1592 | + } |
|
| 1593 | + |
|
| 1594 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1595 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1596 | + if ($size[0] < 1) { |
|
| 1597 | + $size[0] = $destWidth; |
|
| 1598 | + } |
|
| 1599 | + if ($size[1] < 1) { |
|
| 1600 | + $size[1] = $destHeight; |
|
| 1601 | + } |
|
| 1602 | + |
|
| 1603 | + $retour['width'] = $largeur = $size[0]; |
|
| 1604 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1605 | + |
|
| 1606 | + $retour['fichier'] = $vignette; |
|
| 1607 | + $retour['format'] = $format; |
|
| 1608 | + $retour['date'] = @filemtime($vignette); |
|
| 1609 | + |
|
| 1610 | + // renvoyer l'image |
|
| 1611 | + return $retour; |
|
| 1612 | 1612 | } |
| 1613 | 1613 | |
| 1614 | 1614 | /** |
@@ -1628,25 +1628,25 @@ discard block |
||
| 1628 | 1628 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1629 | 1629 | **/ |
| 1630 | 1630 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1631 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1632 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1633 | - |
|
| 1634 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1635 | - $destWidth = $srcWidth; |
|
| 1636 | - $destHeight = $srcHeight; |
|
| 1637 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1638 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1639 | - $destHeight = $maxHeight; |
|
| 1640 | - } else { |
|
| 1641 | - $destWidth = $maxWidth; |
|
| 1642 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1643 | - } |
|
| 1644 | - |
|
| 1645 | - return [ |
|
| 1646 | - intval(round($destWidth)), |
|
| 1647 | - intval(round($destHeight)), |
|
| 1648 | - max($ratioWidth, $ratioHeight) |
|
| 1649 | - ]; |
|
| 1631 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1632 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1633 | + |
|
| 1634 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1635 | + $destWidth = $srcWidth; |
|
| 1636 | + $destHeight = $srcHeight; |
|
| 1637 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1638 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1639 | + $destHeight = $maxHeight; |
|
| 1640 | + } else { |
|
| 1641 | + $destWidth = $maxWidth; |
|
| 1642 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1643 | + } |
|
| 1644 | + |
|
| 1645 | + return [ |
|
| 1646 | + intval(round($destWidth)), |
|
| 1647 | + intval(round($destHeight)), |
|
| 1648 | + max($ratioWidth, $ratioHeight) |
|
| 1649 | + ]; |
|
| 1650 | 1650 | } |
| 1651 | 1651 | |
| 1652 | 1652 | /** |
@@ -1666,25 +1666,25 @@ discard block |
||
| 1666 | 1666 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1667 | 1667 | **/ |
| 1668 | 1668 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1669 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1670 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1671 | - |
|
| 1672 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1673 | - $destWidth = $srcWidth; |
|
| 1674 | - $destHeight = $srcHeight; |
|
| 1675 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1676 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1677 | - $destHeight = $maxHeight; |
|
| 1678 | - } else { |
|
| 1679 | - $destWidth = $maxWidth; |
|
| 1680 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1681 | - } |
|
| 1682 | - |
|
| 1683 | - return [ |
|
| 1684 | - intval(round($destWidth)), |
|
| 1685 | - intval(round($destHeight)), |
|
| 1686 | - min($ratioWidth, $ratioHeight) |
|
| 1687 | - ]; |
|
| 1669 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1670 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1671 | + |
|
| 1672 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1673 | + $destWidth = $srcWidth; |
|
| 1674 | + $destHeight = $srcHeight; |
|
| 1675 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1676 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1677 | + $destHeight = $maxHeight; |
|
| 1678 | + } else { |
|
| 1679 | + $destWidth = $maxWidth; |
|
| 1680 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1681 | + } |
|
| 1682 | + |
|
| 1683 | + return [ |
|
| 1684 | + intval(round($destWidth)), |
|
| 1685 | + intval(round($destHeight)), |
|
| 1686 | + min($ratioWidth, $ratioHeight) |
|
| 1687 | + ]; |
|
| 1688 | 1688 | } |
| 1689 | 1689 | |
| 1690 | 1690 | |
@@ -1697,12 +1697,12 @@ discard block |
||
| 1697 | 1697 | * @return string |
| 1698 | 1698 | */ |
| 1699 | 1699 | function process_image_svg_identite($image) { |
| 1700 | - if ($image['creer']) { |
|
| 1701 | - $source = $image['fichier']; |
|
| 1702 | - _image_gd_output($source, $image); |
|
| 1703 | - } |
|
| 1700 | + if ($image['creer']) { |
|
| 1701 | + $source = $image['fichier']; |
|
| 1702 | + _image_gd_output($source, $image); |
|
| 1703 | + } |
|
| 1704 | 1704 | |
| 1705 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1705 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1706 | 1706 | } |
| 1707 | 1707 | |
| 1708 | 1708 | |
@@ -1735,111 +1735,111 @@ discard block |
||
| 1735 | 1735 | * Code HTML de la balise img produite |
| 1736 | 1736 | **/ |
| 1737 | 1737 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1738 | - $image = false; |
|
| 1739 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1740 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1741 | - } |
|
| 1742 | - # determiner le format de sortie |
|
| 1743 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1744 | - if ($process == 'netpbm') { |
|
| 1745 | - $format_sortie = 'jpg'; |
|
| 1746 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1747 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1748 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1749 | - $gd_formats = formats_image_acceptables(true); |
|
| 1750 | - if ( |
|
| 1751 | - is_array($image) |
|
| 1752 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1753 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1754 | - ) |
|
| 1755 | - ) { |
|
| 1756 | - if ($image['format_source'] == 'jpg') { |
|
| 1757 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1758 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1759 | - { |
|
| 1760 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1761 | - } |
|
| 1762 | - // Choisir le format destination |
|
| 1763 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1764 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1765 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1766 | - # pas *ecrire* |
|
| 1767 | - $format_sortie = ''; |
|
| 1768 | - foreach ($formats_sortie as $fmt) { |
|
| 1769 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1770 | - $format_sortie = $fmt; |
|
| 1771 | - break; |
|
| 1772 | - } |
|
| 1773 | - } |
|
| 1774 | - $image = false; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - |
|
| 1778 | - if (!is_array($image)) { |
|
| 1779 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1780 | - } |
|
| 1781 | - |
|
| 1782 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1783 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1784 | - // on peut resizer en mode html si on dispose des elements |
|
| 1785 | - if ( |
|
| 1786 | - $srcw = extraire_attribut($img, 'width') |
|
| 1787 | - and $srch = extraire_attribut($img, 'height') |
|
| 1788 | - ) { |
|
| 1789 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1790 | - |
|
| 1791 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1792 | - } |
|
| 1793 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1794 | - // sous la forme style='max-width: NNpx;' |
|
| 1795 | - return inserer_attribut( |
|
| 1796 | - $img, |
|
| 1797 | - 'style', |
|
| 1798 | - "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1799 | - ); |
|
| 1800 | - } |
|
| 1801 | - |
|
| 1802 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1803 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1804 | - if ($image['creer']) { |
|
| 1805 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1806 | - } |
|
| 1807 | - |
|
| 1808 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1809 | - } |
|
| 1810 | - |
|
| 1811 | - if ($image['creer'] == false && !$force) { |
|
| 1812 | - return _image_ecrire_tag( |
|
| 1813 | - $image, |
|
| 1814 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1815 | - ); |
|
| 1816 | - } |
|
| 1817 | - |
|
| 1818 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1819 | - $destWidth = $image['largeur_dest']; |
|
| 1820 | - $destHeight = $image['hauteur_dest']; |
|
| 1821 | - $logo = $image['fichier']; |
|
| 1822 | - $date = $image['date_src']; |
|
| 1823 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1824 | - |
|
| 1825 | - if ($preview && $preview['fichier']) { |
|
| 1826 | - $logo = $preview['fichier']; |
|
| 1827 | - $destWidth = $preview['width']; |
|
| 1828 | - $destHeight = $preview['height']; |
|
| 1829 | - $date = $preview['date']; |
|
| 1830 | - } |
|
| 1831 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1832 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1833 | - // quand on fait supprimer/reuploader un logo |
|
| 1834 | - // (pas de filemtime si SAFE MODE) |
|
| 1835 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1836 | - |
|
| 1837 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1838 | - } |
|
| 1839 | - else { |
|
| 1840 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1841 | - return $img; |
|
| 1842 | - } |
|
| 1738 | + $image = false; |
|
| 1739 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1740 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1741 | + } |
|
| 1742 | + # determiner le format de sortie |
|
| 1743 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1744 | + if ($process == 'netpbm') { |
|
| 1745 | + $format_sortie = 'jpg'; |
|
| 1746 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1747 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1748 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1749 | + $gd_formats = formats_image_acceptables(true); |
|
| 1750 | + if ( |
|
| 1751 | + is_array($image) |
|
| 1752 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1753 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1754 | + ) |
|
| 1755 | + ) { |
|
| 1756 | + if ($image['format_source'] == 'jpg') { |
|
| 1757 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1758 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1759 | + { |
|
| 1760 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1761 | + } |
|
| 1762 | + // Choisir le format destination |
|
| 1763 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1764 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1765 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1766 | + # pas *ecrire* |
|
| 1767 | + $format_sortie = ''; |
|
| 1768 | + foreach ($formats_sortie as $fmt) { |
|
| 1769 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1770 | + $format_sortie = $fmt; |
|
| 1771 | + break; |
|
| 1772 | + } |
|
| 1773 | + } |
|
| 1774 | + $image = false; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + |
|
| 1778 | + if (!is_array($image)) { |
|
| 1779 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1780 | + } |
|
| 1781 | + |
|
| 1782 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1783 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1784 | + // on peut resizer en mode html si on dispose des elements |
|
| 1785 | + if ( |
|
| 1786 | + $srcw = extraire_attribut($img, 'width') |
|
| 1787 | + and $srch = extraire_attribut($img, 'height') |
|
| 1788 | + ) { |
|
| 1789 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1790 | + |
|
| 1791 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1792 | + } |
|
| 1793 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1794 | + // sous la forme style='max-width: NNpx;' |
|
| 1795 | + return inserer_attribut( |
|
| 1796 | + $img, |
|
| 1797 | + 'style', |
|
| 1798 | + "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1799 | + ); |
|
| 1800 | + } |
|
| 1801 | + |
|
| 1802 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1803 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1804 | + if ($image['creer']) { |
|
| 1805 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1806 | + } |
|
| 1807 | + |
|
| 1808 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1809 | + } |
|
| 1810 | + |
|
| 1811 | + if ($image['creer'] == false && !$force) { |
|
| 1812 | + return _image_ecrire_tag( |
|
| 1813 | + $image, |
|
| 1814 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1815 | + ); |
|
| 1816 | + } |
|
| 1817 | + |
|
| 1818 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1819 | + $destWidth = $image['largeur_dest']; |
|
| 1820 | + $destHeight = $image['hauteur_dest']; |
|
| 1821 | + $logo = $image['fichier']; |
|
| 1822 | + $date = $image['date_src']; |
|
| 1823 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1824 | + |
|
| 1825 | + if ($preview && $preview['fichier']) { |
|
| 1826 | + $logo = $preview['fichier']; |
|
| 1827 | + $destWidth = $preview['width']; |
|
| 1828 | + $destHeight = $preview['height']; |
|
| 1829 | + $date = $preview['date']; |
|
| 1830 | + } |
|
| 1831 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1832 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1833 | + // quand on fait supprimer/reuploader un logo |
|
| 1834 | + // (pas de filemtime si SAFE MODE) |
|
| 1835 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1836 | + |
|
| 1837 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1838 | + } |
|
| 1839 | + else { |
|
| 1840 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1841 | + return $img; |
|
| 1842 | + } |
|
| 1843 | 1843 | } |
| 1844 | 1844 | |
| 1845 | 1845 | /** |
@@ -1853,145 +1853,145 @@ discard block |
||
| 1853 | 1853 | * Class phpthumb_functions |
| 1854 | 1854 | */ |
| 1855 | 1855 | class phpthumb_functions { |
| 1856 | - /** |
|
| 1857 | - * Retourne la couleur d'un pixel dans une image |
|
| 1858 | - * |
|
| 1859 | - * @param resource|GdImage $img |
|
| 1860 | - * @param int $x |
|
| 1861 | - * @param int $y |
|
| 1862 | - * @return array|bool |
|
| 1863 | - */ |
|
| 1864 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1865 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1866 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1867 | - } |
|
| 1868 | - return false; |
|
| 1869 | - } |
|
| 1870 | - |
|
| 1871 | - /** |
|
| 1872 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1873 | - * |
|
| 1874 | - * @param int $number |
|
| 1875 | - * @param int $minbytes |
|
| 1876 | - * @return string |
|
| 1877 | - */ |
|
| 1878 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1879 | - $intstring = ''; |
|
| 1880 | - while ($number > 0) { |
|
| 1881 | - $intstring = $intstring . chr($number & 255); |
|
| 1882 | - $number >>= 8; |
|
| 1883 | - } |
|
| 1884 | - |
|
| 1885 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1886 | - } |
|
| 1887 | - |
|
| 1888 | - /** |
|
| 1889 | - * Transforme une ressource GD en image au format ICO |
|
| 1890 | - * |
|
| 1891 | - * @param array $gd_image_array |
|
| 1892 | - * Tableau de ressources d'images GD |
|
| 1893 | - * @return string |
|
| 1894 | - * Image au format ICO |
|
| 1895 | - */ |
|
| 1896 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1897 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1898 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1899 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1900 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1901 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1902 | - |
|
| 1903 | - $icXOR[$key] = ''; |
|
| 1904 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1905 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1906 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1907 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1908 | - $r = $argb['red']; |
|
| 1909 | - $g = $argb['green']; |
|
| 1910 | - $b = $argb['blue']; |
|
| 1911 | - |
|
| 1912 | - if ($bpp[$key] == 32) { |
|
| 1913 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1914 | - } elseif ($bpp[$key] == 24) { |
|
| 1915 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1916 | - } |
|
| 1917 | - |
|
| 1918 | - if ($a < 128) { |
|
| 1919 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1920 | - } else { |
|
| 1921 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1922 | - } |
|
| 1923 | - } |
|
| 1924 | - // mask bits are 32-bit aligned per scanline |
|
| 1925 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1926 | - $icANDmask[$key][$y] .= '0'; |
|
| 1927 | - } |
|
| 1928 | - } |
|
| 1929 | - $icAND[$key] = ''; |
|
| 1930 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1931 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1932 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1933 | - } |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - |
|
| 1937 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1938 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1939 | - |
|
| 1940 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1941 | - $BitmapInfoHeader[$key] = ''; |
|
| 1942 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1943 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1944 | - // The biHeight member specifies the combined |
|
| 1945 | - // height of the XOR and AND masks. |
|
| 1946 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1947 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1948 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1949 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1950 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1951 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1952 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1953 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1954 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1955 | - } |
|
| 1956 | - |
|
| 1957 | - |
|
| 1958 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1959 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1960 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1961 | - |
|
| 1962 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1963 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1964 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1965 | - |
|
| 1966 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1967 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1968 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1969 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1970 | - |
|
| 1971 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1972 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1973 | - |
|
| 1974 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1975 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1976 | - $dwBytesInRes, |
|
| 1977 | - 4 |
|
| 1978 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1979 | - |
|
| 1980 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1981 | - $dwImageOffset, |
|
| 1982 | - 4 |
|
| 1983 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1984 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1985 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1986 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1987 | - } |
|
| 1988 | - |
|
| 1989 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1990 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1991 | - $icondata .= $icXOR[$key]; |
|
| 1992 | - $icondata .= $icAND[$key]; |
|
| 1993 | - } |
|
| 1994 | - |
|
| 1995 | - return $icondata; |
|
| 1996 | - } |
|
| 1856 | + /** |
|
| 1857 | + * Retourne la couleur d'un pixel dans une image |
|
| 1858 | + * |
|
| 1859 | + * @param resource|GdImage $img |
|
| 1860 | + * @param int $x |
|
| 1861 | + * @param int $y |
|
| 1862 | + * @return array|bool |
|
| 1863 | + */ |
|
| 1864 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1865 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1866 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1867 | + } |
|
| 1868 | + return false; |
|
| 1869 | + } |
|
| 1870 | + |
|
| 1871 | + /** |
|
| 1872 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1873 | + * |
|
| 1874 | + * @param int $number |
|
| 1875 | + * @param int $minbytes |
|
| 1876 | + * @return string |
|
| 1877 | + */ |
|
| 1878 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1879 | + $intstring = ''; |
|
| 1880 | + while ($number > 0) { |
|
| 1881 | + $intstring = $intstring . chr($number & 255); |
|
| 1882 | + $number >>= 8; |
|
| 1883 | + } |
|
| 1884 | + |
|
| 1885 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1886 | + } |
|
| 1887 | + |
|
| 1888 | + /** |
|
| 1889 | + * Transforme une ressource GD en image au format ICO |
|
| 1890 | + * |
|
| 1891 | + * @param array $gd_image_array |
|
| 1892 | + * Tableau de ressources d'images GD |
|
| 1893 | + * @return string |
|
| 1894 | + * Image au format ICO |
|
| 1895 | + */ |
|
| 1896 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1897 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1898 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1899 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1900 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1901 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1902 | + |
|
| 1903 | + $icXOR[$key] = ''; |
|
| 1904 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1905 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1906 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1907 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1908 | + $r = $argb['red']; |
|
| 1909 | + $g = $argb['green']; |
|
| 1910 | + $b = $argb['blue']; |
|
| 1911 | + |
|
| 1912 | + if ($bpp[$key] == 32) { |
|
| 1913 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1914 | + } elseif ($bpp[$key] == 24) { |
|
| 1915 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1916 | + } |
|
| 1917 | + |
|
| 1918 | + if ($a < 128) { |
|
| 1919 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1920 | + } else { |
|
| 1921 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1922 | + } |
|
| 1923 | + } |
|
| 1924 | + // mask bits are 32-bit aligned per scanline |
|
| 1925 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1926 | + $icANDmask[$key][$y] .= '0'; |
|
| 1927 | + } |
|
| 1928 | + } |
|
| 1929 | + $icAND[$key] = ''; |
|
| 1930 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1931 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1932 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1933 | + } |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + |
|
| 1937 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1938 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1939 | + |
|
| 1940 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1941 | + $BitmapInfoHeader[$key] = ''; |
|
| 1942 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1943 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1944 | + // The biHeight member specifies the combined |
|
| 1945 | + // height of the XOR and AND masks. |
|
| 1946 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1947 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1948 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1949 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1950 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1951 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1952 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1953 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1954 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1955 | + } |
|
| 1956 | + |
|
| 1957 | + |
|
| 1958 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1959 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1960 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1961 | + |
|
| 1962 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1963 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1964 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1965 | + |
|
| 1966 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1967 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1968 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1969 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1970 | + |
|
| 1971 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1972 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1973 | + |
|
| 1974 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1975 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1976 | + $dwBytesInRes, |
|
| 1977 | + 4 |
|
| 1978 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1979 | + |
|
| 1980 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1981 | + $dwImageOffset, |
|
| 1982 | + 4 |
|
| 1983 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1984 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1985 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1986 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1987 | + } |
|
| 1988 | + |
|
| 1989 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1990 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1991 | + $icondata .= $icXOR[$key]; |
|
| 1992 | + $icondata .= $icAND[$key]; |
|
| 1993 | + } |
|
| 1994 | + |
|
| 1995 | + return $icondata; |
|
| 1996 | + } |
|
| 1997 | 1997 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Formulaires |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -36,25 +36,25 @@ discard block |
||
| 36 | 36 | * ($table_source,$objet,$id_objet,$objet_lien) |
| 37 | 37 | */ |
| 38 | 38 | function determine_source_lien_objet($a, $b, $c) { |
| 39 | - $table_source = $objet_lien = $objet = $id_objet = null; |
|
| 40 | - // auteurs, article, 23 : |
|
| 41 | - // associer des auteurs à l'article 23, sur la table pivot spip_auteurs_liens |
|
| 42 | - if (is_numeric($c) and !is_numeric($b)) { |
|
| 43 | - $table_source = table_objet($a); |
|
| 44 | - $objet_lien = objet_type($a); |
|
| 45 | - $objet = objet_type($b); |
|
| 46 | - $id_objet = $c; |
|
| 47 | - } |
|
| 48 | - // article, 23, auteurs |
|
| 49 | - // associer des auteurs à l'article 23, sur la table pivot spip_articles_liens |
|
| 50 | - if (is_numeric($b) and !is_numeric($c)) { |
|
| 51 | - $table_source = table_objet($c); |
|
| 52 | - $objet_lien = objet_type($a); |
|
| 53 | - $objet = objet_type($a); |
|
| 54 | - $id_objet = $b; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - return [$table_source, $objet, $id_objet, $objet_lien]; |
|
| 39 | + $table_source = $objet_lien = $objet = $id_objet = null; |
|
| 40 | + // auteurs, article, 23 : |
|
| 41 | + // associer des auteurs à l'article 23, sur la table pivot spip_auteurs_liens |
|
| 42 | + if (is_numeric($c) and !is_numeric($b)) { |
|
| 43 | + $table_source = table_objet($a); |
|
| 44 | + $objet_lien = objet_type($a); |
|
| 45 | + $objet = objet_type($b); |
|
| 46 | + $id_objet = $c; |
|
| 47 | + } |
|
| 48 | + // article, 23, auteurs |
|
| 49 | + // associer des auteurs à l'article 23, sur la table pivot spip_articles_liens |
|
| 50 | + if (is_numeric($b) and !is_numeric($c)) { |
|
| 51 | + $table_source = table_objet($c); |
|
| 52 | + $objet_lien = objet_type($a); |
|
| 53 | + $objet = objet_type($a); |
|
| 54 | + $id_objet = $b; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + return [$table_source, $objet, $id_objet, $objet_lien]; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | /** |
@@ -80,93 +80,93 @@ discard block |
||
| 80 | 80 | */ |
| 81 | 81 | function formulaires_editer_liens_charger_dist($a, $b, $c, $options = []) { |
| 82 | 82 | |
| 83 | - // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 84 | - if (!is_array($options)) { |
|
| 85 | - $options = ['editable' => $options]; |
|
| 86 | - } elseif (!isset($options['editable'])) { |
|
| 87 | - $options['editable'] = true; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $editable = $options['editable']; |
|
| 91 | - |
|
| 92 | - [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 93 | - if (!$table_source or !$objet or !$objet_lien or !$id_objet) { |
|
| 94 | - return false; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - $objet_source = objet_type($table_source); |
|
| 98 | - $table_sql_source = table_objet_sql($objet_source); |
|
| 99 | - |
|
| 100 | - // verifier existence de la table xxx_liens |
|
| 101 | - include_spip('action/editer_liens'); |
|
| 102 | - if (!objet_associable($objet_lien)) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument |
|
| 107 | - include_spip('inc/autoriser'); |
|
| 108 | - $editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet) |
|
| 109 | - and autoriser('modifier', $objet, $id_objet)); |
|
| 110 | - |
|
| 111 | - if ( |
|
| 112 | - !$editable and !count(objet_trouver_liens( |
|
| 113 | - [$objet_lien => '*'], |
|
| 114 | - [($objet_lien == $objet_source ? $objet : $objet_source) => $id_objet] |
|
| 115 | - )) |
|
| 116 | - ) { |
|
| 117 | - return false; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // squelettes de vue et de d'association |
|
| 121 | - // ils sont différents si des rôles sont définis. |
|
| 122 | - $skel_vue = $table_source . '_lies'; |
|
| 123 | - $skel_ajout = $table_source . '_associer'; |
|
| 124 | - |
|
| 125 | - // description des roles |
|
| 126 | - include_spip('inc/roles'); |
|
| 127 | - if ($roles = roles_presents($objet_source, $objet)) { |
|
| 128 | - // on demande de nouveaux squelettes en conséquence |
|
| 129 | - $skel_vue = $table_source . '_roles_lies'; |
|
| 130 | - $skel_ajout = $table_source . '_roles_associer'; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - $oups = ''; |
|
| 134 | - if ($editable) { |
|
| 135 | - $oups = _request('_oups') ?? ''; |
|
| 136 | - if ($oups) { |
|
| 137 | - if (json_decode(base64_decode($oups, true))) { |
|
| 138 | - // on est bon, rien a faire |
|
| 139 | - } else { |
|
| 140 | - $oups = ''; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - $valeurs = [ |
|
| 145 | - 'id' => "$table_source-$objet-$id_objet-$objet_lien", // identifiant unique pour les id du form |
|
| 146 | - '_vue_liee' => $skel_vue, |
|
| 147 | - '_vue_ajout' => $skel_ajout, |
|
| 148 | - '_objet_lien' => $objet_lien, |
|
| 149 | - 'id_lien_ajoute' => _request('id_lien_ajoute'), |
|
| 150 | - 'objet' => $objet, |
|
| 151 | - 'id_objet' => $id_objet, |
|
| 152 | - 'objet_source' => $objet_source, |
|
| 153 | - 'table_source' => $table_source, |
|
| 154 | - 'recherche' => '', |
|
| 155 | - 'visible' => 0, |
|
| 156 | - 'ajouter_lien' => '', |
|
| 157 | - 'supprimer_lien' => '', |
|
| 158 | - 'qualifier_lien' => '', |
|
| 159 | - 'ordonner_lien' => '', |
|
| 160 | - 'desordonner_liens' => '', |
|
| 161 | - '_roles' => $roles, # description des roles |
|
| 162 | - '_oups' => entites_html($oups), |
|
| 163 | - 'editable' => $editable, |
|
| 164 | - ]; |
|
| 165 | - |
|
| 166 | - // les options non definies dans $valeurs sont passees telles quelles au formulaire html |
|
| 167 | - $valeurs = array_merge($options, $valeurs); |
|
| 168 | - |
|
| 169 | - return $valeurs; |
|
| 83 | + // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 84 | + if (!is_array($options)) { |
|
| 85 | + $options = ['editable' => $options]; |
|
| 86 | + } elseif (!isset($options['editable'])) { |
|
| 87 | + $options['editable'] = true; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $editable = $options['editable']; |
|
| 91 | + |
|
| 92 | + [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 93 | + if (!$table_source or !$objet or !$objet_lien or !$id_objet) { |
|
| 94 | + return false; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + $objet_source = objet_type($table_source); |
|
| 98 | + $table_sql_source = table_objet_sql($objet_source); |
|
| 99 | + |
|
| 100 | + // verifier existence de la table xxx_liens |
|
| 101 | + include_spip('action/editer_liens'); |
|
| 102 | + if (!objet_associable($objet_lien)) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // L'éditabilité :) est définie par un test permanent (par exemple "associermots") ET le 4ème argument |
|
| 107 | + include_spip('inc/autoriser'); |
|
| 108 | + $editable = ($editable and autoriser('associer' . $table_source, $objet, $id_objet) |
|
| 109 | + and autoriser('modifier', $objet, $id_objet)); |
|
| 110 | + |
|
| 111 | + if ( |
|
| 112 | + !$editable and !count(objet_trouver_liens( |
|
| 113 | + [$objet_lien => '*'], |
|
| 114 | + [($objet_lien == $objet_source ? $objet : $objet_source) => $id_objet] |
|
| 115 | + )) |
|
| 116 | + ) { |
|
| 117 | + return false; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // squelettes de vue et de d'association |
|
| 121 | + // ils sont différents si des rôles sont définis. |
|
| 122 | + $skel_vue = $table_source . '_lies'; |
|
| 123 | + $skel_ajout = $table_source . '_associer'; |
|
| 124 | + |
|
| 125 | + // description des roles |
|
| 126 | + include_spip('inc/roles'); |
|
| 127 | + if ($roles = roles_presents($objet_source, $objet)) { |
|
| 128 | + // on demande de nouveaux squelettes en conséquence |
|
| 129 | + $skel_vue = $table_source . '_roles_lies'; |
|
| 130 | + $skel_ajout = $table_source . '_roles_associer'; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + $oups = ''; |
|
| 134 | + if ($editable) { |
|
| 135 | + $oups = _request('_oups') ?? ''; |
|
| 136 | + if ($oups) { |
|
| 137 | + if (json_decode(base64_decode($oups, true))) { |
|
| 138 | + // on est bon, rien a faire |
|
| 139 | + } else { |
|
| 140 | + $oups = ''; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + $valeurs = [ |
|
| 145 | + 'id' => "$table_source-$objet-$id_objet-$objet_lien", // identifiant unique pour les id du form |
|
| 146 | + '_vue_liee' => $skel_vue, |
|
| 147 | + '_vue_ajout' => $skel_ajout, |
|
| 148 | + '_objet_lien' => $objet_lien, |
|
| 149 | + 'id_lien_ajoute' => _request('id_lien_ajoute'), |
|
| 150 | + 'objet' => $objet, |
|
| 151 | + 'id_objet' => $id_objet, |
|
| 152 | + 'objet_source' => $objet_source, |
|
| 153 | + 'table_source' => $table_source, |
|
| 154 | + 'recherche' => '', |
|
| 155 | + 'visible' => 0, |
|
| 156 | + 'ajouter_lien' => '', |
|
| 157 | + 'supprimer_lien' => '', |
|
| 158 | + 'qualifier_lien' => '', |
|
| 159 | + 'ordonner_lien' => '', |
|
| 160 | + 'desordonner_liens' => '', |
|
| 161 | + '_roles' => $roles, # description des roles |
|
| 162 | + '_oups' => entites_html($oups), |
|
| 163 | + 'editable' => $editable, |
|
| 164 | + ]; |
|
| 165 | + |
|
| 166 | + // les options non definies dans $valeurs sont passees telles quelles au formulaire html |
|
| 167 | + $valeurs = array_merge($options, $valeurs); |
|
| 168 | + |
|
| 169 | + return $valeurs; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | /** |
@@ -210,165 +210,165 @@ discard block |
||
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | 212 | function formulaires_editer_liens_traiter_dist($a, $b, $c, $options = []) { |
| 213 | - // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 214 | - if (!is_array($options)) { |
|
| 215 | - $options = ['editable' => $options]; |
|
| 216 | - } elseif (!isset($options['editable'])) { |
|
| 217 | - $options['editable'] = true; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $editable = $options['editable']; |
|
| 221 | - |
|
| 222 | - $res = ['editable' => $editable ? true : false]; |
|
| 223 | - [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 224 | - if (!$table_source or !$objet or !$objet_lien) { |
|
| 225 | - return $res; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - |
|
| 229 | - if (_request('tout_voir')) { |
|
| 230 | - set_request('recherche', ''); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - include_spip('inc/autoriser'); |
|
| 234 | - if (autoriser('modifier', $objet, $id_objet)) { |
|
| 235 | - // annuler les suppressions du coup d'avant ! |
|
| 236 | - if ( |
|
| 237 | - _request('annuler_oups') |
|
| 238 | - and $oups = _request('_oups') |
|
| 239 | - and $oups = base64_decode($oups, true) |
|
| 240 | - and $oups = json_decode($oups, true) |
|
| 241 | - ) { |
|
| 242 | - if ($oups_objets = charger_fonction("editer_liens_oups_{$table_source}_{$objet}_{$objet_lien}", 'action', true)) { |
|
| 243 | - $oups_objets($oups); |
|
| 244 | - } else { |
|
| 245 | - $objet_source = objet_type($table_source); |
|
| 246 | - include_spip('action/editer_liens'); |
|
| 247 | - foreach ($oups as $oup) { |
|
| 248 | - if ($objet_lien == $objet_source) { |
|
| 249 | - objet_associer([$objet_source => $oup[$objet_source]], [$objet => $oup[$objet]], $oup); |
|
| 250 | - } else { |
|
| 251 | - objet_associer([$objet => $oup[$objet]], [$objet_source => $oup[$objet_source]], $oup); |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - # oups ne persiste que pour la derniere action, si suppression |
|
| 256 | - set_request('_oups'); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $supprimer = _request('supprimer_lien'); |
|
| 260 | - $ajouter = _request('ajouter_lien'); |
|
| 261 | - $ordonner = _request('ordonner_lien'); |
|
| 262 | - |
|
| 263 | - if (_request('desordonner_liens')) { |
|
| 264 | - include_spip('action/editer_liens'); |
|
| 265 | - objet_qualifier_liens([$objet_lien => '*'], [$objet => $id_objet], ['rang_lien' => 0]); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - // il est possible de preciser dans une seule variable un remplacement : |
|
| 269 | - // remplacer_lien[old][new] |
|
| 270 | - if ($remplacer = _request('remplacer_lien')) { |
|
| 271 | - foreach ($remplacer as $k => $v) { |
|
| 272 | - if ($old = lien_verifier_action($k, '')) { |
|
| 273 | - foreach (is_array($v) ? $v : [$v] as $kn => $vn) { |
|
| 274 | - if ($new = lien_verifier_action($kn, $vn)) { |
|
| 275 | - $supprimer[$old] = 'x'; |
|
| 276 | - $ajouter[$new] = '+'; |
|
| 277 | - } |
|
| 278 | - } |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - if ($supprimer) { |
|
| 284 | - if ( |
|
| 285 | - $supprimer_objets = charger_fonction( |
|
| 286 | - "editer_liens_supprimer_{$table_source}_{$objet}_{$objet_lien}", |
|
| 287 | - 'action', |
|
| 288 | - true |
|
| 289 | - ) |
|
| 290 | - ) { |
|
| 291 | - $oups = $supprimer_objets($supprimer); |
|
| 292 | - } else { |
|
| 293 | - include_spip('action/editer_liens'); |
|
| 294 | - $oups = []; |
|
| 295 | - |
|
| 296 | - foreach ($supprimer as $k => $v) { |
|
| 297 | - if ($lien = lien_verifier_action($k, $v)) { |
|
| 298 | - $lien = explode('-', $lien); |
|
| 299 | - [$objet_source, $ids, $objet_lie, $idl, $role] = array_pad($lien, 5, null); |
|
| 300 | - // appliquer une condition sur le rôle si défini ('*' pour tous les roles) |
|
| 301 | - $cond = (!is_null($role) ? ['role' => $role] : []); |
|
| 302 | - if ($objet_lien == $objet_source) { |
|
| 303 | - $oups = array_merge( |
|
| 304 | - $oups, |
|
| 305 | - objet_trouver_liens([$objet_source => $ids], [$objet_lie => $idl], $cond) |
|
| 306 | - ); |
|
| 307 | - objet_dissocier([$objet_source => $ids], [$objet_lie => $idl], $cond); |
|
| 308 | - } else { |
|
| 309 | - $oups = array_merge( |
|
| 310 | - $oups, |
|
| 311 | - objet_trouver_liens([$objet_lie => $idl], [$objet_source => $ids], $cond) |
|
| 312 | - ); |
|
| 313 | - objet_dissocier([$objet_lie => $idl], [$objet_source => $ids], $cond); |
|
| 314 | - } |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - set_request('_oups', $oups ? base64_encode(json_encode($oups)) : null); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - if ($ajouter) { |
|
| 322 | - if ( |
|
| 323 | - $ajouter_objets = charger_fonction("editer_liens_ajouter_{$table_source}_{$objet}_{$objet_lien}", 'action', true) |
|
| 324 | - ) { |
|
| 325 | - $ajout_ok = $ajouter_objets($ajouter); |
|
| 326 | - } else { |
|
| 327 | - $ajout_ok = false; |
|
| 328 | - include_spip('action/editer_liens'); |
|
| 329 | - foreach ($ajouter as $k => $v) { |
|
| 330 | - if ($lien = lien_verifier_action($k, $v)) { |
|
| 331 | - $ajout_ok = true; |
|
| 332 | - [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 333 | - $qualifs = lien_retrouver_qualif($objet_lien, $lien); |
|
| 334 | - if ($objet_lien == $objet1) { |
|
| 335 | - lien_ajouter_liaisons($objet1, $ids, $objet2, $idl, $qualifs); |
|
| 336 | - } else { |
|
| 337 | - lien_ajouter_liaisons($objet2, $idl, $objet1, $ids, $qualifs); |
|
| 338 | - } |
|
| 339 | - set_request('id_lien_ajoute', $ids); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - } |
|
| 343 | - # oups ne persiste que pour la derniere action, si suppression |
|
| 344 | - # une suppression suivie d'un ajout dans le meme hit est un remplacement |
|
| 345 | - # non annulable ! |
|
| 346 | - if ($ajout_ok) { |
|
| 347 | - set_request('_oups'); |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - if ($ordonner) { |
|
| 352 | - include_spip('action/editer_liens'); |
|
| 353 | - foreach ($ordonner as $k => $rang_lien) { |
|
| 354 | - if ($lien = lien_verifier_action($k, '')) { |
|
| 355 | - [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 356 | - $qualif = ['rang_lien' => $rang_lien]; |
|
| 357 | - |
|
| 358 | - if ($objet_lien == $objet1) { |
|
| 359 | - objet_qualifier_liens([$objet1 => $ids], [$objet2 => $idl], $qualif); |
|
| 360 | - } else { |
|
| 361 | - objet_qualifier_liens([$objet2 => $idl], [$objet1 => $ids], $qualif); |
|
| 362 | - } |
|
| 363 | - set_request('id_lien_ajoute', $ids); |
|
| 364 | - set_request('_oups'); |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - |
|
| 371 | - return $res; |
|
| 213 | + // compat avec ancienne signature ou le 4eme argument est $editable |
|
| 214 | + if (!is_array($options)) { |
|
| 215 | + $options = ['editable' => $options]; |
|
| 216 | + } elseif (!isset($options['editable'])) { |
|
| 217 | + $options['editable'] = true; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $editable = $options['editable']; |
|
| 221 | + |
|
| 222 | + $res = ['editable' => $editable ? true : false]; |
|
| 223 | + [$table_source, $objet, $id_objet, $objet_lien] = determine_source_lien_objet($a, $b, $c); |
|
| 224 | + if (!$table_source or !$objet or !$objet_lien) { |
|
| 225 | + return $res; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + |
|
| 229 | + if (_request('tout_voir')) { |
|
| 230 | + set_request('recherche', ''); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + include_spip('inc/autoriser'); |
|
| 234 | + if (autoriser('modifier', $objet, $id_objet)) { |
|
| 235 | + // annuler les suppressions du coup d'avant ! |
|
| 236 | + if ( |
|
| 237 | + _request('annuler_oups') |
|
| 238 | + and $oups = _request('_oups') |
|
| 239 | + and $oups = base64_decode($oups, true) |
|
| 240 | + and $oups = json_decode($oups, true) |
|
| 241 | + ) { |
|
| 242 | + if ($oups_objets = charger_fonction("editer_liens_oups_{$table_source}_{$objet}_{$objet_lien}", 'action', true)) { |
|
| 243 | + $oups_objets($oups); |
|
| 244 | + } else { |
|
| 245 | + $objet_source = objet_type($table_source); |
|
| 246 | + include_spip('action/editer_liens'); |
|
| 247 | + foreach ($oups as $oup) { |
|
| 248 | + if ($objet_lien == $objet_source) { |
|
| 249 | + objet_associer([$objet_source => $oup[$objet_source]], [$objet => $oup[$objet]], $oup); |
|
| 250 | + } else { |
|
| 251 | + objet_associer([$objet => $oup[$objet]], [$objet_source => $oup[$objet_source]], $oup); |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + # oups ne persiste que pour la derniere action, si suppression |
|
| 256 | + set_request('_oups'); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $supprimer = _request('supprimer_lien'); |
|
| 260 | + $ajouter = _request('ajouter_lien'); |
|
| 261 | + $ordonner = _request('ordonner_lien'); |
|
| 262 | + |
|
| 263 | + if (_request('desordonner_liens')) { |
|
| 264 | + include_spip('action/editer_liens'); |
|
| 265 | + objet_qualifier_liens([$objet_lien => '*'], [$objet => $id_objet], ['rang_lien' => 0]); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + // il est possible de preciser dans une seule variable un remplacement : |
|
| 269 | + // remplacer_lien[old][new] |
|
| 270 | + if ($remplacer = _request('remplacer_lien')) { |
|
| 271 | + foreach ($remplacer as $k => $v) { |
|
| 272 | + if ($old = lien_verifier_action($k, '')) { |
|
| 273 | + foreach (is_array($v) ? $v : [$v] as $kn => $vn) { |
|
| 274 | + if ($new = lien_verifier_action($kn, $vn)) { |
|
| 275 | + $supprimer[$old] = 'x'; |
|
| 276 | + $ajouter[$new] = '+'; |
|
| 277 | + } |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + if ($supprimer) { |
|
| 284 | + if ( |
|
| 285 | + $supprimer_objets = charger_fonction( |
|
| 286 | + "editer_liens_supprimer_{$table_source}_{$objet}_{$objet_lien}", |
|
| 287 | + 'action', |
|
| 288 | + true |
|
| 289 | + ) |
|
| 290 | + ) { |
|
| 291 | + $oups = $supprimer_objets($supprimer); |
|
| 292 | + } else { |
|
| 293 | + include_spip('action/editer_liens'); |
|
| 294 | + $oups = []; |
|
| 295 | + |
|
| 296 | + foreach ($supprimer as $k => $v) { |
|
| 297 | + if ($lien = lien_verifier_action($k, $v)) { |
|
| 298 | + $lien = explode('-', $lien); |
|
| 299 | + [$objet_source, $ids, $objet_lie, $idl, $role] = array_pad($lien, 5, null); |
|
| 300 | + // appliquer une condition sur le rôle si défini ('*' pour tous les roles) |
|
| 301 | + $cond = (!is_null($role) ? ['role' => $role] : []); |
|
| 302 | + if ($objet_lien == $objet_source) { |
|
| 303 | + $oups = array_merge( |
|
| 304 | + $oups, |
|
| 305 | + objet_trouver_liens([$objet_source => $ids], [$objet_lie => $idl], $cond) |
|
| 306 | + ); |
|
| 307 | + objet_dissocier([$objet_source => $ids], [$objet_lie => $idl], $cond); |
|
| 308 | + } else { |
|
| 309 | + $oups = array_merge( |
|
| 310 | + $oups, |
|
| 311 | + objet_trouver_liens([$objet_lie => $idl], [$objet_source => $ids], $cond) |
|
| 312 | + ); |
|
| 313 | + objet_dissocier([$objet_lie => $idl], [$objet_source => $ids], $cond); |
|
| 314 | + } |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + set_request('_oups', $oups ? base64_encode(json_encode($oups)) : null); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + if ($ajouter) { |
|
| 322 | + if ( |
|
| 323 | + $ajouter_objets = charger_fonction("editer_liens_ajouter_{$table_source}_{$objet}_{$objet_lien}", 'action', true) |
|
| 324 | + ) { |
|
| 325 | + $ajout_ok = $ajouter_objets($ajouter); |
|
| 326 | + } else { |
|
| 327 | + $ajout_ok = false; |
|
| 328 | + include_spip('action/editer_liens'); |
|
| 329 | + foreach ($ajouter as $k => $v) { |
|
| 330 | + if ($lien = lien_verifier_action($k, $v)) { |
|
| 331 | + $ajout_ok = true; |
|
| 332 | + [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 333 | + $qualifs = lien_retrouver_qualif($objet_lien, $lien); |
|
| 334 | + if ($objet_lien == $objet1) { |
|
| 335 | + lien_ajouter_liaisons($objet1, $ids, $objet2, $idl, $qualifs); |
|
| 336 | + } else { |
|
| 337 | + lien_ajouter_liaisons($objet2, $idl, $objet1, $ids, $qualifs); |
|
| 338 | + } |
|
| 339 | + set_request('id_lien_ajoute', $ids); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + } |
|
| 343 | + # oups ne persiste que pour la derniere action, si suppression |
|
| 344 | + # une suppression suivie d'un ajout dans le meme hit est un remplacement |
|
| 345 | + # non annulable ! |
|
| 346 | + if ($ajout_ok) { |
|
| 347 | + set_request('_oups'); |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + if ($ordonner) { |
|
| 352 | + include_spip('action/editer_liens'); |
|
| 353 | + foreach ($ordonner as $k => $rang_lien) { |
|
| 354 | + if ($lien = lien_verifier_action($k, '')) { |
|
| 355 | + [$objet1, $ids, $objet2, $idl] = explode('-', $lien); |
|
| 356 | + $qualif = ['rang_lien' => $rang_lien]; |
|
| 357 | + |
|
| 358 | + if ($objet_lien == $objet1) { |
|
| 359 | + objet_qualifier_liens([$objet1 => $ids], [$objet2 => $idl], $qualif); |
|
| 360 | + } else { |
|
| 361 | + objet_qualifier_liens([$objet2 => $idl], [$objet1 => $ids], $qualif); |
|
| 362 | + } |
|
| 363 | + set_request('id_lien_ajoute', $ids); |
|
| 364 | + set_request('_oups'); |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + |
|
| 371 | + return $res; |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
@@ -391,24 +391,24 @@ discard block |
||
| 391 | 391 | * @return string Action demandée si trouvée, sinon '' |
| 392 | 392 | */ |
| 393 | 393 | function lien_verifier_action($k, $v) { |
| 394 | - $action = ''; |
|
| 395 | - if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $k)) { |
|
| 396 | - $action = $k; |
|
| 397 | - } |
|
| 398 | - if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $v)) { |
|
| 399 | - if (is_numeric($k)) { |
|
| 400 | - $action = $v; |
|
| 401 | - } |
|
| 402 | - if (_request($k)) { |
|
| 403 | - $action = $v; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - // ajout un role null fictif (plus pratique) si pas défini |
|
| 407 | - if ($action and count(explode('-', $action)) == 4) { |
|
| 408 | - $action .= '-'; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - return $action; |
|
| 394 | + $action = ''; |
|
| 395 | + if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $k)) { |
|
| 396 | + $action = $k; |
|
| 397 | + } |
|
| 398 | + if (preg_match(',^\w+-[\w*]+-[\w*]+-[\w*]+(-[\w*])?,', $v)) { |
|
| 399 | + if (is_numeric($k)) { |
|
| 400 | + $action = $v; |
|
| 401 | + } |
|
| 402 | + if (_request($k)) { |
|
| 403 | + $action = $v; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + // ajout un role null fictif (plus pratique) si pas défini |
|
| 407 | + if ($action and count(explode('-', $action)) == 4) { |
|
| 408 | + $action .= '-'; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + return $action; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
@@ -424,66 +424,66 @@ discard block |
||
| 424 | 424 | * Liste des qualifs pour chaque lien. Tableau vide s'il n'y en a pas. |
| 425 | 425 | **/ |
| 426 | 426 | function lien_retrouver_qualif($objet_lien, $lien) { |
| 427 | - // un role est défini dans la liaison |
|
| 428 | - $defs = explode('-', $lien); |
|
| 429 | - [$objet1, , $objet2, , $role] = array_pad($defs, 5, null); |
|
| 430 | - if ($objet_lien == $objet1) { |
|
| 431 | - $colonne_role = roles_colonne($objet1, $objet2); |
|
| 432 | - } else { |
|
| 433 | - $colonne_role = roles_colonne($objet2, $objet1); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - // cas ou le role est defini en 5e argument de l'action sur le lien (suppression, ajout rapide sans autre attribut) |
|
| 437 | - if ($role) { |
|
| 438 | - return [ |
|
| 439 | - // un seul lien avec ce role |
|
| 440 | - [$colonne_role => $role] |
|
| 441 | - ]; |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // retrouver les rôles postés pour cette liaison, s'il y en a. |
|
| 445 | - $qualifier_lien = _request('qualifier_lien'); |
|
| 446 | - if (!$qualifier_lien or !is_array($qualifier_lien)) { |
|
| 447 | - return []; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // pas avec l'action complete (incluant le role) |
|
| 451 | - $qualif = []; |
|
| 452 | - if ( |
|
| 453 | - (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) |
|
| 454 | - and count($defs) == 5 |
|
| 455 | - ) { |
|
| 456 | - // on tente avec l'action sans le role |
|
| 457 | - array_pop($defs); |
|
| 458 | - $lien = implode('-', $defs); |
|
| 459 | - if (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) { |
|
| 460 | - $qualif = []; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // $qualif de la forme array(role=>array(...),valeur=>array(...),....) |
|
| 465 | - // on le reforme en array(array(role=>..,valeur=>..,..),array(role=>..,valeur=>..,..),...) |
|
| 466 | - $qualifs = []; |
|
| 467 | - while (is_countable($qualif) ? count($qualif) : 0) { |
|
| 468 | - $q = []; |
|
| 469 | - foreach ($qualif as $att => $values) { |
|
| 470 | - if (is_array($values)) { |
|
| 471 | - $q[$att] = array_shift($qualif[$att]); |
|
| 472 | - if (!(is_countable($qualif[$att]) ? count($qualif[$att]) : 0)) { |
|
| 473 | - unset($qualif[$att]); |
|
| 474 | - } |
|
| 475 | - } else { |
|
| 476 | - $q[$att] = $values; |
|
| 477 | - unset($qualif[$att]); |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - // pas de rôle vide |
|
| 481 | - if (!$colonne_role or !isset($q[$colonne_role]) or $q[$colonne_role]) { |
|
| 482 | - $qualifs[] = $q; |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return $qualifs; |
|
| 427 | + // un role est défini dans la liaison |
|
| 428 | + $defs = explode('-', $lien); |
|
| 429 | + [$objet1, , $objet2, , $role] = array_pad($defs, 5, null); |
|
| 430 | + if ($objet_lien == $objet1) { |
|
| 431 | + $colonne_role = roles_colonne($objet1, $objet2); |
|
| 432 | + } else { |
|
| 433 | + $colonne_role = roles_colonne($objet2, $objet1); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + // cas ou le role est defini en 5e argument de l'action sur le lien (suppression, ajout rapide sans autre attribut) |
|
| 437 | + if ($role) { |
|
| 438 | + return [ |
|
| 439 | + // un seul lien avec ce role |
|
| 440 | + [$colonne_role => $role] |
|
| 441 | + ]; |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // retrouver les rôles postés pour cette liaison, s'il y en a. |
|
| 445 | + $qualifier_lien = _request('qualifier_lien'); |
|
| 446 | + if (!$qualifier_lien or !is_array($qualifier_lien)) { |
|
| 447 | + return []; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // pas avec l'action complete (incluant le role) |
|
| 451 | + $qualif = []; |
|
| 452 | + if ( |
|
| 453 | + (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) |
|
| 454 | + and count($defs) == 5 |
|
| 455 | + ) { |
|
| 456 | + // on tente avec l'action sans le role |
|
| 457 | + array_pop($defs); |
|
| 458 | + $lien = implode('-', $defs); |
|
| 459 | + if (!isset($qualifier_lien[$lien]) or !$qualif = $qualifier_lien[$lien]) { |
|
| 460 | + $qualif = []; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // $qualif de la forme array(role=>array(...),valeur=>array(...),....) |
|
| 465 | + // on le reforme en array(array(role=>..,valeur=>..,..),array(role=>..,valeur=>..,..),...) |
|
| 466 | + $qualifs = []; |
|
| 467 | + while (is_countable($qualif) ? count($qualif) : 0) { |
|
| 468 | + $q = []; |
|
| 469 | + foreach ($qualif as $att => $values) { |
|
| 470 | + if (is_array($values)) { |
|
| 471 | + $q[$att] = array_shift($qualif[$att]); |
|
| 472 | + if (!(is_countable($qualif[$att]) ? count($qualif[$att]) : 0)) { |
|
| 473 | + unset($qualif[$att]); |
|
| 474 | + } |
|
| 475 | + } else { |
|
| 476 | + $q[$att] = $values; |
|
| 477 | + unset($qualif[$att]); |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + // pas de rôle vide |
|
| 481 | + if (!$colonne_role or !isset($q[$colonne_role]) or $q[$colonne_role]) { |
|
| 482 | + $qualifs[] = $q; |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return $qualifs; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | /** |
@@ -502,12 +502,12 @@ discard block |
||
| 502 | 502 | **/ |
| 503 | 503 | function lien_ajouter_liaisons($objet_source, $ids, $objet_lien, $idl, $qualifs) { |
| 504 | 504 | |
| 505 | - // retrouver la colonne de roles s'il y en a a lier |
|
| 506 | - if (is_array($qualifs) and count($qualifs)) { |
|
| 507 | - foreach ($qualifs as $qualif) { |
|
| 508 | - objet_associer([$objet_source => $ids], [$objet_lien => $idl], $qualif); |
|
| 509 | - } |
|
| 510 | - } else { |
|
| 511 | - objet_associer([$objet_source => $ids], [$objet_lien => $idl]); |
|
| 512 | - } |
|
| 505 | + // retrouver la colonne de roles s'il y en a a lier |
|
| 506 | + if (is_array($qualifs) and count($qualifs)) { |
|
| 507 | + foreach ($qualifs as $qualif) { |
|
| 508 | + objet_associer([$objet_source => $ids], [$objet_lien => $idl], $qualif); |
|
| 509 | + } |
|
| 510 | + } else { |
|
| 511 | + objet_associer([$objet_source => $ids], [$objet_lien => $idl]); |
|
| 512 | + } |
|
| 513 | 513 | } |
@@ -15,11 +15,11 @@ discard block |
||
| 15 | 15 | * Test utilisateur |
| 16 | 16 | */ |
| 17 | 17 | if (isset($_GET['test_ecran_securite'])) { |
| 18 | - $ecran_securite_raison = 'test ' . _ECRAN_SECURITE; |
|
| 18 | + $ecran_securite_raison = 'test ' . _ECRAN_SECURITE; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | if (file_exists($f = __DIR__ . DIRECTORY_SEPARATOR . 'ecran_securite_options.php')) { |
| 22 | - include ($f); |
|
| 22 | + include ($f); |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /* |
@@ -29,222 +29,222 @@ discard block |
||
| 29 | 29 | * le load depasse ECRAN_SECURITE_LOAD) |
| 30 | 30 | */ |
| 31 | 31 | if (!defined('_IS_BOT') and isset($_GET['var_isbot'])) { |
| 32 | - define('_IS_BOT', $_GET['var_isbot'] ? true : false); |
|
| 32 | + define('_IS_BOT', $_GET['var_isbot'] ? true : false); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /* |
| 36 | 36 | * Détecteur de robot d'indexation |
| 37 | 37 | */ |
| 38 | 38 | if (!defined('_IS_BOT')) { |
| 39 | - define( |
|
| 40 | - '_IS_BOT', |
|
| 41 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 42 | - and preg_match( |
|
| 43 | - ',' |
|
| 44 | - . implode('|', array( |
|
| 45 | - // mots generiques |
|
| 46 | - 'bot', |
|
| 47 | - 'slurp', |
|
| 48 | - 'crawler', |
|
| 49 | - 'crwlr', |
|
| 50 | - 'java', |
|
| 51 | - 'monitoring', |
|
| 52 | - 'spider', |
|
| 53 | - 'webvac', |
|
| 54 | - 'yandex', |
|
| 55 | - 'MSIE 6\.0', // botnet 99,9% du temps |
|
| 56 | - // UA plus cibles |
|
| 57 | - '200please', |
|
| 58 | - '80legs', |
|
| 59 | - 'a6-indexer', |
|
| 60 | - 'aboundex', |
|
| 61 | - 'accoona', |
|
| 62 | - 'acrylicapps', |
|
| 63 | - 'addthis', |
|
| 64 | - 'adressendeutschland', |
|
| 65 | - 'alexa', |
|
| 66 | - 'altavista', |
|
| 67 | - 'analyticsseo', |
|
| 68 | - 'antennapod', |
|
| 69 | - 'arachnys', |
|
| 70 | - 'archive', |
|
| 71 | - 'argclrint', |
|
| 72 | - 'aspseek', |
|
| 73 | - 'baidu', |
|
| 74 | - 'begunadvertising', |
|
| 75 | - 'bing', |
|
| 76 | - 'bloglines', |
|
| 77 | - 'buck', |
|
| 78 | - 'browsershots', |
|
| 79 | - 'bubing', |
|
| 80 | - 'butterfly', |
|
| 81 | - 'changedetection', |
|
| 82 | - 'charlotte', |
|
| 83 | - 'chilkat', |
|
| 84 | - 'china', |
|
| 85 | - 'coccoc', |
|
| 86 | - 'crowsnest', |
|
| 87 | - 'dataminr', |
|
| 88 | - 'daumoa', |
|
| 89 | - 'dlvr\.it', |
|
| 90 | - 'dlweb', |
|
| 91 | - 'drupal', |
|
| 92 | - 'ec2linkfinder', |
|
| 93 | - 'eset\.com', |
|
| 94 | - 'estyle', |
|
| 95 | - 'exalead', |
|
| 96 | - 'ezooms', |
|
| 97 | - 'facebookexternalhit', |
|
| 98 | - 'facebookplatform', |
|
| 99 | - 'fairshare', |
|
| 100 | - 'feedfetcher', |
|
| 101 | - 'feedfetcher-google', |
|
| 102 | - 'feedly', |
|
| 103 | - 'fetch', |
|
| 104 | - 'flipboardproxy', |
|
| 105 | - 'genieo', |
|
| 106 | - 'google', |
|
| 107 | - 'go-http-client', |
|
| 108 | - 'grapeshot', |
|
| 109 | - 'hatena-useragent', |
|
| 110 | - 'head', |
|
| 111 | - 'hosttracker', |
|
| 112 | - 'hubspot', |
|
| 113 | - 'ia_archiver', |
|
| 114 | - 'ichiro', |
|
| 115 | - 'iltrovatore-setaccio', |
|
| 116 | - 'immediatenet', |
|
| 117 | - 'ina', |
|
| 118 | - 'inoreader', |
|
| 119 | - 'infegyatlas', |
|
| 120 | - 'infohelfer', |
|
| 121 | - 'instapaper', |
|
| 122 | - 'jabse', |
|
| 123 | - 'james', |
|
| 124 | - 'jersey', |
|
| 125 | - 'kumkie', |
|
| 126 | - 'linkdex', |
|
| 127 | - 'linkfluence', |
|
| 128 | - 'linkwalker', |
|
| 129 | - 'litefinder', |
|
| 130 | - 'loadimpactpageanalyzer', |
|
| 131 | - 'ltx71', |
|
| 132 | - 'luminate', |
|
| 133 | - 'lycos', |
|
| 134 | - 'lycosa', |
|
| 135 | - 'mediapartners-google', |
|
| 136 | - 'msai', |
|
| 137 | - 'myapp', |
|
| 138 | - 'nativehost', |
|
| 139 | - 'najdi', |
|
| 140 | - 'netcraftsurveyagent', |
|
| 141 | - 'netestate', |
|
| 142 | - 'netseer', |
|
| 143 | - 'netnewswire', |
|
| 144 | - 'newspaper', |
|
| 145 | - 'newsblur', |
|
| 146 | - 'nuhk', |
|
| 147 | - 'nuzzel', |
|
| 148 | - 'okhttp', |
|
| 149 | - 'otmedia', |
|
| 150 | - 'owlin', |
|
| 151 | - 'owncloud', |
|
| 152 | - 'panscient', |
|
| 153 | - 'paper\.li', |
|
| 154 | - 'parsijoo', |
|
| 155 | - 'protopage', |
|
| 156 | - 'plukkie', |
|
| 157 | - 'proximic', |
|
| 158 | - 'pubsub', |
|
| 159 | - 'python', |
|
| 160 | - 'qirina', |
|
| 161 | - 'qoshe', |
|
| 162 | - 'qualidator', |
|
| 163 | - 'qwantify', |
|
| 164 | - 'rambler', |
|
| 165 | - 'readability', |
|
| 166 | - 'ruby', |
|
| 167 | - 'sbsearch', |
|
| 168 | - 'scoop\.it', |
|
| 169 | - 'scooter', |
|
| 170 | - 'scoutjet', |
|
| 171 | - 'scrapy', |
|
| 172 | - 'scrubby', |
|
| 173 | - 'scrubbybloglines', |
|
| 174 | - 'shareaholic', |
|
| 175 | - 'shopwiki', |
|
| 176 | - 'simplepie', |
|
| 177 | - 'sistrix', |
|
| 178 | - 'sitechecker', |
|
| 179 | - 'siteexplorer', |
|
| 180 | - 'snapshot', |
|
| 181 | - 'sogou', |
|
| 182 | - 'special_archiver', |
|
| 183 | - 'speedy', |
|
| 184 | - 'spinn3r', |
|
| 185 | - 'spreadtrum', |
|
| 186 | - 'steeler', |
|
| 187 | - 'subscriber', |
|
| 188 | - 'suma', |
|
| 189 | - 'superdownloads', |
|
| 190 | - 'svenska-webbsido', |
|
| 191 | - 'teoma', |
|
| 192 | - 'the knowledge AI', |
|
| 193 | - 'thumbshots', |
|
| 194 | - 'tineye', |
|
| 195 | - 'traackr', |
|
| 196 | - 'trendiction', |
|
| 197 | - 'trendsmap', |
|
| 198 | - 'tweetedtimes', |
|
| 199 | - 'tweetmeme', |
|
| 200 | - 'universalfeedparser', |
|
| 201 | - 'uaslinkchecker', |
|
| 202 | - 'undrip', |
|
| 203 | - 'unwindfetchor', |
|
| 204 | - 'upday', |
|
| 205 | - 'vedma', |
|
| 206 | - 'vkshare', |
|
| 207 | - 'vm', |
|
| 208 | - 'wch', |
|
| 209 | - 'webalta', |
|
| 210 | - 'webcookies', |
|
| 211 | - 'webparser', |
|
| 212 | - 'webthumbnail', |
|
| 213 | - 'wesee', |
|
| 214 | - 'wise-guys', |
|
| 215 | - 'woko', |
|
| 216 | - 'wordpress', |
|
| 217 | - 'wotbox', |
|
| 218 | - 'y!j-bri', |
|
| 219 | - 'y!j-bro', |
|
| 220 | - 'y!j-brw', |
|
| 221 | - 'y!j-bsc', |
|
| 222 | - 'yahoo', |
|
| 223 | - 'yahoo!', |
|
| 224 | - 'yahooysmcm', |
|
| 225 | - 'ymobactus', |
|
| 226 | - 'yats', |
|
| 227 | - 'yeti', |
|
| 228 | - 'zeerch' |
|
| 229 | - )) . ',i', |
|
| 230 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 231 | - ) |
|
| 232 | - ); |
|
| 39 | + define( |
|
| 40 | + '_IS_BOT', |
|
| 41 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 42 | + and preg_match( |
|
| 43 | + ',' |
|
| 44 | + . implode('|', array( |
|
| 45 | + // mots generiques |
|
| 46 | + 'bot', |
|
| 47 | + 'slurp', |
|
| 48 | + 'crawler', |
|
| 49 | + 'crwlr', |
|
| 50 | + 'java', |
|
| 51 | + 'monitoring', |
|
| 52 | + 'spider', |
|
| 53 | + 'webvac', |
|
| 54 | + 'yandex', |
|
| 55 | + 'MSIE 6\.0', // botnet 99,9% du temps |
|
| 56 | + // UA plus cibles |
|
| 57 | + '200please', |
|
| 58 | + '80legs', |
|
| 59 | + 'a6-indexer', |
|
| 60 | + 'aboundex', |
|
| 61 | + 'accoona', |
|
| 62 | + 'acrylicapps', |
|
| 63 | + 'addthis', |
|
| 64 | + 'adressendeutschland', |
|
| 65 | + 'alexa', |
|
| 66 | + 'altavista', |
|
| 67 | + 'analyticsseo', |
|
| 68 | + 'antennapod', |
|
| 69 | + 'arachnys', |
|
| 70 | + 'archive', |
|
| 71 | + 'argclrint', |
|
| 72 | + 'aspseek', |
|
| 73 | + 'baidu', |
|
| 74 | + 'begunadvertising', |
|
| 75 | + 'bing', |
|
| 76 | + 'bloglines', |
|
| 77 | + 'buck', |
|
| 78 | + 'browsershots', |
|
| 79 | + 'bubing', |
|
| 80 | + 'butterfly', |
|
| 81 | + 'changedetection', |
|
| 82 | + 'charlotte', |
|
| 83 | + 'chilkat', |
|
| 84 | + 'china', |
|
| 85 | + 'coccoc', |
|
| 86 | + 'crowsnest', |
|
| 87 | + 'dataminr', |
|
| 88 | + 'daumoa', |
|
| 89 | + 'dlvr\.it', |
|
| 90 | + 'dlweb', |
|
| 91 | + 'drupal', |
|
| 92 | + 'ec2linkfinder', |
|
| 93 | + 'eset\.com', |
|
| 94 | + 'estyle', |
|
| 95 | + 'exalead', |
|
| 96 | + 'ezooms', |
|
| 97 | + 'facebookexternalhit', |
|
| 98 | + 'facebookplatform', |
|
| 99 | + 'fairshare', |
|
| 100 | + 'feedfetcher', |
|
| 101 | + 'feedfetcher-google', |
|
| 102 | + 'feedly', |
|
| 103 | + 'fetch', |
|
| 104 | + 'flipboardproxy', |
|
| 105 | + 'genieo', |
|
| 106 | + 'google', |
|
| 107 | + 'go-http-client', |
|
| 108 | + 'grapeshot', |
|
| 109 | + 'hatena-useragent', |
|
| 110 | + 'head', |
|
| 111 | + 'hosttracker', |
|
| 112 | + 'hubspot', |
|
| 113 | + 'ia_archiver', |
|
| 114 | + 'ichiro', |
|
| 115 | + 'iltrovatore-setaccio', |
|
| 116 | + 'immediatenet', |
|
| 117 | + 'ina', |
|
| 118 | + 'inoreader', |
|
| 119 | + 'infegyatlas', |
|
| 120 | + 'infohelfer', |
|
| 121 | + 'instapaper', |
|
| 122 | + 'jabse', |
|
| 123 | + 'james', |
|
| 124 | + 'jersey', |
|
| 125 | + 'kumkie', |
|
| 126 | + 'linkdex', |
|
| 127 | + 'linkfluence', |
|
| 128 | + 'linkwalker', |
|
| 129 | + 'litefinder', |
|
| 130 | + 'loadimpactpageanalyzer', |
|
| 131 | + 'ltx71', |
|
| 132 | + 'luminate', |
|
| 133 | + 'lycos', |
|
| 134 | + 'lycosa', |
|
| 135 | + 'mediapartners-google', |
|
| 136 | + 'msai', |
|
| 137 | + 'myapp', |
|
| 138 | + 'nativehost', |
|
| 139 | + 'najdi', |
|
| 140 | + 'netcraftsurveyagent', |
|
| 141 | + 'netestate', |
|
| 142 | + 'netseer', |
|
| 143 | + 'netnewswire', |
|
| 144 | + 'newspaper', |
|
| 145 | + 'newsblur', |
|
| 146 | + 'nuhk', |
|
| 147 | + 'nuzzel', |
|
| 148 | + 'okhttp', |
|
| 149 | + 'otmedia', |
|
| 150 | + 'owlin', |
|
| 151 | + 'owncloud', |
|
| 152 | + 'panscient', |
|
| 153 | + 'paper\.li', |
|
| 154 | + 'parsijoo', |
|
| 155 | + 'protopage', |
|
| 156 | + 'plukkie', |
|
| 157 | + 'proximic', |
|
| 158 | + 'pubsub', |
|
| 159 | + 'python', |
|
| 160 | + 'qirina', |
|
| 161 | + 'qoshe', |
|
| 162 | + 'qualidator', |
|
| 163 | + 'qwantify', |
|
| 164 | + 'rambler', |
|
| 165 | + 'readability', |
|
| 166 | + 'ruby', |
|
| 167 | + 'sbsearch', |
|
| 168 | + 'scoop\.it', |
|
| 169 | + 'scooter', |
|
| 170 | + 'scoutjet', |
|
| 171 | + 'scrapy', |
|
| 172 | + 'scrubby', |
|
| 173 | + 'scrubbybloglines', |
|
| 174 | + 'shareaholic', |
|
| 175 | + 'shopwiki', |
|
| 176 | + 'simplepie', |
|
| 177 | + 'sistrix', |
|
| 178 | + 'sitechecker', |
|
| 179 | + 'siteexplorer', |
|
| 180 | + 'snapshot', |
|
| 181 | + 'sogou', |
|
| 182 | + 'special_archiver', |
|
| 183 | + 'speedy', |
|
| 184 | + 'spinn3r', |
|
| 185 | + 'spreadtrum', |
|
| 186 | + 'steeler', |
|
| 187 | + 'subscriber', |
|
| 188 | + 'suma', |
|
| 189 | + 'superdownloads', |
|
| 190 | + 'svenska-webbsido', |
|
| 191 | + 'teoma', |
|
| 192 | + 'the knowledge AI', |
|
| 193 | + 'thumbshots', |
|
| 194 | + 'tineye', |
|
| 195 | + 'traackr', |
|
| 196 | + 'trendiction', |
|
| 197 | + 'trendsmap', |
|
| 198 | + 'tweetedtimes', |
|
| 199 | + 'tweetmeme', |
|
| 200 | + 'universalfeedparser', |
|
| 201 | + 'uaslinkchecker', |
|
| 202 | + 'undrip', |
|
| 203 | + 'unwindfetchor', |
|
| 204 | + 'upday', |
|
| 205 | + 'vedma', |
|
| 206 | + 'vkshare', |
|
| 207 | + 'vm', |
|
| 208 | + 'wch', |
|
| 209 | + 'webalta', |
|
| 210 | + 'webcookies', |
|
| 211 | + 'webparser', |
|
| 212 | + 'webthumbnail', |
|
| 213 | + 'wesee', |
|
| 214 | + 'wise-guys', |
|
| 215 | + 'woko', |
|
| 216 | + 'wordpress', |
|
| 217 | + 'wotbox', |
|
| 218 | + 'y!j-bri', |
|
| 219 | + 'y!j-bro', |
|
| 220 | + 'y!j-brw', |
|
| 221 | + 'y!j-bsc', |
|
| 222 | + 'yahoo', |
|
| 223 | + 'yahoo!', |
|
| 224 | + 'yahooysmcm', |
|
| 225 | + 'ymobactus', |
|
| 226 | + 'yats', |
|
| 227 | + 'yeti', |
|
| 228 | + 'zeerch' |
|
| 229 | + )) . ',i', |
|
| 230 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 231 | + ) |
|
| 232 | + ); |
|
| 233 | 233 | } |
| 234 | 234 | if (!defined('_IS_BOT_FRIEND')) { |
| 235 | - define( |
|
| 236 | - '_IS_BOT_FRIEND', |
|
| 237 | - isset($_SERVER['HTTP_USER_AGENT']) |
|
| 238 | - and preg_match( |
|
| 239 | - ',' . implode('|', array( |
|
| 240 | - 'facebookexternalhit', |
|
| 241 | - 'twitterbot', |
|
| 242 | - 'flipboardproxy', |
|
| 243 | - 'wordpress' |
|
| 244 | - )) . ',i', |
|
| 245 | - (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 246 | - ) |
|
| 247 | - ); |
|
| 235 | + define( |
|
| 236 | + '_IS_BOT_FRIEND', |
|
| 237 | + isset($_SERVER['HTTP_USER_AGENT']) |
|
| 238 | + and preg_match( |
|
| 239 | + ',' . implode('|', array( |
|
| 240 | + 'facebookexternalhit', |
|
| 241 | + 'twitterbot', |
|
| 242 | + 'flipboardproxy', |
|
| 243 | + 'wordpress' |
|
| 244 | + )) . ',i', |
|
| 245 | + (string)$_SERVER['HTTP_USER_AGENT'] |
|
| 246 | + ) |
|
| 247 | + ); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /* |
@@ -256,28 +256,28 @@ discard block |
||
| 256 | 256 | */ |
| 257 | 257 | $_exceptions = array('id_table', 'id_base', 'id_parent', 'id_article_pdf'); |
| 258 | 258 | foreach ($_GET as $var => $val) { |
| 259 | - if ( |
|
| 260 | - $_GET[$var] and strncmp($var, "id_", 3) == 0 |
|
| 261 | - and !in_array($var, $_exceptions) |
|
| 262 | - ) { |
|
| 263 | - $_GET[$var] = is_array($_GET[$var]) ? @array_map('intval', $_GET[$var]) : intval($_GET[$var]); |
|
| 264 | - } |
|
| 259 | + if ( |
|
| 260 | + $_GET[$var] and strncmp($var, "id_", 3) == 0 |
|
| 261 | + and !in_array($var, $_exceptions) |
|
| 262 | + ) { |
|
| 263 | + $_GET[$var] = is_array($_GET[$var]) ? @array_map('intval', $_GET[$var]) : intval($_GET[$var]); |
|
| 264 | + } |
|
| 265 | 265 | } |
| 266 | 266 | foreach ($_POST as $var => $val) { |
| 267 | - if ( |
|
| 268 | - $_POST[$var] and strncmp($var, "id_", 3) == 0 |
|
| 269 | - and !in_array($var, $_exceptions) |
|
| 270 | - ) { |
|
| 271 | - $_POST[$var] = is_array($_POST[$var]) ? @array_map('intval', $_POST[$var]) : intval($_POST[$var]); |
|
| 272 | - } |
|
| 267 | + if ( |
|
| 268 | + $_POST[$var] and strncmp($var, "id_", 3) == 0 |
|
| 269 | + and !in_array($var, $_exceptions) |
|
| 270 | + ) { |
|
| 271 | + $_POST[$var] = is_array($_POST[$var]) ? @array_map('intval', $_POST[$var]) : intval($_POST[$var]); |
|
| 272 | + } |
|
| 273 | 273 | } |
| 274 | 274 | foreach ($GLOBALS as $var => $val) { |
| 275 | - if ( |
|
| 276 | - $GLOBALS[$var] and strncmp($var, "id_", 3) == 0 |
|
| 277 | - and !in_array($var, $_exceptions) |
|
| 278 | - ) { |
|
| 279 | - $GLOBALS[$var] = is_array($GLOBALS[$var]) ? @array_map('intval', $GLOBALS[$var]) : intval($GLOBALS[$var]); |
|
| 280 | - } |
|
| 275 | + if ( |
|
| 276 | + $GLOBALS[$var] and strncmp($var, "id_", 3) == 0 |
|
| 277 | + and !in_array($var, $_exceptions) |
|
| 278 | + ) { |
|
| 279 | + $GLOBALS[$var] = is_array($GLOBALS[$var]) ? @array_map('intval', $GLOBALS[$var]) : intval($GLOBALS[$var]); |
|
| 280 | + } |
|
| 281 | 281 | } |
| 282 | 282 | |
| 283 | 283 | /* |
@@ -290,116 +290,116 @@ discard block |
||
| 290 | 290 | * Contrôle de quelques variables (XSS) |
| 291 | 291 | */ |
| 292 | 292 | foreach (array('lang', 'var_recherche', 'aide', 'var_lang_r', 'lang_r', 'var_ajax_ancre', 'nom_fichier') as $var) { |
| 293 | - if (isset($_GET[$var])) { |
|
| 294 | - $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 295 | - } |
|
| 296 | - if (isset($_POST[$var])) { |
|
| 297 | - $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 298 | - } |
|
| 293 | + if (isset($_GET[$var])) { |
|
| 294 | + $_REQUEST[$var] = $GLOBALS[$var] = $_GET[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_GET[$var]); |
|
| 295 | + } |
|
| 296 | + if (isset($_POST[$var])) { |
|
| 297 | + $_REQUEST[$var] = $GLOBALS[$var] = $_POST[$var] = preg_replace(',[^\w\,/#&;-]+,', ' ', (string)$_POST[$var]); |
|
| 298 | + } |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | /* |
| 302 | 302 | * Filtre l'accès à spip_acces_doc (injection SQL en 1.8.2x) |
| 303 | 303 | */ |
| 304 | 304 | if (isset($_SERVER['REQUEST_URI'])) { |
| 305 | - if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) { |
|
| 306 | - $file = addslashes((string)$_GET['file']); |
|
| 307 | - } |
|
| 305 | + if (preg_match(',^(.*/)?spip_acces_doc\.,', (string)$_SERVER['REQUEST_URI'])) { |
|
| 306 | + $file = addslashes((string)$_GET['file']); |
|
| 307 | + } |
|
| 308 | 308 | } |
| 309 | 309 | |
| 310 | 310 | /* |
| 311 | 311 | * Pas d'inscription abusive |
| 312 | 312 | */ |
| 313 | 313 | if ( |
| 314 | - isset($_REQUEST['mode']) and isset($_REQUEST['page']) |
|
| 315 | - and !in_array($_REQUEST['mode'], array("6forum", "1comite")) |
|
| 316 | - and $_REQUEST['page'] == "identifiants" |
|
| 314 | + isset($_REQUEST['mode']) and isset($_REQUEST['page']) |
|
| 315 | + and !in_array($_REQUEST['mode'], array("6forum", "1comite")) |
|
| 316 | + and $_REQUEST['page'] == "identifiants" |
|
| 317 | 317 | ) { |
| 318 | - $ecran_securite_raison = "identifiants"; |
|
| 318 | + $ecran_securite_raison = "identifiants"; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /* |
| 322 | 322 | * Agenda joue à l'injection php |
| 323 | 323 | */ |
| 324 | 324 | if ( |
| 325 | - isset($_REQUEST['partie_cal']) |
|
| 326 | - and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal']) |
|
| 325 | + isset($_REQUEST['partie_cal']) |
|
| 326 | + and $_REQUEST['partie_cal'] !== htmlentities((string)$_REQUEST['partie_cal']) |
|
| 327 | 327 | ) { |
| 328 | - $ecran_securite_raison = "partie_cal"; |
|
| 328 | + $ecran_securite_raison = "partie_cal"; |
|
| 329 | 329 | } |
| 330 | 330 | if ( |
| 331 | - isset($_REQUEST['echelle']) |
|
| 332 | - and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle']) |
|
| 331 | + isset($_REQUEST['echelle']) |
|
| 332 | + and $_REQUEST['echelle'] !== htmlentities((string)$_REQUEST['echelle']) |
|
| 333 | 333 | ) { |
| 334 | - $ecran_securite_raison = "echelle"; |
|
| 334 | + $ecran_securite_raison = "echelle"; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /* |
| 338 | 338 | * Espace privé |
| 339 | 339 | */ |
| 340 | 340 | if ( |
| 341 | - isset($_REQUEST['exec']) |
|
| 342 | - and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec']) |
|
| 341 | + isset($_REQUEST['exec']) |
|
| 342 | + and !preg_match(',^[\w-]+$,', (string)$_REQUEST['exec']) |
|
| 343 | 343 | ) { |
| 344 | - $ecran_securite_raison = "exec"; |
|
| 344 | + $ecran_securite_raison = "exec"; |
|
| 345 | 345 | } |
| 346 | 346 | if ( |
| 347 | - isset($_REQUEST['cherche_auteur']) |
|
| 348 | - and preg_match(',[<],', (string)$_REQUEST['cherche_auteur']) |
|
| 347 | + isset($_REQUEST['cherche_auteur']) |
|
| 348 | + and preg_match(',[<],', (string)$_REQUEST['cherche_auteur']) |
|
| 349 | 349 | ) { |
| 350 | - $ecran_securite_raison = "cherche_auteur"; |
|
| 350 | + $ecran_securite_raison = "cherche_auteur"; |
|
| 351 | 351 | } |
| 352 | 352 | if ( |
| 353 | - isset($_REQUEST['exec']) |
|
| 354 | - and $_REQUEST['exec'] == 'auteurs' |
|
| 355 | - and isset($_REQUEST['recherche']) |
|
| 356 | - and preg_match(',[<],', (string)$_REQUEST['recherche']) |
|
| 353 | + isset($_REQUEST['exec']) |
|
| 354 | + and $_REQUEST['exec'] == 'auteurs' |
|
| 355 | + and isset($_REQUEST['recherche']) |
|
| 356 | + and preg_match(',[<],', (string)$_REQUEST['recherche']) |
|
| 357 | 357 | ) { |
| 358 | - $ecran_securite_raison = "recherche"; |
|
| 358 | + $ecran_securite_raison = "recherche"; |
|
| 359 | 359 | } |
| 360 | 360 | if ( |
| 361 | - isset($_REQUEST['exec']) |
|
| 362 | - and $_REQUEST['exec'] == 'info_plugin' |
|
| 363 | - and isset($_REQUEST['plugin']) |
|
| 364 | - and preg_match(',[<],', (string)$_REQUEST['plugin']) |
|
| 361 | + isset($_REQUEST['exec']) |
|
| 362 | + and $_REQUEST['exec'] == 'info_plugin' |
|
| 363 | + and isset($_REQUEST['plugin']) |
|
| 364 | + and preg_match(',[<],', (string)$_REQUEST['plugin']) |
|
| 365 | 365 | ) { |
| 366 | - $ecran_securite_raison = "plugin"; |
|
| 366 | + $ecran_securite_raison = "plugin"; |
|
| 367 | 367 | } |
| 368 | 368 | if ( |
| 369 | - isset($_REQUEST['exec']) |
|
| 370 | - and $_REQUEST['exec'] == 'puce_statut' |
|
| 371 | - and isset($_REQUEST['id']) |
|
| 372 | - and !intval($_REQUEST['id']) |
|
| 369 | + isset($_REQUEST['exec']) |
|
| 370 | + and $_REQUEST['exec'] == 'puce_statut' |
|
| 371 | + and isset($_REQUEST['id']) |
|
| 372 | + and !intval($_REQUEST['id']) |
|
| 373 | 373 | ) { |
| 374 | - $ecran_securite_raison = "puce_statut"; |
|
| 374 | + $ecran_securite_raison = "puce_statut"; |
|
| 375 | 375 | } |
| 376 | 376 | if ( |
| 377 | - isset($_REQUEST['action']) |
|
| 378 | - and $_REQUEST['action'] == 'configurer' |
|
| 377 | + isset($_REQUEST['action']) |
|
| 378 | + and $_REQUEST['action'] == 'configurer' |
|
| 379 | 379 | ) { |
| 380 | - if ( |
|
| 381 | - @file_exists('inc_version.php') |
|
| 382 | - or @file_exists('ecrire/inc_version.php') |
|
| 383 | - ) { |
|
| 384 | - function action_configurer() { |
|
| 385 | - include_spip('inc/autoriser'); |
|
| 386 | - if (!autoriser('configurer', _request('configuration'))) { |
|
| 387 | - include_spip('inc/minipres'); |
|
| 388 | - echo minipres(_T('info_acces_interdit')); |
|
| 389 | - exit; |
|
| 390 | - } |
|
| 391 | - require _DIR_RESTREINT . 'action/configurer.php'; |
|
| 392 | - action_configurer_dist(); |
|
| 393 | - } |
|
| 394 | - } |
|
| 380 | + if ( |
|
| 381 | + @file_exists('inc_version.php') |
|
| 382 | + or @file_exists('ecrire/inc_version.php') |
|
| 383 | + ) { |
|
| 384 | + function action_configurer() { |
|
| 385 | + include_spip('inc/autoriser'); |
|
| 386 | + if (!autoriser('configurer', _request('configuration'))) { |
|
| 387 | + include_spip('inc/minipres'); |
|
| 388 | + echo minipres(_T('info_acces_interdit')); |
|
| 389 | + exit; |
|
| 390 | + } |
|
| 391 | + require _DIR_RESTREINT . 'action/configurer.php'; |
|
| 392 | + action_configurer_dist(); |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | 395 | } |
| 396 | 396 | if ( |
| 397 | - isset($_REQUEST['action']) |
|
| 398 | - and $_REQUEST['action'] == 'ordonner_liens_documents' |
|
| 399 | - and isset($_REQUEST['ordre']) |
|
| 400 | - and is_string($_REQUEST['ordre']) |
|
| 397 | + isset($_REQUEST['action']) |
|
| 398 | + and $_REQUEST['action'] == 'ordonner_liens_documents' |
|
| 399 | + and isset($_REQUEST['ordre']) |
|
| 400 | + and is_string($_REQUEST['ordre']) |
|
| 401 | 401 | ) { |
| 402 | - $ecran_securite_raison = "ordre a la chaine"; |
|
| 402 | + $ecran_securite_raison = "ordre a la chaine"; |
|
| 403 | 403 | } |
| 404 | 404 | |
| 405 | 405 | |
@@ -407,29 +407,29 @@ discard block |
||
| 407 | 407 | * Bloque les requêtes contenant %00 (manipulation d'include) |
| 408 | 408 | */ |
| 409 | 409 | if (strpos( |
| 410 | - (function_exists('get_magic_quotes_gpc') and @get_magic_quotes_gpc()) |
|
| 411 | - ? stripslashes(serialize($_REQUEST)) |
|
| 412 | - : serialize($_REQUEST), |
|
| 413 | - chr(0) |
|
| 410 | + (function_exists('get_magic_quotes_gpc') and @get_magic_quotes_gpc()) |
|
| 411 | + ? stripslashes(serialize($_REQUEST)) |
|
| 412 | + : serialize($_REQUEST), |
|
| 413 | + chr(0) |
|
| 414 | 414 | ) !== false) { |
| 415 | - $ecran_securite_raison = "%00"; |
|
| 415 | + $ecran_securite_raison = "%00"; |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /* |
| 419 | 419 | * Bloque les requêtes fond=formulaire_ |
| 420 | 420 | */ |
| 421 | 421 | if ( |
| 422 | - isset($_REQUEST['fond']) |
|
| 423 | - and preg_match(',^formulaire_,i', $_REQUEST['fond']) |
|
| 422 | + isset($_REQUEST['fond']) |
|
| 423 | + and preg_match(',^formulaire_,i', $_REQUEST['fond']) |
|
| 424 | 424 | ) { |
| 425 | - $ecran_securite_raison = "fond=formulaire_"; |
|
| 425 | + $ecran_securite_raison = "fond=formulaire_"; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /* |
| 429 | 429 | * Bloque les requêtes du type ?GLOBALS[type_urls]=toto (bug vieux php) |
| 430 | 430 | */ |
| 431 | 431 | if (isset($_REQUEST['GLOBALS'])) { |
| 432 | - $ecran_securite_raison = "GLOBALS[GLOBALS]"; |
|
| 432 | + $ecran_securite_raison = "GLOBALS[GLOBALS]"; |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | /* |
@@ -438,14 +438,14 @@ discard block |
||
| 438 | 438 | * les paginations entremélées |
| 439 | 439 | */ |
| 440 | 440 | if (_IS_BOT) { |
| 441 | - if ( |
|
| 442 | - (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type'])) |
|
| 443 | - or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI'])) |
|
| 444 | - or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_')) |
|
| 445 | - or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI'])) |
|
| 446 | - ) { |
|
| 447 | - $ecran_securite_raison = "robot agenda/double pagination"; |
|
| 448 | - } |
|
| 441 | + if ( |
|
| 442 | + (isset($_REQUEST['echelle']) and isset($_REQUEST['partie_cal']) and isset($_REQUEST['type'])) |
|
| 443 | + or (strpos((string)$_SERVER['REQUEST_URI'], 'debut_') and preg_match(',[?&]debut_.*&debut_,', (string)$_SERVER['REQUEST_URI'])) |
|
| 444 | + or (isset($_REQUEST['calendrier_annee']) and strpos((string)$_SERVER['REQUEST_URI'], 'debut_')) |
|
| 445 | + or (isset($_REQUEST['calendrier_annee']) and preg_match(',[?&]calendrier_annee=.*&calendrier_annee=,', (string)$_SERVER['REQUEST_URI'])) |
|
| 446 | + ) { |
|
| 447 | + $ecran_securite_raison = "robot agenda/double pagination"; |
|
| 448 | + } |
|
| 449 | 449 | } |
| 450 | 450 | |
| 451 | 451 | /* |
@@ -453,82 +453,82 @@ discard block |
||
| 453 | 453 | * Bloque un XSS sur une page inexistante |
| 454 | 454 | */ |
| 455 | 455 | if (isset($_REQUEST['page'])) { |
| 456 | - if ($_REQUEST['page'] == 'test_cfg') { |
|
| 457 | - $ecran_securite_raison = "test_cfg"; |
|
| 458 | - } |
|
| 459 | - if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) { |
|
| 460 | - $ecran_securite_raison = "xsspage"; |
|
| 461 | - } |
|
| 462 | - if ( |
|
| 463 | - $_REQUEST['page'] == '404' |
|
| 464 | - and isset($_REQUEST['erreur']) |
|
| 465 | - ) { |
|
| 466 | - $ecran_securite_raison = "xss404"; |
|
| 467 | - } |
|
| 456 | + if ($_REQUEST['page'] == 'test_cfg') { |
|
| 457 | + $ecran_securite_raison = "test_cfg"; |
|
| 458 | + } |
|
| 459 | + if ($_REQUEST['page'] !== htmlspecialchars((string)$_REQUEST['page'])) { |
|
| 460 | + $ecran_securite_raison = "xsspage"; |
|
| 461 | + } |
|
| 462 | + if ( |
|
| 463 | + $_REQUEST['page'] == '404' |
|
| 464 | + and isset($_REQUEST['erreur']) |
|
| 465 | + ) { |
|
| 466 | + $ecran_securite_raison = "xss404"; |
|
| 467 | + } |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | /* |
| 471 | 471 | * XSS par array |
| 472 | 472 | */ |
| 473 | 473 | foreach (array('var_login') as $var) { |
| 474 | - if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) { |
|
| 475 | - $ecran_securite_raison = "xss " . $var; |
|
| 476 | - } |
|
| 474 | + if (isset($_REQUEST[$var]) and is_array($_REQUEST[$var])) { |
|
| 475 | + $ecran_securite_raison = "xss " . $var; |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /* |
| 480 | 480 | * Parade antivirale contre un cheval de troie |
| 481 | 481 | */ |
| 482 | 482 | if (!function_exists('tmp_lkojfghx')) { |
| 483 | - function tmp_lkojfghx() {} |
|
| 484 | - function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) { |
|
| 485 | - // si jamais on est arrivé ici sur une erreur php |
|
| 486 | - // et qu'un autre gestionnaire d'erreur est défini, l'appeller |
|
| 487 | - if ($b && $GLOBALS['tmp_xhgfjokl']) { |
|
| 488 | - call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d); |
|
| 489 | - } |
|
| 490 | - } |
|
| 483 | + function tmp_lkojfghx() {} |
|
| 484 | + function tmp_lkojfghx2($a = 0, $b = 0, $c = 0, $d = 0) { |
|
| 485 | + // si jamais on est arrivé ici sur une erreur php |
|
| 486 | + // et qu'un autre gestionnaire d'erreur est défini, l'appeller |
|
| 487 | + if ($b && $GLOBALS['tmp_xhgfjokl']) { |
|
| 488 | + call_user_func($GLOBALS['tmp_xhgfjokl'], $a, $b, $c, $d); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | 491 | } |
| 492 | 492 | if (isset($_POST['tmp_lkojfghx3'])) { |
| 493 | - $ecran_securite_raison = "gumblar"; |
|
| 493 | + $ecran_securite_raison = "gumblar"; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /* |
| 497 | 497 | * Outils XML mal sécurisés < 2.0.9 |
| 498 | 498 | */ |
| 499 | 499 | if (isset($_REQUEST['transformer_xml'])) { |
| 500 | - $ecran_securite_raison = "transformer_xml"; |
|
| 500 | + $ecran_securite_raison = "transformer_xml"; |
|
| 501 | 501 | } |
| 502 | 502 | |
| 503 | 503 | /* |
| 504 | 504 | * Outils XML mal sécurisés again |
| 505 | 505 | */ |
| 506 | 506 | if (isset($_REQUEST['var_url']) and $_REQUEST['var_url'] and isset($_REQUEST['exec']) and $_REQUEST['exec'] == 'valider_xml') { |
| 507 | - $url = trim($_REQUEST['var_url']); |
|
| 508 | - if ( |
|
| 509 | - strncmp($url, '/', 1) == 0 |
|
| 510 | - or (($p = strpos($url, '..')) !== false and strpos($url, '..', $p + 3) !== false) |
|
| 511 | - or (($p = strpos($url, '..')) !== false and strpos($url, 'IMG', $p + 3) !== false) |
|
| 512 | - or (strpos($url, '://') !== false or strpos($url, ':\\') !== false) |
|
| 513 | - ) { |
|
| 514 | - $ecran_securite_raison = 'URL interdite pour var_url'; |
|
| 515 | - } |
|
| 507 | + $url = trim($_REQUEST['var_url']); |
|
| 508 | + if ( |
|
| 509 | + strncmp($url, '/', 1) == 0 |
|
| 510 | + or (($p = strpos($url, '..')) !== false and strpos($url, '..', $p + 3) !== false) |
|
| 511 | + or (($p = strpos($url, '..')) !== false and strpos($url, 'IMG', $p + 3) !== false) |
|
| 512 | + or (strpos($url, '://') !== false or strpos($url, ':\\') !== false) |
|
| 513 | + ) { |
|
| 514 | + $ecran_securite_raison = 'URL interdite pour var_url'; |
|
| 515 | + } |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | /* |
| 519 | 519 | * Sauvegarde mal securisée < 2.0.9 |
| 520 | 520 | */ |
| 521 | 521 | if ( |
| 522 | - isset($_REQUEST['nom_sauvegarde']) |
|
| 523 | - and strstr((string)$_REQUEST['nom_sauvegarde'], '/') |
|
| 522 | + isset($_REQUEST['nom_sauvegarde']) |
|
| 523 | + and strstr((string)$_REQUEST['nom_sauvegarde'], '/') |
|
| 524 | 524 | ) { |
| 525 | - $ecran_securite_raison = 'nom_sauvegarde manipulee'; |
|
| 525 | + $ecran_securite_raison = 'nom_sauvegarde manipulee'; |
|
| 526 | 526 | } |
| 527 | 527 | if ( |
| 528 | - isset($_REQUEST['znom_sauvegarde']) |
|
| 529 | - and strstr((string)$_REQUEST['znom_sauvegarde'], '/') |
|
| 528 | + isset($_REQUEST['znom_sauvegarde']) |
|
| 529 | + and strstr((string)$_REQUEST['znom_sauvegarde'], '/') |
|
| 530 | 530 | ) { |
| 531 | - $ecran_securite_raison = 'znom_sauvegarde manipulee'; |
|
| 531 | + $ecran_securite_raison = 'znom_sauvegarde manipulee'; |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | |
@@ -537,57 +537,57 @@ discard block |
||
| 537 | 537 | * on vérifie 'page' pour ne pas bloquer ... drupal |
| 538 | 538 | */ |
| 539 | 539 | if ( |
| 540 | - isset($_REQUEST['op']) and isset($_REQUEST['page']) |
|
| 541 | - and $_REQUEST['op'] !== preg_replace('/[^\\-\w]/', '', $_REQUEST['op']) |
|
| 540 | + isset($_REQUEST['op']) and isset($_REQUEST['page']) |
|
| 541 | + and $_REQUEST['op'] !== preg_replace('/[^\\-\w]/', '', $_REQUEST['op']) |
|
| 542 | 542 | ) { |
| 543 | - $ecran_securite_raison = 'op'; |
|
| 543 | + $ecran_securite_raison = 'op'; |
|
| 544 | 544 | } |
| 545 | 545 | |
| 546 | 546 | /* |
| 547 | 547 | * Forms & Table ne se méfiait pas assez des uploads de fichiers |
| 548 | 548 | */ |
| 549 | 549 | if (count($_FILES)) { |
| 550 | - foreach ($_FILES as $k => $v) { |
|
| 551 | - if ( |
|
| 552 | - preg_match(',^fichier_\d+$,', $k) |
|
| 553 | - and preg_match(',\.php,i', $v['name']) |
|
| 554 | - ) { |
|
| 555 | - unset($_FILES[$k]); |
|
| 556 | - } |
|
| 557 | - } |
|
| 550 | + foreach ($_FILES as $k => $v) { |
|
| 551 | + if ( |
|
| 552 | + preg_match(',^fichier_\d+$,', $k) |
|
| 553 | + and preg_match(',\.php,i', $v['name']) |
|
| 554 | + ) { |
|
| 555 | + unset($_FILES[$k]); |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | 558 | } |
| 559 | 559 | /* |
| 560 | 560 | * et Contact trop laxiste avec une variable externe |
| 561 | 561 | * on bloque pas le post pour eviter de perdre des donnees mais on unset la variable et c'est tout |
| 562 | 562 | */ |
| 563 | 563 | if (isset($_REQUEST['pj_enregistrees_nom']) and $_REQUEST['pj_enregistrees_nom']) { |
| 564 | - unset($_REQUEST['pj_enregistrees_nom']); |
|
| 565 | - unset($_GET['pj_enregistrees_nom']); |
|
| 566 | - unset($_POST['pj_enregistrees_nom']); |
|
| 564 | + unset($_REQUEST['pj_enregistrees_nom']); |
|
| 565 | + unset($_GET['pj_enregistrees_nom']); |
|
| 566 | + unset($_POST['pj_enregistrees_nom']); |
|
| 567 | 567 | } |
| 568 | 568 | |
| 569 | 569 | /* |
| 570 | 570 | * reinstall=oui un peu trop permissif |
| 571 | 571 | */ |
| 572 | 572 | if ( |
| 573 | - isset($_REQUEST['reinstall']) |
|
| 574 | - and $_REQUEST['reinstall'] == 'oui' |
|
| 573 | + isset($_REQUEST['reinstall']) |
|
| 574 | + and $_REQUEST['reinstall'] == 'oui' |
|
| 575 | 575 | ) { |
| 576 | - $ecran_securite_raison = 'reinstall=oui'; |
|
| 576 | + $ecran_securite_raison = 'reinstall=oui'; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /* |
| 580 | 580 | * Pas d'action pendant l'install |
| 581 | 581 | */ |
| 582 | 582 | if (isset($_REQUEST['exec']) and $_REQUEST['exec'] === 'install' and isset($_REQUEST['action'])) { |
| 583 | - $ecran_securite_raison = 'install&action impossibles'; |
|
| 583 | + $ecran_securite_raison = 'install&action impossibles'; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /* |
| 587 | 587 | * Échappement xss referer |
| 588 | 588 | */ |
| 589 | 589 | if (isset($_SERVER['HTTP_REFERER'])) { |
| 590 | - $_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##'); |
|
| 590 | + $_SERVER['HTTP_REFERER'] = strtr($_SERVER['HTTP_REFERER'], '<>"\'', '[]##'); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | |
@@ -595,7 +595,7 @@ discard block |
||
| 595 | 595 | * Echappement HTTP_X_FORWARDED_HOST |
| 596 | 596 | */ |
| 597 | 597 | if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
| 598 | - $_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 598 | + $_SERVER['HTTP_X_FORWARDED_HOST'] = strtr($_SERVER['HTTP_X_FORWARDED_HOST'], "<>?\"\{\}\$'` \r\n", '____________'); |
|
| 599 | 599 | } |
| 600 | 600 | |
| 601 | 601 | |
@@ -603,9 +603,9 @@ discard block |
||
| 603 | 603 | * Pas d'erreur dans l'erreur |
| 604 | 604 | */ |
| 605 | 605 | if (isset($_REQUEST['var_erreur']) and isset($_REQUEST['page']) and $_REQUEST['page'] === 'login') { |
| 606 | - if (strlen($_REQUEST['var_erreur']) !== strcspn($_REQUEST['var_erreur'], '<>')) { |
|
| 607 | - $ecran_securite_raison = 'var_erreur incorrecte'; |
|
| 608 | - } |
|
| 606 | + if (strlen($_REQUEST['var_erreur']) !== strcspn($_REQUEST['var_erreur'], '<>')) { |
|
| 607 | + $ecran_securite_raison = 'var_erreur incorrecte'; |
|
| 608 | + } |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | |
@@ -613,30 +613,30 @@ discard block |
||
| 613 | 613 | * Réinjection des clés en html dans l'admin r19561 |
| 614 | 614 | */ |
| 615 | 615 | if ( |
| 616 | - (isset($_SERVER['REQUEST_URI']) and strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false) |
|
| 617 | - or isset($_REQUEST['var_memotri']) |
|
| 616 | + (isset($_SERVER['REQUEST_URI']) and strpos($_SERVER['REQUEST_URI'], "ecrire/") !== false) |
|
| 617 | + or isset($_REQUEST['var_memotri']) |
|
| 618 | 618 | ) { |
| 619 | - $zzzz = implode("", array_keys($_REQUEST)); |
|
| 620 | - if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) { |
|
| 621 | - $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
|
| 622 | - } |
|
| 619 | + $zzzz = implode("", array_keys($_REQUEST)); |
|
| 620 | + if (strlen($zzzz) != strcspn($zzzz, '<>"\'')) { |
|
| 621 | + $ecran_securite_raison = 'Cle incorrecte en $_REQUEST'; |
|
| 622 | + } |
|
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | /* |
| 626 | 626 | * Injection par connect |
| 627 | 627 | */ |
| 628 | 628 | if ( |
| 629 | - isset($_REQUEST['connect']) |
|
| 630 | - // cas qui permettent de sortir d'un commentaire PHP |
|
| 631 | - and ( |
|
| 632 | - strpos($_REQUEST['connect'], "?") !== false |
|
| 633 | - or strpos($_REQUEST['connect'], "<") !== false |
|
| 634 | - or strpos($_REQUEST['connect'], ">") !== false |
|
| 635 | - or strpos($_REQUEST['connect'], "\n") !== false |
|
| 636 | - or strpos($_REQUEST['connect'], "\r") !== false |
|
| 637 | - ) |
|
| 629 | + isset($_REQUEST['connect']) |
|
| 630 | + // cas qui permettent de sortir d'un commentaire PHP |
|
| 631 | + and ( |
|
| 632 | + strpos($_REQUEST['connect'], "?") !== false |
|
| 633 | + or strpos($_REQUEST['connect'], "<") !== false |
|
| 634 | + or strpos($_REQUEST['connect'], ">") !== false |
|
| 635 | + or strpos($_REQUEST['connect'], "\n") !== false |
|
| 636 | + or strpos($_REQUEST['connect'], "\r") !== false |
|
| 637 | + ) |
|
| 638 | 638 | ) { |
| 639 | - $ecran_securite_raison = "malformed connect argument"; |
|
| 639 | + $ecran_securite_raison = "malformed connect argument"; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | |
@@ -644,9 +644,9 @@ discard block |
||
| 644 | 644 | * _oups donc |
| 645 | 645 | */ |
| 646 | 646 | if ( |
| 647 | - isset($_REQUEST['_oups']) |
|
| 648 | - and base64_decode($_REQUEST['_oups'], true) === false) { |
|
| 649 | - $ecran_securite_raison = "malformed _oups argument"; |
|
| 647 | + isset($_REQUEST['_oups']) |
|
| 648 | + and base64_decode($_REQUEST['_oups'], true) === false) { |
|
| 649 | + $ecran_securite_raison = "malformed _oups argument"; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | |
@@ -654,23 +654,23 @@ discard block |
||
| 654 | 654 | * S'il y a une raison de mourir, mourons |
| 655 | 655 | */ |
| 656 | 656 | if (isset($ecran_securite_raison)) { |
| 657 | - header("HTTP/1.0 403 Forbidden"); |
|
| 658 | - header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 659 | - header("Cache-Control: no-cache, must-revalidate"); |
|
| 660 | - header("Pragma: no-cache"); |
|
| 661 | - header("Content-Type: text/html"); |
|
| 662 | - header("Connection: close"); |
|
| 663 | - die("<html><title>Error 403: Forbidden</title><body><h1>Error 403</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>"); |
|
| 657 | + header("HTTP/1.0 403 Forbidden"); |
|
| 658 | + header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 659 | + header("Cache-Control: no-cache, must-revalidate"); |
|
| 660 | + header("Pragma: no-cache"); |
|
| 661 | + header("Content-Type: text/html"); |
|
| 662 | + header("Connection: close"); |
|
| 663 | + die("<html><title>Error 403: Forbidden</title><body><h1>Error 403</h1><p>You are not authorized to view this page ($ecran_securite_raison)</p></body></html>"); |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | /* |
| 667 | 667 | * Un filtre filtrer_entites securise |
| 668 | 668 | */ |
| 669 | 669 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 670 | - function filtre_filtrer_entites_dist($t) { |
|
| 671 | - include_spip('inc/texte'); |
|
| 672 | - return interdire_scripts(filtrer_entites($t)); |
|
| 673 | - } |
|
| 670 | + function filtre_filtrer_entites_dist($t) { |
|
| 671 | + include_spip('inc/texte'); |
|
| 672 | + return interdire_scripts(filtrer_entites($t)); |
|
| 673 | + } |
|
| 674 | 674 | } |
| 675 | 675 | |
| 676 | 676 | |
@@ -684,35 +684,35 @@ discard block |
||
| 684 | 684 | * Bloque les bots quand le load déborde |
| 685 | 685 | */ |
| 686 | 686 | if (!defined('_ECRAN_SECURITE_LOAD')) { |
| 687 | - define('_ECRAN_SECURITE_LOAD', 4); |
|
| 687 | + define('_ECRAN_SECURITE_LOAD', 4); |
|
| 688 | 688 | } |
| 689 | 689 | |
| 690 | 690 | if ( |
| 691 | - defined('_ECRAN_SECURITE_LOAD') |
|
| 692 | - and _ECRAN_SECURITE_LOAD > 0 |
|
| 693 | - and _IS_BOT |
|
| 694 | - and !_IS_BOT_FRIEND |
|
| 695 | - and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 696 | - and ( |
|
| 697 | - (function_exists('sys_getloadavg') |
|
| 698 | - and $load = sys_getloadavg() |
|
| 699 | - and is_array($load) |
|
| 700 | - and $load = array_shift($load)) |
|
| 701 | - or |
|
| 702 | - (@is_readable('/proc/loadavg') |
|
| 703 | - and $load = file_get_contents('/proc/loadavg') |
|
| 704 | - and $load = floatval($load)) |
|
| 705 | - ) |
|
| 706 | - and $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite |
|
| 707 | - and rand(0, $load * $load) > _ECRAN_SECURITE_LOAD * _ECRAN_SECURITE_LOAD |
|
| 691 | + defined('_ECRAN_SECURITE_LOAD') |
|
| 692 | + and _ECRAN_SECURITE_LOAD > 0 |
|
| 693 | + and _IS_BOT |
|
| 694 | + and !_IS_BOT_FRIEND |
|
| 695 | + and $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 696 | + and ( |
|
| 697 | + (function_exists('sys_getloadavg') |
|
| 698 | + and $load = sys_getloadavg() |
|
| 699 | + and is_array($load) |
|
| 700 | + and $load = array_shift($load)) |
|
| 701 | + or |
|
| 702 | + (@is_readable('/proc/loadavg') |
|
| 703 | + and $load = file_get_contents('/proc/loadavg') |
|
| 704 | + and $load = floatval($load)) |
|
| 705 | + ) |
|
| 706 | + and $load > _ECRAN_SECURITE_LOAD // eviter l'evaluation suivante si de toute facon le load est inferieur a la limite |
|
| 707 | + and rand(0, $load * $load) > _ECRAN_SECURITE_LOAD * _ECRAN_SECURITE_LOAD |
|
| 708 | 708 | ) { |
| 709 | - //https://webmasters.stackexchange.com/questions/65674/should-i-return-a-429-or-503-status-code-to-a-bot |
|
| 710 | - header("HTTP/1.0 429 Too Many Requests"); |
|
| 711 | - header("Retry-After: 300"); |
|
| 712 | - header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 713 | - header("Cache-Control: no-cache, must-revalidate"); |
|
| 714 | - header("Pragma: no-cache"); |
|
| 715 | - header("Content-Type: text/html"); |
|
| 716 | - header("Connection: close"); |
|
| 717 | - die("<html><title>Status 429: Too Many Requests</title><body><h1>Status 429</h1><p>Too Many Requests (try again soon)</p></body></html>"); |
|
| 709 | + //https://webmasters.stackexchange.com/questions/65674/should-i-return-a-429-or-503-status-code-to-a-bot |
|
| 710 | + header("HTTP/1.0 429 Too Many Requests"); |
|
| 711 | + header("Retry-After: 300"); |
|
| 712 | + header("Expires: Wed, 11 Jan 1984 05:00:00 GMT"); |
|
| 713 | + header("Cache-Control: no-cache, must-revalidate"); |
|
| 714 | + header("Pragma: no-cache"); |
|
| 715 | + header("Content-Type: text/html"); |
|
| 716 | + header("Connection: close"); |
|
| 717 | + die("<html><title>Status 429: Too Many Requests</title><body><h1>Status 429</h1><p>Too Many Requests (try again soon)</p></body></html>"); |
|
| 718 | 718 | } |