@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,92 +79,92 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = []; |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = []; |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = []; |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = []; |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if ( |
|
| 90 | - function_exists('boutons_plugins') |
|
| 91 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | - ) { |
|
| 93 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if ( |
|
| 90 | + function_exists('boutons_plugins') |
|
| 91 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | + ) { |
|
| 93 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($liste_boutons as $id => $infos) { |
|
| 97 | - $parent = ''; |
|
| 98 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | - if ( |
|
| 100 | - !isset($infos['parent']) |
|
| 101 | - or !($parent = $infos['parent']) |
|
| 102 | - or !$autorise |
|
| 103 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | - ) { |
|
| 105 | - if ( |
|
| 106 | - $parent |
|
| 107 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | - and isset($boutons_admin[$parent]) |
|
| 109 | - ) { |
|
| 110 | - if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 111 | - $boutons_admin[$parent]->sousmenu = []; |
|
| 112 | - } |
|
| 113 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 114 | - if ($position < 0) { |
|
| 115 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 116 | - } |
|
| 117 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 118 | - + [ |
|
| 119 | - $id => new Bouton( |
|
| 120 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | - $infos['titre'], // titre |
|
| 122 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 123 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 124 | - ) |
|
| 125 | - ] |
|
| 126 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 127 | - } |
|
| 128 | - if ( |
|
| 129 | - !$parent |
|
| 130 | - // provisoire, eviter les vieux boutons |
|
| 131 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 132 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 133 | - ) { |
|
| 134 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 135 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 136 | - + [ |
|
| 137 | - $id => new Bouton( |
|
| 138 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | - $infos['titre'], // titre |
|
| 140 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 141 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 142 | - ) |
|
| 143 | - ] |
|
| 144 | - + array_slice($boutons_admin, $position, 100); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - } |
|
| 148 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 96 | + foreach ($liste_boutons as $id => $infos) { |
|
| 97 | + $parent = ''; |
|
| 98 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | + if ( |
|
| 100 | + !isset($infos['parent']) |
|
| 101 | + or !($parent = $infos['parent']) |
|
| 102 | + or !$autorise |
|
| 103 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | + ) { |
|
| 105 | + if ( |
|
| 106 | + $parent |
|
| 107 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | + and isset($boutons_admin[$parent]) |
|
| 109 | + ) { |
|
| 110 | + if (!is_array($boutons_admin[$parent]->sousmenu)) { |
|
| 111 | + $boutons_admin[$parent]->sousmenu = []; |
|
| 112 | + } |
|
| 113 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 114 | + if ($position < 0) { |
|
| 115 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 116 | + } |
|
| 117 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 118 | + + [ |
|
| 119 | + $id => new Bouton( |
|
| 120 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 121 | + $infos['titre'], // titre |
|
| 122 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 123 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 124 | + ) |
|
| 125 | + ] |
|
| 126 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 127 | + } |
|
| 128 | + if ( |
|
| 129 | + !$parent |
|
| 130 | + // provisoire, eviter les vieux boutons |
|
| 131 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 132 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 133 | + ) { |
|
| 134 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 135 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 136 | + + [ |
|
| 137 | + $id => new Bouton( |
|
| 138 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 139 | + $infos['titre'], // titre |
|
| 140 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 141 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 142 | + ) |
|
| 143 | + ] |
|
| 144 | + + array_slice($boutons_admin, $position, 100); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + } |
|
| 148 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 149 | 149 | |
| 150 | - // définir les favoris et positions d’origine |
|
| 151 | - if ($boutons_admin) { |
|
| 152 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 153 | - $i = 1; |
|
| 154 | - foreach ($boutons_admin as $key => $menu) { |
|
| 155 | - $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 156 | - $menu->position = $i++; |
|
| 157 | - if ($menu->sousmenu) { |
|
| 158 | - $j = 1; |
|
| 159 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 160 | - $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 161 | - $bouton->position = $j++; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - } |
|
| 150 | + // définir les favoris et positions d’origine |
|
| 151 | + if ($boutons_admin) { |
|
| 152 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 153 | + $i = 1; |
|
| 154 | + foreach ($boutons_admin as $key => $menu) { |
|
| 155 | + $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 156 | + $menu->position = $i++; |
|
| 157 | + if ($menu->sousmenu) { |
|
| 158 | + $j = 1; |
|
| 159 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 160 | + $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 161 | + $bouton->position = $j++; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | 166 | |
| 167 | - return $boutons_admin; |
|
| 167 | + return $boutons_admin; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -176,22 +176,22 @@ discard block |
||
| 176 | 176 | * @return Bouton[] |
| 177 | 177 | */ |
| 178 | 178 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 179 | - foreach ($menus as $menu) { |
|
| 180 | - if ($menu->sousmenu) { |
|
| 181 | - $libelles = $isfavoris = $favoris = []; |
|
| 182 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 183 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 184 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 185 | - $favoris[$key] = $item->favori; |
|
| 186 | - } |
|
| 187 | - if ($avec_favoris) { |
|
| 188 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | - } else { |
|
| 190 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - return $menus; |
|
| 179 | + foreach ($menus as $menu) { |
|
| 180 | + if ($menu->sousmenu) { |
|
| 181 | + $libelles = $isfavoris = $favoris = []; |
|
| 182 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 183 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 184 | + $isfavoris[$key] = (bool)$item->favori; |
|
| 185 | + $favoris[$key] = $item->favori; |
|
| 186 | + } |
|
| 187 | + if ($avec_favoris) { |
|
| 188 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 189 | + } else { |
|
| 190 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + return $menus; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return Bouton[] |
| 203 | 203 | */ |
| 204 | 204 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 205 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 205 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 206 | 206 | } |
| 207 | 207 | |
| 208 | 208 | |
@@ -215,23 +215,23 @@ discard block |
||
| 215 | 215 | * @return string |
| 216 | 216 | */ |
| 217 | 217 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 218 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 219 | - $url = generer_url_ecrire($url, $args, true); |
|
| 220 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 221 | - // &truc=@machin@ |
|
| 222 | - // @machin@ etant remplace par _request('machin') |
|
| 223 | - $url = str_replace('&', '&', $url); |
|
| 224 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 225 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 226 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 227 | - } |
|
| 228 | - $val = _request($matches[2], $contexte); |
|
| 229 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 230 | - } |
|
| 231 | - $url = str_replace('&', '&', $url); |
|
| 232 | - } |
|
| 218 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 219 | + $url = generer_url_ecrire($url, $args, true); |
|
| 220 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 221 | + // &truc=@machin@ |
|
| 222 | + // @machin@ etant remplace par _request('machin') |
|
| 223 | + $url = str_replace('&', '&', $url); |
|
| 224 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 225 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 226 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 227 | + } |
|
| 228 | + $val = _request($matches[2], $contexte); |
|
| 229 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 230 | + } |
|
| 231 | + $url = str_replace('&', '&', $url); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - return $url; |
|
| 234 | + return $url; |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | /** |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * Code HTML du bandeau |
| 242 | 242 | */ |
| 243 | 243 | function inc_bandeau_dist() { |
| 244 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 244 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | |
@@ -250,13 +250,13 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function obtenir_menus_favoris() { |
| 253 | - if ( |
|
| 254 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 256 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 257 | - ) { |
|
| 258 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 259 | - } |
|
| 260 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 261 | - return $definir_menus_favoris(); |
|
| 253 | + if ( |
|
| 254 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 256 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 257 | + ) { |
|
| 258 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 259 | + } |
|
| 260 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 261 | + return $definir_menus_favoris(); |
|
| 262 | 262 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Affichage |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return string Code HTML |
| 26 | 26 | */ |
| 27 | 27 | function debut_grand_cadre() { |
| 28 | - return "\n<div class = 'table_page'>\n"; |
|
| 28 | + return "\n<div class = 'table_page'>\n"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return string Code HTML |
| 35 | 35 | */ |
| 36 | 36 | function fin_grand_cadre() { |
| 37 | - return "\n</div>"; |
|
| 37 | + return "\n</div>"; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Debut de la colonne de gauche |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return string Code HTML |
| 50 | 50 | */ |
| 51 | 51 | function debut_gauche() { |
| 52 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 52 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return string Code HTML |
| 59 | 59 | */ |
| 60 | 60 | function fin_gauche() { |
| 61 | - return "</div></div><br class = 'nettoyeur' />"; |
|
| 61 | + return "</div></div><br class = 'nettoyeur' />"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @return string Code HTML |
| 68 | 68 | */ |
| 69 | 69 | function creer_colonne_droite() { |
| 70 | - static $deja_colonne_droite; |
|
| 71 | - if ($deja_colonne_droite) { |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 74 | - $deja_colonne_droite = true; |
|
| 70 | + static $deja_colonne_droite; |
|
| 71 | + if ($deja_colonne_droite) { |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | + $deja_colonne_droite = true; |
|
| 75 | 75 | |
| 76 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 76 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string Code HTML |
| 83 | 83 | */ |
| 84 | 84 | function debut_droite() { |
| 85 | - return liste_objets_bloques(_request('exec')) |
|
| 86 | - . creer_colonne_droite() |
|
| 87 | - . '</div>' |
|
| 88 | - . "\n<div id='contenu'>"; |
|
| 85 | + return liste_objets_bloques(_request('exec')) |
|
| 86 | + . creer_colonne_droite() |
|
| 87 | + . '</div>' |
|
| 88 | + . "\n<div id='contenu'>"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | * Code HTML |
| 108 | 108 | **/ |
| 109 | 109 | function liste_objets_bloques($exec, $contexte = [], $auteur = null) { |
| 110 | - $res = ''; |
|
| 111 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | - include_spip('inc/drapeau_edition'); |
|
| 113 | - if (is_null($auteur)) { |
|
| 114 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | - } |
|
| 116 | - if ( |
|
| 117 | - $en_cours = trouver_objet_exec($exec) |
|
| 118 | - and $en_cours['edition'] |
|
| 119 | - and $type = $en_cours['type'] |
|
| 120 | - and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | - or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | - ) { |
|
| 123 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | - signale_edition($id, $auteur, $type); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | - if (count($objets_ouverts)) { |
|
| 130 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $res; |
|
| 110 | + $res = ''; |
|
| 111 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | + include_spip('inc/drapeau_edition'); |
|
| 113 | + if (is_null($auteur)) { |
|
| 114 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | + } |
|
| 116 | + if ( |
|
| 117 | + $en_cours = trouver_objet_exec($exec) |
|
| 118 | + and $en_cours['edition'] |
|
| 119 | + and $type = $en_cours['type'] |
|
| 120 | + and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | + or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | + ) { |
|
| 123 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | + signale_edition($id, $auteur, $type); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | + if (count($objets_ouverts)) { |
|
| 130 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $res; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -145,20 +145,20 @@ discard block |
||
| 145 | 145 | * @return string Code HTML |
| 146 | 146 | **/ |
| 147 | 147 | function fin_page() { |
| 148 | - include_spip('inc/pipelines'); |
|
| 149 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | - $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | - and ((_request('var_mode') == 'debug') |
|
| 152 | - or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | - and isset($_COOKIE['spip_admin']))); |
|
| 154 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | - . '</div>' |
|
| 157 | - . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | - . ($debug ? erreur_squelette() : '') |
|
| 159 | - . "</body></html>\n"; |
|
| 160 | - |
|
| 161 | - return f_queue($t); |
|
| 148 | + include_spip('inc/pipelines'); |
|
| 149 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | + $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | + and ((_request('var_mode') == 'debug') |
|
| 152 | + or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | + and isset($_COOKIE['spip_admin']))); |
|
| 154 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | + . '</div>' |
|
| 157 | + . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | + . ($debug ? erreur_squelette() : '') |
|
| 159 | + . "</body></html>\n"; |
|
| 160 | + |
|
| 161 | + return f_queue($t); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return string Code HTML |
| 174 | 174 | **/ |
| 175 | 175 | function html_tests_js() { |
| 176 | - if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | - define( |
|
| 179 | - '_TESTER_NOSCRIPT', |
|
| 180 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | - . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $rejouer = ''; |
|
| 187 | - if (defined('_SESSION_REJOUER')) { |
|
| 188 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 176 | + if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | + define( |
|
| 179 | + '_TESTER_NOSCRIPT', |
|
| 180 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | + . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $rejouer = ''; |
|
| 187 | + if (defined('_SESSION_REJOUER')) { |
|
| 188 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -198,25 +198,25 @@ discard block |
||
| 198 | 198 | **/ |
| 199 | 199 | function info_maj_spip() { |
| 200 | 200 | |
| 201 | - $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 202 | - if (!$maj) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 201 | + $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 202 | + if (!$maj) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - $maj = explode('|', $maj); |
|
| 207 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 206 | + $maj = explode('|', $maj); |
|
| 207 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - if (!autoriser('webmestre')) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 212 | + if (!autoriser('webmestre')) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - array_shift($maj); |
|
| 217 | - $maj = implode('|', $maj); |
|
| 216 | + array_shift($maj); |
|
| 217 | + $maj = implode('|', $maj); |
|
| 218 | 218 | |
| 219 | - return "$maj<br />"; |
|
| 219 | + return "$maj<br />"; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,47 +227,47 @@ discard block |
||
| 227 | 227 | **/ |
| 228 | 228 | function info_copyright() { |
| 229 | 229 | |
| 230 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | - |
|
| 232 | - // |
|
| 233 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | - // |
|
| 235 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | - if ($vcs['vcs'] === 'GIT') { |
|
| 237 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | - } else { |
|
| 241 | - $url = ''; |
|
| 242 | - } |
|
| 243 | - // affichage "GIT [master: abcdef]" |
|
| 244 | - $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 245 | - if ($url) { |
|
| 246 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | - } |
|
| 248 | - if ($vcs['branch']) { |
|
| 249 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | - } |
|
| 251 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // et la version de l'ecran de securite |
|
| 255 | - $secu = defined('_ECRAN_SECURITE') |
|
| 256 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | - : ''; |
|
| 258 | - |
|
| 259 | - return _T( |
|
| 260 | - 'info_copyright', |
|
| 261 | - [ |
|
| 262 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | - 'lien_gpl' => |
|
| 264 | - "<a href='" . generer_url_ecrire( |
|
| 265 | - 'aide', |
|
| 266 | - 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | - ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | - ] |
|
| 269 | - ) |
|
| 270 | - . $secu; |
|
| 230 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | + |
|
| 232 | + // |
|
| 233 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | + // |
|
| 235 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | + if ($vcs['vcs'] === 'GIT') { |
|
| 237 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | + } else { |
|
| 241 | + $url = ''; |
|
| 242 | + } |
|
| 243 | + // affichage "GIT [master: abcdef]" |
|
| 244 | + $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 245 | + if ($url) { |
|
| 246 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | + } |
|
| 248 | + if ($vcs['branch']) { |
|
| 249 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | + } |
|
| 251 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // et la version de l'ecran de securite |
|
| 255 | + $secu = defined('_ECRAN_SECURITE') |
|
| 256 | + ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | + : ''; |
|
| 258 | + |
|
| 259 | + return _T( |
|
| 260 | + 'info_copyright', |
|
| 261 | + [ |
|
| 262 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | + 'lien_gpl' => |
|
| 264 | + "<a href='" . generer_url_ecrire( |
|
| 265 | + 'aide', |
|
| 266 | + 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | + ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | + ] |
|
| 269 | + ) |
|
| 270 | + . $secu; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | * @return string Code HTML |
| 283 | 283 | **/ |
| 284 | 284 | function formulaire_recherche($page, $complement = '') { |
| 285 | - $recherche = _request('recherche'); |
|
| 286 | - $recherche_aff = entites_html($recherche); |
|
| 287 | - if (!strlen($recherche)) { |
|
| 288 | - $recherche_aff = _T('info_rechercher'); |
|
| 289 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | - } else { |
|
| 291 | - $onfocus = ''; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | - |
|
| 297 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 285 | + $recherche = _request('recherche'); |
|
| 286 | + $recherche_aff = entites_html($recherche); |
|
| 287 | + if (!strlen($recherche)) { |
|
| 288 | + $recherche_aff = _T('info_rechercher'); |
|
| 289 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | + } else { |
|
| 291 | + $onfocus = ''; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | + |
|
| 297 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 298 | 298 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 24 | 24 | |
@@ -31,161 +31,161 @@ discard block |
||
| 31 | 31 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 32 | 32 | */ |
| 33 | 33 | function couleur_html_to_hex($couleur) { |
| 34 | - $couleurs_html = [ |
|
| 35 | - 'aliceblue' => 'F0F8FF', |
|
| 36 | - 'antiquewhite' => 'FAEBD7', |
|
| 37 | - 'aqua' => '00FFFF', |
|
| 38 | - 'aquamarine' => '7FFFD4', |
|
| 39 | - 'azure' => 'F0FFFF', |
|
| 40 | - 'beige' => 'F5F5DC', |
|
| 41 | - 'bisque' => 'FFE4C4', |
|
| 42 | - 'black' => '000000', |
|
| 43 | - 'blanchedalmond' => 'FFEBCD', |
|
| 44 | - 'blue' => '0000FF', |
|
| 45 | - 'blueviolet' => '8A2BE2', |
|
| 46 | - 'brown' => 'A52A2A', |
|
| 47 | - 'burlywood' => 'DEB887', |
|
| 48 | - 'cadetblue' => '5F9EA0', |
|
| 49 | - 'chartreuse' => '7FFF00', |
|
| 50 | - 'chocolate' => 'D2691E', |
|
| 51 | - 'coral' => 'FF7F50', |
|
| 52 | - 'cornflowerblue' => '6495ED', |
|
| 53 | - 'cornsilk' => 'FFF8DC', |
|
| 54 | - 'crimson' => 'DC143C', |
|
| 55 | - 'cyan' => '00FFFF', |
|
| 56 | - 'darkblue' => '00008B', |
|
| 57 | - 'darkcyan' => '008B8B', |
|
| 58 | - 'darkgoldenrod' => 'B8860B', |
|
| 59 | - 'darkgray' => 'A9A9A9', |
|
| 60 | - 'darkgreen' => '006400', |
|
| 61 | - 'darkgrey' => 'A9A9A9', |
|
| 62 | - 'darkkhaki' => 'BDB76B', |
|
| 63 | - 'darkmagenta' => '8B008B', |
|
| 64 | - 'darkolivegreen' => '556B2F', |
|
| 65 | - 'darkorange' => 'FF8C00', |
|
| 66 | - 'darkorchid' => '9932CC', |
|
| 67 | - 'darkred' => '8B0000', |
|
| 68 | - 'darksalmon' => 'E9967A', |
|
| 69 | - 'darkseagreen' => '8FBC8F', |
|
| 70 | - 'darkslateblue' => '483D8B', |
|
| 71 | - 'darkslategray' => '2F4F4F', |
|
| 72 | - 'darkslategrey' => '2F4F4F', |
|
| 73 | - 'darkturquoise' => '00CED1', |
|
| 74 | - 'darkviolet' => '9400D3', |
|
| 75 | - 'deeppink' => 'FF1493', |
|
| 76 | - 'deepskyblue' => '00BFFF', |
|
| 77 | - 'dimgray' => '696969', |
|
| 78 | - 'dimgrey' => '696969', |
|
| 79 | - 'dodgerblue' => '1E90FF', |
|
| 80 | - 'firebrick' => 'B22222', |
|
| 81 | - 'floralwhite' => 'FFFAF0', |
|
| 82 | - 'forestgreen' => '228B22', |
|
| 83 | - 'fuchsia' => 'FF00FF', |
|
| 84 | - 'gainsboro' => 'DCDCDC', |
|
| 85 | - 'ghostwhite' => 'F8F8FF', |
|
| 86 | - 'gold' => 'FFD700', |
|
| 87 | - 'goldenrod' => 'DAA520', |
|
| 88 | - 'gray' => '808080', |
|
| 89 | - 'green' => '008000', |
|
| 90 | - 'greenyellow' => 'ADFF2F', |
|
| 91 | - 'grey' => '808080', |
|
| 92 | - 'honeydew' => 'F0FFF0', |
|
| 93 | - 'hotpink' => 'FF69B4', |
|
| 94 | - 'indianred' => 'CD5C5C', |
|
| 95 | - 'indigo' => '4B0082', |
|
| 96 | - 'ivory' => 'FFFFF0', |
|
| 97 | - 'khaki' => 'F0E68C', |
|
| 98 | - 'lavender' => 'E6E6FA', |
|
| 99 | - 'lavenderblush' => 'FFF0F5', |
|
| 100 | - 'lawngreen' => '7CFC00', |
|
| 101 | - 'lemonchiffon' => 'FFFACD', |
|
| 102 | - 'lightblue' => 'ADD8E6', |
|
| 103 | - 'lightcoral' => 'F08080', |
|
| 104 | - 'lightcyan' => 'E0FFFF', |
|
| 105 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | - 'lightgray' => 'D3D3D3', |
|
| 107 | - 'lightgreen' => '90EE90', |
|
| 108 | - 'lightgrey' => 'D3D3D3', |
|
| 109 | - 'lightpink' => 'FFB6C1', |
|
| 110 | - 'lightsalmon' => 'FFA07A', |
|
| 111 | - 'lightseagreen' => '20B2AA', |
|
| 112 | - 'lightskyblue' => '87CEFA', |
|
| 113 | - 'lightslategray' => '778899', |
|
| 114 | - 'lightslategrey' => '778899', |
|
| 115 | - 'lightsteelblue' => 'B0C4DE', |
|
| 116 | - 'lightyellow' => 'FFFFE0', |
|
| 117 | - 'lime' => '00FF00', |
|
| 118 | - 'limegreen' => '32CD32', |
|
| 119 | - 'linen' => 'FAF0E6', |
|
| 120 | - 'magenta' => 'FF00FF', |
|
| 121 | - 'maroon' => '800000', |
|
| 122 | - 'mediumaquamarine' => '66CDAA', |
|
| 123 | - 'mediumblue' => '0000CD', |
|
| 124 | - 'mediumorchid' => 'BA55D3', |
|
| 125 | - 'mediumpurple' => '9370DB', |
|
| 126 | - 'mediumseagreen' => '3CB371', |
|
| 127 | - 'mediumslateblue' => '7B68EE', |
|
| 128 | - 'mediumspringgreen' => '00FA9A', |
|
| 129 | - 'mediumturquoise' => '48D1CC', |
|
| 130 | - 'mediumvioletred' => 'C71585', |
|
| 131 | - 'midnightblue' => '191970', |
|
| 132 | - 'mintcream' => 'F5FFFA', |
|
| 133 | - 'mistyrose' => 'FFE4E1', |
|
| 134 | - 'moccasin' => 'FFE4B5', |
|
| 135 | - 'navajowhite' => 'FFDEAD', |
|
| 136 | - 'navy' => '000080', |
|
| 137 | - 'oldlace' => 'FDF5E6', |
|
| 138 | - 'olive' => '808000', |
|
| 139 | - 'olivedrab' => '6B8E23', |
|
| 140 | - 'orange' => 'FFA500', |
|
| 141 | - 'orangered' => 'FF4500', |
|
| 142 | - 'orchid' => 'DA70D6', |
|
| 143 | - 'palegoldenrod' => 'EEE8AA', |
|
| 144 | - 'palegreen' => '98FB98', |
|
| 145 | - 'paleturquoise' => 'AFEEEE', |
|
| 146 | - 'palevioletred' => 'DB7093', |
|
| 147 | - 'papayawhip' => 'FFEFD5', |
|
| 148 | - 'peachpuff' => 'FFDAB9', |
|
| 149 | - 'peru' => 'CD853F', |
|
| 150 | - 'pink' => 'FFC0CB', |
|
| 151 | - 'plum' => 'DDA0DD', |
|
| 152 | - 'powderblue' => 'B0E0E6', |
|
| 153 | - 'purple' => '800080', |
|
| 154 | - 'rebeccapurple' => '663399', |
|
| 155 | - 'red' => 'FF0000', |
|
| 156 | - 'rosybrown' => 'BC8F8F', |
|
| 157 | - 'royalblue' => '4169E1', |
|
| 158 | - 'saddlebrown' => '8B4513', |
|
| 159 | - 'salmon' => 'FA8072', |
|
| 160 | - 'sandybrown' => 'F4A460', |
|
| 161 | - 'seagreen' => '2E8B57', |
|
| 162 | - 'seashell' => 'FFF5EE', |
|
| 163 | - 'sienna' => 'A0522D', |
|
| 164 | - 'silver' => 'C0C0C0', |
|
| 165 | - 'skyblue' => '87CEEB', |
|
| 166 | - 'slateblue' => '6A5ACD', |
|
| 167 | - 'slategray' => '708090', |
|
| 168 | - 'slategrey' => '708090', |
|
| 169 | - 'snow' => 'FFFAFA', |
|
| 170 | - 'springgreen' => '00FF7F', |
|
| 171 | - 'steelblue' => '4682B4', |
|
| 172 | - 'tan' => 'D2B48C', |
|
| 173 | - 'teal' => '008080', |
|
| 174 | - 'thistle' => 'D8BFD8', |
|
| 175 | - 'tomato' => 'FF6347', |
|
| 176 | - 'turquoise' => '40E0D0', |
|
| 177 | - 'violet' => 'EE82EE', |
|
| 178 | - 'wheat' => 'F5DEB3', |
|
| 179 | - 'white' => 'FFFFFF', |
|
| 180 | - 'whitesmoke' => 'F5F5F5', |
|
| 181 | - 'yellow' => 'FFFF00', |
|
| 182 | - 'yellowgreen' => '9ACD32', |
|
| 183 | - ]; |
|
| 184 | - if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | - return $couleurs_html[$lc]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $couleur; |
|
| 34 | + $couleurs_html = [ |
|
| 35 | + 'aliceblue' => 'F0F8FF', |
|
| 36 | + 'antiquewhite' => 'FAEBD7', |
|
| 37 | + 'aqua' => '00FFFF', |
|
| 38 | + 'aquamarine' => '7FFFD4', |
|
| 39 | + 'azure' => 'F0FFFF', |
|
| 40 | + 'beige' => 'F5F5DC', |
|
| 41 | + 'bisque' => 'FFE4C4', |
|
| 42 | + 'black' => '000000', |
|
| 43 | + 'blanchedalmond' => 'FFEBCD', |
|
| 44 | + 'blue' => '0000FF', |
|
| 45 | + 'blueviolet' => '8A2BE2', |
|
| 46 | + 'brown' => 'A52A2A', |
|
| 47 | + 'burlywood' => 'DEB887', |
|
| 48 | + 'cadetblue' => '5F9EA0', |
|
| 49 | + 'chartreuse' => '7FFF00', |
|
| 50 | + 'chocolate' => 'D2691E', |
|
| 51 | + 'coral' => 'FF7F50', |
|
| 52 | + 'cornflowerblue' => '6495ED', |
|
| 53 | + 'cornsilk' => 'FFF8DC', |
|
| 54 | + 'crimson' => 'DC143C', |
|
| 55 | + 'cyan' => '00FFFF', |
|
| 56 | + 'darkblue' => '00008B', |
|
| 57 | + 'darkcyan' => '008B8B', |
|
| 58 | + 'darkgoldenrod' => 'B8860B', |
|
| 59 | + 'darkgray' => 'A9A9A9', |
|
| 60 | + 'darkgreen' => '006400', |
|
| 61 | + 'darkgrey' => 'A9A9A9', |
|
| 62 | + 'darkkhaki' => 'BDB76B', |
|
| 63 | + 'darkmagenta' => '8B008B', |
|
| 64 | + 'darkolivegreen' => '556B2F', |
|
| 65 | + 'darkorange' => 'FF8C00', |
|
| 66 | + 'darkorchid' => '9932CC', |
|
| 67 | + 'darkred' => '8B0000', |
|
| 68 | + 'darksalmon' => 'E9967A', |
|
| 69 | + 'darkseagreen' => '8FBC8F', |
|
| 70 | + 'darkslateblue' => '483D8B', |
|
| 71 | + 'darkslategray' => '2F4F4F', |
|
| 72 | + 'darkslategrey' => '2F4F4F', |
|
| 73 | + 'darkturquoise' => '00CED1', |
|
| 74 | + 'darkviolet' => '9400D3', |
|
| 75 | + 'deeppink' => 'FF1493', |
|
| 76 | + 'deepskyblue' => '00BFFF', |
|
| 77 | + 'dimgray' => '696969', |
|
| 78 | + 'dimgrey' => '696969', |
|
| 79 | + 'dodgerblue' => '1E90FF', |
|
| 80 | + 'firebrick' => 'B22222', |
|
| 81 | + 'floralwhite' => 'FFFAF0', |
|
| 82 | + 'forestgreen' => '228B22', |
|
| 83 | + 'fuchsia' => 'FF00FF', |
|
| 84 | + 'gainsboro' => 'DCDCDC', |
|
| 85 | + 'ghostwhite' => 'F8F8FF', |
|
| 86 | + 'gold' => 'FFD700', |
|
| 87 | + 'goldenrod' => 'DAA520', |
|
| 88 | + 'gray' => '808080', |
|
| 89 | + 'green' => '008000', |
|
| 90 | + 'greenyellow' => 'ADFF2F', |
|
| 91 | + 'grey' => '808080', |
|
| 92 | + 'honeydew' => 'F0FFF0', |
|
| 93 | + 'hotpink' => 'FF69B4', |
|
| 94 | + 'indianred' => 'CD5C5C', |
|
| 95 | + 'indigo' => '4B0082', |
|
| 96 | + 'ivory' => 'FFFFF0', |
|
| 97 | + 'khaki' => 'F0E68C', |
|
| 98 | + 'lavender' => 'E6E6FA', |
|
| 99 | + 'lavenderblush' => 'FFF0F5', |
|
| 100 | + 'lawngreen' => '7CFC00', |
|
| 101 | + 'lemonchiffon' => 'FFFACD', |
|
| 102 | + 'lightblue' => 'ADD8E6', |
|
| 103 | + 'lightcoral' => 'F08080', |
|
| 104 | + 'lightcyan' => 'E0FFFF', |
|
| 105 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | + 'lightgray' => 'D3D3D3', |
|
| 107 | + 'lightgreen' => '90EE90', |
|
| 108 | + 'lightgrey' => 'D3D3D3', |
|
| 109 | + 'lightpink' => 'FFB6C1', |
|
| 110 | + 'lightsalmon' => 'FFA07A', |
|
| 111 | + 'lightseagreen' => '20B2AA', |
|
| 112 | + 'lightskyblue' => '87CEFA', |
|
| 113 | + 'lightslategray' => '778899', |
|
| 114 | + 'lightslategrey' => '778899', |
|
| 115 | + 'lightsteelblue' => 'B0C4DE', |
|
| 116 | + 'lightyellow' => 'FFFFE0', |
|
| 117 | + 'lime' => '00FF00', |
|
| 118 | + 'limegreen' => '32CD32', |
|
| 119 | + 'linen' => 'FAF0E6', |
|
| 120 | + 'magenta' => 'FF00FF', |
|
| 121 | + 'maroon' => '800000', |
|
| 122 | + 'mediumaquamarine' => '66CDAA', |
|
| 123 | + 'mediumblue' => '0000CD', |
|
| 124 | + 'mediumorchid' => 'BA55D3', |
|
| 125 | + 'mediumpurple' => '9370DB', |
|
| 126 | + 'mediumseagreen' => '3CB371', |
|
| 127 | + 'mediumslateblue' => '7B68EE', |
|
| 128 | + 'mediumspringgreen' => '00FA9A', |
|
| 129 | + 'mediumturquoise' => '48D1CC', |
|
| 130 | + 'mediumvioletred' => 'C71585', |
|
| 131 | + 'midnightblue' => '191970', |
|
| 132 | + 'mintcream' => 'F5FFFA', |
|
| 133 | + 'mistyrose' => 'FFE4E1', |
|
| 134 | + 'moccasin' => 'FFE4B5', |
|
| 135 | + 'navajowhite' => 'FFDEAD', |
|
| 136 | + 'navy' => '000080', |
|
| 137 | + 'oldlace' => 'FDF5E6', |
|
| 138 | + 'olive' => '808000', |
|
| 139 | + 'olivedrab' => '6B8E23', |
|
| 140 | + 'orange' => 'FFA500', |
|
| 141 | + 'orangered' => 'FF4500', |
|
| 142 | + 'orchid' => 'DA70D6', |
|
| 143 | + 'palegoldenrod' => 'EEE8AA', |
|
| 144 | + 'palegreen' => '98FB98', |
|
| 145 | + 'paleturquoise' => 'AFEEEE', |
|
| 146 | + 'palevioletred' => 'DB7093', |
|
| 147 | + 'papayawhip' => 'FFEFD5', |
|
| 148 | + 'peachpuff' => 'FFDAB9', |
|
| 149 | + 'peru' => 'CD853F', |
|
| 150 | + 'pink' => 'FFC0CB', |
|
| 151 | + 'plum' => 'DDA0DD', |
|
| 152 | + 'powderblue' => 'B0E0E6', |
|
| 153 | + 'purple' => '800080', |
|
| 154 | + 'rebeccapurple' => '663399', |
|
| 155 | + 'red' => 'FF0000', |
|
| 156 | + 'rosybrown' => 'BC8F8F', |
|
| 157 | + 'royalblue' => '4169E1', |
|
| 158 | + 'saddlebrown' => '8B4513', |
|
| 159 | + 'salmon' => 'FA8072', |
|
| 160 | + 'sandybrown' => 'F4A460', |
|
| 161 | + 'seagreen' => '2E8B57', |
|
| 162 | + 'seashell' => 'FFF5EE', |
|
| 163 | + 'sienna' => 'A0522D', |
|
| 164 | + 'silver' => 'C0C0C0', |
|
| 165 | + 'skyblue' => '87CEEB', |
|
| 166 | + 'slateblue' => '6A5ACD', |
|
| 167 | + 'slategray' => '708090', |
|
| 168 | + 'slategrey' => '708090', |
|
| 169 | + 'snow' => 'FFFAFA', |
|
| 170 | + 'springgreen' => '00FF7F', |
|
| 171 | + 'steelblue' => '4682B4', |
|
| 172 | + 'tan' => 'D2B48C', |
|
| 173 | + 'teal' => '008080', |
|
| 174 | + 'thistle' => 'D8BFD8', |
|
| 175 | + 'tomato' => 'FF6347', |
|
| 176 | + 'turquoise' => '40E0D0', |
|
| 177 | + 'violet' => 'EE82EE', |
|
| 178 | + 'wheat' => 'F5DEB3', |
|
| 179 | + 'white' => 'FFFFFF', |
|
| 180 | + 'whitesmoke' => 'F5F5F5', |
|
| 181 | + 'yellow' => 'FFFF00', |
|
| 182 | + 'yellowgreen' => '9ACD32', |
|
| 183 | + ]; |
|
| 184 | + if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | + return $couleurs_html[$lc]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $couleur; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -201,16 +201,16 @@ discard block |
||
| 201 | 201 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 202 | 202 | */ |
| 203 | 203 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 204 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | - $hsl = [ |
|
| 206 | - 'h' => round($hsl['h'] * 360), |
|
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | - ]; |
|
| 210 | - if ($format === null) { |
|
| 211 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | - } |
|
| 213 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 204 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | + $hsl = [ |
|
| 206 | + 'h' => round($hsl['h'] * 360), |
|
| 207 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | + ]; |
|
| 210 | + if ($format === null) { |
|
| 211 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | + } |
|
| 213 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 228 | 228 | */ |
| 229 | 229 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 230 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | - $rgb = [ |
|
| 232 | - 'r' => $rgb['red'], |
|
| 233 | - 'g' => $rgb['green'], |
|
| 234 | - 'b' => $rgb['blue'], |
|
| 235 | - ]; |
|
| 236 | - if ($format === null) { |
|
| 237 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | - } |
|
| 239 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 230 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | + $rgb = [ |
|
| 232 | + 'r' => $rgb['red'], |
|
| 233 | + 'g' => $rgb['green'], |
|
| 234 | + 'b' => $rgb['blue'], |
|
| 235 | + ]; |
|
| 236 | + if ($format === null) { |
|
| 237 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | + } |
|
| 239 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | * Code hexadécimal de la couleur plus foncée |
| 253 | 253 | */ |
| 254 | 254 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 255 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 256 | 256 | |
| 257 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 257 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 260 | 260 | |
| 261 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 262 | 262 | |
| 263 | - return $couleur; |
|
| 263 | + return $couleur; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | * Code hexadécimal de la couleur éclaircie |
| 277 | 277 | */ |
| 278 | 278 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 279 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 279 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 280 | 280 | |
| 281 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 284 | 284 | |
| 285 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 285 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 286 | 286 | |
| 287 | - return $couleur; |
|
| 287 | + return $couleur; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -307,28 +307,28 @@ discard block |
||
| 307 | 307 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 308 | 308 | */ |
| 309 | 309 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 310 | - if (!$img) { |
|
| 311 | - return $img; |
|
| 312 | - } |
|
| 313 | - [$h, $l] = taille_image($img); |
|
| 314 | - $select = true; |
|
| 315 | - if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | - $select = false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $class = extraire_attribut($img, 'class'); |
|
| 320 | - $p = strpos($class, 'filtre_inactif'); |
|
| 321 | - if (($select == false) and ($p === false)) { |
|
| 322 | - $class .= ' filtre_inactif'; |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - if (($select == true) and ($p !== false)) { |
|
| 326 | - // no_image_filtrer : historique, a virer |
|
| 327 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | - $img = inserer_attribut($img, 'class', $class); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - return $img; |
|
| 310 | + if (!$img) { |
|
| 311 | + return $img; |
|
| 312 | + } |
|
| 313 | + [$h, $l] = taille_image($img); |
|
| 314 | + $select = true; |
|
| 315 | + if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | + $select = false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $class = extraire_attribut($img, 'class'); |
|
| 320 | + $p = strpos($class, 'filtre_inactif'); |
|
| 321 | + if (($select == false) and ($p === false)) { |
|
| 322 | + $class .= ' filtre_inactif'; |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + if (($select == true) and ($p !== false)) { |
|
| 326 | + // no_image_filtrer : historique, a virer |
|
| 327 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | + $img = inserer_attribut($img, 'class', $class); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + return $img; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -376,45 +376,45 @@ discard block |
||
| 376 | 376 | * Code HTML de l'image ou du texte. |
| 377 | 377 | **/ |
| 378 | 378 | function image_passe_partout( |
| 379 | - $img, |
|
| 380 | - $taille_x = -1, |
|
| 381 | - $taille_y = -1, |
|
| 382 | - $force = false, |
|
| 383 | - $cherche_image = false, |
|
| 384 | - $process = 'AUTO' |
|
| 379 | + $img, |
|
| 380 | + $taille_x = -1, |
|
| 381 | + $taille_y = -1, |
|
| 382 | + $force = false, |
|
| 383 | + $cherche_image = false, |
|
| 384 | + $process = 'AUTO' |
|
| 385 | 385 | ) { |
| 386 | - // PHP 7+ type hint |
|
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 392 | - |
|
| 393 | - if (!$img) { |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - [$hauteur, $largeur] = taille_image($img); |
|
| 397 | - if ($taille_x === -1) { |
|
| 398 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | - } |
|
| 400 | - if ($taille_y === -1) { |
|
| 401 | - $taille_y = $taille_x; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | - $taille_x = 1; |
|
| 406 | - } # {0,300} -> c'est 300 qui compte |
|
| 407 | - elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | - $taille_y = 1; |
|
| 409 | - } # {300,0} -> c'est 300 qui compte |
|
| 410 | - elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | - return ''; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | - |
|
| 417 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 386 | + // PHP 7+ type hint |
|
| 387 | + $img = (string)$img; |
|
| 388 | + $taille_x = (int)$taille_x; |
|
| 389 | + $taille_y = (int)$taille_y; |
|
| 390 | + $force = (bool)$force; |
|
| 391 | + $process = (string)$process; |
|
| 392 | + |
|
| 393 | + if (!$img) { |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + [$hauteur, $largeur] = taille_image($img); |
|
| 397 | + if ($taille_x === -1) { |
|
| 398 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | + } |
|
| 400 | + if ($taille_y === -1) { |
|
| 401 | + $taille_y = $taille_x; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | + $taille_x = 1; |
|
| 406 | + } # {0,300} -> c'est 300 qui compte |
|
| 407 | + elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | + $taille_y = 1; |
|
| 409 | + } # {300,0} -> c'est 300 qui compte |
|
| 410 | + elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | + return ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | + |
|
| 417 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -457,44 +457,44 @@ discard block |
||
| 457 | 457 | * Code HTML de l'image ou du texte. |
| 458 | 458 | **/ |
| 459 | 459 | function image_reduire( |
| 460 | - $img, |
|
| 461 | - $taille = -1, |
|
| 462 | - $taille_y = -1, |
|
| 463 | - $force = false, |
|
| 464 | - $cherche_image = false, |
|
| 465 | - $process = 'AUTO' |
|
| 460 | + $img, |
|
| 461 | + $taille = -1, |
|
| 462 | + $taille_y = -1, |
|
| 463 | + $force = false, |
|
| 464 | + $cherche_image = false, |
|
| 465 | + $process = 'AUTO' |
|
| 466 | 466 | ) { |
| 467 | - // PHP 7+ type hint |
|
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 473 | - |
|
| 474 | - // Determiner la taille x,y maxi |
|
| 475 | - // prendre le reglage de previsu par defaut |
|
| 476 | - if ($taille === -1) { |
|
| 477 | - $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | - ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | - : 150; |
|
| 480 | - } |
|
| 481 | - if ($taille_y === -1) { |
|
| 482 | - $taille_y = $taille; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if ($taille === 0 and $taille_y > 0) { |
|
| 486 | - $taille = 10000; |
|
| 487 | - } # {0,300} -> c'est 300 qui compte |
|
| 488 | - elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | - $taille_y = 10000; |
|
| 490 | - } # {300,0} -> c'est 300 qui compte |
|
| 491 | - elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | - |
|
| 497 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 467 | + // PHP 7+ type hint |
|
| 468 | + $img = (string)$img; |
|
| 469 | + $taille = (int)$taille; |
|
| 470 | + $taille_y = (int)$taille_y; |
|
| 471 | + $force = (bool)$force; |
|
| 472 | + $process = (string)$process; |
|
| 473 | + |
|
| 474 | + // Determiner la taille x,y maxi |
|
| 475 | + // prendre le reglage de previsu par defaut |
|
| 476 | + if ($taille === -1) { |
|
| 477 | + $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | + ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | + : 150; |
|
| 480 | + } |
|
| 481 | + if ($taille_y === -1) { |
|
| 482 | + $taille_y = $taille; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if ($taille === 0 and $taille_y > 0) { |
|
| 486 | + $taille = 10000; |
|
| 487 | + } # {0,300} -> c'est 300 qui compte |
|
| 488 | + elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | + $taille_y = 10000; |
|
| 490 | + } # {300,0} -> c'est 300 qui compte |
|
| 491 | + elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | + |
|
| 497 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,16 +505,16 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | **/ |
| 507 | 507 | function image_recadre_avec_fallback( |
| 508 | - $im, |
|
| 509 | - $width, |
|
| 510 | - $height = '-', |
|
| 511 | - $position = 'focus', |
|
| 512 | - $background_color = 'white' |
|
| 508 | + $im, |
|
| 509 | + $width, |
|
| 510 | + $height = '-', |
|
| 511 | + $position = 'focus', |
|
| 512 | + $background_color = 'white' |
|
| 513 | 513 | ) { |
| 514 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | - } else { return image_passe_partout($im, $width, $height); |
|
| 517 | - } |
|
| 514 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | + } else { return image_passe_partout($im, $width, $height); |
|
| 517 | + } |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,25 +532,25 @@ discard block |
||
| 532 | 532 | * Code HTML de l'image ou du texte. |
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | - // PHP 7+ type hint |
|
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 535 | + // PHP 7+ type hint |
|
| 536 | + $img = (string)$img; |
|
| 537 | + $val = (int)$val; |
|
| 538 | + $force = (bool)$force; |
|
| 539 | 539 | |
| 540 | - [$hauteur, $largeur] = taille_image($img); |
|
| 540 | + [$hauteur, $largeur] = taille_image($img); |
|
| 541 | 541 | |
| 542 | - $l = round($largeur / $val); |
|
| 543 | - $h = round($hauteur / $val); |
|
| 542 | + $l = round($largeur / $val); |
|
| 543 | + $h = round($hauteur / $val); |
|
| 544 | 544 | |
| 545 | - if ($l > $h) { |
|
| 546 | - $h = 0; |
|
| 547 | - } else { |
|
| 548 | - $l = 0; |
|
| 549 | - } |
|
| 545 | + if ($l > $h) { |
|
| 546 | + $h = 0; |
|
| 547 | + } else { |
|
| 548 | + $l = 0; |
|
| 549 | + } |
|
| 550 | 550 | |
| 551 | - $img = image_reduire($img, $l, $h, $force); |
|
| 551 | + $img = image_reduire($img, $l, $h, $force); |
|
| 552 | 552 | |
| 553 | - return $img; |
|
| 553 | + return $img; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * Couleur en écriture hexadécimale. |
| 574 | 574 | **/ |
| 575 | 575 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 576 | - if (function_exists('couleur_saturation')) { |
|
| 577 | - return couleur_saturation($couleur, $val, $strict); |
|
| 578 | - } |
|
| 579 | - return $couleur; |
|
| 576 | + if (function_exists('couleur_saturation')) { |
|
| 577 | + return couleur_saturation($couleur, $val, $strict); |
|
| 578 | + } |
|
| 579 | + return $couleur; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -597,8 +597,8 @@ discard block |
||
| 597 | 597 | * Couleur en écriture hexadécimale. |
| 598 | 598 | **/ |
| 599 | 599 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 600 | - if (function_exists('couleur_luminance')) { |
|
| 601 | - return couleur_luminance($couleur, $val); |
|
| 602 | - } |
|
| 603 | - return $couleur; |
|
| 600 | + if (function_exists('couleur_luminance')) { |
|
| 601 | + return couleur_luminance($couleur, $val); |
|
| 602 | + } |
|
| 603 | + return $couleur; |
|
| 604 | 604 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | **/ |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 25 | - return; |
|
| 25 | + return; |
|
| 26 | 26 | } |
| 27 | 27 | include_spip('inc/filtres'); |
| 28 | 28 | |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | * @return string Rien. |
| 40 | 40 | **/ |
| 41 | 41 | function filtre_image_dist($t) { |
| 42 | - return ''; |
|
| 42 | + return ''; |
|
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | /** |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | * @return string Rien. |
| 53 | 53 | **/ |
| 54 | 54 | function filtre_audio_dist($t) { |
| 55 | - return ''; |
|
| 55 | + return ''; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @return string Rien. |
| 66 | 66 | **/ |
| 67 | 67 | function filtre_video_dist($t) { |
| 68 | - return ''; |
|
| 68 | + return ''; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return string Rien. |
| 79 | 79 | **/ |
| 80 | 80 | function filtre_application_dist($t) { |
| 81 | - return ''; |
|
| 81 | + return ''; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | /** |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | * @return string Rien. |
| 92 | 92 | **/ |
| 93 | 93 | function filtre_message_dist($t) { |
| 94 | - return ''; |
|
| 94 | + return ''; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return string Rien. |
| 105 | 105 | **/ |
| 106 | 106 | function filtre_multipart_dist($t) { |
| 107 | - return ''; |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * @return string Contenu échappé. |
| 118 | 118 | **/ |
| 119 | 119 | function filtre_text_dist($t) { |
| 120 | - static $t1 = ['&', '<', '>']; |
|
| 121 | - static $t2 = ['&', '<', '>']; |
|
| 120 | + static $t1 = ['&', '<', '>']; |
|
| 121 | + static $t2 = ['&', '<', '>']; |
|
| 122 | 122 | |
| 123 | - return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 123 | + return '<pre>' . str_replace($t1, $t2, $t) . '</pre>'; |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | /** |
@@ -135,21 +135,21 @@ discard block |
||
| 135 | 135 | * Tableau (formaté en SPIP) |
| 136 | 136 | **/ |
| 137 | 137 | function filtre_text_csv_dist($t) { |
| 138 | - include_spip('inc/csv'); |
|
| 139 | - [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 140 | - foreach ($lignes as &$l) { |
|
| 141 | - $l = join('|', $l); |
|
| 142 | - } |
|
| 143 | - $corps = join("\n", $lignes) . "\n"; |
|
| 144 | - $corps = $caption . |
|
| 145 | - "\n|{{" . |
|
| 146 | - join('}}|{{', $entete) . |
|
| 147 | - '}}|' . |
|
| 148 | - "\n|" . |
|
| 149 | - str_replace("\n", "|\n|", $corps); |
|
| 150 | - include_spip('inc/texte'); |
|
| 151 | - |
|
| 152 | - return propre($corps); |
|
| 138 | + include_spip('inc/csv'); |
|
| 139 | + [$entete, $lignes, $caption] = analyse_csv($t); |
|
| 140 | + foreach ($lignes as &$l) { |
|
| 141 | + $l = join('|', $l); |
|
| 142 | + } |
|
| 143 | + $corps = join("\n", $lignes) . "\n"; |
|
| 144 | + $corps = $caption . |
|
| 145 | + "\n|{{" . |
|
| 146 | + join('}}|{{', $entete) . |
|
| 147 | + '}}|' . |
|
| 148 | + "\n|" . |
|
| 149 | + str_replace("\n", "|\n|", $corps); |
|
| 150 | + include_spip('inc/texte'); |
|
| 151 | + |
|
| 152 | + return propre($corps); |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | /** |
@@ -163,33 +163,33 @@ discard block |
||
| 163 | 163 | * @return string Code html sécurisé ou texte échappé |
| 164 | 164 | **/ |
| 165 | 165 | function filtre_text_html_dist($t) { |
| 166 | - if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 167 | - return appliquer_filtre($t, 'text/plain'); |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - [, $h, $t] = $r; |
|
| 171 | - |
|
| 172 | - $style = ''; |
|
| 173 | - // recuperer les styles internes |
|
| 174 | - if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 175 | - $style = join("\n", $r[1]); |
|
| 176 | - } |
|
| 177 | - // ... et externes |
|
| 178 | - |
|
| 179 | - include_spip('inc/distant'); |
|
| 180 | - if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 181 | - foreach ($r[0] as $l) { |
|
| 182 | - preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 183 | - $page = recuperer_url($m[1]); |
|
| 184 | - $page = $page['page'] ?? ''; |
|
| 185 | - $style .= "\n/* $l */\n" |
|
| 186 | - . str_replace('<', '', $page); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 190 | - $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 191 | - |
|
| 192 | - return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 166 | + if (!preg_match(',^(.*?)<body[^>]*>(.*)</body>,is', $t, $r)) { |
|
| 167 | + return appliquer_filtre($t, 'text/plain'); |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + [, $h, $t] = $r; |
|
| 171 | + |
|
| 172 | + $style = ''; |
|
| 173 | + // recuperer les styles internes |
|
| 174 | + if (preg_match_all(',<style>(.*?)</style>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 175 | + $style = join("\n", $r[1]); |
|
| 176 | + } |
|
| 177 | + // ... et externes |
|
| 178 | + |
|
| 179 | + include_spip('inc/distant'); |
|
| 180 | + if (preg_match_all(',<link[^>]+type=.text/css[^>]*>,is', $h, $r, PREG_PATTERN_ORDER)) { |
|
| 181 | + foreach ($r[0] as $l) { |
|
| 182 | + preg_match("/href='([^']*)'/", str_replace('"', "'", $l), $m); |
|
| 183 | + $page = recuperer_url($m[1]); |
|
| 184 | + $page = $page['page'] ?? ''; |
|
| 185 | + $style .= "\n/* $l */\n" |
|
| 186 | + . str_replace('<', '', $page); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + // Pourquoi SafeHtml transforme-t-il en texte les scripts dans Body ? |
|
| 190 | + $t = safehtml(preg_replace(',<script' . '.*?</script>,is', '', $t)); |
|
| 191 | + |
|
| 192 | + return (!$style ? '' : "\n<style>" . $style . '</style>') . $t; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | * @return string Code HTML des balises `<param>` |
| 203 | 203 | **/ |
| 204 | 204 | function filtre_audio_x_pn_realaudio($id) { |
| 205 | - return " |
|
| 205 | + return " |
|
| 206 | 206 | <param name='controls' value='PositionSlider' /> |
| 207 | 207 | <param name='controls' value='ImageWindow' /> |
| 208 | 208 | <param name='controls' value='PlayButton' /> |
@@ -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 | |
@@ -23,12 +23,12 @@ discard block |
||
| 23 | 23 | * @return array |
| 24 | 24 | */ |
| 25 | 25 | function inc_simplexml_to_array_dist($u, $utiliser_namespace = false) { |
| 26 | - // decoder la chaine en SimpleXML si pas deja fait |
|
| 27 | - if (is_string($u)) { |
|
| 28 | - $u = simplexml_load_string($u); |
|
| 29 | - } |
|
| 26 | + // decoder la chaine en SimpleXML si pas deja fait |
|
| 27 | + if (is_string($u)) { |
|
| 28 | + $u = simplexml_load_string($u); |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - return ['root' => @xmlObjToArr($u, $utiliser_namespace)]; |
|
| 31 | + return ['root' => @xmlObjToArr($u, $utiliser_namespace)]; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -43,67 +43,67 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function xmlObjToArr($obj, $utiliser_namespace = false) { |
| 45 | 45 | |
| 46 | - $namespace = []; |
|
| 47 | - $tableau = []; |
|
| 46 | + $namespace = []; |
|
| 47 | + $tableau = []; |
|
| 48 | 48 | |
| 49 | - // Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc |
|
| 50 | - // de l'activer ou pas suivant le contenu supposé du XML |
|
| 51 | - if (is_object($obj)) { |
|
| 52 | - if (is_array($utiliser_namespace)) { |
|
| 53 | - $namespace = $utiliser_namespace; |
|
| 54 | - } else { |
|
| 55 | - if ($utiliser_namespace) { |
|
| 56 | - $namespace = $obj->getDocNamespaces(true); |
|
| 57 | - } |
|
| 58 | - $namespace[null] = null; |
|
| 59 | - } |
|
| 49 | + // Cette fonction getDocNamespaces() est longue sur de gros xml. On permet donc |
|
| 50 | + // de l'activer ou pas suivant le contenu supposé du XML |
|
| 51 | + if (is_object($obj)) { |
|
| 52 | + if (is_array($utiliser_namespace)) { |
|
| 53 | + $namespace = $utiliser_namespace; |
|
| 54 | + } else { |
|
| 55 | + if ($utiliser_namespace) { |
|
| 56 | + $namespace = $obj->getDocNamespaces(true); |
|
| 57 | + } |
|
| 58 | + $namespace[null] = null; |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $name = strtolower((string)$obj->getName()); |
|
| 62 | - $text = trim((string)$obj); |
|
| 63 | - if (strlen($text) <= 0) { |
|
| 64 | - $text = null; |
|
| 65 | - } |
|
| 61 | + $name = strtolower((string)$obj->getName()); |
|
| 62 | + $text = trim((string)$obj); |
|
| 63 | + if (strlen($text) <= 0) { |
|
| 64 | + $text = null; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - $children = []; |
|
| 68 | - $attributes = []; |
|
| 67 | + $children = []; |
|
| 68 | + $attributes = []; |
|
| 69 | 69 | |
| 70 | - // get info for all namespaces |
|
| 71 | - foreach ($namespace as $ns => $nsUrl) { |
|
| 72 | - // attributes |
|
| 73 | - $objAttributes = $obj->attributes($ns, true); |
|
| 74 | - foreach ($objAttributes as $attributeName => $attributeValue) { |
|
| 75 | - $attribName = strtolower(trim((string)$attributeName)); |
|
| 76 | - $attribVal = trim((string)$attributeValue); |
|
| 77 | - if (!empty($ns)) { |
|
| 78 | - $attribName = $ns . ':' . $attribName; |
|
| 79 | - } |
|
| 80 | - $attributes[$attribName] = $attribVal; |
|
| 81 | - } |
|
| 70 | + // get info for all namespaces |
|
| 71 | + foreach ($namespace as $ns => $nsUrl) { |
|
| 72 | + // attributes |
|
| 73 | + $objAttributes = $obj->attributes($ns, true); |
|
| 74 | + foreach ($objAttributes as $attributeName => $attributeValue) { |
|
| 75 | + $attribName = strtolower(trim((string)$attributeName)); |
|
| 76 | + $attribVal = trim((string)$attributeValue); |
|
| 77 | + if (!empty($ns)) { |
|
| 78 | + $attribName = $ns . ':' . $attribName; |
|
| 79 | + } |
|
| 80 | + $attributes[$attribName] = $attribVal; |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - // children |
|
| 84 | - $objChildren = $obj->children($ns, true); |
|
| 85 | - foreach ($objChildren as $childName => $child) { |
|
| 86 | - $childName = strtolower((string)$childName); |
|
| 87 | - if (!empty($ns)) { |
|
| 88 | - $childName = $ns . ':' . $childName; |
|
| 89 | - } |
|
| 90 | - $children[$childName][] = xmlObjToArr($child, $namespace); |
|
| 91 | - } |
|
| 92 | - } |
|
| 83 | + // children |
|
| 84 | + $objChildren = $obj->children($ns, true); |
|
| 85 | + foreach ($objChildren as $childName => $child) { |
|
| 86 | + $childName = strtolower((string)$childName); |
|
| 87 | + if (!empty($ns)) { |
|
| 88 | + $childName = $ns . ':' . $childName; |
|
| 89 | + } |
|
| 90 | + $children[$childName][] = xmlObjToArr($child, $namespace); |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $tableau = [ |
|
| 95 | - 'name' => $name, |
|
| 96 | - ]; |
|
| 97 | - if ($text) { |
|
| 98 | - $tableau['text'] = $text; |
|
| 99 | - } |
|
| 100 | - if ($attributes) { |
|
| 101 | - $tableau['attributes'] = $attributes; |
|
| 102 | - } |
|
| 103 | - if ($children) { |
|
| 104 | - $tableau['children'] = $children; |
|
| 105 | - } |
|
| 106 | - } |
|
| 94 | + $tableau = [ |
|
| 95 | + 'name' => $name, |
|
| 96 | + ]; |
|
| 97 | + if ($text) { |
|
| 98 | + $tableau['text'] = $text; |
|
| 99 | + } |
|
| 100 | + if ($attributes) { |
|
| 101 | + $tableau['attributes'] = $attributes; |
|
| 102 | + } |
|
| 103 | + if ($children) { |
|
| 104 | + $tableau['children'] = $children; |
|
| 105 | + } |
|
| 106 | + } |
|
| 107 | 107 | |
| 108 | - return $tableau; |
|
| 108 | + return $tableau; |
|
| 109 | 109 | } |
@@ -11,107 +11,107 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | function inc_log_dist($message, $logname = null, $logdir = null, $logsuf = null) { |
| 18 | - static $test_repertoire = []; |
|
| 19 | - static $compteur = []; |
|
| 20 | - static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | - |
|
| 22 | - if (is_null($logname) or !is_string($logname)) { |
|
| 23 | - $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | - } |
|
| 25 | - if (!isset($compteur[$logname])) { |
|
| 26 | - $compteur[$logname] = 0; |
|
| 27 | - } |
|
| 28 | - if ( |
|
| 29 | - $logname != 'maj' |
|
| 30 | - and defined('_MAX_LOG') |
|
| 31 | - and ( |
|
| 32 | - $compteur[$logname]++ > _MAX_LOG |
|
| 33 | - or !$GLOBALS['nombre_de_logs'] |
|
| 34 | - or !$GLOBALS['taille_des_logs'] |
|
| 35 | - ) |
|
| 36 | - ) { |
|
| 37 | - return; |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - $logfile = ($logdir ?? _DIR_LOG) |
|
| 41 | - . ($logname) |
|
| 42 | - . ($logsuf ?? _FILE_LOG_SUFFIX); |
|
| 43 | - |
|
| 44 | - if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 45 | - $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 46 | - $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 47 | - $d, |
|
| 48 | - '', |
|
| 49 | - false, |
|
| 50 | - true |
|
| 51 | - ) : false)); |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // si spip_log() dans mes_options, ou repertoire log/ non present, poser dans tmp/ |
|
| 55 | - if (!defined('_DIR_LOG') or !$test_repertoire[$d]) { |
|
| 56 | - $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - $rotate = 0; |
|
| 60 | - $pid = '(pid ' . @getmypid() . ')'; |
|
| 61 | - |
|
| 62 | - // accepter spip_log( Array ) |
|
| 63 | - if (!is_string($message)) { |
|
| 64 | - $message = var_export($message, true); |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 68 | - $debug = debug_backtrace(); |
|
| 69 | - $l = $debug[1]['line']; |
|
| 70 | - $fi = $debug[1]['file']; |
|
| 71 | - if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 72 | - $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 73 | - } |
|
| 74 | - $fu = $debug[2]['function'] ?? ''; |
|
| 75 | - $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 79 | - //distinguer les logs prives et publics dans les grep |
|
| 80 | - . $debugverb |
|
| 81 | - . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 82 | - . preg_replace("/\n*$/", "\n", $message); |
|
| 83 | - |
|
| 84 | - |
|
| 85 | - if ( |
|
| 86 | - @is_readable($logfile) |
|
| 87 | - and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 88 | - ) { |
|
| 89 | - $rotate = $GLOBALS['nombre_de_logs']; |
|
| 90 | - $m .= "[-- rotate --]\n"; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - $f = @fopen($logfile, 'ab'); |
|
| 94 | - if ($f) { |
|
| 95 | - fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 96 | - fclose($f); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if ( |
|
| 100 | - $rotate-- > 0 |
|
| 101 | - and function_exists('spip_unlink') |
|
| 102 | - ) { |
|
| 103 | - spip_unlink($logfile . '.' . $rotate); |
|
| 104 | - while ($rotate--) { |
|
| 105 | - @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - // Dupliquer les erreurs specifiques dans le log general |
|
| 110 | - if ( |
|
| 111 | - defined('_FILE_LOG') |
|
| 112 | - and ($logname !== _FILE_LOG) |
|
| 113 | - ) { |
|
| 114 | - inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 115 | - } |
|
| 116 | - $debugverb = ''; |
|
| 18 | + static $test_repertoire = []; |
|
| 19 | + static $compteur = []; |
|
| 20 | + static $debugverb = ''; // pour ne pas le recalculer au reappel |
|
| 21 | + |
|
| 22 | + if (is_null($logname) or !is_string($logname)) { |
|
| 23 | + $logname = defined('_FILE_LOG') ? _FILE_LOG : 'spip'; |
|
| 24 | + } |
|
| 25 | + if (!isset($compteur[$logname])) { |
|
| 26 | + $compteur[$logname] = 0; |
|
| 27 | + } |
|
| 28 | + if ( |
|
| 29 | + $logname != 'maj' |
|
| 30 | + and defined('_MAX_LOG') |
|
| 31 | + and ( |
|
| 32 | + $compteur[$logname]++ > _MAX_LOG |
|
| 33 | + or !$GLOBALS['nombre_de_logs'] |
|
| 34 | + or !$GLOBALS['taille_des_logs'] |
|
| 35 | + ) |
|
| 36 | + ) { |
|
| 37 | + return; |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + $logfile = ($logdir ?? _DIR_LOG) |
|
| 41 | + . ($logname) |
|
| 42 | + . ($logsuf ?? _FILE_LOG_SUFFIX); |
|
| 43 | + |
|
| 44 | + if (!isset($test_repertoire[$d = dirname($logfile)])) { |
|
| 45 | + $test_repertoire[$d] = false; // eviter une recursivite en cas d'erreur de sous_repertoire |
|
| 46 | + $test_repertoire[$d] = (@is_dir($d) ? true : (function_exists('sous_repertoire') ? sous_repertoire( |
|
| 47 | + $d, |
|
| 48 | + '', |
|
| 49 | + false, |
|
| 50 | + true |
|
| 51 | + ) : false)); |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // si spip_log() dans mes_options, ou repertoire log/ non present, poser dans tmp/ |
|
| 55 | + if (!defined('_DIR_LOG') or !$test_repertoire[$d]) { |
|
| 56 | + $logfile = _DIR_RACINE . _NOM_TEMPORAIRES_INACCESSIBLES . $logname . '.log'; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + $rotate = 0; |
|
| 60 | + $pid = '(pid ' . @getmypid() . ')'; |
|
| 61 | + |
|
| 62 | + // accepter spip_log( Array ) |
|
| 63 | + if (!is_string($message)) { |
|
| 64 | + $message = var_export($message, true); |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + if (!$debugverb and defined('_LOG_FILELINE') and _LOG_FILELINE) { |
|
| 68 | + $debug = debug_backtrace(); |
|
| 69 | + $l = $debug[1]['line']; |
|
| 70 | + $fi = $debug[1]['file']; |
|
| 71 | + if (strncmp($fi, _ROOT_RACINE, strlen(_ROOT_RACINE)) == 0) { |
|
| 72 | + $fi = substr($fi, strlen(_ROOT_RACINE)); |
|
| 73 | + } |
|
| 74 | + $fu = $debug[2]['function'] ?? ''; |
|
| 75 | + $debugverb = "$fi:L$l:$fu" . '():'; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $m = date('Y-m-d H:i:s') . ' ' . ($GLOBALS['ip'] ?? '') . ' ' . $pid . ' ' |
|
| 79 | + //distinguer les logs prives et publics dans les grep |
|
| 80 | + . $debugverb |
|
| 81 | + . (test_espace_prive() ? ':Pri:' : ':Pub:') |
|
| 82 | + . preg_replace("/\n*$/", "\n", $message); |
|
| 83 | + |
|
| 84 | + |
|
| 85 | + if ( |
|
| 86 | + @is_readable($logfile) |
|
| 87 | + and (!$s = @filesize($logfile) or $s > $GLOBALS['taille_des_logs'] * 1024) |
|
| 88 | + ) { |
|
| 89 | + $rotate = $GLOBALS['nombre_de_logs']; |
|
| 90 | + $m .= "[-- rotate --]\n"; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + $f = @fopen($logfile, 'ab'); |
|
| 94 | + if ($f) { |
|
| 95 | + fputs($f, (defined('_LOG_BRUT') and _LOG_BRUT) ? $m : str_replace('<', '<', $m)); |
|
| 96 | + fclose($f); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if ( |
|
| 100 | + $rotate-- > 0 |
|
| 101 | + and function_exists('spip_unlink') |
|
| 102 | + ) { |
|
| 103 | + spip_unlink($logfile . '.' . $rotate); |
|
| 104 | + while ($rotate--) { |
|
| 105 | + @rename($logfile . ($rotate ? '.' . $rotate : ''), $logfile . '.' . ($rotate + 1)); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + // Dupliquer les erreurs specifiques dans le log general |
|
| 110 | + if ( |
|
| 111 | + defined('_FILE_LOG') |
|
| 112 | + and ($logname !== _FILE_LOG) |
|
| 113 | + ) { |
|
| 114 | + inc_log_dist($logname == 'maj' ? 'cf maj.log' : $message); |
|
| 115 | + } |
|
| 116 | + $debugverb = ''; |
|
| 117 | 117 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Mail |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function nettoyer_titre_email($titre) { |
| 35 | - return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre)))); |
|
| 35 | + return str_replace("\n", ' ', nettoyer_caracteres_mail(textebrut(corriger_typo($titre)))); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | /** |
@@ -48,23 +48,23 @@ discard block |
||
| 48 | 48 | */ |
| 49 | 49 | function nettoyer_caracteres_mail($t) { |
| 50 | 50 | |
| 51 | - $t = filtrer_entites($t); |
|
| 51 | + $t = filtrer_entites($t); |
|
| 52 | 52 | |
| 53 | - if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | - $t = str_replace( |
|
| 55 | - ['’', '“', '”'], |
|
| 56 | - ["'", '"', '"'], |
|
| 57 | - $t |
|
| 58 | - ); |
|
| 59 | - } |
|
| 53 | + if ($GLOBALS['meta']['charset'] <> 'utf-8') { |
|
| 54 | + $t = str_replace( |
|
| 55 | + ['’', '“', '”'], |
|
| 56 | + ["'", '"', '"'], |
|
| 57 | + $t |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $t = str_replace( |
|
| 62 | - ['—', '&endash;'], |
|
| 63 | - ['--', '-'], |
|
| 64 | - $t |
|
| 65 | - ); |
|
| 61 | + $t = str_replace( |
|
| 62 | + ['—', '&endash;'], |
|
| 63 | + ['--', '-'], |
|
| 64 | + $t |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - return $t; |
|
| 67 | + return $t; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -97,86 +97,86 @@ discard block |
||
| 97 | 97 | */ |
| 98 | 98 | function inc_envoyer_mail_dist($destinataire, $sujet, $corps, $from = '', $headers = '') { |
| 99 | 99 | |
| 100 | - if (!email_valide($destinataire)) { |
|
| 101 | - return false; |
|
| 102 | - } |
|
| 103 | - if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | - return false; |
|
| 105 | - } // tres fort |
|
| 106 | - |
|
| 107 | - // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | - // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | - |
|
| 110 | - $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | - if (!email_valide($email_envoi)) { |
|
| 112 | - spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | - $email_envoi = $destinataire; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $parts = ''; |
|
| 117 | - if (is_array($corps)) { |
|
| 118 | - $texte = $corps['texte']; |
|
| 119 | - $from = ($corps['from'] ?? $from); |
|
| 120 | - $headers = ($corps['headers'] ?? $headers); |
|
| 121 | - if (is_array($headers)) { |
|
| 122 | - $headers = implode("\n", $headers); |
|
| 123 | - } |
|
| 124 | - if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | - $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | - } |
|
| 127 | - } else { |
|
| 128 | - $texte = $corps; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - if (!$from) { |
|
| 132 | - $from = $email_envoi; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | - if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | - $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // nettoyer les é ’, &emdash; etc... |
|
| 141 | - // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | - // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | - $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | - $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | - |
|
| 146 | - // encoder le sujet si possible selon la RFC |
|
| 147 | - if (init_mb_string()) { |
|
| 148 | - # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | - # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | - $charset = $GLOBALS['meta']['charset']; |
|
| 151 | - mb_internal_encoding($charset); |
|
| 152 | - $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | - mb_internal_encoding('utf-8'); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 157 | - $texte = wordwrap($texte); |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 161 | - |
|
| 162 | - if (_OS_SERVEUR == 'windows') { |
|
| 163 | - $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 164 | - $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 165 | - $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 169 | - // mode TEST : forcer l'email |
|
| 170 | - if (defined('_TEST_EMAIL_DEST')) { |
|
| 171 | - if (!_TEST_EMAIL_DEST) { |
|
| 172 | - return false; |
|
| 173 | - } else { |
|
| 174 | - $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 175 | - $destinataire = _TEST_EMAIL_DEST; |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return @mail($destinataire, $sujet, $texte, $headers); |
|
| 100 | + if (!email_valide($destinataire)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 103 | + if ($destinataire == _T('info_mail_fournisseur')) { |
|
| 104 | + return false; |
|
| 105 | + } // tres fort |
|
| 106 | + |
|
| 107 | + // Fournir si possible un Message-Id: conforme au RFC1036, |
|
| 108 | + // sinon SpamAssassin denoncera un MSGID_FROM_MTA_HEADER |
|
| 109 | + |
|
| 110 | + $email_envoi = $GLOBALS['meta']['email_envoi']; |
|
| 111 | + if (!email_valide($email_envoi)) { |
|
| 112 | + spip_log('Meta email_envoi invalide. Le mail sera probablement vu comme spam.'); |
|
| 113 | + $email_envoi = $destinataire; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $parts = ''; |
|
| 117 | + if (is_array($corps)) { |
|
| 118 | + $texte = $corps['texte']; |
|
| 119 | + $from = ($corps['from'] ?? $from); |
|
| 120 | + $headers = ($corps['headers'] ?? $headers); |
|
| 121 | + if (is_array($headers)) { |
|
| 122 | + $headers = implode("\n", $headers); |
|
| 123 | + } |
|
| 124 | + if (isset($corps['pieces_jointes']) and function_exists('mail_embarquer_pieces_jointes')) { |
|
| 125 | + $parts = mail_embarquer_pieces_jointes($corps['pieces_jointes']); |
|
| 126 | + } |
|
| 127 | + } else { |
|
| 128 | + $texte = $corps; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + if (!$from) { |
|
| 132 | + $from = $email_envoi; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // ceci est la RegExp NO_REAL_NAME faisant hurler SpamAssassin |
|
| 136 | + if (preg_match('/^["\s]*\<?\S+\@\S+\>?\s*$/', $from)) { |
|
| 137 | + $from .= ' (' . str_replace(')', '', translitteration(str_replace('@', ' at ', $from))) . ')'; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // nettoyer les é ’, &emdash; etc... |
|
| 141 | + // les 'cliquer ici' etc sont a eviter; voir: |
|
| 142 | + // http://mta.org.ua/spamassassin-2.55/stuff/wiki.CustomRulesets/20050914/rules/french_rules.cf |
|
| 143 | + $texte = nettoyer_caracteres_mail($texte); |
|
| 144 | + $sujet = nettoyer_caracteres_mail($sujet); |
|
| 145 | + |
|
| 146 | + // encoder le sujet si possible selon la RFC |
|
| 147 | + if (init_mb_string()) { |
|
| 148 | + # un bug de mb_string casse mb_encode_mimeheader si l'encoding interne |
|
| 149 | + # est UTF-8 et le charset iso-8859-1 (constate php5-mac ; php4.3-debian) |
|
| 150 | + $charset = $GLOBALS['meta']['charset']; |
|
| 151 | + mb_internal_encoding($charset); |
|
| 152 | + $sujet = mb_encode_mimeheader($sujet, $charset, 'Q', "\n"); |
|
| 153 | + mb_internal_encoding('utf-8'); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + if (function_exists('wordwrap') && (preg_match(',multipart/mixed,', $headers) == 0)) { |
|
| 157 | + $texte = wordwrap($texte); |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + [$headers, $texte] = mail_normaliser_headers($headers, $from, $destinataire, $texte, $parts); |
|
| 161 | + |
|
| 162 | + if (_OS_SERVEUR == 'windows') { |
|
| 163 | + $texte = preg_replace("@\r*\n@", "\r\n", $texte); |
|
| 164 | + $headers = preg_replace("@\r*\n@", "\r\n", $headers); |
|
| 165 | + $sujet = preg_replace("@\r*\n@", "\r\n", $sujet); |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + spip_log("mail $destinataire\n$sujet\n$headers", 'mails'); |
|
| 169 | + // mode TEST : forcer l'email |
|
| 170 | + if (defined('_TEST_EMAIL_DEST')) { |
|
| 171 | + if (!_TEST_EMAIL_DEST) { |
|
| 172 | + return false; |
|
| 173 | + } else { |
|
| 174 | + $texte = "Dest : $destinataire\r\n" . $texte; |
|
| 175 | + $destinataire = _TEST_EMAIL_DEST; |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return @mail($destinataire, $sujet, $texte, $headers); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -190,58 +190,58 @@ discard block |
||
| 190 | 190 | * @return array |
| 191 | 191 | */ |
| 192 | 192 | function mail_normaliser_headers($headers, $from, $to, $texte, $parts = '') { |
| 193 | - $charset = $GLOBALS['meta']['charset']; |
|
| 194 | - |
|
| 195 | - // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 196 | - if (strpos($headers, 'Content-Type: ') === false) { |
|
| 197 | - $type = |
|
| 198 | - "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 199 | - "Content-Transfer-Encoding: 8bit\n"; |
|
| 200 | - } else { |
|
| 201 | - $type = ''; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - // calculer un identifiant unique |
|
| 205 | - // Marie Toto <[email protected]> => @toto.com |
|
| 206 | - if (preg_match('/@[^\s>]+/', $from, $domain)) { |
|
| 207 | - $domain = $domain[0]; |
|
| 208 | - } |
|
| 209 | - else { |
|
| 210 | - $domain = '@unknown-' . md5($from) . '.org'; |
|
| 211 | - } |
|
| 212 | - $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 213 | - |
|
| 214 | - // Si multi-part, s'en servir comme borne ... |
|
| 215 | - if ($parts) { |
|
| 216 | - $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 217 | - foreach ($parts as $part) { |
|
| 218 | - $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 219 | - $e = join("\n", $part[0]); |
|
| 220 | - $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 221 | - } |
|
| 222 | - $texte .= "\n\n--$uniq--\n"; |
|
| 223 | - // Si boundary n'est pas entre guillemets, |
|
| 224 | - // elle est comprise mais le charset est ignoree ! |
|
| 225 | - $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // .. et s'en servir pour plaire a SpamAssassin |
|
| 229 | - |
|
| 230 | - $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 231 | - |
|
| 232 | - // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 233 | - // sauf si deja mis par l'envoyeur |
|
| 234 | - $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 235 | - |
|
| 236 | - // Nettoyer les en-tetes envoyees |
|
| 237 | - // Ajouter le \n final |
|
| 238 | - if (strlen($headers = trim($headers))) { |
|
| 239 | - $headers .= "\n"; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // Et mentionner l'indeboulonable nomenclature ratee |
|
| 243 | - |
|
| 244 | - $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 245 | - |
|
| 246 | - return [$headers, $texte]; |
|
| 193 | + $charset = $GLOBALS['meta']['charset']; |
|
| 194 | + |
|
| 195 | + // Ajouter le Content-Type et consort s'il n'y est pas deja |
|
| 196 | + if (strpos($headers, 'Content-Type: ') === false) { |
|
| 197 | + $type = |
|
| 198 | + "Content-Type: text/plain;charset=\"$charset\";\n" . |
|
| 199 | + "Content-Transfer-Encoding: 8bit\n"; |
|
| 200 | + } else { |
|
| 201 | + $type = ''; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + // calculer un identifiant unique |
|
| 205 | + // Marie Toto <[email protected]> => @toto.com |
|
| 206 | + if (preg_match('/@[^\s>]+/', $from, $domain)) { |
|
| 207 | + $domain = $domain[0]; |
|
| 208 | + } |
|
| 209 | + else { |
|
| 210 | + $domain = '@unknown-' . md5($from) . '.org'; |
|
| 211 | + } |
|
| 212 | + $uniq = random_int(0, mt_getrandmax()) . '_' . md5($to . $texte) . $domain; |
|
| 213 | + |
|
| 214 | + // Si multi-part, s'en servir comme borne ... |
|
| 215 | + if ($parts) { |
|
| 216 | + $texte = "--$uniq\n$type\n" . $texte . "\n"; |
|
| 217 | + foreach ($parts as $part) { |
|
| 218 | + $n = strlen($part[1]) . ($part[0] ? "\n" : ''); |
|
| 219 | + $e = join("\n", $part[0]); |
|
| 220 | + $texte .= "\n--$uniq\nContent-Length: $n$e\n\n" . $part[1]; |
|
| 221 | + } |
|
| 222 | + $texte .= "\n\n--$uniq--\n"; |
|
| 223 | + // Si boundary n'est pas entre guillemets, |
|
| 224 | + // elle est comprise mais le charset est ignoree ! |
|
| 225 | + $type = "Content-Type: multipart/mixed; boundary=\"$uniq\"\n"; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // .. et s'en servir pour plaire a SpamAssassin |
|
| 229 | + |
|
| 230 | + $mid = 'Message-Id: <' . $uniq . '>'; |
|
| 231 | + |
|
| 232 | + // indispensable pour les sites qui collent d'office From: serveur-http |
|
| 233 | + // sauf si deja mis par l'envoyeur |
|
| 234 | + $rep = (strpos($headers, 'Reply-To:') !== false) ? '' : "Reply-To: $from\n"; |
|
| 235 | + |
|
| 236 | + // Nettoyer les en-tetes envoyees |
|
| 237 | + // Ajouter le \n final |
|
| 238 | + if (strlen($headers = trim($headers))) { |
|
| 239 | + $headers .= "\n"; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // Et mentionner l'indeboulonable nomenclature ratee |
|
| 243 | + |
|
| 244 | + $headers .= "From: $from\n$type$rep$mid\nMIME-Version: 1.0\n"; |
|
| 245 | + |
|
| 246 | + return [$headers, $texte]; |
|
| 247 | 247 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | function set_spip_doc(?string $fichier): string { |
| 33 | - if ($fichier and strpos($fichier, (string) _DIR_IMG) === 0) { |
|
| 34 | - return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | - } else { |
|
| 36 | - // ex: fichier distant |
|
| 37 | - return $fichier ?? ''; |
|
| 38 | - } |
|
| 33 | + if ($fichier and strpos($fichier, (string) _DIR_IMG) === 0) { |
|
| 34 | + return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | + } else { |
|
| 36 | + // ex: fichier distant |
|
| 37 | + return $fichier ?? ''; |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | * @return bool|string |
| 48 | 48 | */ |
| 49 | 49 | function get_spip_doc(?string $fichier) { |
| 50 | - if ($fichier === null) { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // fichier distant |
|
| 55 | - if (tester_url_absolue($fichier)) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // gestion d'erreurs, fichier='' |
|
| 60 | - if (!strlen($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) { |
|
| 65 | - $fichier = _DIR_IMG . $fichier; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // fichier normal |
|
| 69 | - return $fichier; |
|
| 50 | + if ($fichier === null) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // fichier distant |
|
| 55 | + if (tester_url_absolue($fichier)) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // gestion d'erreurs, fichier='' |
|
| 60 | + if (!strlen($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) { |
|
| 65 | + $fichier = _DIR_IMG . $fichier; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // fichier normal |
|
| 69 | + return $fichier; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -80,26 +80,26 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | function creer_repertoire_documents($ext) { |
| 83 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 84 | - |
|
| 85 | - if (!$ext or !$rep) { |
|
| 86 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 87 | - exit; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 91 | - // par exemple acces_restreint |
|
| 92 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 93 | - if ( |
|
| 94 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 95 | - and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 96 | - and $ext !== 'logo' |
|
| 97 | - ) { |
|
| 98 | - include_spip('inc/acces'); |
|
| 99 | - verifier_htaccess($rep); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return $rep; |
|
| 83 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 84 | + |
|
| 85 | + if (!$ext or !$rep) { |
|
| 86 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 87 | + exit; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 91 | + // par exemple acces_restreint |
|
| 92 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 93 | + if ( |
|
| 94 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 95 | + and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 96 | + and $ext !== 'logo' |
|
| 97 | + ) { |
|
| 98 | + include_spip('inc/acces'); |
|
| 99 | + verifier_htaccess($rep); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return $rep; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,22 +108,22 @@ discard block |
||
| 108 | 108 | * @param string $nom |
| 109 | 109 | */ |
| 110 | 110 | function effacer_repertoire_temporaire($nom) { |
| 111 | - if ($d = opendir($nom)) { |
|
| 112 | - while (($f = readdir($d)) !== false) { |
|
| 113 | - if (is_file("$nom/$f")) { |
|
| 114 | - spip_unlink("$nom/$f"); |
|
| 115 | - } else { |
|
| 116 | - if ( |
|
| 117 | - $f <> '.' and $f <> '..' |
|
| 118 | - and is_dir("$nom/$f") |
|
| 119 | - ) { |
|
| 120 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - closedir($d); |
|
| 126 | - @rmdir($nom); |
|
| 111 | + if ($d = opendir($nom)) { |
|
| 112 | + while (($f = readdir($d)) !== false) { |
|
| 113 | + if (is_file("$nom/$f")) { |
|
| 114 | + spip_unlink("$nom/$f"); |
|
| 115 | + } else { |
|
| 116 | + if ( |
|
| 117 | + $f <> '.' and $f <> '..' |
|
| 118 | + and is_dir("$nom/$f") |
|
| 119 | + ) { |
|
| 120 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + closedir($d); |
|
| 126 | + @rmdir($nom); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // |
@@ -140,45 +140,45 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 142 | 142 | |
| 143 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 144 | - $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 145 | - |
|
| 146 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 147 | - $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 148 | - $dest = translitteration($dest); |
|
| 149 | - $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 150 | - |
|
| 151 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 152 | - // pour les images transformees par rotation (action/documenter) |
|
| 153 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 154 | - |
|
| 155 | - while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 156 | - if ( |
|
| 157 | - !function_exists('verifier_upload_autorise') |
|
| 158 | - or !$r = verifier_upload_autorise($dest) |
|
| 159 | - or $r['autozip'] |
|
| 160 | - ) { |
|
| 161 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 162 | - break; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 166 | - $ext = $m[1] . '.' . $ext; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 171 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 172 | - return $source; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 176 | - $n = 0; |
|
| 177 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 178 | - ; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return deplacer_fichier_upload($source, $newFile); |
|
| 143 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 144 | + $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 145 | + |
|
| 146 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 147 | + $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 148 | + $dest = translitteration($dest); |
|
| 149 | + $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 150 | + |
|
| 151 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 152 | + // pour les images transformees par rotation (action/documenter) |
|
| 153 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 154 | + |
|
| 155 | + while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 156 | + if ( |
|
| 157 | + !function_exists('verifier_upload_autorise') |
|
| 158 | + or !$r = verifier_upload_autorise($dest) |
|
| 159 | + or $r['autozip'] |
|
| 160 | + ) { |
|
| 161 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 162 | + break; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 166 | + $ext = $m[1] . '.' . $ext; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 171 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 172 | + return $source; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 176 | + $n = 0; |
|
| 177 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 178 | + ; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return deplacer_fichier_upload($source, $newFile); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -193,28 +193,28 @@ discard block |
||
| 193 | 193 | * @return bool|string |
| 194 | 194 | */ |
| 195 | 195 | function determine_upload($type = '') { |
| 196 | - if (!function_exists('autoriser')) { |
|
| 197 | - include_spip('inc/autoriser'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ( |
|
| 201 | - !autoriser('chargerftp') |
|
| 202 | - or $type == 'logos' |
|
| 203 | - ) { # on ne le permet pas pour les logos |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $repertoire = _DIR_TRANSFERT; |
|
| 208 | - if (!@is_dir($repertoire)) { |
|
| 209 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 210 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 214 | - return $repertoire; |
|
| 215 | - } else { |
|
| 216 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 217 | - } |
|
| 196 | + if (!function_exists('autoriser')) { |
|
| 197 | + include_spip('inc/autoriser'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ( |
|
| 201 | + !autoriser('chargerftp') |
|
| 202 | + or $type == 'logos' |
|
| 203 | + ) { # on ne le permet pas pour les logos |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $repertoire = _DIR_TRANSFERT; |
|
| 208 | + if (!@is_dir($repertoire)) { |
|
| 209 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 210 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 214 | + return $repertoire; |
|
| 215 | + } else { |
|
| 216 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -233,35 +233,35 @@ discard block |
||
| 233 | 233 | * @return bool|mixed|string |
| 234 | 234 | */ |
| 235 | 235 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 236 | - // Securite |
|
| 237 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 238 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 239 | - } else { |
|
| 240 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - if ($move) { |
|
| 244 | - $ok = @rename($source, $dest); |
|
| 245 | - } else { |
|
| 246 | - $ok = @copy($source, $dest); |
|
| 247 | - } |
|
| 248 | - if (!$ok) { |
|
| 249 | - $ok = @move_uploaded_file($source, $dest); |
|
| 250 | - } |
|
| 251 | - if ($ok) { |
|
| 252 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 253 | - } else { |
|
| 254 | - $f = @fopen($dest, 'w'); |
|
| 255 | - if ($f) { |
|
| 256 | - fclose($f); |
|
| 257 | - } else { |
|
| 258 | - include_spip('inc/flock'); |
|
| 259 | - raler_fichier($dest); |
|
| 260 | - } |
|
| 261 | - spip_unlink($dest); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $ok ? $dest : false; |
|
| 236 | + // Securite |
|
| 237 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 238 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 239 | + } else { |
|
| 240 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + if ($move) { |
|
| 244 | + $ok = @rename($source, $dest); |
|
| 245 | + } else { |
|
| 246 | + $ok = @copy($source, $dest); |
|
| 247 | + } |
|
| 248 | + if (!$ok) { |
|
| 249 | + $ok = @move_uploaded_file($source, $dest); |
|
| 250 | + } |
|
| 251 | + if ($ok) { |
|
| 252 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 253 | + } else { |
|
| 254 | + $f = @fopen($dest, 'w'); |
|
| 255 | + if ($f) { |
|
| 256 | + fclose($f); |
|
| 257 | + } else { |
|
| 258 | + include_spip('inc/flock'); |
|
| 259 | + raler_fichier($dest); |
|
| 260 | + } |
|
| 261 | + spip_unlink($dest); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $ok ? $dest : false; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -285,60 +285,60 @@ discard block |
||
| 285 | 285 | */ |
| 286 | 286 | function check_upload_error($error, $msg = '', $return = false) { |
| 287 | 287 | |
| 288 | - if (!$error) { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 293 | - |
|
| 294 | - switch ($error) { |
|
| 295 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 296 | - return true; |
|
| 297 | - |
|
| 298 | - # on peut affiner les differents messages d'erreur |
|
| 299 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 300 | - $msg = _T( |
|
| 301 | - 'upload_limit', |
|
| 302 | - ['max' => ini_get('upload_max_filesize')] |
|
| 303 | - ); |
|
| 304 | - break; |
|
| 305 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 306 | - $msg = _T( |
|
| 307 | - 'upload_limit', |
|
| 308 | - ['max' => ini_get('upload_max_filesize')] |
|
| 309 | - ); |
|
| 310 | - break; |
|
| 311 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 312 | - $msg = _T( |
|
| 313 | - 'upload_limit', |
|
| 314 | - ['max' => ini_get('upload_max_filesize')] |
|
| 315 | - ); |
|
| 316 | - break; |
|
| 317 | - |
|
| 318 | - default: /* autre */ |
|
| 319 | - if (!$msg) { |
|
| 320 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 321 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 322 | - } |
|
| 323 | - break; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - spip_log("erreur upload $error"); |
|
| 327 | - if ($return) { |
|
| 328 | - return $msg; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - if (_request('iframe') == 'iframe') { |
|
| 332 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 333 | - exit; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - include_spip('inc/minipres'); |
|
| 337 | - echo minipres( |
|
| 338 | - $msg, |
|
| 339 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 340 | - ); |
|
| 341 | - exit; |
|
| 288 | + if (!$error) { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 293 | + |
|
| 294 | + switch ($error) { |
|
| 295 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 296 | + return true; |
|
| 297 | + |
|
| 298 | + # on peut affiner les differents messages d'erreur |
|
| 299 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 300 | + $msg = _T( |
|
| 301 | + 'upload_limit', |
|
| 302 | + ['max' => ini_get('upload_max_filesize')] |
|
| 303 | + ); |
|
| 304 | + break; |
|
| 305 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 306 | + $msg = _T( |
|
| 307 | + 'upload_limit', |
|
| 308 | + ['max' => ini_get('upload_max_filesize')] |
|
| 309 | + ); |
|
| 310 | + break; |
|
| 311 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 312 | + $msg = _T( |
|
| 313 | + 'upload_limit', |
|
| 314 | + ['max' => ini_get('upload_max_filesize')] |
|
| 315 | + ); |
|
| 316 | + break; |
|
| 317 | + |
|
| 318 | + default: /* autre */ |
|
| 319 | + if (!$msg) { |
|
| 320 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 321 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 322 | + } |
|
| 323 | + break; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + spip_log("erreur upload $error"); |
|
| 327 | + if ($return) { |
|
| 328 | + return $msg; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + if (_request('iframe') == 'iframe') { |
|
| 332 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 333 | + exit; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + include_spip('inc/minipres'); |
|
| 337 | + echo minipres( |
|
| 338 | + $msg, |
|
| 339 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 340 | + ); |
|
| 341 | + exit; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -355,24 +355,24 @@ discard block |
||
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | 357 | function corriger_extension($ext) { |
| 358 | - $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 359 | - switch ($ext) { |
|
| 360 | - case 'htm': |
|
| 361 | - $ext = 'html'; |
|
| 362 | - break; |
|
| 363 | - case 'jpeg': |
|
| 364 | - $ext = 'jpg'; |
|
| 365 | - break; |
|
| 366 | - case 'tiff': |
|
| 367 | - $ext = 'tif'; |
|
| 368 | - break; |
|
| 369 | - case 'aif': |
|
| 370 | - $ext = 'aiff'; |
|
| 371 | - break; |
|
| 372 | - case 'mpeg': |
|
| 373 | - $ext = 'mpg'; |
|
| 374 | - break; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return $ext; |
|
| 358 | + $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 359 | + switch ($ext) { |
|
| 360 | + case 'htm': |
|
| 361 | + $ext = 'html'; |
|
| 362 | + break; |
|
| 363 | + case 'jpeg': |
|
| 364 | + $ext = 'jpg'; |
|
| 365 | + break; |
|
| 366 | + case 'tiff': |
|
| 367 | + $ext = 'tif'; |
|
| 368 | + break; |
|
| 369 | + case 'aif': |
|
| 370 | + $ext = 'aiff'; |
|
| 371 | + break; |
|
| 372 | + case 'mpeg': |
|
| 373 | + $ext = 'mpg'; |
|
| 374 | + break; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return $ext; |
|
| 378 | 378 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/charsets'); |
@@ -42,22 +42,22 @@ discard block |
||
| 42 | 42 | * @return array |
| 43 | 43 | */ |
| 44 | 44 | function importer_csv_importcharset($texte, $definir_charset_source = false) { |
| 45 | - // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | - static $charset_source = 'iso-8859-1'; |
|
| 47 | - if ($definir_charset_source) { |
|
| 48 | - if ($definir_charset_source === true) { |
|
| 49 | - $charset_source = 'iso-8859-1'; |
|
| 50 | - } else { |
|
| 51 | - $charset_source = $definir_charset_source; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | - if (is_utf8($texte)) { |
|
| 56 | - $charset = 'utf-8'; |
|
| 57 | - } else { |
|
| 58 | - $charset = $charset_source; |
|
| 59 | - } |
|
| 60 | - return importer_charset($texte, $charset); |
|
| 45 | + // le plus frequent, en particulier avec les trucs de ms@@@ |
|
| 46 | + static $charset_source = 'iso-8859-1'; |
|
| 47 | + if ($definir_charset_source) { |
|
| 48 | + if ($definir_charset_source === true) { |
|
| 49 | + $charset_source = 'iso-8859-1'; |
|
| 50 | + } else { |
|
| 51 | + $charset_source = $definir_charset_source; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + // mais open-office sait faire mieux, donc mefiance ! |
|
| 55 | + if (is_utf8($texte)) { |
|
| 56 | + $charset = 'utf-8'; |
|
| 57 | + } else { |
|
| 58 | + $charset = $charset_source; |
|
| 59 | + } |
|
| 60 | + return importer_charset($texte, $charset); |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | /** |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return string |
| 69 | 69 | */ |
| 70 | 70 | function importer_csv_nettoie_key($key) { |
| 71 | - return translitteration($key); |
|
| 71 | + return translitteration($key); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -87,77 +87,77 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function inc_importer_csv_dist($file, $options = []) { |
| 89 | 89 | |
| 90 | - // support ancienne syntaxe |
|
| 91 | - // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | - if (!is_array($options)) { |
|
| 93 | - $args = func_get_args(); |
|
| 94 | - $options = []; |
|
| 95 | - foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | - if (!empty($args[$k])) { |
|
| 97 | - $options[$option] = $args[$k]; |
|
| 98 | - } |
|
| 99 | - } |
|
| 100 | - } |
|
| 90 | + // support ancienne syntaxe |
|
| 91 | + // inc_importer_csv_dist($file, $head = false, $delim = ',', $enclos = '"', $len = 10000, $charset_source = '') |
|
| 92 | + if (!is_array($options)) { |
|
| 93 | + $args = func_get_args(); |
|
| 94 | + $options = []; |
|
| 95 | + foreach ([1 => 'head', 2 => 'delim', 3 => 'enclos', 4 => 'len', 5 => 'charset_source'] as $k => $option) { |
|
| 96 | + if (!empty($args[$k])) { |
|
| 97 | + $options[$option] = $args[$k]; |
|
| 98 | + } |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - $default_options = [ |
|
| 103 | - 'head' => false, |
|
| 104 | - 'delim' => ',', |
|
| 105 | - 'enclos' => '"', |
|
| 106 | - 'len' => 10000, |
|
| 107 | - 'charset_source' => '', |
|
| 108 | - ]; |
|
| 109 | - $options = array_merge($default_options, $options); |
|
| 102 | + $default_options = [ |
|
| 103 | + 'head' => false, |
|
| 104 | + 'delim' => ',', |
|
| 105 | + 'enclos' => '"', |
|
| 106 | + 'len' => 10000, |
|
| 107 | + 'charset_source' => '', |
|
| 108 | + ]; |
|
| 109 | + $options = array_merge($default_options, $options); |
|
| 110 | 110 | |
| 111 | 111 | |
| 112 | - $return = false; |
|
| 113 | - if ( |
|
| 114 | - @file_exists($file) |
|
| 115 | - and $handle = fopen($file, 'r') |
|
| 116 | - ) { |
|
| 117 | - if ($options['charset_source']) { |
|
| 118 | - importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | - } |
|
| 120 | - if ($options['head']) { |
|
| 121 | - $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | - if ($header) { |
|
| 123 | - $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | - $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | - $header_type = []; |
|
| 126 | - foreach ($header as $heading) { |
|
| 127 | - if (!isset($header_type[$heading])) { |
|
| 128 | - $header_type[$heading] = 'scalar'; |
|
| 129 | - } else { |
|
| 130 | - $header_type[$heading] = 'array'; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - } |
|
| 112 | + $return = false; |
|
| 113 | + if ( |
|
| 114 | + @file_exists($file) |
|
| 115 | + and $handle = fopen($file, 'r') |
|
| 116 | + ) { |
|
| 117 | + if ($options['charset_source']) { |
|
| 118 | + importer_csv_importcharset('', $options['charset_source']); |
|
| 119 | + } |
|
| 120 | + if ($options['head']) { |
|
| 121 | + $header = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos']); |
|
| 122 | + if ($header) { |
|
| 123 | + $header = array_map('importer_csv_importcharset', $header); |
|
| 124 | + $header = array_map('importer_csv_nettoie_key', $header); |
|
| 125 | + $header_type = []; |
|
| 126 | + foreach ($header as $heading) { |
|
| 127 | + if (!isset($header_type[$heading])) { |
|
| 128 | + $header_type[$heading] = 'scalar'; |
|
| 129 | + } else { |
|
| 130 | + $header_type[$heading] = 'array'; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | - $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | - if ($options['head'] and isset($header)) { |
|
| 139 | - $row = []; |
|
| 140 | - foreach ($header as $key => $heading) { |
|
| 141 | - if ($header_type[$heading] == 'array') { |
|
| 142 | - if (!isset($row[$heading])) { |
|
| 143 | - $row[$heading] = []; |
|
| 144 | - } |
|
| 145 | - if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | - $row[$heading][] = $data[$key]; |
|
| 147 | - } |
|
| 148 | - } else { |
|
| 149 | - $row[$heading] = $data[$key] ?? ''; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - $return[] = $row; |
|
| 153 | - } else { |
|
| 154 | - $return[] = $data; |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - if ($options['charset_source']) { |
|
| 158 | - importer_csv_importcharset('', true); |
|
| 159 | - } |
|
| 160 | - } |
|
| 136 | + while (($data = fgetcsv($handle, $options['len'], $options['delim'], $options['enclos'])) !== false) { |
|
| 137 | + $data = array_map('importer_csv_importcharset', $data); |
|
| 138 | + if ($options['head'] and isset($header)) { |
|
| 139 | + $row = []; |
|
| 140 | + foreach ($header as $key => $heading) { |
|
| 141 | + if ($header_type[$heading] == 'array') { |
|
| 142 | + if (!isset($row[$heading])) { |
|
| 143 | + $row[$heading] = []; |
|
| 144 | + } |
|
| 145 | + if (isset($data[$key]) and strlen($data[$key])) { |
|
| 146 | + $row[$heading][] = $data[$key]; |
|
| 147 | + } |
|
| 148 | + } else { |
|
| 149 | + $row[$heading] = $data[$key] ?? ''; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + $return[] = $row; |
|
| 153 | + } else { |
|
| 154 | + $return[] = $data; |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + if ($options['charset_source']) { |
|
| 158 | + importer_csv_importcharset('', true); |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $return; |
|
| 162 | + return $return; |
|
| 163 | 163 | } |