@@ -16,12 +16,12 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/rechercher'); |
| 23 | 23 | if (!defined('_DELAI_CACHE_resultats')) { |
| 24 | - define('_DELAI_CACHE_resultats', 600); |
|
| 24 | + define('_DELAI_CACHE_resultats', 600); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -48,126 +48,126 @@ discard block |
||
| 48 | 48 | * @return array |
| 49 | 49 | */ |
| 50 | 50 | function inc_prepare_recherche_dist( |
| 51 | - $recherche, |
|
| 52 | - $table = 'articles', |
|
| 53 | - $cond = false, |
|
| 54 | - $serveur = '', |
|
| 55 | - $modificateurs = [], |
|
| 56 | - $primary = '' |
|
| 51 | + $recherche, |
|
| 52 | + $table = 'articles', |
|
| 53 | + $cond = false, |
|
| 54 | + $serveur = '', |
|
| 55 | + $modificateurs = [], |
|
| 56 | + $primary = '' |
|
| 57 | 57 | ) { |
| 58 | - $where = null; |
|
| 59 | - $rows = null; |
|
| 60 | - static $cache = []; |
|
| 61 | - $delai_fraicheur = min( |
|
| 62 | - \_DELAI_CACHE_resultats, |
|
| 63 | - time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 64 | - ); |
|
| 65 | - |
|
| 66 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 67 | - // ca permet de faire des inclure simple. |
|
| 68 | - if (!isset($recherche) && isset($GLOBALS['recherche'])) { |
|
| 69 | - $recherche = $GLOBALS['recherche']; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // traiter le cas {recherche?} |
|
| 73 | - if ($cond && !strlen($recherche)) { |
|
| 74 | - return [ |
|
| 75 | - '0 as points' /* as points */, /* where */ |
|
| 76 | - '' |
|
| 77 | - ]; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - |
|
| 81 | - $rechercher = false; |
|
| 82 | - |
|
| 83 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 84 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 85 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 86 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 87 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 88 | - $row = sql_fetsel( |
|
| 89 | - 'recherche', |
|
| 90 | - 'spip_resultats AS resultats', |
|
| 91 | - $where . " AND $where_resultat_recent", |
|
| 92 | - '', |
|
| 93 | - '', |
|
| 94 | - '0,1' |
|
| 95 | - ); |
|
| 96 | - if (!$row || (defined('_VAR_MODE') && _VAR_MODE == 'recalcul')) { |
|
| 97 | - $rechercher = true; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 102 | - if ($rechercher) { |
|
| 103 | - //$tables = liste_des_champs(); |
|
| 104 | - $x = objet_type($table); |
|
| 105 | - $points = recherche_en_base( |
|
| 106 | - $recherche, |
|
| 107 | - $x, |
|
| 108 | - [ |
|
| 109 | - 'score' => true, |
|
| 110 | - 'toutvoir' => true, |
|
| 111 | - 'jointures' => true |
|
| 112 | - ], |
|
| 113 | - $serveur |
|
| 114 | - ); |
|
| 115 | - // pas de résultat, pas de point |
|
| 116 | - $points = $points[$x] ?? []; |
|
| 117 | - |
|
| 118 | - // permettre aux plugins de modifier le resultat |
|
| 119 | - $points = pipeline('prepare_recherche', [ |
|
| 120 | - 'args' => [ |
|
| 121 | - 'type' => $x, |
|
| 122 | - 'recherche' => $recherche, |
|
| 123 | - 'serveur' => $serveur, |
|
| 124 | - 'modificateurs' => $modificateurs |
|
| 125 | - ], |
|
| 126 | - 'data' => $points |
|
| 127 | - ]); |
|
| 128 | - |
|
| 129 | - // supprimer les anciens resultats de cette recherche |
|
| 130 | - // et les resultats trop vieux avec une marge |
|
| 131 | - // pas de AS resultats dans un delete (mysql) |
|
| 132 | - $whered = str_replace( |
|
| 133 | - ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 134 | - ['recherche', 'table_objet', 'serveur'], |
|
| 135 | - $where |
|
| 136 | - ); |
|
| 137 | - |
|
| 138 | - sql_delete( |
|
| 139 | - 'spip_resultats', |
|
| 140 | - "NOT($where_resultat_recent) OR ($whered)" |
|
| 141 | - ); |
|
| 142 | - |
|
| 143 | - // inserer les resultats dans la table de cache des resultats |
|
| 144 | - if (is_countable($points) ? count($points) : 0) { |
|
| 145 | - $tab_couples = []; |
|
| 146 | - foreach ($points as $id => $p) { |
|
| 147 | - $tab_couples[] = [ |
|
| 148 | - 'recherche' => $hash, |
|
| 149 | - 'id' => $id, |
|
| 150 | - 'points' => $p['score'], |
|
| 151 | - 'table_objet' => $table, |
|
| 152 | - 'serveur' => $hash_serv, |
|
| 153 | - ]; |
|
| 154 | - } |
|
| 155 | - sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 160 | - if (!$serveur) { |
|
| 161 | - $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 162 | - } else { |
|
| 163 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 164 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 165 | - } |
|
| 166 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - return $cache[$serveur][$table][$recherche]; |
|
| 58 | + $where = null; |
|
| 59 | + $rows = null; |
|
| 60 | + static $cache = []; |
|
| 61 | + $delai_fraicheur = min( |
|
| 62 | + \_DELAI_CACHE_resultats, |
|
| 63 | + time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 64 | + ); |
|
| 65 | + |
|
| 66 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 67 | + // ca permet de faire des inclure simple. |
|
| 68 | + if (!isset($recherche) && isset($GLOBALS['recherche'])) { |
|
| 69 | + $recherche = $GLOBALS['recherche']; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // traiter le cas {recherche?} |
|
| 73 | + if ($cond && !strlen($recherche)) { |
|
| 74 | + return [ |
|
| 75 | + '0 as points' /* as points */, /* where */ |
|
| 76 | + '' |
|
| 77 | + ]; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + |
|
| 81 | + $rechercher = false; |
|
| 82 | + |
|
| 83 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 84 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 85 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 86 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 87 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 88 | + $row = sql_fetsel( |
|
| 89 | + 'recherche', |
|
| 90 | + 'spip_resultats AS resultats', |
|
| 91 | + $where . " AND $where_resultat_recent", |
|
| 92 | + '', |
|
| 93 | + '', |
|
| 94 | + '0,1' |
|
| 95 | + ); |
|
| 96 | + if (!$row || (defined('_VAR_MODE') && _VAR_MODE == 'recalcul')) { |
|
| 97 | + $rechercher = true; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 102 | + if ($rechercher) { |
|
| 103 | + //$tables = liste_des_champs(); |
|
| 104 | + $x = objet_type($table); |
|
| 105 | + $points = recherche_en_base( |
|
| 106 | + $recherche, |
|
| 107 | + $x, |
|
| 108 | + [ |
|
| 109 | + 'score' => true, |
|
| 110 | + 'toutvoir' => true, |
|
| 111 | + 'jointures' => true |
|
| 112 | + ], |
|
| 113 | + $serveur |
|
| 114 | + ); |
|
| 115 | + // pas de résultat, pas de point |
|
| 116 | + $points = $points[$x] ?? []; |
|
| 117 | + |
|
| 118 | + // permettre aux plugins de modifier le resultat |
|
| 119 | + $points = pipeline('prepare_recherche', [ |
|
| 120 | + 'args' => [ |
|
| 121 | + 'type' => $x, |
|
| 122 | + 'recherche' => $recherche, |
|
| 123 | + 'serveur' => $serveur, |
|
| 124 | + 'modificateurs' => $modificateurs |
|
| 125 | + ], |
|
| 126 | + 'data' => $points |
|
| 127 | + ]); |
|
| 128 | + |
|
| 129 | + // supprimer les anciens resultats de cette recherche |
|
| 130 | + // et les resultats trop vieux avec une marge |
|
| 131 | + // pas de AS resultats dans un delete (mysql) |
|
| 132 | + $whered = str_replace( |
|
| 133 | + ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 134 | + ['recherche', 'table_objet', 'serveur'], |
|
| 135 | + $where |
|
| 136 | + ); |
|
| 137 | + |
|
| 138 | + sql_delete( |
|
| 139 | + 'spip_resultats', |
|
| 140 | + "NOT($where_resultat_recent) OR ($whered)" |
|
| 141 | + ); |
|
| 142 | + |
|
| 143 | + // inserer les resultats dans la table de cache des resultats |
|
| 144 | + if (is_countable($points) ? count($points) : 0) { |
|
| 145 | + $tab_couples = []; |
|
| 146 | + foreach ($points as $id => $p) { |
|
| 147 | + $tab_couples[] = [ |
|
| 148 | + 'recherche' => $hash, |
|
| 149 | + 'id' => $id, |
|
| 150 | + 'points' => $p['score'], |
|
| 151 | + 'table_objet' => $table, |
|
| 152 | + 'serveur' => $hash_serv, |
|
| 153 | + ]; |
|
| 154 | + } |
|
| 155 | + sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 160 | + if (!$serveur) { |
|
| 161 | + $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 162 | + } else { |
|
| 163 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 164 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 165 | + } |
|
| 166 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + return $cache[$serveur][$table][$recherche]; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | |
@@ -183,22 +183,22 @@ discard block |
||
| 183 | 183 | * @return array |
| 184 | 184 | */ |
| 185 | 185 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 186 | - # calculer le {id_article IN()} et le {... as points} |
|
| 187 | - if ($rows === []) { |
|
| 188 | - return ["''", '0=1']; |
|
| 189 | - } else { |
|
| 190 | - $listes_ids = []; |
|
| 191 | - $select = '0'; |
|
| 192 | - foreach ($rows as $r) { |
|
| 193 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - foreach ($listes_ids as $p => $ids) { |
|
| 197 | - $select .= "+$p*(" . |
|
| 198 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 199 | - . ') '; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 203 | - } |
|
| 186 | + # calculer le {id_article IN()} et le {... as points} |
|
| 187 | + if ($rows === []) { |
|
| 188 | + return ["''", '0=1']; |
|
| 189 | + } else { |
|
| 190 | + $listes_ids = []; |
|
| 191 | + $select = '0'; |
|
| 192 | + foreach ($rows as $r) { |
|
| 193 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + foreach ($listes_ids as $p => $ids) { |
|
| 197 | + $select .= "+$p*(" . |
|
| 198 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 199 | + . ') '; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 203 | + } |
|
| 204 | 204 | } |
@@ -10,10 +10,10 @@ discard block |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | if (!defined('_AUTO_SELECTION_RUBRIQUE')) { |
| 16 | - define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 16 | + define('_AUTO_SELECTION_RUBRIQUE', false); |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | |
@@ -27,39 +27,39 @@ discard block |
||
| 27 | 27 | * @return string |
| 28 | 28 | */ |
| 29 | 29 | function inc_preselectionner_parent_nouvel_objet_dist($objet, $row) { |
| 30 | - if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | - return ''; |
|
| 32 | - } |
|
| 30 | + if (!_AUTO_SELECTION_RUBRIQUE) { |
|
| 31 | + return ''; |
|
| 32 | + } |
|
| 33 | 33 | |
| 34 | - if (!isset($row['id_rubrique'])) { |
|
| 35 | - return ''; |
|
| 36 | - } |
|
| 34 | + if (!isset($row['id_rubrique'])) { |
|
| 35 | + return ''; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $id_rubrique = ''; |
|
| 39 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | - // si admin restreint : sa rubrique |
|
| 41 | - $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | - } elseif ( |
|
| 43 | - is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | - ) { |
|
| 46 | - $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | - } else { |
|
| 48 | - // sinon la derniere rubrique cree |
|
| 49 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | - } |
|
| 52 | - // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | - $id_rubrique = ''; |
|
| 55 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | - while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - } |
|
| 38 | + $id_rubrique = ''; |
|
| 39 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 40 | + // si admin restreint : sa rubrique |
|
| 41 | + $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
|
| 42 | + } elseif ( |
|
| 43 | + is_int(_AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | + ) { |
|
| 46 | + $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
|
| 47 | + } else { |
|
| 48 | + // sinon la derniere rubrique cree |
|
| 49 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', '0,1'); |
|
| 50 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 51 | + } |
|
| 52 | + // si le choix ne convient pas, on cherche dans un secteur |
|
| 53 | + if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | + $id_rubrique = ''; |
|
| 55 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 56 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 57 | + while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
|
| 58 | + if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | 63 | |
| 64 | - return $id_rubrique; |
|
| 64 | + return $id_rubrique; |
|
| 65 | 65 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | $id_rubrique = $GLOBALS['connect_id_rubrique'][0]; |
| 42 | 42 | } elseif ( |
| 43 | 43 | is_int(_AUTO_SELECTION_RUBRIQUE) |
| 44 | - && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique=' . (int) _AUTO_SELECTION_RUBRIQUE) |
|
| 44 | + && sql_fetsel('id_rubrique', 'spip_rubriques', 'id_rubrique='.(int) _AUTO_SELECTION_RUBRIQUE) |
|
| 45 | 45 | ) { |
| 46 | 46 | $id_rubrique = _AUTO_SELECTION_RUBRIQUE; |
| 47 | 47 | } else { |
@@ -50,12 +50,12 @@ discard block |
||
| 50 | 50 | $id_rubrique = $row_rub['id_rubrique']; |
| 51 | 51 | } |
| 52 | 52 | // si le choix ne convient pas, on cherche dans un secteur |
| 53 | - if (!autoriser('creer' . $objet . 'dans', 'rubrique', $id_rubrique)) { |
|
| 53 | + if (!autoriser('creer'.$objet.'dans', 'rubrique', $id_rubrique)) { |
|
| 54 | 54 | $id_rubrique = ''; |
| 55 | 55 | // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
| 56 | 56 | $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
| 57 | 57 | while (!$id_rubrique && ($row_rub = sql_fetch($res))) { |
| 58 | - if (autoriser('creer' . $objet . 'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 58 | + if (autoriser('creer'.$objet.'dans', 'rubrique', $row_rub['id_rubrique'])) { |
|
| 59 | 59 | $id_rubrique = $row_rub['id_rubrique']; |
| 60 | 60 | } |
| 61 | 61 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | include_spip('inc/acces'); |
@@ -101,93 +101,93 @@ discard block |
||
| 101 | 101 | * @return int|bool Timestamp du verrou, false si erreur |
| 102 | 102 | */ |
| 103 | 103 | function spip_nfslock($fichier, $max_age = 0) { |
| 104 | - $tries = 0; |
|
| 104 | + $tries = 0; |
|
| 105 | 105 | |
| 106 | - if (!$max_age) { |
|
| 107 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | - } |
|
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 106 | + if (!$max_age) { |
|
| 107 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 108 | + } |
|
| 109 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - /* |
|
| 112 | + /* |
|
| 113 | 113 | * 1. create a tmp file with a psuedo random file name. we also make |
| 114 | 114 | * tpath which is a buffer to store the full pathname of the tmp file. |
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | - $id = creer_uniqid(); |
|
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | - $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | - if (!$tmpfd) { /* open failed */ |
|
| 121 | - @fclose($tmpfd); |
|
| 122 | - spip_unlink($tpath); |
|
| 117 | + $id = creer_uniqid(); |
|
| 118 | + $tpath = _DIR_TMP . "slock.$id"; |
|
| 119 | + $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
|
| 120 | + if (!$tmpfd) { /* open failed */ |
|
| 121 | + @fclose($tmpfd); |
|
| 122 | + spip_unlink($tpath); |
|
| 123 | 123 | |
| 124 | - return false; //NFSL_SYSF |
|
| 125 | - } |
|
| 124 | + return false; //NFSL_SYSF |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - /* |
|
| 127 | + /* |
|
| 128 | 128 | * 2. make fullpath, a buffer for the full pathname of the lock file. |
| 129 | 129 | * then start looping trying to lock it |
| 130 | 130 | */ |
| 131 | 131 | |
| 132 | - while ($tries < 10) { |
|
| 133 | - /* |
|
| 132 | + while ($tries < 10) { |
|
| 133 | + /* |
|
| 134 | 134 | * 3. link tmp file to lock file. if it goes, we win and we clean |
| 135 | 135 | * up and return the st_ctime of the lock file. |
| 136 | 136 | */ |
| 137 | 137 | |
| 138 | - if (link($tpath, $lock_file) == 1) { |
|
| 139 | - spip_unlink($tpath); /* got it! */ |
|
| 140 | - @fclose($tmpfd); |
|
| 141 | - if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | - spip_unlink($lock_file); |
|
| 138 | + if (link($tpath, $lock_file) == 1) { |
|
| 139 | + spip_unlink($tpath); /* got it! */ |
|
| 140 | + @fclose($tmpfd); |
|
| 141 | + if (($our_tmp = lstat($lock_file)) == false) { /* stat failed... shouldn't happen */ |
|
| 142 | + spip_unlink($lock_file); |
|
| 143 | 143 | |
| 144 | - return false; // (NFSL_SYSF); |
|
| 145 | - } |
|
| 144 | + return false; // (NFSL_SYSF); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return ($our_tmp['ctime']); |
|
| 148 | - } |
|
| 147 | + return ($our_tmp['ctime']); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | - /* |
|
| 150 | + /* |
|
| 151 | 151 | * 4. the lock failed. check for a stale lock file, being mindful |
| 152 | 152 | * of NFS and the fact the time is set from the NFS server. we |
| 153 | 153 | * do a write on the tmp file to update its time to the server's |
| 154 | 154 | * idea of "now." |
| 155 | 155 | */ |
| 156 | 156 | |
| 157 | - $old_stat = lstat($lock_file); |
|
| 158 | - if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | - break; |
|
| 160 | - } /* something bogus is going on */ |
|
| 157 | + $old_stat = lstat($lock_file); |
|
| 158 | + if (@fwrite($tmpfd, 'zz', 2) != 2 || !$our_tmp = fstat($tmpfd)) { |
|
| 159 | + break; |
|
| 160 | + } /* something bogus is going on */ |
|
| 161 | 161 | |
| 162 | 162 | |
| 163 | - if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | - spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | - $tries++; |
|
| 166 | - /* It is CRITICAL that we sleep after breaking |
|
| 163 | + if ($old_stat != false && (($old_stat['ctime'] + $max_age) < $our_tmp['ctime'])) { |
|
| 164 | + spip_unlink($lock_file); /* break the stale lock */ |
|
| 165 | + $tries++; |
|
| 166 | + /* It is CRITICAL that we sleep after breaking |
|
| 167 | 167 | * the lock. Otherwise, we could race with |
| 168 | 168 | * another process and unlink it's newly- |
| 169 | 169 | * created file. |
| 170 | 170 | */ |
| 171 | - sleep(1 + random_int(0, 4)); |
|
| 172 | - continue; |
|
| 173 | - } |
|
| 171 | + sleep(1 + random_int(0, 4)); |
|
| 172 | + continue; |
|
| 173 | + } |
|
| 174 | 174 | |
| 175 | - /* |
|
| 175 | + /* |
|
| 176 | 176 | * 5. try again |
| 177 | 177 | */ |
| 178 | 178 | |
| 179 | - $tries++; |
|
| 180 | - sleep(1 + random_int(0, 4)); |
|
| 181 | - } |
|
| 179 | + $tries++; |
|
| 180 | + sleep(1 + random_int(0, 4)); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - /* |
|
| 183 | + /* |
|
| 184 | 184 | * 6. give up, failure. |
| 185 | 185 | */ |
| 186 | 186 | |
| 187 | - spip_unlink($tpath); |
|
| 188 | - @fclose($tmpfd); |
|
| 187 | + spip_unlink($tpath); |
|
| 188 | + @fclose($tmpfd); |
|
| 189 | 189 | |
| 190 | - return false; //(NFSL_LOCKED); |
|
| 190 | + return false; //(NFSL_LOCKED); |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | /** |
@@ -231,71 +231,71 @@ discard block |
||
| 231 | 231 | * return bool true si déverrouillé, false sinon |
| 232 | 232 | */ |
| 233 | 233 | function spip_nfsunlock($fichier, $birth, $max_age = 0, $test = false) { |
| 234 | - $id = creer_uniqid(); |
|
| 235 | - if (!$max_age) { |
|
| 236 | - $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | - } |
|
| 234 | + $id = creer_uniqid(); |
|
| 235 | + if (!$max_age) { |
|
| 236 | + $max_age = _DEFAULT_LOCKTIME; |
|
| 237 | + } |
|
| 238 | 238 | |
| 239 | - /* |
|
| 239 | + /* |
|
| 240 | 240 | * 1. Build a temp file and stat that to get an idea of what the server |
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | - $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | - if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
|
| 247 | - /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 248 | - @fclose($tmpfd); |
|
| 249 | - spip_unlink($tpath); |
|
| 244 | + $tpath = _DIR_TMP . "stime.$id"; |
|
| 245 | + $tmpfd = @fopen($tpath, 'w'); |
|
| 246 | + if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
|
| 247 | + /* The open failed, or we can't write the file, or we can't stat it */ |
|
| 248 | + @fclose($tmpfd); |
|
| 249 | + spip_unlink($tpath); |
|
| 250 | 250 | |
| 251 | - return false; //(NFSL_SYSF); |
|
| 252 | - } |
|
| 251 | + return false; //(NFSL_SYSF); |
|
| 252 | + } |
|
| 253 | 253 | |
| 254 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | - spip_unlink($tpath); |
|
| 254 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | + spip_unlink($tpath); |
|
| 256 | 256 | |
| 257 | - /* |
|
| 257 | + /* |
|
| 258 | 258 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 259 | 259 | */ |
| 260 | 260 | |
| 261 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 261 | + $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 262 | 262 | |
| 263 | - /* |
|
| 263 | + /* |
|
| 264 | 264 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
| 265 | 265 | * lock has expired, sleep the usual random interval before returning. |
| 266 | 266 | * If we didn't sleep, there could be a race if the caller immediately |
| 267 | 267 | * tries to relock the file. |
| 268 | 268 | */ |
| 269 | 269 | |
| 270 | - if ( |
|
| 271 | - ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 272 | - && ($old_stat['ctime'] == $birth) |
|
| 273 | - ) { /* hasn't been modified since birth */ |
|
| 274 | - if (!$test) { |
|
| 275 | - spip_unlink($lock_file); |
|
| 276 | - } /* so the lock is ours to remove */ |
|
| 277 | - if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 278 | - if (!$test) { |
|
| 279 | - return false; |
|
| 280 | - } //(NFSL_LOST); |
|
| 281 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return true;//(NFSL_OK); /* success */ |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - /* |
|
| 270 | + if ( |
|
| 271 | + ($old_stat = @lstat($lock_file)) /* stat succeeds so file is there */ |
|
| 272 | + && ($old_stat['ctime'] == $birth) |
|
| 273 | + ) { /* hasn't been modified since birth */ |
|
| 274 | + if (!$test) { |
|
| 275 | + spip_unlink($lock_file); |
|
| 276 | + } /* so the lock is ours to remove */ |
|
| 277 | + if ($our_tmp['ctime'] >= $birth + $max_age) { /* the lock has expired */ |
|
| 278 | + if (!$test) { |
|
| 279 | + return false; |
|
| 280 | + } //(NFSL_LOST); |
|
| 281 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return true;//(NFSL_OK); /* success */ |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + /* |
|
| 288 | 288 | * 4. Either ctime has been modified, or the entire lock file is missing. |
| 289 | 289 | * If the lock should still be ours, based on the ctime of the temp |
| 290 | 290 | * file, return with NFSL_STOLEN. If not, then our lock is expired and |
| 291 | 291 | * someone else has grabbed the file, so return NFSL_LOST. |
| 292 | 292 | */ |
| 293 | 293 | |
| 294 | - if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 295 | - return false; |
|
| 296 | - } //(NFSL_STOLEN); |
|
| 294 | + if ($our_tmp['ctime'] < $birth + $max_age) { /* lock was stolen */ |
|
| 295 | + return false; |
|
| 296 | + } //(NFSL_STOLEN); |
|
| 297 | 297 | |
| 298 | - return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 298 | + return false; //(NFSL_LOST); /* The lock must have expired first. */ |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | |
@@ -319,5 +319,5 @@ discard block |
||
| 319 | 319 | * return bool true si déverrouillé, false sinon |
| 320 | 320 | */ |
| 321 | 321 | function spip_nfslock_test($fichier, $birth, $max_age = 0) { |
| 322 | - return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 322 | + return spip_nfsunlock($fichier, $birth, $max_age, true); |
|
| 323 | 323 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | if (!$max_age) { |
| 107 | 107 | $max_age = _DEFAULT_LOCKTIME; |
| 108 | 108 | } |
| 109 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 109 | + $lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | 112 | /* |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | |
| 117 | 117 | $id = creer_uniqid(); |
| 118 | - $tpath = _DIR_TMP . "slock.$id"; |
|
| 118 | + $tpath = _DIR_TMP."slock.$id"; |
|
| 119 | 119 | $tmpfd = @fopen($tpath, 'w'); // hum, le 'x' necessite php4,3,2 ... |
| 120 | 120 | if (!$tmpfd) { /* open failed */ |
| 121 | 121 | @fclose($tmpfd); |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * thinks the current time is (our_tmp.st_ctime).. |
| 242 | 242 | */ |
| 243 | 243 | |
| 244 | - $tpath = _DIR_TMP . "stime.$id"; |
|
| 244 | + $tpath = _DIR_TMP."stime.$id"; |
|
| 245 | 245 | $tmpfd = @fopen($tpath, 'w'); |
| 246 | 246 | if (!$tmpfd || @fwrite($tmpfd, 'zz', 2) != 2 || !($our_tmp = fstat($tmpfd))) { |
| 247 | 247 | /* The open failed, or we can't write the file, or we can't stat it */ |
@@ -251,14 +251,14 @@ discard block |
||
| 251 | 251 | return false; //(NFSL_SYSF); |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | - @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 254 | + @fclose($tmpfd); /* We don't need this once we have our_tmp.st_ctime. */ |
|
| 255 | 255 | spip_unlink($tpath); |
| 256 | 256 | |
| 257 | 257 | /* |
| 258 | 258 | * 2. make fullpath, a buffer for the full pathname of the lock file |
| 259 | 259 | */ |
| 260 | 260 | |
| 261 | - $lock_file = _DIR_TMP . _NAME_LOCK . '-' . substr(md5($fichier), 0, 8); |
|
| 261 | + $lock_file = _DIR_TMP._NAME_LOCK.'-'.substr(md5($fichier), 0, 8); |
|
| 262 | 262 | |
| 263 | 263 | /* |
| 264 | 264 | * 3. If the ctime hasn't been modified, unlink the file and return. If the |
@@ -278,10 +278,10 @@ discard block |
||
| 278 | 278 | if (!$test) { |
| 279 | 279 | return false; |
| 280 | 280 | } //(NFSL_LOST); |
| 281 | - sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 281 | + sleep(1 + (random_int(0, 4))); /* so sleep a bit */ |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | - return true;//(NFSL_OK); /* success */ |
|
| 284 | + return true; //(NFSL_OK); /* success */ |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /* |
@@ -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 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 23 | 23 | |
@@ -30,161 +30,161 @@ discard block |
||
| 30 | 30 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 31 | 31 | */ |
| 32 | 32 | function couleur_html_to_hex($couleur) { |
| 33 | - $couleurs_html = [ |
|
| 34 | - 'aliceblue' => 'F0F8FF', |
|
| 35 | - 'antiquewhite' => 'FAEBD7', |
|
| 36 | - 'aqua' => '00FFFF', |
|
| 37 | - 'aquamarine' => '7FFFD4', |
|
| 38 | - 'azure' => 'F0FFFF', |
|
| 39 | - 'beige' => 'F5F5DC', |
|
| 40 | - 'bisque' => 'FFE4C4', |
|
| 41 | - 'black' => '000000', |
|
| 42 | - 'blanchedalmond' => 'FFEBCD', |
|
| 43 | - 'blue' => '0000FF', |
|
| 44 | - 'blueviolet' => '8A2BE2', |
|
| 45 | - 'brown' => 'A52A2A', |
|
| 46 | - 'burlywood' => 'DEB887', |
|
| 47 | - 'cadetblue' => '5F9EA0', |
|
| 48 | - 'chartreuse' => '7FFF00', |
|
| 49 | - 'chocolate' => 'D2691E', |
|
| 50 | - 'coral' => 'FF7F50', |
|
| 51 | - 'cornflowerblue' => '6495ED', |
|
| 52 | - 'cornsilk' => 'FFF8DC', |
|
| 53 | - 'crimson' => 'DC143C', |
|
| 54 | - 'cyan' => '00FFFF', |
|
| 55 | - 'darkblue' => '00008B', |
|
| 56 | - 'darkcyan' => '008B8B', |
|
| 57 | - 'darkgoldenrod' => 'B8860B', |
|
| 58 | - 'darkgray' => 'A9A9A9', |
|
| 59 | - 'darkgreen' => '006400', |
|
| 60 | - 'darkgrey' => 'A9A9A9', |
|
| 61 | - 'darkkhaki' => 'BDB76B', |
|
| 62 | - 'darkmagenta' => '8B008B', |
|
| 63 | - 'darkolivegreen' => '556B2F', |
|
| 64 | - 'darkorange' => 'FF8C00', |
|
| 65 | - 'darkorchid' => '9932CC', |
|
| 66 | - 'darkred' => '8B0000', |
|
| 67 | - 'darksalmon' => 'E9967A', |
|
| 68 | - 'darkseagreen' => '8FBC8F', |
|
| 69 | - 'darkslateblue' => '483D8B', |
|
| 70 | - 'darkslategray' => '2F4F4F', |
|
| 71 | - 'darkslategrey' => '2F4F4F', |
|
| 72 | - 'darkturquoise' => '00CED1', |
|
| 73 | - 'darkviolet' => '9400D3', |
|
| 74 | - 'deeppink' => 'FF1493', |
|
| 75 | - 'deepskyblue' => '00BFFF', |
|
| 76 | - 'dimgray' => '696969', |
|
| 77 | - 'dimgrey' => '696969', |
|
| 78 | - 'dodgerblue' => '1E90FF', |
|
| 79 | - 'firebrick' => 'B22222', |
|
| 80 | - 'floralwhite' => 'FFFAF0', |
|
| 81 | - 'forestgreen' => '228B22', |
|
| 82 | - 'fuchsia' => 'FF00FF', |
|
| 83 | - 'gainsboro' => 'DCDCDC', |
|
| 84 | - 'ghostwhite' => 'F8F8FF', |
|
| 85 | - 'gold' => 'FFD700', |
|
| 86 | - 'goldenrod' => 'DAA520', |
|
| 87 | - 'gray' => '808080', |
|
| 88 | - 'green' => '008000', |
|
| 89 | - 'greenyellow' => 'ADFF2F', |
|
| 90 | - 'grey' => '808080', |
|
| 91 | - 'honeydew' => 'F0FFF0', |
|
| 92 | - 'hotpink' => 'FF69B4', |
|
| 93 | - 'indianred' => 'CD5C5C', |
|
| 94 | - 'indigo' => '4B0082', |
|
| 95 | - 'ivory' => 'FFFFF0', |
|
| 96 | - 'khaki' => 'F0E68C', |
|
| 97 | - 'lavender' => 'E6E6FA', |
|
| 98 | - 'lavenderblush' => 'FFF0F5', |
|
| 99 | - 'lawngreen' => '7CFC00', |
|
| 100 | - 'lemonchiffon' => 'FFFACD', |
|
| 101 | - 'lightblue' => 'ADD8E6', |
|
| 102 | - 'lightcoral' => 'F08080', |
|
| 103 | - 'lightcyan' => 'E0FFFF', |
|
| 104 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 105 | - 'lightgray' => 'D3D3D3', |
|
| 106 | - 'lightgreen' => '90EE90', |
|
| 107 | - 'lightgrey' => 'D3D3D3', |
|
| 108 | - 'lightpink' => 'FFB6C1', |
|
| 109 | - 'lightsalmon' => 'FFA07A', |
|
| 110 | - 'lightseagreen' => '20B2AA', |
|
| 111 | - 'lightskyblue' => '87CEFA', |
|
| 112 | - 'lightslategray' => '778899', |
|
| 113 | - 'lightslategrey' => '778899', |
|
| 114 | - 'lightsteelblue' => 'B0C4DE', |
|
| 115 | - 'lightyellow' => 'FFFFE0', |
|
| 116 | - 'lime' => '00FF00', |
|
| 117 | - 'limegreen' => '32CD32', |
|
| 118 | - 'linen' => 'FAF0E6', |
|
| 119 | - 'magenta' => 'FF00FF', |
|
| 120 | - 'maroon' => '800000', |
|
| 121 | - 'mediumaquamarine' => '66CDAA', |
|
| 122 | - 'mediumblue' => '0000CD', |
|
| 123 | - 'mediumorchid' => 'BA55D3', |
|
| 124 | - 'mediumpurple' => '9370DB', |
|
| 125 | - 'mediumseagreen' => '3CB371', |
|
| 126 | - 'mediumslateblue' => '7B68EE', |
|
| 127 | - 'mediumspringgreen' => '00FA9A', |
|
| 128 | - 'mediumturquoise' => '48D1CC', |
|
| 129 | - 'mediumvioletred' => 'C71585', |
|
| 130 | - 'midnightblue' => '191970', |
|
| 131 | - 'mintcream' => 'F5FFFA', |
|
| 132 | - 'mistyrose' => 'FFE4E1', |
|
| 133 | - 'moccasin' => 'FFE4B5', |
|
| 134 | - 'navajowhite' => 'FFDEAD', |
|
| 135 | - 'navy' => '000080', |
|
| 136 | - 'oldlace' => 'FDF5E6', |
|
| 137 | - 'olive' => '808000', |
|
| 138 | - 'olivedrab' => '6B8E23', |
|
| 139 | - 'orange' => 'FFA500', |
|
| 140 | - 'orangered' => 'FF4500', |
|
| 141 | - 'orchid' => 'DA70D6', |
|
| 142 | - 'palegoldenrod' => 'EEE8AA', |
|
| 143 | - 'palegreen' => '98FB98', |
|
| 144 | - 'paleturquoise' => 'AFEEEE', |
|
| 145 | - 'palevioletred' => 'DB7093', |
|
| 146 | - 'papayawhip' => 'FFEFD5', |
|
| 147 | - 'peachpuff' => 'FFDAB9', |
|
| 148 | - 'peru' => 'CD853F', |
|
| 149 | - 'pink' => 'FFC0CB', |
|
| 150 | - 'plum' => 'DDA0DD', |
|
| 151 | - 'powderblue' => 'B0E0E6', |
|
| 152 | - 'purple' => '800080', |
|
| 153 | - 'rebeccapurple' => '663399', |
|
| 154 | - 'red' => 'FF0000', |
|
| 155 | - 'rosybrown' => 'BC8F8F', |
|
| 156 | - 'royalblue' => '4169E1', |
|
| 157 | - 'saddlebrown' => '8B4513', |
|
| 158 | - 'salmon' => 'FA8072', |
|
| 159 | - 'sandybrown' => 'F4A460', |
|
| 160 | - 'seagreen' => '2E8B57', |
|
| 161 | - 'seashell' => 'FFF5EE', |
|
| 162 | - 'sienna' => 'A0522D', |
|
| 163 | - 'silver' => 'C0C0C0', |
|
| 164 | - 'skyblue' => '87CEEB', |
|
| 165 | - 'slateblue' => '6A5ACD', |
|
| 166 | - 'slategray' => '708090', |
|
| 167 | - 'slategrey' => '708090', |
|
| 168 | - 'snow' => 'FFFAFA', |
|
| 169 | - 'springgreen' => '00FF7F', |
|
| 170 | - 'steelblue' => '4682B4', |
|
| 171 | - 'tan' => 'D2B48C', |
|
| 172 | - 'teal' => '008080', |
|
| 173 | - 'thistle' => 'D8BFD8', |
|
| 174 | - 'tomato' => 'FF6347', |
|
| 175 | - 'turquoise' => '40E0D0', |
|
| 176 | - 'violet' => 'EE82EE', |
|
| 177 | - 'wheat' => 'F5DEB3', |
|
| 178 | - 'white' => 'FFFFFF', |
|
| 179 | - 'whitesmoke' => 'F5F5F5', |
|
| 180 | - 'yellow' => 'FFFF00', |
|
| 181 | - 'yellowgreen' => '9ACD32', |
|
| 182 | - ]; |
|
| 183 | - if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 184 | - return $couleurs_html[$lc]; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - return $couleur; |
|
| 33 | + $couleurs_html = [ |
|
| 34 | + 'aliceblue' => 'F0F8FF', |
|
| 35 | + 'antiquewhite' => 'FAEBD7', |
|
| 36 | + 'aqua' => '00FFFF', |
|
| 37 | + 'aquamarine' => '7FFFD4', |
|
| 38 | + 'azure' => 'F0FFFF', |
|
| 39 | + 'beige' => 'F5F5DC', |
|
| 40 | + 'bisque' => 'FFE4C4', |
|
| 41 | + 'black' => '000000', |
|
| 42 | + 'blanchedalmond' => 'FFEBCD', |
|
| 43 | + 'blue' => '0000FF', |
|
| 44 | + 'blueviolet' => '8A2BE2', |
|
| 45 | + 'brown' => 'A52A2A', |
|
| 46 | + 'burlywood' => 'DEB887', |
|
| 47 | + 'cadetblue' => '5F9EA0', |
|
| 48 | + 'chartreuse' => '7FFF00', |
|
| 49 | + 'chocolate' => 'D2691E', |
|
| 50 | + 'coral' => 'FF7F50', |
|
| 51 | + 'cornflowerblue' => '6495ED', |
|
| 52 | + 'cornsilk' => 'FFF8DC', |
|
| 53 | + 'crimson' => 'DC143C', |
|
| 54 | + 'cyan' => '00FFFF', |
|
| 55 | + 'darkblue' => '00008B', |
|
| 56 | + 'darkcyan' => '008B8B', |
|
| 57 | + 'darkgoldenrod' => 'B8860B', |
|
| 58 | + 'darkgray' => 'A9A9A9', |
|
| 59 | + 'darkgreen' => '006400', |
|
| 60 | + 'darkgrey' => 'A9A9A9', |
|
| 61 | + 'darkkhaki' => 'BDB76B', |
|
| 62 | + 'darkmagenta' => '8B008B', |
|
| 63 | + 'darkolivegreen' => '556B2F', |
|
| 64 | + 'darkorange' => 'FF8C00', |
|
| 65 | + 'darkorchid' => '9932CC', |
|
| 66 | + 'darkred' => '8B0000', |
|
| 67 | + 'darksalmon' => 'E9967A', |
|
| 68 | + 'darkseagreen' => '8FBC8F', |
|
| 69 | + 'darkslateblue' => '483D8B', |
|
| 70 | + 'darkslategray' => '2F4F4F', |
|
| 71 | + 'darkslategrey' => '2F4F4F', |
|
| 72 | + 'darkturquoise' => '00CED1', |
|
| 73 | + 'darkviolet' => '9400D3', |
|
| 74 | + 'deeppink' => 'FF1493', |
|
| 75 | + 'deepskyblue' => '00BFFF', |
|
| 76 | + 'dimgray' => '696969', |
|
| 77 | + 'dimgrey' => '696969', |
|
| 78 | + 'dodgerblue' => '1E90FF', |
|
| 79 | + 'firebrick' => 'B22222', |
|
| 80 | + 'floralwhite' => 'FFFAF0', |
|
| 81 | + 'forestgreen' => '228B22', |
|
| 82 | + 'fuchsia' => 'FF00FF', |
|
| 83 | + 'gainsboro' => 'DCDCDC', |
|
| 84 | + 'ghostwhite' => 'F8F8FF', |
|
| 85 | + 'gold' => 'FFD700', |
|
| 86 | + 'goldenrod' => 'DAA520', |
|
| 87 | + 'gray' => '808080', |
|
| 88 | + 'green' => '008000', |
|
| 89 | + 'greenyellow' => 'ADFF2F', |
|
| 90 | + 'grey' => '808080', |
|
| 91 | + 'honeydew' => 'F0FFF0', |
|
| 92 | + 'hotpink' => 'FF69B4', |
|
| 93 | + 'indianred' => 'CD5C5C', |
|
| 94 | + 'indigo' => '4B0082', |
|
| 95 | + 'ivory' => 'FFFFF0', |
|
| 96 | + 'khaki' => 'F0E68C', |
|
| 97 | + 'lavender' => 'E6E6FA', |
|
| 98 | + 'lavenderblush' => 'FFF0F5', |
|
| 99 | + 'lawngreen' => '7CFC00', |
|
| 100 | + 'lemonchiffon' => 'FFFACD', |
|
| 101 | + 'lightblue' => 'ADD8E6', |
|
| 102 | + 'lightcoral' => 'F08080', |
|
| 103 | + 'lightcyan' => 'E0FFFF', |
|
| 104 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 105 | + 'lightgray' => 'D3D3D3', |
|
| 106 | + 'lightgreen' => '90EE90', |
|
| 107 | + 'lightgrey' => 'D3D3D3', |
|
| 108 | + 'lightpink' => 'FFB6C1', |
|
| 109 | + 'lightsalmon' => 'FFA07A', |
|
| 110 | + 'lightseagreen' => '20B2AA', |
|
| 111 | + 'lightskyblue' => '87CEFA', |
|
| 112 | + 'lightslategray' => '778899', |
|
| 113 | + 'lightslategrey' => '778899', |
|
| 114 | + 'lightsteelblue' => 'B0C4DE', |
|
| 115 | + 'lightyellow' => 'FFFFE0', |
|
| 116 | + 'lime' => '00FF00', |
|
| 117 | + 'limegreen' => '32CD32', |
|
| 118 | + 'linen' => 'FAF0E6', |
|
| 119 | + 'magenta' => 'FF00FF', |
|
| 120 | + 'maroon' => '800000', |
|
| 121 | + 'mediumaquamarine' => '66CDAA', |
|
| 122 | + 'mediumblue' => '0000CD', |
|
| 123 | + 'mediumorchid' => 'BA55D3', |
|
| 124 | + 'mediumpurple' => '9370DB', |
|
| 125 | + 'mediumseagreen' => '3CB371', |
|
| 126 | + 'mediumslateblue' => '7B68EE', |
|
| 127 | + 'mediumspringgreen' => '00FA9A', |
|
| 128 | + 'mediumturquoise' => '48D1CC', |
|
| 129 | + 'mediumvioletred' => 'C71585', |
|
| 130 | + 'midnightblue' => '191970', |
|
| 131 | + 'mintcream' => 'F5FFFA', |
|
| 132 | + 'mistyrose' => 'FFE4E1', |
|
| 133 | + 'moccasin' => 'FFE4B5', |
|
| 134 | + 'navajowhite' => 'FFDEAD', |
|
| 135 | + 'navy' => '000080', |
|
| 136 | + 'oldlace' => 'FDF5E6', |
|
| 137 | + 'olive' => '808000', |
|
| 138 | + 'olivedrab' => '6B8E23', |
|
| 139 | + 'orange' => 'FFA500', |
|
| 140 | + 'orangered' => 'FF4500', |
|
| 141 | + 'orchid' => 'DA70D6', |
|
| 142 | + 'palegoldenrod' => 'EEE8AA', |
|
| 143 | + 'palegreen' => '98FB98', |
|
| 144 | + 'paleturquoise' => 'AFEEEE', |
|
| 145 | + 'palevioletred' => 'DB7093', |
|
| 146 | + 'papayawhip' => 'FFEFD5', |
|
| 147 | + 'peachpuff' => 'FFDAB9', |
|
| 148 | + 'peru' => 'CD853F', |
|
| 149 | + 'pink' => 'FFC0CB', |
|
| 150 | + 'plum' => 'DDA0DD', |
|
| 151 | + 'powderblue' => 'B0E0E6', |
|
| 152 | + 'purple' => '800080', |
|
| 153 | + 'rebeccapurple' => '663399', |
|
| 154 | + 'red' => 'FF0000', |
|
| 155 | + 'rosybrown' => 'BC8F8F', |
|
| 156 | + 'royalblue' => '4169E1', |
|
| 157 | + 'saddlebrown' => '8B4513', |
|
| 158 | + 'salmon' => 'FA8072', |
|
| 159 | + 'sandybrown' => 'F4A460', |
|
| 160 | + 'seagreen' => '2E8B57', |
|
| 161 | + 'seashell' => 'FFF5EE', |
|
| 162 | + 'sienna' => 'A0522D', |
|
| 163 | + 'silver' => 'C0C0C0', |
|
| 164 | + 'skyblue' => '87CEEB', |
|
| 165 | + 'slateblue' => '6A5ACD', |
|
| 166 | + 'slategray' => '708090', |
|
| 167 | + 'slategrey' => '708090', |
|
| 168 | + 'snow' => 'FFFAFA', |
|
| 169 | + 'springgreen' => '00FF7F', |
|
| 170 | + 'steelblue' => '4682B4', |
|
| 171 | + 'tan' => 'D2B48C', |
|
| 172 | + 'teal' => '008080', |
|
| 173 | + 'thistle' => 'D8BFD8', |
|
| 174 | + 'tomato' => 'FF6347', |
|
| 175 | + 'turquoise' => '40E0D0', |
|
| 176 | + 'violet' => 'EE82EE', |
|
| 177 | + 'wheat' => 'F5DEB3', |
|
| 178 | + 'white' => 'FFFFFF', |
|
| 179 | + 'whitesmoke' => 'F5F5F5', |
|
| 180 | + 'yellow' => 'FFFF00', |
|
| 181 | + 'yellowgreen' => '9ACD32', |
|
| 182 | + ]; |
|
| 183 | + if (isset($couleurs_html[$lc = strtolower($couleur ?? '')])) { |
|
| 184 | + return $couleurs_html[$lc]; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + return $couleur; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -200,16 +200,16 @@ discard block |
||
| 200 | 200 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 201 | 201 | */ |
| 202 | 202 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 203 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 204 | - $hsl = [ |
|
| 205 | - 'h' => round($hsl['h'] * 360), |
|
| 206 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 207 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 208 | - ]; |
|
| 209 | - if ($format === null) { |
|
| 210 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 211 | - } |
|
| 212 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 203 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 204 | + $hsl = [ |
|
| 205 | + 'h' => round($hsl['h'] * 360), |
|
| 206 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 207 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 208 | + ]; |
|
| 209 | + if ($format === null) { |
|
| 210 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 211 | + } |
|
| 212 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | |
@@ -226,16 +226,16 @@ discard block |
||
| 226 | 226 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 227 | 227 | */ |
| 228 | 228 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 229 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 230 | - $rgb = [ |
|
| 231 | - 'r' => $rgb['red'], |
|
| 232 | - 'g' => $rgb['green'], |
|
| 233 | - 'b' => $rgb['blue'], |
|
| 234 | - ]; |
|
| 235 | - if ($format === null) { |
|
| 236 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 237 | - } |
|
| 238 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 229 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 230 | + $rgb = [ |
|
| 231 | + 'r' => $rgb['red'], |
|
| 232 | + 'g' => $rgb['green'], |
|
| 233 | + 'b' => $rgb['blue'], |
|
| 234 | + ]; |
|
| 235 | + if ($format === null) { |
|
| 236 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 237 | + } |
|
| 238 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 239 | 239 | } |
| 240 | 240 | |
| 241 | 241 | /** |
@@ -251,13 +251,13 @@ discard block |
||
| 251 | 251 | * Code hexadécimal de la couleur plus foncée |
| 252 | 252 | */ |
| 253 | 253 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 254 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 254 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | 255 | |
| 256 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 257 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 258 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 256 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 257 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 258 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 259 | 259 | |
| 260 | - return _couleur_dec_to_hex($red, $green, $blue); |
|
| 260 | + return _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -273,13 +273,13 @@ discard block |
||
| 273 | 273 | * Code hexadécimal de la couleur éclaircie |
| 274 | 274 | */ |
| 275 | 275 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 276 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 276 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 277 | 277 | |
| 278 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 279 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 280 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 278 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 279 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 280 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | 281 | |
| 282 | - return _couleur_dec_to_hex($red, $green, $blue); |
|
| 282 | + return _couleur_dec_to_hex($red, $green, $blue); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -302,28 +302,28 @@ discard block |
||
| 302 | 302 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 303 | 303 | */ |
| 304 | 304 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 305 | - if (!$img) { |
|
| 306 | - return $img; |
|
| 307 | - } |
|
| 308 | - [$h, $l] = taille_image($img); |
|
| 309 | - $select = true; |
|
| 310 | - if ($l < $width_min || $l > $width_max || $h < $height_min || $h > $height_max) { |
|
| 311 | - $select = false; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $class = extraire_attribut($img, 'class'); |
|
| 315 | - $p = strpos($class, 'filtre_inactif'); |
|
| 316 | - if ($select == false && $p === false) { |
|
| 317 | - $class .= ' filtre_inactif'; |
|
| 318 | - $img = inserer_attribut($img, 'class', $class); |
|
| 319 | - } |
|
| 320 | - if ($select == true && $p !== false) { |
|
| 321 | - // no_image_filtrer : historique, a virer |
|
| 322 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - return $img; |
|
| 305 | + if (!$img) { |
|
| 306 | + return $img; |
|
| 307 | + } |
|
| 308 | + [$h, $l] = taille_image($img); |
|
| 309 | + $select = true; |
|
| 310 | + if ($l < $width_min || $l > $width_max || $h < $height_min || $h > $height_max) { |
|
| 311 | + $select = false; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $class = extraire_attribut($img, 'class'); |
|
| 315 | + $p = strpos($class, 'filtre_inactif'); |
|
| 316 | + if ($select == false && $p === false) { |
|
| 317 | + $class .= ' filtre_inactif'; |
|
| 318 | + $img = inserer_attribut($img, 'class', $class); |
|
| 319 | + } |
|
| 320 | + if ($select == true && $p !== false) { |
|
| 321 | + // no_image_filtrer : historique, a virer |
|
| 322 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + return $img; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | /** |
@@ -371,45 +371,45 @@ discard block |
||
| 371 | 371 | * Code HTML de l'image ou du texte. |
| 372 | 372 | **/ |
| 373 | 373 | function image_passe_partout( |
| 374 | - $img, |
|
| 375 | - $taille_x = -1, |
|
| 376 | - $taille_y = -1, |
|
| 377 | - $force = false, |
|
| 378 | - $cherche_image = false, |
|
| 379 | - $process = 'AUTO' |
|
| 374 | + $img, |
|
| 375 | + $taille_x = -1, |
|
| 376 | + $taille_y = -1, |
|
| 377 | + $force = false, |
|
| 378 | + $cherche_image = false, |
|
| 379 | + $process = 'AUTO' |
|
| 380 | 380 | ) { |
| 381 | - // PHP 7+ type hint |
|
| 382 | - $img = (string)$img; |
|
| 383 | - $taille_x = (int)$taille_x; |
|
| 384 | - $taille_y = (int)$taille_y; |
|
| 385 | - $force = (bool)$force; |
|
| 386 | - $process = (string)$process; |
|
| 387 | - |
|
| 388 | - if (!$img) { |
|
| 389 | - return ''; |
|
| 390 | - } |
|
| 391 | - [$hauteur, $largeur] = taille_image($img); |
|
| 392 | - if ($taille_x === -1) { |
|
| 393 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 394 | - } |
|
| 395 | - if ($taille_y === -1) { |
|
| 396 | - $taille_y = $taille_x; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if ($taille_x === 0 && $taille_y > 0) { |
|
| 400 | - $taille_x = 1; |
|
| 401 | - } # {0,300} -> c'est 300 qui compte |
|
| 402 | - elseif ($taille_x > 0 && $taille_y === 0) { |
|
| 403 | - $taille_y = 1; |
|
| 404 | - } # {300,0} -> c'est 300 qui compte |
|
| 405 | - elseif ($taille_x == 0 && $taille_y === 0) { |
|
| 406 | - return ''; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 410 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 411 | - |
|
| 412 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 381 | + // PHP 7+ type hint |
|
| 382 | + $img = (string)$img; |
|
| 383 | + $taille_x = (int)$taille_x; |
|
| 384 | + $taille_y = (int)$taille_y; |
|
| 385 | + $force = (bool)$force; |
|
| 386 | + $process = (string)$process; |
|
| 387 | + |
|
| 388 | + if (!$img) { |
|
| 389 | + return ''; |
|
| 390 | + } |
|
| 391 | + [$hauteur, $largeur] = taille_image($img); |
|
| 392 | + if ($taille_x === -1) { |
|
| 393 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 394 | + } |
|
| 395 | + if ($taille_y === -1) { |
|
| 396 | + $taille_y = $taille_x; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if ($taille_x === 0 && $taille_y > 0) { |
|
| 400 | + $taille_x = 1; |
|
| 401 | + } # {0,300} -> c'est 300 qui compte |
|
| 402 | + elseif ($taille_x > 0 && $taille_y === 0) { |
|
| 403 | + $taille_y = 1; |
|
| 404 | + } # {300,0} -> c'est 300 qui compte |
|
| 405 | + elseif ($taille_x == 0 && $taille_y === 0) { |
|
| 406 | + return ''; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 410 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 411 | + |
|
| 412 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -452,44 +452,44 @@ discard block |
||
| 452 | 452 | * Code HTML de l'image ou du texte. |
| 453 | 453 | **/ |
| 454 | 454 | function image_reduire( |
| 455 | - $img, |
|
| 456 | - $taille = -1, |
|
| 457 | - $taille_y = -1, |
|
| 458 | - $force = false, |
|
| 459 | - $cherche_image = false, |
|
| 460 | - $process = 'AUTO' |
|
| 455 | + $img, |
|
| 456 | + $taille = -1, |
|
| 457 | + $taille_y = -1, |
|
| 458 | + $force = false, |
|
| 459 | + $cherche_image = false, |
|
| 460 | + $process = 'AUTO' |
|
| 461 | 461 | ) { |
| 462 | - // PHP 7+ type hint |
|
| 463 | - $img = (string)$img; |
|
| 464 | - $taille = (int)$taille; |
|
| 465 | - $taille_y = (int)$taille_y; |
|
| 466 | - $force = (bool)$force; |
|
| 467 | - $process = (string)$process; |
|
| 468 | - |
|
| 469 | - // Determiner la taille x,y maxi |
|
| 470 | - // prendre le reglage de previsu par defaut |
|
| 471 | - if ($taille === -1) { |
|
| 472 | - $taille = (isset($GLOBALS['meta']['taille_preview']) && (int) $GLOBALS['meta']['taille_preview']) |
|
| 473 | - ? (int) $GLOBALS['meta']['taille_preview'] |
|
| 474 | - : 150; |
|
| 475 | - } |
|
| 476 | - if ($taille_y === -1) { |
|
| 477 | - $taille_y = $taille; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - if ($taille === 0 && $taille_y > 0) { |
|
| 481 | - $taille = 10000; |
|
| 482 | - } # {0,300} -> c'est 300 qui compte |
|
| 483 | - elseif ($taille > 0 && $taille_y === 0) { |
|
| 484 | - $taille_y = 10000; |
|
| 485 | - } # {300,0} -> c'est 300 qui compte |
|
| 486 | - elseif ($taille == 0 && $taille_y === 0) { |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - |
|
| 490 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 491 | - |
|
| 492 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 462 | + // PHP 7+ type hint |
|
| 463 | + $img = (string)$img; |
|
| 464 | + $taille = (int)$taille; |
|
| 465 | + $taille_y = (int)$taille_y; |
|
| 466 | + $force = (bool)$force; |
|
| 467 | + $process = (string)$process; |
|
| 468 | + |
|
| 469 | + // Determiner la taille x,y maxi |
|
| 470 | + // prendre le reglage de previsu par defaut |
|
| 471 | + if ($taille === -1) { |
|
| 472 | + $taille = (isset($GLOBALS['meta']['taille_preview']) && (int) $GLOBALS['meta']['taille_preview']) |
|
| 473 | + ? (int) $GLOBALS['meta']['taille_preview'] |
|
| 474 | + : 150; |
|
| 475 | + } |
|
| 476 | + if ($taille_y === -1) { |
|
| 477 | + $taille_y = $taille; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + if ($taille === 0 && $taille_y > 0) { |
|
| 481 | + $taille = 10000; |
|
| 482 | + } # {0,300} -> c'est 300 qui compte |
|
| 483 | + elseif ($taille > 0 && $taille_y === 0) { |
|
| 484 | + $taille_y = 10000; |
|
| 485 | + } # {300,0} -> c'est 300 qui compte |
|
| 486 | + elseif ($taille == 0 && $taille_y === 0) { |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + |
|
| 490 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 491 | + |
|
| 492 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 493 | 493 | } |
| 494 | 494 | |
| 495 | 495 | /** |
@@ -500,16 +500,16 @@ discard block |
||
| 500 | 500 | * |
| 501 | 501 | **/ |
| 502 | 502 | function image_recadre_avec_fallback( |
| 503 | - $im, |
|
| 504 | - $width, |
|
| 505 | - $height = '-', |
|
| 506 | - $position = 'focus', |
|
| 507 | - $background_color = 'white' |
|
| 503 | + $im, |
|
| 504 | + $width, |
|
| 505 | + $height = '-', |
|
| 506 | + $position = 'focus', |
|
| 507 | + $background_color = 'white' |
|
| 508 | 508 | ) { |
| 509 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 510 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 511 | - } else { return image_passe_partout($im, $width, $height); |
|
| 512 | - } |
|
| 509 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 510 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 511 | + } else { return image_passe_partout($im, $width, $height); |
|
| 512 | + } |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -527,23 +527,23 @@ discard block |
||
| 527 | 527 | * Code HTML de l'image ou du texte. |
| 528 | 528 | **/ |
| 529 | 529 | function image_reduire_par($img, $val = 1, $force = false) { |
| 530 | - // PHP 7+ type hint |
|
| 531 | - $img = (string)$img; |
|
| 532 | - $val = (int)$val; |
|
| 533 | - $force = (bool)$force; |
|
| 530 | + // PHP 7+ type hint |
|
| 531 | + $img = (string)$img; |
|
| 532 | + $val = (int)$val; |
|
| 533 | + $force = (bool)$force; |
|
| 534 | 534 | |
| 535 | - [$hauteur, $largeur] = taille_image($img); |
|
| 535 | + [$hauteur, $largeur] = taille_image($img); |
|
| 536 | 536 | |
| 537 | - $l = round($largeur / $val); |
|
| 538 | - $h = round($hauteur / $val); |
|
| 537 | + $l = round($largeur / $val); |
|
| 538 | + $h = round($hauteur / $val); |
|
| 539 | 539 | |
| 540 | - if ($l > $h) { |
|
| 541 | - $h = 0; |
|
| 542 | - } else { |
|
| 543 | - $l = 0; |
|
| 544 | - } |
|
| 540 | + if ($l > $h) { |
|
| 541 | + $h = 0; |
|
| 542 | + } else { |
|
| 543 | + $l = 0; |
|
| 544 | + } |
|
| 545 | 545 | |
| 546 | - return image_reduire($img, $l, $h, $force); |
|
| 546 | + return image_reduire($img, $l, $h, $force); |
|
| 547 | 547 | } |
| 548 | 548 | |
| 549 | 549 | /** |
@@ -566,10 +566,10 @@ discard block |
||
| 566 | 566 | * Couleur en écriture hexadécimale. |
| 567 | 567 | **/ |
| 568 | 568 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 569 | - if (function_exists('couleur_saturation')) { |
|
| 570 | - return couleur_saturation($couleur, $val, $strict); |
|
| 571 | - } |
|
| 572 | - return $couleur; |
|
| 569 | + if (function_exists('couleur_saturation')) { |
|
| 570 | + return couleur_saturation($couleur, $val, $strict); |
|
| 571 | + } |
|
| 572 | + return $couleur; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -590,8 +590,8 @@ discard block |
||
| 590 | 590 | * Couleur en écriture hexadécimale. |
| 591 | 591 | **/ |
| 592 | 592 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 593 | - if (function_exists('couleur_luminance')) { |
|
| 594 | - return couleur_luminance($couleur, $val); |
|
| 595 | - } |
|
| 596 | - return $couleur; |
|
| 593 | + if (function_exists('couleur_luminance')) { |
|
| 594 | + return couleur_luminance($couleur, $val); |
|
| 595 | + } |
|
| 596 | + return $couleur; |
|
| 597 | 597 | } |
@@ -17,18 +17,18 @@ 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('_ACTIVER_PUCE_RAPIDE')) { |
| 24 | - /** |
|
| 25 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | - * |
|
| 27 | - * Peut ralentir un site sur des listes très longues. |
|
| 28 | - * |
|
| 29 | - * @var bool |
|
| 30 | - **/ |
|
| 31 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 24 | + /** |
|
| 25 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 26 | + * |
|
| 27 | + * Peut ralentir un site sur des listes très longues. |
|
| 28 | + * |
|
| 29 | + * @var bool |
|
| 30 | + **/ |
|
| 31 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -56,31 +56,31 @@ discard block |
||
| 56 | 56 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 57 | 57 | */ |
| 58 | 58 | function inc_puce_statut_dist( |
| 59 | - $id_objet, |
|
| 60 | - $statut, |
|
| 61 | - $id_parent, |
|
| 62 | - $type, |
|
| 63 | - $ajax = false, |
|
| 64 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 59 | + $id_objet, |
|
| 60 | + $statut, |
|
| 61 | + $id_parent, |
|
| 62 | + $type, |
|
| 63 | + $ajax = false, |
|
| 64 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 65 | 65 | ) { |
| 66 | - static $f_puce_statut = []; |
|
| 67 | - $type = objet_type($type); |
|
| 68 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | - if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | - } |
|
| 72 | - if ($f_puce_statut[$type]) { |
|
| 73 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | - // composer une puce, avec si possible changement rapide |
|
| 78 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | - return $puce; |
|
| 80 | - } // sinon fausse puce avec le type de l'image |
|
| 81 | - else { |
|
| 82 | - return http_img_pack("$type-16.png", ''); |
|
| 83 | - } |
|
| 66 | + static $f_puce_statut = []; |
|
| 67 | + $type = objet_type($type); |
|
| 68 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 69 | + if (!isset($f_puce_statut[$type]) || is_null($f_puce_statut[$type])) { |
|
| 70 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 71 | + } |
|
| 72 | + if ($f_puce_statut[$type]) { |
|
| 73 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 77 | + // composer une puce, avec si possible changement rapide |
|
| 78 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 79 | + return $puce; |
|
| 80 | + } // sinon fausse puce avec le type de l'image |
|
| 81 | + else { |
|
| 82 | + return http_img_pack("$type-16.png", ''); |
|
| 83 | + } |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -109,41 +109,41 @@ discard block |
||
| 109 | 109 | * null si pas capable de déterminer l'image |
| 110 | 110 | */ |
| 111 | 111 | function statut_image($objet, $statut) { |
| 112 | - $src = null; |
|
| 113 | - $table = table_objet_sql($objet); |
|
| 114 | - $desc = lister_tables_objets_sql($table); |
|
| 115 | - if (isset($desc['statut_images'])) { |
|
| 116 | - // si une declaration statut_images |
|
| 117 | - // mais rien pour le statut demande, ne rien afficher |
|
| 118 | - $src = ''; |
|
| 119 | - if (isset($desc['statut_images'][$statut])) { |
|
| 120 | - $src = $desc['statut_images'][$statut]; |
|
| 121 | - } // sinon image par defaut ? |
|
| 122 | - elseif (isset($desc['statut_images'][0])) { |
|
| 123 | - $src = $desc['statut_images'][0]; |
|
| 124 | - } |
|
| 125 | - } else { |
|
| 126 | - switch ($statut) { |
|
| 127 | - case 'prepa': |
|
| 128 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | - break; |
|
| 130 | - case 'prop': |
|
| 131 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | - break; |
|
| 133 | - case 'publie': |
|
| 134 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | - break; |
|
| 136 | - case 'refuse': |
|
| 137 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | - break; |
|
| 139 | - case 'poubelle': |
|
| 140 | - case 'poub': |
|
| 141 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - return $src; |
|
| 112 | + $src = null; |
|
| 113 | + $table = table_objet_sql($objet); |
|
| 114 | + $desc = lister_tables_objets_sql($table); |
|
| 115 | + if (isset($desc['statut_images'])) { |
|
| 116 | + // si une declaration statut_images |
|
| 117 | + // mais rien pour le statut demande, ne rien afficher |
|
| 118 | + $src = ''; |
|
| 119 | + if (isset($desc['statut_images'][$statut])) { |
|
| 120 | + $src = $desc['statut_images'][$statut]; |
|
| 121 | + } // sinon image par defaut ? |
|
| 122 | + elseif (isset($desc['statut_images'][0])) { |
|
| 123 | + $src = $desc['statut_images'][0]; |
|
| 124 | + } |
|
| 125 | + } else { |
|
| 126 | + switch ($statut) { |
|
| 127 | + case 'prepa': |
|
| 128 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 129 | + break; |
|
| 130 | + case 'prop': |
|
| 131 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 132 | + break; |
|
| 133 | + case 'publie': |
|
| 134 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 135 | + break; |
|
| 136 | + case 'refuse': |
|
| 137 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 138 | + break; |
|
| 139 | + case 'poubelle': |
|
| 140 | + case 'poub': |
|
| 141 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + return $src; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -171,40 +171,40 @@ discard block |
||
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | 173 | function statut_titre($objet, $statut) { |
| 174 | - $titre = ''; |
|
| 175 | - $table = table_objet_sql($objet); |
|
| 176 | - $desc = lister_tables_objets_sql($table); |
|
| 177 | - if (isset($desc['statut_titres'])) { |
|
| 178 | - // si une declaration statut_titres |
|
| 179 | - // mais rien pour le statut demande, ne rien afficher |
|
| 180 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | - $titre = $desc['statut_titres'][$statut]; |
|
| 182 | - } // sinon image par defaut ? |
|
| 183 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | - $titre = $desc['statut_titres'][0]; |
|
| 185 | - } |
|
| 186 | - } else { |
|
| 187 | - switch ($statut) { |
|
| 188 | - case 'prepa': |
|
| 189 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | - break; |
|
| 191 | - case 'prop': |
|
| 192 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | - break; |
|
| 194 | - case 'publie': |
|
| 195 | - $titre = 'texte_statut_publie'; |
|
| 196 | - break; |
|
| 197 | - case 'refuse': |
|
| 198 | - $titre = 'texte_statut_refuse'; |
|
| 199 | - break; |
|
| 200 | - case 'poubelle': |
|
| 201 | - case 'poub': |
|
| 202 | - $titre = 'texte_statut_poubelle'; |
|
| 203 | - break; |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - return $titre ? _T($titre) : ''; |
|
| 174 | + $titre = ''; |
|
| 175 | + $table = table_objet_sql($objet); |
|
| 176 | + $desc = lister_tables_objets_sql($table); |
|
| 177 | + if (isset($desc['statut_titres'])) { |
|
| 178 | + // si une declaration statut_titres |
|
| 179 | + // mais rien pour le statut demande, ne rien afficher |
|
| 180 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 181 | + $titre = $desc['statut_titres'][$statut]; |
|
| 182 | + } // sinon image par defaut ? |
|
| 183 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 184 | + $titre = $desc['statut_titres'][0]; |
|
| 185 | + } |
|
| 186 | + } else { |
|
| 187 | + switch ($statut) { |
|
| 188 | + case 'prepa': |
|
| 189 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 190 | + break; |
|
| 191 | + case 'prop': |
|
| 192 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 193 | + break; |
|
| 194 | + case 'publie': |
|
| 195 | + $titre = 'texte_statut_publie'; |
|
| 196 | + break; |
|
| 197 | + case 'refuse': |
|
| 198 | + $titre = 'texte_statut_refuse'; |
|
| 199 | + break; |
|
| 200 | + case 'poubelle': |
|
| 201 | + case 'poub': |
|
| 202 | + $titre = 'texte_statut_poubelle'; |
|
| 203 | + break; |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + return $titre ? _T($titre) : ''; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -224,37 +224,37 @@ discard block |
||
| 224 | 224 | * @return string |
| 225 | 225 | */ |
| 226 | 226 | function statut_texte_instituer($objet, $statut) { |
| 227 | - $texte = ''; |
|
| 228 | - $table = table_objet_sql($objet); |
|
| 229 | - $desc = lister_tables_objets_sql($table); |
|
| 230 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | - // si une declaration statut_titres |
|
| 232 | - // mais rien pour le statut demande, ne rien afficher |
|
| 233 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | - } |
|
| 236 | - } else { |
|
| 237 | - switch ($statut) { |
|
| 238 | - case 'prepa': |
|
| 239 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | - break; |
|
| 241 | - case 'prop': |
|
| 242 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | - break; |
|
| 244 | - case 'publie': |
|
| 245 | - $texte = 'texte_statut_publie'; |
|
| 246 | - break; |
|
| 247 | - case 'refuse': |
|
| 248 | - $texte = 'texte_statut_refuse'; |
|
| 249 | - break; |
|
| 250 | - case 'poubelle': |
|
| 251 | - case 'poub': |
|
| 252 | - $texte = 'texte_statut_poubelle'; |
|
| 253 | - break; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - return $texte ? _T($texte) : ''; |
|
| 227 | + $texte = ''; |
|
| 228 | + $table = table_objet_sql($objet); |
|
| 229 | + $desc = lister_tables_objets_sql($table); |
|
| 230 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 231 | + // si une declaration statut_titres |
|
| 232 | + // mais rien pour le statut demande, ne rien afficher |
|
| 233 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 234 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 235 | + } |
|
| 236 | + } else { |
|
| 237 | + switch ($statut) { |
|
| 238 | + case 'prepa': |
|
| 239 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 240 | + break; |
|
| 241 | + case 'prop': |
|
| 242 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 243 | + break; |
|
| 244 | + case 'publie': |
|
| 245 | + $texte = 'texte_statut_publie'; |
|
| 246 | + break; |
|
| 247 | + case 'refuse': |
|
| 248 | + $texte = 'texte_statut_refuse'; |
|
| 249 | + break; |
|
| 250 | + case 'poubelle': |
|
| 251 | + case 'poub': |
|
| 252 | + $texte = 'texte_statut_poubelle'; |
|
| 253 | + break; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + return $texte ? _T($texte) : ''; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -274,16 +274,16 @@ discard block |
||
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | 276 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 277 | - $img = statut_image('auteur', $statut); |
|
| 278 | - if (!$img) { |
|
| 279 | - return ''; |
|
| 280 | - } |
|
| 281 | - $alt = statut_titre('auteur', $statut); |
|
| 277 | + $img = statut_image('auteur', $statut); |
|
| 278 | + if (!$img) { |
|
| 279 | + return ''; |
|
| 280 | + } |
|
| 281 | + $alt = statut_titre('auteur', $statut); |
|
| 282 | 282 | |
| 283 | - $fond = ''; |
|
| 284 | - $titre = ''; |
|
| 283 | + $fond = ''; |
|
| 284 | + $titre = ''; |
|
| 285 | 285 | |
| 286 | - /* |
|
| 286 | + /* |
|
| 287 | 287 | if ($type != 'auteur') { |
| 288 | 288 | $img2 = chemin_image('del-16.png'); |
| 289 | 289 | $titre = _T('titre_image_redacteur'); |
@@ -293,12 +293,12 @@ discard block |
||
| 293 | 293 | } |
| 294 | 294 | */ |
| 295 | 295 | |
| 296 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 296 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | |
| 300 | 300 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 301 | - return http_img_pack('rubrique-16.png', ''); |
|
| 301 | + return http_img_pack('rubrique-16.png', ''); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -322,101 +322,101 @@ discard block |
||
| 322 | 322 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 323 | 323 | **/ |
| 324 | 324 | function puce_statut_changement_rapide( |
| 325 | - $id, |
|
| 326 | - $statut, |
|
| 327 | - $id_rubrique, |
|
| 328 | - $type = 'article', |
|
| 329 | - $ajax = false, |
|
| 330 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 325 | + $id, |
|
| 326 | + $statut, |
|
| 327 | + $id_rubrique, |
|
| 328 | + $type = 'article', |
|
| 329 | + $ajax = false, |
|
| 330 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 331 | 331 | ) { |
| 332 | - $src = statut_image($type, $statut); |
|
| 333 | - if (!$src) { |
|
| 334 | - return $src; |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | - |
|
| 339 | - |
|
| 340 | - $t = statut_titre($type, $statut); |
|
| 341 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | - |
|
| 343 | - if (!$ajax_node) { |
|
| 344 | - return $inser_puce; |
|
| 345 | - } |
|
| 346 | - |
|
| 347 | - $table = table_objet_sql($type); |
|
| 348 | - $desc = lister_tables_objets_sql($table); |
|
| 349 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | - return $inser_puce; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!function_exists('autoriser')) { |
|
| 354 | - include_spip('inc/autoriser'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | - if ($id_rubrique) { |
|
| 359 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | - return $inser_puce; |
|
| 361 | - } |
|
| 362 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | - else { |
|
| 364 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | - return $inser_puce; |
|
| 366 | - } |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | - if (!isset($coord[$statut])) { |
|
| 371 | - return $inser_puce; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | - ; |
|
| 376 | - $margin = 0; /* marge a gauche + droite */ |
|
| 377 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | - ; |
|
| 379 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | - |
|
| 381 | - if ($ajax) { |
|
| 382 | - $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | - . $inser_puce |
|
| 385 | - . '</span>' |
|
| 386 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | - $i = 0; |
|
| 388 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - return $out . '</span>'; |
|
| 393 | - } else { |
|
| 394 | - $nom = 'puce_statut_'; |
|
| 395 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | - $lang_dir = lang_dir(lang_typo()); |
|
| 397 | - |
|
| 398 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | - . $inser_puce |
|
| 400 | - . '</span>'; |
|
| 401 | - } |
|
| 332 | + $src = statut_image($type, $statut); |
|
| 333 | + if (!$src) { |
|
| 334 | + return $src; |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + $ajax_node = (!$id || !_SPIP_AJAX || !$menu_rapide) ? '' : " class='imgstatut$type$id'"; |
|
| 338 | + |
|
| 339 | + |
|
| 340 | + $t = statut_titre($type, $statut); |
|
| 341 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 342 | + |
|
| 343 | + if (!$ajax_node) { |
|
| 344 | + return $inser_puce; |
|
| 345 | + } |
|
| 346 | + |
|
| 347 | + $table = table_objet_sql($type); |
|
| 348 | + $desc = lister_tables_objets_sql($table); |
|
| 349 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 350 | + return $inser_puce; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!function_exists('autoriser')) { |
|
| 354 | + include_spip('inc/autoriser'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 358 | + if ($id_rubrique) { |
|
| 359 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 360 | + return $inser_puce; |
|
| 361 | + } |
|
| 362 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 363 | + else { |
|
| 364 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 365 | + return $inser_puce; |
|
| 366 | + } |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 370 | + if (!isset($coord[$statut])) { |
|
| 371 | + return $inser_puce; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 375 | + ; |
|
| 376 | + $margin = 0; /* marge a gauche + droite */ |
|
| 377 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 378 | + ; |
|
| 379 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 380 | + |
|
| 381 | + if ($ajax) { |
|
| 382 | + $width = $unit * (is_countable($desc['statut_textes_instituer']) ? count($desc['statut_textes_instituer']) : 0) + $margin; |
|
| 383 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 384 | + . $inser_puce |
|
| 385 | + . '</span>' |
|
| 386 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 387 | + $i = 0; |
|
| 388 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 389 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + return $out . '</span>'; |
|
| 393 | + } else { |
|
| 394 | + $nom = 'puce_statut_'; |
|
| 395 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 396 | + $lang_dir = lang_dir(lang_typo()); |
|
| 397 | + |
|
| 398 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 399 | + . $inser_puce |
|
| 400 | + . '</span>'; |
|
| 401 | + } |
|
| 402 | 402 | } |
| 403 | 403 | |
| 404 | 404 | |
| 405 | 405 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 406 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | - $t = supprimer_tags($titre); |
|
| 406 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 407 | + $t = supprimer_tags($titre); |
|
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |
| 413 | 413 | // La couleur du statut |
| 414 | 414 | |
| 415 | 415 | function puce_statut($statut, $atts = '') { |
| 416 | - $src = statut_image('article', $statut); |
|
| 417 | - if (!$src) { |
|
| 418 | - return ''; |
|
| 419 | - } |
|
| 416 | + $src = statut_image('article', $statut); |
|
| 417 | + if (!$src) { |
|
| 418 | + return ''; |
|
| 419 | + } |
|
| 420 | 420 | |
| 421 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 421 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 422 | 422 | } |
@@ -389,7 +389,7 @@ discard block |
||
| 389 | 389 | $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
| 390 | 390 | } |
| 391 | 391 | |
| 392 | - return $out . '</span>'; |
|
| 392 | + return $out.'</span>'; |
|
| 393 | 393 | } else { |
| 394 | 394 | $nom = 'puce_statut_'; |
| 395 | 395 | $action = generer_url_ecrire('puce_statut', '', true); |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
| 407 | 407 | $t = supprimer_tags($titre); |
| 408 | 408 | |
| 409 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 409 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t).'</a>'; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | // compat |
@@ -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 | include_spip('inc/filtres'); // par precaution |
| 23 | 23 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -37,21 +37,21 @@ discard block |
||
| 37 | 37 | * Le code de la couleur en hexadécimal. |
| 38 | 38 | */ |
| 39 | 39 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 40 | - $red = dechex($red); |
|
| 41 | - $green = dechex($green); |
|
| 42 | - $blue = dechex($blue); |
|
| 43 | - |
|
| 44 | - if (strlen($red) == 1) { |
|
| 45 | - $red = '0' . $red; |
|
| 46 | - } |
|
| 47 | - if (strlen($green) == 1) { |
|
| 48 | - $green = '0' . $green; |
|
| 49 | - } |
|
| 50 | - if (strlen($blue) == 1) { |
|
| 51 | - $blue = '0' . $blue; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return "$red$green$blue"; |
|
| 40 | + $red = dechex($red); |
|
| 41 | + $green = dechex($green); |
|
| 42 | + $blue = dechex($blue); |
|
| 43 | + |
|
| 44 | + if (strlen($red) == 1) { |
|
| 45 | + $red = '0' . $red; |
|
| 46 | + } |
|
| 47 | + if (strlen($green) == 1) { |
|
| 48 | + $green = '0' . $green; |
|
| 49 | + } |
|
| 50 | + if (strlen($blue) == 1) { |
|
| 51 | + $blue = '0' . $blue; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return "$red$green$blue"; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -63,18 +63,18 @@ discard block |
||
| 63 | 63 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 64 | 64 | */ |
| 65 | 65 | function _couleur_hex_to_dec($couleur) { |
| 66 | - $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; |
|
| 66 | + $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; |
|
| 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,55 +120,55 @@ 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 | - $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min); |
|
| 141 | - |
|
| 142 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 143 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 144 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 145 | - |
|
| 146 | - if ($var_R === $var_Max) { |
|
| 147 | - $H = $del_B - $del_G; |
|
| 148 | - } else { |
|
| 149 | - if ($var_G === $var_Max) { |
|
| 150 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 151 | - } else { |
|
| 152 | - if ($var_B === $var_Max) { |
|
| 153 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - if ($H < 0) { |
|
| 159 | - $H += 1; |
|
| 160 | - } |
|
| 161 | - if ($H > 1) { |
|
| 162 | - $H -= 1; |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - $ret = []; |
|
| 167 | - $ret['h'] = $H; |
|
| 168 | - $ret['s'] = $S; |
|
| 169 | - $ret['l'] = $L; |
|
| 170 | - |
|
| 171 | - 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 | + $S = $L < 0.5 ? $del_Max / ($var_Max + $var_Min) : $del_Max / (2 - $var_Max - $var_Min); |
|
| 141 | + |
|
| 142 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 143 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 144 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 145 | + |
|
| 146 | + if ($var_R === $var_Max) { |
|
| 147 | + $H = $del_B - $del_G; |
|
| 148 | + } else { |
|
| 149 | + if ($var_G === $var_Max) { |
|
| 150 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 151 | + } else { |
|
| 152 | + if ($var_B === $var_Max) { |
|
| 153 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + if ($H < 0) { |
|
| 159 | + $H += 1; |
|
| 160 | + } |
|
| 161 | + if ($H > 1) { |
|
| 162 | + $H -= 1; |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + $ret = []; |
|
| 167 | + $ret['h'] = $H; |
|
| 168 | + $ret['s'] = $S; |
|
| 169 | + $ret['l'] = $L; |
|
| 170 | + |
|
| 171 | + return $ret; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | |
@@ -184,48 +184,48 @@ discard block |
||
| 184 | 184 | * @return array |
| 185 | 185 | */ |
| 186 | 186 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 187 | - // helper |
|
| 188 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 189 | - if ($vH < 0) { |
|
| 190 | - $vH += 1; |
|
| 191 | - } |
|
| 192 | - if ($vH > 1) { |
|
| 193 | - $vH -= 1; |
|
| 194 | - } |
|
| 195 | - if ((6 * $vH) < 1) { |
|
| 196 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 197 | - } |
|
| 198 | - if ((2 * $vH) < 1) { |
|
| 199 | - return ($v2); |
|
| 200 | - } |
|
| 201 | - if ((3 * $vH) < 2) { |
|
| 202 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - return ($v1); |
|
| 206 | - }; |
|
| 207 | - |
|
| 208 | - if ($S == 0) { |
|
| 209 | - // HSV values = 0 -> 1 |
|
| 210 | - $R = $L * 255; |
|
| 211 | - $G = $L * 255; |
|
| 212 | - $B = $L * 255; |
|
| 213 | - } else { |
|
| 214 | - $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L); |
|
| 215 | - |
|
| 216 | - $var_1 = 2 * $L - $var_2; |
|
| 217 | - |
|
| 218 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 219 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 220 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $ret = []; |
|
| 224 | - $ret['r'] = floor($R); |
|
| 225 | - $ret['g'] = floor($G); |
|
| 226 | - $ret['b'] = floor($B); |
|
| 227 | - |
|
| 228 | - return $ret; |
|
| 187 | + // helper |
|
| 188 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 189 | + if ($vH < 0) { |
|
| 190 | + $vH += 1; |
|
| 191 | + } |
|
| 192 | + if ($vH > 1) { |
|
| 193 | + $vH -= 1; |
|
| 194 | + } |
|
| 195 | + if ((6 * $vH) < 1) { |
|
| 196 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 197 | + } |
|
| 198 | + if ((2 * $vH) < 1) { |
|
| 199 | + return ($v2); |
|
| 200 | + } |
|
| 201 | + if ((3 * $vH) < 2) { |
|
| 202 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + return ($v1); |
|
| 206 | + }; |
|
| 207 | + |
|
| 208 | + if ($S == 0) { |
|
| 209 | + // HSV values = 0 -> 1 |
|
| 210 | + $R = $L * 255; |
|
| 211 | + $G = $L * 255; |
|
| 212 | + $B = $L * 255; |
|
| 213 | + } else { |
|
| 214 | + $var_2 = $L < 0.5 ? $L * (1 + $S) : ($L + $S) - ($S * $L); |
|
| 215 | + |
|
| 216 | + $var_1 = 2 * $L - $var_2; |
|
| 217 | + |
|
| 218 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 219 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 220 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $ret = []; |
|
| 224 | + $ret['r'] = floor($R); |
|
| 225 | + $ret['g'] = floor($G); |
|
| 226 | + $ret['b'] = floor($B); |
|
| 227 | + |
|
| 228 | + return $ret; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -243,11 +243,11 @@ discard block |
||
| 243 | 243 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 244 | 244 | */ |
| 245 | 245 | function statut_effacer_images_temporaires($stat) { |
| 246 | - static $statut = false; // par defaut on grave toute les images |
|
| 247 | - if ($stat === 'get') { |
|
| 248 | - return $statut; |
|
| 249 | - } |
|
| 250 | - $statut = (bool) $stat; |
|
| 246 | + static $statut = false; // par defaut on grave toute les images |
|
| 247 | + if ($stat === 'get') { |
|
| 248 | + return $statut; |
|
| 249 | + } |
|
| 250 | + $statut = (bool) $stat; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -300,251 +300,251 @@ discard block |
||
| 300 | 300 | * - array : tableau décrivant de l'image |
| 301 | 301 | */ |
| 302 | 302 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 303 | - $valeurs = []; |
|
| 304 | - $ret = []; |
|
| 305 | - $f = null; |
|
| 306 | - static $images_recalcul = []; |
|
| 307 | - if (strlen($img) == 0) { |
|
| 308 | - return false; |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 312 | - if (strlen($source) < 1) { |
|
| 313 | - if (!str_starts_with($img, '<img ')) { |
|
| 314 | - $source = $img; |
|
| 315 | - $img = "<img src='$source' />"; |
|
| 316 | - } else { |
|
| 317 | - // pas d'attribut src sur cette balise <img../> |
|
| 318 | - return false; |
|
| 319 | - } |
|
| 320 | - } elseif ( |
|
| 321 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 322 | - && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])) |
|
| 323 | - && in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 324 | - ) { |
|
| 325 | - # gerer img src="data:....base64" |
|
| 326 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 327 | - if (!file_exists($local)) { |
|
| 328 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 329 | - } |
|
| 330 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 331 | - $sanitizer($local); |
|
| 332 | - } |
|
| 333 | - $source = $local; |
|
| 334 | - $img = inserer_attribut($img, 'src', $source); |
|
| 335 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 336 | - $img = inserer_attribut($img, 'width', ''); |
|
| 337 | - $img = inserer_attribut($img, 'height', ''); |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // les protocoles web prennent au moins 3 lettres |
|
| 341 | - if (tester_url_absolue($source)) { |
|
| 342 | - include_spip('inc/distant'); |
|
| 343 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 344 | - if (!$fichier) { |
|
| 345 | - return ''; |
|
| 346 | - } |
|
| 347 | - if ( |
|
| 348 | - ($extension = _image_trouver_extension($fichier)) |
|
| 349 | - && ($sanitizer = charger_fonction($extension, 'sanitizer', true)) |
|
| 350 | - ) { |
|
| 351 | - $sanitizer($fichier); |
|
| 352 | - } |
|
| 353 | - } else { |
|
| 354 | - // enlever le timestamp eventuel |
|
| 355 | - if (str_contains($source, '?')) { |
|
| 356 | - $source = preg_replace(',[?]\d+$,', '', $source); |
|
| 357 | - } |
|
| 358 | - if ( |
|
| 359 | - str_contains($source, '?') |
|
| 360 | - && str_starts_with($source, _DIR_IMG) |
|
| 361 | - && file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 362 | - ) { |
|
| 363 | - $source = $f; |
|
| 364 | - } |
|
| 365 | - $fichier = $source; |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - $terminaison_dest = ''; |
|
| 369 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 370 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - if ( |
|
| 374 | - $forcer_format !== false |
|
| 375 | - && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 376 | - ) { |
|
| 377 | - $terminaison_dest = $forcer_format; |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - if (!$terminaison_dest) { |
|
| 381 | - return false; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 385 | - $fichier_dest = $nom_fichier; |
|
| 386 | - if ( |
|
| 387 | - $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f) |
|
| 388 | - || @file_exists($f = $fichier) |
|
| 389 | - ) { |
|
| 390 | - // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance |
|
| 391 | - // on lit directement les infos du fichier |
|
| 392 | - [$ret['hauteur'], $ret['largeur']] = taille_image($f); |
|
| 393 | - $date_src = @filemtime($f); |
|
| 394 | - } elseif ( |
|
| 395 | - @file_exists($f = "$fichier.src") |
|
| 396 | - && lire_fichier($f, $valeurs) |
|
| 397 | - && ($valeurs = unserialize($valeurs)) |
|
| 398 | - && isset($valeurs['hauteur_dest']) |
|
| 399 | - && isset($valeurs['largeur_dest']) |
|
| 400 | - ) { |
|
| 401 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 402 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 403 | - $date_src = $valeurs['date']; |
|
| 404 | - } // pas de fichier source par la |
|
| 405 | - else { |
|
| 406 | - return false; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - // pas de taille mesurable ? |
|
| 410 | - if ( |
|
| 411 | - !$ret['hauteur'] |
|
| 412 | - || !($ret['hauteur'] = (int) round($ret['hauteur'])) |
|
| 413 | - || !$ret['largeur'] |
|
| 414 | - || !($ret['largeur'] = (int) round($ret['largeur'])) |
|
| 415 | - ) { |
|
| 416 | - return false; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // les images calculees dependent du chemin du fichier source |
|
| 420 | - // 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 |
|
| 421 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 422 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 423 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 424 | - // alors que ca concerne peu de site au final |
|
| 425 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 426 | - $identifiant = $fichier; |
|
| 427 | - |
|
| 428 | - // cas general : |
|
| 429 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 430 | - // cas particulier de reduire : |
|
| 431 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 432 | - $cache = 'cache-gd2'; |
|
| 433 | - if (str_starts_with($effet, 'reduire')) { |
|
| 434 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 435 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 436 | - $ret['largeur_dest'] = $destWidth; |
|
| 437 | - $ret['hauteur_dest'] = $destHeight; |
|
| 438 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 439 | - $cache = 'cache-vignettes'; |
|
| 440 | - $fichier_dest = basename($fichier_dest); |
|
| 441 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 442 | - // on garde la terminaison initiale car image simplement copiee |
|
| 443 | - // et on postfixe son nom avec un md5 du path |
|
| 444 | - $terminaison_dest = $terminaison; |
|
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 446 | - } else { |
|
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 448 | - } |
|
| 449 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 450 | - $cache = sous_repertoire($cache, $effet); |
|
| 451 | - } else { |
|
| 452 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 453 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 454 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 455 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 459 | - |
|
| 460 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 461 | - |
|
| 462 | - $creer = true; |
|
| 463 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 464 | - if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) { |
|
| 465 | - $images_recalcul[$fichier_dest] = true; |
|
| 466 | - } else { |
|
| 467 | - if (@file_exists($f = $fichier_dest)) { |
|
| 468 | - if (filemtime($f) >= $date_src) { |
|
| 469 | - $creer = false; |
|
| 470 | - } |
|
| 471 | - } else { |
|
| 472 | - if ( |
|
| 473 | - @file_exists($f = "$fichier_dest.src") |
|
| 474 | - && lire_fichier($f, $valeurs) |
|
| 475 | - && ($valeurs = unserialize($valeurs)) |
|
| 476 | - && $valeurs['date'] >= $date_src |
|
| 477 | - ) { |
|
| 478 | - $creer = false; |
|
| 479 | - } |
|
| 480 | - } |
|
| 481 | - } |
|
| 482 | - if ($creer && !@file_exists($fichier)) { |
|
| 483 | - if (!@file_exists("$fichier.src")) { |
|
| 484 | - spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR); |
|
| 485 | - |
|
| 486 | - return false; |
|
| 487 | - } |
|
| 488 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 489 | - reconstruire_image_intermediaire($fichier); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if ($creer) { |
|
| 493 | - spip_log( |
|
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | - $ret['fichier'] = $fichier; |
|
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | - $ret['format_dest'] = $terminaison_dest; |
|
| 506 | - $ret['date_src'] = $date_src; |
|
| 507 | - $ret['creer'] = $creer; |
|
| 508 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | - $ret['tag'] = $img; |
|
| 512 | - if ($fonction_creation) { |
|
| 513 | - $ret['reconstruction'] = $fonction_creation; |
|
| 514 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | - 'args' => [ |
|
| 522 | - 'img' => $img, |
|
| 523 | - 'effet' => $effet, |
|
| 524 | - 'forcer_format' => $forcer_format, |
|
| 525 | - 'fonction_creation' => $fonction_creation, |
|
| 526 | - 'find_in_path' => $find_in_path, |
|
| 527 | - ], |
|
| 528 | - 'data' => $ret |
|
| 529 | - ]); |
|
| 530 | - |
|
| 531 | - // une globale pour le debug en cas de crash memoire |
|
| 532 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | - |
|
| 534 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | - if ($term_fonction === 'svg') { |
|
| 536 | - if ($creer && !$support_svg) { |
|
| 537 | - process_image_svg_identite($ret); |
|
| 538 | - $ret['creer'] = false; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - else { |
|
| 542 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $ret; |
|
| 303 | + $valeurs = []; |
|
| 304 | + $ret = []; |
|
| 305 | + $f = null; |
|
| 306 | + static $images_recalcul = []; |
|
| 307 | + if (strlen($img) == 0) { |
|
| 308 | + return false; |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 312 | + if (strlen($source) < 1) { |
|
| 313 | + if (!str_starts_with($img, '<img ')) { |
|
| 314 | + $source = $img; |
|
| 315 | + $img = "<img src='$source' />"; |
|
| 316 | + } else { |
|
| 317 | + // pas d'attribut src sur cette balise <img../> |
|
| 318 | + return false; |
|
| 319 | + } |
|
| 320 | + } elseif ( |
|
| 321 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 322 | + && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])) |
|
| 323 | + && in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 324 | + ) { |
|
| 325 | + # gerer img src="data:....base64" |
|
| 326 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 327 | + if (!file_exists($local)) { |
|
| 328 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 329 | + } |
|
| 330 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 331 | + $sanitizer($local); |
|
| 332 | + } |
|
| 333 | + $source = $local; |
|
| 334 | + $img = inserer_attribut($img, 'src', $source); |
|
| 335 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 336 | + $img = inserer_attribut($img, 'width', ''); |
|
| 337 | + $img = inserer_attribut($img, 'height', ''); |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // les protocoles web prennent au moins 3 lettres |
|
| 341 | + if (tester_url_absolue($source)) { |
|
| 342 | + include_spip('inc/distant'); |
|
| 343 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 344 | + if (!$fichier) { |
|
| 345 | + return ''; |
|
| 346 | + } |
|
| 347 | + if ( |
|
| 348 | + ($extension = _image_trouver_extension($fichier)) |
|
| 349 | + && ($sanitizer = charger_fonction($extension, 'sanitizer', true)) |
|
| 350 | + ) { |
|
| 351 | + $sanitizer($fichier); |
|
| 352 | + } |
|
| 353 | + } else { |
|
| 354 | + // enlever le timestamp eventuel |
|
| 355 | + if (str_contains($source, '?')) { |
|
| 356 | + $source = preg_replace(',[?]\d+$,', '', $source); |
|
| 357 | + } |
|
| 358 | + if ( |
|
| 359 | + str_contains($source, '?') |
|
| 360 | + && str_starts_with($source, _DIR_IMG) |
|
| 361 | + && file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 362 | + ) { |
|
| 363 | + $source = $f; |
|
| 364 | + } |
|
| 365 | + $fichier = $source; |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + $terminaison_dest = ''; |
|
| 369 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 370 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + if ( |
|
| 374 | + $forcer_format !== false |
|
| 375 | + && ($terminaison_dest !== 'svg' || $support_svg || !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 376 | + ) { |
|
| 377 | + $terminaison_dest = $forcer_format; |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + if (!$terminaison_dest) { |
|
| 381 | + return false; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 385 | + $fichier_dest = $nom_fichier; |
|
| 386 | + if ( |
|
| 387 | + $find_in_path && ($f = find_in_path($fichier)) && ($fichier = $f) |
|
| 388 | + || @file_exists($f = $fichier) |
|
| 389 | + ) { |
|
| 390 | + // on ne passe jamais la balise img qui est peut-être en x2 et à laquelle on ne peut pas faire confiance |
|
| 391 | + // on lit directement les infos du fichier |
|
| 392 | + [$ret['hauteur'], $ret['largeur']] = taille_image($f); |
|
| 393 | + $date_src = @filemtime($f); |
|
| 394 | + } elseif ( |
|
| 395 | + @file_exists($f = "$fichier.src") |
|
| 396 | + && lire_fichier($f, $valeurs) |
|
| 397 | + && ($valeurs = unserialize($valeurs)) |
|
| 398 | + && isset($valeurs['hauteur_dest']) |
|
| 399 | + && isset($valeurs['largeur_dest']) |
|
| 400 | + ) { |
|
| 401 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 402 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 403 | + $date_src = $valeurs['date']; |
|
| 404 | + } // pas de fichier source par la |
|
| 405 | + else { |
|
| 406 | + return false; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + // pas de taille mesurable ? |
|
| 410 | + if ( |
|
| 411 | + !$ret['hauteur'] |
|
| 412 | + || !($ret['hauteur'] = (int) round($ret['hauteur'])) |
|
| 413 | + || !$ret['largeur'] |
|
| 414 | + || !($ret['largeur'] = (int) round($ret['largeur'])) |
|
| 415 | + ) { |
|
| 416 | + return false; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // les images calculees dependent du chemin du fichier source |
|
| 420 | + // 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 |
|
| 421 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 422 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 423 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 424 | + // alors que ca concerne peu de site au final |
|
| 425 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 426 | + $identifiant = $fichier; |
|
| 427 | + |
|
| 428 | + // cas general : |
|
| 429 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 430 | + // cas particulier de reduire : |
|
| 431 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 432 | + $cache = 'cache-gd2'; |
|
| 433 | + if (str_starts_with($effet, 'reduire')) { |
|
| 434 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 435 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 436 | + $ret['largeur_dest'] = $destWidth; |
|
| 437 | + $ret['hauteur_dest'] = $destHeight; |
|
| 438 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 439 | + $cache = 'cache-vignettes'; |
|
| 440 | + $fichier_dest = basename($fichier_dest); |
|
| 441 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 442 | + // on garde la terminaison initiale car image simplement copiee |
|
| 443 | + // et on postfixe son nom avec un md5 du path |
|
| 444 | + $terminaison_dest = $terminaison; |
|
| 445 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 446 | + } else { |
|
| 447 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 448 | + } |
|
| 449 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 450 | + $cache = sous_repertoire($cache, $effet); |
|
| 451 | + } else { |
|
| 452 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 453 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 454 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 455 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 459 | + |
|
| 460 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 461 | + |
|
| 462 | + $creer = true; |
|
| 463 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 464 | + if (defined('_VAR_IMAGES') && _VAR_IMAGES && !isset($images_recalcul[$fichier_dest])) { |
|
| 465 | + $images_recalcul[$fichier_dest] = true; |
|
| 466 | + } else { |
|
| 467 | + if (@file_exists($f = $fichier_dest)) { |
|
| 468 | + if (filemtime($f) >= $date_src) { |
|
| 469 | + $creer = false; |
|
| 470 | + } |
|
| 471 | + } else { |
|
| 472 | + if ( |
|
| 473 | + @file_exists($f = "$fichier_dest.src") |
|
| 474 | + && lire_fichier($f, $valeurs) |
|
| 475 | + && ($valeurs = unserialize($valeurs)) |
|
| 476 | + && $valeurs['date'] >= $date_src |
|
| 477 | + ) { |
|
| 478 | + $creer = false; |
|
| 479 | + } |
|
| 480 | + } |
|
| 481 | + } |
|
| 482 | + if ($creer && !@file_exists($fichier)) { |
|
| 483 | + if (!@file_exists("$fichier.src")) { |
|
| 484 | + spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR); |
|
| 485 | + |
|
| 486 | + return false; |
|
| 487 | + } |
|
| 488 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 489 | + reconstruire_image_intermediaire($fichier); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if ($creer) { |
|
| 493 | + spip_log( |
|
| 494 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | + 'images' . _LOG_DEBUG |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | + $ret['fichier'] = $fichier; |
|
| 502 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | + $ret['format_dest'] = $terminaison_dest; |
|
| 506 | + $ret['date_src'] = $date_src; |
|
| 507 | + $ret['creer'] = $creer; |
|
| 508 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | + $ret['tag'] = $img; |
|
| 512 | + if ($fonction_creation) { |
|
| 513 | + $ret['reconstruction'] = $fonction_creation; |
|
| 514 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | + 'args' => [ |
|
| 522 | + 'img' => $img, |
|
| 523 | + 'effet' => $effet, |
|
| 524 | + 'forcer_format' => $forcer_format, |
|
| 525 | + 'fonction_creation' => $fonction_creation, |
|
| 526 | + 'find_in_path' => $find_in_path, |
|
| 527 | + ], |
|
| 528 | + 'data' => $ret |
|
| 529 | + ]); |
|
| 530 | + |
|
| 531 | + // une globale pour le debug en cas de crash memoire |
|
| 532 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | + |
|
| 534 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | + if ($term_fonction === 'svg') { |
|
| 536 | + if ($creer && !$support_svg) { |
|
| 537 | + process_image_svg_identite($ret); |
|
| 538 | + $ret['creer'] = false; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + else { |
|
| 542 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $ret; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -553,54 +553,54 @@ discard block |
||
| 553 | 553 | * @return array |
| 554 | 554 | */ |
| 555 | 555 | function _image_extensions_acceptees_en_entree() { |
| 556 | - static $extensions = null; |
|
| 557 | - if (empty($extensions)) { |
|
| 558 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 559 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 560 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 561 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 562 | - $extensions = array_map('trim', $extensions); |
|
| 563 | - $extensions = array_filter($extensions); |
|
| 564 | - if (in_array('jpg', $extensions)) { |
|
| 565 | - $extensions[] = 'jpeg'; |
|
| 566 | - } |
|
| 567 | - $extensions = array_unique($extensions); |
|
| 568 | - } |
|
| 569 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $extensions; |
|
| 556 | + static $extensions = null; |
|
| 557 | + if (empty($extensions)) { |
|
| 558 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 559 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 560 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 561 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 562 | + $extensions = array_map('trim', $extensions); |
|
| 563 | + $extensions = array_filter($extensions); |
|
| 564 | + if (in_array('jpg', $extensions)) { |
|
| 565 | + $extensions[] = 'jpeg'; |
|
| 566 | + } |
|
| 567 | + $extensions = array_unique($extensions); |
|
| 568 | + } |
|
| 569 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $extensions; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
| 576 | 576 | * @return array|string[]|null |
| 577 | 577 | */ |
| 578 | 578 | function _image_extensions_acceptees_en_sortie() { |
| 579 | - static $extensions = null; |
|
| 580 | - if (empty($extensions)) { |
|
| 581 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 582 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 583 | - if (in_array('gif', $extensions) && !function_exists('imagegif')) { |
|
| 584 | - $extensions = array_diff($extensions, ['gif']); |
|
| 585 | - } |
|
| 586 | - if (in_array('webp', $extensions) && !function_exists('imagewebp')) { |
|
| 587 | - $extensions = array_diff($extensions, ['webp']); |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $extensions; |
|
| 579 | + static $extensions = null; |
|
| 580 | + if (empty($extensions)) { |
|
| 581 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 582 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 583 | + if (in_array('gif', $extensions) && !function_exists('imagegif')) { |
|
| 584 | + $extensions = array_diff($extensions, ['gif']); |
|
| 585 | + } |
|
| 586 | + if (in_array('webp', $extensions) && !function_exists('imagewebp')) { |
|
| 587 | + $extensions = array_diff($extensions, ['webp']); |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $extensions; |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | function _image_extension_normalisee($extension) { |
| 595 | - $extension = strtolower($extension); |
|
| 596 | - if ($extension === 'jpeg') { |
|
| 597 | - $extension = 'jpg'; |
|
| 598 | - } |
|
| 599 | - return $extension; |
|
| 595 | + $extension = strtolower($extension); |
|
| 596 | + if ($extension === 'jpeg') { |
|
| 597 | + $extension = 'jpg'; |
|
| 598 | + } |
|
| 599 | + return $extension; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | function _image_extensions_conservent_transparence() { |
| 603 | - return ['png', 'webp']; |
|
| 603 | + return ['png', 'webp']; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -610,11 +610,11 @@ discard block |
||
| 610 | 610 | * @return string |
| 611 | 611 | */ |
| 612 | 612 | function _image_trouver_extension($path) { |
| 613 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 614 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 615 | - return strtolower($regs[1]); |
|
| 616 | - } |
|
| 617 | - return ''; |
|
| 613 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 614 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 615 | + return strtolower($regs[1]); |
|
| 616 | + } |
|
| 617 | + return ''; |
|
| 618 | 618 | } |
| 619 | 619 | |
| 620 | 620 | /** |
@@ -625,28 +625,28 @@ discard block |
||
| 625 | 625 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 626 | 626 | */ |
| 627 | 627 | function _image_trouver_extension_pertinente($path) { |
| 628 | - $path = supprimer_timestamp($path); |
|
| 629 | - $terminaison = _image_trouver_extension($path); |
|
| 630 | - if ($terminaison == 'jpg') { |
|
| 631 | - $terminaison = 'jpeg'; |
|
| 632 | - } |
|
| 633 | - |
|
| 634 | - if (!file_exists($path)) { |
|
| 635 | - return $terminaison; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - if (!$info = @spip_getimagesize($path)) { |
|
| 639 | - return $terminaison; |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - $mime = $info['mime'] ?? image_type_to_mime_type($info[2]); |
|
| 643 | - |
|
| 644 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 645 | - if ($_terminaison && $_terminaison !== $terminaison) { |
|
| 646 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 647 | - $terminaison = $_terminaison; |
|
| 648 | - } |
|
| 649 | - return $terminaison; |
|
| 628 | + $path = supprimer_timestamp($path); |
|
| 629 | + $terminaison = _image_trouver_extension($path); |
|
| 630 | + if ($terminaison == 'jpg') { |
|
| 631 | + $terminaison = 'jpeg'; |
|
| 632 | + } |
|
| 633 | + |
|
| 634 | + if (!file_exists($path)) { |
|
| 635 | + return $terminaison; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + if (!$info = @spip_getimagesize($path)) { |
|
| 639 | + return $terminaison; |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + $mime = $info['mime'] ?? image_type_to_mime_type($info[2]); |
|
| 643 | + |
|
| 644 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 645 | + if ($_terminaison && $_terminaison !== $terminaison) { |
|
| 646 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 647 | + $terminaison = $_terminaison; |
|
| 648 | + } |
|
| 649 | + return $terminaison; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -654,14 +654,14 @@ discard block |
||
| 654 | 654 | * @return string |
| 655 | 655 | */ |
| 656 | 656 | function _image_trouver_extension_depuis_mime($mime) { |
| 657 | - return match (strtolower($mime)) { |
|
| 658 | - 'image/png', 'image/x-png' => 'png', |
|
| 659 | - 'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg', |
|
| 660 | - 'image/gif' => 'gif', |
|
| 661 | - 'image/webp', 'image/x-webp' => 'webp', |
|
| 662 | - 'image/svg+xml' => 'svg', |
|
| 663 | - default => '', |
|
| 664 | - }; |
|
| 657 | + return match (strtolower($mime)) { |
|
| 658 | + 'image/png', 'image/x-png' => 'png', |
|
| 659 | + 'image/jpg', 'image/jpeg', 'image/pjpeg' => 'jpeg', |
|
| 660 | + 'image/gif' => 'gif', |
|
| 661 | + 'image/webp', 'image/x-webp' => 'webp', |
|
| 662 | + 'image/svg+xml' => 'svg', |
|
| 663 | + default => '', |
|
| 664 | + }; |
|
| 665 | 665 | } |
| 666 | 666 | |
| 667 | 667 | |
@@ -681,18 +681,18 @@ discard block |
||
| 681 | 681 | * Une ressource de type Image GD. |
| 682 | 682 | */ |
| 683 | 683 | function _imagecreatefrom_func(string $func, string $filename) { |
| 684 | - if (!function_exists($func)) { |
|
| 685 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 686 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 687 | - return null; |
|
| 688 | - } |
|
| 689 | - $img = @$func($filename); |
|
| 690 | - if (!$img) { |
|
| 691 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 692 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 693 | - $img = imagecreate(10, 10); |
|
| 694 | - } |
|
| 695 | - return $img; |
|
| 684 | + if (!function_exists($func)) { |
|
| 685 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 686 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 687 | + return null; |
|
| 688 | + } |
|
| 689 | + $img = @$func($filename); |
|
| 690 | + if (!$img) { |
|
| 691 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 692 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 693 | + $img = imagecreate(10, 10); |
|
| 694 | + } |
|
| 695 | + return $img; |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -708,7 +708,7 @@ discard block |
||
| 708 | 708 | * Une ressource de type Image GD. |
| 709 | 709 | */ |
| 710 | 710 | function _imagecreatefromjpeg($filename) { |
| 711 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 711 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 712 | 712 | } |
| 713 | 713 | |
| 714 | 714 | /** |
@@ -724,7 +724,7 @@ discard block |
||
| 724 | 724 | * Une ressource de type Image GD. |
| 725 | 725 | */ |
| 726 | 726 | function _imagecreatefrompng($filename) { |
| 727 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 727 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 728 | 728 | } |
| 729 | 729 | |
| 730 | 730 | /** |
@@ -740,7 +740,7 @@ discard block |
||
| 740 | 740 | * Une ressource de type Image GD. |
| 741 | 741 | */ |
| 742 | 742 | function _imagecreatefromgif($filename) { |
| 743 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 743 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * Une ressource de type Image GD. |
| 758 | 758 | */ |
| 759 | 759 | function _imagecreatefromwebp($filename) { |
| 760 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 760 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -775,24 +775,24 @@ discard block |
||
| 775 | 775 | * - true si une image est bien retournée. |
| 776 | 776 | */ |
| 777 | 777 | function _image_imagepng($img, $fichier) { |
| 778 | - if (!function_exists('imagepng')) { |
|
| 779 | - return false; |
|
| 780 | - } |
|
| 781 | - $tmp = $fichier . '.tmp'; |
|
| 782 | - $ret = imagepng($img, $tmp); |
|
| 783 | - if (file_exists($tmp)) { |
|
| 784 | - $taille_test = @getimagesize($tmp); |
|
| 785 | - if (empty($taille_test[0])) { |
|
| 786 | - return false; |
|
| 787 | - } |
|
| 788 | - |
|
| 789 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 790 | - @rename($tmp, $fichier); |
|
| 791 | - |
|
| 792 | - return $ret; |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - return false; |
|
| 778 | + if (!function_exists('imagepng')) { |
|
| 779 | + return false; |
|
| 780 | + } |
|
| 781 | + $tmp = $fichier . '.tmp'; |
|
| 782 | + $ret = imagepng($img, $tmp); |
|
| 783 | + if (file_exists($tmp)) { |
|
| 784 | + $taille_test = @getimagesize($tmp); |
|
| 785 | + if (empty($taille_test[0])) { |
|
| 786 | + return false; |
|
| 787 | + } |
|
| 788 | + |
|
| 789 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 790 | + @rename($tmp, $fichier); |
|
| 791 | + |
|
| 792 | + return $ret; |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + return false; |
|
| 796 | 796 | } |
| 797 | 797 | |
| 798 | 798 | /** |
@@ -810,24 +810,24 @@ discard block |
||
| 810 | 810 | * - true si une image est bien retournée. |
| 811 | 811 | */ |
| 812 | 812 | function _image_imagegif($img, $fichier) { |
| 813 | - if (!function_exists('imagegif')) { |
|
| 814 | - return false; |
|
| 815 | - } |
|
| 816 | - $tmp = $fichier . '.tmp'; |
|
| 817 | - $ret = imagegif($img, $tmp); |
|
| 818 | - if (file_exists($tmp)) { |
|
| 819 | - $taille_test = @getimagesize($tmp); |
|
| 820 | - if (empty($taille_test[0])) { |
|
| 821 | - return false; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 825 | - @rename($tmp, $fichier); |
|
| 826 | - |
|
| 827 | - return $ret; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - return false; |
|
| 813 | + if (!function_exists('imagegif')) { |
|
| 814 | + return false; |
|
| 815 | + } |
|
| 816 | + $tmp = $fichier . '.tmp'; |
|
| 817 | + $ret = imagegif($img, $tmp); |
|
| 818 | + if (file_exists($tmp)) { |
|
| 819 | + $taille_test = @getimagesize($tmp); |
|
| 820 | + if (empty($taille_test[0])) { |
|
| 821 | + return false; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 825 | + @rename($tmp, $fichier); |
|
| 826 | + |
|
| 827 | + return $ret; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + return false; |
|
| 831 | 831 | } |
| 832 | 832 | |
| 833 | 833 | /** |
@@ -850,29 +850,29 @@ discard block |
||
| 850 | 850 | * - true si une image est bien retournée. |
| 851 | 851 | */ |
| 852 | 852 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 853 | - if (!function_exists('imagejpeg')) { |
|
| 854 | - return false; |
|
| 855 | - } |
|
| 856 | - $tmp = $fichier . '.tmp'; |
|
| 853 | + if (!function_exists('imagejpeg')) { |
|
| 854 | + return false; |
|
| 855 | + } |
|
| 856 | + $tmp = $fichier . '.tmp'; |
|
| 857 | 857 | |
| 858 | - // Enable interlancing |
|
| 859 | - imageinterlace($img, true); |
|
| 858 | + // Enable interlancing |
|
| 859 | + imageinterlace($img, true); |
|
| 860 | 860 | |
| 861 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 861 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 862 | 862 | |
| 863 | - if (file_exists($tmp)) { |
|
| 864 | - $taille_test = @getimagesize($tmp); |
|
| 865 | - if (empty($taille_test[0])) { |
|
| 866 | - return false; |
|
| 867 | - } |
|
| 863 | + if (file_exists($tmp)) { |
|
| 864 | + $taille_test = @getimagesize($tmp); |
|
| 865 | + if (empty($taille_test[0])) { |
|
| 866 | + return false; |
|
| 867 | + } |
|
| 868 | 868 | |
| 869 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 870 | - @rename($tmp, $fichier); |
|
| 869 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 870 | + @rename($tmp, $fichier); |
|
| 871 | 871 | |
| 872 | - return $ret; |
|
| 873 | - } |
|
| 872 | + return $ret; |
|
| 873 | + } |
|
| 874 | 874 | |
| 875 | - return false; |
|
| 875 | + return false; |
|
| 876 | 876 | } |
| 877 | 877 | |
| 878 | 878 | /** |
@@ -890,9 +890,9 @@ discard block |
||
| 890 | 890 | * true si le fichier a bien été créé ; false sinon. |
| 891 | 891 | */ |
| 892 | 892 | function _image_imageico($img, $fichier) { |
| 893 | - $gd_image_array = [$img]; |
|
| 893 | + $gd_image_array = [$img]; |
|
| 894 | 894 | |
| 895 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 895 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | |
@@ -911,24 +911,24 @@ discard block |
||
| 911 | 911 | * - true si une image est bien retournée. |
| 912 | 912 | */ |
| 913 | 913 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 914 | - if (!function_exists('imagewebp')) { |
|
| 915 | - return false; |
|
| 916 | - } |
|
| 917 | - $tmp = $fichier . '.tmp'; |
|
| 918 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 919 | - if (file_exists($tmp)) { |
|
| 920 | - $taille_test = @getimagesize($tmp); |
|
| 921 | - if (empty($taille_test[0])) { |
|
| 922 | - return false; |
|
| 923 | - } |
|
| 924 | - |
|
| 925 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 926 | - @rename($tmp, $fichier); |
|
| 927 | - |
|
| 928 | - return $ret; |
|
| 929 | - } |
|
| 930 | - |
|
| 931 | - return false; |
|
| 914 | + if (!function_exists('imagewebp')) { |
|
| 915 | + return false; |
|
| 916 | + } |
|
| 917 | + $tmp = $fichier . '.tmp'; |
|
| 918 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 919 | + if (file_exists($tmp)) { |
|
| 920 | + $taille_test = @getimagesize($tmp); |
|
| 921 | + if (empty($taille_test[0])) { |
|
| 922 | + return false; |
|
| 923 | + } |
|
| 924 | + |
|
| 925 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 926 | + @rename($tmp, $fichier); |
|
| 927 | + |
|
| 928 | + return $ret; |
|
| 929 | + } |
|
| 930 | + |
|
| 931 | + return false; |
|
| 932 | 932 | } |
| 933 | 933 | |
| 934 | 934 | /** |
@@ -948,35 +948,35 @@ discard block |
||
| 948 | 948 | */ |
| 949 | 949 | function _image_imagesvg($img, $fichier) { |
| 950 | 950 | |
| 951 | - $tmp = $fichier . '.tmp'; |
|
| 952 | - if (!str_contains($img, '<')) { |
|
| 953 | - $img = supprimer_timestamp($img); |
|
| 954 | - if (!file_exists($img)) { |
|
| 955 | - return false; |
|
| 956 | - } |
|
| 957 | - @copy($img, $tmp); |
|
| 958 | - if (filesize($tmp) === filesize($img)) { |
|
| 959 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 960 | - @rename($tmp, $fichier); |
|
| 961 | - return true; |
|
| 962 | - } |
|
| 963 | - return false; |
|
| 964 | - } |
|
| 965 | - |
|
| 966 | - file_put_contents($tmp, $img); |
|
| 967 | - if (file_exists($tmp)) { |
|
| 968 | - $taille_test = spip_getimagesize($tmp); |
|
| 969 | - if (empty($taille_test[0])) { |
|
| 970 | - return false; |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 974 | - @rename($tmp, $fichier); |
|
| 975 | - |
|
| 976 | - return true; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - return false; |
|
| 951 | + $tmp = $fichier . '.tmp'; |
|
| 952 | + if (!str_contains($img, '<')) { |
|
| 953 | + $img = supprimer_timestamp($img); |
|
| 954 | + if (!file_exists($img)) { |
|
| 955 | + return false; |
|
| 956 | + } |
|
| 957 | + @copy($img, $tmp); |
|
| 958 | + if (filesize($tmp) === filesize($img)) { |
|
| 959 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 960 | + @rename($tmp, $fichier); |
|
| 961 | + return true; |
|
| 962 | + } |
|
| 963 | + return false; |
|
| 964 | + } |
|
| 965 | + |
|
| 966 | + file_put_contents($tmp, $img); |
|
| 967 | + if (file_exists($tmp)) { |
|
| 968 | + $taille_test = spip_getimagesize($tmp); |
|
| 969 | + if (empty($taille_test[0])) { |
|
| 970 | + return false; |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 974 | + @rename($tmp, $fichier); |
|
| 975 | + |
|
| 976 | + return true; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + return false; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | |
@@ -1004,30 +1004,30 @@ discard block |
||
| 1004 | 1004 | * - false sinon. |
| 1005 | 1005 | */ |
| 1006 | 1006 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1007 | - if (is_null($fonction)) { |
|
| 1008 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1009 | - } |
|
| 1010 | - $ret = false; |
|
| 1011 | - #un flag pour reperer les images gravees |
|
| 1012 | - $lock = ( |
|
| 1013 | - !statut_effacer_images_temporaires('get') |
|
| 1014 | - || @file_exists($valeurs['fichier_dest']) |
|
| 1015 | - && !@file_exists($valeurs['fichier_dest'] . '.src') |
|
| 1016 | - ); |
|
| 1017 | - if ( |
|
| 1018 | - function_exists($fonction) |
|
| 1019 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1020 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1021 | - && !$lock && @file_exists($valeurs['fichier_dest']) |
|
| 1022 | - ) { |
|
| 1023 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1024 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1025 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); |
|
| 1026 | - // pour la retrouver apres disparition |
|
| 1027 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1028 | - } |
|
| 1029 | - |
|
| 1030 | - return $ret; |
|
| 1007 | + if (is_null($fonction)) { |
|
| 1008 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1009 | + } |
|
| 1010 | + $ret = false; |
|
| 1011 | + #un flag pour reperer les images gravees |
|
| 1012 | + $lock = ( |
|
| 1013 | + !statut_effacer_images_temporaires('get') |
|
| 1014 | + || @file_exists($valeurs['fichier_dest']) |
|
| 1015 | + && !@file_exists($valeurs['fichier_dest'] . '.src') |
|
| 1016 | + ); |
|
| 1017 | + if ( |
|
| 1018 | + function_exists($fonction) |
|
| 1019 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1020 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1021 | + && !$lock && @file_exists($valeurs['fichier_dest']) |
|
| 1022 | + ) { |
|
| 1023 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1024 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1025 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); |
|
| 1026 | + // pour la retrouver apres disparition |
|
| 1027 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1028 | + } |
|
| 1029 | + |
|
| 1030 | + return $ret; |
|
| 1031 | 1031 | } |
| 1032 | 1032 | |
| 1033 | 1033 | /** |
@@ -1040,28 +1040,28 @@ discard block |
||
| 1040 | 1040 | * Chemin vers le fichier manquant |
| 1041 | 1041 | **/ |
| 1042 | 1042 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1043 | - $source = null; |
|
| 1044 | - $reconstruire = []; |
|
| 1045 | - $fichier = $fichier_manquant; |
|
| 1046 | - while ( |
|
| 1047 | - !str_contains($fichier, '://') |
|
| 1048 | - && !@file_exists($fichier) |
|
| 1049 | - && lire_fichier($src = "$fichier.src", $source) |
|
| 1050 | - && ($valeurs = unserialize($source)) |
|
| 1051 | - && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1052 | - ) { |
|
| 1053 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1054 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1055 | - } |
|
| 1056 | - while (count($reconstruire)) { |
|
| 1057 | - $r = array_pop($reconstruire); |
|
| 1058 | - $fonction = $r[0]; |
|
| 1059 | - $args = $r[1]; |
|
| 1060 | - $fonction(...$args); |
|
| 1061 | - } |
|
| 1062 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1063 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1064 | - ramasse_miettes($fichier_manquant); |
|
| 1043 | + $source = null; |
|
| 1044 | + $reconstruire = []; |
|
| 1045 | + $fichier = $fichier_manquant; |
|
| 1046 | + while ( |
|
| 1047 | + !str_contains($fichier, '://') |
|
| 1048 | + && !@file_exists($fichier) |
|
| 1049 | + && lire_fichier($src = "$fichier.src", $source) |
|
| 1050 | + && ($valeurs = unserialize($source)) |
|
| 1051 | + && ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1052 | + ) { |
|
| 1053 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1054 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1055 | + } |
|
| 1056 | + while (count($reconstruire)) { |
|
| 1057 | + $r = array_pop($reconstruire); |
|
| 1058 | + $fonction = $r[0]; |
|
| 1059 | + $args = $r[1]; |
|
| 1060 | + $fonction(...$args); |
|
| 1061 | + } |
|
| 1062 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1063 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1064 | + ramasse_miettes($fichier_manquant); |
|
| 1065 | 1065 | } |
| 1066 | 1066 | |
| 1067 | 1067 | /** |
@@ -1081,26 +1081,26 @@ discard block |
||
| 1081 | 1081 | * Chemin du fichier d'image calculé |
| 1082 | 1082 | **/ |
| 1083 | 1083 | function ramasse_miettes($fichier) { |
| 1084 | - $source = null; |
|
| 1085 | - if ( |
|
| 1086 | - str_contains($fichier, '://') |
|
| 1087 | - || !lire_fichier($src = "$fichier.src", $source) |
|
| 1088 | - || !$valeurs = unserialize($source) |
|
| 1089 | - ) { |
|
| 1090 | - return; |
|
| 1091 | - } |
|
| 1092 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1093 | - while ( |
|
| 1094 | - ($fichier = $valeurs['fichier']) |
|
| 1095 | - && str_starts_with($fichier, _DIR_VAR) |
|
| 1096 | - && lire_fichier($src = "$fichier.src", $source) |
|
| 1097 | - && ($valeurs = unserialize($source)) # et valide |
|
| 1098 | - ) { |
|
| 1099 | - # on efface le fichier |
|
| 1100 | - spip_unlink($fichier); |
|
| 1101 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1102 | - #spip_unlink($src); |
|
| 1103 | - } |
|
| 1084 | + $source = null; |
|
| 1085 | + if ( |
|
| 1086 | + str_contains($fichier, '://') |
|
| 1087 | + || !lire_fichier($src = "$fichier.src", $source) |
|
| 1088 | + || !$valeurs = unserialize($source) |
|
| 1089 | + ) { |
|
| 1090 | + return; |
|
| 1091 | + } |
|
| 1092 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1093 | + while ( |
|
| 1094 | + ($fichier = $valeurs['fichier']) |
|
| 1095 | + && str_starts_with($fichier, _DIR_VAR) |
|
| 1096 | + && lire_fichier($src = "$fichier.src", $source) |
|
| 1097 | + && ($valeurs = unserialize($source)) # et valide |
|
| 1098 | + ) { |
|
| 1099 | + # on efface le fichier |
|
| 1100 | + spip_unlink($fichier); |
|
| 1101 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1102 | + #spip_unlink($src); |
|
| 1103 | + } |
|
| 1104 | 1104 | } |
| 1105 | 1105 | |
| 1106 | 1106 | |
@@ -1125,33 +1125,33 @@ discard block |
||
| 1125 | 1125 | * Code HTML de l'image |
| 1126 | 1126 | **/ |
| 1127 | 1127 | function image_graver($img) { |
| 1128 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1129 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1130 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1131 | - |
|
| 1132 | - $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? ''); |
|
| 1133 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1134 | - $fichier = substr($fichier, 0, $p); |
|
| 1135 | - } |
|
| 1136 | - if (strlen($fichier) < 1 && !str_starts_with($img, '<img ')) { |
|
| 1137 | - $fichier = $img; |
|
| 1138 | - } |
|
| 1139 | - if (strlen($fichier)) { |
|
| 1140 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1141 | - # et qu'il ne s'agit pas d'une URL |
|
| 1142 | - if (!str_contains($fichier, '://') && !@file_exists($fichier)) { |
|
| 1143 | - reconstruire_image_intermediaire($fichier); |
|
| 1144 | - } |
|
| 1145 | - ramasse_miettes($fichier); |
|
| 1146 | - |
|
| 1147 | - // ajouter le timestamp si besoin |
|
| 1148 | - if (!str_contains($fichier_ori, '?')) { |
|
| 1149 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1150 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1151 | - } |
|
| 1152 | - } |
|
| 1153 | - |
|
| 1154 | - return $img; |
|
| 1128 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1129 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1130 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1131 | + |
|
| 1132 | + $fichier_ori = $fichier = (extraire_attribut($img, 'src') ?? ''); |
|
| 1133 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1134 | + $fichier = substr($fichier, 0, $p); |
|
| 1135 | + } |
|
| 1136 | + if (strlen($fichier) < 1 && !str_starts_with($img, '<img ')) { |
|
| 1137 | + $fichier = $img; |
|
| 1138 | + } |
|
| 1139 | + if (strlen($fichier)) { |
|
| 1140 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1141 | + # et qu'il ne s'agit pas d'une URL |
|
| 1142 | + if (!str_contains($fichier, '://') && !@file_exists($fichier)) { |
|
| 1143 | + reconstruire_image_intermediaire($fichier); |
|
| 1144 | + } |
|
| 1145 | + ramasse_miettes($fichier); |
|
| 1146 | + |
|
| 1147 | + // ajouter le timestamp si besoin |
|
| 1148 | + if (!str_contains($fichier_ori, '?')) { |
|
| 1149 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1150 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1151 | + } |
|
| 1152 | + } |
|
| 1153 | + |
|
| 1154 | + return $img; |
|
| 1155 | 1155 | } |
| 1156 | 1156 | |
| 1157 | 1157 | /** |
@@ -1178,32 +1178,32 @@ discard block |
||
| 1178 | 1178 | * Code html modifié de la balise. |
| 1179 | 1179 | **/ |
| 1180 | 1180 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1181 | - if ($style === false) { |
|
| 1182 | - $style = extraire_attribut($tag, 'style'); |
|
| 1183 | - } |
|
| 1184 | - |
|
| 1185 | - // enlever le width et height du style |
|
| 1186 | - if ($style) { |
|
| 1187 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1188 | - } |
|
| 1189 | - if ($style && $style[0] === ';') { |
|
| 1190 | - $style = substr($style, 1); |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - // mettre des attributs de width et height sur les images, |
|
| 1194 | - // ca accelere le rendu du navigateur |
|
| 1195 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1196 | - // quand on a desactive l'affichage des images. |
|
| 1197 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1198 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1199 | - |
|
| 1200 | - // attributs deprecies. Transformer en CSS |
|
| 1201 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1202 | - $style = "margin:{$espace}px;" . $style; |
|
| 1203 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1204 | - } |
|
| 1205 | - |
|
| 1206 | - return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style); |
|
| 1181 | + if ($style === false) { |
|
| 1182 | + $style = extraire_attribut($tag, 'style'); |
|
| 1183 | + } |
|
| 1184 | + |
|
| 1185 | + // enlever le width et height du style |
|
| 1186 | + if ($style) { |
|
| 1187 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1188 | + } |
|
| 1189 | + if ($style && $style[0] === ';') { |
|
| 1190 | + $style = substr($style, 1); |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + // mettre des attributs de width et height sur les images, |
|
| 1194 | + // ca accelere le rendu du navigateur |
|
| 1195 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1196 | + // quand on a desactive l'affichage des images. |
|
| 1197 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1198 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1199 | + |
|
| 1200 | + // attributs deprecies. Transformer en CSS |
|
| 1201 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1202 | + $style = "margin:{$espace}px;" . $style; |
|
| 1203 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1204 | + } |
|
| 1205 | + |
|
| 1206 | + return inserer_attribut($tag, 'style', (string) $style, true, !(bool) $style); |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | |
@@ -1229,70 +1229,70 @@ discard block |
||
| 1229 | 1229 | * Retourne le code HTML de l'image |
| 1230 | 1230 | **/ |
| 1231 | 1231 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1232 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1233 | - |
|
| 1234 | - // fermer les tags img pas bien fermes; |
|
| 1235 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1236 | - |
|
| 1237 | - // le style |
|
| 1238 | - $style = $valeurs['style']; |
|
| 1239 | - if (isset($surcharge['style'])) { |
|
| 1240 | - $style = $surcharge['style']; |
|
| 1241 | - unset($surcharge['style']); |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - // traiter specifiquement la largeur et la hauteur |
|
| 1245 | - $width = $valeurs['largeur']; |
|
| 1246 | - if (isset($surcharge['width'])) { |
|
| 1247 | - $width = $surcharge['width']; |
|
| 1248 | - unset($surcharge['width']); |
|
| 1249 | - } |
|
| 1250 | - $height = $valeurs['hauteur']; |
|
| 1251 | - if (isset($surcharge['height'])) { |
|
| 1252 | - $height = $surcharge['height']; |
|
| 1253 | - unset($surcharge['height']); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1257 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1258 | - // on remplace toute les ref a src dans le tag |
|
| 1259 | - $src = extraire_attribut($tag, 'src'); |
|
| 1260 | - if (isset($surcharge['src'])) { |
|
| 1261 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1262 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1263 | - // pas garanti comme methode, mais mieux que rien |
|
| 1264 | - if (str_contains($src, '&')) { |
|
| 1265 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1266 | - } |
|
| 1267 | - $src = $surcharge['src']; |
|
| 1268 | - unset($surcharge['src']); |
|
| 1269 | - } |
|
| 1270 | - |
|
| 1271 | - $class = $valeurs['class']; |
|
| 1272 | - if (isset($surcharge['class'])) { |
|
| 1273 | - $class = $surcharge['class']; |
|
| 1274 | - unset($surcharge['class']); |
|
| 1275 | - } |
|
| 1276 | - if (is_scalar($class) && strlen($class)) { |
|
| 1277 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1278 | - } |
|
| 1279 | - |
|
| 1280 | - if ($surcharge !== []) { |
|
| 1281 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1282 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1283 | - } |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - return pipeline( |
|
| 1287 | - 'image_ecrire_tag_finir', |
|
| 1288 | - [ |
|
| 1289 | - 'args' => [ |
|
| 1290 | - 'valeurs' => $valeurs, |
|
| 1291 | - 'surcharge' => $surcharge, |
|
| 1292 | - ], |
|
| 1293 | - 'data' => $tag |
|
| 1294 | - ] |
|
| 1295 | - ); |
|
| 1232 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1233 | + |
|
| 1234 | + // fermer les tags img pas bien fermes; |
|
| 1235 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1236 | + |
|
| 1237 | + // le style |
|
| 1238 | + $style = $valeurs['style']; |
|
| 1239 | + if (isset($surcharge['style'])) { |
|
| 1240 | + $style = $surcharge['style']; |
|
| 1241 | + unset($surcharge['style']); |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + // traiter specifiquement la largeur et la hauteur |
|
| 1245 | + $width = $valeurs['largeur']; |
|
| 1246 | + if (isset($surcharge['width'])) { |
|
| 1247 | + $width = $surcharge['width']; |
|
| 1248 | + unset($surcharge['width']); |
|
| 1249 | + } |
|
| 1250 | + $height = $valeurs['hauteur']; |
|
| 1251 | + if (isset($surcharge['height'])) { |
|
| 1252 | + $height = $surcharge['height']; |
|
| 1253 | + unset($surcharge['height']); |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1257 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1258 | + // on remplace toute les ref a src dans le tag |
|
| 1259 | + $src = extraire_attribut($tag, 'src'); |
|
| 1260 | + if (isset($surcharge['src'])) { |
|
| 1261 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1262 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1263 | + // pas garanti comme methode, mais mieux que rien |
|
| 1264 | + if (str_contains($src, '&')) { |
|
| 1265 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1266 | + } |
|
| 1267 | + $src = $surcharge['src']; |
|
| 1268 | + unset($surcharge['src']); |
|
| 1269 | + } |
|
| 1270 | + |
|
| 1271 | + $class = $valeurs['class']; |
|
| 1272 | + if (isset($surcharge['class'])) { |
|
| 1273 | + $class = $surcharge['class']; |
|
| 1274 | + unset($surcharge['class']); |
|
| 1275 | + } |
|
| 1276 | + if (is_scalar($class) && strlen($class)) { |
|
| 1277 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1278 | + } |
|
| 1279 | + |
|
| 1280 | + if ($surcharge !== []) { |
|
| 1281 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1282 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1283 | + } |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + return pipeline( |
|
| 1287 | + 'image_ecrire_tag_finir', |
|
| 1288 | + [ |
|
| 1289 | + 'args' => [ |
|
| 1290 | + 'valeurs' => $valeurs, |
|
| 1291 | + 'surcharge' => $surcharge, |
|
| 1292 | + ], |
|
| 1293 | + 'data' => $tag |
|
| 1294 | + ] |
|
| 1295 | + ); |
|
| 1296 | 1296 | } |
| 1297 | 1297 | |
| 1298 | 1298 | /** |
@@ -1315,268 +1315,268 @@ discard block |
||
| 1315 | 1315 | * Description de l'image, sinon null. |
| 1316 | 1316 | **/ |
| 1317 | 1317 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1318 | - $srcHeight = null; |
|
| 1319 | - $retour = []; |
|
| 1320 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1321 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1322 | - $image = $valeurs['fichier']; |
|
| 1323 | - $format = $valeurs['format_source']; |
|
| 1324 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1325 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1326 | - |
|
| 1327 | - $format_sortie = $valeurs['format_dest']; |
|
| 1328 | - |
|
| 1329 | - if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1330 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1331 | - } |
|
| 1332 | - |
|
| 1333 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1334 | - if (!$force && !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1335 | - return; |
|
| 1336 | - } |
|
| 1337 | - $destination = "$destdir/$destfile"; |
|
| 1338 | - |
|
| 1339 | - // calculer la taille |
|
| 1340 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1341 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1342 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1343 | - } |
|
| 1344 | - } elseif ($process == 'convert' || $process == 'imagick') { |
|
| 1345 | - $destWidth = $maxWidth; |
|
| 1346 | - $destHeight = $maxHeight; |
|
| 1347 | - } else { |
|
| 1348 | - spip_log("echec $process sur $image"); |
|
| 1349 | - |
|
| 1350 | - return; |
|
| 1351 | - } |
|
| 1352 | - |
|
| 1353 | - $vignette = ''; |
|
| 1354 | - |
|
| 1355 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1356 | - if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1357 | - $vignette = $destination . '.' . $format; |
|
| 1358 | - @copy($image, $vignette); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1362 | - include_spip('inc/svg'); |
|
| 1363 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1364 | - $format_sortie = 'svg'; |
|
| 1365 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1366 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1367 | - _image_gd_output($svg, $valeurs); |
|
| 1368 | - } |
|
| 1369 | - } |
|
| 1370 | - |
|
| 1371 | - // imagemagick en ligne de commande |
|
| 1372 | - elseif ($process == 'convert') { |
|
| 1373 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1374 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1375 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1376 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1377 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1378 | - } |
|
| 1379 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1380 | - $commande = str_replace( |
|
| 1381 | - ['%x', '%y', '%src', '%dest'], |
|
| 1382 | - [ |
|
| 1383 | - $destWidth, |
|
| 1384 | - $destHeight, |
|
| 1385 | - escapeshellcmd($image), |
|
| 1386 | - escapeshellcmd($vignette) |
|
| 1387 | - ], |
|
| 1388 | - _RESIZE_COMMAND |
|
| 1389 | - ); |
|
| 1390 | - spip_log($commande); |
|
| 1391 | - exec($commande); |
|
| 1392 | - if (!@file_exists($vignette)) { |
|
| 1393 | - spip_log("echec convert sur $vignette"); |
|
| 1394 | - |
|
| 1395 | - return; // echec commande |
|
| 1396 | - } |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - // php5 imagemagick |
|
| 1400 | - elseif ($process == 'imagick') { |
|
| 1401 | - if (!class_exists(\Imagick::class)) { |
|
| 1402 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1403 | - |
|
| 1404 | - return; |
|
| 1405 | - } |
|
| 1406 | - |
|
| 1407 | - // chemin compatible Windows |
|
| 1408 | - $output = realpath(dirname($destination)); |
|
| 1409 | - if (!$output) { |
|
| 1410 | - return; |
|
| 1411 | - } |
|
| 1412 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1413 | - |
|
| 1414 | - $imagick = new Imagick(); |
|
| 1415 | - $imagick->readImage(realpath($image)); |
|
| 1416 | - $imagick->resizeImage( |
|
| 1417 | - $destWidth, |
|
| 1418 | - $destHeight, |
|
| 1419 | - Imagick::FILTER_LANCZOS, |
|
| 1420 | - 1 |
|
| 1421 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1422 | - $imagick->writeImage($vignette); |
|
| 1423 | - |
|
| 1424 | - if (!@file_exists($vignette)) { |
|
| 1425 | - spip_log("echec imagick sur $vignette"); |
|
| 1426 | - |
|
| 1427 | - return; |
|
| 1428 | - } |
|
| 1429 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1430 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1431 | - } |
|
| 1432 | - |
|
| 1433 | - // netpbm |
|
| 1434 | - elseif ($process == 'netpbm') { |
|
| 1435 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1436 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1437 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1438 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1439 | - return; |
|
| 1440 | - } |
|
| 1441 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1442 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1443 | - if ($format == 'jpg') { |
|
| 1444 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1445 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1446 | - if (!($s = @filesize($vignette))) { |
|
| 1447 | - spip_unlink($vignette); |
|
| 1448 | - } |
|
| 1449 | - if (!@file_exists($vignette)) { |
|
| 1450 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1451 | - |
|
| 1452 | - return; |
|
| 1453 | - } |
|
| 1454 | - } else { |
|
| 1455 | - if ($format == 'gif') { |
|
| 1456 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1457 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1458 | - if (!($s = @filesize($vignette))) { |
|
| 1459 | - spip_unlink($vignette); |
|
| 1460 | - } |
|
| 1461 | - if (!@file_exists($vignette)) { |
|
| 1462 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1463 | - |
|
| 1464 | - return; |
|
| 1465 | - } |
|
| 1466 | - } else { |
|
| 1467 | - if ($format == 'png') { |
|
| 1468 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1469 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1470 | - if (!($s = @filesize($vignette))) { |
|
| 1471 | - spip_unlink($vignette); |
|
| 1472 | - } |
|
| 1473 | - if (!@file_exists($vignette)) { |
|
| 1474 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1475 | - |
|
| 1476 | - return; |
|
| 1477 | - } |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - |
|
| 1483 | - // gd ou gd2 |
|
| 1484 | - elseif ($process == 'gd1' || $process == 'gd2') { |
|
| 1485 | - if (!function_exists('gd_info')) { |
|
| 1486 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1487 | - |
|
| 1488 | - return; |
|
| 1489 | - } |
|
| 1490 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1491 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1492 | - |
|
| 1493 | - return; |
|
| 1494 | - } |
|
| 1495 | - $destFormat = $format_sortie; |
|
| 1496 | - if (!$destFormat) { |
|
| 1497 | - spip_log("pas de format pour $image"); |
|
| 1498 | - |
|
| 1499 | - return; |
|
| 1500 | - } |
|
| 1501 | - |
|
| 1502 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1503 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1504 | - return; |
|
| 1505 | - } |
|
| 1506 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1507 | - if (!$srcImage) { |
|
| 1508 | - spip_log('echec gd1/gd2'); |
|
| 1509 | - |
|
| 1510 | - return; |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - // Initialisation de l'image destination |
|
| 1514 | - $destImage = null; |
|
| 1515 | - if ($process == 'gd2' && $destFormat != 'gif') { |
|
| 1516 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1517 | - } |
|
| 1518 | - if (!$destImage) { |
|
| 1519 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1520 | - } |
|
| 1521 | - |
|
| 1522 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1523 | - $ok = false; |
|
| 1524 | - if ($process == 'gd2' && function_exists('ImageCopyResampled')) { |
|
| 1525 | - if ($format == 'gif') { |
|
| 1526 | - // Si un GIF est transparent, |
|
| 1527 | - // fabriquer un PNG transparent |
|
| 1528 | - $transp = imagecolortransparent($srcImage); |
|
| 1529 | - if ($transp > 0) { |
|
| 1530 | - $destFormat = 'png'; |
|
| 1531 | - } |
|
| 1532 | - } |
|
| 1533 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1534 | - // Conserver la transparence |
|
| 1535 | - if (function_exists('imageAntiAlias')) { |
|
| 1536 | - imageAntiAlias($destImage, true); |
|
| 1537 | - } |
|
| 1538 | - @imagealphablending($destImage, false); |
|
| 1539 | - @imagesavealpha($destImage, true); |
|
| 1540 | - } |
|
| 1541 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1542 | - } |
|
| 1543 | - if (!$ok) { |
|
| 1544 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1545 | - } |
|
| 1546 | - |
|
| 1547 | - // Sauvegarde de l'image destination |
|
| 1548 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1549 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1550 | - _image_gd_output($destImage, $valeurs); |
|
| 1551 | - |
|
| 1552 | - if ($srcImage) { |
|
| 1553 | - ImageDestroy($srcImage); |
|
| 1554 | - } |
|
| 1555 | - ImageDestroy($destImage); |
|
| 1556 | - } |
|
| 1557 | - |
|
| 1558 | - if (!$vignette || !$size = @spip_getimagesize($vignette)) { |
|
| 1559 | - $size = [$destWidth, $destHeight]; |
|
| 1560 | - } |
|
| 1561 | - |
|
| 1562 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1563 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1564 | - if ($size[0] < 1) { |
|
| 1565 | - $size[0] = $destWidth; |
|
| 1566 | - } |
|
| 1567 | - if ($size[1] < 1) { |
|
| 1568 | - $size[1] = $destHeight; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - $retour['width'] = $largeur = $size[0]; |
|
| 1572 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1573 | - |
|
| 1574 | - $retour['fichier'] = $vignette; |
|
| 1575 | - $retour['format'] = $format; |
|
| 1576 | - $retour['date'] = @filemtime($vignette); |
|
| 1577 | - |
|
| 1578 | - // renvoyer l'image |
|
| 1579 | - return $retour; |
|
| 1318 | + $srcHeight = null; |
|
| 1319 | + $retour = []; |
|
| 1320 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1321 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1322 | + $image = $valeurs['fichier']; |
|
| 1323 | + $format = $valeurs['format_source']; |
|
| 1324 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1325 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1326 | + |
|
| 1327 | + $format_sortie = $valeurs['format_dest']; |
|
| 1328 | + |
|
| 1329 | + if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1330 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1331 | + } |
|
| 1332 | + |
|
| 1333 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1334 | + if (!$force && !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1335 | + return; |
|
| 1336 | + } |
|
| 1337 | + $destination = "$destdir/$destfile"; |
|
| 1338 | + |
|
| 1339 | + // calculer la taille |
|
| 1340 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1341 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1342 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1343 | + } |
|
| 1344 | + } elseif ($process == 'convert' || $process == 'imagick') { |
|
| 1345 | + $destWidth = $maxWidth; |
|
| 1346 | + $destHeight = $maxHeight; |
|
| 1347 | + } else { |
|
| 1348 | + spip_log("echec $process sur $image"); |
|
| 1349 | + |
|
| 1350 | + return; |
|
| 1351 | + } |
|
| 1352 | + |
|
| 1353 | + $vignette = ''; |
|
| 1354 | + |
|
| 1355 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1356 | + if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1357 | + $vignette = $destination . '.' . $format; |
|
| 1358 | + @copy($image, $vignette); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1362 | + include_spip('inc/svg'); |
|
| 1363 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1364 | + $format_sortie = 'svg'; |
|
| 1365 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1366 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1367 | + _image_gd_output($svg, $valeurs); |
|
| 1368 | + } |
|
| 1369 | + } |
|
| 1370 | + |
|
| 1371 | + // imagemagick en ligne de commande |
|
| 1372 | + elseif ($process == 'convert') { |
|
| 1373 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1374 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1375 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1376 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1377 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1378 | + } |
|
| 1379 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1380 | + $commande = str_replace( |
|
| 1381 | + ['%x', '%y', '%src', '%dest'], |
|
| 1382 | + [ |
|
| 1383 | + $destWidth, |
|
| 1384 | + $destHeight, |
|
| 1385 | + escapeshellcmd($image), |
|
| 1386 | + escapeshellcmd($vignette) |
|
| 1387 | + ], |
|
| 1388 | + _RESIZE_COMMAND |
|
| 1389 | + ); |
|
| 1390 | + spip_log($commande); |
|
| 1391 | + exec($commande); |
|
| 1392 | + if (!@file_exists($vignette)) { |
|
| 1393 | + spip_log("echec convert sur $vignette"); |
|
| 1394 | + |
|
| 1395 | + return; // echec commande |
|
| 1396 | + } |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + // php5 imagemagick |
|
| 1400 | + elseif ($process == 'imagick') { |
|
| 1401 | + if (!class_exists(\Imagick::class)) { |
|
| 1402 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1403 | + |
|
| 1404 | + return; |
|
| 1405 | + } |
|
| 1406 | + |
|
| 1407 | + // chemin compatible Windows |
|
| 1408 | + $output = realpath(dirname($destination)); |
|
| 1409 | + if (!$output) { |
|
| 1410 | + return; |
|
| 1411 | + } |
|
| 1412 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1413 | + |
|
| 1414 | + $imagick = new Imagick(); |
|
| 1415 | + $imagick->readImage(realpath($image)); |
|
| 1416 | + $imagick->resizeImage( |
|
| 1417 | + $destWidth, |
|
| 1418 | + $destHeight, |
|
| 1419 | + Imagick::FILTER_LANCZOS, |
|
| 1420 | + 1 |
|
| 1421 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1422 | + $imagick->writeImage($vignette); |
|
| 1423 | + |
|
| 1424 | + if (!@file_exists($vignette)) { |
|
| 1425 | + spip_log("echec imagick sur $vignette"); |
|
| 1426 | + |
|
| 1427 | + return; |
|
| 1428 | + } |
|
| 1429 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1430 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1431 | + } |
|
| 1432 | + |
|
| 1433 | + // netpbm |
|
| 1434 | + elseif ($process == 'netpbm') { |
|
| 1435 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1436 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1437 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1438 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1439 | + return; |
|
| 1440 | + } |
|
| 1441 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1442 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1443 | + if ($format == 'jpg') { |
|
| 1444 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1445 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1446 | + if (!($s = @filesize($vignette))) { |
|
| 1447 | + spip_unlink($vignette); |
|
| 1448 | + } |
|
| 1449 | + if (!@file_exists($vignette)) { |
|
| 1450 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1451 | + |
|
| 1452 | + return; |
|
| 1453 | + } |
|
| 1454 | + } else { |
|
| 1455 | + if ($format == 'gif') { |
|
| 1456 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1457 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1458 | + if (!($s = @filesize($vignette))) { |
|
| 1459 | + spip_unlink($vignette); |
|
| 1460 | + } |
|
| 1461 | + if (!@file_exists($vignette)) { |
|
| 1462 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1463 | + |
|
| 1464 | + return; |
|
| 1465 | + } |
|
| 1466 | + } else { |
|
| 1467 | + if ($format == 'png') { |
|
| 1468 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1469 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1470 | + if (!($s = @filesize($vignette))) { |
|
| 1471 | + spip_unlink($vignette); |
|
| 1472 | + } |
|
| 1473 | + if (!@file_exists($vignette)) { |
|
| 1474 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1475 | + |
|
| 1476 | + return; |
|
| 1477 | + } |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + } |
|
| 1481 | + } |
|
| 1482 | + |
|
| 1483 | + // gd ou gd2 |
|
| 1484 | + elseif ($process == 'gd1' || $process == 'gd2') { |
|
| 1485 | + if (!function_exists('gd_info')) { |
|
| 1486 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1487 | + |
|
| 1488 | + return; |
|
| 1489 | + } |
|
| 1490 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1491 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1492 | + |
|
| 1493 | + return; |
|
| 1494 | + } |
|
| 1495 | + $destFormat = $format_sortie; |
|
| 1496 | + if (!$destFormat) { |
|
| 1497 | + spip_log("pas de format pour $image"); |
|
| 1498 | + |
|
| 1499 | + return; |
|
| 1500 | + } |
|
| 1501 | + |
|
| 1502 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1503 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1504 | + return; |
|
| 1505 | + } |
|
| 1506 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1507 | + if (!$srcImage) { |
|
| 1508 | + spip_log('echec gd1/gd2'); |
|
| 1509 | + |
|
| 1510 | + return; |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + // Initialisation de l'image destination |
|
| 1514 | + $destImage = null; |
|
| 1515 | + if ($process == 'gd2' && $destFormat != 'gif') { |
|
| 1516 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1517 | + } |
|
| 1518 | + if (!$destImage) { |
|
| 1519 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1520 | + } |
|
| 1521 | + |
|
| 1522 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1523 | + $ok = false; |
|
| 1524 | + if ($process == 'gd2' && function_exists('ImageCopyResampled')) { |
|
| 1525 | + if ($format == 'gif') { |
|
| 1526 | + // Si un GIF est transparent, |
|
| 1527 | + // fabriquer un PNG transparent |
|
| 1528 | + $transp = imagecolortransparent($srcImage); |
|
| 1529 | + if ($transp > 0) { |
|
| 1530 | + $destFormat = 'png'; |
|
| 1531 | + } |
|
| 1532 | + } |
|
| 1533 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1534 | + // Conserver la transparence |
|
| 1535 | + if (function_exists('imageAntiAlias')) { |
|
| 1536 | + imageAntiAlias($destImage, true); |
|
| 1537 | + } |
|
| 1538 | + @imagealphablending($destImage, false); |
|
| 1539 | + @imagesavealpha($destImage, true); |
|
| 1540 | + } |
|
| 1541 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1542 | + } |
|
| 1543 | + if (!$ok) { |
|
| 1544 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1545 | + } |
|
| 1546 | + |
|
| 1547 | + // Sauvegarde de l'image destination |
|
| 1548 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1549 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1550 | + _image_gd_output($destImage, $valeurs); |
|
| 1551 | + |
|
| 1552 | + if ($srcImage) { |
|
| 1553 | + ImageDestroy($srcImage); |
|
| 1554 | + } |
|
| 1555 | + ImageDestroy($destImage); |
|
| 1556 | + } |
|
| 1557 | + |
|
| 1558 | + if (!$vignette || !$size = @spip_getimagesize($vignette)) { |
|
| 1559 | + $size = [$destWidth, $destHeight]; |
|
| 1560 | + } |
|
| 1561 | + |
|
| 1562 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1563 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1564 | + if ($size[0] < 1) { |
|
| 1565 | + $size[0] = $destWidth; |
|
| 1566 | + } |
|
| 1567 | + if ($size[1] < 1) { |
|
| 1568 | + $size[1] = $destHeight; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + $retour['width'] = $largeur = $size[0]; |
|
| 1572 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1573 | + |
|
| 1574 | + $retour['fichier'] = $vignette; |
|
| 1575 | + $retour['format'] = $format; |
|
| 1576 | + $retour['date'] = @filemtime($vignette); |
|
| 1577 | + |
|
| 1578 | + // renvoyer l'image |
|
| 1579 | + return $retour; |
|
| 1580 | 1580 | } |
| 1581 | 1581 | |
| 1582 | 1582 | /** |
@@ -1596,25 +1596,25 @@ discard block |
||
| 1596 | 1596 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1597 | 1597 | **/ |
| 1598 | 1598 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1599 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1600 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1601 | - |
|
| 1602 | - if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1603 | - $destWidth = $srcWidth; |
|
| 1604 | - $destHeight = $srcHeight; |
|
| 1605 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1606 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1607 | - $destHeight = $maxHeight; |
|
| 1608 | - } else { |
|
| 1609 | - $destWidth = $maxWidth; |
|
| 1610 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1611 | - } |
|
| 1612 | - |
|
| 1613 | - return [ |
|
| 1614 | - (int) round($destWidth), |
|
| 1615 | - (int) round($destHeight), |
|
| 1616 | - max($ratioWidth, $ratioHeight) |
|
| 1617 | - ]; |
|
| 1599 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1600 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1601 | + |
|
| 1602 | + if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1603 | + $destWidth = $srcWidth; |
|
| 1604 | + $destHeight = $srcHeight; |
|
| 1605 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1606 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1607 | + $destHeight = $maxHeight; |
|
| 1608 | + } else { |
|
| 1609 | + $destWidth = $maxWidth; |
|
| 1610 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1611 | + } |
|
| 1612 | + |
|
| 1613 | + return [ |
|
| 1614 | + (int) round($destWidth), |
|
| 1615 | + (int) round($destHeight), |
|
| 1616 | + max($ratioWidth, $ratioHeight) |
|
| 1617 | + ]; |
|
| 1618 | 1618 | } |
| 1619 | 1619 | |
| 1620 | 1620 | /** |
@@ -1634,25 +1634,25 @@ discard block |
||
| 1634 | 1634 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1635 | 1635 | **/ |
| 1636 | 1636 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1637 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1638 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1639 | - |
|
| 1640 | - if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1641 | - $destWidth = $srcWidth; |
|
| 1642 | - $destHeight = $srcHeight; |
|
| 1643 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1644 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1645 | - $destHeight = $maxHeight; |
|
| 1646 | - } else { |
|
| 1647 | - $destWidth = $maxWidth; |
|
| 1648 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1649 | - } |
|
| 1650 | - |
|
| 1651 | - return [ |
|
| 1652 | - (int) round($destWidth), |
|
| 1653 | - (int) round($destHeight), |
|
| 1654 | - min($ratioWidth, $ratioHeight) |
|
| 1655 | - ]; |
|
| 1637 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1638 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1639 | + |
|
| 1640 | + if ($srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
|
| 1641 | + $destWidth = $srcWidth; |
|
| 1642 | + $destHeight = $srcHeight; |
|
| 1643 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1644 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1645 | + $destHeight = $maxHeight; |
|
| 1646 | + } else { |
|
| 1647 | + $destWidth = $maxWidth; |
|
| 1648 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1649 | + } |
|
| 1650 | + |
|
| 1651 | + return [ |
|
| 1652 | + (int) round($destWidth), |
|
| 1653 | + (int) round($destHeight), |
|
| 1654 | + min($ratioWidth, $ratioHeight) |
|
| 1655 | + ]; |
|
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | |
@@ -1665,12 +1665,12 @@ discard block |
||
| 1665 | 1665 | * @return string |
| 1666 | 1666 | */ |
| 1667 | 1667 | function process_image_svg_identite($image) { |
| 1668 | - if ($image['creer']) { |
|
| 1669 | - $source = $image['fichier']; |
|
| 1670 | - _image_gd_output($source, $image); |
|
| 1671 | - } |
|
| 1668 | + if ($image['creer']) { |
|
| 1669 | + $source = $image['fichier']; |
|
| 1670 | + _image_gd_output($source, $image); |
|
| 1671 | + } |
|
| 1672 | 1672 | |
| 1673 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1673 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 1676 | 1676 | |
@@ -1703,101 +1703,101 @@ discard block |
||
| 1703 | 1703 | * Code HTML de la balise img produite |
| 1704 | 1704 | **/ |
| 1705 | 1705 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1706 | - $image = false; |
|
| 1707 | - if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1708 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1709 | - } |
|
| 1710 | - # determiner le format de sortie |
|
| 1711 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1712 | - if ($process == 'netpbm') { |
|
| 1713 | - $format_sortie = 'jpg'; |
|
| 1714 | - } elseif ($process == 'gd1' || $process == 'gd2') { |
|
| 1715 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1716 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1717 | - $gd_formats = formats_image_acceptables(true); |
|
| 1718 | - if ( |
|
| 1719 | - is_array($image) && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1720 | - ) { |
|
| 1721 | - $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif']; |
|
| 1722 | - // Choisir le format destination |
|
| 1723 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1724 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1725 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1726 | - # pas *ecrire* |
|
| 1727 | - $format_sortie = ''; |
|
| 1728 | - foreach ($formats_sortie as $fmt) { |
|
| 1729 | - if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1730 | - $format_sortie = $fmt; |
|
| 1731 | - break; |
|
| 1732 | - } |
|
| 1733 | - } |
|
| 1734 | - $image = false; |
|
| 1735 | - } |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - if (!is_array($image)) { |
|
| 1739 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1740 | - } |
|
| 1741 | - |
|
| 1742 | - if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) { |
|
| 1743 | - spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1744 | - // on peut resizer en mode html si on dispose des elements |
|
| 1745 | - [$srcw, $srch] = taille_image($img); |
|
| 1746 | - if ($srcw && $srch) { |
|
| 1747 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1748 | - |
|
| 1749 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1750 | - } |
|
| 1751 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1752 | - // sous la forme style='max-width: NNpx;' |
|
| 1753 | - return inserer_attribut( |
|
| 1754 | - $img, |
|
| 1755 | - 'style', |
|
| 1756 | - "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1757 | - ); |
|
| 1758 | - } |
|
| 1759 | - |
|
| 1760 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1761 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1762 | - if ($image['creer']) { |
|
| 1763 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1764 | - } |
|
| 1765 | - |
|
| 1766 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1767 | - } |
|
| 1768 | - |
|
| 1769 | - if ($image['creer'] == false && !$force) { |
|
| 1770 | - return _image_ecrire_tag( |
|
| 1771 | - $image, |
|
| 1772 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1773 | - ); |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1777 | - $destWidth = $image['largeur_dest']; |
|
| 1778 | - $destHeight = $image['hauteur_dest']; |
|
| 1779 | - $logo = $image['fichier']; |
|
| 1780 | - $date = $image['date_src']; |
|
| 1781 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1782 | - |
|
| 1783 | - if ($preview && $preview['fichier']) { |
|
| 1784 | - $logo = $preview['fichier']; |
|
| 1785 | - $destWidth = $preview['width']; |
|
| 1786 | - $destHeight = $preview['height']; |
|
| 1787 | - $date = $preview['date']; |
|
| 1788 | - } |
|
| 1789 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1790 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1791 | - // quand on fait supprimer/reuploader un logo |
|
| 1792 | - // (pas de filemtime si SAFE MODE) |
|
| 1793 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1794 | - |
|
| 1795 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1796 | - } |
|
| 1797 | - else { |
|
| 1798 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1799 | - return $img; |
|
| 1800 | - } |
|
| 1706 | + $image = false; |
|
| 1707 | + if ($process == 'AUTO' && isset($GLOBALS['meta']['image_process'])) { |
|
| 1708 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1709 | + } |
|
| 1710 | + # determiner le format de sortie |
|
| 1711 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1712 | + if ($process == 'netpbm') { |
|
| 1713 | + $format_sortie = 'jpg'; |
|
| 1714 | + } elseif ($process == 'gd1' || $process == 'gd2') { |
|
| 1715 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1716 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1717 | + $gd_formats = formats_image_acceptables(true); |
|
| 1718 | + if ( |
|
| 1719 | + is_array($image) && (!in_array($image['format_dest'], $gd_formats) || !in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1720 | + ) { |
|
| 1721 | + $formats_sortie = $image['format_source'] == 'jpg' ? ['jpg', 'png', 'gif'] : ['png', 'jpg', 'gif']; |
|
| 1722 | + // Choisir le format destination |
|
| 1723 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1724 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1725 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1726 | + # pas *ecrire* |
|
| 1727 | + $format_sortie = ''; |
|
| 1728 | + foreach ($formats_sortie as $fmt) { |
|
| 1729 | + if (in_array($fmt, $gd_formats) && in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1730 | + $format_sortie = $fmt; |
|
| 1731 | + break; |
|
| 1732 | + } |
|
| 1733 | + } |
|
| 1734 | + $image = false; |
|
| 1735 | + } |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + if (!is_array($image)) { |
|
| 1739 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1740 | + } |
|
| 1741 | + |
|
| 1742 | + if (!is_array($image) || !$image['largeur'] || !$image['hauteur']) { |
|
| 1743 | + spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1744 | + // on peut resizer en mode html si on dispose des elements |
|
| 1745 | + [$srcw, $srch] = taille_image($img); |
|
| 1746 | + if ($srcw && $srch) { |
|
| 1747 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1748 | + |
|
| 1749 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1750 | + } |
|
| 1751 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1752 | + // sous la forme style='max-width: NNpx;' |
|
| 1753 | + return inserer_attribut( |
|
| 1754 | + $img, |
|
| 1755 | + 'style', |
|
| 1756 | + "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1757 | + ); |
|
| 1758 | + } |
|
| 1759 | + |
|
| 1760 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1761 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1762 | + if ($image['creer']) { |
|
| 1763 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1764 | + } |
|
| 1765 | + |
|
| 1766 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1767 | + } |
|
| 1768 | + |
|
| 1769 | + if ($image['creer'] == false && !$force) { |
|
| 1770 | + return _image_ecrire_tag( |
|
| 1771 | + $image, |
|
| 1772 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1773 | + ); |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1777 | + $destWidth = $image['largeur_dest']; |
|
| 1778 | + $destHeight = $image['hauteur_dest']; |
|
| 1779 | + $logo = $image['fichier']; |
|
| 1780 | + $date = $image['date_src']; |
|
| 1781 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1782 | + |
|
| 1783 | + if ($preview && $preview['fichier']) { |
|
| 1784 | + $logo = $preview['fichier']; |
|
| 1785 | + $destWidth = $preview['width']; |
|
| 1786 | + $destHeight = $preview['height']; |
|
| 1787 | + $date = $preview['date']; |
|
| 1788 | + } |
|
| 1789 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1790 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1791 | + // quand on fait supprimer/reuploader un logo |
|
| 1792 | + // (pas de filemtime si SAFE MODE) |
|
| 1793 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1794 | + |
|
| 1795 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1796 | + } |
|
| 1797 | + else { |
|
| 1798 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1799 | + return $img; |
|
| 1800 | + } |
|
| 1801 | 1801 | } |
| 1802 | 1802 | |
| 1803 | 1803 | /** |
@@ -1811,145 +1811,145 @@ discard block |
||
| 1811 | 1811 | * Class phpthumb_functions |
| 1812 | 1812 | */ |
| 1813 | 1813 | class phpthumb_functions { |
| 1814 | - /** |
|
| 1815 | - * Retourne la couleur d'un pixel dans une image |
|
| 1816 | - * |
|
| 1817 | - * @param GdImage $img |
|
| 1818 | - * @param int $x |
|
| 1819 | - * @param int $y |
|
| 1820 | - * @return array|bool |
|
| 1821 | - */ |
|
| 1822 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1823 | - if ($img instanceof \GdImage) { |
|
| 1824 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1825 | - } |
|
| 1826 | - return false; |
|
| 1827 | - } |
|
| 1828 | - |
|
| 1829 | - /** |
|
| 1830 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1831 | - * |
|
| 1832 | - * @param int $number |
|
| 1833 | - * @param int $minbytes |
|
| 1834 | - * @return string |
|
| 1835 | - */ |
|
| 1836 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1837 | - $intstring = ''; |
|
| 1838 | - while ($number > 0) { |
|
| 1839 | - $intstring .= chr($number & 255); |
|
| 1840 | - $number >>= 8; |
|
| 1841 | - } |
|
| 1842 | - |
|
| 1843 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - /** |
|
| 1847 | - * Transforme une ressource GD en image au format ICO |
|
| 1848 | - * |
|
| 1849 | - * @param array $gd_image_array |
|
| 1850 | - * Tableau de ressources d'images GD |
|
| 1851 | - * @return string |
|
| 1852 | - * Image au format ICO |
|
| 1853 | - */ |
|
| 1854 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1855 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1856 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1857 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1858 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1859 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1860 | - |
|
| 1861 | - $icXOR[$key] = ''; |
|
| 1862 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1863 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1864 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1865 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1866 | - $r = $argb['red']; |
|
| 1867 | - $g = $argb['green']; |
|
| 1868 | - $b = $argb['blue']; |
|
| 1869 | - |
|
| 1870 | - if ($bpp[$key] == 32) { |
|
| 1871 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1872 | - } elseif ($bpp[$key] === 24) { |
|
| 1873 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1874 | - } |
|
| 1875 | - |
|
| 1876 | - if ($a < 128) { |
|
| 1877 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1878 | - } else { |
|
| 1879 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1880 | - } |
|
| 1881 | - } |
|
| 1882 | - // mask bits are 32-bit aligned per scanline |
|
| 1883 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1884 | - $icANDmask[$key][$y] .= '0'; |
|
| 1885 | - } |
|
| 1886 | - } |
|
| 1887 | - $icAND[$key] = ''; |
|
| 1888 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1889 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1890 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1891 | - } |
|
| 1892 | - } |
|
| 1893 | - } |
|
| 1894 | - |
|
| 1895 | - foreach (array_keys($gd_image_array) as $key) { |
|
| 1896 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1897 | - |
|
| 1898 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1899 | - $BitmapInfoHeader[$key] = ''; |
|
| 1900 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1901 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1902 | - // The biHeight member specifies the combined |
|
| 1903 | - // height of the XOR and AND masks. |
|
| 1904 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1905 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1906 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1907 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1908 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1909 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1910 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1911 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1912 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1913 | - } |
|
| 1914 | - |
|
| 1915 | - |
|
| 1916 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1917 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1918 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1919 | - |
|
| 1920 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1921 | - foreach (array_keys($gd_image_array) as $key) { |
|
| 1922 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1923 | - |
|
| 1924 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1925 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1926 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1927 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1928 | - |
|
| 1929 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1930 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1931 | - |
|
| 1932 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1933 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1934 | - $dwBytesInRes, |
|
| 1935 | - 4 |
|
| 1936 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1937 | - |
|
| 1938 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1939 | - $dwImageOffset, |
|
| 1940 | - 4 |
|
| 1941 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1942 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1943 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1944 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1945 | - } |
|
| 1946 | - |
|
| 1947 | - foreach (array_keys($gd_image_array) as $key) { |
|
| 1948 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1949 | - $icondata .= $icXOR[$key]; |
|
| 1950 | - $icondata .= $icAND[$key]; |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - return $icondata; |
|
| 1954 | - } |
|
| 1814 | + /** |
|
| 1815 | + * Retourne la couleur d'un pixel dans une image |
|
| 1816 | + * |
|
| 1817 | + * @param GdImage $img |
|
| 1818 | + * @param int $x |
|
| 1819 | + * @param int $y |
|
| 1820 | + * @return array|bool |
|
| 1821 | + */ |
|
| 1822 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1823 | + if ($img instanceof \GdImage) { |
|
| 1824 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1825 | + } |
|
| 1826 | + return false; |
|
| 1827 | + } |
|
| 1828 | + |
|
| 1829 | + /** |
|
| 1830 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1831 | + * |
|
| 1832 | + * @param int $number |
|
| 1833 | + * @param int $minbytes |
|
| 1834 | + * @return string |
|
| 1835 | + */ |
|
| 1836 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1837 | + $intstring = ''; |
|
| 1838 | + while ($number > 0) { |
|
| 1839 | + $intstring .= chr($number & 255); |
|
| 1840 | + $number >>= 8; |
|
| 1841 | + } |
|
| 1842 | + |
|
| 1843 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + /** |
|
| 1847 | + * Transforme une ressource GD en image au format ICO |
|
| 1848 | + * |
|
| 1849 | + * @param array $gd_image_array |
|
| 1850 | + * Tableau de ressources d'images GD |
|
| 1851 | + * @return string |
|
| 1852 | + * Image au format ICO |
|
| 1853 | + */ |
|
| 1854 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1855 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1856 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1857 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1858 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1859 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1860 | + |
|
| 1861 | + $icXOR[$key] = ''; |
|
| 1862 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1863 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1864 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1865 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1866 | + $r = $argb['red']; |
|
| 1867 | + $g = $argb['green']; |
|
| 1868 | + $b = $argb['blue']; |
|
| 1869 | + |
|
| 1870 | + if ($bpp[$key] == 32) { |
|
| 1871 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1872 | + } elseif ($bpp[$key] === 24) { |
|
| 1873 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1874 | + } |
|
| 1875 | + |
|
| 1876 | + if ($a < 128) { |
|
| 1877 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1878 | + } else { |
|
| 1879 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1880 | + } |
|
| 1881 | + } |
|
| 1882 | + // mask bits are 32-bit aligned per scanline |
|
| 1883 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1884 | + $icANDmask[$key][$y] .= '0'; |
|
| 1885 | + } |
|
| 1886 | + } |
|
| 1887 | + $icAND[$key] = ''; |
|
| 1888 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1889 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1890 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1891 | + } |
|
| 1892 | + } |
|
| 1893 | + } |
|
| 1894 | + |
|
| 1895 | + foreach (array_keys($gd_image_array) as $key) { |
|
| 1896 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1897 | + |
|
| 1898 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1899 | + $BitmapInfoHeader[$key] = ''; |
|
| 1900 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1901 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1902 | + // The biHeight member specifies the combined |
|
| 1903 | + // height of the XOR and AND masks. |
|
| 1904 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1905 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1906 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1907 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1908 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1909 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1910 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1911 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1912 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1913 | + } |
|
| 1914 | + |
|
| 1915 | + |
|
| 1916 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1917 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1918 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1919 | + |
|
| 1920 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1921 | + foreach (array_keys($gd_image_array) as $key) { |
|
| 1922 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1923 | + |
|
| 1924 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1925 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1926 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1927 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1928 | + |
|
| 1929 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1930 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1931 | + |
|
| 1932 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1933 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1934 | + $dwBytesInRes, |
|
| 1935 | + 4 |
|
| 1936 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1937 | + |
|
| 1938 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1939 | + $dwImageOffset, |
|
| 1940 | + 4 |
|
| 1941 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1942 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1943 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1944 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1945 | + } |
|
| 1946 | + |
|
| 1947 | + foreach (array_keys($gd_image_array) as $key) { |
|
| 1948 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1949 | + $icondata .= $icXOR[$key]; |
|
| 1950 | + $icondata .= $icAND[$key]; |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + return $icondata; |
|
| 1954 | + } |
|
| 1955 | 1955 | } |
@@ -42,13 +42,13 @@ discard block |
||
| 42 | 42 | $blue = dechex($blue); |
| 43 | 43 | |
| 44 | 44 | if (strlen($red) == 1) { |
| 45 | - $red = '0' . $red; |
|
| 45 | + $red = '0'.$red; |
|
| 46 | 46 | } |
| 47 | 47 | if (strlen($green) == 1) { |
| 48 | - $green = '0' . $green; |
|
| 48 | + $green = '0'.$green; |
|
| 49 | 49 | } |
| 50 | 50 | if (strlen($blue) == 1) { |
| 51 | - $blue = '0' . $blue; |
|
| 51 | + $blue = '0'.$blue; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | return "$red$green$blue"; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $couleur = couleur_html_to_hex($couleur); |
| 68 | 68 | $couleur = ltrim($couleur, '#'); |
| 69 | 69 | if (strlen($couleur) === 3) { |
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 70 | + $couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2]; |
|
| 71 | 71 | } |
| 72 | 72 | $retour = []; |
| 73 | 73 | $retour['red'] = hexdec(substr($couleur, 0, 2)); |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | $var_G = ($G / 255); |
| 126 | 126 | $var_B = ($B / 255); |
| 127 | 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 |
|
| 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 | 131 | |
| 132 | 132 | $L = ($var_Max + $var_Min) / 2; |
| 133 | 133 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 187 | 187 | // helper |
| 188 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 188 | + $hue_2_rgb = function($v1, $v2, $vH) { |
|
| 189 | 189 | if ($vH < 0) { |
| 190 | 190 | $vH += 1; |
| 191 | 191 | } |
@@ -319,11 +319,11 @@ discard block |
||
| 319 | 319 | } |
| 320 | 320 | } elseif ( |
| 321 | 321 | preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
| 322 | - && ($extension = _image_trouver_extension_depuis_mime('image/' . $regs[1])) |
|
| 322 | + && ($extension = _image_trouver_extension_depuis_mime('image/'.$regs[1])) |
|
| 323 | 323 | && in_array($extension, _image_extensions_acceptees_en_entree()) |
| 324 | 324 | ) { |
| 325 | 325 | # gerer img src="data:....base64" |
| 326 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 326 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension); |
|
| 327 | 327 | if (!file_exists($local)) { |
| 328 | 328 | ecrire_fichier($local, base64_decode($regs[2])); |
| 329 | 329 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | // les protocoles web prennent au moins 3 lettres |
| 341 | 341 | if (tester_url_absolue($source)) { |
| 342 | 342 | include_spip('inc/distant'); |
| 343 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 343 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 344 | 344 | if (!$fichier) { |
| 345 | 345 | return ''; |
| 346 | 346 | } |
@@ -442,9 +442,9 @@ discard block |
||
| 442 | 442 | // on garde la terminaison initiale car image simplement copiee |
| 443 | 443 | // et on postfixe son nom avec un md5 du path |
| 444 | 444 | $terminaison_dest = $terminaison; |
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 445 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 446 | 446 | } else { |
| 447 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 447 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 448 | 448 | } |
| 449 | 449 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 450 | 450 | $cache = sous_repertoire($cache, $effet); |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | $fichier_dest = substr($fichier_dest, 2); |
| 456 | 456 | } |
| 457 | 457 | |
| 458 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 458 | + $fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest; |
|
| 459 | 459 | |
| 460 | 460 | $GLOBALS['images_calculees'][] = $fichier_dest; |
| 461 | 461 | |
@@ -481,7 +481,7 @@ discard block |
||
| 481 | 481 | } |
| 482 | 482 | if ($creer && !@file_exists($fichier)) { |
| 483 | 483 | if (!@file_exists("$fichier.src")) { |
| 484 | - spip_log("Image absente : $fichier", 'images' . _LOG_ERREUR); |
|
| 484 | + spip_log("Image absente : $fichier", 'images'._LOG_ERREUR); |
|
| 485 | 485 | |
| 486 | 486 | return false; |
| 487 | 487 | } |
@@ -491,15 +491,15 @@ discard block |
||
| 491 | 491 | |
| 492 | 492 | if ($creer) { |
| 493 | 493 | spip_log( |
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 494 | + 'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 495 | + 'images'._LOG_DEBUG |
|
| 496 | 496 | ); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $term_fonction = _image_trouver_extension_pertinente($fichier); |
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction; |
|
| 501 | 501 | $ret['fichier'] = $fichier; |
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | + $ret['fonction_image'] = '_image_image'.$terminaison_dest; |
|
| 503 | 503 | $ret['fichier_dest'] = $fichier_dest; |
| 504 | 504 | $ret['format_source'] = _image_extension_normalisee($terminaison); |
| 505 | 505 | $ret['format_dest'] = $terminaison_dest; |
@@ -643,7 +643,7 @@ discard block |
||
| 643 | 643 | |
| 644 | 644 | $_terminaison = _image_trouver_extension_depuis_mime($mime); |
| 645 | 645 | if ($_terminaison && $_terminaison !== $terminaison) { |
| 646 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 646 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE); |
|
| 647 | 647 | $terminaison = $_terminaison; |
| 648 | 648 | } |
| 649 | 649 | return $terminaison; |
@@ -778,7 +778,7 @@ discard block |
||
| 778 | 778 | if (!function_exists('imagepng')) { |
| 779 | 779 | return false; |
| 780 | 780 | } |
| 781 | - $tmp = $fichier . '.tmp'; |
|
| 781 | + $tmp = $fichier.'.tmp'; |
|
| 782 | 782 | $ret = imagepng($img, $tmp); |
| 783 | 783 | if (file_exists($tmp)) { |
| 784 | 784 | $taille_test = @getimagesize($tmp); |
@@ -813,7 +813,7 @@ discard block |
||
| 813 | 813 | if (!function_exists('imagegif')) { |
| 814 | 814 | return false; |
| 815 | 815 | } |
| 816 | - $tmp = $fichier . '.tmp'; |
|
| 816 | + $tmp = $fichier.'.tmp'; |
|
| 817 | 817 | $ret = imagegif($img, $tmp); |
| 818 | 818 | if (file_exists($tmp)) { |
| 819 | 819 | $taille_test = @getimagesize($tmp); |
@@ -853,7 +853,7 @@ discard block |
||
| 853 | 853 | if (!function_exists('imagejpeg')) { |
| 854 | 854 | return false; |
| 855 | 855 | } |
| 856 | - $tmp = $fichier . '.tmp'; |
|
| 856 | + $tmp = $fichier.'.tmp'; |
|
| 857 | 857 | |
| 858 | 858 | // Enable interlancing |
| 859 | 859 | imageinterlace($img, true); |
@@ -914,7 +914,7 @@ discard block |
||
| 914 | 914 | if (!function_exists('imagewebp')) { |
| 915 | 915 | return false; |
| 916 | 916 | } |
| 917 | - $tmp = $fichier . '.tmp'; |
|
| 917 | + $tmp = $fichier.'.tmp'; |
|
| 918 | 918 | $ret = imagewebp($img, $tmp, $qualite); |
| 919 | 919 | if (file_exists($tmp)) { |
| 920 | 920 | $taille_test = @getimagesize($tmp); |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | */ |
| 949 | 949 | function _image_imagesvg($img, $fichier) { |
| 950 | 950 | |
| 951 | - $tmp = $fichier . '.tmp'; |
|
| 951 | + $tmp = $fichier.'.tmp'; |
|
| 952 | 952 | if (!str_contains($img, '<')) { |
| 953 | 953 | $img = supprimer_timestamp($img); |
| 954 | 954 | if (!file_exists($img)) { |
@@ -1005,14 +1005,14 @@ discard block |
||
| 1005 | 1005 | */ |
| 1006 | 1006 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1007 | 1007 | if (is_null($fonction)) { |
| 1008 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1008 | + $fonction = '_image_image'.$valeurs['format_dest']; |
|
| 1009 | 1009 | } |
| 1010 | 1010 | $ret = false; |
| 1011 | 1011 | #un flag pour reperer les images gravees |
| 1012 | 1012 | $lock = ( |
| 1013 | 1013 | !statut_effacer_images_temporaires('get') |
| 1014 | 1014 | || @file_exists($valeurs['fichier_dest']) |
| 1015 | - && !@file_exists($valeurs['fichier_dest'] . '.src') |
|
| 1015 | + && !@file_exists($valeurs['fichier_dest'].'.src') |
|
| 1016 | 1016 | ); |
| 1017 | 1017 | if ( |
| 1018 | 1018 | function_exists($fonction) |
@@ -1024,7 +1024,7 @@ discard block |
||
| 1024 | 1024 | [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
| 1025 | 1025 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); |
| 1026 | 1026 | // pour la retrouver apres disparition |
| 1027 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1027 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 1028 | 1028 | } |
| 1029 | 1029 | |
| 1030 | 1030 | return $ret; |
@@ -1199,7 +1199,7 @@ discard block |
||
| 1199 | 1199 | |
| 1200 | 1200 | // attributs deprecies. Transformer en CSS |
| 1201 | 1201 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 1202 | - $style = "margin:{$espace}px;" . $style; |
|
| 1202 | + $style = "margin:{$espace}px;".$style; |
|
| 1203 | 1203 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 1204 | 1204 | } |
| 1205 | 1205 | |
@@ -1322,7 +1322,7 @@ discard block |
||
| 1322 | 1322 | $image = $valeurs['fichier']; |
| 1323 | 1323 | $format = $valeurs['format_source']; |
| 1324 | 1324 | $destdir = dirname($valeurs['fichier_dest']); |
| 1325 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1325 | + $destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']); |
|
| 1326 | 1326 | |
| 1327 | 1327 | $format_sortie = $valeurs['format_dest']; |
| 1328 | 1328 | |
@@ -1354,7 +1354,7 @@ discard block |
||
| 1354 | 1354 | |
| 1355 | 1355 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 1356 | 1356 | if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
| 1357 | - $vignette = $destination . '.' . $format; |
|
| 1357 | + $vignette = $destination.'.'.$format; |
|
| 1358 | 1358 | @copy($image, $vignette); |
| 1359 | 1359 | } |
| 1360 | 1360 | |
@@ -1362,7 +1362,7 @@ discard block |
||
| 1362 | 1362 | include_spip('inc/svg'); |
| 1363 | 1363 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1364 | 1364 | $format_sortie = 'svg'; |
| 1365 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1365 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1366 | 1366 | $valeurs['fichier_dest'] = $vignette; |
| 1367 | 1367 | _image_gd_output($svg, $valeurs); |
| 1368 | 1368 | } |
@@ -1374,9 +1374,9 @@ discard block |
||
| 1374 | 1374 | define('_CONVERT_COMMAND', 'convert'); |
| 1375 | 1375 | } // Securite : mes_options.php peut preciser le chemin absolu |
| 1376 | 1376 | if (!defined('_RESIZE_COMMAND')) { |
| 1377 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1377 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -orient Undefined -resize %xx%y! %src %dest'); |
|
| 1378 | 1378 | } |
| 1379 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1379 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1380 | 1380 | $commande = str_replace( |
| 1381 | 1381 | ['%x', '%y', '%src', '%dest'], |
| 1382 | 1382 | [ |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | if (!@file_exists($vignette)) { |
| 1393 | 1393 | spip_log("echec convert sur $vignette"); |
| 1394 | 1394 | |
| 1395 | - return; // echec commande |
|
| 1395 | + return; // echec commande |
|
| 1396 | 1396 | } |
| 1397 | 1397 | } |
| 1398 | 1398 | |
@@ -1409,7 +1409,7 @@ discard block |
||
| 1409 | 1409 | if (!$output) { |
| 1410 | 1410 | return; |
| 1411 | 1411 | } |
| 1412 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1412 | + $vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie; |
|
| 1413 | 1413 | |
| 1414 | 1414 | $imagick = new Imagick(); |
| 1415 | 1415 | $imagick->readImage(realpath($image)); |
@@ -1418,7 +1418,7 @@ discard block |
||
| 1418 | 1418 | $destHeight, |
| 1419 | 1419 | Imagick::FILTER_LANCZOS, |
| 1420 | 1420 | 1 |
| 1421 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1421 | + ); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1422 | 1422 | $imagick->writeImage($vignette); |
| 1423 | 1423 | |
| 1424 | 1424 | if (!@file_exists($vignette)) { |
@@ -1427,7 +1427,7 @@ discard block |
||
| 1427 | 1427 | return; |
| 1428 | 1428 | } |
| 1429 | 1429 | // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
| 1430 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1430 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1431 | 1431 | } |
| 1432 | 1432 | |
| 1433 | 1433 | // netpbm |
@@ -1438,11 +1438,11 @@ discard block |
||
| 1438 | 1438 | if (_PNMSCALE_COMMAND == '') { |
| 1439 | 1439 | return; |
| 1440 | 1440 | } |
| 1441 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1441 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1442 | 1442 | $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
| 1443 | 1443 | if ($format == 'jpg') { |
| 1444 | 1444 | $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
| 1445 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1445 | + exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1446 | 1446 | if (!($s = @filesize($vignette))) { |
| 1447 | 1447 | spip_unlink($vignette); |
| 1448 | 1448 | } |
@@ -1454,7 +1454,7 @@ discard block |
||
| 1454 | 1454 | } else { |
| 1455 | 1455 | if ($format == 'gif') { |
| 1456 | 1456 | $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
| 1457 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1457 | + exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1458 | 1458 | if (!($s = @filesize($vignette))) { |
| 1459 | 1459 | spip_unlink($vignette); |
| 1460 | 1460 | } |
@@ -1466,7 +1466,7 @@ discard block |
||
| 1466 | 1466 | } else { |
| 1467 | 1467 | if ($format == 'png') { |
| 1468 | 1468 | $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
| 1469 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1469 | + exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1470 | 1470 | if (!($s = @filesize($vignette))) { |
| 1471 | 1471 | spip_unlink($vignette); |
| 1472 | 1472 | } |
@@ -1488,7 +1488,7 @@ discard block |
||
| 1488 | 1488 | return; |
| 1489 | 1489 | } |
| 1490 | 1490 | if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
| 1491 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1491 | + spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels'); |
|
| 1492 | 1492 | |
| 1493 | 1493 | return; |
| 1494 | 1494 | } |
@@ -1790,7 +1790,7 @@ discard block |
||
| 1790 | 1790 | // de l'image, de facon a tromper le cache du navigateur |
| 1791 | 1791 | // quand on fait supprimer/reuploader un logo |
| 1792 | 1792 | // (pas de filemtime si SAFE MODE) |
| 1793 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1793 | + $date = test_espace_prive() ? ('?'.$date) : ''; |
|
| 1794 | 1794 | |
| 1795 | 1795 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1796 | 1796 | } |
@@ -1868,9 +1868,9 @@ discard block |
||
| 1868 | 1868 | $b = $argb['blue']; |
| 1869 | 1869 | |
| 1870 | 1870 | if ($bpp[$key] == 32) { |
| 1871 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1871 | + $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a); |
|
| 1872 | 1872 | } elseif ($bpp[$key] === 24) { |
| 1873 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1873 | + $icXOR[$key] .= chr($b).chr($g).chr($r); |
|
| 1874 | 1874 | } |
| 1875 | 1875 | |
| 1876 | 1876 | if ($a < 128) { |
@@ -1897,48 +1897,48 @@ discard block |
||
| 1897 | 1897 | |
| 1898 | 1898 | // BITMAPINFOHEADER - 40 bytes |
| 1899 | 1899 | $BitmapInfoHeader[$key] = ''; |
| 1900 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1901 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1900 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1901 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1902 | 1902 | // The biHeight member specifies the combined |
| 1903 | 1903 | // height of the XOR and AND masks. |
| 1904 | 1904 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
| 1905 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1906 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1907 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1908 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1909 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1910 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1911 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1912 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1905 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1906 | + $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount; |
|
| 1907 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1908 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1909 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1910 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1911 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1912 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1913 | 1913 | } |
| 1914 | 1914 | |
| 1915 | 1915 | |
| 1916 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1917 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1918 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1916 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1917 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1918 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1919 | 1919 | |
| 1920 | 1920 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
| 1921 | 1921 | foreach (array_keys($gd_image_array) as $key) { |
| 1922 | 1922 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
| 1923 | 1923 | |
| 1924 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1925 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1926 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1927 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1924 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1925 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1926 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1927 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1928 | 1928 | |
| 1929 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1930 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1929 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1930 | + $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel |
|
| 1931 | 1931 | |
| 1932 | 1932 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
| 1933 | 1933 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1934 | 1934 | $dwBytesInRes, |
| 1935 | 1935 | 4 |
| 1936 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1936 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1937 | 1937 | |
| 1938 | 1938 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1939 | 1939 | $dwImageOffset, |
| 1940 | 1940 | 4 |
| 1941 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1941 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1942 | 1942 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
| 1943 | 1943 | $dwImageOffset += strlen($icXOR[$key]); |
| 1944 | 1944 | $dwImageOffset += strlen($icAND[$key]); |
@@ -537,8 +537,7 @@ discard block |
||
| 537 | 537 | process_image_svg_identite($ret); |
| 538 | 538 | $ret['creer'] = false; |
| 539 | 539 | } |
| 540 | - } |
|
| 541 | - else { |
|
| 540 | + } else { |
|
| 542 | 541 | if (!function_exists($ret['fonction_imagecreatefrom'])) { |
| 543 | 542 | return false; |
| 544 | 543 | } |
@@ -1356,9 +1355,7 @@ discard block |
||
| 1356 | 1355 | if ($srcWidth && $srcWidth <= $maxWidth && $srcHeight <= $maxHeight) { |
| 1357 | 1356 | $vignette = $destination . '.' . $format; |
| 1358 | 1357 | @copy($image, $vignette); |
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1358 | + } elseif ($valeurs['format_source'] === 'svg') { |
|
| 1362 | 1359 | include_spip('inc/svg'); |
| 1363 | 1360 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1364 | 1361 | $format_sortie = 'svg'; |
@@ -1793,8 +1790,7 @@ discard block |
||
| 1793 | 1790 | $date = test_espace_prive() ? ('?' . $date) : ''; |
| 1794 | 1791 | |
| 1795 | 1792 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1796 | - } |
|
| 1797 | - else { |
|
| 1793 | + } else { |
|
| 1798 | 1794 | # BMP, tiff ... les redacteurs osent tout! |
| 1799 | 1795 | return $img; |
| 1800 | 1796 | } |
@@ -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 | /** |
@@ -39,18 +39,18 @@ discard block |
||
| 39 | 39 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 40 | 40 | */ |
| 41 | 41 | function find_langs_in_path($file, $dirname = 'lang') { |
| 42 | - static $dirs = []; |
|
| 43 | - $liste = []; |
|
| 44 | - foreach (creer_chemin() as $dir) { |
|
| 45 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 46 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 47 | - } |
|
| 48 | - if ($dirs[$a] && is_readable($a .= $file)) { |
|
| 49 | - $liste[] = $a; |
|
| 50 | - } |
|
| 51 | - } |
|
| 42 | + static $dirs = []; |
|
| 43 | + $liste = []; |
|
| 44 | + foreach (creer_chemin() as $dir) { |
|
| 45 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 46 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 47 | + } |
|
| 48 | + if ($dirs[$a] && is_readable($a .= $file)) { |
|
| 49 | + $liste[] = $a; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - return array_reverse($liste); |
|
| 53 | + return array_reverse($liste); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | /** |
@@ -65,23 +65,23 @@ discard block |
||
| 65 | 65 | * Liste des fichiers touvés pour ce module et cette langue. |
| 66 | 66 | **/ |
| 67 | 67 | function chercher_module_lang($module, $lang = '') { |
| 68 | - if ($lang) { |
|
| 69 | - $lang = '_' . $lang; |
|
| 70 | - } |
|
| 68 | + if ($lang) { |
|
| 69 | + $lang = '_' . $lang; |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 73 | - if ( |
|
| 74 | - $f = ($module == 'local' |
|
| 75 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 76 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 77 | - ) { |
|
| 78 | - return is_array($f) ? $f : [$f]; |
|
| 79 | - } |
|
| 72 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 73 | + if ( |
|
| 74 | + $f = ($module == 'local' |
|
| 75 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 76 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 77 | + ) { |
|
| 78 | + return is_array($f) ? $f : [$f]; |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 82 | - return ($module == 'local' || strpos($module, '/')) |
|
| 83 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 84 | - : false; |
|
| 81 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 82 | + return ($module == 'local' || strpos($module, '/')) |
|
| 83 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 84 | + : false; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -103,33 +103,33 @@ discard block |
||
| 103 | 103 | * @return void |
| 104 | 104 | **/ |
| 105 | 105 | function charger_langue($lang, $module = 'spip') { |
| 106 | - static $langs = []; |
|
| 107 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 108 | - if (!isset($langs[$lang])) { |
|
| 109 | - $langs[$lang] = []; |
|
| 110 | - if ($lang) { |
|
| 111 | - $langs[$lang][] = $lang; |
|
| 112 | - if (str_contains($lang, '_')) { |
|
| 113 | - $l = explode('_', $lang); |
|
| 114 | - $langs[$lang][] = reset($l); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 118 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 119 | - } |
|
| 120 | - foreach ($langs[$lang] as $l) { |
|
| 121 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 122 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 123 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 124 | - surcharger_langue($fichiers_lang); |
|
| 125 | - if ($l !== $lang) { |
|
| 126 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 127 | - } |
|
| 128 | - $GLOBALS['lang_' . $var] = $l; |
|
| 129 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 130 | - break; |
|
| 131 | - } |
|
| 132 | - } |
|
| 106 | + static $langs = []; |
|
| 107 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 108 | + if (!isset($langs[$lang])) { |
|
| 109 | + $langs[$lang] = []; |
|
| 110 | + if ($lang) { |
|
| 111 | + $langs[$lang][] = $lang; |
|
| 112 | + if (str_contains($lang, '_')) { |
|
| 113 | + $l = explode('_', $lang); |
|
| 114 | + $langs[$lang][] = reset($l); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 118 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 119 | + } |
|
| 120 | + foreach ($langs[$lang] as $l) { |
|
| 121 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 122 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 123 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 124 | + surcharger_langue($fichiers_lang); |
|
| 125 | + if ($l !== $lang) { |
|
| 126 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 127 | + } |
|
| 128 | + $GLOBALS['lang_' . $var] = $l; |
|
| 129 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 130 | + break; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
@@ -142,21 +142,21 @@ discard block |
||
| 142 | 142 | * @return array<string, string> |
| 143 | 143 | */ |
| 144 | 144 | function lire_fichier_langue(string $fichier): array { |
| 145 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 146 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 147 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 148 | - $idx_lang = include $fichier; |
|
| 149 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 150 | - if (!is_array($idx_lang)) { |
|
| 151 | - if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 152 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 153 | - } else { |
|
| 154 | - $idx_lang = []; |
|
| 155 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 156 | - } |
|
| 157 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 158 | - } |
|
| 159 | - return $idx_lang; |
|
| 145 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 146 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 147 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 148 | + $idx_lang = include $fichier; |
|
| 149 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 150 | + if (!is_array($idx_lang)) { |
|
| 151 | + if (isset($GLOBALS[$idx_lang_tmp]) && is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 152 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 153 | + } else { |
|
| 154 | + $idx_lang = []; |
|
| 155 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 156 | + } |
|
| 157 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 158 | + } |
|
| 159 | + return $idx_lang; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -176,29 +176,29 @@ discard block |
||
| 176 | 176 | * Liste des chemins de fichiers de langue à surcharger. |
| 177 | 177 | **/ |
| 178 | 178 | function surcharger_langue($fichiers) { |
| 179 | - static $surcharges = []; |
|
| 180 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 181 | - return; |
|
| 182 | - } |
|
| 179 | + static $surcharges = []; |
|
| 180 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 181 | + return; |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - if (!is_array($fichiers)) { |
|
| 185 | - $fichiers = [$fichiers]; |
|
| 186 | - } |
|
| 187 | - if ($fichiers === []) { |
|
| 188 | - return; |
|
| 189 | - } |
|
| 190 | - foreach ($fichiers as $fichier) { |
|
| 191 | - if (!isset($surcharges[$fichier])) { |
|
| 192 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 193 | - } |
|
| 194 | - if (is_array($surcharges[$fichier])) { |
|
| 195 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 196 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 197 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 198 | - $surcharges[$fichier] |
|
| 199 | - ); |
|
| 200 | - } |
|
| 201 | - } |
|
| 184 | + if (!is_array($fichiers)) { |
|
| 185 | + $fichiers = [$fichiers]; |
|
| 186 | + } |
|
| 187 | + if ($fichiers === []) { |
|
| 188 | + return; |
|
| 189 | + } |
|
| 190 | + foreach ($fichiers as $fichier) { |
|
| 191 | + if (!isset($surcharges[$fichier])) { |
|
| 192 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 193 | + } |
|
| 194 | + if (is_array($surcharges[$fichier])) { |
|
| 195 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 196 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 197 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 198 | + $surcharges[$fichier] |
|
| 199 | + ); |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | /** |
@@ -239,99 +239,99 @@ discard block |
||
| 239 | 239 | * - Description : traduction et description (texte, module, langue) |
| 240 | 240 | **/ |
| 241 | 241 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 242 | - static $deja_vu = []; |
|
| 243 | - static $local = []; |
|
| 242 | + static $deja_vu = []; |
|
| 243 | + static $local = []; |
|
| 244 | 244 | |
| 245 | - if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') { |
|
| 246 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 247 | - } |
|
| 245 | + if (isset($deja_vu[$lang][$ori]) && _request('var_mode') != 'traduction') { |
|
| 246 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 250 | - if (strpos($ori, ':')) { |
|
| 251 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 252 | - $modules = explode('|', $modules); |
|
| 253 | - $ori_complet = $ori; |
|
| 254 | - } else { |
|
| 255 | - $modules = ['spip', 'ecrire']; |
|
| 256 | - $code = $ori; |
|
| 257 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 258 | - } |
|
| 249 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 250 | + if (strpos($ori, ':')) { |
|
| 251 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 252 | + $modules = explode('|', $modules); |
|
| 253 | + $ori_complet = $ori; |
|
| 254 | + } else { |
|
| 255 | + $modules = ['spip', 'ecrire']; |
|
| 256 | + $code = $ori; |
|
| 257 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - $desc = new Description(); |
|
| 260 | + $desc = new Description(); |
|
| 261 | 261 | |
| 262 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 263 | - foreach ($modules as $module) { |
|
| 264 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 262 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 263 | + foreach ($modules as $module) { |
|
| 264 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 265 | 265 | |
| 266 | - if (empty($GLOBALS[$var])) { |
|
| 267 | - charger_langue($lang, $module); |
|
| 268 | - // surcharges persos -- on cherche |
|
| 269 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 270 | - if (!isset($local['local_' . $lang])) { |
|
| 271 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 272 | - $GLOBALS['idx_lang'] = $var; |
|
| 273 | - // ... (lang/)local_xx.php |
|
| 274 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 275 | - } |
|
| 276 | - if ($local['local_' . $lang]) { |
|
| 277 | - surcharger_langue($local['local_' . $lang]); |
|
| 278 | - } |
|
| 279 | - // ... puis (lang/)local.php |
|
| 280 | - if (!isset($local['local'])) { |
|
| 281 | - $local['local'] = chercher_module_lang('local'); |
|
| 282 | - } |
|
| 283 | - if ($local['local']) { |
|
| 284 | - surcharger_langue($local['local']); |
|
| 285 | - } |
|
| 286 | - } |
|
| 266 | + if (empty($GLOBALS[$var])) { |
|
| 267 | + charger_langue($lang, $module); |
|
| 268 | + // surcharges persos -- on cherche |
|
| 269 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 270 | + if (!isset($local['local_' . $lang])) { |
|
| 271 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 272 | + $GLOBALS['idx_lang'] = $var; |
|
| 273 | + // ... (lang/)local_xx.php |
|
| 274 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 275 | + } |
|
| 276 | + if ($local['local_' . $lang]) { |
|
| 277 | + surcharger_langue($local['local_' . $lang]); |
|
| 278 | + } |
|
| 279 | + // ... puis (lang/)local.php |
|
| 280 | + if (!isset($local['local'])) { |
|
| 281 | + $local['local'] = chercher_module_lang('local'); |
|
| 282 | + } |
|
| 283 | + if ($local['local']) { |
|
| 284 | + surcharger_langue($local['local']); |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - if (isset($GLOBALS[$var][$code])) { |
|
| 289 | - $desc->code = $code; |
|
| 290 | - $desc->module = $module; |
|
| 291 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 292 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 293 | - break; |
|
| 294 | - } |
|
| 295 | - } |
|
| 288 | + if (isset($GLOBALS[$var][$code])) { |
|
| 289 | + $desc->code = $code; |
|
| 290 | + $desc->module = $module; |
|
| 291 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 292 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 293 | + break; |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - if (!$desc->corrections) { |
|
| 298 | - $desc->corrections = true; |
|
| 299 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 300 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 301 | - if ( |
|
| 302 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 303 | - && $lang !== _LANGUE_PAR_DEFAUT |
|
| 304 | - ) { |
|
| 305 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 306 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 307 | - } else { |
|
| 308 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 309 | - } |
|
| 310 | - } |
|
| 297 | + if (!$desc->corrections) { |
|
| 298 | + $desc->corrections = true; |
|
| 299 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 300 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 301 | + if ( |
|
| 302 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 303 | + && $lang !== _LANGUE_PAR_DEFAUT |
|
| 304 | + ) { |
|
| 305 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 306 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 307 | + } else { |
|
| 308 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | 311 | |
| 312 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 313 | - if ($desc->texte && str_starts_with($desc->texte, '<')) { |
|
| 314 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 315 | - } |
|
| 312 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 313 | + if ($desc->texte && str_starts_with($desc->texte, '<')) { |
|
| 314 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 315 | + } |
|
| 316 | 316 | |
| 317 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 318 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 319 | - if ( |
|
| 320 | - (!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 321 | - && preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 322 | - ) { |
|
| 323 | - include_spip('inc/charsets'); |
|
| 324 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 325 | - } |
|
| 326 | - } |
|
| 317 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 318 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 319 | + if ( |
|
| 320 | + (!isset($GLOBALS['meta']['charset']) || $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 321 | + && preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 322 | + ) { |
|
| 323 | + include_spip('inc/charsets'); |
|
| 324 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 325 | + } |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - if (_request('var_mode') == 'traduction') { |
|
| 329 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 330 | - } else { |
|
| 331 | - $deja_vu[$lang][$ori] = $desc; |
|
| 332 | - } |
|
| 328 | + if (_request('var_mode') == 'traduction') { |
|
| 329 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 330 | + } else { |
|
| 331 | + $deja_vu[$lang][$ori] = $desc; |
|
| 332 | + } |
|
| 333 | 333 | |
| 334 | - return $raw ? $desc : $desc->texte; |
|
| 334 | + return $raw ? $desc : $desc->texte; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -343,23 +343,23 @@ discard block |
||
| 343 | 343 | * @return Description |
| 344 | 344 | */ |
| 345 | 345 | function definir_details_traduction($desc, $modules) { |
| 346 | - if (!$desc->mode && $desc->texte) { |
|
| 347 | - // ne pas modifier 2 fois l'affichage |
|
| 348 | - $desc->mode = 'traduction'; |
|
| 349 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 350 | - $desc->texte = '<span ' |
|
| 351 | - . 'lang=' . $desc->langue |
|
| 352 | - . ' class=' . $classe |
|
| 353 | - . ' data-module=' . $desc->module |
|
| 354 | - . ' data-code=' . $desc->code |
|
| 355 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 356 | - . $desc->texte |
|
| 357 | - . '</span>'; |
|
| 358 | - $desc->texte = str_replace( |
|
| 359 | - ["$desc->module:", "$desc->module|"], |
|
| 360 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 361 | - $desc->texte |
|
| 362 | - ); |
|
| 363 | - } |
|
| 364 | - return $desc; |
|
| 346 | + if (!$desc->mode && $desc->texte) { |
|
| 347 | + // ne pas modifier 2 fois l'affichage |
|
| 348 | + $desc->mode = 'traduction'; |
|
| 349 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 350 | + $desc->texte = '<span ' |
|
| 351 | + . 'lang=' . $desc->langue |
|
| 352 | + . ' class=' . $classe |
|
| 353 | + . ' data-module=' . $desc->module |
|
| 354 | + . ' data-code=' . $desc->code |
|
| 355 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 356 | + . $desc->texte |
|
| 357 | + . '</span>'; |
|
| 358 | + $desc->texte = str_replace( |
|
| 359 | + ["$desc->module:", "$desc->module|"], |
|
| 360 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 361 | + $desc->texte |
|
| 362 | + ); |
|
| 363 | + } |
|
| 364 | + return $desc; |
|
| 365 | 365 | } |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | static $dirs = []; |
| 43 | 43 | $liste = []; |
| 44 | 44 | foreach (creer_chemin() as $dir) { |
| 45 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | + if (!isset($dirs[$a = $dir.$dirname])) { |
|
| 46 | 46 | $dirs[$a] = (is_dir($a) || !$a); |
| 47 | 47 | } |
| 48 | 48 | if ($dirs[$a] && is_readable($a .= $file)) { |
@@ -66,21 +66,21 @@ discard block |
||
| 66 | 66 | **/ |
| 67 | 67 | function chercher_module_lang($module, $lang = '') { |
| 68 | 68 | if ($lang) { |
| 69 | - $lang = '_' . $lang; |
|
| 69 | + $lang = '_'.$lang; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
| 73 | 73 | if ( |
| 74 | 74 | $f = ($module == 'local' |
| 75 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 76 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 75 | + ? find_in_path($module.$lang.'.php', 'lang/') |
|
| 76 | + : find_langs_in_path($module.$lang.'.php', 'lang/')) |
|
| 77 | 77 | ) { |
| 78 | 78 | return is_array($f) ? $f : [$f]; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | // 2) directement dans le chemin (old style, uniquement pour local) |
| 82 | 82 | return ($module == 'local' || strpos($module, '/')) |
| 83 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 83 | + ? (($f = find_in_path($module.$lang.'.php')) ? [$f] : false) |
|
| 84 | 84 | : false; |
| 85 | 85 | } |
| 86 | 86 | |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | **/ |
| 105 | 105 | function charger_langue($lang, $module = 'spip') { |
| 106 | 106 | static $langs = []; |
| 107 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 107 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 108 | 108 | if (!isset($langs[$lang])) { |
| 109 | 109 | $langs[$lang] = []; |
| 110 | 110 | if ($lang) { |
@@ -119,13 +119,13 @@ discard block |
||
| 119 | 119 | } |
| 120 | 120 | foreach ($langs[$lang] as $l) { |
| 121 | 121 | if ($fichiers_lang = chercher_module_lang($module, $l)) { |
| 122 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 122 | + $GLOBALS['idx_lang'] = 'i18n_'.$module.'_'.$l; |
|
| 123 | 123 | $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
| 124 | 124 | surcharger_langue($fichiers_lang); |
| 125 | 125 | if ($l !== $lang) { |
| 126 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 126 | + $GLOBALS[$var] = &$GLOBALS['i18n_'.$module.'_'.$l]; |
|
| 127 | 127 | } |
| 128 | - $GLOBALS['lang_' . $var] = $l; |
|
| 128 | + $GLOBALS['lang_'.$var] = $l; |
|
| 129 | 129 | #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
| 130 | 130 | break; |
| 131 | 131 | } |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | */ |
| 144 | 144 | function lire_fichier_langue(string $fichier): array { |
| 145 | 145 | $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
| 146 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 146 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang').'@temporaire'; |
|
| 147 | 147 | $GLOBALS['idx_lang'] = $idx_lang_tmp; |
| 148 | 148 | $idx_lang = include $fichier; |
| 149 | 149 | $GLOBALS['idx_lang'] = $idx_lang_before; |
@@ -254,27 +254,27 @@ discard block |
||
| 254 | 254 | } else { |
| 255 | 255 | $modules = ['spip', 'ecrire']; |
| 256 | 256 | $code = $ori; |
| 257 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 257 | + $ori_complet = implode('|', $modules).':'.$ori; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | $desc = new Description(); |
| 261 | 261 | |
| 262 | 262 | // parcourir tous les modules jusqu'a ce qu'on trouve |
| 263 | 263 | foreach ($modules as $module) { |
| 264 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 264 | + $var = 'i18n_'.$module.'_'.$lang; |
|
| 265 | 265 | |
| 266 | 266 | if (empty($GLOBALS[$var])) { |
| 267 | 267 | charger_langue($lang, $module); |
| 268 | 268 | // surcharges persos -- on cherche |
| 269 | 269 | // (lang/)local_xx.php et/ou (lang/)local.php ... |
| 270 | - if (!isset($local['local_' . $lang])) { |
|
| 270 | + if (!isset($local['local_'.$lang])) { |
|
| 271 | 271 | // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
| 272 | 272 | $GLOBALS['idx_lang'] = $var; |
| 273 | 273 | // ... (lang/)local_xx.php |
| 274 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 274 | + $local['local_'.$lang] = chercher_module_lang('local', $lang); |
|
| 275 | 275 | } |
| 276 | - if ($local['local_' . $lang]) { |
|
| 277 | - surcharger_langue($local['local_' . $lang]); |
|
| 276 | + if ($local['local_'.$lang]) { |
|
| 277 | + surcharger_langue($local['local_'.$lang]); |
|
| 278 | 278 | } |
| 279 | 279 | // ... puis (lang/)local.php |
| 280 | 280 | if (!isset($local['local'])) { |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | if (isset($GLOBALS[$var][$code])) { |
| 289 | 289 | $desc->code = $code; |
| 290 | 290 | $desc->module = $module; |
| 291 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 291 | + $desc->langue = $GLOBALS['lang_'.$var] ?? $lang; |
|
| 292 | 292 | $desc->texte = $GLOBALS[$var][$code]; |
| 293 | 293 | break; |
| 294 | 294 | } |
@@ -346,13 +346,13 @@ discard block |
||
| 346 | 346 | if (!$desc->mode && $desc->texte) { |
| 347 | 347 | // ne pas modifier 2 fois l'affichage |
| 348 | 348 | $desc->mode = 'traduction'; |
| 349 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 349 | + $classe = 'debug-traduction'.($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 350 | 350 | $desc->texte = '<span ' |
| 351 | - . 'lang=' . $desc->langue |
|
| 352 | - . ' class=' . $classe |
|
| 353 | - . ' data-module=' . $desc->module |
|
| 354 | - . ' data-code=' . $desc->code |
|
| 355 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 351 | + . 'lang='.$desc->langue |
|
| 352 | + . ' class='.$classe |
|
| 353 | + . ' data-module='.$desc->module |
|
| 354 | + . ' data-code='.$desc->code |
|
| 355 | + . ' title='.$modules.'('.$desc->langue.')>' |
|
| 356 | 356 | . $desc->texte |
| 357 | 357 | . '</span>'; |
| 358 | 358 | $desc->texte = str_replace( |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | |
| 12 | 12 | // |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // |
@@ -20,52 +20,52 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function produire_image_math($tex) { |
| 22 | 22 | |
| 23 | - switch ($GLOBALS['traiter_math']) { |
|
| 24 | - // Attention: mathml desactiv'e pour l'instant |
|
| 25 | - case 'mathml': |
|
| 26 | - $ext = '.xhtml'; |
|
| 27 | - $server = $GLOBALS['mathml_server']; |
|
| 28 | - break; |
|
| 29 | - case 'tex': |
|
| 30 | - $ext = '.png'; |
|
| 31 | - $server = $GLOBALS['tex_server']; |
|
| 32 | - break; |
|
| 33 | - default: |
|
| 34 | - return $tex; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | - } |
|
| 41 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - // Aller chercher l'image sur le serveur |
|
| 45 | - if (!@file_exists($fichier) && $server) { |
|
| 46 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 47 | - include_spip('inc/distant'); |
|
| 48 | - recuperer_url($url, ['file' => $fichier]); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - // Composer la reponse selon presence ou non de l'image |
|
| 53 | - $tex = entites_html($tex); |
|
| 54 | - if (@file_exists($fichier)) { |
|
| 55 | - // MathML |
|
| 56 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | - return implode('', file($fichier)); |
|
| 58 | - } // TeX |
|
| 59 | - else { |
|
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | - |
|
| 63 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | - } |
|
| 65 | - } else // pas de fichier |
|
| 66 | - { |
|
| 67 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | - } |
|
| 23 | + switch ($GLOBALS['traiter_math']) { |
|
| 24 | + // Attention: mathml desactiv'e pour l'instant |
|
| 25 | + case 'mathml': |
|
| 26 | + $ext = '.xhtml'; |
|
| 27 | + $server = $GLOBALS['mathml_server']; |
|
| 28 | + break; |
|
| 29 | + case 'tex': |
|
| 30 | + $ext = '.png'; |
|
| 31 | + $server = $GLOBALS['tex_server']; |
|
| 32 | + break; |
|
| 33 | + default: |
|
| 34 | + return $tex; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | + } |
|
| 41 | + $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + // Aller chercher l'image sur le serveur |
|
| 45 | + if (!@file_exists($fichier) && $server) { |
|
| 46 | + spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 47 | + include_spip('inc/distant'); |
|
| 48 | + recuperer_url($url, ['file' => $fichier]); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + // Composer la reponse selon presence ou non de l'image |
|
| 53 | + $tex = entites_html($tex); |
|
| 54 | + if (@file_exists($fichier)) { |
|
| 55 | + // MathML |
|
| 56 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | + return implode('', file($fichier)); |
|
| 58 | + } // TeX |
|
| 59 | + else { |
|
| 60 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | + |
|
| 63 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | + } |
|
| 65 | + } else // pas de fichier |
|
| 66 | + { |
|
| 67 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -100,52 +100,52 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 102 | 102 | |
| 103 | - $texte_a_voir = $letexte; |
|
| 104 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | - $fin = strlen($texte_a_voir); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | - $texte_milieu = substr( |
|
| 111 | - $texte_a_voir, |
|
| 112 | - $debut + strlen('<math>'), |
|
| 113 | - $fin - $debut - strlen('<math>') |
|
| 114 | - ); |
|
| 115 | - $texte_fin = substr( |
|
| 116 | - $texte_a_voir, |
|
| 117 | - $fin + strlen('</math>'), |
|
| 118 | - strlen($texte_a_voir) |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | - $expression = $regs[1]; |
|
| 124 | - if ($defaire_amp) { |
|
| 125 | - $expression = str_replace('&', '&', $expression); |
|
| 126 | - } |
|
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | - . code_echappement($echap, $source) |
|
| 131 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Les simples $x^2$ en mode 'span' |
|
| 135 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | - $expression = $regs[1]; |
|
| 137 | - if ($defaire_amp) { |
|
| 138 | - $expression = str_replace('&', '&', $expression); |
|
| 139 | - } |
|
| 140 | - $echap = produire_image_math($expression); |
|
| 141 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | - . code_echappement($echap, $source) |
|
| 144 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $texte_a_voir; |
|
| 103 | + $texte_a_voir = $letexte; |
|
| 104 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | + $fin = strlen($texte_a_voir); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | + $texte_milieu = substr( |
|
| 111 | + $texte_a_voir, |
|
| 112 | + $debut + strlen('<math>'), |
|
| 113 | + $fin - $debut - strlen('<math>') |
|
| 114 | + ); |
|
| 115 | + $texte_fin = substr( |
|
| 116 | + $texte_a_voir, |
|
| 117 | + $fin + strlen('</math>'), |
|
| 118 | + strlen($texte_a_voir) |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | + $expression = $regs[1]; |
|
| 124 | + if ($defaire_amp) { |
|
| 125 | + $expression = str_replace('&', '&', $expression); |
|
| 126 | + } |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | + . code_echappement($echap, $source) |
|
| 131 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Les simples $x^2$ en mode 'span' |
|
| 135 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | + $expression = $regs[1]; |
|
| 137 | + if ($defaire_amp) { |
|
| 138 | + $expression = str_replace('&', '&', $expression); |
|
| 139 | + } |
|
| 140 | + $echap = produire_image_math($expression); |
|
| 141 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | + . code_echappement($echap, $source) |
|
| 144 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $texte_a_voir; |
|
| 151 | 151 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 39 | 39 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 40 | 40 | } |
| 41 | - $fichier = $dir_tex . md5(trim($tex)) . $ext; |
|
| 41 | + $fichier = $dir_tex.md5(trim($tex)).$ext; |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | // Aller chercher l'image sur le serveur |
| 45 | 45 | if (!@file_exists($fichier) && $server) { |
| 46 | - spip_log($url = $server . '?' . rawurlencode($tex)); |
|
| 46 | + spip_log($url = $server.'?'.rawurlencode($tex)); |
|
| 47 | 47 | include_spip('inc/distant'); |
| 48 | 48 | recuperer_url($url, ['file' => $fichier]); |
| 49 | 49 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | return implode('', file($fichier)); |
| 58 | 58 | } // TeX |
| 59 | 59 | else { |
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 60 | + [,,, $size] = @spip_getimagesize($fichier); |
|
| 61 | 61 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 62 | 62 | |
| 63 | 63 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if ($defaire_amp) { |
| 125 | 125 | $expression = str_replace('&', '&', $expression); |
| 126 | 126 | } |
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 128 | 128 | $pos = strpos($texte_milieu, (string) $regs[0]); |
| 129 | 129 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 130 | 130 | . code_echappement($echap, $source) |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 147 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $texte_a_voir; |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/config'); |
@@ -31,31 +31,31 @@ discard block |
||
| 31 | 31 | * @return array|false |
| 32 | 32 | */ |
| 33 | 33 | function cvtconf_formulaire_charger($flux) { |
| 34 | - if ( |
|
| 35 | - ($form = $flux['args']['form']) |
|
| 36 | - && str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 37 | - ) { |
|
| 38 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 39 | - include_spip('inc/autoriser'); |
|
| 40 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 41 | - return false; |
|
| 42 | - } |
|
| 34 | + if ( |
|
| 35 | + ($form = $flux['args']['form']) |
|
| 36 | + && str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 37 | + ) { |
|
| 38 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 39 | + include_spip('inc/autoriser'); |
|
| 40 | + if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 41 | + return false; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 45 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 46 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 47 | - $flux['data']['editable'] = true; |
|
| 48 | - if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 49 | - if (!_AJAX) { |
|
| 50 | - var_dump($flux['data']); |
|
| 51 | - } |
|
| 52 | - // reinjecter pour la trace au traitement |
|
| 53 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 54 | - } |
|
| 55 | - } |
|
| 56 | - } |
|
| 44 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 45 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 46 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 47 | + $flux['data']['editable'] = true; |
|
| 48 | + if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 49 | + if (!_AJAX) { |
|
| 50 | + var_dump($flux['data']); |
|
| 51 | + } |
|
| 52 | + // reinjecter pour la trace au traitement |
|
| 53 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 54 | + } |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return $flux; |
|
| 58 | + return $flux; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | * @return array |
| 66 | 66 | */ |
| 67 | 67 | function cvtconf_formulaire_traiter($flux) { |
| 68 | - if ( |
|
| 69 | - ($form = $flux['args']['form']) |
|
| 70 | - && str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 71 | - && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 72 | - ) { |
|
| 73 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 74 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | - } |
|
| 68 | + if ( |
|
| 69 | + ($form = $flux['args']['form']) |
|
| 70 | + && str_starts_with($form, 'configurer_') // un #FORMULAIRE_CONFIGURER_XXX |
|
| 71 | + && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 72 | + ) { |
|
| 73 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 74 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - return $flux; |
|
| 77 | + return $flux; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -90,32 +90,32 @@ discard block |
||
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | 92 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 93 | - $valeurs = []; |
|
| 94 | - // charger les valeurs |
|
| 95 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 96 | - // qui prend alors la main sur l'auto detection |
|
| 97 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 98 | - $valeurs = $charger_valeurs(...$args); |
|
| 99 | - } |
|
| 100 | - $valeurs = pipeline( |
|
| 101 | - 'formulaire_charger', |
|
| 102 | - [ |
|
| 103 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 104 | - 'data' => $valeurs |
|
| 105 | - ] |
|
| 106 | - ); |
|
| 107 | - // ne pas stocker editable ! |
|
| 108 | - unset($valeurs['editable']); |
|
| 93 | + $valeurs = []; |
|
| 94 | + // charger les valeurs |
|
| 95 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 96 | + // qui prend alors la main sur l'auto detection |
|
| 97 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 98 | + $valeurs = $charger_valeurs(...$args); |
|
| 99 | + } |
|
| 100 | + $valeurs = pipeline( |
|
| 101 | + 'formulaire_charger', |
|
| 102 | + [ |
|
| 103 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 104 | + 'data' => $valeurs |
|
| 105 | + ] |
|
| 106 | + ); |
|
| 107 | + // ne pas stocker editable ! |
|
| 108 | + unset($valeurs['editable']); |
|
| 109 | 109 | |
| 110 | - // recuperer les valeurs postees |
|
| 111 | - $store = []; |
|
| 112 | - foreach ($valeurs as $k => $v) { |
|
| 113 | - if (!str_starts_with($k, '_')) { |
|
| 114 | - $store[$k] = _request($k); |
|
| 115 | - } |
|
| 116 | - } |
|
| 110 | + // recuperer les valeurs postees |
|
| 111 | + $store = []; |
|
| 112 | + foreach ($valeurs as $k => $v) { |
|
| 113 | + if (!str_starts_with($k, '_')) { |
|
| 114 | + $store[$k] = _request($k); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 118 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -131,31 +131,31 @@ discard block |
||
| 131 | 131 | * @return array |
| 132 | 132 | */ |
| 133 | 133 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 134 | - // stocker en base |
|
| 135 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 136 | - $casier = substr($form, 11); |
|
| 137 | - $table = 'meta'; |
|
| 138 | - $prefixe = ''; |
|
| 139 | - $stockage = ''; |
|
| 134 | + // stocker en base |
|
| 135 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 136 | + $casier = substr($form, 11); |
|
| 137 | + $table = 'meta'; |
|
| 138 | + $prefixe = ''; |
|
| 139 | + $stockage = ''; |
|
| 140 | 140 | |
| 141 | - if (isset($valeurs['_meta_casier'])) { |
|
| 142 | - $casier = $valeurs['_meta_casier']; |
|
| 143 | - } |
|
| 144 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 145 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 146 | - } |
|
| 147 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 148 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | - } |
|
| 141 | + if (isset($valeurs['_meta_casier'])) { |
|
| 142 | + $casier = $valeurs['_meta_casier']; |
|
| 143 | + } |
|
| 144 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 145 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 146 | + } |
|
| 147 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 148 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | + } |
|
| 150 | 150 | |
| 151 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 152 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 153 | - if (isset($valeurs['_meta_table'])) { |
|
| 154 | - $table = $valeurs['_meta_table']; |
|
| 155 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 156 | - } |
|
| 151 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 152 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 153 | + if (isset($valeurs['_meta_table'])) { |
|
| 154 | + $table = $valeurs['_meta_table']; |
|
| 155 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 158 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | /** |
@@ -166,49 +166,49 @@ discard block |
||
| 166 | 166 | * @return array |
| 167 | 167 | */ |
| 168 | 168 | function cvtconf_formulaires_configurer_recense($form) { |
| 169 | - $contenu = null; |
|
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 169 | + $contenu = null; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | - && lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | + && lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - ($n = extraire_attribut($b, 'name')) |
|
| 193 | - && preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | - && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - && extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (str_starts_with($r[1], '_meta_')) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + ($n = extraire_attribut($b, 'name')) |
|
| 193 | + && preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | + && !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + && extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (str_starts_with($r[1], '_meta_')) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach (array_keys($valeurs) as $k) { |
|
| 265 | - if (!str_starts_with($k, '_')) { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach (array_keys($valeurs) as $k) { |
|
| 265 | + if (!str_starts_with($k, '_')) { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | ) { |
| 38 | 38 | // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
| 39 | 39 | include_spip('inc/autoriser'); |
| 40 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 40 | + if (!autoriser('configurer', '_'.substr($form, 11))) { |
|
| 41 | 41 | return false; |
| 42 | 42 | } |
| 43 | 43 | |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | && !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
| 72 | 72 | ) { |
| 73 | 73 | $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
| 74 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 74 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true]; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | return $flux; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $prefixe = $valeurs['_meta_prefixe']; |
| 146 | 146 | } |
| 147 | 147 | if (isset($valeurs['_meta_stockage'])) { |
| 148 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 148 | + $stockage = $valeurs['_meta_stockage'].'::'; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | // si on indique juste une table, il faut vider les autres proprietes |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // sinon cas analyse du squelette |
| 173 | 173 | if ( |
| 174 | - ($f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 174 | + ($f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/')) |
|
| 175 | 175 | && lire_fichier($f, $contenu) |
| 176 | 176 | ) { |
| 177 | 177 | for ($i = 0; $i < 2; $i++) { |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | lire_metas($table); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 231 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 232 | 232 | $table = ($table) ? "/$table/" : ''; |
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/').'/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | 235 | foreach ($store as $k => $v) { |
| 236 | 236 | ecrire_config("$stockage$table$prefixe$casier$k", $v); |
| 237 | 237 | if (_request('var_mode') == 'configurer' && autoriser('webmestre')) { |
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 238 | + $trace .= "<br />table $table : ".$prefixe.$k." = $v;"; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
| 253 | 253 | |
| 254 | 254 | $table = ($table) ? "/$table/" : ''; |
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 255 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 256 | 256 | if ($casier) { |
| 257 | 257 | $meta = lire_config("$stockage$table$prefixe$casier"); |
| 258 | 258 | $prefixe = ''; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | foreach (array_keys($valeurs) as $k) { |
| 265 | 265 | if (!str_starts_with($k, '_')) { |
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe.$k] ?? null); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |