@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('base/abstract_sql'); |
@@ -35,33 +35,33 @@ discard block |
||
| 35 | 35 | * - une chaîne vide si autorisation à pénétrer dans l'espace privé. |
| 36 | 36 | */ |
| 37 | 37 | function inc_auth_dist() { |
| 38 | - $row = auth_mode(); |
|
| 38 | + $row = auth_mode(); |
|
| 39 | 39 | |
| 40 | - if ($row) { |
|
| 41 | - return auth_init_droits($row); |
|
| 42 | - } |
|
| 40 | + if ($row) { |
|
| 41 | + return auth_init_droits($row); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - if (!$GLOBALS['connect_login']) { |
|
| 45 | - return auth_a_loger(); |
|
| 46 | - } |
|
| 44 | + if (!$GLOBALS['connect_login']) { |
|
| 45 | + return auth_a_loger(); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 49 | - // C'est soit parce que la base est inutilisable, |
|
| 50 | - // soit parce que la table des auteurs a changee (restauration etc) |
|
| 51 | - // Pas la peine d'insister. |
|
| 52 | - // Renvoyer le nom fautif et une URL de remise a zero |
|
| 48 | + // Cas ou l'auteur a ete identifie mais on n'a pas d'info sur lui |
|
| 49 | + // C'est soit parce que la base est inutilisable, |
|
| 50 | + // soit parce que la table des auteurs a changee (restauration etc) |
|
| 51 | + // Pas la peine d'insister. |
|
| 52 | + // Renvoyer le nom fautif et une URL de remise a zero |
|
| 53 | 53 | |
| 54 | - if (spip_connect()) { |
|
| 55 | - return [ |
|
| 56 | - 'login' => $GLOBALS['connect_login'], |
|
| 57 | - 'site' => generer_url_public('', 'action=logout&logout=prive') |
|
| 58 | - ]; |
|
| 59 | - } |
|
| 54 | + if (spip_connect()) { |
|
| 55 | + return [ |
|
| 56 | + 'login' => $GLOBALS['connect_login'], |
|
| 57 | + 'site' => generer_url_public('', 'action=logout&logout=prive') |
|
| 58 | + ]; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $n = intval(sql_errno()); |
|
| 62 | - spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 61 | + $n = intval(sql_errno()); |
|
| 62 | + spip_log("Erreur base de donnees $n " . sql_error()); |
|
| 63 | 63 | |
| 64 | - return $n ?: 1; |
|
| 64 | + return $n ?: 1; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -73,39 +73,39 @@ discard block |
||
| 73 | 73 | * @return array|string |
| 74 | 74 | */ |
| 75 | 75 | function auth_echec($raison) { |
| 76 | - include_spip('inc/minipres'); |
|
| 77 | - include_spip('inc/headers'); |
|
| 78 | - // pas authentifie. Pourquoi ? |
|
| 79 | - if (is_string($raison)) { |
|
| 80 | - // redirection vers une page d'authentification |
|
| 81 | - // on ne revient pas de cette fonction |
|
| 82 | - // sauf si pb de header |
|
| 83 | - $raison = redirige_formulaire($raison); |
|
| 84 | - } elseif (is_int($raison)) { |
|
| 85 | - // erreur SQL a afficher |
|
| 86 | - $raison = minipres( |
|
| 87 | - _T('info_travaux_titre'), |
|
| 88 | - _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 89 | - ); |
|
| 90 | - } elseif (@$raison['statut']) { |
|
| 91 | - // un simple visiteur n'a pas acces a l'espace prive |
|
| 92 | - spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 93 | - $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 94 | - } else { |
|
| 95 | - // auteur en fin de droits ... |
|
| 96 | - $h = $raison['site']; |
|
| 97 | - $raison = minipres( |
|
| 98 | - _T('avis_erreur_connexion'), |
|
| 99 | - '<br /><br /><p>' |
|
| 100 | - . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 101 | - . " <a href='$h'>" |
|
| 102 | - . _T('texte_inc_auth_2') |
|
| 103 | - . '</a>' |
|
| 104 | - . _T('texte_inc_auth_3') |
|
| 105 | - ); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return $raison; |
|
| 76 | + include_spip('inc/minipres'); |
|
| 77 | + include_spip('inc/headers'); |
|
| 78 | + // pas authentifie. Pourquoi ? |
|
| 79 | + if (is_string($raison)) { |
|
| 80 | + // redirection vers une page d'authentification |
|
| 81 | + // on ne revient pas de cette fonction |
|
| 82 | + // sauf si pb de header |
|
| 83 | + $raison = redirige_formulaire($raison); |
|
| 84 | + } elseif (is_int($raison)) { |
|
| 85 | + // erreur SQL a afficher |
|
| 86 | + $raison = minipres( |
|
| 87 | + _T('info_travaux_titre'), |
|
| 88 | + _T('titre_probleme_technique') . '<p><tt>' . sql_errno() . ' ' . sql_error() . '</tt></p>' |
|
| 89 | + ); |
|
| 90 | + } elseif (@$raison['statut']) { |
|
| 91 | + // un simple visiteur n'a pas acces a l'espace prive |
|
| 92 | + spip_log('connexion refusee a ' . @$raison['id_auteur']); |
|
| 93 | + $raison = minipres(_T('avis_erreur_connexion'), _T('avis_erreur_visiteur')); |
|
| 94 | + } else { |
|
| 95 | + // auteur en fin de droits ... |
|
| 96 | + $h = $raison['site']; |
|
| 97 | + $raison = minipres( |
|
| 98 | + _T('avis_erreur_connexion'), |
|
| 99 | + '<br /><br /><p>' |
|
| 100 | + . _T('texte_inc_auth_1', ['auth_login' => $raison['login']]) |
|
| 101 | + . " <a href='$h'>" |
|
| 102 | + . _T('texte_inc_auth_2') |
|
| 103 | + . '</a>' |
|
| 104 | + . _T('texte_inc_auth_3') |
|
| 105 | + ); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return $raison; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -115,81 +115,81 @@ discard block |
||
| 115 | 115 | * @return array|bool|string |
| 116 | 116 | */ |
| 117 | 117 | function auth_mode() { |
| 118 | - // |
|
| 119 | - // Initialiser variables (eviter hacks par URL) |
|
| 120 | - // |
|
| 121 | - $GLOBALS['connect_login'] = ''; |
|
| 122 | - $id_auteur = null; |
|
| 123 | - $GLOBALS['auth_can_disconnect'] = false; |
|
| 124 | - |
|
| 125 | - // |
|
| 126 | - // Recuperer les donnees d'identification |
|
| 127 | - // |
|
| 128 | - include_spip('inc/session'); |
|
| 129 | - // Session valide en cours ? |
|
| 130 | - if (isset($_COOKIE['spip_session'])) { |
|
| 131 | - $session = charger_fonction('session', 'inc'); |
|
| 132 | - if ( |
|
| 133 | - $id_auteur = $session() |
|
| 134 | - or $id_auteur === 0 // reprise sur restauration |
|
| 135 | - ) { |
|
| 136 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 137 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 138 | - } else { |
|
| 139 | - unset($_COOKIE['spip_session']); |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // Essayer auth http si significatif |
|
| 144 | - // (ignorer les login d'intranet independants de spip) |
|
| 145 | - if (!$GLOBALS['ignore_auth_http']) { |
|
| 146 | - if ( |
|
| 147 | - (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) |
|
| 148 | - and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 149 | - or |
|
| 150 | - // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 151 | - // est indisponible mais tentons quand meme pour |
|
| 152 | - // autocreation via LDAP |
|
| 153 | - (isset($_SERVER['REMOTE_USER']) |
|
| 154 | - and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 155 | - ) { |
|
| 156 | - if (!$id_auteur) { |
|
| 157 | - $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 158 | - $GLOBALS['auth_can_disconnect'] = true; |
|
| 159 | - $GLOBALS['visiteur_session'] = $r; |
|
| 160 | - $GLOBALS['connect_login'] = session_get('login'); |
|
| 161 | - $id_auteur = $r['id_auteur']; |
|
| 162 | - } else { |
|
| 163 | - // cas de la session en plus de PHP_AUTH |
|
| 164 | - /* if ($id_auteur != $r['id_auteur']){ |
|
| 118 | + // |
|
| 119 | + // Initialiser variables (eviter hacks par URL) |
|
| 120 | + // |
|
| 121 | + $GLOBALS['connect_login'] = ''; |
|
| 122 | + $id_auteur = null; |
|
| 123 | + $GLOBALS['auth_can_disconnect'] = false; |
|
| 124 | + |
|
| 125 | + // |
|
| 126 | + // Recuperer les donnees d'identification |
|
| 127 | + // |
|
| 128 | + include_spip('inc/session'); |
|
| 129 | + // Session valide en cours ? |
|
| 130 | + if (isset($_COOKIE['spip_session'])) { |
|
| 131 | + $session = charger_fonction('session', 'inc'); |
|
| 132 | + if ( |
|
| 133 | + $id_auteur = $session() |
|
| 134 | + or $id_auteur === 0 // reprise sur restauration |
|
| 135 | + ) { |
|
| 136 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 137 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 138 | + } else { |
|
| 139 | + unset($_COOKIE['spip_session']); |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // Essayer auth http si significatif |
|
| 144 | + // (ignorer les login d'intranet independants de spip) |
|
| 145 | + if (!$GLOBALS['ignore_auth_http']) { |
|
| 146 | + if ( |
|
| 147 | + (isset($_SERVER['PHP_AUTH_USER']) and isset($_SERVER['PHP_AUTH_PW']) |
|
| 148 | + and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'], $_SERVER['PHP_AUTH_PW'])) |
|
| 149 | + or |
|
| 150 | + // Si auth http differtente de basic, PHP_AUTH_PW |
|
| 151 | + // est indisponible mais tentons quand meme pour |
|
| 152 | + // autocreation via LDAP |
|
| 153 | + (isset($_SERVER['REMOTE_USER']) |
|
| 154 | + and $r = lire_php_auth($_SERVER['PHP_AUTH_USER'] = $_SERVER['REMOTE_USER'], '')) |
|
| 155 | + ) { |
|
| 156 | + if (!$id_auteur) { |
|
| 157 | + $_SERVER['PHP_AUTH_PW'] = ''; |
|
| 158 | + $GLOBALS['auth_can_disconnect'] = true; |
|
| 159 | + $GLOBALS['visiteur_session'] = $r; |
|
| 160 | + $GLOBALS['connect_login'] = session_get('login'); |
|
| 161 | + $id_auteur = $r['id_auteur']; |
|
| 162 | + } else { |
|
| 163 | + // cas de la session en plus de PHP_AUTH |
|
| 164 | + /* if ($id_auteur != $r['id_auteur']){ |
|
| 165 | 165 | spip_log("vol de session $id_auteur" . join(', ', $r)); |
| 166 | 166 | unset($_COOKIE['spip_session']); |
| 167 | 167 | $id_auteur = ''; |
| 168 | 168 | } */ |
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - // Authentification .htaccess old style, car .htaccess semble |
|
| 172 | - // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 173 | - if (isset($_SERVER['REMOTE_USER'])) { |
|
| 174 | - $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $where = (is_numeric($id_auteur) |
|
| 180 | - /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 181 | - ) ? |
|
| 182 | - "id_auteur=$id_auteur" : |
|
| 183 | - (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text')); |
|
| 184 | - |
|
| 185 | - if (!$where) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Trouver les autres infos dans la table auteurs. |
|
| 190 | - // le champ 'quand' est utilise par l'agenda |
|
| 191 | - |
|
| 192 | - return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + // Authentification .htaccess old style, car .htaccess semble |
|
| 172 | + // souvent definir *aussi* PHP_AUTH_USER et PHP_AUTH_PW |
|
| 173 | + if (isset($_SERVER['REMOTE_USER'])) { |
|
| 174 | + $GLOBALS['connect_login'] = $_SERVER['REMOTE_USER']; |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $where = (is_numeric($id_auteur) |
|
| 180 | + /*AND $id_auteur>0*/ // reprise lors des restaurations |
|
| 181 | + ) ? |
|
| 182 | + "id_auteur=$id_auteur" : |
|
| 183 | + (!strlen($GLOBALS['connect_login']) ? '' : 'login=' . sql_quote($GLOBALS['connect_login'], '', 'text')); |
|
| 184 | + |
|
| 185 | + if (!$where) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Trouver les autres infos dans la table auteurs. |
|
| 190 | + // le champ 'quand' est utilise par l'agenda |
|
| 191 | + |
|
| 192 | + return sql_fetsel('*, en_ligne AS quand', 'spip_auteurs', "$where AND statut!='5poubelle'"); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -207,86 +207,86 @@ discard block |
||
| 207 | 207 | */ |
| 208 | 208 | function auth_init_droits($row) { |
| 209 | 209 | |
| 210 | - include_spip('inc/autoriser'); |
|
| 211 | - if (!autoriser('loger', '', 0, $row)) { |
|
| 212 | - return false; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - |
|
| 216 | - if ($row['statut'] == 'nouveau') { |
|
| 217 | - include_spip('action/inscrire_auteur'); |
|
| 218 | - $row = confirmer_statut_inscription($row); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 222 | - $GLOBALS['connect_login'] = $row['login']; |
|
| 223 | - $GLOBALS['connect_statut'] = $row['statut']; |
|
| 224 | - |
|
| 225 | - $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 226 | - |
|
| 227 | - // au cas ou : ne pas memoriser les champs sensibles |
|
| 228 | - unset($GLOBALS['visiteur_session']['pass']); |
|
| 229 | - unset($GLOBALS['visiteur_session']['htpass']); |
|
| 230 | - unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 231 | - unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 232 | - unset($GLOBALS['visiteur_session']['ldap_password']); |
|
| 233 | - |
|
| 234 | - // creer la session au besoin |
|
| 235 | - if (!isset($_COOKIE['spip_session'])) { |
|
| 236 | - $session = charger_fonction('session', 'inc'); |
|
| 237 | - $spip_session = $session($row); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 241 | - // car utilisees au retour par auth_loger() |
|
| 242 | - $r = @unserialize($row['prefs']); |
|
| 243 | - $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 244 | - // si prefs pas definies, les definir par defaut |
|
| 245 | - if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 246 | - $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 247 | - $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 248 | - $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 249 | - $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui'; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - $GLOBALS['visiteur_session'] = pipeline( |
|
| 253 | - 'preparer_visiteur_session', |
|
| 254 | - ['args' => ['row' => $row], |
|
| 255 | - 'data' => $GLOBALS['visiteur_session']] |
|
| 256 | - ); |
|
| 257 | - |
|
| 258 | - // Etablir les droits selon le codage attendu |
|
| 259 | - // dans ecrire/index.php ecrire/prive.php |
|
| 260 | - |
|
| 261 | - // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 262 | - // A noter : le premier appel a autoriser() a le bon gout |
|
| 263 | - // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 264 | - // qui ne figure pas dans le fichier de session |
|
| 265 | - |
|
| 266 | - if (!autoriser('ecrire')) { |
|
| 267 | - return $row; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 271 | - |
|
| 272 | - auth_trace($row); |
|
| 273 | - |
|
| 274 | - // Administrateurs |
|
| 275 | - if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 276 | - if ( |
|
| 277 | - isset($GLOBALS['visiteur_session']['restreint']) |
|
| 278 | - and is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 279 | - ) { |
|
| 280 | - $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 281 | - } |
|
| 282 | - if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 283 | - $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 288 | - |
|
| 289 | - return ''; // i.e. pas de pb. |
|
| 210 | + include_spip('inc/autoriser'); |
|
| 211 | + if (!autoriser('loger', '', 0, $row)) { |
|
| 212 | + return false; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + |
|
| 216 | + if ($row['statut'] == 'nouveau') { |
|
| 217 | + include_spip('action/inscrire_auteur'); |
|
| 218 | + $row = confirmer_statut_inscription($row); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $GLOBALS['connect_id_auteur'] = $row['id_auteur']; |
|
| 222 | + $GLOBALS['connect_login'] = $row['login']; |
|
| 223 | + $GLOBALS['connect_statut'] = $row['statut']; |
|
| 224 | + |
|
| 225 | + $GLOBALS['visiteur_session'] = array_merge((array)$GLOBALS['visiteur_session'], $row); |
|
| 226 | + |
|
| 227 | + // au cas ou : ne pas memoriser les champs sensibles |
|
| 228 | + unset($GLOBALS['visiteur_session']['pass']); |
|
| 229 | + unset($GLOBALS['visiteur_session']['htpass']); |
|
| 230 | + unset($GLOBALS['visiteur_session']['alea_actuel']); |
|
| 231 | + unset($GLOBALS['visiteur_session']['alea_futur']); |
|
| 232 | + unset($GLOBALS['visiteur_session']['ldap_password']); |
|
| 233 | + |
|
| 234 | + // creer la session au besoin |
|
| 235 | + if (!isset($_COOKIE['spip_session'])) { |
|
| 236 | + $session = charger_fonction('session', 'inc'); |
|
| 237 | + $spip_session = $session($row); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // reinjecter les preferences_auteur apres le reset de spip_session |
|
| 241 | + // car utilisees au retour par auth_loger() |
|
| 242 | + $r = @unserialize($row['prefs']); |
|
| 243 | + $GLOBALS['visiteur_session']['prefs'] = ($r ?: []); |
|
| 244 | + // si prefs pas definies, les definir par defaut |
|
| 245 | + if (!isset($GLOBALS['visiteur_session']['prefs']['couleur'])) { |
|
| 246 | + $GLOBALS['visiteur_session']['prefs']['couleur'] = 2; |
|
| 247 | + $GLOBALS['visiteur_session']['prefs']['display'] = 2; |
|
| 248 | + $GLOBALS['visiteur_session']['prefs']['display_navigation'] = 'navigation_avec_icones'; |
|
| 249 | + $GLOBALS['visiteur_session']['prefs']['display_outils'] = 'oui'; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + $GLOBALS['visiteur_session'] = pipeline( |
|
| 253 | + 'preparer_visiteur_session', |
|
| 254 | + ['args' => ['row' => $row], |
|
| 255 | + 'data' => $GLOBALS['visiteur_session']] |
|
| 256 | + ); |
|
| 257 | + |
|
| 258 | + // Etablir les droits selon le codage attendu |
|
| 259 | + // dans ecrire/index.php ecrire/prive.php |
|
| 260 | + |
|
| 261 | + // Pas autorise a acceder a ecrire ? renvoyer le tableau |
|
| 262 | + // A noter : le premier appel a autoriser() a le bon gout |
|
| 263 | + // d'initialiser $GLOBALS['visiteur_session']['restreint'], |
|
| 264 | + // qui ne figure pas dans le fichier de session |
|
| 265 | + |
|
| 266 | + if (!autoriser('ecrire')) { |
|
| 267 | + return $row; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // autoriser('ecrire') ne laisse passer que les Admin et les Redac |
|
| 271 | + |
|
| 272 | + auth_trace($row); |
|
| 273 | + |
|
| 274 | + // Administrateurs |
|
| 275 | + if (in_array($GLOBALS['connect_statut'], explode(',', _STATUT_AUTEUR_RUBRIQUE))) { |
|
| 276 | + if ( |
|
| 277 | + isset($GLOBALS['visiteur_session']['restreint']) |
|
| 278 | + and is_array($GLOBALS['visiteur_session']['restreint']) |
|
| 279 | + ) { |
|
| 280 | + $GLOBALS['connect_id_rubrique'] = $GLOBALS['visiteur_session']['restreint']; |
|
| 281 | + } |
|
| 282 | + if ($GLOBALS['connect_statut'] == '0minirezo') { |
|
| 283 | + $GLOBALS['connect_toutes_rubriques'] = !$GLOBALS['connect_id_rubrique']; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + // Pour les redacteurs, inc_version a fait l'initialisation minimale |
|
| 288 | + |
|
| 289 | + return ''; // i.e. pas de pb. |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -295,23 +295,23 @@ discard block |
||
| 295 | 295 | * @return string |
| 296 | 296 | */ |
| 297 | 297 | function auth_a_loger() { |
| 298 | - $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), '&'); |
|
| 299 | - |
|
| 300 | - // un echec au "bonjour" (login initial) quand le statut est |
|
| 301 | - // inconnu signale sans doute un probleme de cookies |
|
| 302 | - if (isset($_GET['bonjour'])) { |
|
| 303 | - $redirect = parametre_url( |
|
| 304 | - $redirect, |
|
| 305 | - 'var_erreur', |
|
| 306 | - (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 307 | - ? 'cookie' |
|
| 308 | - : 'statut' |
|
| 309 | - ), |
|
| 310 | - '&' |
|
| 311 | - ); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $redirect; |
|
| 298 | + $redirect = generer_url_public('login', 'url=' . rawurlencode(self('&', true)), '&'); |
|
| 299 | + |
|
| 300 | + // un echec au "bonjour" (login initial) quand le statut est |
|
| 301 | + // inconnu signale sans doute un probleme de cookies |
|
| 302 | + if (isset($_GET['bonjour'])) { |
|
| 303 | + $redirect = parametre_url( |
|
| 304 | + $redirect, |
|
| 305 | + 'var_erreur', |
|
| 306 | + (!isset($GLOBALS['visiteur_session']['statut']) |
|
| 307 | + ? 'cookie' |
|
| 308 | + : 'statut' |
|
| 309 | + ), |
|
| 310 | + '&' |
|
| 311 | + ); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $redirect; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | /** |
@@ -323,19 +323,19 @@ discard block |
||
| 323 | 323 | * @param null|string $date |
| 324 | 324 | */ |
| 325 | 325 | function auth_trace($row, $date = null) { |
| 326 | - // Indiquer la connexion. A la minute pres ca suffit. |
|
| 327 | - if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 328 | - $connect_quand = strtotime($connect_quand); |
|
| 329 | - } |
|
| 326 | + // Indiquer la connexion. A la minute pres ca suffit. |
|
| 327 | + if (!is_numeric($connect_quand = $row['quand'] ?? '')) { |
|
| 328 | + $connect_quand = strtotime($connect_quand); |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - $date ??= date('Y-m-d H:i:s'); |
|
| 331 | + $date ??= date('Y-m-d H:i:s'); |
|
| 332 | 332 | |
| 333 | - if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 334 | - sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 335 | - $row['en_ligne'] = $date; |
|
| 336 | - } |
|
| 333 | + if (abs(strtotime($date) - $connect_quand) >= 60) { |
|
| 334 | + sql_updateq('spip_auteurs', ['en_ligne' => $date], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 335 | + $row['en_ligne'] = $date; |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 338 | + pipeline('trig_auth_trace', ['args' => ['row' => $row, 'date' => $date]]); |
|
| 339 | 339 | } |
| 340 | 340 | |
| 341 | 341 | |
@@ -361,28 +361,28 @@ discard block |
||
| 361 | 361 | * @return mixed |
| 362 | 362 | */ |
| 363 | 363 | function auth_administrer($fonction, $args, $defaut = false) { |
| 364 | - $auth_methode = array_shift($args); |
|
| 365 | - $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 366 | - if ( |
|
| 367 | - $auth = charger_fonction($auth_methode, 'auth', true) |
|
| 368 | - and function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 369 | - ) { |
|
| 370 | - $res = call_user_func_array($f, $args); |
|
| 371 | - } else { |
|
| 372 | - $res = $defaut; |
|
| 373 | - } |
|
| 374 | - $res = pipeline( |
|
| 375 | - 'auth_administrer', |
|
| 376 | - [ |
|
| 377 | - 'args' => [ |
|
| 378 | - 'fonction' => $fonction, |
|
| 379 | - 'methode' => $auth_methode, |
|
| 380 | - 'args' => $args |
|
| 381 | - ], |
|
| 382 | - 'data' => $res |
|
| 383 | - ] |
|
| 384 | - ); |
|
| 385 | - return $res; |
|
| 364 | + $auth_methode = array_shift($args); |
|
| 365 | + $auth_methode = $auth_methode ?: 'spip'; // valeur par defaut au cas ou |
|
| 366 | + if ( |
|
| 367 | + $auth = charger_fonction($auth_methode, 'auth', true) |
|
| 368 | + and function_exists($f = "auth_{$auth_methode}_$fonction") |
|
| 369 | + ) { |
|
| 370 | + $res = call_user_func_array($f, $args); |
|
| 371 | + } else { |
|
| 372 | + $res = $defaut; |
|
| 373 | + } |
|
| 374 | + $res = pipeline( |
|
| 375 | + 'auth_administrer', |
|
| 376 | + [ |
|
| 377 | + 'args' => [ |
|
| 378 | + 'fonction' => $fonction, |
|
| 379 | + 'methode' => $auth_methode, |
|
| 380 | + 'args' => $args |
|
| 381 | + ], |
|
| 382 | + 'data' => $res |
|
| 383 | + ] |
|
| 384 | + ); |
|
| 385 | + return $res; |
|
| 386 | 386 | } |
| 387 | 387 | |
| 388 | 388 | /** |
@@ -392,11 +392,11 @@ discard block |
||
| 392 | 392 | * @return array |
| 393 | 393 | */ |
| 394 | 394 | function auth_formulaire_login($flux) { |
| 395 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 396 | - $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 397 | - } |
|
| 395 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 396 | + $flux = auth_administrer('formulaire_login', [$methode, $flux], $flux); |
|
| 397 | + } |
|
| 398 | 398 | |
| 399 | - return $flux; |
|
| 399 | + return $flux; |
|
| 400 | 400 | } |
| 401 | 401 | |
| 402 | 402 | |
@@ -410,19 +410,19 @@ discard block |
||
| 410 | 410 | * @return string/bool |
| 411 | 411 | */ |
| 412 | 412 | function auth_retrouver_login($login, $serveur = '') { |
| 413 | - if (!spip_connect($serveur)) { |
|
| 414 | - include_spip('inc/minipres'); |
|
| 415 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 416 | - exit; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 420 | - if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 421 | - return $auteur; |
|
| 422 | - } |
|
| 423 | - } |
|
| 424 | - |
|
| 425 | - return false; |
|
| 413 | + if (!spip_connect($serveur)) { |
|
| 414 | + include_spip('inc/minipres'); |
|
| 415 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique')); |
|
| 416 | + exit; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 420 | + if ($auteur = auth_administrer('retrouver_login', [$methode, $login, $serveur])) { |
|
| 421 | + return $auteur; |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + |
|
| 425 | + return false; |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -437,52 +437,52 @@ discard block |
||
| 437 | 437 | * @return array |
| 438 | 438 | */ |
| 439 | 439 | function auth_informer_login($login, $serveur = '') { |
| 440 | - if ( |
|
| 441 | - !$login |
|
| 442 | - or !$login_base = auth_retrouver_login($login, $serveur) |
|
| 443 | - or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 444 | - ) { |
|
| 445 | - // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 446 | - // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 447 | - include_spip('inc/securiser_action'); |
|
| 448 | - $fauxalea1 = md5('fauxalea' . secret_du_site() . $login . floor(date('U') / 86400)); |
|
| 449 | - $fauxalea2 = md5('fauxalea' . secret_du_site() . $login . ceil(date('U') / 86400)); |
|
| 450 | - |
|
| 451 | - $row = [ |
|
| 452 | - 'login' => $login, |
|
| 453 | - 'cnx' => '0', |
|
| 454 | - 'logo' => '', |
|
| 455 | - 'alea_actuel' => substr_replace($fauxalea1, '.', 24, 0), |
|
| 456 | - 'alea_futur' => substr_replace($fauxalea2, '.', 24, 0) |
|
| 457 | - ]; |
|
| 458 | - |
|
| 459 | - // permettre d'autoriser l'envoi de password non crypte lorsque |
|
| 460 | - // l'auteur n'est pas (encore) declare dans SPIP, par exemple pour les cas |
|
| 461 | - // de premiere authentification via SPIP a une autre application. |
|
| 462 | - if (defined('_AUTORISER_AUTH_FAIBLE') and _AUTORISER_AUTH_FAIBLE) { |
|
| 463 | - $row['alea_actuel'] = ''; |
|
| 464 | - $row['alea_futur'] = ''; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - return $row; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - $prefs = @unserialize($row['prefs']); |
|
| 471 | - $infos = [ |
|
| 472 | - 'id_auteur' => $row['id_auteur'], |
|
| 473 | - 'login' => $row['login'], |
|
| 474 | - 'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 475 | - 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 476 | - ]; |
|
| 477 | - |
|
| 478 | - // desactiver le hash md5 si pas auteur spip ? |
|
| 479 | - if ($row['source'] !== 'spip') { |
|
| 480 | - $row['alea_actuel'] = ''; |
|
| 481 | - $row['alea_futur'] = ''; |
|
| 482 | - } |
|
| 483 | - verifier_visiteur(); |
|
| 484 | - |
|
| 485 | - return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 440 | + if ( |
|
| 441 | + !$login |
|
| 442 | + or !$login_base = auth_retrouver_login($login, $serveur) |
|
| 443 | + or !$row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login_base, $serveur, 'text'), '', '', '', '', $serveur) |
|
| 444 | + ) { |
|
| 445 | + // generer de fausses infos, mais credibles, pour eviter une attaque |
|
| 446 | + // https://core.spip.net/issues/1758 + https://core.spip.net/issues/3691 |
|
| 447 | + include_spip('inc/securiser_action'); |
|
| 448 | + $fauxalea1 = md5('fauxalea' . secret_du_site() . $login . floor(date('U') / 86400)); |
|
| 449 | + $fauxalea2 = md5('fauxalea' . secret_du_site() . $login . ceil(date('U') / 86400)); |
|
| 450 | + |
|
| 451 | + $row = [ |
|
| 452 | + 'login' => $login, |
|
| 453 | + 'cnx' => '0', |
|
| 454 | + 'logo' => '', |
|
| 455 | + 'alea_actuel' => substr_replace($fauxalea1, '.', 24, 0), |
|
| 456 | + 'alea_futur' => substr_replace($fauxalea2, '.', 24, 0) |
|
| 457 | + ]; |
|
| 458 | + |
|
| 459 | + // permettre d'autoriser l'envoi de password non crypte lorsque |
|
| 460 | + // l'auteur n'est pas (encore) declare dans SPIP, par exemple pour les cas |
|
| 461 | + // de premiere authentification via SPIP a une autre application. |
|
| 462 | + if (defined('_AUTORISER_AUTH_FAIBLE') and _AUTORISER_AUTH_FAIBLE) { |
|
| 463 | + $row['alea_actuel'] = ''; |
|
| 464 | + $row['alea_futur'] = ''; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + return $row; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + $prefs = @unserialize($row['prefs']); |
|
| 471 | + $infos = [ |
|
| 472 | + 'id_auteur' => $row['id_auteur'], |
|
| 473 | + 'login' => $row['login'], |
|
| 474 | + 'cnx' => (isset($prefs['cnx']) and $prefs['cnx'] === 'perma') ? '1' : '0', |
|
| 475 | + 'logo' => recuperer_fond('formulaires/inc-logo_auteur', $row), |
|
| 476 | + ]; |
|
| 477 | + |
|
| 478 | + // desactiver le hash md5 si pas auteur spip ? |
|
| 479 | + if ($row['source'] !== 'spip') { |
|
| 480 | + $row['alea_actuel'] = ''; |
|
| 481 | + $row['alea_futur'] = ''; |
|
| 482 | + } |
|
| 483 | + verifier_visiteur(); |
|
| 484 | + |
|
| 485 | + return auth_administrer('informer_login', [$row['source'], $infos, $row, $serveur], $infos); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | |
@@ -496,21 +496,21 @@ discard block |
||
| 496 | 496 | * @return mixed |
| 497 | 497 | */ |
| 498 | 498 | function auth_identifier_login($login, $password, $serveur = '') { |
| 499 | - $erreur = ''; |
|
| 500 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 501 | - if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 502 | - $auteur = $auth($login, $password, $serveur); |
|
| 503 | - if (is_array($auteur) and count($auteur)) { |
|
| 504 | - spip_log("connexion de $login par methode $methode"); |
|
| 505 | - $auteur['auth'] = $methode; |
|
| 506 | - return $auteur; |
|
| 507 | - } elseif (is_string($auteur)) { |
|
| 508 | - $erreur .= "$auteur "; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - } |
|
| 512 | - |
|
| 513 | - return $erreur; |
|
| 499 | + $erreur = ''; |
|
| 500 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 501 | + if ($auth = charger_fonction($methode, 'auth', true)) { |
|
| 502 | + $auteur = $auth($login, $password, $serveur); |
|
| 503 | + if (is_array($auteur) and count($auteur)) { |
|
| 504 | + spip_log("connexion de $login par methode $methode"); |
|
| 505 | + $auteur['auth'] = $methode; |
|
| 506 | + return $auteur; |
|
| 507 | + } elseif (is_string($auteur)) { |
|
| 508 | + $erreur .= "$auteur "; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + } |
|
| 512 | + |
|
| 513 | + return $erreur; |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -524,8 +524,8 @@ discard block |
||
| 524 | 524 | * @return string |
| 525 | 525 | */ |
| 526 | 526 | function auth_url_retour_login($auth_methode, $login, $redirect = '', $serveur = '') { |
| 527 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 528 | - return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 527 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 528 | + return $securiser_action('auth', "$auth_methode/$login", $redirect, true); |
|
| 529 | 529 | } |
| 530 | 530 | |
| 531 | 531 | /** |
@@ -539,9 +539,9 @@ discard block |
||
| 539 | 539 | * @return mixed |
| 540 | 540 | */ |
| 541 | 541 | function auth_terminer_identifier_login($auth_methode, $login, $serveur = '') { |
| 542 | - $args = func_get_args(); |
|
| 543 | - $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 544 | - return $auteur; |
|
| 542 | + $args = func_get_args(); |
|
| 543 | + $auteur = auth_administrer('terminer_identifier_login', $args); |
|
| 544 | + return $auteur; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | /** |
@@ -551,29 +551,29 @@ discard block |
||
| 551 | 551 | * @return bool |
| 552 | 552 | */ |
| 553 | 553 | function auth_loger($auteur) { |
| 554 | - if (!is_array($auteur) or !count($auteur)) { |
|
| 555 | - return false; |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - // initialiser et poser le cookie de session |
|
| 559 | - unset($_COOKIE['spip_session']); |
|
| 560 | - if (auth_init_droits($auteur) === false) { |
|
| 561 | - return false; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - // initialiser les prefs |
|
| 565 | - $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 566 | - $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 567 | - |
|
| 568 | - sql_updateq( |
|
| 569 | - 'spip_auteurs', |
|
| 570 | - ['prefs' => serialize($p)], |
|
| 571 | - 'id_auteur=' . intval($auteur['id_auteur']) |
|
| 572 | - ); |
|
| 573 | - |
|
| 574 | - // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 575 | - verifier_visiteur(); |
|
| 576 | - return true; |
|
| 554 | + if (!is_array($auteur) or !count($auteur)) { |
|
| 555 | + return false; |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + // initialiser et poser le cookie de session |
|
| 559 | + unset($_COOKIE['spip_session']); |
|
| 560 | + if (auth_init_droits($auteur) === false) { |
|
| 561 | + return false; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + // initialiser les prefs |
|
| 565 | + $p = $GLOBALS['visiteur_session']['prefs']; |
|
| 566 | + $p['cnx'] = (isset($auteur['cookie']) and $auteur['cookie'] == 'oui') ? 'perma' : ''; |
|
| 567 | + |
|
| 568 | + sql_updateq( |
|
| 569 | + 'spip_auteurs', |
|
| 570 | + ['prefs' => serialize($p)], |
|
| 571 | + 'id_auteur=' . intval($auteur['id_auteur']) |
|
| 572 | + ); |
|
| 573 | + |
|
| 574 | + // bloquer ici le visiteur qui tente d'abuser de ses droits |
|
| 575 | + verifier_visiteur(); |
|
| 576 | + return true; |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -583,8 +583,8 @@ discard block |
||
| 583 | 583 | * return void |
| 584 | 584 | **/ |
| 585 | 585 | function auth_deloger() { |
| 586 | - $logout = charger_fonction('logout', 'action'); |
|
| 587 | - $logout(); |
|
| 586 | + $logout = charger_fonction('logout', 'action'); |
|
| 587 | + $logout(); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -598,8 +598,8 @@ discard block |
||
| 598 | 598 | * @return bool |
| 599 | 599 | */ |
| 600 | 600 | function auth_autoriser_modifier_login($auth_methode, $serveur = '') { |
| 601 | - $args = func_get_args(); |
|
| 602 | - return auth_administrer('autoriser_modifier_login', $args); |
|
| 601 | + $args = func_get_args(); |
|
| 602 | + return auth_administrer('autoriser_modifier_login', $args); |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | /** |
@@ -614,8 +614,8 @@ discard block |
||
| 614 | 614 | * message d'erreur ou chaine vide si pas d'erreur |
| 615 | 615 | */ |
| 616 | 616 | function auth_verifier_login($auth_methode, $new_login, $id_auteur = 0, $serveur = '') { |
| 617 | - $args = func_get_args(); |
|
| 618 | - return auth_administrer('verifier_login', $args, ''); |
|
| 617 | + $args = func_get_args(); |
|
| 618 | + return auth_administrer('verifier_login', $args, ''); |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -628,8 +628,8 @@ discard block |
||
| 628 | 628 | * @return bool |
| 629 | 629 | */ |
| 630 | 630 | function auth_modifier_login($auth_methode, $new_login, $id_auteur, $serveur = '') { |
| 631 | - $args = func_get_args(); |
|
| 632 | - return auth_administrer('modifier_login', $args); |
|
| 631 | + $args = func_get_args(); |
|
| 632 | + return auth_administrer('modifier_login', $args); |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | /** |
@@ -644,8 +644,8 @@ discard block |
||
| 644 | 644 | * succès ou échec |
| 645 | 645 | */ |
| 646 | 646 | function auth_autoriser_modifier_pass($auth_methode, $serveur = '') { |
| 647 | - $args = func_get_args(); |
|
| 648 | - return auth_administrer('autoriser_modifier_pass', $args); |
|
| 647 | + $args = func_get_args(); |
|
| 648 | + return auth_administrer('autoriser_modifier_pass', $args); |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | /** |
@@ -661,8 +661,8 @@ discard block |
||
| 661 | 661 | * message d'erreur ou chaine vide si pas d'erreur |
| 662 | 662 | */ |
| 663 | 663 | function auth_verifier_pass($auth_methode, $login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 664 | - $args = func_get_args(); |
|
| 665 | - return auth_administrer('verifier_pass', $args, ''); |
|
| 664 | + $args = func_get_args(); |
|
| 665 | + return auth_administrer('verifier_pass', $args, ''); |
|
| 666 | 666 | } |
| 667 | 667 | |
| 668 | 668 | /** |
@@ -678,8 +678,8 @@ discard block |
||
| 678 | 678 | * succes ou echec |
| 679 | 679 | */ |
| 680 | 680 | function auth_modifier_pass($auth_methode, $login, $new_pass, $id_auteur, $serveur = '') { |
| 681 | - $args = func_get_args(); |
|
| 682 | - return auth_administrer('modifier_pass', $args); |
|
| 681 | + $args = func_get_args(); |
|
| 682 | + return auth_administrer('modifier_pass', $args); |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | /** |
@@ -695,24 +695,24 @@ discard block |
||
| 695 | 695 | * @return void |
| 696 | 696 | */ |
| 697 | 697 | function auth_synchroniser_distant( |
| 698 | - $auth_methode = true, |
|
| 699 | - $id_auteur = 0, |
|
| 700 | - $champs = [], |
|
| 701 | - $options = [], |
|
| 702 | - $serveur = '' |
|
| 698 | + $auth_methode = true, |
|
| 699 | + $id_auteur = 0, |
|
| 700 | + $champs = [], |
|
| 701 | + $options = [], |
|
| 702 | + $serveur = '' |
|
| 703 | 703 | ) { |
| 704 | - $args = func_get_args(); |
|
| 705 | - if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) { |
|
| 706 | - $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 707 | - $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 708 | - foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 709 | - array_shift($args); |
|
| 710 | - array_unshift($args, $methode); |
|
| 711 | - auth_administrer('synchroniser_distant', $args); |
|
| 712 | - } |
|
| 713 | - } else { |
|
| 714 | - auth_administrer('synchroniser_distant', $args); |
|
| 715 | - } |
|
| 704 | + $args = func_get_args(); |
|
| 705 | + if ($auth_methode === true or (isset($options['all']) and $options['all'] == true)) { |
|
| 706 | + $options['all'] = true; // ajouter une option all=>true pour chaque auth |
|
| 707 | + $args = [true, $id_auteur, $champs, $options, $serveur]; |
|
| 708 | + foreach ($GLOBALS['liste_des_authentifications'] as $methode) { |
|
| 709 | + array_shift($args); |
|
| 710 | + array_unshift($args, $methode); |
|
| 711 | + auth_administrer('synchroniser_distant', $args); |
|
| 712 | + } |
|
| 713 | + } else { |
|
| 714 | + auth_administrer('synchroniser_distant', $args); |
|
| 715 | + } |
|
| 716 | 716 | } |
| 717 | 717 | |
| 718 | 718 | |
@@ -725,44 +725,44 @@ discard block |
||
| 725 | 725 | * @return array|bool |
| 726 | 726 | */ |
| 727 | 727 | function lire_php_auth($login, $pw, $serveur = '') { |
| 728 | - if ( |
|
| 729 | - !$login |
|
| 730 | - or !$login = auth_retrouver_login($login, $serveur) |
|
| 731 | - ) { |
|
| 732 | - return false; |
|
| 733 | - } |
|
| 734 | - |
|
| 735 | - $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 736 | - |
|
| 737 | - if (!$row) { |
|
| 738 | - if ( |
|
| 739 | - spip_connect_ldap($serveur) |
|
| 740 | - and $auth_ldap = charger_fonction('ldap', 'auth', true) |
|
| 741 | - ) { |
|
| 742 | - return $auth_ldap($login, $pw, $serveur, true); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - return false; |
|
| 746 | - } |
|
| 747 | - // su pas de source definie |
|
| 748 | - // ou auth/xxx introuvable, utiliser 'spip' |
|
| 749 | - if ( |
|
| 750 | - !$auth_methode = $row['source'] |
|
| 751 | - or !$auth = charger_fonction($auth_methode, 'auth', true) |
|
| 752 | - ) { |
|
| 753 | - $auth = charger_fonction('spip', 'auth', true); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - $auteur = ''; |
|
| 757 | - if ($auth) { |
|
| 758 | - $auteur = $auth($login, $pw, $serveur, true); |
|
| 759 | - } |
|
| 760 | - // verifier que ce n'est pas un message d'erreur |
|
| 761 | - if (is_array($auteur) and count($auteur)) { |
|
| 762 | - return $auteur; |
|
| 763 | - } |
|
| 764 | - |
|
| 765 | - return false; |
|
| 728 | + if ( |
|
| 729 | + !$login |
|
| 730 | + or !$login = auth_retrouver_login($login, $serveur) |
|
| 731 | + ) { |
|
| 732 | + return false; |
|
| 733 | + } |
|
| 734 | + |
|
| 735 | + $row = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login, $serveur, 'text'), '', '', '', '', $serveur); |
|
| 736 | + |
|
| 737 | + if (!$row) { |
|
| 738 | + if ( |
|
| 739 | + spip_connect_ldap($serveur) |
|
| 740 | + and $auth_ldap = charger_fonction('ldap', 'auth', true) |
|
| 741 | + ) { |
|
| 742 | + return $auth_ldap($login, $pw, $serveur, true); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + return false; |
|
| 746 | + } |
|
| 747 | + // su pas de source definie |
|
| 748 | + // ou auth/xxx introuvable, utiliser 'spip' |
|
| 749 | + if ( |
|
| 750 | + !$auth_methode = $row['source'] |
|
| 751 | + or !$auth = charger_fonction($auth_methode, 'auth', true) |
|
| 752 | + ) { |
|
| 753 | + $auth = charger_fonction('spip', 'auth', true); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + $auteur = ''; |
|
| 757 | + if ($auth) { |
|
| 758 | + $auteur = $auth($login, $pw, $serveur, true); |
|
| 759 | + } |
|
| 760 | + // verifier que ce n'est pas un message d'erreur |
|
| 761 | + if (is_array($auteur) and count($auteur)) { |
|
| 762 | + return $auteur; |
|
| 763 | + } |
|
| 764 | + |
|
| 765 | + return false; |
|
| 766 | 766 | } |
| 767 | 767 | |
| 768 | 768 | /** |
@@ -778,21 +778,21 @@ discard block |
||
| 778 | 778 | * @param string $lien |
| 779 | 779 | */ |
| 780 | 780 | function ask_php_auth($pb, $raison, $retour = '', $url = '', $re = '', $lien = '') { |
| 781 | - @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 782 | - @Header('HTTP/1.0 401 Unauthorized'); |
|
| 783 | - $corps = ''; |
|
| 784 | - $public = generer_url_public(); |
|
| 785 | - $ecrire = generer_url_ecrire(); |
|
| 786 | - $retour = $retour ?: _T('icone_retour'); |
|
| 787 | - $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 788 | - if ($url) { |
|
| 789 | - $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - if ($lien) { |
|
| 793 | - $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 794 | - } |
|
| 795 | - include_spip('inc/minipres'); |
|
| 796 | - echo minipres($pb, $corps); |
|
| 797 | - exit; |
|
| 781 | + @Header('WWW-Authenticate: Basic realm="espace prive"'); |
|
| 782 | + @Header('HTTP/1.0 401 Unauthorized'); |
|
| 783 | + $corps = ''; |
|
| 784 | + $public = generer_url_public(); |
|
| 785 | + $ecrire = generer_url_ecrire(); |
|
| 786 | + $retour = $retour ?: _T('icone_retour'); |
|
| 787 | + $corps .= "<p>$raison</p>[<a href='$public'>$retour</a>] "; |
|
| 788 | + if ($url) { |
|
| 789 | + $corps .= "[<a href='" . generer_url_action('cookie', "essai_auth_http=oui&$url") . "'>$re</a>]"; |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + if ($lien) { |
|
| 793 | + $corps .= " [<a href='$ecrire'>" . _T('login_espace_prive') . '</a>]'; |
|
| 794 | + } |
|
| 795 | + include_spip('inc/minipres'); |
|
| 796 | + echo minipres($pb, $corps); |
|
| 797 | + exit; |
|
| 798 | 798 | } |
@@ -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 | /** |
@@ -250,11 +250,11 @@ discard block |
||
| 250 | 250 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 251 | 251 | */ |
| 252 | 252 | function statut_effacer_images_temporaires($stat) { |
| 253 | - static $statut = false; // par defaut on grave toute les images |
|
| 254 | - if ($stat === 'get') { |
|
| 255 | - return $statut; |
|
| 256 | - } |
|
| 257 | - $statut = $stat ? true : false; |
|
| 253 | + static $statut = false; // par defaut on grave toute les images |
|
| 254 | + if ($stat === 'get') { |
|
| 255 | + return $statut; |
|
| 256 | + } |
|
| 257 | + $statut = $stat ? true : false; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -307,243 +307,243 @@ discard block |
||
| 307 | 307 | * - array : tableau décrivant de l'image |
| 308 | 308 | */ |
| 309 | 309 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 310 | - $ret = []; |
|
| 311 | - $f = null; |
|
| 312 | - static $images_recalcul = []; |
|
| 313 | - if (strlen($img) == 0) { |
|
| 314 | - return false; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 318 | - if (strlen($source) < 1) { |
|
| 319 | - $source = $img; |
|
| 320 | - $img = "<img src='$source' />"; |
|
| 321 | - } elseif ( |
|
| 322 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 323 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 325 | - ) { |
|
| 326 | - # gerer img src="data:....base64" |
|
| 327 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | - if (!file_exists($local)) { |
|
| 329 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 330 | - } |
|
| 331 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 332 | - $sanitizer($local); |
|
| 333 | - } |
|
| 334 | - $source = $local; |
|
| 335 | - $img = inserer_attribut($img, 'src', $source); |
|
| 336 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 337 | - $img = inserer_attribut($img, 'width', ''); |
|
| 338 | - $img = inserer_attribut($img, 'height', ''); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // les protocoles web prennent au moins 3 lettres |
|
| 342 | - if (tester_url_absolue($source)) { |
|
| 343 | - include_spip('inc/distant'); |
|
| 344 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | - if (!$fichier) { |
|
| 346 | - return ''; |
|
| 347 | - } |
|
| 348 | - if ( |
|
| 349 | - $extension = _image_trouver_extension($fichier) |
|
| 350 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 351 | - ) { |
|
| 352 | - $sanitizer($fichier); |
|
| 353 | - } |
|
| 354 | - } else { |
|
| 355 | - // enlever le timestamp eventuel |
|
| 356 | - if (strpos($source, '?') !== false) { |
|
| 357 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 358 | - } |
|
| 359 | - if ( |
|
| 360 | - strpos($source, '?') !== false |
|
| 361 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 362 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 363 | - ) { |
|
| 364 | - $source = $f; |
|
| 365 | - } |
|
| 366 | - $fichier = $source; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $terminaison_dest = ''; |
|
| 370 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 371 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - if ( |
|
| 375 | - $forcer_format !== false |
|
| 376 | - // 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 |
|
| 377 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 378 | - ) { |
|
| 379 | - $terminaison_dest = $forcer_format; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - if (!$terminaison_dest) { |
|
| 383 | - return false; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 387 | - $fichier_dest = $nom_fichier; |
|
| 388 | - if ( |
|
| 389 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 390 | - or @file_exists($f = $fichier) |
|
| 391 | - ) { |
|
| 392 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 393 | - // au lieu de faire un acces disque sur le fichier |
|
| 394 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 395 | - $date_src = @filemtime($f); |
|
| 396 | - } elseif ( |
|
| 397 | - @file_exists($f = "$fichier.src") |
|
| 398 | - and lire_fichier($f, $valeurs) |
|
| 399 | - and $valeurs = unserialize($valeurs) |
|
| 400 | - and isset($valeurs['hauteur_dest']) |
|
| 401 | - and isset($valeurs['largeur_dest']) |
|
| 402 | - ) { |
|
| 403 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 404 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 405 | - $date_src = $valeurs['date']; |
|
| 406 | - } // pas de fichier source par la |
|
| 407 | - else { |
|
| 408 | - return false; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - // pas de taille mesurable |
|
| 412 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 413 | - return false; |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - // les images calculees dependent du chemin du fichier source |
|
| 417 | - // 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 |
|
| 418 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 419 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 420 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 421 | - // alors que ca concerne peu de site au final |
|
| 422 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 423 | - $identifiant = $fichier; |
|
| 424 | - |
|
| 425 | - // cas general : |
|
| 426 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 427 | - // cas particulier de reduire : |
|
| 428 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 429 | - $cache = 'cache-gd2'; |
|
| 430 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 431 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 432 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 433 | - $ret['largeur_dest'] = $destWidth; |
|
| 434 | - $ret['hauteur_dest'] = $destHeight; |
|
| 435 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 436 | - $cache = 'cache-vignettes'; |
|
| 437 | - $fichier_dest = basename($fichier_dest); |
|
| 438 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 439 | - // on garde la terminaison initiale car image simplement copiee |
|
| 440 | - // et on postfixe son nom avec un md5 du path |
|
| 441 | - $terminaison_dest = $terminaison; |
|
| 442 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 443 | - } else { |
|
| 444 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 445 | - } |
|
| 446 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 447 | - $cache = sous_repertoire($cache, $effet); |
|
| 448 | - } else { |
|
| 449 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 450 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 451 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 452 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 456 | - |
|
| 457 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 458 | - |
|
| 459 | - $creer = true; |
|
| 460 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 461 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 462 | - $images_recalcul[$fichier_dest] = true; |
|
| 463 | - } else { |
|
| 464 | - if (@file_exists($f = $fichier_dest)) { |
|
| 465 | - if (filemtime($f) >= $date_src) { |
|
| 466 | - $creer = false; |
|
| 467 | - } |
|
| 468 | - } else { |
|
| 469 | - if ( |
|
| 470 | - @file_exists($f = "$fichier_dest.src") |
|
| 471 | - and lire_fichier($f, $valeurs) |
|
| 472 | - and $valeurs = unserialize($valeurs) |
|
| 473 | - and $valeurs['date'] >= $date_src |
|
| 474 | - ) { |
|
| 475 | - $creer = false; |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - if ($creer) { |
|
| 480 | - if (!@file_exists($fichier)) { |
|
| 481 | - if (!@file_exists("$fichier.src")) { |
|
| 482 | - spip_log("Image absente : $fichier"); |
|
| 483 | - |
|
| 484 | - return false; |
|
| 485 | - } |
|
| 486 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 487 | - reconstruire_image_intermediaire($fichier); |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - if ($creer) { |
|
| 492 | - spip_log( |
|
| 493 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 494 | - 'images' . _LOG_DEBUG |
|
| 495 | - ); |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 499 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | - $ret['fichier'] = $fichier; |
|
| 501 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 503 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 504 | - $ret['format_dest'] = $terminaison_dest; |
|
| 505 | - $ret['date_src'] = $date_src; |
|
| 506 | - $ret['creer'] = $creer; |
|
| 507 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 508 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 509 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 510 | - $ret['tag'] = $img; |
|
| 511 | - if ($fonction_creation) { |
|
| 512 | - $ret['reconstruction'] = $fonction_creation; |
|
| 513 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 514 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 515 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 516 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 517 | - } |
|
| 518 | - |
|
| 519 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 520 | - 'args' => [ |
|
| 521 | - 'img' => $img, |
|
| 522 | - 'effet' => $effet, |
|
| 523 | - 'forcer_format' => $forcer_format, |
|
| 524 | - 'fonction_creation' => $fonction_creation, |
|
| 525 | - 'find_in_path' => $find_in_path, |
|
| 526 | - ], |
|
| 527 | - 'data' => $ret |
|
| 528 | - ]); |
|
| 529 | - |
|
| 530 | - // une globale pour le debug en cas de crash memoire |
|
| 531 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 532 | - |
|
| 533 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 534 | - if ($term_fonction === 'svg') { |
|
| 535 | - if ($creer and !$support_svg) { |
|
| 536 | - process_image_svg_identite($ret); |
|
| 537 | - $ret['creer'] = false; |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - else { |
|
| 541 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 542 | - return false; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - return $ret; |
|
| 310 | + $ret = []; |
|
| 311 | + $f = null; |
|
| 312 | + static $images_recalcul = []; |
|
| 313 | + if (strlen($img) == 0) { |
|
| 314 | + return false; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 318 | + if (strlen($source) < 1) { |
|
| 319 | + $source = $img; |
|
| 320 | + $img = "<img src='$source' />"; |
|
| 321 | + } elseif ( |
|
| 322 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 323 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 325 | + ) { |
|
| 326 | + # gerer img src="data:....base64" |
|
| 327 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | + if (!file_exists($local)) { |
|
| 329 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 330 | + } |
|
| 331 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 332 | + $sanitizer($local); |
|
| 333 | + } |
|
| 334 | + $source = $local; |
|
| 335 | + $img = inserer_attribut($img, 'src', $source); |
|
| 336 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 337 | + $img = inserer_attribut($img, 'width', ''); |
|
| 338 | + $img = inserer_attribut($img, 'height', ''); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // les protocoles web prennent au moins 3 lettres |
|
| 342 | + if (tester_url_absolue($source)) { |
|
| 343 | + include_spip('inc/distant'); |
|
| 344 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | + if (!$fichier) { |
|
| 346 | + return ''; |
|
| 347 | + } |
|
| 348 | + if ( |
|
| 349 | + $extension = _image_trouver_extension($fichier) |
|
| 350 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 351 | + ) { |
|
| 352 | + $sanitizer($fichier); |
|
| 353 | + } |
|
| 354 | + } else { |
|
| 355 | + // enlever le timestamp eventuel |
|
| 356 | + if (strpos($source, '?') !== false) { |
|
| 357 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 358 | + } |
|
| 359 | + if ( |
|
| 360 | + strpos($source, '?') !== false |
|
| 361 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 362 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 363 | + ) { |
|
| 364 | + $source = $f; |
|
| 365 | + } |
|
| 366 | + $fichier = $source; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $terminaison_dest = ''; |
|
| 370 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 371 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + if ( |
|
| 375 | + $forcer_format !== false |
|
| 376 | + // 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 |
|
| 377 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 378 | + ) { |
|
| 379 | + $terminaison_dest = $forcer_format; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + if (!$terminaison_dest) { |
|
| 383 | + return false; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 387 | + $fichier_dest = $nom_fichier; |
|
| 388 | + if ( |
|
| 389 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 390 | + or @file_exists($f = $fichier) |
|
| 391 | + ) { |
|
| 392 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 393 | + // au lieu de faire un acces disque sur le fichier |
|
| 394 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 395 | + $date_src = @filemtime($f); |
|
| 396 | + } elseif ( |
|
| 397 | + @file_exists($f = "$fichier.src") |
|
| 398 | + and lire_fichier($f, $valeurs) |
|
| 399 | + and $valeurs = unserialize($valeurs) |
|
| 400 | + and isset($valeurs['hauteur_dest']) |
|
| 401 | + and isset($valeurs['largeur_dest']) |
|
| 402 | + ) { |
|
| 403 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 404 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 405 | + $date_src = $valeurs['date']; |
|
| 406 | + } // pas de fichier source par la |
|
| 407 | + else { |
|
| 408 | + return false; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + // pas de taille mesurable |
|
| 412 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 413 | + return false; |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + // les images calculees dependent du chemin du fichier source |
|
| 417 | + // 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 |
|
| 418 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 419 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 420 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 421 | + // alors que ca concerne peu de site au final |
|
| 422 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 423 | + $identifiant = $fichier; |
|
| 424 | + |
|
| 425 | + // cas general : |
|
| 426 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 427 | + // cas particulier de reduire : |
|
| 428 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 429 | + $cache = 'cache-gd2'; |
|
| 430 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 431 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 432 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 433 | + $ret['largeur_dest'] = $destWidth; |
|
| 434 | + $ret['hauteur_dest'] = $destHeight; |
|
| 435 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 436 | + $cache = 'cache-vignettes'; |
|
| 437 | + $fichier_dest = basename($fichier_dest); |
|
| 438 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 439 | + // on garde la terminaison initiale car image simplement copiee |
|
| 440 | + // et on postfixe son nom avec un md5 du path |
|
| 441 | + $terminaison_dest = $terminaison; |
|
| 442 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 443 | + } else { |
|
| 444 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 445 | + } |
|
| 446 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 447 | + $cache = sous_repertoire($cache, $effet); |
|
| 448 | + } else { |
|
| 449 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 450 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 451 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 452 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 456 | + |
|
| 457 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 458 | + |
|
| 459 | + $creer = true; |
|
| 460 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 461 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 462 | + $images_recalcul[$fichier_dest] = true; |
|
| 463 | + } else { |
|
| 464 | + if (@file_exists($f = $fichier_dest)) { |
|
| 465 | + if (filemtime($f) >= $date_src) { |
|
| 466 | + $creer = false; |
|
| 467 | + } |
|
| 468 | + } else { |
|
| 469 | + if ( |
|
| 470 | + @file_exists($f = "$fichier_dest.src") |
|
| 471 | + and lire_fichier($f, $valeurs) |
|
| 472 | + and $valeurs = unserialize($valeurs) |
|
| 473 | + and $valeurs['date'] >= $date_src |
|
| 474 | + ) { |
|
| 475 | + $creer = false; |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + if ($creer) { |
|
| 480 | + if (!@file_exists($fichier)) { |
|
| 481 | + if (!@file_exists("$fichier.src")) { |
|
| 482 | + spip_log("Image absente : $fichier"); |
|
| 483 | + |
|
| 484 | + return false; |
|
| 485 | + } |
|
| 486 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 487 | + reconstruire_image_intermediaire($fichier); |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($creer) { |
|
| 492 | + spip_log( |
|
| 493 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 494 | + 'images' . _LOG_DEBUG |
|
| 495 | + ); |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 499 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | + $ret['fichier'] = $fichier; |
|
| 501 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 503 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 504 | + $ret['format_dest'] = $terminaison_dest; |
|
| 505 | + $ret['date_src'] = $date_src; |
|
| 506 | + $ret['creer'] = $creer; |
|
| 507 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 508 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 509 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 510 | + $ret['tag'] = $img; |
|
| 511 | + if ($fonction_creation) { |
|
| 512 | + $ret['reconstruction'] = $fonction_creation; |
|
| 513 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 514 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 515 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 516 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 517 | + } |
|
| 518 | + |
|
| 519 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 520 | + 'args' => [ |
|
| 521 | + 'img' => $img, |
|
| 522 | + 'effet' => $effet, |
|
| 523 | + 'forcer_format' => $forcer_format, |
|
| 524 | + 'fonction_creation' => $fonction_creation, |
|
| 525 | + 'find_in_path' => $find_in_path, |
|
| 526 | + ], |
|
| 527 | + 'data' => $ret |
|
| 528 | + ]); |
|
| 529 | + |
|
| 530 | + // une globale pour le debug en cas de crash memoire |
|
| 531 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 532 | + |
|
| 533 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 534 | + if ($term_fonction === 'svg') { |
|
| 535 | + if ($creer and !$support_svg) { |
|
| 536 | + process_image_svg_identite($ret); |
|
| 537 | + $ret['creer'] = false; |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + else { |
|
| 541 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 542 | + return false; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + return $ret; |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | |
@@ -552,53 +552,53 @@ discard block |
||
| 552 | 552 | * @return array |
| 553 | 553 | */ |
| 554 | 554 | function _image_extensions_acceptees_en_entree() { |
| 555 | - static $extensions = null; |
|
| 556 | - if (empty($extensions)) { |
|
| 557 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 558 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 559 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 560 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 561 | - $extensions = array_map('trim', $extensions); |
|
| 562 | - $extensions = array_filter($extensions); |
|
| 563 | - $extensions = array_unique($extensions); |
|
| 564 | - if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 565 | - } |
|
| 566 | - } |
|
| 567 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - return $extensions; |
|
| 555 | + static $extensions = null; |
|
| 556 | + if (empty($extensions)) { |
|
| 557 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 558 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 559 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 560 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 561 | + $extensions = array_map('trim', $extensions); |
|
| 562 | + $extensions = array_filter($extensions); |
|
| 563 | + $extensions = array_unique($extensions); |
|
| 564 | + if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 565 | + } |
|
| 566 | + } |
|
| 567 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + return $extensions; |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | /** |
| 574 | 574 | * @return array|string[]|null |
| 575 | 575 | */ |
| 576 | 576 | function _image_extensions_acceptees_en_sortie() { |
| 577 | - static $extensions = null; |
|
| 578 | - if (empty($extensions)) { |
|
| 579 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 580 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 581 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 582 | - $extensions = array_diff($extensions, ['gif']); |
|
| 583 | - } |
|
| 584 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 585 | - $extensions = array_diff($extensions, ['webp']); |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - |
|
| 589 | - return $extensions; |
|
| 577 | + static $extensions = null; |
|
| 578 | + if (empty($extensions)) { |
|
| 579 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 580 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 581 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 582 | + $extensions = array_diff($extensions, ['gif']); |
|
| 583 | + } |
|
| 584 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 585 | + $extensions = array_diff($extensions, ['webp']); |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + |
|
| 589 | + return $extensions; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | function _image_extension_normalisee($extension) { |
| 593 | - $extension = strtolower($extension); |
|
| 594 | - if ($extension === 'jpeg') { |
|
| 595 | - $extension = 'jpg'; |
|
| 596 | - } |
|
| 597 | - return $extension; |
|
| 593 | + $extension = strtolower($extension); |
|
| 594 | + if ($extension === 'jpeg') { |
|
| 595 | + $extension = 'jpg'; |
|
| 596 | + } |
|
| 597 | + return $extension; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | function _image_extensions_conservent_transparence() { |
| 601 | - return ['png', 'webp']; |
|
| 601 | + return ['png', 'webp']; |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | |
@@ -608,12 +608,12 @@ discard block |
||
| 608 | 608 | * @return string |
| 609 | 609 | */ |
| 610 | 610 | function _image_trouver_extension($path) { |
| 611 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 612 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 613 | - $terminaison = strtolower($regs[1]); |
|
| 614 | - return $terminaison; |
|
| 615 | - } |
|
| 616 | - return ''; |
|
| 611 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 612 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 613 | + $terminaison = strtolower($regs[1]); |
|
| 614 | + return $terminaison; |
|
| 615 | + } |
|
| 616 | + return ''; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | /** |
@@ -624,33 +624,33 @@ discard block |
||
| 624 | 624 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 625 | 625 | */ |
| 626 | 626 | function _image_trouver_extension_pertinente($path) { |
| 627 | - $path = supprimer_timestamp($path); |
|
| 628 | - $terminaison = _image_trouver_extension($path); |
|
| 629 | - if ($terminaison == 'jpg') { |
|
| 630 | - $terminaison = 'jpeg'; |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - if (!file_exists($path)) { |
|
| 634 | - return $terminaison; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - if (!$info = @spip_getimagesize($path)) { |
|
| 638 | - return $terminaison; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - if (isset($info['mime'])) { |
|
| 642 | - $mime = $info['mime']; |
|
| 643 | - } |
|
| 644 | - else { |
|
| 645 | - $mime = image_type_to_mime_type($info[2]); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 649 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 650 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 651 | - $terminaison = $_terminaison; |
|
| 652 | - } |
|
| 653 | - return $terminaison; |
|
| 627 | + $path = supprimer_timestamp($path); |
|
| 628 | + $terminaison = _image_trouver_extension($path); |
|
| 629 | + if ($terminaison == 'jpg') { |
|
| 630 | + $terminaison = 'jpeg'; |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + if (!file_exists($path)) { |
|
| 634 | + return $terminaison; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + if (!$info = @spip_getimagesize($path)) { |
|
| 638 | + return $terminaison; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + if (isset($info['mime'])) { |
|
| 642 | + $mime = $info['mime']; |
|
| 643 | + } |
|
| 644 | + else { |
|
| 645 | + $mime = image_type_to_mime_type($info[2]); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 649 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 650 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 651 | + $terminaison = $_terminaison; |
|
| 652 | + } |
|
| 653 | + return $terminaison; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -658,36 +658,36 @@ discard block |
||
| 658 | 658 | * @return string |
| 659 | 659 | */ |
| 660 | 660 | function _image_trouver_extension_depuis_mime($mime) { |
| 661 | - switch (strtolower($mime)) { |
|
| 662 | - case 'image/png': |
|
| 663 | - case 'image/x-png': |
|
| 664 | - $terminaison = 'png'; |
|
| 665 | - break; |
|
| 666 | - |
|
| 667 | - case 'image/jpg': |
|
| 668 | - case 'image/jpeg': |
|
| 669 | - case 'image/pjpeg': |
|
| 670 | - $terminaison = 'jpeg'; |
|
| 671 | - break; |
|
| 672 | - |
|
| 673 | - case 'image/gif': |
|
| 674 | - $terminaison = 'gif'; |
|
| 675 | - break; |
|
| 676 | - |
|
| 677 | - case 'image/webp': |
|
| 678 | - case 'image/x-webp': |
|
| 679 | - $terminaison = 'webp'; |
|
| 680 | - break; |
|
| 681 | - |
|
| 682 | - case 'image/svg+xml': |
|
| 683 | - $terminaison = 'svg'; |
|
| 684 | - break; |
|
| 685 | - |
|
| 686 | - default: |
|
| 687 | - $terminaison = ''; |
|
| 688 | - } |
|
| 689 | - |
|
| 690 | - return $terminaison; |
|
| 661 | + switch (strtolower($mime)) { |
|
| 662 | + case 'image/png': |
|
| 663 | + case 'image/x-png': |
|
| 664 | + $terminaison = 'png'; |
|
| 665 | + break; |
|
| 666 | + |
|
| 667 | + case 'image/jpg': |
|
| 668 | + case 'image/jpeg': |
|
| 669 | + case 'image/pjpeg': |
|
| 670 | + $terminaison = 'jpeg'; |
|
| 671 | + break; |
|
| 672 | + |
|
| 673 | + case 'image/gif': |
|
| 674 | + $terminaison = 'gif'; |
|
| 675 | + break; |
|
| 676 | + |
|
| 677 | + case 'image/webp': |
|
| 678 | + case 'image/x-webp': |
|
| 679 | + $terminaison = 'webp'; |
|
| 680 | + break; |
|
| 681 | + |
|
| 682 | + case 'image/svg+xml': |
|
| 683 | + $terminaison = 'svg'; |
|
| 684 | + break; |
|
| 685 | + |
|
| 686 | + default: |
|
| 687 | + $terminaison = ''; |
|
| 688 | + } |
|
| 689 | + |
|
| 690 | + return $terminaison; |
|
| 691 | 691 | } |
| 692 | 692 | |
| 693 | 693 | |
@@ -707,18 +707,18 @@ discard block |
||
| 707 | 707 | * Une ressource de type Image GD. |
| 708 | 708 | */ |
| 709 | 709 | function _imagecreatefrom_func(string $func, string $filename) { |
| 710 | - if (!function_exists($func)) { |
|
| 711 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 712 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 713 | - return null; |
|
| 714 | - } |
|
| 715 | - $img = @$func($filename); |
|
| 716 | - if (!$img) { |
|
| 717 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 718 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 719 | - $img = imagecreate(10, 10); |
|
| 720 | - } |
|
| 721 | - return $img; |
|
| 710 | + if (!function_exists($func)) { |
|
| 711 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 712 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 713 | + return null; |
|
| 714 | + } |
|
| 715 | + $img = @$func($filename); |
|
| 716 | + if (!$img) { |
|
| 717 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 718 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 719 | + $img = imagecreate(10, 10); |
|
| 720 | + } |
|
| 721 | + return $img; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | /** |
@@ -734,7 +734,7 @@ discard block |
||
| 734 | 734 | * Une ressource de type Image GD. |
| 735 | 735 | */ |
| 736 | 736 | function _imagecreatefromjpeg($filename) { |
| 737 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 737 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 738 | 738 | } |
| 739 | 739 | |
| 740 | 740 | /** |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | * Une ressource de type Image GD. |
| 751 | 751 | */ |
| 752 | 752 | function _imagecreatefrompng($filename) { |
| 753 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 753 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 754 | 754 | } |
| 755 | 755 | |
| 756 | 756 | /** |
@@ -766,7 +766,7 @@ discard block |
||
| 766 | 766 | * Une ressource de type Image GD. |
| 767 | 767 | */ |
| 768 | 768 | function _imagecreatefromgif($filename) { |
| 769 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 769 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 770 | 770 | } |
| 771 | 771 | |
| 772 | 772 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | * Une ressource de type Image GD. |
| 784 | 784 | */ |
| 785 | 785 | function _imagecreatefromwebp($filename) { |
| 786 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 786 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 787 | 787 | } |
| 788 | 788 | |
| 789 | 789 | /** |
@@ -801,24 +801,24 @@ discard block |
||
| 801 | 801 | * - true si une image est bien retournée. |
| 802 | 802 | */ |
| 803 | 803 | function _image_imagepng($img, $fichier) { |
| 804 | - if (!function_exists('imagepng')) { |
|
| 805 | - return false; |
|
| 806 | - } |
|
| 807 | - $tmp = $fichier . '.tmp'; |
|
| 808 | - $ret = imagepng($img, $tmp); |
|
| 809 | - if (file_exists($tmp)) { |
|
| 810 | - $taille_test = getimagesize($tmp); |
|
| 811 | - if ($taille_test[0] < 1) { |
|
| 812 | - return false; |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 816 | - @rename($tmp, $fichier); |
|
| 817 | - |
|
| 818 | - return $ret; |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - return false; |
|
| 804 | + if (!function_exists('imagepng')) { |
|
| 805 | + return false; |
|
| 806 | + } |
|
| 807 | + $tmp = $fichier . '.tmp'; |
|
| 808 | + $ret = imagepng($img, $tmp); |
|
| 809 | + if (file_exists($tmp)) { |
|
| 810 | + $taille_test = getimagesize($tmp); |
|
| 811 | + if ($taille_test[0] < 1) { |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 816 | + @rename($tmp, $fichier); |
|
| 817 | + |
|
| 818 | + return $ret; |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + return false; |
|
| 822 | 822 | } |
| 823 | 823 | |
| 824 | 824 | /** |
@@ -836,24 +836,24 @@ discard block |
||
| 836 | 836 | * - true si une image est bien retournée. |
| 837 | 837 | */ |
| 838 | 838 | function _image_imagegif($img, $fichier) { |
| 839 | - if (!function_exists('imagegif')) { |
|
| 840 | - return false; |
|
| 841 | - } |
|
| 842 | - $tmp = $fichier . '.tmp'; |
|
| 843 | - $ret = imagegif($img, $tmp); |
|
| 844 | - if (file_exists($tmp)) { |
|
| 845 | - $taille_test = getimagesize($tmp); |
|
| 846 | - if ($taille_test[0] < 1) { |
|
| 847 | - return false; |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 851 | - @rename($tmp, $fichier); |
|
| 852 | - |
|
| 853 | - return $ret; |
|
| 854 | - } |
|
| 855 | - |
|
| 856 | - return false; |
|
| 839 | + if (!function_exists('imagegif')) { |
|
| 840 | + return false; |
|
| 841 | + } |
|
| 842 | + $tmp = $fichier . '.tmp'; |
|
| 843 | + $ret = imagegif($img, $tmp); |
|
| 844 | + if (file_exists($tmp)) { |
|
| 845 | + $taille_test = getimagesize($tmp); |
|
| 846 | + if ($taille_test[0] < 1) { |
|
| 847 | + return false; |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 851 | + @rename($tmp, $fichier); |
|
| 852 | + |
|
| 853 | + return $ret; |
|
| 854 | + } |
|
| 855 | + |
|
| 856 | + return false; |
|
| 857 | 857 | } |
| 858 | 858 | |
| 859 | 859 | /** |
@@ -876,29 +876,29 @@ discard block |
||
| 876 | 876 | * - true si une image est bien retournée. |
| 877 | 877 | */ |
| 878 | 878 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 879 | - if (!function_exists('imagejpeg')) { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 882 | - $tmp = $fichier . '.tmp'; |
|
| 879 | + if (!function_exists('imagejpeg')) { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | + $tmp = $fichier . '.tmp'; |
|
| 883 | 883 | |
| 884 | - // Enable interlancing |
|
| 885 | - imageinterlace($img, true); |
|
| 884 | + // Enable interlancing |
|
| 885 | + imageinterlace($img, true); |
|
| 886 | 886 | |
| 887 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 887 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 888 | 888 | |
| 889 | - if (file_exists($tmp)) { |
|
| 890 | - $taille_test = getimagesize($tmp); |
|
| 891 | - if ($taille_test[0] < 1) { |
|
| 892 | - return false; |
|
| 893 | - } |
|
| 889 | + if (file_exists($tmp)) { |
|
| 890 | + $taille_test = getimagesize($tmp); |
|
| 891 | + if ($taille_test[0] < 1) { |
|
| 892 | + return false; |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 896 | - @rename($tmp, $fichier); |
|
| 895 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 896 | + @rename($tmp, $fichier); |
|
| 897 | 897 | |
| 898 | - return $ret; |
|
| 899 | - } |
|
| 898 | + return $ret; |
|
| 899 | + } |
|
| 900 | 900 | |
| 901 | - return false; |
|
| 901 | + return false; |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | /** |
@@ -916,9 +916,9 @@ discard block |
||
| 916 | 916 | * true si le fichier a bien été créé ; false sinon. |
| 917 | 917 | */ |
| 918 | 918 | function _image_imageico($img, $fichier) { |
| 919 | - $gd_image_array = [$img]; |
|
| 919 | + $gd_image_array = [$img]; |
|
| 920 | 920 | |
| 921 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 921 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 922 | 922 | } |
| 923 | 923 | |
| 924 | 924 | |
@@ -937,24 +937,24 @@ discard block |
||
| 937 | 937 | * - true si une image est bien retournée. |
| 938 | 938 | */ |
| 939 | 939 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 940 | - if (!function_exists('imagewebp')) { |
|
| 941 | - return false; |
|
| 942 | - } |
|
| 943 | - $tmp = $fichier . '.tmp'; |
|
| 944 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 945 | - if (file_exists($tmp)) { |
|
| 946 | - $taille_test = getimagesize($tmp); |
|
| 947 | - if ($taille_test[0] < 1) { |
|
| 948 | - return false; |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 952 | - @rename($tmp, $fichier); |
|
| 953 | - |
|
| 954 | - return $ret; |
|
| 955 | - } |
|
| 956 | - |
|
| 957 | - return false; |
|
| 940 | + if (!function_exists('imagewebp')) { |
|
| 941 | + return false; |
|
| 942 | + } |
|
| 943 | + $tmp = $fichier . '.tmp'; |
|
| 944 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 945 | + if (file_exists($tmp)) { |
|
| 946 | + $taille_test = getimagesize($tmp); |
|
| 947 | + if ($taille_test[0] < 1) { |
|
| 948 | + return false; |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 952 | + @rename($tmp, $fichier); |
|
| 953 | + |
|
| 954 | + return $ret; |
|
| 955 | + } |
|
| 956 | + |
|
| 957 | + return false; |
|
| 958 | 958 | } |
| 959 | 959 | |
| 960 | 960 | /** |
@@ -974,35 +974,35 @@ discard block |
||
| 974 | 974 | */ |
| 975 | 975 | function _image_imagesvg($img, $fichier) { |
| 976 | 976 | |
| 977 | - $tmp = $fichier . '.tmp'; |
|
| 978 | - if (strpos($img, '<') === false) { |
|
| 979 | - $img = supprimer_timestamp($img); |
|
| 980 | - if (!file_exists($img)) { |
|
| 981 | - return false; |
|
| 982 | - } |
|
| 983 | - @copy($img, $tmp); |
|
| 984 | - if (filesize($tmp) == filesize($img)) { |
|
| 985 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 986 | - @rename($tmp, $fichier); |
|
| 987 | - return true; |
|
| 988 | - } |
|
| 989 | - return false; |
|
| 990 | - } |
|
| 991 | - |
|
| 992 | - file_put_contents($tmp, $img); |
|
| 993 | - if (file_exists($tmp)) { |
|
| 994 | - $taille_test = spip_getimagesize($tmp); |
|
| 995 | - if ($taille_test[0] < 1) { |
|
| 996 | - return false; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1000 | - @rename($tmp, $fichier); |
|
| 1001 | - |
|
| 1002 | - return true; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - return false; |
|
| 977 | + $tmp = $fichier . '.tmp'; |
|
| 978 | + if (strpos($img, '<') === false) { |
|
| 979 | + $img = supprimer_timestamp($img); |
|
| 980 | + if (!file_exists($img)) { |
|
| 981 | + return false; |
|
| 982 | + } |
|
| 983 | + @copy($img, $tmp); |
|
| 984 | + if (filesize($tmp) == filesize($img)) { |
|
| 985 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 986 | + @rename($tmp, $fichier); |
|
| 987 | + return true; |
|
| 988 | + } |
|
| 989 | + return false; |
|
| 990 | + } |
|
| 991 | + |
|
| 992 | + file_put_contents($tmp, $img); |
|
| 993 | + if (file_exists($tmp)) { |
|
| 994 | + $taille_test = spip_getimagesize($tmp); |
|
| 995 | + if ($taille_test[0] < 1) { |
|
| 996 | + return false; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1000 | + @rename($tmp, $fichier); |
|
| 1001 | + |
|
| 1002 | + return true; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + return false; |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | |
@@ -1030,29 +1030,29 @@ discard block |
||
| 1030 | 1030 | * - false sinon. |
| 1031 | 1031 | */ |
| 1032 | 1032 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1033 | - if (is_null($fonction)) { |
|
| 1034 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1035 | - } |
|
| 1036 | - $ret = false; |
|
| 1037 | - #un flag pour reperer les images gravees |
|
| 1038 | - $lock = |
|
| 1039 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1040 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1041 | - if ( |
|
| 1042 | - function_exists($fonction) |
|
| 1043 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1044 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1045 | - && !$lock |
|
| 1046 | - ) { |
|
| 1047 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1048 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1049 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1050 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1051 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1052 | - } |
|
| 1053 | - } |
|
| 1054 | - |
|
| 1055 | - return $ret; |
|
| 1033 | + if (is_null($fonction)) { |
|
| 1034 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1035 | + } |
|
| 1036 | + $ret = false; |
|
| 1037 | + #un flag pour reperer les images gravees |
|
| 1038 | + $lock = |
|
| 1039 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1040 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1041 | + if ( |
|
| 1042 | + function_exists($fonction) |
|
| 1043 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1044 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1045 | + && !$lock |
|
| 1046 | + ) { |
|
| 1047 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1048 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1049 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1050 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1051 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1052 | + } |
|
| 1053 | + } |
|
| 1054 | + |
|
| 1055 | + return $ret; |
|
| 1056 | 1056 | } |
| 1057 | 1057 | |
| 1058 | 1058 | /** |
@@ -1065,27 +1065,27 @@ discard block |
||
| 1065 | 1065 | * Chemin vers le fichier manquant |
| 1066 | 1066 | **/ |
| 1067 | 1067 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1068 | - $reconstruire = []; |
|
| 1069 | - $fichier = $fichier_manquant; |
|
| 1070 | - while ( |
|
| 1071 | - strpos($fichier, '://') === false |
|
| 1072 | - and !@file_exists($fichier) |
|
| 1073 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1074 | - and $valeurs = unserialize($source) |
|
| 1075 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1076 | - ) { |
|
| 1077 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1078 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1079 | - } |
|
| 1080 | - while (count($reconstruire)) { |
|
| 1081 | - $r = array_pop($reconstruire); |
|
| 1082 | - $fonction = $r[0]; |
|
| 1083 | - $args = $r[1]; |
|
| 1084 | - call_user_func_array($fonction, $args); |
|
| 1085 | - } |
|
| 1086 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1087 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1088 | - ramasse_miettes($fichier_manquant); |
|
| 1068 | + $reconstruire = []; |
|
| 1069 | + $fichier = $fichier_manquant; |
|
| 1070 | + while ( |
|
| 1071 | + strpos($fichier, '://') === false |
|
| 1072 | + and !@file_exists($fichier) |
|
| 1073 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1074 | + and $valeurs = unserialize($source) |
|
| 1075 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1076 | + ) { |
|
| 1077 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1078 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1079 | + } |
|
| 1080 | + while (count($reconstruire)) { |
|
| 1081 | + $r = array_pop($reconstruire); |
|
| 1082 | + $fonction = $r[0]; |
|
| 1083 | + $args = $r[1]; |
|
| 1084 | + call_user_func_array($fonction, $args); |
|
| 1085 | + } |
|
| 1086 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1087 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1088 | + ramasse_miettes($fichier_manquant); |
|
| 1089 | 1089 | } |
| 1090 | 1090 | |
| 1091 | 1091 | /** |
@@ -1105,28 +1105,28 @@ discard block |
||
| 1105 | 1105 | * Chemin du fichier d'image calculé |
| 1106 | 1106 | **/ |
| 1107 | 1107 | function ramasse_miettes($fichier) { |
| 1108 | - if ( |
|
| 1109 | - strpos($fichier, '://') !== false |
|
| 1110 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1111 | - or !$valeurs = unserialize($source) |
|
| 1112 | - ) { |
|
| 1113 | - return; |
|
| 1114 | - } |
|
| 1115 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1116 | - while ( |
|
| 1117 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1118 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1119 | - and (lire_fichier( |
|
| 1120 | - $src = "$fichier.src", |
|
| 1121 | - $source |
|
| 1122 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1123 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1124 | - ) { |
|
| 1125 | - # on efface le fichier |
|
| 1126 | - spip_unlink($fichier); |
|
| 1127 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1128 | - #spip_unlink($src); |
|
| 1129 | - } |
|
| 1108 | + if ( |
|
| 1109 | + strpos($fichier, '://') !== false |
|
| 1110 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1111 | + or !$valeurs = unserialize($source) |
|
| 1112 | + ) { |
|
| 1113 | + return; |
|
| 1114 | + } |
|
| 1115 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1116 | + while ( |
|
| 1117 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1118 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1119 | + and (lire_fichier( |
|
| 1120 | + $src = "$fichier.src", |
|
| 1121 | + $source |
|
| 1122 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1123 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1124 | + ) { |
|
| 1125 | + # on efface le fichier |
|
| 1126 | + spip_unlink($fichier); |
|
| 1127 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1128 | + #spip_unlink($src); |
|
| 1129 | + } |
|
| 1130 | 1130 | } |
| 1131 | 1131 | |
| 1132 | 1132 | |
@@ -1151,71 +1151,71 @@ discard block |
||
| 1151 | 1151 | * Code HTML de l'image |
| 1152 | 1152 | **/ |
| 1153 | 1153 | function image_graver($img) { |
| 1154 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1155 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1156 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1157 | - |
|
| 1158 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1159 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1160 | - $fichier = substr($fichier, 0, $p); |
|
| 1161 | - } |
|
| 1162 | - if (strlen($fichier) < 1) { |
|
| 1163 | - $fichier = $img; |
|
| 1164 | - } |
|
| 1165 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1166 | - # et qu'il ne s'agit pas d'une URL |
|
| 1167 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1168 | - reconstruire_image_intermediaire($fichier); |
|
| 1169 | - } |
|
| 1170 | - ramasse_miettes($fichier); |
|
| 1171 | - |
|
| 1172 | - // ajouter le timestamp si besoin |
|
| 1173 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1174 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1175 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1176 | - } |
|
| 1177 | - |
|
| 1178 | - return $img; |
|
| 1154 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1155 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1156 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1157 | + |
|
| 1158 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1159 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1160 | + $fichier = substr($fichier, 0, $p); |
|
| 1161 | + } |
|
| 1162 | + if (strlen($fichier) < 1) { |
|
| 1163 | + $fichier = $img; |
|
| 1164 | + } |
|
| 1165 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1166 | + # et qu'il ne s'agit pas d'une URL |
|
| 1167 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1168 | + reconstruire_image_intermediaire($fichier); |
|
| 1169 | + } |
|
| 1170 | + ramasse_miettes($fichier); |
|
| 1171 | + |
|
| 1172 | + // ajouter le timestamp si besoin |
|
| 1173 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1174 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1175 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1176 | + } |
|
| 1177 | + |
|
| 1178 | + return $img; |
|
| 1179 | 1179 | } |
| 1180 | 1180 | |
| 1181 | 1181 | |
| 1182 | 1182 | if (!function_exists('imagepalettetotruecolor')) { |
| 1183 | - /** |
|
| 1184 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1185 | - * |
|
| 1186 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 1187 | - * |
|
| 1188 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1189 | - * |
|
| 1190 | - * @param ressource $img |
|
| 1191 | - * @return bool |
|
| 1192 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1193 | - * - false si la transformation ne peut être faite. |
|
| 1194 | - **/ |
|
| 1195 | - function imagepalettetotruecolor(&$img) { |
|
| 1196 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1197 | - return false; |
|
| 1198 | - } elseif (!imageistruecolor($img)) { |
|
| 1199 | - $w = imagesx($img); |
|
| 1200 | - $h = imagesy($img); |
|
| 1201 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 1202 | - //Conserver la transparence si possible |
|
| 1203 | - if (function_exists('ImageCopyResampled')) { |
|
| 1204 | - if (function_exists('imageAntiAlias')) { |
|
| 1205 | - imageAntiAlias($img1, true); |
|
| 1206 | - } |
|
| 1207 | - @imagealphablending($img1, false); |
|
| 1208 | - @imagesavealpha($img1, true); |
|
| 1209 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1210 | - } else { |
|
| 1211 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1212 | - } |
|
| 1213 | - |
|
| 1214 | - $img = $img1; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - return true; |
|
| 1218 | - } |
|
| 1183 | + /** |
|
| 1184 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1185 | + * |
|
| 1186 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 1187 | + * |
|
| 1188 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1189 | + * |
|
| 1190 | + * @param ressource $img |
|
| 1191 | + * @return bool |
|
| 1192 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1193 | + * - false si la transformation ne peut être faite. |
|
| 1194 | + **/ |
|
| 1195 | + function imagepalettetotruecolor(&$img) { |
|
| 1196 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1197 | + return false; |
|
| 1198 | + } elseif (!imageistruecolor($img)) { |
|
| 1199 | + $w = imagesx($img); |
|
| 1200 | + $h = imagesy($img); |
|
| 1201 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 1202 | + //Conserver la transparence si possible |
|
| 1203 | + if (function_exists('ImageCopyResampled')) { |
|
| 1204 | + if (function_exists('imageAntiAlias')) { |
|
| 1205 | + imageAntiAlias($img1, true); |
|
| 1206 | + } |
|
| 1207 | + @imagealphablending($img1, false); |
|
| 1208 | + @imagesavealpha($img1, true); |
|
| 1209 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1210 | + } else { |
|
| 1211 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1212 | + } |
|
| 1213 | + |
|
| 1214 | + $img = $img1; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + return true; |
|
| 1218 | + } |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | /** |
@@ -1242,34 +1242,34 @@ discard block |
||
| 1242 | 1242 | * Code html modifié de la balise. |
| 1243 | 1243 | **/ |
| 1244 | 1244 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1245 | - if ($style === false) { |
|
| 1246 | - $style = extraire_attribut($tag, 'style'); |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - // enlever le width et height du style |
|
| 1250 | - if ($style) { |
|
| 1251 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1252 | - } |
|
| 1253 | - if ($style and $style[0] === ';') { |
|
| 1254 | - $style = substr($style, 1); |
|
| 1255 | - } |
|
| 1256 | - |
|
| 1257 | - // mettre des attributs de width et height sur les images, |
|
| 1258 | - // ca accelere le rendu du navigateur |
|
| 1259 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1260 | - // quand on a desactive l'affichage des images. |
|
| 1261 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1262 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1263 | - |
|
| 1264 | - // attributs deprecies. Transformer en CSS |
|
| 1265 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1266 | - $style = "margin:${espace}px;" . $style; |
|
| 1267 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1271 | - |
|
| 1272 | - return $tag; |
|
| 1245 | + if ($style === false) { |
|
| 1246 | + $style = extraire_attribut($tag, 'style'); |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + // enlever le width et height du style |
|
| 1250 | + if ($style) { |
|
| 1251 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1252 | + } |
|
| 1253 | + if ($style and $style[0] === ';') { |
|
| 1254 | + $style = substr($style, 1); |
|
| 1255 | + } |
|
| 1256 | + |
|
| 1257 | + // mettre des attributs de width et height sur les images, |
|
| 1258 | + // ca accelere le rendu du navigateur |
|
| 1259 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1260 | + // quand on a desactive l'affichage des images. |
|
| 1261 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1262 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1263 | + |
|
| 1264 | + // attributs deprecies. Transformer en CSS |
|
| 1265 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1266 | + $style = "margin:${espace}px;" . $style; |
|
| 1267 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1271 | + |
|
| 1272 | + return $tag; |
|
| 1273 | 1273 | } |
| 1274 | 1274 | |
| 1275 | 1275 | |
@@ -1295,72 +1295,72 @@ discard block |
||
| 1295 | 1295 | * Retourne le code HTML de l'image |
| 1296 | 1296 | **/ |
| 1297 | 1297 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1298 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1299 | - |
|
| 1300 | - // fermer les tags img pas bien fermes; |
|
| 1301 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1302 | - |
|
| 1303 | - // le style |
|
| 1304 | - $style = $valeurs['style']; |
|
| 1305 | - if (isset($surcharge['style'])) { |
|
| 1306 | - $style = $surcharge['style']; |
|
| 1307 | - unset($surcharge['style']); |
|
| 1308 | - } |
|
| 1309 | - |
|
| 1310 | - // traiter specifiquement la largeur et la hauteur |
|
| 1311 | - $width = $valeurs['largeur']; |
|
| 1312 | - if (isset($surcharge['width'])) { |
|
| 1313 | - $width = $surcharge['width']; |
|
| 1314 | - unset($surcharge['width']); |
|
| 1315 | - } |
|
| 1316 | - $height = $valeurs['hauteur']; |
|
| 1317 | - if (isset($surcharge['height'])) { |
|
| 1318 | - $height = $surcharge['height']; |
|
| 1319 | - unset($surcharge['height']); |
|
| 1320 | - } |
|
| 1321 | - |
|
| 1322 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1323 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1324 | - // on remplace toute les ref a src dans le tag |
|
| 1325 | - $src = extraire_attribut($tag, 'src'); |
|
| 1326 | - if (isset($surcharge['src'])) { |
|
| 1327 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1328 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1329 | - // pas garanti comme methode, mais mieux que rien |
|
| 1330 | - if (strpos($src, '&') !== false) { |
|
| 1331 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1332 | - } |
|
| 1333 | - $src = $surcharge['src']; |
|
| 1334 | - unset($surcharge['src']); |
|
| 1335 | - } |
|
| 1336 | - |
|
| 1337 | - $class = $valeurs['class']; |
|
| 1338 | - if (isset($surcharge['class'])) { |
|
| 1339 | - $class = $surcharge['class']; |
|
| 1340 | - unset($surcharge['class']); |
|
| 1341 | - } |
|
| 1342 | - if (is_scalar($class) && strlen($class)) { |
|
| 1343 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1344 | - } |
|
| 1345 | - |
|
| 1346 | - if (count($surcharge)) { |
|
| 1347 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1348 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1349 | - } |
|
| 1350 | - } |
|
| 1351 | - |
|
| 1352 | - $tag = pipeline( |
|
| 1353 | - 'image_ecrire_tag_finir', |
|
| 1354 | - [ |
|
| 1355 | - 'args' => [ |
|
| 1356 | - 'valeurs' => $valeurs, |
|
| 1357 | - 'surcharge' => $surcharge, |
|
| 1358 | - ], |
|
| 1359 | - 'data' => $tag |
|
| 1360 | - ] |
|
| 1361 | - ); |
|
| 1362 | - |
|
| 1363 | - return $tag; |
|
| 1298 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1299 | + |
|
| 1300 | + // fermer les tags img pas bien fermes; |
|
| 1301 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1302 | + |
|
| 1303 | + // le style |
|
| 1304 | + $style = $valeurs['style']; |
|
| 1305 | + if (isset($surcharge['style'])) { |
|
| 1306 | + $style = $surcharge['style']; |
|
| 1307 | + unset($surcharge['style']); |
|
| 1308 | + } |
|
| 1309 | + |
|
| 1310 | + // traiter specifiquement la largeur et la hauteur |
|
| 1311 | + $width = $valeurs['largeur']; |
|
| 1312 | + if (isset($surcharge['width'])) { |
|
| 1313 | + $width = $surcharge['width']; |
|
| 1314 | + unset($surcharge['width']); |
|
| 1315 | + } |
|
| 1316 | + $height = $valeurs['hauteur']; |
|
| 1317 | + if (isset($surcharge['height'])) { |
|
| 1318 | + $height = $surcharge['height']; |
|
| 1319 | + unset($surcharge['height']); |
|
| 1320 | + } |
|
| 1321 | + |
|
| 1322 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1323 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1324 | + // on remplace toute les ref a src dans le tag |
|
| 1325 | + $src = extraire_attribut($tag, 'src'); |
|
| 1326 | + if (isset($surcharge['src'])) { |
|
| 1327 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1328 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1329 | + // pas garanti comme methode, mais mieux que rien |
|
| 1330 | + if (strpos($src, '&') !== false) { |
|
| 1331 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1332 | + } |
|
| 1333 | + $src = $surcharge['src']; |
|
| 1334 | + unset($surcharge['src']); |
|
| 1335 | + } |
|
| 1336 | + |
|
| 1337 | + $class = $valeurs['class']; |
|
| 1338 | + if (isset($surcharge['class'])) { |
|
| 1339 | + $class = $surcharge['class']; |
|
| 1340 | + unset($surcharge['class']); |
|
| 1341 | + } |
|
| 1342 | + if (is_scalar($class) && strlen($class)) { |
|
| 1343 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1344 | + } |
|
| 1345 | + |
|
| 1346 | + if (count($surcharge)) { |
|
| 1347 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1348 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1349 | + } |
|
| 1350 | + } |
|
| 1351 | + |
|
| 1352 | + $tag = pipeline( |
|
| 1353 | + 'image_ecrire_tag_finir', |
|
| 1354 | + [ |
|
| 1355 | + 'args' => [ |
|
| 1356 | + 'valeurs' => $valeurs, |
|
| 1357 | + 'surcharge' => $surcharge, |
|
| 1358 | + ], |
|
| 1359 | + 'data' => $tag |
|
| 1360 | + ] |
|
| 1361 | + ); |
|
| 1362 | + |
|
| 1363 | + return $tag; |
|
| 1364 | 1364 | } |
| 1365 | 1365 | |
| 1366 | 1366 | /** |
@@ -1383,259 +1383,259 @@ discard block |
||
| 1383 | 1383 | * Description de l'image, sinon null. |
| 1384 | 1384 | **/ |
| 1385 | 1385 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1386 | - $srcHeight = null; |
|
| 1387 | - $retour = []; |
|
| 1388 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1389 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1390 | - $image = $valeurs['fichier']; |
|
| 1391 | - $format = $valeurs['format_source']; |
|
| 1392 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1393 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1394 | - |
|
| 1395 | - $format_sortie = $valeurs['format_dest']; |
|
| 1396 | - |
|
| 1397 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1398 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1402 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1403 | - return; |
|
| 1404 | - } |
|
| 1405 | - $destination = "$destdir/$destfile"; |
|
| 1406 | - |
|
| 1407 | - // calculer la taille |
|
| 1408 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1409 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1410 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1411 | - } |
|
| 1412 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1413 | - $destWidth = $maxWidth; |
|
| 1414 | - $destHeight = $maxHeight; |
|
| 1415 | - } else { |
|
| 1416 | - spip_log("echec $process sur $image"); |
|
| 1417 | - |
|
| 1418 | - return; |
|
| 1419 | - } |
|
| 1420 | - |
|
| 1421 | - $vignette = ''; |
|
| 1422 | - |
|
| 1423 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1424 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1425 | - $vignette = $destination . '.' . $format; |
|
| 1426 | - @copy($image, $vignette); |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1430 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1431 | - $format_sortie = 'svg'; |
|
| 1432 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1433 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1434 | - _image_gd_output($svg, $valeurs); |
|
| 1435 | - } |
|
| 1436 | - } |
|
| 1437 | - |
|
| 1438 | - // imagemagick en ligne de commande |
|
| 1439 | - elseif ($process == 'convert') { |
|
| 1440 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1441 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1442 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1443 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1444 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1445 | - } |
|
| 1446 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1447 | - $commande = str_replace( |
|
| 1448 | - ['%x', '%y', '%src', '%dest'], |
|
| 1449 | - [ |
|
| 1450 | - $destWidth, |
|
| 1451 | - $destHeight, |
|
| 1452 | - escapeshellcmd($image), |
|
| 1453 | - escapeshellcmd($vignette) |
|
| 1454 | - ], |
|
| 1455 | - _RESIZE_COMMAND |
|
| 1456 | - ); |
|
| 1457 | - spip_log($commande); |
|
| 1458 | - exec($commande); |
|
| 1459 | - if (!@file_exists($vignette)) { |
|
| 1460 | - spip_log("echec convert sur $vignette"); |
|
| 1461 | - |
|
| 1462 | - return; // echec commande |
|
| 1463 | - } |
|
| 1464 | - } |
|
| 1465 | - |
|
| 1466 | - // php5 imagemagick |
|
| 1467 | - elseif ($process == 'imagick') { |
|
| 1468 | - $vignette = "$destination." . $format_sortie; |
|
| 1469 | - |
|
| 1470 | - if (!class_exists(\Imagick::class)) { |
|
| 1471 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1472 | - |
|
| 1473 | - return; |
|
| 1474 | - } |
|
| 1475 | - $imagick = new Imagick(); |
|
| 1476 | - $imagick->readImage($image); |
|
| 1477 | - $imagick->resizeImage( |
|
| 1478 | - $destWidth, |
|
| 1479 | - $destHeight, |
|
| 1480 | - Imagick::FILTER_LANCZOS, |
|
| 1481 | - 1 |
|
| 1482 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1483 | - $imagick->writeImage($vignette); |
|
| 1484 | - |
|
| 1485 | - if (!@file_exists($vignette)) { |
|
| 1486 | - spip_log("echec imagick sur $vignette"); |
|
| 1487 | - |
|
| 1488 | - return; |
|
| 1489 | - } |
|
| 1490 | - } |
|
| 1491 | - |
|
| 1492 | - // netpbm |
|
| 1493 | - elseif ($process == 'netpbm') { |
|
| 1494 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1495 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1496 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1497 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1498 | - return; |
|
| 1499 | - } |
|
| 1500 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1501 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1502 | - if ($format == 'jpg') { |
|
| 1503 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | - if (!($s = @filesize($vignette))) { |
|
| 1506 | - spip_unlink($vignette); |
|
| 1507 | - } |
|
| 1508 | - if (!@file_exists($vignette)) { |
|
| 1509 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1510 | - |
|
| 1511 | - return; |
|
| 1512 | - } |
|
| 1513 | - } else { |
|
| 1514 | - if ($format == 'gif') { |
|
| 1515 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1516 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1517 | - if (!($s = @filesize($vignette))) { |
|
| 1518 | - spip_unlink($vignette); |
|
| 1519 | - } |
|
| 1520 | - if (!@file_exists($vignette)) { |
|
| 1521 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1522 | - |
|
| 1523 | - return; |
|
| 1524 | - } |
|
| 1525 | - } else { |
|
| 1526 | - if ($format == 'png') { |
|
| 1527 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1528 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1529 | - if (!($s = @filesize($vignette))) { |
|
| 1530 | - spip_unlink($vignette); |
|
| 1531 | - } |
|
| 1532 | - if (!@file_exists($vignette)) { |
|
| 1533 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1534 | - |
|
| 1535 | - return; |
|
| 1536 | - } |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - } |
|
| 1540 | - } |
|
| 1541 | - |
|
| 1542 | - // gd ou gd2 |
|
| 1543 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1544 | - if (!function_exists('gd_info')) { |
|
| 1545 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1546 | - |
|
| 1547 | - return; |
|
| 1548 | - } |
|
| 1549 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1550 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1551 | - |
|
| 1552 | - return; |
|
| 1553 | - } |
|
| 1554 | - $destFormat = $format_sortie; |
|
| 1555 | - if (!$destFormat) { |
|
| 1556 | - spip_log("pas de format pour $image"); |
|
| 1557 | - |
|
| 1558 | - return; |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1562 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1563 | - return ''; |
|
| 1564 | - } |
|
| 1565 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1566 | - if (!$srcImage) { |
|
| 1567 | - spip_log('echec gd1/gd2'); |
|
| 1568 | - |
|
| 1569 | - return; |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - // Initialisation de l'image destination |
|
| 1573 | - $destImage = null; |
|
| 1574 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1575 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1576 | - } |
|
| 1577 | - if (!$destImage) { |
|
| 1578 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1582 | - $ok = false; |
|
| 1583 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1584 | - if ($format == 'gif') { |
|
| 1585 | - // Si un GIF est transparent, |
|
| 1586 | - // fabriquer un PNG transparent |
|
| 1587 | - $transp = imagecolortransparent($srcImage); |
|
| 1588 | - if ($transp > 0) { |
|
| 1589 | - $destFormat = 'png'; |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1593 | - // Conserver la transparence |
|
| 1594 | - if (function_exists('imageAntiAlias')) { |
|
| 1595 | - imageAntiAlias($destImage, true); |
|
| 1596 | - } |
|
| 1597 | - @imagealphablending($destImage, false); |
|
| 1598 | - @imagesavealpha($destImage, true); |
|
| 1599 | - } |
|
| 1600 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1601 | - } |
|
| 1602 | - if (!$ok) { |
|
| 1603 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - // Sauvegarde de l'image destination |
|
| 1607 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1608 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1609 | - _image_gd_output($destImage, $valeurs); |
|
| 1610 | - |
|
| 1611 | - if ($srcImage) { |
|
| 1612 | - ImageDestroy($srcImage); |
|
| 1613 | - } |
|
| 1614 | - ImageDestroy($destImage); |
|
| 1615 | - } |
|
| 1616 | - |
|
| 1617 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1618 | - $size = [$destWidth, $destHeight]; |
|
| 1619 | - } |
|
| 1620 | - |
|
| 1621 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1622 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1623 | - if ($size[0] < 1) { |
|
| 1624 | - $size[0] = $destWidth; |
|
| 1625 | - } |
|
| 1626 | - if ($size[1] < 1) { |
|
| 1627 | - $size[1] = $destHeight; |
|
| 1628 | - } |
|
| 1629 | - |
|
| 1630 | - $retour['width'] = $largeur = $size[0]; |
|
| 1631 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1632 | - |
|
| 1633 | - $retour['fichier'] = $vignette; |
|
| 1634 | - $retour['format'] = $format; |
|
| 1635 | - $retour['date'] = @filemtime($vignette); |
|
| 1636 | - |
|
| 1637 | - // renvoyer l'image |
|
| 1638 | - return $retour; |
|
| 1386 | + $srcHeight = null; |
|
| 1387 | + $retour = []; |
|
| 1388 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1389 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1390 | + $image = $valeurs['fichier']; |
|
| 1391 | + $format = $valeurs['format_source']; |
|
| 1392 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1393 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1394 | + |
|
| 1395 | + $format_sortie = $valeurs['format_dest']; |
|
| 1396 | + |
|
| 1397 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1398 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1402 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1403 | + return; |
|
| 1404 | + } |
|
| 1405 | + $destination = "$destdir/$destfile"; |
|
| 1406 | + |
|
| 1407 | + // calculer la taille |
|
| 1408 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1409 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1410 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1411 | + } |
|
| 1412 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1413 | + $destWidth = $maxWidth; |
|
| 1414 | + $destHeight = $maxHeight; |
|
| 1415 | + } else { |
|
| 1416 | + spip_log("echec $process sur $image"); |
|
| 1417 | + |
|
| 1418 | + return; |
|
| 1419 | + } |
|
| 1420 | + |
|
| 1421 | + $vignette = ''; |
|
| 1422 | + |
|
| 1423 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1424 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1425 | + $vignette = $destination . '.' . $format; |
|
| 1426 | + @copy($image, $vignette); |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1430 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1431 | + $format_sortie = 'svg'; |
|
| 1432 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1433 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1434 | + _image_gd_output($svg, $valeurs); |
|
| 1435 | + } |
|
| 1436 | + } |
|
| 1437 | + |
|
| 1438 | + // imagemagick en ligne de commande |
|
| 1439 | + elseif ($process == 'convert') { |
|
| 1440 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1441 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1442 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1443 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1444 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1445 | + } |
|
| 1446 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1447 | + $commande = str_replace( |
|
| 1448 | + ['%x', '%y', '%src', '%dest'], |
|
| 1449 | + [ |
|
| 1450 | + $destWidth, |
|
| 1451 | + $destHeight, |
|
| 1452 | + escapeshellcmd($image), |
|
| 1453 | + escapeshellcmd($vignette) |
|
| 1454 | + ], |
|
| 1455 | + _RESIZE_COMMAND |
|
| 1456 | + ); |
|
| 1457 | + spip_log($commande); |
|
| 1458 | + exec($commande); |
|
| 1459 | + if (!@file_exists($vignette)) { |
|
| 1460 | + spip_log("echec convert sur $vignette"); |
|
| 1461 | + |
|
| 1462 | + return; // echec commande |
|
| 1463 | + } |
|
| 1464 | + } |
|
| 1465 | + |
|
| 1466 | + // php5 imagemagick |
|
| 1467 | + elseif ($process == 'imagick') { |
|
| 1468 | + $vignette = "$destination." . $format_sortie; |
|
| 1469 | + |
|
| 1470 | + if (!class_exists(\Imagick::class)) { |
|
| 1471 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1472 | + |
|
| 1473 | + return; |
|
| 1474 | + } |
|
| 1475 | + $imagick = new Imagick(); |
|
| 1476 | + $imagick->readImage($image); |
|
| 1477 | + $imagick->resizeImage( |
|
| 1478 | + $destWidth, |
|
| 1479 | + $destHeight, |
|
| 1480 | + Imagick::FILTER_LANCZOS, |
|
| 1481 | + 1 |
|
| 1482 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1483 | + $imagick->writeImage($vignette); |
|
| 1484 | + |
|
| 1485 | + if (!@file_exists($vignette)) { |
|
| 1486 | + spip_log("echec imagick sur $vignette"); |
|
| 1487 | + |
|
| 1488 | + return; |
|
| 1489 | + } |
|
| 1490 | + } |
|
| 1491 | + |
|
| 1492 | + // netpbm |
|
| 1493 | + elseif ($process == 'netpbm') { |
|
| 1494 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1495 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1496 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1497 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1498 | + return; |
|
| 1499 | + } |
|
| 1500 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1501 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1502 | + if ($format == 'jpg') { |
|
| 1503 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | + if (!($s = @filesize($vignette))) { |
|
| 1506 | + spip_unlink($vignette); |
|
| 1507 | + } |
|
| 1508 | + if (!@file_exists($vignette)) { |
|
| 1509 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1510 | + |
|
| 1511 | + return; |
|
| 1512 | + } |
|
| 1513 | + } else { |
|
| 1514 | + if ($format == 'gif') { |
|
| 1515 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1516 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1517 | + if (!($s = @filesize($vignette))) { |
|
| 1518 | + spip_unlink($vignette); |
|
| 1519 | + } |
|
| 1520 | + if (!@file_exists($vignette)) { |
|
| 1521 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1522 | + |
|
| 1523 | + return; |
|
| 1524 | + } |
|
| 1525 | + } else { |
|
| 1526 | + if ($format == 'png') { |
|
| 1527 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1528 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1529 | + if (!($s = @filesize($vignette))) { |
|
| 1530 | + spip_unlink($vignette); |
|
| 1531 | + } |
|
| 1532 | + if (!@file_exists($vignette)) { |
|
| 1533 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1534 | + |
|
| 1535 | + return; |
|
| 1536 | + } |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + } |
|
| 1540 | + } |
|
| 1541 | + |
|
| 1542 | + // gd ou gd2 |
|
| 1543 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1544 | + if (!function_exists('gd_info')) { |
|
| 1545 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1546 | + |
|
| 1547 | + return; |
|
| 1548 | + } |
|
| 1549 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1550 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1551 | + |
|
| 1552 | + return; |
|
| 1553 | + } |
|
| 1554 | + $destFormat = $format_sortie; |
|
| 1555 | + if (!$destFormat) { |
|
| 1556 | + spip_log("pas de format pour $image"); |
|
| 1557 | + |
|
| 1558 | + return; |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1562 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1563 | + return ''; |
|
| 1564 | + } |
|
| 1565 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1566 | + if (!$srcImage) { |
|
| 1567 | + spip_log('echec gd1/gd2'); |
|
| 1568 | + |
|
| 1569 | + return; |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + // Initialisation de l'image destination |
|
| 1573 | + $destImage = null; |
|
| 1574 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1575 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1576 | + } |
|
| 1577 | + if (!$destImage) { |
|
| 1578 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1582 | + $ok = false; |
|
| 1583 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1584 | + if ($format == 'gif') { |
|
| 1585 | + // Si un GIF est transparent, |
|
| 1586 | + // fabriquer un PNG transparent |
|
| 1587 | + $transp = imagecolortransparent($srcImage); |
|
| 1588 | + if ($transp > 0) { |
|
| 1589 | + $destFormat = 'png'; |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1593 | + // Conserver la transparence |
|
| 1594 | + if (function_exists('imageAntiAlias')) { |
|
| 1595 | + imageAntiAlias($destImage, true); |
|
| 1596 | + } |
|
| 1597 | + @imagealphablending($destImage, false); |
|
| 1598 | + @imagesavealpha($destImage, true); |
|
| 1599 | + } |
|
| 1600 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1601 | + } |
|
| 1602 | + if (!$ok) { |
|
| 1603 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + // Sauvegarde de l'image destination |
|
| 1607 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1608 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1609 | + _image_gd_output($destImage, $valeurs); |
|
| 1610 | + |
|
| 1611 | + if ($srcImage) { |
|
| 1612 | + ImageDestroy($srcImage); |
|
| 1613 | + } |
|
| 1614 | + ImageDestroy($destImage); |
|
| 1615 | + } |
|
| 1616 | + |
|
| 1617 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1618 | + $size = [$destWidth, $destHeight]; |
|
| 1619 | + } |
|
| 1620 | + |
|
| 1621 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1622 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1623 | + if ($size[0] < 1) { |
|
| 1624 | + $size[0] = $destWidth; |
|
| 1625 | + } |
|
| 1626 | + if ($size[1] < 1) { |
|
| 1627 | + $size[1] = $destHeight; |
|
| 1628 | + } |
|
| 1629 | + |
|
| 1630 | + $retour['width'] = $largeur = $size[0]; |
|
| 1631 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1632 | + |
|
| 1633 | + $retour['fichier'] = $vignette; |
|
| 1634 | + $retour['format'] = $format; |
|
| 1635 | + $retour['date'] = @filemtime($vignette); |
|
| 1636 | + |
|
| 1637 | + // renvoyer l'image |
|
| 1638 | + return $retour; |
|
| 1639 | 1639 | } |
| 1640 | 1640 | |
| 1641 | 1641 | /** |
@@ -1655,25 +1655,25 @@ discard block |
||
| 1655 | 1655 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1656 | 1656 | **/ |
| 1657 | 1657 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1658 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1659 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1660 | - |
|
| 1661 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1662 | - $destWidth = $srcWidth; |
|
| 1663 | - $destHeight = $srcHeight; |
|
| 1664 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1665 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1666 | - $destHeight = $maxHeight; |
|
| 1667 | - } else { |
|
| 1668 | - $destWidth = $maxWidth; |
|
| 1669 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1670 | - } |
|
| 1671 | - |
|
| 1672 | - return [ |
|
| 1673 | - intval(round($destWidth)), |
|
| 1674 | - intval(round($destHeight)), |
|
| 1675 | - max($ratioWidth, $ratioHeight) |
|
| 1676 | - ]; |
|
| 1658 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1659 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1660 | + |
|
| 1661 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1662 | + $destWidth = $srcWidth; |
|
| 1663 | + $destHeight = $srcHeight; |
|
| 1664 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1665 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1666 | + $destHeight = $maxHeight; |
|
| 1667 | + } else { |
|
| 1668 | + $destWidth = $maxWidth; |
|
| 1669 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1670 | + } |
|
| 1671 | + |
|
| 1672 | + return [ |
|
| 1673 | + intval(round($destWidth)), |
|
| 1674 | + intval(round($destHeight)), |
|
| 1675 | + max($ratioWidth, $ratioHeight) |
|
| 1676 | + ]; |
|
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | 1679 | /** |
@@ -1693,25 +1693,25 @@ discard block |
||
| 1693 | 1693 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1694 | 1694 | **/ |
| 1695 | 1695 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1696 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1697 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1698 | - |
|
| 1699 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1700 | - $destWidth = $srcWidth; |
|
| 1701 | - $destHeight = $srcHeight; |
|
| 1702 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1703 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1704 | - $destHeight = $maxHeight; |
|
| 1705 | - } else { |
|
| 1706 | - $destWidth = $maxWidth; |
|
| 1707 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1708 | - } |
|
| 1709 | - |
|
| 1710 | - return [ |
|
| 1711 | - intval(round($destWidth)), |
|
| 1712 | - intval(round($destHeight)), |
|
| 1713 | - min($ratioWidth, $ratioHeight) |
|
| 1714 | - ]; |
|
| 1696 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1697 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1698 | + |
|
| 1699 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1700 | + $destWidth = $srcWidth; |
|
| 1701 | + $destHeight = $srcHeight; |
|
| 1702 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1703 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1704 | + $destHeight = $maxHeight; |
|
| 1705 | + } else { |
|
| 1706 | + $destWidth = $maxWidth; |
|
| 1707 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1708 | + } |
|
| 1709 | + |
|
| 1710 | + return [ |
|
| 1711 | + intval(round($destWidth)), |
|
| 1712 | + intval(round($destHeight)), |
|
| 1713 | + min($ratioWidth, $ratioHeight) |
|
| 1714 | + ]; |
|
| 1715 | 1715 | } |
| 1716 | 1716 | |
| 1717 | 1717 | |
@@ -1724,12 +1724,12 @@ discard block |
||
| 1724 | 1724 | * @return string |
| 1725 | 1725 | */ |
| 1726 | 1726 | function process_image_svg_identite($image) { |
| 1727 | - if ($image['creer']) { |
|
| 1728 | - $source = $image['fichier']; |
|
| 1729 | - _image_gd_output($source, $image); |
|
| 1730 | - } |
|
| 1727 | + if ($image['creer']) { |
|
| 1728 | + $source = $image['fichier']; |
|
| 1729 | + _image_gd_output($source, $image); |
|
| 1730 | + } |
|
| 1731 | 1731 | |
| 1732 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1732 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1733 | 1733 | } |
| 1734 | 1734 | |
| 1735 | 1735 | |
@@ -1762,111 +1762,111 @@ discard block |
||
| 1762 | 1762 | * Code HTML de la balise img produite |
| 1763 | 1763 | **/ |
| 1764 | 1764 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1765 | - $image = false; |
|
| 1766 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1767 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1768 | - } |
|
| 1769 | - # determiner le format de sortie |
|
| 1770 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1771 | - if ($process == 'netpbm') { |
|
| 1772 | - $format_sortie = 'jpg'; |
|
| 1773 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1774 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1775 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1776 | - $gd_formats = formats_image_acceptables(true); |
|
| 1777 | - if ( |
|
| 1778 | - is_array($image) |
|
| 1779 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1780 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1781 | - ) |
|
| 1782 | - ) { |
|
| 1783 | - if ($image['format_source'] == 'jpg') { |
|
| 1784 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1785 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1786 | - { |
|
| 1787 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1788 | - } |
|
| 1789 | - // Choisir le format destination |
|
| 1790 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1791 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1792 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1793 | - # pas *ecrire* |
|
| 1794 | - $format_sortie = ''; |
|
| 1795 | - foreach ($formats_sortie as $fmt) { |
|
| 1796 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1797 | - $format_sortie = $fmt; |
|
| 1798 | - break; |
|
| 1799 | - } |
|
| 1800 | - } |
|
| 1801 | - $image = false; |
|
| 1802 | - } |
|
| 1803 | - } |
|
| 1804 | - |
|
| 1805 | - if (!is_array($image)) { |
|
| 1806 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1810 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1811 | - // on peut resizer en mode html si on dispose des elements |
|
| 1812 | - if ( |
|
| 1813 | - $srcw = extraire_attribut($img, 'width') |
|
| 1814 | - and $srch = extraire_attribut($img, 'height') |
|
| 1815 | - ) { |
|
| 1816 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1817 | - |
|
| 1818 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1819 | - } |
|
| 1820 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1821 | - // sous la forme style='max-width: NNpx;' |
|
| 1822 | - return inserer_attribut( |
|
| 1823 | - $img, |
|
| 1824 | - 'style', |
|
| 1825 | - "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1826 | - ); |
|
| 1827 | - } |
|
| 1828 | - |
|
| 1829 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1830 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1831 | - if ($image['creer']) { |
|
| 1832 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1833 | - } |
|
| 1834 | - |
|
| 1835 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1836 | - } |
|
| 1837 | - |
|
| 1838 | - if ($image['creer'] == false && !$force) { |
|
| 1839 | - return _image_ecrire_tag( |
|
| 1840 | - $image, |
|
| 1841 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1842 | - ); |
|
| 1843 | - } |
|
| 1844 | - |
|
| 1845 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1846 | - $destWidth = $image['largeur_dest']; |
|
| 1847 | - $destHeight = $image['hauteur_dest']; |
|
| 1848 | - $logo = $image['fichier']; |
|
| 1849 | - $date = $image['date_src']; |
|
| 1850 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1851 | - |
|
| 1852 | - if ($preview && $preview['fichier']) { |
|
| 1853 | - $logo = $preview['fichier']; |
|
| 1854 | - $destWidth = $preview['width']; |
|
| 1855 | - $destHeight = $preview['height']; |
|
| 1856 | - $date = $preview['date']; |
|
| 1857 | - } |
|
| 1858 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1859 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1860 | - // quand on fait supprimer/reuploader un logo |
|
| 1861 | - // (pas de filemtime si SAFE MODE) |
|
| 1862 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1863 | - |
|
| 1864 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1865 | - } |
|
| 1866 | - else { |
|
| 1867 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1868 | - return $img; |
|
| 1869 | - } |
|
| 1765 | + $image = false; |
|
| 1766 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1767 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1768 | + } |
|
| 1769 | + # determiner le format de sortie |
|
| 1770 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1771 | + if ($process == 'netpbm') { |
|
| 1772 | + $format_sortie = 'jpg'; |
|
| 1773 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1774 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1775 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1776 | + $gd_formats = formats_image_acceptables(true); |
|
| 1777 | + if ( |
|
| 1778 | + is_array($image) |
|
| 1779 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1780 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1781 | + ) |
|
| 1782 | + ) { |
|
| 1783 | + if ($image['format_source'] == 'jpg') { |
|
| 1784 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1785 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1786 | + { |
|
| 1787 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1788 | + } |
|
| 1789 | + // Choisir le format destination |
|
| 1790 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1791 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1792 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1793 | + # pas *ecrire* |
|
| 1794 | + $format_sortie = ''; |
|
| 1795 | + foreach ($formats_sortie as $fmt) { |
|
| 1796 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1797 | + $format_sortie = $fmt; |
|
| 1798 | + break; |
|
| 1799 | + } |
|
| 1800 | + } |
|
| 1801 | + $image = false; |
|
| 1802 | + } |
|
| 1803 | + } |
|
| 1804 | + |
|
| 1805 | + if (!is_array($image)) { |
|
| 1806 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1810 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1811 | + // on peut resizer en mode html si on dispose des elements |
|
| 1812 | + if ( |
|
| 1813 | + $srcw = extraire_attribut($img, 'width') |
|
| 1814 | + and $srch = extraire_attribut($img, 'height') |
|
| 1815 | + ) { |
|
| 1816 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1817 | + |
|
| 1818 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1819 | + } |
|
| 1820 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1821 | + // sous la forme style='max-width: NNpx;' |
|
| 1822 | + return inserer_attribut( |
|
| 1823 | + $img, |
|
| 1824 | + 'style', |
|
| 1825 | + "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1826 | + ); |
|
| 1827 | + } |
|
| 1828 | + |
|
| 1829 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1830 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1831 | + if ($image['creer']) { |
|
| 1832 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1833 | + } |
|
| 1834 | + |
|
| 1835 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1836 | + } |
|
| 1837 | + |
|
| 1838 | + if ($image['creer'] == false && !$force) { |
|
| 1839 | + return _image_ecrire_tag( |
|
| 1840 | + $image, |
|
| 1841 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1842 | + ); |
|
| 1843 | + } |
|
| 1844 | + |
|
| 1845 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1846 | + $destWidth = $image['largeur_dest']; |
|
| 1847 | + $destHeight = $image['hauteur_dest']; |
|
| 1848 | + $logo = $image['fichier']; |
|
| 1849 | + $date = $image['date_src']; |
|
| 1850 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1851 | + |
|
| 1852 | + if ($preview && $preview['fichier']) { |
|
| 1853 | + $logo = $preview['fichier']; |
|
| 1854 | + $destWidth = $preview['width']; |
|
| 1855 | + $destHeight = $preview['height']; |
|
| 1856 | + $date = $preview['date']; |
|
| 1857 | + } |
|
| 1858 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1859 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1860 | + // quand on fait supprimer/reuploader un logo |
|
| 1861 | + // (pas de filemtime si SAFE MODE) |
|
| 1862 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1863 | + |
|
| 1864 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1865 | + } |
|
| 1866 | + else { |
|
| 1867 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1868 | + return $img; |
|
| 1869 | + } |
|
| 1870 | 1870 | } |
| 1871 | 1871 | |
| 1872 | 1872 | /** |
@@ -1881,145 +1881,145 @@ discard block |
||
| 1881 | 1881 | */ |
| 1882 | 1882 | class phpthumb_functions { |
| 1883 | 1883 | |
| 1884 | - /** |
|
| 1885 | - * Retourne la couleur d'un pixel dans une image |
|
| 1886 | - * |
|
| 1887 | - * @param ressource $img |
|
| 1888 | - * @param int $x |
|
| 1889 | - * @param int $y |
|
| 1890 | - * @return array|bool |
|
| 1891 | - */ |
|
| 1892 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1893 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1894 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1895 | - } |
|
| 1896 | - return false; |
|
| 1897 | - } |
|
| 1898 | - |
|
| 1899 | - /** |
|
| 1900 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1901 | - * |
|
| 1902 | - * @param int $number |
|
| 1903 | - * @param int $minbytes |
|
| 1904 | - * @return string |
|
| 1905 | - */ |
|
| 1906 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1907 | - $intstring = ''; |
|
| 1908 | - while ($number > 0) { |
|
| 1909 | - $intstring = $intstring . chr($number & 255); |
|
| 1910 | - $number >>= 8; |
|
| 1911 | - } |
|
| 1912 | - |
|
| 1913 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1914 | - } |
|
| 1915 | - |
|
| 1916 | - /** |
|
| 1917 | - * Transforme une ressource GD en image au format ICO |
|
| 1918 | - * |
|
| 1919 | - * @param array $gd_image_array |
|
| 1920 | - * Tableau de ressources d'images GD |
|
| 1921 | - * @return string |
|
| 1922 | - * Image au format ICO |
|
| 1923 | - */ |
|
| 1924 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1925 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1926 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1927 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1928 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1929 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1930 | - |
|
| 1931 | - $icXOR[$key] = ''; |
|
| 1932 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1933 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1934 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1935 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1936 | - $r = $argb['red']; |
|
| 1937 | - $g = $argb['green']; |
|
| 1938 | - $b = $argb['blue']; |
|
| 1939 | - |
|
| 1940 | - if ($bpp[$key] == 32) { |
|
| 1941 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1942 | - } elseif ($bpp[$key] == 24) { |
|
| 1943 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1944 | - } |
|
| 1945 | - |
|
| 1946 | - if ($a < 128) { |
|
| 1947 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1948 | - } else { |
|
| 1949 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1950 | - } |
|
| 1951 | - } |
|
| 1952 | - // mask bits are 32-bit aligned per scanline |
|
| 1953 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1954 | - $icANDmask[$key][$y] .= '0'; |
|
| 1955 | - } |
|
| 1956 | - } |
|
| 1957 | - $icAND[$key] = ''; |
|
| 1958 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1959 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1960 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1961 | - } |
|
| 1962 | - } |
|
| 1963 | - } |
|
| 1964 | - |
|
| 1965 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1966 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1967 | - |
|
| 1968 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1969 | - $BitmapInfoHeader[$key] = ''; |
|
| 1970 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1971 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1972 | - // The biHeight member specifies the combined |
|
| 1973 | - // height of the XOR and AND masks. |
|
| 1974 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1975 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1976 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1977 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1978 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1979 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1980 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1981 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1982 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1983 | - } |
|
| 1984 | - |
|
| 1985 | - |
|
| 1986 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1987 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1988 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1989 | - |
|
| 1990 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1991 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1992 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1993 | - |
|
| 1994 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1995 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1996 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1997 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1998 | - |
|
| 1999 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 2000 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 2001 | - |
|
| 2002 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 2003 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2004 | - $dwBytesInRes, |
|
| 2005 | - 4 |
|
| 2006 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2007 | - |
|
| 2008 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2009 | - $dwImageOffset, |
|
| 2010 | - 4 |
|
| 2011 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 2012 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2013 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 2014 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 2015 | - } |
|
| 2016 | - |
|
| 2017 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 2018 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 2019 | - $icondata .= $icXOR[$key]; |
|
| 2020 | - $icondata .= $icAND[$key]; |
|
| 2021 | - } |
|
| 2022 | - |
|
| 2023 | - return $icondata; |
|
| 2024 | - } |
|
| 1884 | + /** |
|
| 1885 | + * Retourne la couleur d'un pixel dans une image |
|
| 1886 | + * |
|
| 1887 | + * @param ressource $img |
|
| 1888 | + * @param int $x |
|
| 1889 | + * @param int $y |
|
| 1890 | + * @return array|bool |
|
| 1891 | + */ |
|
| 1892 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1893 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1894 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1895 | + } |
|
| 1896 | + return false; |
|
| 1897 | + } |
|
| 1898 | + |
|
| 1899 | + /** |
|
| 1900 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1901 | + * |
|
| 1902 | + * @param int $number |
|
| 1903 | + * @param int $minbytes |
|
| 1904 | + * @return string |
|
| 1905 | + */ |
|
| 1906 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1907 | + $intstring = ''; |
|
| 1908 | + while ($number > 0) { |
|
| 1909 | + $intstring = $intstring . chr($number & 255); |
|
| 1910 | + $number >>= 8; |
|
| 1911 | + } |
|
| 1912 | + |
|
| 1913 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1914 | + } |
|
| 1915 | + |
|
| 1916 | + /** |
|
| 1917 | + * Transforme une ressource GD en image au format ICO |
|
| 1918 | + * |
|
| 1919 | + * @param array $gd_image_array |
|
| 1920 | + * Tableau de ressources d'images GD |
|
| 1921 | + * @return string |
|
| 1922 | + * Image au format ICO |
|
| 1923 | + */ |
|
| 1924 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1925 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1926 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1927 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1928 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1929 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1930 | + |
|
| 1931 | + $icXOR[$key] = ''; |
|
| 1932 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1933 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1934 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1935 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1936 | + $r = $argb['red']; |
|
| 1937 | + $g = $argb['green']; |
|
| 1938 | + $b = $argb['blue']; |
|
| 1939 | + |
|
| 1940 | + if ($bpp[$key] == 32) { |
|
| 1941 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1942 | + } elseif ($bpp[$key] == 24) { |
|
| 1943 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1944 | + } |
|
| 1945 | + |
|
| 1946 | + if ($a < 128) { |
|
| 1947 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1948 | + } else { |
|
| 1949 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1950 | + } |
|
| 1951 | + } |
|
| 1952 | + // mask bits are 32-bit aligned per scanline |
|
| 1953 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1954 | + $icANDmask[$key][$y] .= '0'; |
|
| 1955 | + } |
|
| 1956 | + } |
|
| 1957 | + $icAND[$key] = ''; |
|
| 1958 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1959 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1960 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1961 | + } |
|
| 1962 | + } |
|
| 1963 | + } |
|
| 1964 | + |
|
| 1965 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1966 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1967 | + |
|
| 1968 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1969 | + $BitmapInfoHeader[$key] = ''; |
|
| 1970 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1971 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1972 | + // The biHeight member specifies the combined |
|
| 1973 | + // height of the XOR and AND masks. |
|
| 1974 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1975 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1976 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1977 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1978 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1979 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1980 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1981 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1982 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + |
|
| 1986 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1987 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1988 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1989 | + |
|
| 1990 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1991 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1992 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1993 | + |
|
| 1994 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1995 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1996 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1997 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1998 | + |
|
| 1999 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 2000 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 2001 | + |
|
| 2002 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 2003 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2004 | + $dwBytesInRes, |
|
| 2005 | + 4 |
|
| 2006 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 2007 | + |
|
| 2008 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 2009 | + $dwImageOffset, |
|
| 2010 | + 4 |
|
| 2011 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 2012 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 2013 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 2014 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 2015 | + } |
|
| 2016 | + |
|
| 2017 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 2018 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 2019 | + $icondata .= $icXOR[$key]; |
|
| 2020 | + $icondata .= $icAND[$key]; |
|
| 2021 | + } |
|
| 2022 | + |
|
| 2023 | + return $icondata; |
|
| 2024 | + } |
|
| 2025 | 2025 | } |
@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | - define('IMG_SVG', 128); |
|
| 26 | - define('IMAGETYPE_SVG', 19); |
|
| 24 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | + define('IMG_SVG', 128); |
|
| 26 | + define('IMAGETYPE_SVG', 19); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | 41 | function svg_charger($fichier, $maxlen = null) { |
| 42 | - if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | - $image = explode(';', $fichier, 2); |
|
| 44 | - $image = end($image); |
|
| 45 | - if (strpos($image, 'base64,') === 0) { |
|
| 46 | - $image = base64_decode(substr($image, 7)); |
|
| 47 | - } |
|
| 48 | - if (strpos($image, '<svg') !== false) { |
|
| 49 | - return $image; |
|
| 50 | - } |
|
| 51 | - // encodage inconnu ou autre format d'image ? |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - // c'est peut etre deja une image svg ? |
|
| 55 | - if (strpos($fichier, '<svg') !== false) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - if (!file_exists($fichier)) { |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (is_null($maxlen)) { |
|
| 65 | - $image = file_get_contents($fichier); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | - } |
|
| 70 | - // est-ce bien une image svg ? |
|
| 71 | - if (strpos($image, '<svg') !== false) { |
|
| 72 | - return $image; |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 42 | + if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | + $image = explode(';', $fichier, 2); |
|
| 44 | + $image = end($image); |
|
| 45 | + if (strpos($image, 'base64,') === 0) { |
|
| 46 | + $image = base64_decode(substr($image, 7)); |
|
| 47 | + } |
|
| 48 | + if (strpos($image, '<svg') !== false) { |
|
| 49 | + return $image; |
|
| 50 | + } |
|
| 51 | + // encodage inconnu ou autre format d'image ? |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + // c'est peut etre deja une image svg ? |
|
| 55 | + if (strpos($fichier, '<svg') !== false) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + if (!file_exists($fichier)) { |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (is_null($maxlen)) { |
|
| 65 | + $image = file_get_contents($fichier); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | + } |
|
| 70 | + // est-ce bien une image svg ? |
|
| 71 | + if (strpos($image, '<svg') !== false) { |
|
| 72 | + return $image; |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,28 +80,28 @@ discard block |
||
| 80 | 80 | * @return array|bool |
| 81 | 81 | */ |
| 82 | 82 | function svg_lire_balise_svg($fichier) { |
| 83 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | - |
|
| 91 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | - if (!function_exists('extraire_attribut')) { |
|
| 93 | - include_spip('inc/filtres'); |
|
| 94 | - } |
|
| 95 | - $attributs = []; |
|
| 96 | - foreach ($matches[1] as $att) { |
|
| 97 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return [$balise_svg, $attributs]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return false; |
|
| 83 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | + |
|
| 91 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | + if (!function_exists('extraire_attribut')) { |
|
| 93 | + include_spip('inc/filtres'); |
|
| 94 | + } |
|
| 95 | + $attributs = []; |
|
| 96 | + foreach ($matches[1] as $att) { |
|
| 97 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return [$balise_svg, $attributs]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return false; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function svg_lire_attributs($img) { |
| 113 | 113 | |
| 114 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | - return $attributs; |
|
| 117 | - } |
|
| 114 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | + return $attributs; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 119 | + return false; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,38 +126,38 @@ discard block |
||
| 126 | 126 | * @return bool|float|int |
| 127 | 127 | */ |
| 128 | 128 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 129 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | - switch (strtolower($m[2])) { |
|
| 131 | - case '%': |
|
| 132 | - // on ne sait pas faire :( |
|
| 133 | - return false; |
|
| 134 | - break; |
|
| 135 | - case 'em': |
|
| 136 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | - break; |
|
| 138 | - case 'ex': |
|
| 139 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | - break; |
|
| 141 | - case 'pc': |
|
| 142 | - return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | - break; |
|
| 144 | - case 'cm': |
|
| 145 | - return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | - break; |
|
| 147 | - case 'mm': |
|
| 148 | - return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | - break; |
|
| 150 | - case 'in': |
|
| 151 | - return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | - break; |
|
| 153 | - case 'px': |
|
| 154 | - case 'pt': |
|
| 155 | - default: |
|
| 156 | - return $m[1]; |
|
| 157 | - break; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return false; |
|
| 129 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | + switch (strtolower($m[2])) { |
|
| 131 | + case '%': |
|
| 132 | + // on ne sait pas faire :( |
|
| 133 | + return false; |
|
| 134 | + break; |
|
| 135 | + case 'em': |
|
| 136 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | + break; |
|
| 138 | + case 'ex': |
|
| 139 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | + break; |
|
| 141 | + case 'pc': |
|
| 142 | + return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | + break; |
|
| 144 | + case 'cm': |
|
| 145 | + return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | + break; |
|
| 147 | + case 'mm': |
|
| 148 | + return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | + break; |
|
| 150 | + case 'in': |
|
| 151 | + return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | + break; |
|
| 153 | + case 'px': |
|
| 154 | + case 'pt': |
|
| 155 | + default: |
|
| 156 | + return $m[1]; |
|
| 157 | + break; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return false; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | 170 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 171 | - $new_balise_svg = '<svg'; |
|
| 172 | - foreach ($attributs as $k => $v) { |
|
| 173 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | - } |
|
| 175 | - $new_balise_svg .= '>'; |
|
| 176 | - |
|
| 177 | - $p = strpos($svg, $old_balise_svg); |
|
| 178 | - $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | - return $svg; |
|
| 171 | + $new_balise_svg = '<svg'; |
|
| 172 | + foreach ($attributs as $k => $v) { |
|
| 173 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | + } |
|
| 175 | + $new_balise_svg .= '>'; |
|
| 176 | + |
|
| 177 | + $p = strpos($svg, $old_balise_svg); |
|
| 178 | + $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | + return $svg; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 190 | 190 | |
| 191 | - if ($start === false or $start === 'end') { |
|
| 192 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | - } |
|
| 194 | - else { |
|
| 195 | - $p = stripos($svg, '<svg'); |
|
| 196 | - $p = strpos($svg, '>', $p); |
|
| 197 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | - } |
|
| 199 | - return $svg; |
|
| 191 | + if ($start === false or $start === 'end') { |
|
| 192 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | + } |
|
| 194 | + else { |
|
| 195 | + $p = stripos($svg, '<svg'); |
|
| 196 | + $p = strpos($svg, '>', $p); |
|
| 197 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | + } |
|
| 199 | + return $svg; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | 211 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 212 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | - return $svg; |
|
| 212 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | + return $svg; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -226,22 +226,22 @@ discard block |
||
| 226 | 226 | * @return bool|string |
| 227 | 227 | */ |
| 228 | 228 | function svg_redimensionner($img, $new_width, $new_height) { |
| 229 | - if ( |
|
| 230 | - $svg = svg_charger($img) |
|
| 231 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | - ) { |
|
| 233 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | - if (!isset($attributs['viewBox'])) { |
|
| 235 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | - } |
|
| 237 | - $attributs['width'] = strval($new_width); |
|
| 238 | - $attributs['height'] = strval($new_height); |
|
| 239 | - |
|
| 240 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | - return $svg; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return $img; |
|
| 229 | + if ( |
|
| 230 | + $svg = svg_charger($img) |
|
| 231 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | + ) { |
|
| 233 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | + if (!isset($attributs['viewBox'])) { |
|
| 235 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | + } |
|
| 237 | + $attributs['width'] = strval($new_width); |
|
| 238 | + $attributs['height'] = strval($new_height); |
|
| 239 | + |
|
| 240 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | + return $svg; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return $img; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,15 +250,15 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | - $c = explode(',', substr($couleur, 4)); |
|
| 255 | - $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | - } |
|
| 257 | - else { |
|
| 258 | - $couleur = couleur_html_to_hex($couleur); |
|
| 259 | - } |
|
| 260 | - $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | - return $couleur; |
|
| 253 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | + $c = explode(',', substr($couleur, 4)); |
|
| 255 | + $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | + } |
|
| 257 | + else { |
|
| 258 | + $couleur = couleur_html_to_hex($couleur); |
|
| 259 | + } |
|
| 260 | + $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | + return $couleur; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | - $c = explode(',', substr($couleur, 4)); |
|
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | - } |
|
| 274 | - return _couleur_hex_to_dec($couleur); |
|
| 270 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | + $c = explode(',', substr($couleur, 4)); |
|
| 272 | + return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | + } |
|
| 274 | + return _couleur_hex_to_dec($couleur); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -281,70 +281,70 @@ discard block |
||
| 281 | 281 | * @return array |
| 282 | 282 | */ |
| 283 | 283 | function svg_getimagesize_from_attr($attributs) { |
| 284 | - $width = 350; // default width |
|
| 285 | - $height = 150; // default height |
|
| 286 | - |
|
| 287 | - $viewBox = "0 0 $width $height"; |
|
| 288 | - if (isset($attributs['viewBox'])) { |
|
| 289 | - $viewBox = $attributs['viewBox']; |
|
| 290 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | - } |
|
| 292 | - // et on la convertit en px |
|
| 293 | - $viewBox = explode(' ', $viewBox); |
|
| 294 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | - if (!$viewBox[2]) { |
|
| 296 | - $viewBox[2] = $width; |
|
| 297 | - } |
|
| 298 | - if (!$viewBox[3]) { |
|
| 299 | - $viewBox[3] = $height; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $coeff = 1; |
|
| 303 | - if ( |
|
| 304 | - isset($attributs['width']) |
|
| 305 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | - ) { |
|
| 307 | - $width = $w; |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 311 | - $width = $viewBox[2]; |
|
| 312 | - if ($width < 1) { |
|
| 313 | - $coeff = max($coeff, 1000); |
|
| 314 | - } |
|
| 315 | - elseif ($width < 10) { |
|
| 316 | - $coeff = max($coeff, 100); |
|
| 317 | - } |
|
| 318 | - elseif ($width < 100) { |
|
| 319 | - $coeff = max($coeff, 10); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - if ( |
|
| 323 | - isset($attributs['height']) |
|
| 324 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 325 | - ) { |
|
| 326 | - $height = $h; |
|
| 327 | - } |
|
| 328 | - else { |
|
| 329 | - $height = $viewBox[3]; |
|
| 330 | - if ($height < 1) { |
|
| 331 | - $coeff = max($coeff, 1000); |
|
| 332 | - } |
|
| 333 | - elseif ($height < 10) { |
|
| 334 | - $coeff = max($coeff, 100); |
|
| 335 | - } |
|
| 336 | - elseif ($height < 100) { |
|
| 337 | - $coeff = max($coeff, 10); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // arrondir le width et height en pixel in fine |
|
| 342 | - $width = round($coeff * $width); |
|
| 343 | - $height = round($coeff * $height); |
|
| 344 | - |
|
| 345 | - $viewBox = implode(' ', $viewBox); |
|
| 346 | - |
|
| 347 | - return [$width, $height, $viewBox]; |
|
| 284 | + $width = 350; // default width |
|
| 285 | + $height = 150; // default height |
|
| 286 | + |
|
| 287 | + $viewBox = "0 0 $width $height"; |
|
| 288 | + if (isset($attributs['viewBox'])) { |
|
| 289 | + $viewBox = $attributs['viewBox']; |
|
| 290 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | + } |
|
| 292 | + // et on la convertit en px |
|
| 293 | + $viewBox = explode(' ', $viewBox); |
|
| 294 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | + if (!$viewBox[2]) { |
|
| 296 | + $viewBox[2] = $width; |
|
| 297 | + } |
|
| 298 | + if (!$viewBox[3]) { |
|
| 299 | + $viewBox[3] = $height; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $coeff = 1; |
|
| 303 | + if ( |
|
| 304 | + isset($attributs['width']) |
|
| 305 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | + ) { |
|
| 307 | + $width = $w; |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 311 | + $width = $viewBox[2]; |
|
| 312 | + if ($width < 1) { |
|
| 313 | + $coeff = max($coeff, 1000); |
|
| 314 | + } |
|
| 315 | + elseif ($width < 10) { |
|
| 316 | + $coeff = max($coeff, 100); |
|
| 317 | + } |
|
| 318 | + elseif ($width < 100) { |
|
| 319 | + $coeff = max($coeff, 10); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + if ( |
|
| 323 | + isset($attributs['height']) |
|
| 324 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 325 | + ) { |
|
| 326 | + $height = $h; |
|
| 327 | + } |
|
| 328 | + else { |
|
| 329 | + $height = $viewBox[3]; |
|
| 330 | + if ($height < 1) { |
|
| 331 | + $coeff = max($coeff, 1000); |
|
| 332 | + } |
|
| 333 | + elseif ($height < 10) { |
|
| 334 | + $coeff = max($coeff, 100); |
|
| 335 | + } |
|
| 336 | + elseif ($height < 100) { |
|
| 337 | + $coeff = max($coeff, 10); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // arrondir le width et height en pixel in fine |
|
| 342 | + $width = round($coeff * $width); |
|
| 343 | + $height = round($coeff * $height); |
|
| 344 | + |
|
| 345 | + $viewBox = implode(' ', $viewBox); |
|
| 346 | + |
|
| 347 | + return [$width, $height, $viewBox]; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -360,25 +360,25 @@ discard block |
||
| 360 | 360 | * @return string |
| 361 | 361 | */ |
| 362 | 362 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 363 | - if ( |
|
| 364 | - $svg = svg_charger($img) |
|
| 365 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | - ) { |
|
| 367 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 363 | + if ( |
|
| 364 | + $svg = svg_charger($img) |
|
| 365 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | + ) { |
|
| 367 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 368 | 368 | |
| 369 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 369 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 370 | 370 | |
| 371 | - if ($force_width_and_height) { |
|
| 372 | - $attributs['width'] = $width; |
|
| 373 | - $attributs['height'] = $height; |
|
| 374 | - } |
|
| 371 | + if ($force_width_and_height) { |
|
| 372 | + $attributs['width'] = $width; |
|
| 373 | + $attributs['height'] = $height; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $attributs['viewBox'] = $viewBox; |
|
| 376 | + $attributs['viewBox'] = $viewBox; |
|
| 377 | 377 | |
| 378 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 379 | - return $svg; |
|
| 380 | - } |
|
| 381 | - return $img; |
|
| 378 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 379 | + return $svg; |
|
| 380 | + } |
|
| 381 | + return $img; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | * @return array|mixed |
| 388 | 388 | */ |
| 389 | 389 | function svg_extract_couleurs($img) { |
| 390 | - if ($svg = svg_charger($img)) { |
|
| 391 | - if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) { |
|
| 392 | - return $matches[0]; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - return []; |
|
| 390 | + if ($svg = svg_charger($img)) { |
|
| 391 | + if (preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches)) { |
|
| 392 | + return $matches[0]; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + return []; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -403,58 +403,58 @@ discard block |
||
| 403 | 403 | * @return bool|string |
| 404 | 404 | */ |
| 405 | 405 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 406 | - if ( |
|
| 407 | - $svg = svg_force_viewBox_px($img) |
|
| 408 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 409 | - ) { |
|
| 410 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 411 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 412 | - |
|
| 413 | - $viewport_w = $new_width; |
|
| 414 | - $viewport_h = $new_height; |
|
| 415 | - $viewport_ox = $offset_width; |
|
| 416 | - $viewport_oy = $offset_height; |
|
| 417 | - |
|
| 418 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 419 | - if ( |
|
| 420 | - isset($attributs['width']) |
|
| 421 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 422 | - and isset($attributs['height']) |
|
| 423 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 424 | - ) { |
|
| 425 | - $xscale = $viewBox[2] / $w; |
|
| 426 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 427 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 428 | - $yscale = $viewBox[3] / $h; |
|
| 429 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 430 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 434 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // maintenant on redefinit la viewBox |
|
| 438 | - $viewBox[0] += $viewport_ox; |
|
| 439 | - $viewBox[1] += $viewport_oy; |
|
| 440 | - $viewBox[2] = $viewport_w; |
|
| 441 | - $viewBox[3] = $viewport_h; |
|
| 442 | - |
|
| 443 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 444 | - $attributs['width'] = strval($new_width); |
|
| 445 | - $attributs['height'] = strval($new_height); |
|
| 446 | - |
|
| 447 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 448 | - |
|
| 449 | - // ajouter un background |
|
| 450 | - if ($background_color and $background_color !== 'transparent') { |
|
| 451 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $svg; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - return $img; |
|
| 406 | + if ( |
|
| 407 | + $svg = svg_force_viewBox_px($img) |
|
| 408 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 409 | + ) { |
|
| 410 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 411 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 412 | + |
|
| 413 | + $viewport_w = $new_width; |
|
| 414 | + $viewport_h = $new_height; |
|
| 415 | + $viewport_ox = $offset_width; |
|
| 416 | + $viewport_oy = $offset_height; |
|
| 417 | + |
|
| 418 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 419 | + if ( |
|
| 420 | + isset($attributs['width']) |
|
| 421 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 422 | + and isset($attributs['height']) |
|
| 423 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 424 | + ) { |
|
| 425 | + $xscale = $viewBox[2] / $w; |
|
| 426 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 427 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 428 | + $yscale = $viewBox[3] / $h; |
|
| 429 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 430 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 434 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // maintenant on redefinit la viewBox |
|
| 438 | + $viewBox[0] += $viewport_ox; |
|
| 439 | + $viewBox[1] += $viewport_oy; |
|
| 440 | + $viewBox[2] = $viewport_w; |
|
| 441 | + $viewBox[3] = $viewport_h; |
|
| 442 | + |
|
| 443 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 444 | + $attributs['width'] = strval($new_width); |
|
| 445 | + $attributs['height'] = strval($new_height); |
|
| 446 | + |
|
| 447 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 448 | + |
|
| 449 | + // ajouter un background |
|
| 450 | + if ($background_color and $background_color !== 'transparent') { |
|
| 451 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $svg; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + return $img; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | * @return bool|string |
| 465 | 465 | */ |
| 466 | 466 | function svg_ajouter_background($img, $background_color) { |
| 467 | - if ( |
|
| 468 | - $svg = svg_charger($img) |
|
| 469 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 470 | - ) { |
|
| 471 | - if ($background_color and $background_color !== 'transparent') { |
|
| 472 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 473 | - |
|
| 474 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 475 | - if (isset($attributs['viewBox'])) { |
|
| 476 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 477 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 478 | - } |
|
| 479 | - else { |
|
| 480 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 481 | - } |
|
| 482 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 483 | - } |
|
| 484 | - return $svg; |
|
| 485 | - } |
|
| 486 | - return $img; |
|
| 467 | + if ( |
|
| 468 | + $svg = svg_charger($img) |
|
| 469 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 470 | + ) { |
|
| 471 | + if ($background_color and $background_color !== 'transparent') { |
|
| 472 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 473 | + |
|
| 474 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 475 | + if (isset($attributs['viewBox'])) { |
|
| 476 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 477 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 478 | + } |
|
| 479 | + else { |
|
| 480 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 481 | + } |
|
| 482 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 483 | + } |
|
| 484 | + return $svg; |
|
| 485 | + } |
|
| 486 | + return $img; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -494,26 +494,26 @@ discard block |
||
| 494 | 494 | * @return bool|string |
| 495 | 495 | */ |
| 496 | 496 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 497 | - if ( |
|
| 498 | - $svg = svg_charger($img) |
|
| 499 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 500 | - ) { |
|
| 501 | - if ($background_color and $background_color !== 'transparent') { |
|
| 502 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 503 | - |
|
| 504 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 505 | - if (isset($attributs['viewBox'])) { |
|
| 506 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 507 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | - } |
|
| 509 | - else { |
|
| 510 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 511 | - } |
|
| 512 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 513 | - } |
|
| 514 | - return $svg; |
|
| 515 | - } |
|
| 516 | - return $img; |
|
| 497 | + if ( |
|
| 498 | + $svg = svg_charger($img) |
|
| 499 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 500 | + ) { |
|
| 501 | + if ($background_color and $background_color !== 'transparent') { |
|
| 502 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 503 | + |
|
| 504 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 505 | + if (isset($attributs['viewBox'])) { |
|
| 506 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 507 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | + } |
|
| 509 | + else { |
|
| 510 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 511 | + } |
|
| 512 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 513 | + } |
|
| 514 | + return $svg; |
|
| 515 | + } |
|
| 516 | + return $img; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | |
@@ -524,27 +524,27 @@ discard block |
||
| 524 | 524 | * @return bool|string |
| 525 | 525 | */ |
| 526 | 526 | function svg_transformer($img, $attributs) { |
| 527 | - if ( |
|
| 528 | - $svg = svg_charger($img) |
|
| 529 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 530 | - ) { |
|
| 531 | - if ($attributs) { |
|
| 532 | - [$balise_svg, ] = $svg_infos; |
|
| 533 | - $g = '<g'; |
|
| 534 | - foreach ($attributs as $k => $v) { |
|
| 535 | - if (strlen($v)) { |
|
| 536 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - if (strlen($g) > 2) { |
|
| 540 | - $g .= '>'; |
|
| 541 | - $svg = svg_insert_shapes($svg, $g); |
|
| 542 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - return $svg; |
|
| 546 | - } |
|
| 547 | - return $img; |
|
| 527 | + if ( |
|
| 528 | + $svg = svg_charger($img) |
|
| 529 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 530 | + ) { |
|
| 531 | + if ($attributs) { |
|
| 532 | + [$balise_svg, ] = $svg_infos; |
|
| 533 | + $g = '<g'; |
|
| 534 | + foreach ($attributs as $k => $v) { |
|
| 535 | + if (strlen($v)) { |
|
| 536 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + if (strlen($g) > 2) { |
|
| 540 | + $g .= '>'; |
|
| 541 | + $svg = svg_insert_shapes($svg, $g); |
|
| 542 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + return $svg; |
|
| 546 | + } |
|
| 547 | + return $img; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -555,21 +555,21 @@ discard block |
||
| 555 | 555 | * @return bool|string |
| 556 | 556 | */ |
| 557 | 557 | function svg_apply_filter($img, $filter_def) { |
| 558 | - if ( |
|
| 559 | - $svg = svg_charger($img) |
|
| 560 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 561 | - ) { |
|
| 562 | - if ($filter_def) { |
|
| 563 | - [$balise_svg, ] = $svg_infos; |
|
| 564 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 565 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 566 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 567 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 568 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 569 | - } |
|
| 570 | - return $svg; |
|
| 571 | - } |
|
| 572 | - return $img; |
|
| 558 | + if ( |
|
| 559 | + $svg = svg_charger($img) |
|
| 560 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 561 | + ) { |
|
| 562 | + if ($filter_def) { |
|
| 563 | + [$balise_svg, ] = $svg_infos; |
|
| 564 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 565 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 566 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 567 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 568 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 569 | + } |
|
| 570 | + return $svg; |
|
| 571 | + } |
|
| 572 | + return $img; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -579,8 +579,8 @@ discard block |
||
| 579 | 579 | * @return string |
| 580 | 580 | */ |
| 581 | 581 | function svg_filter_blur($img, $blur_width) { |
| 582 | - $blur_width = intval($blur_width); |
|
| 583 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 582 | + $blur_width = intval($blur_width); |
|
| 583 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * @return bool|string |
| 591 | 591 | */ |
| 592 | 592 | function svg_filter_grayscale($img, $intensity) { |
| 593 | - $value = round(1.0 - $intensity, 2); |
|
| 594 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 595 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 596 | - return svg_apply_filter($img, $filter); |
|
| 593 | + $value = round(1.0 - $intensity, 2); |
|
| 594 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 595 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 596 | + return svg_apply_filter($img, $filter); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | * @return bool|string |
| 604 | 604 | */ |
| 605 | 605 | function svg_filter_sepia($img, $intensity) { |
| 606 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 607 | - return svg_apply_filter($img, $filter); |
|
| 606 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 607 | + return svg_apply_filter($img, $filter); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -614,31 +614,31 @@ discard block |
||
| 614 | 614 | * @return bool|string |
| 615 | 615 | */ |
| 616 | 616 | function svg_flip($img, $HorV) { |
| 617 | - if ( |
|
| 618 | - $svg = svg_force_viewBox_px($img) |
|
| 619 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 620 | - ) { |
|
| 621 | - [$balise_svg, $atts] = $svg_infos; |
|
| 622 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 623 | - |
|
| 624 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 625 | - $transform = 'scale(-1,1)'; |
|
| 626 | - |
|
| 627 | - $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 628 | - $mx = -$x; |
|
| 629 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 630 | - } |
|
| 631 | - else { |
|
| 632 | - $transform = 'scale(1,-1)'; |
|
| 633 | - |
|
| 634 | - $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 635 | - $my = -$y; |
|
| 636 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 637 | - } |
|
| 638 | - $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 639 | - return $svg; |
|
| 640 | - } |
|
| 641 | - return $img; |
|
| 617 | + if ( |
|
| 618 | + $svg = svg_force_viewBox_px($img) |
|
| 619 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 620 | + ) { |
|
| 621 | + [$balise_svg, $atts] = $svg_infos; |
|
| 622 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 623 | + |
|
| 624 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 625 | + $transform = 'scale(-1,1)'; |
|
| 626 | + |
|
| 627 | + $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 628 | + $mx = -$x; |
|
| 629 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 630 | + } |
|
| 631 | + else { |
|
| 632 | + $transform = 'scale(1,-1)'; |
|
| 633 | + |
|
| 634 | + $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 635 | + $my = -$y; |
|
| 636 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 637 | + } |
|
| 638 | + $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 639 | + return $svg; |
|
| 640 | + } |
|
| 641 | + return $img; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -652,20 +652,20 @@ discard block |
||
| 652 | 652 | * @return bool|string |
| 653 | 653 | */ |
| 654 | 654 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 655 | - if ( |
|
| 656 | - $svg = svg_force_viewBox_px($img) |
|
| 657 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 658 | - ) { |
|
| 659 | - [$balise_svg, $atts] = $svg_infos; |
|
| 660 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 661 | - |
|
| 662 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 663 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 664 | - $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 665 | - |
|
| 666 | - return $svg; |
|
| 667 | - } |
|
| 668 | - return $img; |
|
| 655 | + if ( |
|
| 656 | + $svg = svg_force_viewBox_px($img) |
|
| 657 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 658 | + ) { |
|
| 659 | + [$balise_svg, $atts] = $svg_infos; |
|
| 660 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 661 | + |
|
| 662 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 663 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 664 | + $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 665 | + |
|
| 666 | + return $svg; |
|
| 667 | + } |
|
| 668 | + return $img; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -677,41 +677,41 @@ discard block |
||
| 677 | 677 | * @return bool|mixed|string |
| 678 | 678 | */ |
| 679 | 679 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 680 | - if ( |
|
| 681 | - $svg = svg_force_viewBox_px($img) |
|
| 682 | - and $colors = svg_extract_couleurs($svg) |
|
| 683 | - ) { |
|
| 684 | - $colors = array_unique($colors); |
|
| 685 | - |
|
| 686 | - $short = []; |
|
| 687 | - $long = []; |
|
| 688 | - while (count($colors)) { |
|
| 689 | - $c = array_shift($colors); |
|
| 690 | - if (strlen($c) == 4) { |
|
| 691 | - $short[] = $c; |
|
| 692 | - } |
|
| 693 | - else { |
|
| 694 | - $long[] = $c; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $colors = [...$long, ...$short]; |
|
| 699 | - $new_colors = []; |
|
| 700 | - $colors = array_flip($colors); |
|
| 701 | - foreach ($colors as $c => $k) { |
|
| 702 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - foreach ($colors as $original => $replace) { |
|
| 707 | - $new = svg_couleur_to_hexa($original); |
|
| 708 | - $new_colors[$replace] = $callback_filter($new); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 712 | - $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 713 | - |
|
| 714 | - return $svg; |
|
| 715 | - } |
|
| 716 | - return $img; |
|
| 680 | + if ( |
|
| 681 | + $svg = svg_force_viewBox_px($img) |
|
| 682 | + and $colors = svg_extract_couleurs($svg) |
|
| 683 | + ) { |
|
| 684 | + $colors = array_unique($colors); |
|
| 685 | + |
|
| 686 | + $short = []; |
|
| 687 | + $long = []; |
|
| 688 | + while (count($colors)) { |
|
| 689 | + $c = array_shift($colors); |
|
| 690 | + if (strlen($c) == 4) { |
|
| 691 | + $short[] = $c; |
|
| 692 | + } |
|
| 693 | + else { |
|
| 694 | + $long[] = $c; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $colors = [...$long, ...$short]; |
|
| 699 | + $new_colors = []; |
|
| 700 | + $colors = array_flip($colors); |
|
| 701 | + foreach ($colors as $c => $k) { |
|
| 702 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + foreach ($colors as $original => $replace) { |
|
| 707 | + $new = svg_couleur_to_hexa($original); |
|
| 708 | + $new_colors[$replace] = $callback_filter($new); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 712 | + $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 713 | + |
|
| 714 | + return $svg; |
|
| 715 | + } |
|
| 716 | + return $img; |
|
| 717 | 717 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,18 +44,18 @@ discard block |
||
| 44 | 44 | * Pile complétée par le code à générer |
| 45 | 45 | */ |
| 46 | 46 | function balise_BOITE_OUVRIR_dist($p) { |
| 47 | - $_titre = interprete_argument_balise(1, $p); |
|
| 48 | - $_class = interprete_argument_balise(2, $p); |
|
| 49 | - $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | - $_titre = ($_titre ?: "''"); |
|
| 51 | - $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | - $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | - |
|
| 54 | - $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | - $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | - $p->interdire_scripts = false; |
|
| 57 | - |
|
| 58 | - return $p; |
|
| 47 | + $_titre = interprete_argument_balise(1, $p); |
|
| 48 | + $_class = interprete_argument_balise(2, $p); |
|
| 49 | + $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | + $_titre = ($_titre ?: "''"); |
|
| 51 | + $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | + $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | + |
|
| 54 | + $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | + $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | + $p->interdire_scripts = false; |
|
| 57 | + |
|
| 58 | + return $p; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * Pile complétée par le code à générer |
| 76 | 76 | */ |
| 77 | 77 | function balise_BOITE_PIED_dist($p) { |
| 78 | - $_class = interprete_argument_balise(1, $p); |
|
| 79 | - $_class = ($_class ? "$_class" : ''); |
|
| 78 | + $_class = interprete_argument_balise(1, $p); |
|
| 79 | + $_class = ($_class ? "$_class" : ''); |
|
| 80 | 80 | |
| 81 | - $f = chercher_filtre('boite_pied'); |
|
| 82 | - $p->code = "$f($_class)"; |
|
| 83 | - $p->interdire_scripts = false; |
|
| 81 | + $f = chercher_filtre('boite_pied'); |
|
| 82 | + $p->code = "$f($_class)"; |
|
| 83 | + $p->interdire_scripts = false; |
|
| 84 | 84 | |
| 85 | - return $p; |
|
| 85 | + return $p; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * Pile complétée par le code à générer |
| 103 | 103 | */ |
| 104 | 104 | function balise_BOITE_FERMER_dist($p) { |
| 105 | - $f = chercher_filtre('boite_fermer'); |
|
| 106 | - $p->code = "$f()"; |
|
| 107 | - $p->interdire_scripts = false; |
|
| 105 | + $f = chercher_filtre('boite_fermer'); |
|
| 106 | + $p->code = "$f()"; |
|
| 107 | + $p->interdire_scripts = false; |
|
| 108 | 108 | |
| 109 | - return $p; |
|
| 109 | + return $p; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | * HTML du début de la boîte |
| 129 | 129 | */ |
| 130 | 130 | function boite_ouvrir($titre, $class = '', $head_class = '', $id = '') { |
| 131 | - $class = "box $class"; |
|
| 132 | - $head_class = "box__header $head_class clearfix"; |
|
| 133 | - // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | - if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) { |
|
| 135 | - $titre = "<h3>$titre</h3>"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | - . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | - . '<div class="box__body clearfix">'; |
|
| 131 | + $class = "box $class"; |
|
| 132 | + $head_class = "box__header $head_class clearfix"; |
|
| 133 | + // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | + if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) { |
|
| 135 | + $titre = "<h3>$titre</h3>"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | + . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | + . '<div class="box__body clearfix">'; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | * HTML de transition vers le pied de la boîte |
| 155 | 155 | */ |
| 156 | 156 | function boite_pied($class = 'act') { |
| 157 | - $class = "box__footer $class"; |
|
| 157 | + $class = "box__footer $class"; |
|
| 158 | 158 | |
| 159 | - return '</div>' |
|
| 160 | - . "<div class=\"$class clearfix\">"; |
|
| 159 | + return '</div>' |
|
| 160 | + . "<div class=\"$class clearfix\">"; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -172,6 +172,6 @@ discard block |
||
| 172 | 172 | * HTML de fin de la boîte |
| 173 | 173 | */ |
| 174 | 174 | function boite_fermer() { |
| 175 | - return '</div>' |
|
| 176 | - . '</div>'; |
|
| 175 | + return '</div>' |
|
| 176 | + . '</div>'; |
|
| 177 | 177 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | - public $icone; |
|
| 30 | - |
|
| 31 | - /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | - public $sousmenu = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Définit un bouton |
|
| 51 | - * |
|
| 52 | - * @param string $icone |
|
| 53 | - * L'icone à mettre dans le bouton |
|
| 54 | - * @param string $libelle |
|
| 55 | - * Le nom de l'entrée i18n associé |
|
| 56 | - * @param null|string $url |
|
| 57 | - * L'URL de la page |
|
| 58 | - * @param null|string|array $urlArg |
|
| 59 | - * Arguments supplémentaires de l'URL |
|
| 60 | - * @param null|string $url2 |
|
| 61 | - * URL du javascript |
|
| 62 | - * @param null|mixed $target |
|
| 63 | - * Pour ouvrir une fenêtre à part |
|
| 64 | - */ |
|
| 65 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | - $this->icone = $icone; |
|
| 67 | - $this->libelle = $libelle; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->urlArg = $urlArg; |
|
| 70 | - $this->url2 = $url2; |
|
| 71 | - $this->target = $target; |
|
| 72 | - } |
|
| 28 | + /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | + public $icone; |
|
| 30 | + |
|
| 31 | + /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | + public $sousmenu = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Définit un bouton |
|
| 51 | + * |
|
| 52 | + * @param string $icone |
|
| 53 | + * L'icone à mettre dans le bouton |
|
| 54 | + * @param string $libelle |
|
| 55 | + * Le nom de l'entrée i18n associé |
|
| 56 | + * @param null|string $url |
|
| 57 | + * L'URL de la page |
|
| 58 | + * @param null|string|array $urlArg |
|
| 59 | + * Arguments supplémentaires de l'URL |
|
| 60 | + * @param null|string $url2 |
|
| 61 | + * URL du javascript |
|
| 62 | + * @param null|mixed $target |
|
| 63 | + * Pour ouvrir une fenêtre à part |
|
| 64 | + */ |
|
| 65 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | + $this->icone = $icone; |
|
| 67 | + $this->libelle = $libelle; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->urlArg = $urlArg; |
|
| 70 | + $this->url2 = $url2; |
|
| 71 | + $this->target = $target; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function definir_barre_onglets($script) { |
| 88 | 88 | |
| 89 | - $onglets = []; |
|
| 90 | - $liste_onglets = []; |
|
| 91 | - |
|
| 92 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | - if (function_exists('onglets_plugins')) { |
|
| 94 | - $liste_onglets = onglets_plugins(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - foreach ($liste_onglets as $id => $infos) { |
|
| 99 | - if ( |
|
| 100 | - ($parent = $infos['parent']) |
|
| 101 | - && $parent == $script |
|
| 102 | - && autoriser('onglet', "_$id") |
|
| 103 | - ) { |
|
| 104 | - $onglets[$id] = new Bouton( |
|
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 107 | - (isset($infos['action']) and $infos['action']) |
|
| 108 | - ? generer_url_ecrire( |
|
| 109 | - $infos['action'], |
|
| 110 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | - ) |
|
| 112 | - : null |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 89 | + $onglets = []; |
|
| 90 | + $liste_onglets = []; |
|
| 91 | + |
|
| 92 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | + if (function_exists('onglets_plugins')) { |
|
| 94 | + $liste_onglets = onglets_plugins(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + foreach ($liste_onglets as $id => $infos) { |
|
| 99 | + if ( |
|
| 100 | + ($parent = $infos['parent']) |
|
| 101 | + && $parent == $script |
|
| 102 | + && autoriser('onglet', "_$id") |
|
| 103 | + ) { |
|
| 104 | + $onglets[$id] = new Bouton( |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | + (isset($infos['action']) and $infos['action']) |
|
| 108 | + ? generer_url_ecrire( |
|
| 109 | + $infos['action'], |
|
| 110 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | + ) |
|
| 112 | + : null |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 136 | - include_spip('inc/presentation'); |
|
| 136 | + include_spip('inc/presentation'); |
|
| 137 | 137 | |
| 138 | - $res = ''; |
|
| 138 | + $res = ''; |
|
| 139 | 139 | |
| 140 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | - } |
|
| 140 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 142 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 146 | 146 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | |
| 23 | 23 | // securité |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | // se faciliter la lecture du charset |
@@ -42,45 +42,45 @@ discard block |
||
| 42 | 42 | * - false si le charset n'est pas décrit dans le répertoire charsets/ |
| 43 | 43 | **/ |
| 44 | 44 | function load_charset($charset = 'AUTO') { |
| 45 | - if ($charset == 'AUTO') { |
|
| 46 | - $charset = $GLOBALS['meta']['charset']; |
|
| 47 | - } |
|
| 48 | - $charset = trim(strtolower($charset)); |
|
| 49 | - if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | - return $charset; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if ($charset == 'utf-8') { |
|
| 54 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | - |
|
| 56 | - return $charset; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // Quelques synonymes |
|
| 60 | - if ($charset == '') { |
|
| 61 | - $charset = 'iso-8859-1'; |
|
| 62 | - } else { |
|
| 63 | - if ($charset == 'windows-1250') { |
|
| 64 | - $charset = 'cp1250'; |
|
| 65 | - } else { |
|
| 66 | - if ($charset == 'windows-1251') { |
|
| 67 | - $charset = 'cp1251'; |
|
| 68 | - } else { |
|
| 69 | - if ($charset == 'windows-1256') { |
|
| 70 | - $charset = 'cp1256'; |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | - return $charset; |
|
| 78 | - } else { |
|
| 79 | - spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | - $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | - |
|
| 82 | - return false; |
|
| 83 | - } |
|
| 45 | + if ($charset == 'AUTO') { |
|
| 46 | + $charset = $GLOBALS['meta']['charset']; |
|
| 47 | + } |
|
| 48 | + $charset = trim(strtolower($charset)); |
|
| 49 | + if (isset($GLOBALS['CHARSET'][$charset])) { |
|
| 50 | + return $charset; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if ($charset == 'utf-8') { |
|
| 54 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 55 | + |
|
| 56 | + return $charset; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // Quelques synonymes |
|
| 60 | + if ($charset == '') { |
|
| 61 | + $charset = 'iso-8859-1'; |
|
| 62 | + } else { |
|
| 63 | + if ($charset == 'windows-1250') { |
|
| 64 | + $charset = 'cp1250'; |
|
| 65 | + } else { |
|
| 66 | + if ($charset == 'windows-1251') { |
|
| 67 | + $charset = 'cp1251'; |
|
| 68 | + } else { |
|
| 69 | + if ($charset == 'windows-1256') { |
|
| 70 | + $charset = 'cp1256'; |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + if (find_in_path($charset . '.php', 'charsets/', true)) { |
|
| 77 | + return $charset; |
|
| 78 | + } else { |
|
| 79 | + spip_log("Erreur: pas de fichier de conversion 'charsets/$charset'"); |
|
| 80 | + $GLOBALS['CHARSET'][$charset] = []; |
|
| 81 | + |
|
| 82 | + return false; |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | |
@@ -91,31 +91,31 @@ discard block |
||
| 91 | 91 | * true si toutes les fonctions mb nécessaires sont présentes |
| 92 | 92 | **/ |
| 93 | 93 | function init_mb_string() { |
| 94 | - static $mb; |
|
| 95 | - |
|
| 96 | - // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | - // et que le charset interne est connu de mb_string |
|
| 98 | - if (!$mb) { |
|
| 99 | - if ( |
|
| 100 | - function_exists('mb_internal_encoding') |
|
| 101 | - and function_exists('mb_detect_order') |
|
| 102 | - and function_exists('mb_substr') |
|
| 103 | - and function_exists('mb_strlen') |
|
| 104 | - and function_exists('mb_strtolower') |
|
| 105 | - and function_exists('mb_strtoupper') |
|
| 106 | - and function_exists('mb_encode_mimeheader') |
|
| 107 | - and function_exists('mb_encode_numericentity') |
|
| 108 | - and function_exists('mb_decode_numericentity') |
|
| 109 | - and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | - ) { |
|
| 111 | - mb_internal_encoding('utf-8'); |
|
| 112 | - $mb = 1; |
|
| 113 | - } else { |
|
| 114 | - $mb = -1; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - return ($mb == 1); |
|
| 94 | + static $mb; |
|
| 95 | + |
|
| 96 | + // verifier que tout est present (fonctions mb_string pour php >= 4.0.6) |
|
| 97 | + // et que le charset interne est connu de mb_string |
|
| 98 | + if (!$mb) { |
|
| 99 | + if ( |
|
| 100 | + function_exists('mb_internal_encoding') |
|
| 101 | + and function_exists('mb_detect_order') |
|
| 102 | + and function_exists('mb_substr') |
|
| 103 | + and function_exists('mb_strlen') |
|
| 104 | + and function_exists('mb_strtolower') |
|
| 105 | + and function_exists('mb_strtoupper') |
|
| 106 | + and function_exists('mb_encode_mimeheader') |
|
| 107 | + and function_exists('mb_encode_numericentity') |
|
| 108 | + and function_exists('mb_decode_numericentity') |
|
| 109 | + and mb_detect_order(lire_config('charset', _DEFAULT_CHARSET)) |
|
| 110 | + ) { |
|
| 111 | + mb_internal_encoding('utf-8'); |
|
| 112 | + $mb = 1; |
|
| 113 | + } else { |
|
| 114 | + $mb = -1; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + return ($mb == 1); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -130,21 +130,21 @@ discard block |
||
| 130 | 130 | * true si iconv fonctionne correctement |
| 131 | 131 | **/ |
| 132 | 132 | function test_iconv() { |
| 133 | - static $iconv_ok; |
|
| 134 | - |
|
| 135 | - if (!$iconv_ok) { |
|
| 136 | - if (!function_exists('iconv')) { |
|
| 137 | - $iconv_ok = -1; |
|
| 138 | - } else { |
|
| 139 | - if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | - $iconv_ok = 1; |
|
| 141 | - } else { |
|
| 142 | - $iconv_ok = -1; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ($iconv_ok == 1); |
|
| 133 | + static $iconv_ok; |
|
| 134 | + |
|
| 135 | + if (!$iconv_ok) { |
|
| 136 | + if (!function_exists('iconv')) { |
|
| 137 | + $iconv_ok = -1; |
|
| 138 | + } else { |
|
| 139 | + if (utf_32_to_unicode(@iconv('utf-8', 'utf-32', 'chaine de test')) == 'chaine de test') { |
|
| 140 | + $iconv_ok = 1; |
|
| 141 | + } else { |
|
| 142 | + $iconv_ok = -1; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ($iconv_ok == 1); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -157,18 +157,18 @@ discard block |
||
| 157 | 157 | * true si PCRE supporte l'UTF-8 correctement |
| 158 | 158 | **/ |
| 159 | 159 | function test_pcre_unicode() { |
| 160 | - static $pcre_ok = 0; |
|
| 161 | - |
|
| 162 | - if (!$pcre_ok) { |
|
| 163 | - $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | - if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | - $pcre_ok = 1; |
|
| 166 | - } else { |
|
| 167 | - $pcre_ok = -1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $pcre_ok == 1; |
|
| 160 | + static $pcre_ok = 0; |
|
| 161 | + |
|
| 162 | + if (!$pcre_ok) { |
|
| 163 | + $s = ' ' . chr(195) . chr(169) . 't' . chr(195) . chr(169) . ' '; |
|
| 164 | + if (preg_match(',\W...\W,u', $s)) { |
|
| 165 | + $pcre_ok = 1; |
|
| 166 | + } else { |
|
| 167 | + $pcre_ok = -1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $pcre_ok == 1; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -184,22 +184,22 @@ discard block |
||
| 184 | 184 | * Plage de caractères |
| 185 | 185 | **/ |
| 186 | 186 | function pcre_lettres_unicode() { |
| 187 | - static $plage_unicode; |
|
| 188 | - |
|
| 189 | - if (!$plage_unicode) { |
|
| 190 | - if (test_pcre_unicode()) { |
|
| 191 | - // cf. http://www.unicode.org/charts/ |
|
| 192 | - $plage_unicode = '\w' // iso-latin |
|
| 193 | - . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | - . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | - ; |
|
| 196 | - } else { |
|
| 197 | - // fallback a trois sous |
|
| 198 | - $plage_unicode = '\w'; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $plage_unicode; |
|
| 187 | + static $plage_unicode; |
|
| 188 | + |
|
| 189 | + if (!$plage_unicode) { |
|
| 190 | + if (test_pcre_unicode()) { |
|
| 191 | + // cf. http://www.unicode.org/charts/ |
|
| 192 | + $plage_unicode = '\w' // iso-latin |
|
| 193 | + . '\x{100}-\x{24f}' // europeen etendu |
|
| 194 | + . '\x{300}-\x{1cff}' // des tas de trucs |
|
| 195 | + ; |
|
| 196 | + } else { |
|
| 197 | + // fallback a trois sous |
|
| 198 | + $plage_unicode = '\w'; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $plage_unicode; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -217,7 +217,7 @@ discard block |
||
| 217 | 217 | * Plage de caractères |
| 218 | 218 | **/ |
| 219 | 219 | function plage_punct_unicode() { |
| 220 | - return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 220 | + return '\xE2(\x80[\x80-\xBF]|\x81[\x80-\xAF])'; |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | /** |
@@ -237,75 +237,75 @@ discard block |
||
| 237 | 237 | * Texte corrigé |
| 238 | 238 | **/ |
| 239 | 239 | function corriger_caracteres_windows($texte, $charset = 'AUTO', $charset_cible = 'unicode') { |
| 240 | - static $trans; |
|
| 241 | - |
|
| 242 | - if (is_array($texte)) { |
|
| 243 | - return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - if ($charset == 'AUTO') { |
|
| 247 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | - } |
|
| 249 | - if ($charset == 'utf-8') { |
|
| 250 | - $p = chr(194); |
|
| 251 | - if (strpos($texte, $p) == false) { |
|
| 252 | - return $texte; |
|
| 253 | - } |
|
| 254 | - } else { |
|
| 255 | - if ($charset == 'iso-8859-1') { |
|
| 256 | - $p = ''; |
|
| 257 | - } else { |
|
| 258 | - return $texte; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | - $trans[$charset][$charset_cible] = [ |
|
| 264 | - $p . chr(128) => '€', |
|
| 265 | - $p . chr(129) => ' ', # pas affecte |
|
| 266 | - $p . chr(130) => '‚', |
|
| 267 | - $p . chr(131) => 'ƒ', |
|
| 268 | - $p . chr(132) => '„', |
|
| 269 | - $p . chr(133) => '…', |
|
| 270 | - $p . chr(134) => '†', |
|
| 271 | - $p . chr(135) => '‡', |
|
| 272 | - $p . chr(136) => 'ˆ', |
|
| 273 | - $p . chr(137) => '‰', |
|
| 274 | - $p . chr(138) => 'Š', |
|
| 275 | - $p . chr(139) => '‹', |
|
| 276 | - $p . chr(140) => 'Œ', |
|
| 277 | - $p . chr(141) => ' ', # pas affecte |
|
| 278 | - $p . chr(142) => 'Ž', |
|
| 279 | - $p . chr(143) => ' ', # pas affecte |
|
| 280 | - $p . chr(144) => ' ', # pas affecte |
|
| 281 | - $p . chr(145) => '‘', |
|
| 282 | - $p . chr(146) => '’', |
|
| 283 | - $p . chr(147) => '“', |
|
| 284 | - $p . chr(148) => '”', |
|
| 285 | - $p . chr(149) => '•', |
|
| 286 | - $p . chr(150) => '–', |
|
| 287 | - $p . chr(151) => '—', |
|
| 288 | - $p . chr(152) => '˜', |
|
| 289 | - $p . chr(153) => '™', |
|
| 290 | - $p . chr(154) => 'š', |
|
| 291 | - $p . chr(155) => '›', |
|
| 292 | - $p . chr(156) => 'œ', |
|
| 293 | - $p . chr(157) => ' ', # pas affecte |
|
| 294 | - $p . chr(158) => 'ž', |
|
| 295 | - $p . chr(159) => 'Ÿ', |
|
| 296 | - ]; |
|
| 297 | - if ($charset_cible != 'unicode') { |
|
| 298 | - foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | - $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return @str_replace( |
|
| 305 | - array_keys($trans[$charset][$charset_cible]), |
|
| 306 | - array_values($trans[$charset][$charset_cible]), |
|
| 307 | - $texte |
|
| 308 | - ); |
|
| 240 | + static $trans; |
|
| 241 | + |
|
| 242 | + if (is_array($texte)) { |
|
| 243 | + return array_map('corriger_caracteres_windows', $texte); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + if ($charset == 'AUTO') { |
|
| 247 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 248 | + } |
|
| 249 | + if ($charset == 'utf-8') { |
|
| 250 | + $p = chr(194); |
|
| 251 | + if (strpos($texte, $p) == false) { |
|
| 252 | + return $texte; |
|
| 253 | + } |
|
| 254 | + } else { |
|
| 255 | + if ($charset == 'iso-8859-1') { |
|
| 256 | + $p = ''; |
|
| 257 | + } else { |
|
| 258 | + return $texte; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + if (!isset($trans[$charset][$charset_cible])) { |
|
| 263 | + $trans[$charset][$charset_cible] = [ |
|
| 264 | + $p . chr(128) => '€', |
|
| 265 | + $p . chr(129) => ' ', # pas affecte |
|
| 266 | + $p . chr(130) => '‚', |
|
| 267 | + $p . chr(131) => 'ƒ', |
|
| 268 | + $p . chr(132) => '„', |
|
| 269 | + $p . chr(133) => '…', |
|
| 270 | + $p . chr(134) => '†', |
|
| 271 | + $p . chr(135) => '‡', |
|
| 272 | + $p . chr(136) => 'ˆ', |
|
| 273 | + $p . chr(137) => '‰', |
|
| 274 | + $p . chr(138) => 'Š', |
|
| 275 | + $p . chr(139) => '‹', |
|
| 276 | + $p . chr(140) => 'Œ', |
|
| 277 | + $p . chr(141) => ' ', # pas affecte |
|
| 278 | + $p . chr(142) => 'Ž', |
|
| 279 | + $p . chr(143) => ' ', # pas affecte |
|
| 280 | + $p . chr(144) => ' ', # pas affecte |
|
| 281 | + $p . chr(145) => '‘', |
|
| 282 | + $p . chr(146) => '’', |
|
| 283 | + $p . chr(147) => '“', |
|
| 284 | + $p . chr(148) => '”', |
|
| 285 | + $p . chr(149) => '•', |
|
| 286 | + $p . chr(150) => '–', |
|
| 287 | + $p . chr(151) => '—', |
|
| 288 | + $p . chr(152) => '˜', |
|
| 289 | + $p . chr(153) => '™', |
|
| 290 | + $p . chr(154) => 'š', |
|
| 291 | + $p . chr(155) => '›', |
|
| 292 | + $p . chr(156) => 'œ', |
|
| 293 | + $p . chr(157) => ' ', # pas affecte |
|
| 294 | + $p . chr(158) => 'ž', |
|
| 295 | + $p . chr(159) => 'Ÿ', |
|
| 296 | + ]; |
|
| 297 | + if ($charset_cible != 'unicode') { |
|
| 298 | + foreach ($trans[$charset][$charset_cible] as $k => $c) { |
|
| 299 | + $trans[$charset][$charset_cible][$k] = unicode2charset($c, $charset_cible); |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return @str_replace( |
|
| 305 | + array_keys($trans[$charset][$charset_cible]), |
|
| 306 | + array_values($trans[$charset][$charset_cible]), |
|
| 307 | + $texte |
|
| 308 | + ); |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | |
@@ -322,26 +322,26 @@ discard block |
||
| 322 | 322 | * Texte converti |
| 323 | 323 | **/ |
| 324 | 324 | function html2unicode($texte, $secure = false) { |
| 325 | - if (strpos($texte, '&') === false) { |
|
| 326 | - return $texte; |
|
| 327 | - } |
|
| 328 | - static $trans = []; |
|
| 329 | - if (!$trans) { |
|
| 330 | - load_charset('html'); |
|
| 331 | - foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | - $trans["&$key;"] = $val; |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - if ($secure) { |
|
| 337 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | - } else { |
|
| 339 | - return str_replace( |
|
| 340 | - ['&', '"', '<', '>'], |
|
| 341 | - ['&', '"', '<', '>'], |
|
| 342 | - str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | - ); |
|
| 344 | - } |
|
| 325 | + if (strpos($texte, '&') === false) { |
|
| 326 | + return $texte; |
|
| 327 | + } |
|
| 328 | + static $trans = []; |
|
| 329 | + if (!$trans) { |
|
| 330 | + load_charset('html'); |
|
| 331 | + foreach ($GLOBALS['CHARSET']['html'] as $key => $val) { |
|
| 332 | + $trans["&$key;"] = $val; |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + if ($secure) { |
|
| 337 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 338 | + } else { |
|
| 339 | + return str_replace( |
|
| 340 | + ['&', '"', '<', '>'], |
|
| 341 | + ['&', '"', '<', '>'], |
|
| 342 | + str_replace(array_keys($trans), array_values($trans), $texte) |
|
| 343 | + ); |
|
| 344 | + } |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -356,16 +356,16 @@ discard block |
||
| 356 | 356 | * Texte converti |
| 357 | 357 | **/ |
| 358 | 358 | function mathml2unicode($texte) { |
| 359 | - static $trans; |
|
| 360 | - if (!$trans) { |
|
| 361 | - load_charset('mathml'); |
|
| 359 | + static $trans; |
|
| 360 | + if (!$trans) { |
|
| 361 | + load_charset('mathml'); |
|
| 362 | 362 | |
| 363 | - foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | - $trans["&$key;"] = $val; |
|
| 365 | - } |
|
| 366 | - } |
|
| 363 | + foreach ($GLOBALS['CHARSET']['mathml'] as $key => $val) { |
|
| 364 | + $trans["&$key;"] = $val; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | 367 | |
| 368 | - return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 368 | + return str_replace(array_keys($trans), array_values($trans), $texte); |
|
| 369 | 369 | } |
| 370 | 370 | |
| 371 | 371 | |
@@ -387,75 +387,75 @@ discard block |
||
| 387 | 387 | * Texte converti en unicode |
| 388 | 388 | **/ |
| 389 | 389 | function charset2unicode($texte, $charset = 'AUTO' /* $forcer: obsolete*/) { |
| 390 | - static $trans; |
|
| 391 | - |
|
| 392 | - if ($charset == 'AUTO') { |
|
| 393 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - if ($charset == '') { |
|
| 397 | - $charset = 'iso-8859-1'; |
|
| 398 | - } |
|
| 399 | - $charset = strtolower($charset); |
|
| 400 | - |
|
| 401 | - switch ($charset) { |
|
| 402 | - case 'utf-8': |
|
| 403 | - case 'utf8': |
|
| 404 | - return utf_8_to_unicode($texte); |
|
| 405 | - |
|
| 406 | - case 'iso-8859-1': |
|
| 407 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | - // pas de break; ici, on suit sur default: |
|
| 409 | - |
|
| 410 | - default: |
|
| 411 | - // mbstring presente ? |
|
| 412 | - if (init_mb_string()) { |
|
| 413 | - $order = mb_detect_order(); |
|
| 414 | - try { |
|
| 415 | - # mb_string connait-il $charset? |
|
| 416 | - if ($order and mb_detect_order($charset)) { |
|
| 417 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | - if ($s && $s != $texte) { |
|
| 419 | - return utf_8_to_unicode($s); |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - } catch (\Error $e) { |
|
| 423 | - // Le charset n'existe probablement pas |
|
| 424 | - } finally { |
|
| 425 | - mb_detect_order($order); # remettre comme precedemment |
|
| 426 | - } |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | - if (!isset($trans[$charset])) { |
|
| 431 | - if ( |
|
| 432 | - $cset = load_charset($charset) |
|
| 433 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | - ) { |
|
| 435 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | - $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | - } |
|
| 443 | - |
|
| 444 | - // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | - // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | - // surtout en utf-8, gere ci-dessus) |
|
| 447 | - if (test_iconv()) { |
|
| 448 | - $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | - if ($s) { |
|
| 450 | - return utf_32_to_unicode($s); |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // Au pire ne rien faire |
|
| 455 | - spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | - |
|
| 457 | - return $texte; |
|
| 458 | - } |
|
| 390 | + static $trans; |
|
| 391 | + |
|
| 392 | + if ($charset == 'AUTO') { |
|
| 393 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + if ($charset == '') { |
|
| 397 | + $charset = 'iso-8859-1'; |
|
| 398 | + } |
|
| 399 | + $charset = strtolower($charset); |
|
| 400 | + |
|
| 401 | + switch ($charset) { |
|
| 402 | + case 'utf-8': |
|
| 403 | + case 'utf8': |
|
| 404 | + return utf_8_to_unicode($texte); |
|
| 405 | + |
|
| 406 | + case 'iso-8859-1': |
|
| 407 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1'); |
|
| 408 | + // pas de break; ici, on suit sur default: |
|
| 409 | + |
|
| 410 | + default: |
|
| 411 | + // mbstring presente ? |
|
| 412 | + if (init_mb_string()) { |
|
| 413 | + $order = mb_detect_order(); |
|
| 414 | + try { |
|
| 415 | + # mb_string connait-il $charset? |
|
| 416 | + if ($order and mb_detect_order($charset)) { |
|
| 417 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 418 | + if ($s && $s != $texte) { |
|
| 419 | + return utf_8_to_unicode($s); |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + } catch (\Error $e) { |
|
| 423 | + // Le charset n'existe probablement pas |
|
| 424 | + } finally { |
|
| 425 | + mb_detect_order($order); # remettre comme precedemment |
|
| 426 | + } |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 430 | + if (!isset($trans[$charset])) { |
|
| 431 | + if ( |
|
| 432 | + $cset = load_charset($charset) |
|
| 433 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 434 | + ) { |
|
| 435 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 436 | + $trans[$charset][chr($key)] = '&#' . $val . ';'; |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + if (isset($trans[$charset]) and is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 441 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 442 | + } |
|
| 443 | + |
|
| 444 | + // Sinon demander a iconv (malgre le fait qu'il coupe quand un |
|
| 445 | + // caractere n'appartient pas au charset, mais c'est un probleme |
|
| 446 | + // surtout en utf-8, gere ci-dessus) |
|
| 447 | + if (test_iconv()) { |
|
| 448 | + $s = iconv($charset, 'utf-32le', $texte); |
|
| 449 | + if ($s) { |
|
| 450 | + return utf_32_to_unicode($s); |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // Au pire ne rien faire |
|
| 455 | + spip_log("erreur charset '$charset' non supporte"); |
|
| 456 | + |
|
| 457 | + return $texte; |
|
| 458 | + } |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | |
@@ -474,44 +474,44 @@ discard block |
||
| 474 | 474 | * Texte transformé dans le charset souhaité |
| 475 | 475 | **/ |
| 476 | 476 | function unicode2charset($texte, $charset = 'AUTO') { |
| 477 | - static $CHARSET_REVERSE = []; |
|
| 478 | - static $trans = []; |
|
| 479 | - |
|
| 480 | - if ($charset == 'AUTO') { |
|
| 481 | - $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - switch ($charset) { |
|
| 485 | - case 'utf-8': |
|
| 486 | - return unicode_to_utf_8($texte); |
|
| 487 | - break; |
|
| 488 | - |
|
| 489 | - default: |
|
| 490 | - $charset = load_charset($charset); |
|
| 491 | - |
|
| 492 | - if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | - $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - if (!isset($trans[$charset])) { |
|
| 497 | - $trans[$charset] = []; |
|
| 498 | - $t = &$trans[$charset]; |
|
| 499 | - for ($e = 128; $e < 255; $e++) { |
|
| 500 | - $h = dechex($e); |
|
| 501 | - if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | - $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | - } else { |
|
| 506 | - $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | - $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | - } |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | - |
|
| 513 | - return $texte; |
|
| 514 | - } |
|
| 477 | + static $CHARSET_REVERSE = []; |
|
| 478 | + static $trans = []; |
|
| 479 | + |
|
| 480 | + if ($charset == 'AUTO') { |
|
| 481 | + $charset = lire_config('charset', _DEFAULT_CHARSET); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + switch ($charset) { |
|
| 485 | + case 'utf-8': |
|
| 486 | + return unicode_to_utf_8($texte); |
|
| 487 | + break; |
|
| 488 | + |
|
| 489 | + default: |
|
| 490 | + $charset = load_charset($charset); |
|
| 491 | + |
|
| 492 | + if (empty($CHARSET_REVERSE[$charset])) { |
|
| 493 | + $CHARSET_REVERSE[$charset] = array_flip($GLOBALS['CHARSET'][$charset]); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + if (!isset($trans[$charset])) { |
|
| 497 | + $trans[$charset] = []; |
|
| 498 | + $t = &$trans[$charset]; |
|
| 499 | + for ($e = 128; $e < 255; $e++) { |
|
| 500 | + $h = dechex($e); |
|
| 501 | + if ($s = isset($CHARSET_REVERSE[$charset][$e])) { |
|
| 502 | + $s = $CHARSET_REVERSE[$charset][$e]; |
|
| 503 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($s); |
|
| 504 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($s); |
|
| 505 | + } else { |
|
| 506 | + $t['&#' . $e . ';'] = $t['�' . $e . ';'] = $t['�' . $e . ';'] = chr($e); |
|
| 507 | + $t['&#x' . $h . ';'] = $t['�' . $h . ';'] = $t['�' . $h . ';'] = chr($e); |
|
| 508 | + } |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + $texte = str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 512 | + |
|
| 513 | + return $texte; |
|
| 514 | + } |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
@@ -529,40 +529,40 @@ discard block |
||
| 529 | 529 | * Texte transformé dans le charset site |
| 530 | 530 | **/ |
| 531 | 531 | function importer_charset($texte, $charset = 'AUTO') { |
| 532 | - $s = null; |
|
| 533 | - static $trans = []; |
|
| 534 | - // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 535 | - if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 536 | - $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 537 | - if (init_mb_string()) { |
|
| 538 | - if ( |
|
| 539 | - $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 540 | - and mb_detect_order($charset) |
|
| 541 | - ) { |
|
| 542 | - $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 543 | - } |
|
| 544 | - mb_detect_order($order); # remettre comme precedemment |
|
| 545 | - return $s; |
|
| 546 | - } |
|
| 547 | - // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 548 | - if (!isset($trans[$charset])) { |
|
| 549 | - if ( |
|
| 550 | - $cset = load_charset($charset) |
|
| 551 | - and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 552 | - ) { |
|
| 553 | - foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 554 | - $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 555 | - } |
|
| 556 | - } |
|
| 557 | - } |
|
| 558 | - if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 559 | - return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - return $texte; |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - return unicode2charset(charset2unicode($texte, $charset)); |
|
| 532 | + $s = null; |
|
| 533 | + static $trans = []; |
|
| 534 | + // on traite le cas le plus frequent iso-8859-1 vers utf directement pour aller plus vite ! |
|
| 535 | + if (($charset == 'iso-8859-1') && ($GLOBALS['meta']['charset'] == 'utf-8')) { |
|
| 536 | + $texte = corriger_caracteres_windows($texte, 'iso-8859-1', $GLOBALS['meta']['charset']); |
|
| 537 | + if (init_mb_string()) { |
|
| 538 | + if ( |
|
| 539 | + $order = mb_detect_order() # mb_string connait-il $charset? |
|
| 540 | + and mb_detect_order($charset) |
|
| 541 | + ) { |
|
| 542 | + $s = mb_convert_encoding($texte, 'utf-8', $charset); |
|
| 543 | + } |
|
| 544 | + mb_detect_order($order); # remettre comme precedemment |
|
| 545 | + return $s; |
|
| 546 | + } |
|
| 547 | + // Sinon, peut-etre connaissons-nous ce charset ? |
|
| 548 | + if (!isset($trans[$charset])) { |
|
| 549 | + if ( |
|
| 550 | + $cset = load_charset($charset) |
|
| 551 | + and is_array($GLOBALS['CHARSET'][$cset]) |
|
| 552 | + ) { |
|
| 553 | + foreach ($GLOBALS['CHARSET'][$cset] as $key => $val) { |
|
| 554 | + $trans[$charset][chr($key)] = unicode2charset('&#' . $val . ';'); |
|
| 555 | + } |
|
| 556 | + } |
|
| 557 | + } |
|
| 558 | + if (is_countable($trans[$charset]) ? count($trans[$charset]) : 0) { |
|
| 559 | + return str_replace(array_keys($trans[$charset]), array_values($trans[$charset]), $texte); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + return $texte; |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + return unicode2charset(charset2unicode($texte, $charset)); |
|
| 566 | 566 | } |
| 567 | 567 | |
| 568 | 568 | |
@@ -578,92 +578,92 @@ discard block |
||
| 578 | 578 | **/ |
| 579 | 579 | function utf_8_to_unicode($source) { |
| 580 | 580 | |
| 581 | - // mb_string : methode rapide |
|
| 582 | - if (init_mb_string()) { |
|
| 583 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 584 | - |
|
| 585 | - return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 586 | - } |
|
| 587 | - |
|
| 588 | - // Sinon methode pas a pas |
|
| 589 | - static $decrement; |
|
| 590 | - static $shift; |
|
| 591 | - |
|
| 592 | - // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 593 | - if (!is_array($decrement)) { |
|
| 594 | - // array used to figure what number to decrement from character order value |
|
| 595 | - // according to number of characters used to map unicode to ascii by utf-8 |
|
| 596 | - $decrement[4] = 240; |
|
| 597 | - $decrement[3] = 224; |
|
| 598 | - $decrement[2] = 192; |
|
| 599 | - $decrement[1] = 0; |
|
| 600 | - // the number of bits to shift each charNum by |
|
| 601 | - $shift[1][0] = 0; |
|
| 602 | - $shift[2][0] = 6; |
|
| 603 | - $shift[2][1] = 0; |
|
| 604 | - $shift[3][0] = 12; |
|
| 605 | - $shift[3][1] = 6; |
|
| 606 | - $shift[3][2] = 0; |
|
| 607 | - $shift[4][0] = 18; |
|
| 608 | - $shift[4][1] = 12; |
|
| 609 | - $shift[4][2] = 6; |
|
| 610 | - $shift[4][3] = 0; |
|
| 611 | - } |
|
| 612 | - |
|
| 613 | - $pos = 0; |
|
| 614 | - $len = strlen($source); |
|
| 615 | - $encodedString = ''; |
|
| 616 | - while ($pos < $len) { |
|
| 617 | - $char = ''; |
|
| 618 | - $ischar = false; |
|
| 619 | - $asciiPos = ord(substr($source, $pos, 1)); |
|
| 620 | - if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 621 | - // 4 chars representing one unicode character |
|
| 622 | - $thisLetter = substr($source, $pos, 4); |
|
| 623 | - $pos += 4; |
|
| 624 | - } else { |
|
| 625 | - if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 626 | - // 3 chars representing one unicode character |
|
| 627 | - $thisLetter = substr($source, $pos, 3); |
|
| 628 | - $pos += 3; |
|
| 629 | - } else { |
|
| 630 | - if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 631 | - // 2 chars representing one unicode character |
|
| 632 | - $thisLetter = substr($source, $pos, 2); |
|
| 633 | - $pos += 2; |
|
| 634 | - } else { |
|
| 635 | - // 1 char (lower ascii) |
|
| 636 | - $thisLetter = substr($source, $pos, 1); |
|
| 637 | - $pos += 1; |
|
| 638 | - $char = $thisLetter; |
|
| 639 | - $ischar = true; |
|
| 640 | - } |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if ($ischar) { |
|
| 645 | - $encodedString .= $char; |
|
| 646 | - } else { // process the string representing the letter to a unicode entity |
|
| 647 | - $thisLen = strlen($thisLetter); |
|
| 648 | - $thisPos = 0; |
|
| 649 | - $decimalCode = 0; |
|
| 650 | - while ($thisPos < $thisLen) { |
|
| 651 | - $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 652 | - if ($thisPos == 0) { |
|
| 653 | - $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 654 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 655 | - } else { |
|
| 656 | - $charNum = intval($thisCharOrd - 128); |
|
| 657 | - $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 658 | - } |
|
| 659 | - $thisPos++; |
|
| 660 | - } |
|
| 661 | - $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 662 | - $encodedString .= $encodedLetter; |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $encodedString; |
|
| 581 | + // mb_string : methode rapide |
|
| 582 | + if (init_mb_string()) { |
|
| 583 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 584 | + |
|
| 585 | + return mb_encode_numericentity($source, $convmap, 'UTF-8'); |
|
| 586 | + } |
|
| 587 | + |
|
| 588 | + // Sinon methode pas a pas |
|
| 589 | + static $decrement; |
|
| 590 | + static $shift; |
|
| 591 | + |
|
| 592 | + // Cf. php.net, par Ronen. Adapte pour compatibilite < php4 |
|
| 593 | + if (!is_array($decrement)) { |
|
| 594 | + // array used to figure what number to decrement from character order value |
|
| 595 | + // according to number of characters used to map unicode to ascii by utf-8 |
|
| 596 | + $decrement[4] = 240; |
|
| 597 | + $decrement[3] = 224; |
|
| 598 | + $decrement[2] = 192; |
|
| 599 | + $decrement[1] = 0; |
|
| 600 | + // the number of bits to shift each charNum by |
|
| 601 | + $shift[1][0] = 0; |
|
| 602 | + $shift[2][0] = 6; |
|
| 603 | + $shift[2][1] = 0; |
|
| 604 | + $shift[3][0] = 12; |
|
| 605 | + $shift[3][1] = 6; |
|
| 606 | + $shift[3][2] = 0; |
|
| 607 | + $shift[4][0] = 18; |
|
| 608 | + $shift[4][1] = 12; |
|
| 609 | + $shift[4][2] = 6; |
|
| 610 | + $shift[4][3] = 0; |
|
| 611 | + } |
|
| 612 | + |
|
| 613 | + $pos = 0; |
|
| 614 | + $len = strlen($source); |
|
| 615 | + $encodedString = ''; |
|
| 616 | + while ($pos < $len) { |
|
| 617 | + $char = ''; |
|
| 618 | + $ischar = false; |
|
| 619 | + $asciiPos = ord(substr($source, $pos, 1)); |
|
| 620 | + if (($asciiPos >= 240) && ($asciiPos <= 255)) { |
|
| 621 | + // 4 chars representing one unicode character |
|
| 622 | + $thisLetter = substr($source, $pos, 4); |
|
| 623 | + $pos += 4; |
|
| 624 | + } else { |
|
| 625 | + if (($asciiPos >= 224) && ($asciiPos <= 239)) { |
|
| 626 | + // 3 chars representing one unicode character |
|
| 627 | + $thisLetter = substr($source, $pos, 3); |
|
| 628 | + $pos += 3; |
|
| 629 | + } else { |
|
| 630 | + if (($asciiPos >= 192) && ($asciiPos <= 223)) { |
|
| 631 | + // 2 chars representing one unicode character |
|
| 632 | + $thisLetter = substr($source, $pos, 2); |
|
| 633 | + $pos += 2; |
|
| 634 | + } else { |
|
| 635 | + // 1 char (lower ascii) |
|
| 636 | + $thisLetter = substr($source, $pos, 1); |
|
| 637 | + $pos += 1; |
|
| 638 | + $char = $thisLetter; |
|
| 639 | + $ischar = true; |
|
| 640 | + } |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if ($ischar) { |
|
| 645 | + $encodedString .= $char; |
|
| 646 | + } else { // process the string representing the letter to a unicode entity |
|
| 647 | + $thisLen = strlen($thisLetter); |
|
| 648 | + $thisPos = 0; |
|
| 649 | + $decimalCode = 0; |
|
| 650 | + while ($thisPos < $thisLen) { |
|
| 651 | + $thisCharOrd = ord(substr($thisLetter, $thisPos, 1)); |
|
| 652 | + if ($thisPos == 0) { |
|
| 653 | + $charNum = intval($thisCharOrd - $decrement[$thisLen]); |
|
| 654 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 655 | + } else { |
|
| 656 | + $charNum = intval($thisCharOrd - 128); |
|
| 657 | + $decimalCode += ($charNum << $shift[$thisLen][$thisPos]); |
|
| 658 | + } |
|
| 659 | + $thisPos++; |
|
| 660 | + } |
|
| 661 | + $encodedLetter = '&#' . preg_replace('/^0+/', '', $decimalCode) . ';'; |
|
| 662 | + $encodedString .= $encodedLetter; |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $encodedString; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -682,32 +682,32 @@ discard block |
||
| 682 | 682 | **/ |
| 683 | 683 | function utf_32_to_unicode($source) { |
| 684 | 684 | |
| 685 | - // mb_string : methode rapide |
|
| 686 | - if (init_mb_string()) { |
|
| 687 | - $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 688 | - $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 689 | - |
|
| 690 | - return str_replace(chr(0), '', $source); |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - // Sinon methode lente |
|
| 694 | - $texte = ''; |
|
| 695 | - while ($source) { |
|
| 696 | - $words = unpack('V*', substr($source, 0, 1024)); |
|
| 697 | - $source = substr($source, 1024); |
|
| 698 | - foreach ($words as $word) { |
|
| 699 | - if ($word < 128) { |
|
| 700 | - $texte .= chr($word); |
|
| 701 | - } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 702 | - else { |
|
| 703 | - if ($word != 65279) { |
|
| 704 | - $texte .= '&#' . $word . ';'; |
|
| 705 | - } |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $texte; |
|
| 685 | + // mb_string : methode rapide |
|
| 686 | + if (init_mb_string()) { |
|
| 687 | + $convmap = [0x7F, 0xFFFFFF, 0x0, 0xFFFFFF]; |
|
| 688 | + $source = mb_encode_numericentity($source, $convmap, 'UTF-32LE'); |
|
| 689 | + |
|
| 690 | + return str_replace(chr(0), '', $source); |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + // Sinon methode lente |
|
| 694 | + $texte = ''; |
|
| 695 | + while ($source) { |
|
| 696 | + $words = unpack('V*', substr($source, 0, 1024)); |
|
| 697 | + $source = substr($source, 1024); |
|
| 698 | + foreach ($words as $word) { |
|
| 699 | + if ($word < 128) { |
|
| 700 | + $texte .= chr($word); |
|
| 701 | + } // ignorer le BOM - http://www.unicode.org/faq/utf_bom.html |
|
| 702 | + else { |
|
| 703 | + if ($word != 65279) { |
|
| 704 | + $texte .= '&#' . $word . ';'; |
|
| 705 | + } |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $texte; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | |
@@ -724,21 +724,21 @@ discard block |
||
| 724 | 724 | * Caractère utf8 si trouvé, '' sinon |
| 725 | 725 | **/ |
| 726 | 726 | function caractere_utf_8($num) { |
| 727 | - $num = intval($num); |
|
| 728 | - if ($num < 128) { |
|
| 729 | - return chr($num); |
|
| 730 | - } |
|
| 731 | - if ($num < 2048) { |
|
| 732 | - return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 733 | - } |
|
| 734 | - if ($num < 65536) { |
|
| 735 | - return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 736 | - } |
|
| 737 | - if ($num < 1_114_112) { |
|
| 738 | - return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - return ''; |
|
| 727 | + $num = intval($num); |
|
| 728 | + if ($num < 128) { |
|
| 729 | + return chr($num); |
|
| 730 | + } |
|
| 731 | + if ($num < 2048) { |
|
| 732 | + return chr(($num >> 6) + 192) . chr(($num & 63) + 128); |
|
| 733 | + } |
|
| 734 | + if ($num < 65536) { |
|
| 735 | + return chr(($num >> 12) + 224) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 736 | + } |
|
| 737 | + if ($num < 1_114_112) { |
|
| 738 | + return chr(($num >> 18) + 240) . chr((($num >> 12) & 63) + 128) . chr((($num >> 6) & 63) + 128) . chr(($num & 63) + 128); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + return ''; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | /** |
@@ -751,42 +751,42 @@ discard block |
||
| 751 | 751 | **/ |
| 752 | 752 | function unicode_to_utf_8($texte) { |
| 753 | 753 | |
| 754 | - // 1. Entites € et suivantes |
|
| 755 | - $vu = []; |
|
| 756 | - if ( |
|
| 757 | - preg_match_all( |
|
| 758 | - ',�*([1-9][0-9][0-9]+);,S', |
|
| 759 | - $texte, |
|
| 760 | - $regs, |
|
| 761 | - PREG_SET_ORDER |
|
| 762 | - ) |
|
| 763 | - ) { |
|
| 764 | - foreach ($regs as $reg) { |
|
| 765 | - if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 766 | - $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 767 | - } |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 771 | - |
|
| 772 | - // 2. Entites > ÿ |
|
| 773 | - //$vu = array(); |
|
| 774 | - if ( |
|
| 775 | - preg_match_all( |
|
| 776 | - ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 777 | - $texte, |
|
| 778 | - $regs, |
|
| 779 | - PREG_SET_ORDER |
|
| 780 | - ) |
|
| 781 | - ) { |
|
| 782 | - foreach ($regs as $reg) { |
|
| 783 | - if (!isset($vu[$reg[0]])) { |
|
| 784 | - $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 785 | - } |
|
| 786 | - } |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 754 | + // 1. Entites € et suivantes |
|
| 755 | + $vu = []; |
|
| 756 | + if ( |
|
| 757 | + preg_match_all( |
|
| 758 | + ',�*([1-9][0-9][0-9]+);,S', |
|
| 759 | + $texte, |
|
| 760 | + $regs, |
|
| 761 | + PREG_SET_ORDER |
|
| 762 | + ) |
|
| 763 | + ) { |
|
| 764 | + foreach ($regs as $reg) { |
|
| 765 | + if ($reg[1] > 127 and !isset($vu[$reg[0]])) { |
|
| 766 | + $vu[$reg[0]] = caractere_utf_8($reg[1]); |
|
| 767 | + } |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + //$texte = str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 771 | + |
|
| 772 | + // 2. Entites > ÿ |
|
| 773 | + //$vu = array(); |
|
| 774 | + if ( |
|
| 775 | + preg_match_all( |
|
| 776 | + ',�*([1-9a-f][0-9a-f][0-9a-f]+);,iS', |
|
| 777 | + $texte, |
|
| 778 | + $regs, |
|
| 779 | + PREG_SET_ORDER |
|
| 780 | + ) |
|
| 781 | + ) { |
|
| 782 | + foreach ($regs as $reg) { |
|
| 783 | + if (!isset($vu[$reg[0]])) { |
|
| 784 | + $vu[$reg[0]] = caractere_utf_8(hexdec($reg[1])); |
|
| 785 | + } |
|
| 786 | + } |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + return str_replace(array_keys($vu), array_values($vu), $texte); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -798,15 +798,15 @@ discard block |
||
| 798 | 798 | * Texte converti |
| 799 | 799 | **/ |
| 800 | 800 | function unicode_to_javascript($texte) { |
| 801 | - $vu = []; |
|
| 802 | - while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 803 | - $num = $regs[1]; |
|
| 804 | - $vu[$num] = true; |
|
| 805 | - $s = '\u' . sprintf('%04x', $num); |
|
| 806 | - $texte = str_replace($regs[0], $s, $texte); |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return $texte; |
|
| 801 | + $vu = []; |
|
| 802 | + while (preg_match(',�*([0-9]+);,S', $texte, $regs) and !isset($vu[$regs[1]])) { |
|
| 803 | + $num = $regs[1]; |
|
| 804 | + $vu[$num] = true; |
|
| 805 | + $s = '\u' . sprintf('%04x', $num); |
|
| 806 | + $texte = str_replace($regs[0], $s, $texte); |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return $texte; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -818,11 +818,11 @@ discard block |
||
| 818 | 818 | * Texte converti |
| 819 | 819 | **/ |
| 820 | 820 | function javascript_to_unicode($texte) { |
| 821 | - while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 822 | - $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 823 | - } |
|
| 821 | + while (preg_match(',%u([0-9A-F][0-9A-F][0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 822 | + $texte = str_replace($regs[0], '&#' . hexdec($regs[1]) . ';', $texte); |
|
| 823 | + } |
|
| 824 | 824 | |
| 825 | - return $texte; |
|
| 825 | + return $texte; |
|
| 826 | 826 | } |
| 827 | 827 | |
| 828 | 828 | /** |
@@ -834,11 +834,11 @@ discard block |
||
| 834 | 834 | * Texte converti |
| 835 | 835 | **/ |
| 836 | 836 | function javascript_to_binary($texte) { |
| 837 | - while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 838 | - $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 839 | - } |
|
| 837 | + while (preg_match(',%([0-9A-F][0-9A-F]),', $texte, $regs)) { |
|
| 838 | + $texte = str_replace($regs[0], chr(hexdec($regs[1])), $texte); |
|
| 839 | + } |
|
| 840 | 840 | |
| 841 | - return $texte; |
|
| 841 | + return $texte; |
|
| 842 | 842 | } |
| 843 | 843 | |
| 844 | 844 | |
@@ -856,26 +856,26 @@ discard block |
||
| 856 | 856 | * @return string |
| 857 | 857 | */ |
| 858 | 858 | function translitteration_rapide($texte, $charset = 'AUTO', $complexe = '') { |
| 859 | - static $trans = []; |
|
| 860 | - if ($charset == 'AUTO') { |
|
| 861 | - $charset = $GLOBALS['meta']['charset']; |
|
| 862 | - } |
|
| 863 | - if (!strlen($texte)) { |
|
| 864 | - return $texte; |
|
| 865 | - } |
|
| 866 | - |
|
| 867 | - $table_translit = 'translit' . $complexe; |
|
| 868 | - |
|
| 869 | - // 2. Translitterer grace a la table predefinie |
|
| 870 | - if (!isset($trans[$complexe])) { |
|
| 871 | - $trans[$complexe] = []; |
|
| 872 | - load_charset($table_translit); |
|
| 873 | - foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 874 | - $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 859 | + static $trans = []; |
|
| 860 | + if ($charset == 'AUTO') { |
|
| 861 | + $charset = $GLOBALS['meta']['charset']; |
|
| 862 | + } |
|
| 863 | + if (!strlen($texte)) { |
|
| 864 | + return $texte; |
|
| 865 | + } |
|
| 866 | + |
|
| 867 | + $table_translit = 'translit' . $complexe; |
|
| 868 | + |
|
| 869 | + // 2. Translitterer grace a la table predefinie |
|
| 870 | + if (!isset($trans[$complexe])) { |
|
| 871 | + $trans[$complexe] = []; |
|
| 872 | + load_charset($table_translit); |
|
| 873 | + foreach ($GLOBALS['CHARSET'][$table_translit] as $key => $val) { |
|
| 874 | + $trans[$complexe][caractere_utf_8($key)] = $val; |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + return str_replace(array_keys($trans[$complexe]), array_values($trans[$complexe]), $texte); |
|
| 879 | 879 | } |
| 880 | 880 | |
| 881 | 881 | /** |
@@ -898,14 +898,14 @@ discard block |
||
| 898 | 898 | * @return string |
| 899 | 899 | */ |
| 900 | 900 | function translitteration($texte, $charset = 'AUTO', $complexe = '') { |
| 901 | - // 0. Supprimer les caracteres illegaux |
|
| 902 | - include_spip('inc/filtres'); |
|
| 903 | - $texte = corriger_caracteres($texte); |
|
| 901 | + // 0. Supprimer les caracteres illegaux |
|
| 902 | + include_spip('inc/filtres'); |
|
| 903 | + $texte = corriger_caracteres($texte); |
|
| 904 | 904 | |
| 905 | - // 1. Passer le charset et les é en utf-8 |
|
| 906 | - $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 905 | + // 1. Passer le charset et les é en utf-8 |
|
| 906 | + $texte = unicode_to_utf_8(html2unicode(charset2unicode($texte, $charset))); |
|
| 907 | 907 | |
| 908 | - return translitteration_rapide($texte, $charset, $complexe); |
|
| 908 | + return translitteration_rapide($texte, $charset, $complexe); |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -920,17 +920,17 @@ discard block |
||
| 920 | 920 | * @return string |
| 921 | 921 | */ |
| 922 | 922 | function translitteration_complexe($texte, $chiffres = false) { |
| 923 | - $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 923 | + $texte = translitteration($texte, 'AUTO', 'complexe'); |
|
| 924 | 924 | |
| 925 | - if ($chiffres) { |
|
| 926 | - $texte = preg_replace_callback( |
|
| 927 | - "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 928 | - fn($m) => translitteration_chiffree($m[0]), |
|
| 929 | - $texte |
|
| 930 | - ); |
|
| 931 | - } |
|
| 925 | + if ($chiffres) { |
|
| 926 | + $texte = preg_replace_callback( |
|
| 927 | + "/[aeiuoyd]['`?~.^+(-]{1,2}/S", |
|
| 928 | + fn($m) => translitteration_chiffree($m[0]), |
|
| 929 | + $texte |
|
| 930 | + ); |
|
| 931 | + } |
|
| 932 | 932 | |
| 933 | - return $texte; |
|
| 933 | + return $texte; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | * @return string |
| 943 | 943 | */ |
| 944 | 944 | function translitteration_chiffree($car) { |
| 945 | - return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 945 | + return strtr($car, "'`?~.^+(-", '123456789'); |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | |
@@ -955,7 +955,7 @@ discard block |
||
| 955 | 955 | * true s'il a un BOM |
| 956 | 956 | **/ |
| 957 | 957 | function bom_utf8($texte) { |
| 958 | - return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 958 | + return (substr($texte, 0, 3) == chr(0xEF) . chr(0xBB) . chr(0xBF)); |
|
| 959 | 959 | } |
| 960 | 960 | |
| 961 | 961 | /** |
@@ -972,21 +972,21 @@ discard block |
||
| 972 | 972 | * true si c'est le cas |
| 973 | 973 | **/ |
| 974 | 974 | function is_utf8($string) { |
| 975 | - return !strlen( |
|
| 976 | - preg_replace( |
|
| 977 | - ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 978 | - . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 979 | - . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 980 | - . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 981 | - . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 982 | - . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 983 | - . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 984 | - . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 985 | - . ',sS', |
|
| 986 | - '', |
|
| 987 | - $string |
|
| 988 | - ) |
|
| 989 | - ); |
|
| 975 | + return !strlen( |
|
| 976 | + preg_replace( |
|
| 977 | + ',[\x09\x0A\x0D\x20-\x7E]' # ASCII |
|
| 978 | + . '|[\xC2-\xDF][\x80-\xBF]' # non-overlong 2-byte |
|
| 979 | + . '|\xE0[\xA0-\xBF][\x80-\xBF]' # excluding overlongs |
|
| 980 | + . '|[\xE1-\xEC\xEE\xEF][\x80-\xBF]{2}' # straight 3-byte |
|
| 981 | + . '|\xED[\x80-\x9F][\x80-\xBF]' # excluding surrogates |
|
| 982 | + . '|\xF0[\x90-\xBF][\x80-\xBF]{2}' # planes 1-3 |
|
| 983 | + . '|[\xF1-\xF3][\x80-\xBF]{3}' # planes 4-15 |
|
| 984 | + . '|\xF4[\x80-\x8F][\x80-\xBF]{2}' # plane 16 |
|
| 985 | + . ',sS', |
|
| 986 | + '', |
|
| 987 | + $string |
|
| 988 | + ) |
|
| 989 | + ); |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | /** |
@@ -998,13 +998,13 @@ discard block |
||
| 998 | 998 | * true si c'est le cas |
| 999 | 999 | **/ |
| 1000 | 1000 | function is_ascii($string) { |
| 1001 | - return !strlen( |
|
| 1002 | - preg_replace( |
|
| 1003 | - ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1004 | - '', |
|
| 1005 | - $string |
|
| 1006 | - ) |
|
| 1007 | - ); |
|
| 1001 | + return !strlen( |
|
| 1002 | + preg_replace( |
|
| 1003 | + ',[\x09\x0A\x0D\x20-\x7E],sS', |
|
| 1004 | + '', |
|
| 1005 | + $string |
|
| 1006 | + ) |
|
| 1007 | + ); |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | /** |
@@ -1023,53 +1023,53 @@ discard block |
||
| 1023 | 1023 | **/ |
| 1024 | 1024 | function transcoder_page($texte, $headers = '') { |
| 1025 | 1025 | |
| 1026 | - // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1027 | - if (is_ascii($texte)) { |
|
| 1028 | - #spip_log('charset: ascii'); |
|
| 1029 | - return $texte; |
|
| 1030 | - } |
|
| 1031 | - |
|
| 1032 | - if (bom_utf8($texte)) { |
|
| 1033 | - // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1034 | - $charset = 'utf-8'; |
|
| 1035 | - $texte = substr($texte, 3); |
|
| 1036 | - } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1037 | - // charset precise par le contenu (xml) |
|
| 1038 | - $charset = trim(strtolower($regs[1])); |
|
| 1039 | - } elseif ( |
|
| 1040 | - // charset precise par le contenu (html) |
|
| 1041 | - preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1042 | - # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1043 | - and false === strpos($regs[2], '#') |
|
| 1044 | - and $tmp = trim(strtolower($regs[2])) |
|
| 1045 | - ) { |
|
| 1046 | - $charset = $tmp; |
|
| 1047 | - } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1048 | - // charset de la reponse http |
|
| 1049 | - $charset = trim(strtolower($regs[1])); |
|
| 1050 | - } else { |
|
| 1051 | - $charset = ''; |
|
| 1052 | - } |
|
| 1053 | - |
|
| 1054 | - |
|
| 1055 | - // normaliser les noms du shif-jis japonais |
|
| 1056 | - if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1057 | - $charset = 'shift-jis'; |
|
| 1058 | - } |
|
| 1059 | - |
|
| 1060 | - if ($charset) { |
|
| 1061 | - spip_log("charset: $charset"); |
|
| 1062 | - } else { |
|
| 1063 | - // valeur par defaut |
|
| 1064 | - if (is_utf8($texte)) { |
|
| 1065 | - $charset = 'utf-8'; |
|
| 1066 | - } else { |
|
| 1067 | - $charset = 'iso-8859-1'; |
|
| 1068 | - } |
|
| 1069 | - spip_log("charset probable: $charset"); |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return importer_charset($texte, $charset); |
|
| 1026 | + // Si tout est < 128 pas la peine d'aller plus loin |
|
| 1027 | + if (is_ascii($texte)) { |
|
| 1028 | + #spip_log('charset: ascii'); |
|
| 1029 | + return $texte; |
|
| 1030 | + } |
|
| 1031 | + |
|
| 1032 | + if (bom_utf8($texte)) { |
|
| 1033 | + // Reconnaitre le BOM utf-8 (0xEFBBBF) |
|
| 1034 | + $charset = 'utf-8'; |
|
| 1035 | + $texte = substr($texte, 3); |
|
| 1036 | + } elseif (preg_match(',<[?]xml[^>]*encoding[^>]*=[^>]*([-_a-z0-9]+?),UimsS', $texte, $regs)) { |
|
| 1037 | + // charset precise par le contenu (xml) |
|
| 1038 | + $charset = trim(strtolower($regs[1])); |
|
| 1039 | + } elseif ( |
|
| 1040 | + // charset precise par le contenu (html) |
|
| 1041 | + preg_match(',<(meta|html|body)[^>]*charset[^>]*=[^>]*([#-_a-z0-9]+?),UimsS', $texte, $regs) |
|
| 1042 | + # eviter toute balise SPIP tel que #CHARSET ou #CONFIG d'un squelette |
|
| 1043 | + and false === strpos($regs[2], '#') |
|
| 1044 | + and $tmp = trim(strtolower($regs[2])) |
|
| 1045 | + ) { |
|
| 1046 | + $charset = $tmp; |
|
| 1047 | + } elseif (preg_match(',charset=([-_a-z0-9]+),i', $headers, $regs)) { |
|
| 1048 | + // charset de la reponse http |
|
| 1049 | + $charset = trim(strtolower($regs[1])); |
|
| 1050 | + } else { |
|
| 1051 | + $charset = ''; |
|
| 1052 | + } |
|
| 1053 | + |
|
| 1054 | + |
|
| 1055 | + // normaliser les noms du shif-jis japonais |
|
| 1056 | + if (preg_match(',^(x|shift)[_-]s?jis$,i', $charset)) { |
|
| 1057 | + $charset = 'shift-jis'; |
|
| 1058 | + } |
|
| 1059 | + |
|
| 1060 | + if ($charset) { |
|
| 1061 | + spip_log("charset: $charset"); |
|
| 1062 | + } else { |
|
| 1063 | + // valeur par defaut |
|
| 1064 | + if (is_utf8($texte)) { |
|
| 1065 | + $charset = 'utf-8'; |
|
| 1066 | + } else { |
|
| 1067 | + $charset = 'iso-8859-1'; |
|
| 1068 | + } |
|
| 1069 | + spip_log("charset probable: $charset"); |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return importer_charset($texte, $charset); |
|
| 1073 | 1073 | } |
| 1074 | 1074 | |
| 1075 | 1075 | |
@@ -1093,26 +1093,26 @@ discard block |
||
| 1093 | 1093 | * Le texte coupé |
| 1094 | 1094 | **/ |
| 1095 | 1095 | function spip_substr($c, $start = 0, $length = null) { |
| 1096 | - // Si ce n'est pas utf-8, utiliser substr |
|
| 1097 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1098 | - if ($length) { |
|
| 1099 | - return substr($c, $start, $length); |
|
| 1100 | - } else { |
|
| 1101 | - substr($c, $start); |
|
| 1102 | - } |
|
| 1103 | - } |
|
| 1104 | - |
|
| 1105 | - // Si utf-8, voir si on dispose de mb_string |
|
| 1106 | - if (init_mb_string()) { |
|
| 1107 | - if ($length) { |
|
| 1108 | - return mb_substr($c, $start, $length); |
|
| 1109 | - } else { |
|
| 1110 | - return mb_substr($c, $start); |
|
| 1111 | - } |
|
| 1112 | - } |
|
| 1113 | - |
|
| 1114 | - // Version manuelle (cf. ci-dessous) |
|
| 1115 | - return spip_substr_manuelle($c, $start, $length); |
|
| 1096 | + // Si ce n'est pas utf-8, utiliser substr |
|
| 1097 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1098 | + if ($length) { |
|
| 1099 | + return substr($c, $start, $length); |
|
| 1100 | + } else { |
|
| 1101 | + substr($c, $start); |
|
| 1102 | + } |
|
| 1103 | + } |
|
| 1104 | + |
|
| 1105 | + // Si utf-8, voir si on dispose de mb_string |
|
| 1106 | + if (init_mb_string()) { |
|
| 1107 | + if ($length) { |
|
| 1108 | + return mb_substr($c, $start, $length); |
|
| 1109 | + } else { |
|
| 1110 | + return mb_substr($c, $start); |
|
| 1111 | + } |
|
| 1112 | + } |
|
| 1113 | + |
|
| 1114 | + // Version manuelle (cf. ci-dessous) |
|
| 1115 | + return spip_substr_manuelle($c, $start, $length); |
|
| 1116 | 1116 | } |
| 1117 | 1117 | |
| 1118 | 1118 | |
@@ -1131,40 +1131,40 @@ discard block |
||
| 1131 | 1131 | **/ |
| 1132 | 1132 | function spip_substr_manuelle($c, $start, $length = null) { |
| 1133 | 1133 | |
| 1134 | - // Cas pathologique |
|
| 1135 | - if ($length === 0) { |
|
| 1136 | - return ''; |
|
| 1137 | - } |
|
| 1138 | - |
|
| 1139 | - // S'il y a un demarrage, on se positionne |
|
| 1140 | - if ($start > 0) { |
|
| 1141 | - $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1142 | - } elseif ($start < 0) { |
|
| 1143 | - return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - if (!$length) { |
|
| 1147 | - return $c; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - if ($length > 0) { |
|
| 1151 | - // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1152 | - // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1153 | - $n = 0; |
|
| 1154 | - while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | - ; |
|
| 1156 | - } |
|
| 1157 | - $c = substr($c, 0, $n * $length); |
|
| 1158 | - // puis, tant qu'on est trop long, on coupe... |
|
| 1159 | - while (($l = spip_strlen($c)) > $length) { |
|
| 1160 | - $c = substr($c, 0, $length - $l); |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - return $c; |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - // $length < 0 |
|
| 1167 | - return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1134 | + // Cas pathologique |
|
| 1135 | + if ($length === 0) { |
|
| 1136 | + return ''; |
|
| 1137 | + } |
|
| 1138 | + |
|
| 1139 | + // S'il y a un demarrage, on se positionne |
|
| 1140 | + if ($start > 0) { |
|
| 1141 | + $c = substr($c, strlen(spip_substr_manuelle($c, 0, $start))); |
|
| 1142 | + } elseif ($start < 0) { |
|
| 1143 | + return spip_substr_manuelle($c, spip_strlen($c) + $start, $length); |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + if (!$length) { |
|
| 1147 | + return $c; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + if ($length > 0) { |
|
| 1151 | + // on prend n fois la longueur desiree, pour etre surs d'avoir tout |
|
| 1152 | + // (un caractere utf-8 prenant au maximum n bytes) |
|
| 1153 | + $n = 0; |
|
| 1154 | + while (preg_match(',[\x80-\xBF]{' . (++$n) . '},', $c)) { |
|
| 1155 | + ; |
|
| 1156 | + } |
|
| 1157 | + $c = substr($c, 0, $n * $length); |
|
| 1158 | + // puis, tant qu'on est trop long, on coupe... |
|
| 1159 | + while (($l = spip_strlen($c)) > $length) { |
|
| 1160 | + $c = substr($c, 0, $length - $l); |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + return $c; |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + // $length < 0 |
|
| 1167 | + return spip_substr_manuelle($c, 0, spip_strlen($c) + $length); |
|
| 1168 | 1168 | } |
| 1169 | 1169 | |
| 1170 | 1170 | /** |
@@ -1178,14 +1178,14 @@ discard block |
||
| 1178 | 1178 | * La chaîne avec une majuscule sur le premier mot |
| 1179 | 1179 | */ |
| 1180 | 1180 | function spip_ucfirst($c) { |
| 1181 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1182 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1183 | - return ucfirst($c); |
|
| 1184 | - } |
|
| 1181 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser ucfirst |
|
| 1182 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1183 | + return ucfirst($c); |
|
| 1184 | + } |
|
| 1185 | 1185 | |
| 1186 | - $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1186 | + $lettre1 = mb_strtoupper(spip_substr($c, 0, 1)); |
|
| 1187 | 1187 | |
| 1188 | - return $lettre1 . spip_substr($c, 1); |
|
| 1188 | + return $lettre1 . spip_substr($c, 1); |
|
| 1189 | 1189 | } |
| 1190 | 1190 | |
| 1191 | 1191 | /** |
@@ -1199,12 +1199,12 @@ discard block |
||
| 1199 | 1199 | * La chaîne en minuscules |
| 1200 | 1200 | */ |
| 1201 | 1201 | function spip_strtolower($c) { |
| 1202 | - // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1203 | - if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1204 | - return strtolower($c); |
|
| 1205 | - } |
|
| 1202 | + // Si on n'a pas mb_* ou si ce n'est pas utf-8, utiliser strtolower |
|
| 1203 | + if (!init_mb_string() or $GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1204 | + return strtolower($c); |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | - return mb_strtolower($c); |
|
| 1207 | + return mb_strtolower($c); |
|
| 1208 | 1208 | } |
| 1209 | 1209 | |
| 1210 | 1210 | /** |
@@ -1218,23 +1218,23 @@ discard block |
||
| 1218 | 1218 | * Longueur de la chaîne |
| 1219 | 1219 | */ |
| 1220 | 1220 | function spip_strlen($c) { |
| 1221 | - // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1222 | - $c = str_replace("\r\n", "\n", $c); |
|
| 1223 | - |
|
| 1224 | - // Si ce n'est pas utf-8, utiliser strlen |
|
| 1225 | - if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1226 | - return strlen($c); |
|
| 1227 | - } |
|
| 1228 | - |
|
| 1229 | - // Sinon, utiliser mb_strlen() si disponible |
|
| 1230 | - if (init_mb_string()) { |
|
| 1231 | - return mb_strlen($c); |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - // Methode manuelle : on supprime les bytes 10......, |
|
| 1235 | - // on compte donc les ascii (0.......) et les demarrages |
|
| 1236 | - // de caracteres utf-8 (11......) |
|
| 1237 | - return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1221 | + // On transforme les sauts de ligne pour ne pas compter deux caractères |
|
| 1222 | + $c = str_replace("\r\n", "\n", $c); |
|
| 1223 | + |
|
| 1224 | + // Si ce n'est pas utf-8, utiliser strlen |
|
| 1225 | + if ($GLOBALS['meta']['charset'] != 'utf-8') { |
|
| 1226 | + return strlen($c); |
|
| 1227 | + } |
|
| 1228 | + |
|
| 1229 | + // Sinon, utiliser mb_strlen() si disponible |
|
| 1230 | + if (init_mb_string()) { |
|
| 1231 | + return mb_strlen($c); |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + // Methode manuelle : on supprime les bytes 10......, |
|
| 1235 | + // on compte donc les ascii (0.......) et les demarrages |
|
| 1236 | + // de caracteres utf-8 (11......) |
|
| 1237 | + return strlen(preg_replace(',[\x80-\xBF],S', '', $c)); |
|
| 1238 | 1238 | } |
| 1239 | 1239 | |
| 1240 | 1240 | // Initialisation |
@@ -1244,16 +1244,16 @@ discard block |
||
| 1244 | 1244 | // dans les preg_replace pour ne pas casser certaines lettres accentuees : |
| 1245 | 1245 | // en utf-8 chr(195).chr(160) = a` alors qu'en iso-latin chr(160) = nbsp |
| 1246 | 1246 | if ( |
| 1247 | - !isset($GLOBALS['meta']['pcre_u']) |
|
| 1248 | - or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1247 | + !isset($GLOBALS['meta']['pcre_u']) |
|
| 1248 | + or (isset($_GET['var_mode']) and !isset($_GET['var_profile'])) |
|
| 1249 | 1249 | ) { |
| 1250 | - include_spip('inc/meta'); |
|
| 1251 | - ecrire_meta( |
|
| 1252 | - 'pcre_u', |
|
| 1253 | - $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1254 | - and test_pcre_unicode()) |
|
| 1255 | - ? 'u' : '' |
|
| 1256 | - ); |
|
| 1250 | + include_spip('inc/meta'); |
|
| 1251 | + ecrire_meta( |
|
| 1252 | + 'pcre_u', |
|
| 1253 | + $u = (lire_config('charset', _DEFAULT_CHARSET) == 'utf-8' |
|
| 1254 | + and test_pcre_unicode()) |
|
| 1255 | + ? 'u' : '' |
|
| 1256 | + ); |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1269,17 +1269,17 @@ discard block |
||
| 1269 | 1269 | * en unicode : 💩 |
| 1270 | 1270 | */ |
| 1271 | 1271 | function utf8_noplanes($x) { |
| 1272 | - $regexp_utf8_4bytes = '/( |
|
| 1272 | + $regexp_utf8_4bytes = '/( |
|
| 1273 | 1273 | \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3 |
| 1274 | 1274 | | [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15 |
| 1275 | 1275 | | \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16 |
| 1276 | 1276 | )/xS'; |
| 1277 | - if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1278 | - foreach ($z[0] as $k) { |
|
| 1279 | - $ku = utf_8_to_unicode($k); |
|
| 1280 | - $x = str_replace($k, $ku, $x); |
|
| 1281 | - } |
|
| 1282 | - } |
|
| 1283 | - |
|
| 1284 | - return $x; |
|
| 1277 | + if (preg_match_all($regexp_utf8_4bytes, $x, $z, PREG_PATTERN_ORDER)) { |
|
| 1278 | + foreach ($z[0] as $k) { |
|
| 1279 | + $ku = utf_8_to_unicode($k); |
|
| 1280 | + $x = str_replace($k, $ku, $x); |
|
| 1281 | + } |
|
| 1282 | + } |
|
| 1283 | + |
|
| 1284 | + return $x; |
|
| 1285 | 1285 | } |
@@ -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 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,44 +69,44 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - $mot = null; |
|
| 73 | - $get = null; |
|
| 74 | - $hash = null; |
|
| 75 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | - return $lien; |
|
| 77 | - } |
|
| 78 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | - $r = array_pad($r, 3, null); |
|
| 72 | + $mot = null; |
|
| 73 | + $get = null; |
|
| 74 | + $hash = null; |
|
| 75 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | + return $lien; |
|
| 77 | + } |
|
| 78 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | + $r = array_pad($r, 3, null); |
|
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 82 | - } |
|
| 81 | + return $r[1] . resolve_path($r[2]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - # L'url site spip est un lien absolu aussi |
|
| 85 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | - return $lien; |
|
| 87 | - } |
|
| 84 | + # L'url site spip est un lien absolu aussi |
|
| 85 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | + return $lien; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - # lien relatif, il faut verifier l'url de base |
|
| 90 | - # commencer par virer la chaine de get de l'url de base |
|
| 91 | - $dir = '/'; |
|
| 92 | - $debut = ''; |
|
| 93 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | - $debut = $regs[1]; |
|
| 95 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | - $mot = $regs[3]; |
|
| 97 | - $get = $regs[4] ?? ''; |
|
| 98 | - $hash = $regs[5] ?? ''; |
|
| 99 | - } |
|
| 100 | - switch (substr($lien, 0, 1)) { |
|
| 101 | - case '/': |
|
| 102 | - return $debut . resolve_path($lien); |
|
| 103 | - case '#': |
|
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | - case '': |
|
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | - default: |
|
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 109 | - } |
|
| 89 | + # lien relatif, il faut verifier l'url de base |
|
| 90 | + # commencer par virer la chaine de get de l'url de base |
|
| 91 | + $dir = '/'; |
|
| 92 | + $debut = ''; |
|
| 93 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | + $debut = $regs[1]; |
|
| 95 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | + $mot = $regs[3]; |
|
| 97 | + $get = $regs[4] ?? ''; |
|
| 98 | + $hash = $regs[5] ?? ''; |
|
| 99 | + } |
|
| 100 | + switch (substr($lien, 0, 1)) { |
|
| 101 | + case '/': |
|
| 102 | + return $debut . resolve_path($lien); |
|
| 103 | + case '#': |
|
| 104 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | + case '': |
|
| 106 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | + default: |
|
| 108 | + return $debut . resolve_path($dir . $lien); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * @return string Texte ou URL (en absolus) |
| 130 | 130 | **/ |
| 131 | 131 | function url_absolue($url, $base = '') { |
| 132 | - if (strlen($url = trim($url)) == 0) { |
|
| 133 | - return ''; |
|
| 134 | - } |
|
| 135 | - if (!$base) { |
|
| 136 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 137 | - } |
|
| 132 | + if (strlen($url = trim($url)) == 0) { |
|
| 133 | + return ''; |
|
| 134 | + } |
|
| 135 | + if (!$base) { |
|
| 136 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - return suivre_lien($base, $url); |
|
| 139 | + return suivre_lien($base, $url); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | /** |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | * @return string |
| 148 | 148 | */ |
| 149 | 149 | function protocole_implicite($url_absolue) { |
| 150 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 150 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -158,16 +158,16 @@ discard block |
||
| 158 | 158 | */ |
| 159 | 159 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 160 | 160 | |
| 161 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 162 | - $protocole = $m[1]; |
|
| 163 | - if ( |
|
| 164 | - in_array($protocole, $protocoles_autorises) |
|
| 165 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 166 | - ) { |
|
| 167 | - return true; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - return false; |
|
| 161 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 162 | + $protocole = $m[1]; |
|
| 163 | + if ( |
|
| 164 | + in_array($protocole, $protocoles_autorises) |
|
| 165 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 166 | + ) { |
|
| 167 | + return true; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + return false; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -184,27 +184,27 @@ discard block |
||
| 184 | 184 | * @return string Texte avec des URLs absolues |
| 185 | 185 | **/ |
| 186 | 186 | function liens_absolus($texte, $base = '') { |
| 187 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 188 | - if (!function_exists('extraire_attribut')) { |
|
| 189 | - include_spip('inc/filtres'); |
|
| 190 | - } |
|
| 191 | - foreach ($liens as $lien) { |
|
| 192 | - foreach (['href', 'src'] as $attr) { |
|
| 193 | - $href = extraire_attribut($lien[0], $attr); |
|
| 194 | - if (strlen($href) > 0) { |
|
| 195 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 196 | - $abs = url_absolue($href, $base); |
|
| 197 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 198 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 199 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 187 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 188 | + if (!function_exists('extraire_attribut')) { |
|
| 189 | + include_spip('inc/filtres'); |
|
| 190 | + } |
|
| 191 | + foreach ($liens as $lien) { |
|
| 192 | + foreach (['href', 'src'] as $attr) { |
|
| 193 | + $href = extraire_attribut($lien[0], $attr); |
|
| 194 | + if (strlen($href) > 0) { |
|
| 195 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 196 | + $abs = url_absolue($href, $base); |
|
| 197 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 198 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 199 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $texte; |
|
| 207 | + return $texte; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | * @return string Texte ou URL (en absolus) |
| 221 | 221 | **/ |
| 222 | 222 | function abs_url($texte, $base = '') { |
| 223 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 224 | - return url_absolue($texte, $base); |
|
| 225 | - } else { |
|
| 226 | - return liens_absolus($texte, $base); |
|
| 227 | - } |
|
| 223 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 224 | + return url_absolue($texte, $base); |
|
| 225 | + } else { |
|
| 226 | + return liens_absolus($texte, $base); |
|
| 227 | + } |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -237,11 +237,11 @@ discard block |
||
| 237 | 237 | * @return string |
| 238 | 238 | */ |
| 239 | 239 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 240 | - if (is_null($flags)) { |
|
| 241 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 242 | - } |
|
| 240 | + if (is_null($flags)) { |
|
| 241 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 244 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -254,9 +254,9 @@ discard block |
||
| 254 | 254 | * @return string |
| 255 | 255 | */ |
| 256 | 256 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 257 | - if (is_null($flags)) { |
|
| 258 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 259 | - } |
|
| 257 | + if (is_null($flags)) { |
|
| 258 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 259 | + } |
|
| 260 | 260 | |
| 261 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 261 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 262 | 262 | } |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | |
| 68 | 68 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 69 | - return; |
|
| 69 | + return; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -77,46 +77,46 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function cvtmulti_recuperer_post_precedents($form) { |
| 80 | - include_spip('inc/filtres'); |
|
| 81 | - if ( |
|
| 82 | - $form |
|
| 83 | - and $c = _request('cvtm_prev_post') |
|
| 84 | - and $c = decoder_contexte_ajax($c, $form) |
|
| 85 | - ) { |
|
| 86 | - #var_dump($c); |
|
| 80 | + include_spip('inc/filtres'); |
|
| 81 | + if ( |
|
| 82 | + $form |
|
| 83 | + and $c = _request('cvtm_prev_post') |
|
| 84 | + and $c = decoder_contexte_ajax($c, $form) |
|
| 85 | + ) { |
|
| 86 | + #var_dump($c); |
|
| 87 | 87 | |
| 88 | - # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 89 | - # toutes les saisies dans un seul tableau |
|
| 90 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 91 | - $store = &$_POST; |
|
| 92 | - } else { |
|
| 93 | - $store = &$_GET; |
|
| 94 | - } |
|
| 88 | + # reinjecter dans la bonne variable pour permettre de retrouver |
|
| 89 | + # toutes les saisies dans un seul tableau |
|
| 90 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') { |
|
| 91 | + $store = &$_POST; |
|
| 92 | + } else { |
|
| 93 | + $store = &$_GET; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 97 | - if (!isset($store[$k])) { |
|
| 98 | - $_REQUEST[$k] = $store[$k] = $v; |
|
| 99 | - } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 100 | - elseif ( |
|
| 101 | - is_array($store[$k]) |
|
| 102 | - and is_array($v) |
|
| 103 | - and $z = array_keys($v) |
|
| 104 | - and !is_numeric(reset($z)) |
|
| 105 | - and $z = array_keys($store[$k]) |
|
| 106 | - and !is_numeric(reset($z)) |
|
| 107 | - ) { |
|
| 108 | - $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 109 | - } |
|
| 110 | - } |
|
| 96 | + foreach ($c as $k => $v) { // on ecrase pas si saisi a nouveau ! |
|
| 97 | + if (!isset($store[$k])) { |
|
| 98 | + $_REQUEST[$k] = $store[$k] = $v; |
|
| 99 | + } // mais si tableau des deux cotes, on merge avec priorite a la derniere saisie |
|
| 100 | + elseif ( |
|
| 101 | + is_array($store[$k]) |
|
| 102 | + and is_array($v) |
|
| 103 | + and $z = array_keys($v) |
|
| 104 | + and !is_numeric(reset($z)) |
|
| 105 | + and $z = array_keys($store[$k]) |
|
| 106 | + and !is_numeric(reset($z)) |
|
| 107 | + ) { |
|
| 108 | + $_REQUEST[$k] = $store[$k] = array_merge($v, $store[$k]); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | 111 | |
| 112 | - // vider pour eviter un second appel a verifier_n |
|
| 113 | - // en cas de double implementation (unipotence) |
|
| 114 | - set_request('cvtm_prev_post'); |
|
| 112 | + // vider pour eviter un second appel a verifier_n |
|
| 113 | + // en cas de double implementation (unipotence) |
|
| 114 | + set_request('cvtm_prev_post'); |
|
| 115 | 115 | |
| 116 | - return [$c['_etape'], $c['_etapes']]; |
|
| 117 | - } |
|
| 116 | + return [$c['_etape'], $c['_etapes']]; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 119 | + return false; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -129,28 +129,28 @@ discard block |
||
| 129 | 129 | * @return array |
| 130 | 130 | */ |
| 131 | 131 | function cvtmulti_sauver_post($form, $je_suis_poste, &$valeurs) { |
| 132 | - if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 133 | - $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 134 | - foreach (array_keys($valeurs) as $champ) { |
|
| 135 | - if (substr($champ, 0, 1) !== '_') { |
|
| 136 | - if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) { |
|
| 137 | - if (($v = _request($champ)) !== null) { |
|
| 138 | - $post[$champ] = $v; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - include_spip('inc/filtres'); |
|
| 144 | - $c = encoder_contexte_ajax($post, $form); |
|
| 145 | - if (!isset($valeurs['_hidden'])) { |
|
| 146 | - $valeurs['_hidden'] = ''; |
|
| 147 | - } |
|
| 148 | - $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 149 | - // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 150 | - $valeurs['_cvtm_prev_post'] = true; |
|
| 151 | - } |
|
| 132 | + if (!isset($valeurs['_cvtm_prev_post'])) { |
|
| 133 | + $post = ['_etape' => $valeurs['_etape'], '_etapes' => $valeurs['_etapes']]; |
|
| 134 | + foreach (array_keys($valeurs) as $champ) { |
|
| 135 | + if (substr($champ, 0, 1) !== '_') { |
|
| 136 | + if ($je_suis_poste || (isset($valeurs['_forcer_request']) && $valeurs['_forcer_request'])) { |
|
| 137 | + if (($v = _request($champ)) !== null) { |
|
| 138 | + $post[$champ] = $v; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + include_spip('inc/filtres'); |
|
| 144 | + $c = encoder_contexte_ajax($post, $form); |
|
| 145 | + if (!isset($valeurs['_hidden'])) { |
|
| 146 | + $valeurs['_hidden'] = ''; |
|
| 147 | + } |
|
| 148 | + $valeurs['_hidden'] .= "<input type='hidden' name='cvtm_prev_post' value='$c' />"; |
|
| 149 | + // marquer comme fait, pour eviter double encodage (unipotence) |
|
| 150 | + $valeurs['_cvtm_prev_post'] = true; |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - return $valeurs; |
|
| 153 | + return $valeurs; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -164,14 +164,14 @@ discard block |
||
| 164 | 164 | * @return array |
| 165 | 165 | */ |
| 166 | 166 | function cvtmulti_formulaire_charger($flux) { |
| 167 | - if ( |
|
| 168 | - is_array($flux['data']) |
|
| 169 | - and isset($flux['data']['_etapes']) |
|
| 170 | - ) { |
|
| 171 | - $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 172 | - } |
|
| 167 | + if ( |
|
| 168 | + is_array($flux['data']) |
|
| 169 | + and isset($flux['data']['_etapes']) |
|
| 170 | + ) { |
|
| 171 | + $flux['data'] = cvtmulti_formulaire_charger_etapes($flux['args'], $flux['data']); |
|
| 172 | + } |
|
| 173 | 173 | |
| 174 | - return $flux; |
|
| 174 | + return $flux; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -181,19 +181,19 @@ discard block |
||
| 181 | 181 | * @return array |
| 182 | 182 | */ |
| 183 | 183 | function cvtmulti_formulaire_charger_etapes($args, $valeurs) { |
| 184 | - if (!isset($valeurs['_etape'])) { |
|
| 185 | - $form = $args['form']; |
|
| 186 | - $je_suis_poste = $args['je_suis_poste']; |
|
| 187 | - $nb_etapes = $valeurs['_etapes']; |
|
| 188 | - $etape = _request('_etape'); |
|
| 189 | - $etape = min(max($etape, 1), $nb_etapes); |
|
| 190 | - set_request('_etape', $etape); |
|
| 191 | - $valeurs['_etape'] = $etape; |
|
| 184 | + if (!isset($valeurs['_etape'])) { |
|
| 185 | + $form = $args['form']; |
|
| 186 | + $je_suis_poste = $args['je_suis_poste']; |
|
| 187 | + $nb_etapes = $valeurs['_etapes']; |
|
| 188 | + $etape = _request('_etape'); |
|
| 189 | + $etape = min(max($etape, 1), $nb_etapes); |
|
| 190 | + set_request('_etape', $etape); |
|
| 191 | + $valeurs['_etape'] = $etape; |
|
| 192 | 192 | |
| 193 | - // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 194 | - $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 195 | - } |
|
| 196 | - return $valeurs; |
|
| 193 | + // sauver les posts de cette etape pour les avoir a la prochaine etape |
|
| 194 | + $valeurs = cvtmulti_sauver_post($form, $je_suis_poste, $valeurs); |
|
| 195 | + } |
|
| 196 | + return $valeurs; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | * @return array |
| 207 | 207 | */ |
| 208 | 208 | function cvtmulti_formulaire_verifier($flux) { |
| 209 | - $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 210 | - return $flux; |
|
| 209 | + $flux['data'] = cvtmulti_formulaire_verifier_etapes($flux['args'], $flux['data']); |
|
| 210 | + return $flux; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | /** |
@@ -218,87 +218,87 @@ discard block |
||
| 218 | 218 | * @return array |
| 219 | 219 | */ |
| 220 | 220 | function cvtmulti_formulaire_verifier_etapes($args, $erreurs) { |
| 221 | - #var_dump('Pipe verifier'); |
|
| 221 | + #var_dump('Pipe verifier'); |
|
| 222 | 222 | |
| 223 | - if ( |
|
| 224 | - $form = $args['form'] |
|
| 225 | - and ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 226 | - ) { |
|
| 227 | - // recuperer l'etape saisie et le nombre d'etapes total |
|
| 228 | - [$etape, $etapes] = $e; |
|
| 229 | - $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape |
|
| 223 | + if ( |
|
| 224 | + $form = $args['form'] |
|
| 225 | + and ($e = cvtmulti_recuperer_post_precedents($form)) !== false |
|
| 226 | + ) { |
|
| 227 | + // recuperer l'etape saisie et le nombre d'etapes total |
|
| 228 | + [$etape, $etapes] = $e; |
|
| 229 | + $etape_demandee = intval(_request('aller_a_etape')); // possibilite de poster un entier dans aller_a_etape |
|
| 230 | 230 | |
| 231 | - $args['etape_saisie'] = $etape; |
|
| 232 | - $args['etapes'] = $etapes; |
|
| 233 | - // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 234 | - $erreurs_etapes = []; |
|
| 235 | - $derniere_etape_ok = 0; |
|
| 236 | - $e = 0; |
|
| 237 | - while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) { |
|
| 238 | - $e++; |
|
| 239 | - $erreurs_etapes[$e] = []; |
|
| 240 | - if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 241 | - $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']); |
|
| 242 | - } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 243 | - $a = $args['args']; |
|
| 244 | - array_unshift($a, $e); |
|
| 245 | - $erreurs_etapes[$e] = call_user_func_array($verifier, $a); |
|
| 246 | - } |
|
| 247 | - // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 248 | - $args['etape'] = $e; |
|
| 249 | - $args['etape_demandee'] = $etape_demandee; |
|
| 250 | - $erreurs_etapes[$e] = pipeline( |
|
| 251 | - 'formulaire_verifier_etape', |
|
| 252 | - [ |
|
| 253 | - 'args' => $args, |
|
| 254 | - 'data' => $erreurs_etapes[$e] |
|
| 255 | - ] |
|
| 256 | - ); |
|
| 231 | + $args['etape_saisie'] = $etape; |
|
| 232 | + $args['etapes'] = $etapes; |
|
| 233 | + // lancer les verifs pour chaque etape deja saisie de 1 a $etape |
|
| 234 | + $erreurs_etapes = []; |
|
| 235 | + $derniere_etape_ok = 0; |
|
| 236 | + $e = 0; |
|
| 237 | + while ($e < max($etape, $etape_demandee - 1) and $e < $etapes) { |
|
| 238 | + $e++; |
|
| 239 | + $erreurs_etapes[$e] = []; |
|
| 240 | + if ($verifier = charger_fonction("verifier_$e", "formulaires/$form/", true)) { |
|
| 241 | + $erreurs_etapes[$e] = call_user_func_array($verifier, $args['args']); |
|
| 242 | + } elseif ($verifier = charger_fonction('verifier_etape', "formulaires/$form/", true)) { |
|
| 243 | + $a = $args['args']; |
|
| 244 | + array_unshift($a, $e); |
|
| 245 | + $erreurs_etapes[$e] = call_user_func_array($verifier, $a); |
|
| 246 | + } |
|
| 247 | + // et on appelle un pipeline dedie aux etapes, plus easy |
|
| 248 | + $args['etape'] = $e; |
|
| 249 | + $args['etape_demandee'] = $etape_demandee; |
|
| 250 | + $erreurs_etapes[$e] = pipeline( |
|
| 251 | + 'formulaire_verifier_etape', |
|
| 252 | + [ |
|
| 253 | + 'args' => $args, |
|
| 254 | + 'data' => $erreurs_etapes[$e] |
|
| 255 | + ] |
|
| 256 | + ); |
|
| 257 | 257 | |
| 258 | - if ($derniere_etape_ok == $e - 1 and !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 259 | - $derniere_etape_ok = $e; |
|
| 260 | - } |
|
| 261 | - // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 262 | - if (!is_null(_request("_retour_etape_$e"))) { |
|
| 263 | - $etape_demandee = $e; |
|
| 264 | - } |
|
| 265 | - // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 266 | - if ($aller_a_etape = intval(_request('aller_a_etape'))) { |
|
| 267 | - $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 268 | - } |
|
| 269 | - } |
|
| 258 | + if ($derniere_etape_ok == $e - 1 and !(is_countable($erreurs_etapes[$e]) ? count($erreurs_etapes[$e]) : 0)) { |
|
| 259 | + $derniere_etape_ok = $e; |
|
| 260 | + } |
|
| 261 | + // possibilite de poster dans _retour_etape_x ou aller_a_etape |
|
| 262 | + if (!is_null(_request("_retour_etape_$e"))) { |
|
| 263 | + $etape_demandee = $e; |
|
| 264 | + } |
|
| 265 | + // Il se peut que les verifications ait décidé de faire sauter des étapes |
|
| 266 | + if ($aller_a_etape = intval(_request('aller_a_etape'))) { |
|
| 267 | + $etape_demandee = $aller_a_etape; // possibilite de poster un entier dans aller_a_etape |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | 271 | |
| 272 | - // si la derniere etape OK etait la derniere |
|
| 273 | - // on renvoie le flux inchange et ca declenche traiter |
|
| 274 | - if ( |
|
| 275 | - $derniere_etape_ok == $etapes |
|
| 276 | - and (!$etape_demandee or $etape_demandee >= $etapes) |
|
| 277 | - ) { |
|
| 278 | - return $erreurs; |
|
| 279 | - } else { |
|
| 280 | - $etape = $derniere_etape_ok + 1; |
|
| 281 | - if ($etape_demandee > 0 and $etape_demandee < $etape) { |
|
| 282 | - $etape = $etape_demandee; |
|
| 283 | - } |
|
| 284 | - $etape = min($etape, $etapes); |
|
| 285 | - #var_dump("prochaine etape $etape"); |
|
| 286 | - // retourner les erreurs de l'etape ciblee |
|
| 287 | - $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 288 | - // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 289 | - if ($erreurs) { |
|
| 290 | - if (!isset($erreurs['message_erreur'])) { |
|
| 291 | - $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 292 | - } |
|
| 293 | - } else { |
|
| 294 | - $erreurs['message_erreur'] = ''; |
|
| 295 | - } |
|
| 296 | - $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 297 | - set_request('_etape', $etape); |
|
| 298 | - } |
|
| 299 | - } |
|
| 272 | + // si la derniere etape OK etait la derniere |
|
| 273 | + // on renvoie le flux inchange et ca declenche traiter |
|
| 274 | + if ( |
|
| 275 | + $derniere_etape_ok == $etapes |
|
| 276 | + and (!$etape_demandee or $etape_demandee >= $etapes) |
|
| 277 | + ) { |
|
| 278 | + return $erreurs; |
|
| 279 | + } else { |
|
| 280 | + $etape = $derniere_etape_ok + 1; |
|
| 281 | + if ($etape_demandee > 0 and $etape_demandee < $etape) { |
|
| 282 | + $etape = $etape_demandee; |
|
| 283 | + } |
|
| 284 | + $etape = min($etape, $etapes); |
|
| 285 | + #var_dump("prochaine etape $etape"); |
|
| 286 | + // retourner les erreurs de l'etape ciblee |
|
| 287 | + $erreurs = $erreurs_etapes[$etape] ?? []; |
|
| 288 | + // Ne pas se tromper dans le texte du message d'erreur : la clé '_etapes' n'est pas une erreur ! |
|
| 289 | + if ($erreurs) { |
|
| 290 | + if (!isset($erreurs['message_erreur'])) { |
|
| 291 | + $erreurs['message_erreur'] = singulier_ou_pluriel(is_countable($erreurs) ? count($erreurs) : 0, 'avis_1_erreur_saisie', 'avis_nb_erreurs_saisie'); |
|
| 292 | + } |
|
| 293 | + } else { |
|
| 294 | + $erreurs['message_erreur'] = ''; |
|
| 295 | + } |
|
| 296 | + $erreurs['_etapes'] = "etape suivante $etape"; |
|
| 297 | + set_request('_etape', $etape); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - return $erreurs; |
|
| 301 | + return $erreurs; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -310,17 +310,17 @@ discard block |
||
| 310 | 310 | * @return array |
| 311 | 311 | */ |
| 312 | 312 | function cvtmulti_styliser($flux) { |
| 313 | - if ( |
|
| 314 | - strncmp($flux['args']['fond'], 'formulaires/', 12) == 0 |
|
| 315 | - and isset($flux['args']['contexte']['_etapes']) |
|
| 316 | - and isset($flux['args']['contexte']['_etape']) |
|
| 317 | - and ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 318 | - and $ext = $flux['args']['ext'] |
|
| 319 | - and $f = $flux['data'] |
|
| 320 | - and file_exists($f . "_$e.$ext") |
|
| 321 | - ) { |
|
| 322 | - $flux['data'] = $f . "_$e"; |
|
| 323 | - } |
|
| 313 | + if ( |
|
| 314 | + strncmp($flux['args']['fond'], 'formulaires/', 12) == 0 |
|
| 315 | + and isset($flux['args']['contexte']['_etapes']) |
|
| 316 | + and isset($flux['args']['contexte']['_etape']) |
|
| 317 | + and ($e = $flux['args']['contexte']['_etape']) > 1 |
|
| 318 | + and $ext = $flux['args']['ext'] |
|
| 319 | + and $f = $flux['data'] |
|
| 320 | + and file_exists($f . "_$e.$ext") |
|
| 321 | + ) { |
|
| 322 | + $flux['data'] = $f . "_$e"; |
|
| 323 | + } |
|
| 324 | 324 | |
| 325 | - return $flux; |
|
| 325 | + return $flux; |
|
| 326 | 326 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 31 | - return; |
|
| 31 | + return; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -48,55 +48,55 @@ discard block |
||
| 48 | 48 | * array : description des roles applicables dans 3 index : colonne, titres, roles |
| 49 | 49 | **/ |
| 50 | 50 | function roles_presents($objet, $objet_destination = '') { |
| 51 | - $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 52 | - |
|
| 53 | - // pas de liste de roles, on sort |
|
| 54 | - if (!isset($desc['roles_titres']) or !($titres = $desc['roles_titres'])) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // on vérifie que la table de liaison existe |
|
| 59 | - include_spip('action/editer_liens'); |
|
| 60 | - if (!$lien = objet_associable($objet)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 65 | - $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 66 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 67 | - [, $table_lien] = $lien; |
|
| 68 | - $desc_lien = $trouver_table($table_lien); |
|
| 69 | - if (!isset($desc_lien['field'][$colonne])) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // sur quoi peuvent s'appliquer nos rôles |
|
| 74 | - if (!$application = $desc['roles_objets']) { |
|
| 75 | - return false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // destination presente, on restreint si possible |
|
| 79 | - if ($objet_destination) { |
|
| 80 | - $objet_destination = table_objet($objet_destination); |
|
| 81 | - |
|
| 82 | - // pour l'objet |
|
| 83 | - if (isset($application[$objet_destination])) { |
|
| 84 | - $application = $application[$objet_destination]; |
|
| 85 | - // sinon pour tous les objets |
|
| 86 | - } elseif (isset($application['*'])) { |
|
| 87 | - $application = $application['*']; |
|
| 88 | - } // sinon tant pis |
|
| 89 | - else { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // tout est ok |
|
| 95 | - return [ |
|
| 96 | - 'titres' => $titres, |
|
| 97 | - 'roles' => $application, |
|
| 98 | - 'colonne' => $colonne |
|
| 99 | - ]; |
|
| 51 | + $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 52 | + |
|
| 53 | + // pas de liste de roles, on sort |
|
| 54 | + if (!isset($desc['roles_titres']) or !($titres = $desc['roles_titres'])) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // on vérifie que la table de liaison existe |
|
| 59 | + include_spip('action/editer_liens'); |
|
| 60 | + if (!$lien = objet_associable($objet)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 65 | + $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 66 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 67 | + [, $table_lien] = $lien; |
|
| 68 | + $desc_lien = $trouver_table($table_lien); |
|
| 69 | + if (!isset($desc_lien['field'][$colonne])) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // sur quoi peuvent s'appliquer nos rôles |
|
| 74 | + if (!$application = $desc['roles_objets']) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // destination presente, on restreint si possible |
|
| 79 | + if ($objet_destination) { |
|
| 80 | + $objet_destination = table_objet($objet_destination); |
|
| 81 | + |
|
| 82 | + // pour l'objet |
|
| 83 | + if (isset($application[$objet_destination])) { |
|
| 84 | + $application = $application[$objet_destination]; |
|
| 85 | + // sinon pour tous les objets |
|
| 86 | + } elseif (isset($application['*'])) { |
|
| 87 | + $application = $application['*']; |
|
| 88 | + } // sinon tant pis |
|
| 89 | + else { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // tout est ok |
|
| 95 | + return [ |
|
| 96 | + 'titres' => $titres, |
|
| 97 | + 'roles' => $application, |
|
| 98 | + 'colonne' => $colonne |
|
| 99 | + ]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * Nom de la colonne, sinon vide |
| 111 | 111 | **/ |
| 112 | 112 | function roles_colonne($objet, $objet_destination) { |
| 113 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 114 | - return $roles['colonne']; |
|
| 115 | - } |
|
| 113 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 114 | + return $roles['colonne']; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return ''; |
|
| 117 | + return ''; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -136,24 +136,24 @@ discard block |
||
| 136 | 136 | * Liste ('', '', array()) sinon. |
| 137 | 137 | **/ |
| 138 | 138 | function roles_trouver_dans_qualif($objet, $objet_destination, $qualif = []) { |
| 139 | - // si des rôles sont possibles, on les utilise |
|
| 140 | - $role = $colonne_role = ''; # role défini |
|
| 141 | - // condition du where par defaut |
|
| 142 | - $cond = []; |
|
| 143 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 144 | - $colonne_role = $roles['colonne']; |
|
| 145 | - // qu'il n'est pas défini |
|
| 146 | - if ( |
|
| 147 | - !isset($qualif[$colonne_role]) |
|
| 148 | - or !($role = $qualif[$colonne_role]) |
|
| 149 | - ) { |
|
| 150 | - $role = $roles['roles']['defaut']; |
|
| 151 | - } |
|
| 152 | - // where |
|
| 153 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return [$role, $colonne_role, $cond]; |
|
| 139 | + // si des rôles sont possibles, on les utilise |
|
| 140 | + $role = $colonne_role = ''; # role défini |
|
| 141 | + // condition du where par defaut |
|
| 142 | + $cond = []; |
|
| 143 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 144 | + $colonne_role = $roles['colonne']; |
|
| 145 | + // qu'il n'est pas défini |
|
| 146 | + if ( |
|
| 147 | + !isset($qualif[$colonne_role]) |
|
| 148 | + or !($role = $qualif[$colonne_role]) |
|
| 149 | + ) { |
|
| 150 | + $role = $roles['roles']['defaut']; |
|
| 151 | + } |
|
| 152 | + // where |
|
| 153 | + $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return [$role, $colonne_role, $cond]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -175,21 +175,21 @@ discard block |
||
| 175 | 175 | * Liste (Tableau de conditions where complété du role, Colonne du role, role utilisé) |
| 176 | 176 | **/ |
| 177 | 177 | function roles_creer_condition_role($objet_source, $objet, $cond, $tous_si_absent = false) { |
| 178 | - // role par défaut, colonne |
|
| 179 | - [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 178 | + // role par défaut, colonne |
|
| 179 | + [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 180 | 180 | |
| 181 | - // chercher d'eventuels rôles transmis |
|
| 182 | - $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 183 | - unset($cond['role']); // cette condition est particuliere... |
|
| 181 | + // chercher d'eventuels rôles transmis |
|
| 182 | + $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 183 | + unset($cond['role']); // cette condition est particuliere... |
|
| 184 | 184 | |
| 185 | - if ($colonne_role) { |
|
| 186 | - // on ajoute la condition du role aux autres conditions. |
|
| 187 | - if ($role != '*') { |
|
| 188 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 189 | - } |
|
| 190 | - } |
|
| 185 | + if ($colonne_role) { |
|
| 186 | + // on ajoute la condition du role aux autres conditions. |
|
| 187 | + if ($role != '*') { |
|
| 188 | + $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - return [$cond, $colonne_role, $role]; |
|
| 192 | + return [$cond, $colonne_role, $role]; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -211,28 +211,28 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | function roles_complets($objet_source, $objet, $id_objet, $objet_lien) { |
| 213 | 213 | |
| 214 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 215 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 216 | - if ($presents === false) { |
|
| 217 | - return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // types de roles possibles |
|
| 221 | - $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 222 | - // couples id / roles |
|
| 223 | - $ids = $presents['ids']; |
|
| 224 | - |
|
| 225 | - // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 226 | - // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 227 | - // n'est pas complet |
|
| 228 | - $complets = []; |
|
| 229 | - foreach ($ids as $id => $roles_presents) { |
|
| 230 | - if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 231 | - $complets[] = $id; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $complets; |
|
| 214 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 215 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 216 | + if ($presents === false) { |
|
| 217 | + return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // types de roles possibles |
|
| 221 | + $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 222 | + // couples id / roles |
|
| 223 | + $ids = $presents['ids']; |
|
| 224 | + |
|
| 225 | + // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 226 | + // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 227 | + // n'est pas complet |
|
| 228 | + $complets = []; |
|
| 229 | + foreach ($ids as $id => $roles_presents) { |
|
| 230 | + if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 231 | + $complets[] = $id; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $complets; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | function roles_presents_sur_id($id_objet_source, $objet_source, $objet, $id_objet, $objet_lien) { |
| 251 | 251 | |
| 252 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 253 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 254 | - if ($presents === false) { |
|
| 255 | - return []; |
|
| 256 | - } |
|
| 252 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 253 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 254 | + if ($presents === false) { |
|
| 255 | + return []; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - if (!isset($presents['ids'][$id_objet_source])) { |
|
| 259 | - return []; |
|
| 260 | - } |
|
| 258 | + if (!isset($presents['ids'][$id_objet_source])) { |
|
| 259 | + return []; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return $presents['ids'][$id_objet_source]; |
|
| 262 | + return $presents['ids'][$id_objet_source]; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -287,47 +287,47 @@ discard block |
||
| 287 | 287 | * - False si pas de role déclarés |
| 288 | 288 | */ |
| 289 | 289 | function roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien) { |
| 290 | - static $done = []; |
|
| 291 | - |
|
| 292 | - // stocker le résultat |
|
| 293 | - $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 294 | - if (isset($done[$hash])) { |
|
| 295 | - return $done[$hash]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // pas de roles sur ces objets, on sort |
|
| 299 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 300 | - if (!$roles) { |
|
| 301 | - return $done[$hash] = false; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // inspiré de lister_objets_lies() |
|
| 305 | - if ($objet_lien == $objet) { |
|
| 306 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 307 | - } else { |
|
| 308 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // types de roles possibles |
|
| 312 | - $roles_possibles = $roles['roles']['choix']; |
|
| 313 | - // colonne du role |
|
| 314 | - $colonne = $roles['colonne']; |
|
| 315 | - |
|
| 316 | - // on recupere par id, et role existant |
|
| 317 | - $ids = []; |
|
| 318 | - while ($row = array_shift($res)) { |
|
| 319 | - $id = $row[$objet_source]; |
|
| 320 | - if (!isset($ids[$id])) { |
|
| 321 | - $ids[$id] = []; |
|
| 322 | - } |
|
| 323 | - // tableau des roles présents |
|
| 324 | - $ids[$id][] = $row[$colonne]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $done[$hash] = [ |
|
| 328 | - 'roles' => $roles, |
|
| 329 | - 'ids' => $ids |
|
| 330 | - ]; |
|
| 290 | + static $done = []; |
|
| 291 | + |
|
| 292 | + // stocker le résultat |
|
| 293 | + $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 294 | + if (isset($done[$hash])) { |
|
| 295 | + return $done[$hash]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // pas de roles sur ces objets, on sort |
|
| 299 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 300 | + if (!$roles) { |
|
| 301 | + return $done[$hash] = false; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // inspiré de lister_objets_lies() |
|
| 305 | + if ($objet_lien == $objet) { |
|
| 306 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 307 | + } else { |
|
| 308 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // types de roles possibles |
|
| 312 | + $roles_possibles = $roles['roles']['choix']; |
|
| 313 | + // colonne du role |
|
| 314 | + $colonne = $roles['colonne']; |
|
| 315 | + |
|
| 316 | + // on recupere par id, et role existant |
|
| 317 | + $ids = []; |
|
| 318 | + while ($row = array_shift($res)) { |
|
| 319 | + $id = $row[$objet_source]; |
|
| 320 | + if (!isset($ids[$id])) { |
|
| 321 | + $ids[$id] = []; |
|
| 322 | + } |
|
| 323 | + // tableau des roles présents |
|
| 324 | + $ids[$id][] = $row[$colonne]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $done[$hash] = [ |
|
| 328 | + 'roles' => $roles, |
|
| 329 | + 'ids' => $ids |
|
| 330 | + ]; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -345,33 +345,33 @@ discard block |
||
| 345 | 345 | * - false si pas de role déclarés |
| 346 | 346 | */ |
| 347 | 347 | function roles_connus_en_base($objet_source, $objet, $objet_lien) { |
| 348 | - static $done = []; |
|
| 349 | - |
|
| 350 | - // stocker le résultat |
|
| 351 | - $hash = "$objet_source-$objet-$objet_lien"; |
|
| 352 | - if (isset($done[$hash])) { |
|
| 353 | - return $done[$hash]; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if (!$lien = objet_associable($objet_lien)) { |
|
| 357 | - return $done[$hash] = false; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // pas de roles sur ces objets, on sort |
|
| 361 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 362 | - if (!$roles) { |
|
| 363 | - return $done[$hash] = false; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - [$primary, $l] = $lien; |
|
| 367 | - $colone_role = $roles['colonne']; |
|
| 368 | - |
|
| 369 | - $all = sql_allfetsel( |
|
| 370 | - "DISTINCT $colone_role", |
|
| 371 | - $l, |
|
| 372 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 373 | - ); |
|
| 374 | - $done[$hash] = array_map('reset', $all); |
|
| 375 | - |
|
| 376 | - return $done[$hash]; |
|
| 348 | + static $done = []; |
|
| 349 | + |
|
| 350 | + // stocker le résultat |
|
| 351 | + $hash = "$objet_source-$objet-$objet_lien"; |
|
| 352 | + if (isset($done[$hash])) { |
|
| 353 | + return $done[$hash]; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if (!$lien = objet_associable($objet_lien)) { |
|
| 357 | + return $done[$hash] = false; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // pas de roles sur ces objets, on sort |
|
| 361 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 362 | + if (!$roles) { |
|
| 363 | + return $done[$hash] = false; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + [$primary, $l] = $lien; |
|
| 367 | + $colone_role = $roles['colonne']; |
|
| 368 | + |
|
| 369 | + $all = sql_allfetsel( |
|
| 370 | + "DISTINCT $colone_role", |
|
| 371 | + $l, |
|
| 372 | + 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 373 | + ); |
|
| 374 | + $done[$hash] = array_map('reset', $all); |
|
| 375 | + |
|
| 376 | + return $done[$hash]; |
|
| 377 | 377 | } |