@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/actions'); |
@@ -45,30 +45,30 @@ discard block |
||
| 45 | 45 | * Environnement du formulaire |
| 46 | 46 | **/ |
| 47 | 47 | function formulaires_editer_article_charger_dist( |
| 48 | - $id_article = 'new', |
|
| 49 | - $id_rubrique = 0, |
|
| 50 | - $retour = '', |
|
| 51 | - $lier_trad = 0, |
|
| 52 | - $config_fonc = 'articles_edit_config', |
|
| 53 | - $row = [], |
|
| 54 | - $hidden = '' |
|
| 48 | + $id_article = 'new', |
|
| 49 | + $id_rubrique = 0, |
|
| 50 | + $retour = '', |
|
| 51 | + $lier_trad = 0, |
|
| 52 | + $config_fonc = 'articles_edit_config', |
|
| 53 | + $row = [], |
|
| 54 | + $hidden = '' |
|
| 55 | 55 | ) { |
| 56 | - $valeurs = formulaires_editer_objet_charger( |
|
| 57 | - 'article', |
|
| 58 | - $id_article, |
|
| 59 | - $id_rubrique, |
|
| 60 | - $lier_trad, |
|
| 61 | - $retour, |
|
| 62 | - $config_fonc, |
|
| 63 | - $row, |
|
| 64 | - $hidden |
|
| 65 | - ); |
|
| 56 | + $valeurs = formulaires_editer_objet_charger( |
|
| 57 | + 'article', |
|
| 58 | + $id_article, |
|
| 59 | + $id_rubrique, |
|
| 60 | + $lier_trad, |
|
| 61 | + $retour, |
|
| 62 | + $config_fonc, |
|
| 63 | + $row, |
|
| 64 | + $hidden |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 68 | - $valeurs['editable'] = ''; |
|
| 69 | - } |
|
| 67 | + if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 68 | + $valeurs['editable'] = ''; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $valeurs; |
|
| 71 | + return $valeurs; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -93,15 +93,15 @@ discard block |
||
| 93 | 93 | * Hash du formulaire |
| 94 | 94 | */ |
| 95 | 95 | function formulaires_editer_article_identifier_dist( |
| 96 | - $id_article = 'new', |
|
| 97 | - $id_rubrique = 0, |
|
| 98 | - $retour = '', |
|
| 99 | - $lier_trad = 0, |
|
| 100 | - $config_fonc = 'articles_edit_config', |
|
| 101 | - $row = [], |
|
| 102 | - $hidden = '' |
|
| 96 | + $id_article = 'new', |
|
| 97 | + $id_rubrique = 0, |
|
| 98 | + $retour = '', |
|
| 99 | + $lier_trad = 0, |
|
| 100 | + $config_fonc = 'articles_edit_config', |
|
| 101 | + $row = [], |
|
| 102 | + $hidden = '' |
|
| 103 | 103 | ) { |
| 104 | - return serialize([intval($id_article), $lier_trad]); |
|
| 104 | + return serialize([intval($id_article), $lier_trad]); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -114,12 +114,12 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | function articles_edit_config(array $row): array { |
| 116 | 116 | |
| 117 | - $config = []; |
|
| 118 | - $config['lignes'] = 8; |
|
| 119 | - $config['langue'] = $GLOBALS['spip_lang']; |
|
| 120 | - $config['restreint'] = ($row['statut'] === 'publie'); |
|
| 117 | + $config = []; |
|
| 118 | + $config['lignes'] = 8; |
|
| 119 | + $config['langue'] = $GLOBALS['spip_lang']; |
|
| 120 | + $config['restreint'] = ($row['statut'] === 'publie'); |
|
| 121 | 121 | |
| 122 | - return $config; |
|
| 122 | + return $config; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | /** |
@@ -145,43 +145,43 @@ discard block |
||
| 145 | 145 | * Erreurs du formulaire |
| 146 | 146 | **/ |
| 147 | 147 | function formulaires_editer_article_verifier_dist( |
| 148 | - $id_article = 'new', |
|
| 149 | - $id_rubrique = 0, |
|
| 150 | - $retour = '', |
|
| 151 | - $lier_trad = 0, |
|
| 152 | - $config_fonc = 'articles_edit_config', |
|
| 153 | - $row = [], |
|
| 154 | - $hidden = '' |
|
| 148 | + $id_article = 'new', |
|
| 149 | + $id_rubrique = 0, |
|
| 150 | + $retour = '', |
|
| 151 | + $lier_trad = 0, |
|
| 152 | + $config_fonc = 'articles_edit_config', |
|
| 153 | + $row = [], |
|
| 154 | + $hidden = '' |
|
| 155 | 155 | ) { |
| 156 | - // auto-renseigner le titre si il n'existe pas |
|
| 157 | - titre_automatique('titre', ['descriptif', 'chapo', 'texte']); |
|
| 158 | - if (!_request('id_parent') and !intval($id_article)) { |
|
| 159 | - $valeurs = formulaires_editer_objet_charger( |
|
| 160 | - 'article', |
|
| 161 | - $id_article, |
|
| 162 | - $id_rubrique, |
|
| 163 | - $lier_trad, |
|
| 164 | - $retour, |
|
| 165 | - $config_fonc, |
|
| 166 | - $row, |
|
| 167 | - $hidden |
|
| 168 | - ); |
|
| 169 | - set_request('id_parent', $valeurs['id_parent']); |
|
| 170 | - } |
|
| 171 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 172 | - $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']); |
|
| 173 | - // si on utilise le formulaire dans le public |
|
| 174 | - if (!function_exists('autoriser')) { |
|
| 175 | - include_spip('inc/autoriser'); |
|
| 176 | - } |
|
| 177 | - if ( |
|
| 178 | - !isset($erreurs['id_parent']) |
|
| 179 | - and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 180 | - ) { |
|
| 181 | - $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 182 | - } |
|
| 156 | + // auto-renseigner le titre si il n'existe pas |
|
| 157 | + titre_automatique('titre', ['descriptif', 'chapo', 'texte']); |
|
| 158 | + if (!_request('id_parent') and !intval($id_article)) { |
|
| 159 | + $valeurs = formulaires_editer_objet_charger( |
|
| 160 | + 'article', |
|
| 161 | + $id_article, |
|
| 162 | + $id_rubrique, |
|
| 163 | + $lier_trad, |
|
| 164 | + $retour, |
|
| 165 | + $config_fonc, |
|
| 166 | + $row, |
|
| 167 | + $hidden |
|
| 168 | + ); |
|
| 169 | + set_request('id_parent', $valeurs['id_parent']); |
|
| 170 | + } |
|
| 171 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 172 | + $erreurs = formulaires_editer_objet_verifier('article', $id_article, ['id_parent']); |
|
| 173 | + // si on utilise le formulaire dans le public |
|
| 174 | + if (!function_exists('autoriser')) { |
|
| 175 | + include_spip('inc/autoriser'); |
|
| 176 | + } |
|
| 177 | + if ( |
|
| 178 | + !isset($erreurs['id_parent']) |
|
| 179 | + and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 180 | + ) { |
|
| 181 | + $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - return $erreurs; |
|
| 184 | + return $erreurs; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -207,29 +207,29 @@ discard block |
||
| 207 | 207 | * Retours des traitements |
| 208 | 208 | **/ |
| 209 | 209 | function formulaires_editer_article_traiter_dist( |
| 210 | - $id_article = 'new', |
|
| 211 | - $id_rubrique = 0, |
|
| 212 | - $retour = '', |
|
| 213 | - $lier_trad = 0, |
|
| 214 | - $config_fonc = 'articles_edit_config', |
|
| 215 | - $row = [], |
|
| 216 | - $hidden = '' |
|
| 210 | + $id_article = 'new', |
|
| 211 | + $id_rubrique = 0, |
|
| 212 | + $retour = '', |
|
| 213 | + $lier_trad = 0, |
|
| 214 | + $config_fonc = 'articles_edit_config', |
|
| 215 | + $row = [], |
|
| 216 | + $hidden = '' |
|
| 217 | 217 | ) { |
| 218 | - // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 219 | - // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 220 | - // en fonction de la config du site et de la rubrique choisie |
|
| 221 | - if (!$lier_trad) { |
|
| 222 | - set_request('changer_lang'); |
|
| 223 | - } |
|
| 218 | + // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 219 | + // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 220 | + // en fonction de la config du site et de la rubrique choisie |
|
| 221 | + if (!$lier_trad) { |
|
| 222 | + set_request('changer_lang'); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - return formulaires_editer_objet_traiter( |
|
| 226 | - 'article', |
|
| 227 | - $id_article, |
|
| 228 | - $id_rubrique, |
|
| 229 | - $lier_trad, |
|
| 230 | - $retour, |
|
| 231 | - $config_fonc, |
|
| 232 | - $row, |
|
| 233 | - $hidden |
|
| 234 | - ); |
|
| 225 | + return formulaires_editer_objet_traiter( |
|
| 226 | + 'article', |
|
| 227 | + $id_article, |
|
| 228 | + $id_rubrique, |
|
| 229 | + $lier_trad, |
|
| 230 | + $retour, |
|
| 231 | + $config_fonc, |
|
| 232 | + $row, |
|
| 233 | + $hidden |
|
| 234 | + ); |
|
| 235 | 235 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -32,16 +32,16 @@ discard block |
||
| 32 | 32 | * @return array|bool|null |
| 33 | 33 | */ |
| 34 | 34 | function quete_virtuel($id_article, $connect) { |
| 35 | - return sql_getfetsel( |
|
| 36 | - 'virtuel', |
|
| 37 | - 'spip_articles', |
|
| 38 | - ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 39 | - '', |
|
| 40 | - '', |
|
| 41 | - '', |
|
| 42 | - '', |
|
| 43 | - $connect |
|
| 44 | - ); |
|
| 35 | + return sql_getfetsel( |
|
| 36 | + 'virtuel', |
|
| 37 | + 'spip_articles', |
|
| 38 | + ['id_article=' . intval($id_article), "statut='publie'"], |
|
| 39 | + '', |
|
| 40 | + '', |
|
| 41 | + '', |
|
| 42 | + '', |
|
| 43 | + $connect |
|
| 44 | + ); |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | /** |
@@ -56,41 +56,41 @@ discard block |
||
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | 58 | function quete_parent_lang($table, $id, string $connect = '') { |
| 59 | - static $cache_quete = []; |
|
| 60 | - |
|
| 61 | - if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 62 | - if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 63 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 64 | - if ( |
|
| 65 | - !$desc = $trouver_table( |
|
| 66 | - $table, |
|
| 67 | - $connect |
|
| 68 | - ) or !isset($desc['field']['id_rubrique']) |
|
| 69 | - ) { |
|
| 70 | - // pas de parent rubrique, on passe |
|
| 71 | - $cache_quete[$connect][$table]['_select'] = false; |
|
| 72 | - } else { |
|
| 73 | - $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 74 | - $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 75 | - $cache_quete[$connect][$table]['_select'] = $select; |
|
| 76 | - $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - if ($cache_quete[$connect][$table]['_select']) { |
|
| 80 | - $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 81 | - $cache_quete[$connect][$table]['_select'], |
|
| 82 | - $table, |
|
| 83 | - $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 84 | - '', |
|
| 85 | - '', |
|
| 86 | - '', |
|
| 87 | - '', |
|
| 88 | - $connect |
|
| 89 | - ); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $cache_quete[$connect][$table][$id] ?? null; |
|
| 59 | + static $cache_quete = []; |
|
| 60 | + |
|
| 61 | + if (!isset($cache_quete[$connect][$table][$id])) { |
|
| 62 | + if (!isset($cache_quete[$connect][$table]['_select'])) { |
|
| 63 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 64 | + if ( |
|
| 65 | + !$desc = $trouver_table( |
|
| 66 | + $table, |
|
| 67 | + $connect |
|
| 68 | + ) or !isset($desc['field']['id_rubrique']) |
|
| 69 | + ) { |
|
| 70 | + // pas de parent rubrique, on passe |
|
| 71 | + $cache_quete[$connect][$table]['_select'] = false; |
|
| 72 | + } else { |
|
| 73 | + $select = ($table == 'spip_rubriques' ? 'id_parent' : 'id_rubrique'); |
|
| 74 | + $select .= isset($desc['field']['lang']) ? ', lang' : ''; |
|
| 75 | + $cache_quete[$connect][$table]['_select'] = $select; |
|
| 76 | + $cache_quete[$connect][$table]['_id'] = id_table_objet(objet_type($table)); |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + if ($cache_quete[$connect][$table]['_select']) { |
|
| 80 | + $cache_quete[$connect][$table][$id] = sql_fetsel( |
|
| 81 | + $cache_quete[$connect][$table]['_select'], |
|
| 82 | + $table, |
|
| 83 | + $cache_quete[$connect][$table]['_id'] . '=' . intval($id), |
|
| 84 | + '', |
|
| 85 | + '', |
|
| 86 | + '', |
|
| 87 | + '', |
|
| 88 | + $connect |
|
| 89 | + ); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $cache_quete[$connect][$table][$id] ?? null; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -107,11 +107,11 @@ discard block |
||
| 107 | 107 | * @return int |
| 108 | 108 | */ |
| 109 | 109 | function quete_parent($id_rubrique, string $connect = '') { |
| 110 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 111 | - return 0; |
|
| 112 | - } |
|
| 113 | - $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 114 | - return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 110 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 111 | + return 0; |
|
| 112 | + } |
|
| 113 | + $id_parent = quete_parent_lang('spip_rubriques', $id_rubrique, $connect); |
|
| 114 | + return $id_parent ? $id_parent['id_parent'] : 0; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -127,9 +127,9 @@ discard block |
||
| 127 | 127 | * @return int |
| 128 | 128 | */ |
| 129 | 129 | function quete_rubrique($id_article, $serveur) { |
| 130 | - $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 130 | + $id_parent = quete_parent_lang('spip_articles', $id_article, $serveur); |
|
| 131 | 131 | |
| 132 | - return $id_parent['id_rubrique'] ?? 0; |
|
| 132 | + return $id_parent['id_rubrique'] ?? 0; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | * @return int |
| 144 | 144 | */ |
| 145 | 145 | function quete_profondeur($id, string $connect = '') { |
| 146 | - $n = 0; |
|
| 147 | - while ($id) { |
|
| 148 | - $n++; |
|
| 149 | - $id = quete_parent($id, $connect); |
|
| 150 | - } |
|
| 146 | + $n = 0; |
|
| 147 | + while ($id) { |
|
| 148 | + $n++; |
|
| 149 | + $id = quete_parent($id, $connect); |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - return $n; |
|
| 152 | + return $n; |
|
| 153 | 153 | } |
| 154 | 154 | |
| 155 | 155 | |
@@ -165,15 +165,15 @@ discard block |
||
| 165 | 165 | * Morceau de la requête SQL testant la date |
| 166 | 166 | */ |
| 167 | 167 | function quete_condition_postdates($champ_date, $serveur = '', $ignore_previsu = false) { |
| 168 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 169 | - return '1=1'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - return |
|
| 173 | - (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 174 | - and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 175 | - ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 176 | - : '1=1'; |
|
| 168 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 169 | + return '1=1'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + return |
|
| 173 | + (isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 174 | + and $GLOBALS['meta']['date_prochain_postdate'] > time()) |
|
| 175 | + ? "$champ_date<" . sql_quote(date('Y-m-d H:i:s', $GLOBALS['meta']['date_prochain_postdate']), $serveur) |
|
| 176 | + : '1=1'; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -193,101 +193,101 @@ discard block |
||
| 193 | 193 | * @return array|string |
| 194 | 194 | */ |
| 195 | 195 | function quete_condition_statut($mstatut, $previsu, $publie, $serveur = '', $ignore_previsu = false) { |
| 196 | - static $cond = []; |
|
| 197 | - $key = func_get_args(); |
|
| 198 | - $key = implode('-', $key); |
|
| 199 | - if (isset($cond[$key])) { |
|
| 200 | - return $cond[$key]; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $liste_statuts = $publie; |
|
| 204 | - if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 205 | - $liste_statuts = $previsu; |
|
| 206 | - } |
|
| 207 | - $not = false; |
|
| 208 | - if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 209 | - $not = true; |
|
| 210 | - $liste_statuts = substr($liste_statuts, 1); |
|
| 211 | - } |
|
| 212 | - // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 213 | - if (!strlen($liste_statuts)) { |
|
| 214 | - return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $liste_statuts = explode(',', $liste_statuts); |
|
| 218 | - $where = []; |
|
| 219 | - foreach ($liste_statuts as $k => $v) { |
|
| 220 | - // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 221 | - // a ceux de l'auteur identifie |
|
| 222 | - if (strpos($v, '/') !== false) { |
|
| 223 | - $v = explode('/', $v); |
|
| 224 | - $filtre = end($v); |
|
| 225 | - $v = reset($v); |
|
| 226 | - $v = preg_replace(',\W,', '', $v); |
|
| 227 | - if ( |
|
| 228 | - $filtre == 'auteur' |
|
| 229 | - and (strpos($mstatut, '.') !== false) |
|
| 230 | - and $objet = explode('.', $mstatut) |
|
| 231 | - and $id_table = reset($objet) |
|
| 232 | - and $objet = objet_type($id_table) |
|
| 233 | - ) { |
|
| 234 | - $w = "$mstatut<>" . sql_quote($v); |
|
| 235 | - |
|
| 236 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 237 | - // sinon l’auteur en session |
|
| 238 | - include_spip('inc/securiser_action'); |
|
| 239 | - if ($desc = decrire_token_previsu()) { |
|
| 240 | - $id_auteur = $desc['id_auteur']; |
|
| 241 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 242 | - $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 243 | - } else { |
|
| 244 | - $id_auteur = null; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 248 | - if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 249 | - // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 250 | - if (!$id_auteur) { |
|
| 251 | - $where[] = $w; |
|
| 252 | - } else { |
|
| 253 | - $primary = id_table_objet($objet); |
|
| 254 | - $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 255 | - 'ssss.id_objet', |
|
| 256 | - 'spip_auteurs_liens AS ssss', |
|
| 257 | - 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 258 | - '', |
|
| 259 | - '', |
|
| 260 | - '', |
|
| 261 | - '', |
|
| 262 | - $serveur |
|
| 263 | - ) . '))'; |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 267 | - else { |
|
| 268 | - $v = ''; |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - // securite |
|
| 272 | - $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 273 | - } |
|
| 274 | - $liste_statuts = array_filter($liste_statuts); |
|
| 275 | - if (count($liste_statuts) == 1) { |
|
| 276 | - $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 277 | - } else { |
|
| 278 | - $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 279 | - } |
|
| 280 | - |
|
| 281 | - while (count($where) > 1) { |
|
| 282 | - $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 283 | - $where[] = $and; |
|
| 284 | - } |
|
| 285 | - $cond[$key] = reset($where); |
|
| 286 | - if ($not) { |
|
| 287 | - $cond[$key] = ['NOT', $cond[$key]]; |
|
| 288 | - } |
|
| 289 | - |
|
| 290 | - return $cond[$key]; |
|
| 196 | + static $cond = []; |
|
| 197 | + $key = func_get_args(); |
|
| 198 | + $key = implode('-', $key); |
|
| 199 | + if (isset($cond[$key])) { |
|
| 200 | + return $cond[$key]; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $liste_statuts = $publie; |
|
| 204 | + if (defined('_VAR_PREVIEW') and _VAR_PREVIEW and !$ignore_previsu) { |
|
| 205 | + $liste_statuts = $previsu; |
|
| 206 | + } |
|
| 207 | + $not = false; |
|
| 208 | + if (strncmp($liste_statuts, '!', 1) == 0) { |
|
| 209 | + $not = true; |
|
| 210 | + $liste_statuts = substr($liste_statuts, 1); |
|
| 211 | + } |
|
| 212 | + // '' => ne rien afficher, '!'=> ne rien filtrer |
|
| 213 | + if (!strlen($liste_statuts)) { |
|
| 214 | + return $cond[$key] = ($not ? '1=1' : '0=1'); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $liste_statuts = explode(',', $liste_statuts); |
|
| 218 | + $where = []; |
|
| 219 | + foreach ($liste_statuts as $k => $v) { |
|
| 220 | + // filtrage /auteur pour limiter les objets d'un statut (prepa en general) |
|
| 221 | + // a ceux de l'auteur identifie |
|
| 222 | + if (strpos($v, '/') !== false) { |
|
| 223 | + $v = explode('/', $v); |
|
| 224 | + $filtre = end($v); |
|
| 225 | + $v = reset($v); |
|
| 226 | + $v = preg_replace(',\W,', '', $v); |
|
| 227 | + if ( |
|
| 228 | + $filtre == 'auteur' |
|
| 229 | + and (strpos($mstatut, '.') !== false) |
|
| 230 | + and $objet = explode('.', $mstatut) |
|
| 231 | + and $id_table = reset($objet) |
|
| 232 | + and $objet = objet_type($id_table) |
|
| 233 | + ) { |
|
| 234 | + $w = "$mstatut<>" . sql_quote($v); |
|
| 235 | + |
|
| 236 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 237 | + // sinon l’auteur en session |
|
| 238 | + include_spip('inc/securiser_action'); |
|
| 239 | + if ($desc = decrire_token_previsu()) { |
|
| 240 | + $id_auteur = $desc['id_auteur']; |
|
| 241 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 242 | + $id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']); |
|
| 243 | + } else { |
|
| 244 | + $id_auteur = null; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 248 | + if (!autoriser('previsualiser' . $v, $objet, '', $id_auteur)) { |
|
| 249 | + // si pas d'auteur identifie pas de sous-requete car pas d'article qui matche |
|
| 250 | + if (!$id_auteur) { |
|
| 251 | + $where[] = $w; |
|
| 252 | + } else { |
|
| 253 | + $primary = id_table_objet($objet); |
|
| 254 | + $where[] = "($w OR $id_table.$primary IN (" . sql_get_select( |
|
| 255 | + 'ssss.id_objet', |
|
| 256 | + 'spip_auteurs_liens AS ssss', |
|
| 257 | + 'ssss.objet=' . sql_quote($objet) . ' AND ssss.id_auteur=' . intval($id_auteur), |
|
| 258 | + '', |
|
| 259 | + '', |
|
| 260 | + '', |
|
| 261 | + '', |
|
| 262 | + $serveur |
|
| 263 | + ) . '))'; |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } // ignorer ce statut si on ne sait pas comment le filtrer |
|
| 267 | + else { |
|
| 268 | + $v = ''; |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + // securite |
|
| 272 | + $liste_statuts[$k] = preg_replace(',\W,', '', $v); |
|
| 273 | + } |
|
| 274 | + $liste_statuts = array_filter($liste_statuts); |
|
| 275 | + if (count($liste_statuts) == 1) { |
|
| 276 | + $where[] = ['=', $mstatut, sql_quote(reset($liste_statuts), $serveur)]; |
|
| 277 | + } else { |
|
| 278 | + $where[] = sql_in($mstatut, $liste_statuts, $not, $serveur); |
|
| 279 | + } |
|
| 280 | + |
|
| 281 | + while (count($where) > 1) { |
|
| 282 | + $and = ['AND', array_pop($where), array_pop($where)]; |
|
| 283 | + $where[] = $and; |
|
| 284 | + } |
|
| 285 | + $cond[$key] = reset($where); |
|
| 286 | + if ($not) { |
|
| 287 | + $cond[$key] = ['NOT', $cond[$key]]; |
|
| 288 | + } |
|
| 289 | + |
|
| 290 | + return $cond[$key]; |
|
| 291 | 291 | } |
| 292 | 292 | |
| 293 | 293 | /** |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | * @return array|bool|null |
| 299 | 299 | */ |
| 300 | 300 | function quete_fichier($id_document, $serveur = '') { |
| 301 | - return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 301 | + return sql_getfetsel('fichier', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @return array|bool |
| 310 | 310 | */ |
| 311 | 311 | function quete_document($id_document, $serveur = '') { |
| 312 | - return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 312 | + return sql_fetsel('*', 'spip_documents', ('id_document=' . intval($id_document)), '', [], '', '', $serveur); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | * @return array|bool|null |
| 321 | 321 | */ |
| 322 | 322 | function quete_meta($nom, $serveur) { |
| 323 | - return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 323 | + return sql_getfetsel('valeur', 'spip_meta', 'nom=' . sql_quote($nom), '', '', '', '', $serveur); |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -346,72 +346,72 @@ discard block |
||
| 346 | 346 | * Retourne soit un tableau, soit le chemin du fichier. |
| 347 | 347 | */ |
| 348 | 348 | function quete_logo($cle_objet, $onoff, $id, $id_rubrique, $flag = false) { |
| 349 | - include_spip('base/objets'); |
|
| 350 | - $nom = strtolower($onoff); |
|
| 351 | - |
|
| 352 | - $cle_objet = id_table_objet($cle_objet); |
|
| 353 | - |
|
| 354 | - while (1) { |
|
| 355 | - $objet = objet_type($cle_objet); |
|
| 356 | - |
|
| 357 | - $on = quete_logo_objet($id, $objet, $nom); |
|
| 358 | - |
|
| 359 | - if ($on) { |
|
| 360 | - if ($flag) { |
|
| 361 | - return $on['fichier']; |
|
| 362 | - } else { |
|
| 363 | - $taille = @spip_getimagesize($on['chemin']); |
|
| 364 | - |
|
| 365 | - // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 366 | - // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 367 | - // alors on ne cherche pas du tout le survol ici |
|
| 368 | - if ($onoff != 'ON') { |
|
| 369 | - $off = ''; |
|
| 370 | - } else { |
|
| 371 | - // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 372 | - $off = quete_logo_objet($id, $objet, 'off'); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - // on retourne une url du type IMG/artonXX?timestamp |
|
| 376 | - // qui permet de distinguer le changement de logo |
|
| 377 | - // et placer un expire sur le dossier IMG/ |
|
| 378 | - $res = [ |
|
| 379 | - $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 380 | - ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 381 | - (!$taille ? '' : (' ' . $taille[3])) |
|
| 382 | - ]; |
|
| 383 | - $res['src'] = $res[0]; |
|
| 384 | - $res['logo_on'] = $res[0]; |
|
| 385 | - $res['logo_off'] = $res[1]; |
|
| 386 | - $res['width'] = ($taille ? $taille[0] : ''); |
|
| 387 | - $res['height'] = ($taille ? $taille[1] : ''); |
|
| 388 | - $res['fichier'] = $on['fichier']; |
|
| 389 | - $res['titre'] = ($on['titre'] ?? ''); |
|
| 390 | - $res['descriptif'] = ($on['descriptif'] ?? ''); |
|
| 391 | - $res['credits'] = ($on['credits'] ?? ''); |
|
| 392 | - $res['alt'] = ($on['alt'] ?? ''); |
|
| 393 | - $res['id'] = ($on['id_document'] ?? 0); |
|
| 394 | - |
|
| 395 | - return $res; |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 399 | - return ''; |
|
| 400 | - } else { |
|
| 401 | - if ($id_rubrique) { |
|
| 402 | - $cle_objet = 'id_rubrique'; |
|
| 403 | - $id = $id_rubrique; |
|
| 404 | - $id_rubrique = 0; |
|
| 405 | - } else { |
|
| 406 | - if ($id and $cle_objet == 'id_rubrique') { |
|
| 407 | - $id = quete_parent($id); |
|
| 408 | - } else { |
|
| 409 | - return ''; |
|
| 410 | - } |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 349 | + include_spip('base/objets'); |
|
| 350 | + $nom = strtolower($onoff); |
|
| 351 | + |
|
| 352 | + $cle_objet = id_table_objet($cle_objet); |
|
| 353 | + |
|
| 354 | + while (1) { |
|
| 355 | + $objet = objet_type($cle_objet); |
|
| 356 | + |
|
| 357 | + $on = quete_logo_objet($id, $objet, $nom); |
|
| 358 | + |
|
| 359 | + if ($on) { |
|
| 360 | + if ($flag) { |
|
| 361 | + return $on['fichier']; |
|
| 362 | + } else { |
|
| 363 | + $taille = @spip_getimagesize($on['chemin']); |
|
| 364 | + |
|
| 365 | + // Si on a déjà demandé un survol directement ($onoff = off) |
|
| 366 | + // ou qu'on a demandé uniquement le normal ($onoff = on) |
|
| 367 | + // alors on ne cherche pas du tout le survol ici |
|
| 368 | + if ($onoff != 'ON') { |
|
| 369 | + $off = ''; |
|
| 370 | + } else { |
|
| 371 | + // Sinon, c'est qu'on demande normal ET survol à la fois, donc on cherche maintenant le survol |
|
| 372 | + $off = quete_logo_objet($id, $objet, 'off'); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + // on retourne une url du type IMG/artonXX?timestamp |
|
| 376 | + // qui permet de distinguer le changement de logo |
|
| 377 | + // et placer un expire sur le dossier IMG/ |
|
| 378 | + $res = [ |
|
| 379 | + $on['chemin'] . ($on['timestamp'] ? "?{$on['timestamp']}" : ''), |
|
| 380 | + ($off ? $off['chemin'] . ($off['timestamp'] ? "?{$off['timestamp']}" : '') : ''), |
|
| 381 | + (!$taille ? '' : (' ' . $taille[3])) |
|
| 382 | + ]; |
|
| 383 | + $res['src'] = $res[0]; |
|
| 384 | + $res['logo_on'] = $res[0]; |
|
| 385 | + $res['logo_off'] = $res[1]; |
|
| 386 | + $res['width'] = ($taille ? $taille[0] : ''); |
|
| 387 | + $res['height'] = ($taille ? $taille[1] : ''); |
|
| 388 | + $res['fichier'] = $on['fichier']; |
|
| 389 | + $res['titre'] = ($on['titre'] ?? ''); |
|
| 390 | + $res['descriptif'] = ($on['descriptif'] ?? ''); |
|
| 391 | + $res['credits'] = ($on['credits'] ?? ''); |
|
| 392 | + $res['alt'] = ($on['alt'] ?? ''); |
|
| 393 | + $res['id'] = ($on['id_document'] ?? 0); |
|
| 394 | + |
|
| 395 | + return $res; |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + if (defined('_LOGO_RUBRIQUE_DESACTIVER_HERITAGE')) { |
|
| 399 | + return ''; |
|
| 400 | + } else { |
|
| 401 | + if ($id_rubrique) { |
|
| 402 | + $cle_objet = 'id_rubrique'; |
|
| 403 | + $id = $id_rubrique; |
|
| 404 | + $id_rubrique = 0; |
|
| 405 | + } else { |
|
| 406 | + if ($id and $cle_objet == 'id_rubrique') { |
|
| 407 | + $id = quete_parent($id); |
|
| 408 | + } else { |
|
| 409 | + return ''; |
|
| 410 | + } |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | 415 | } |
| 416 | 416 | |
| 417 | 417 | /** |
@@ -426,43 +426,43 @@ discard block |
||
| 426 | 426 | * @return bool|array |
| 427 | 427 | **/ |
| 428 | 428 | function quete_logo_objet($id_objet, $objet, $mode) { |
| 429 | - static $chercher_logo; |
|
| 430 | - if (is_null($chercher_logo)) { |
|
| 431 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 432 | - } |
|
| 433 | - $cle_objet = id_table_objet($objet); |
|
| 434 | - |
|
| 435 | - // On cherche pas la méthode classique |
|
| 436 | - $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 437 | - |
|
| 438 | - // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 439 | - if (!empty($infos_logo)) { |
|
| 440 | - $infos = [ |
|
| 441 | - 'chemin' => $infos_logo[0], |
|
| 442 | - 'timestamp' => $infos_logo[4], |
|
| 443 | - 'id_document' => ($infos_logo[5]['id_document'] ?? ''), |
|
| 444 | - ]; |
|
| 445 | - foreach (['fichier', 'titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 446 | - $infos[$champ] = ($infos_logo[5][$champ] ?? ''); |
|
| 447 | - } |
|
| 448 | - $infos_logo = $infos; |
|
| 449 | - } |
|
| 450 | - |
|
| 451 | - // On passe cette recherche de logo dans un pipeline |
|
| 452 | - $infos_logo = pipeline( |
|
| 453 | - 'quete_logo_objet', |
|
| 454 | - [ |
|
| 455 | - 'args' => [ |
|
| 456 | - 'id_objet' => $id_objet, |
|
| 457 | - 'objet' => $objet, |
|
| 458 | - 'cle_objet' => $cle_objet, |
|
| 459 | - 'mode' => $mode, |
|
| 460 | - ], |
|
| 461 | - 'data' => $infos_logo, |
|
| 462 | - ] |
|
| 463 | - ); |
|
| 464 | - |
|
| 465 | - return $infos_logo; |
|
| 429 | + static $chercher_logo; |
|
| 430 | + if (is_null($chercher_logo)) { |
|
| 431 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 432 | + } |
|
| 433 | + $cle_objet = id_table_objet($objet); |
|
| 434 | + |
|
| 435 | + // On cherche pas la méthode classique |
|
| 436 | + $infos_logo = $chercher_logo($id_objet, $cle_objet, $mode); |
|
| 437 | + |
|
| 438 | + // Si la méthode classique a trouvé quelque chose, on utilise le nouveau format |
|
| 439 | + if (!empty($infos_logo)) { |
|
| 440 | + $infos = [ |
|
| 441 | + 'chemin' => $infos_logo[0], |
|
| 442 | + 'timestamp' => $infos_logo[4], |
|
| 443 | + 'id_document' => ($infos_logo[5]['id_document'] ?? ''), |
|
| 444 | + ]; |
|
| 445 | + foreach (['fichier', 'titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 446 | + $infos[$champ] = ($infos_logo[5][$champ] ?? ''); |
|
| 447 | + } |
|
| 448 | + $infos_logo = $infos; |
|
| 449 | + } |
|
| 450 | + |
|
| 451 | + // On passe cette recherche de logo dans un pipeline |
|
| 452 | + $infos_logo = pipeline( |
|
| 453 | + 'quete_logo_objet', |
|
| 454 | + [ |
|
| 455 | + 'args' => [ |
|
| 456 | + 'id_objet' => $id_objet, |
|
| 457 | + 'objet' => $objet, |
|
| 458 | + 'cle_objet' => $cle_objet, |
|
| 459 | + 'mode' => $mode, |
|
| 460 | + ], |
|
| 461 | + 'data' => $infos_logo, |
|
| 462 | + ] |
|
| 463 | + ); |
|
| 464 | + |
|
| 465 | + return $infos_logo; |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -475,25 +475,25 @@ discard block |
||
| 475 | 475 | * @return bool|string |
| 476 | 476 | */ |
| 477 | 477 | function quete_logo_file($row, $connect = null) { |
| 478 | - include_spip('inc/documents'); |
|
| 479 | - $logo = vignette_logo_document($row, $connect); |
|
| 480 | - if (!$logo) { |
|
| 481 | - $logo = image_du_document($row, $connect); |
|
| 482 | - } |
|
| 483 | - if (!$logo) { |
|
| 484 | - $f = charger_fonction('vignette', 'inc'); |
|
| 485 | - $logo = $f($row['extension'], false); |
|
| 486 | - } |
|
| 487 | - // si c'est une vignette type doc, la renvoyer direct |
|
| 488 | - if ( |
|
| 489 | - strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 490 | - or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 491 | - or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 492 | - ) { |
|
| 493 | - return $logo; |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - return get_spip_doc($logo); |
|
| 478 | + include_spip('inc/documents'); |
|
| 479 | + $logo = vignette_logo_document($row, $connect); |
|
| 480 | + if (!$logo) { |
|
| 481 | + $logo = image_du_document($row, $connect); |
|
| 482 | + } |
|
| 483 | + if (!$logo) { |
|
| 484 | + $f = charger_fonction('vignette', 'inc'); |
|
| 485 | + $logo = $f($row['extension'], false); |
|
| 486 | + } |
|
| 487 | + // si c'est une vignette type doc, la renvoyer direct |
|
| 488 | + if ( |
|
| 489 | + strcmp($logo, _DIR_PLUGINS) == 0 |
|
| 490 | + or strcmp($logo, _DIR_PLUGINS_DIST) == 0 |
|
| 491 | + or strcmp($logo, _DIR_RACINE . 'prive/') == 0 |
|
| 492 | + ) { |
|
| 493 | + return $logo; |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + return get_spip_doc($logo); |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | /** |
@@ -521,20 +521,20 @@ discard block |
||
| 521 | 521 | */ |
| 522 | 522 | function quete_logo_document($row, $lien, $align, $mode_logo, $x, $y, string $connect = '') { |
| 523 | 523 | |
| 524 | - include_spip('inc/documents'); |
|
| 525 | - $logo = ''; |
|
| 526 | - if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 527 | - $logo = vignette_logo_document($row, $connect); |
|
| 528 | - } |
|
| 529 | - // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 530 | - if ($mode_logo == 'vignette' and !$logo) { |
|
| 531 | - return ''; |
|
| 532 | - } |
|
| 533 | - if ($mode_logo == 'icone') { |
|
| 534 | - $row['fichier'] = ''; |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 524 | + include_spip('inc/documents'); |
|
| 525 | + $logo = ''; |
|
| 526 | + if (!in_array($mode_logo, ['icone', 'apercu'])) { |
|
| 527 | + $logo = vignette_logo_document($row, $connect); |
|
| 528 | + } |
|
| 529 | + // si on veut explicitement la vignette, ne rien renvoyer si il n'y en a pas |
|
| 530 | + if ($mode_logo == 'vignette' and !$logo) { |
|
| 531 | + return ''; |
|
| 532 | + } |
|
| 533 | + if ($mode_logo == 'icone') { |
|
| 534 | + $row['fichier'] = ''; |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return vignette_automatique($logo, $row, $lien, $x, $y, $align, null, $connect); |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -546,26 +546,26 @@ discard block |
||
| 546 | 546 | */ |
| 547 | 547 | function quete_html_logo($logo, $align, $lien) { |
| 548 | 548 | |
| 549 | - if (!is_array($logo)) { |
|
| 550 | - return ''; |
|
| 551 | - } |
|
| 552 | - |
|
| 553 | - $contexte = []; |
|
| 554 | - foreach ($logo as $k => $v) { |
|
| 555 | - if (!is_numeric($k)) { |
|
| 556 | - $contexte[$k] = $v; |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - foreach (['titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 561 | - if (!empty($contexte[$champ])) { |
|
| 562 | - $contexte[$champ] = appliquer_traitement_champ($contexte[$champ] , $champ, 'document'); |
|
| 563 | - } |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - $contexte['align'] = $align; |
|
| 567 | - $contexte['lien'] = $lien; |
|
| 568 | - return recuperer_fond('modeles/logo', $contexte); |
|
| 549 | + if (!is_array($logo)) { |
|
| 550 | + return ''; |
|
| 551 | + } |
|
| 552 | + |
|
| 553 | + $contexte = []; |
|
| 554 | + foreach ($logo as $k => $v) { |
|
| 555 | + if (!is_numeric($k)) { |
|
| 556 | + $contexte[$k] = $v; |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + foreach (['titre', 'descriptif', 'credits', 'alt'] as $champ) { |
|
| 561 | + if (!empty($contexte[$champ])) { |
|
| 562 | + $contexte[$champ] = appliquer_traitement_champ($contexte[$champ] , $champ, 'document'); |
|
| 563 | + } |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + $contexte['align'] = $align; |
|
| 567 | + $contexte['lien'] = $lien; |
|
| 568 | + return recuperer_fond('modeles/logo', $contexte); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | /** |
@@ -579,14 +579,14 @@ discard block |
||
| 579 | 579 | * @return string|false |
| 580 | 580 | */ |
| 581 | 581 | function document_spip_externe($fichier, $connect) { |
| 582 | - if ($connect) { |
|
| 583 | - $site = quete_meta('adresse_site', $connect); |
|
| 584 | - if ($site) { |
|
| 585 | - $dir = quete_meta('dir_img', $connect); |
|
| 586 | - return "$site/$dir$fichier"; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - return false; |
|
| 582 | + if ($connect) { |
|
| 583 | + $site = quete_meta('adresse_site', $connect); |
|
| 584 | + if ($site) { |
|
| 585 | + $dir = quete_meta('dir_img', $connect); |
|
| 586 | + return "$site/$dir$fichier"; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + return false; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | /** |
@@ -600,23 +600,23 @@ discard block |
||
| 600 | 600 | */ |
| 601 | 601 | function vignette_logo_document($row, string $connect = '') { |
| 602 | 602 | |
| 603 | - if (!$row or empty($row['id_vignette'])) { |
|
| 604 | - return ''; |
|
| 605 | - } |
|
| 606 | - $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 607 | - if ($url = document_spip_externe($fichier, $connect)) { |
|
| 608 | - return $url; |
|
| 609 | - } |
|
| 610 | - |
|
| 611 | - $f = get_spip_doc($fichier); |
|
| 612 | - if ($f and @file_exists($f)) { |
|
| 613 | - return $f; |
|
| 614 | - } |
|
| 615 | - if ($row['mode'] !== 'vignette') { |
|
| 616 | - return ''; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 603 | + if (!$row or empty($row['id_vignette'])) { |
|
| 604 | + return ''; |
|
| 605 | + } |
|
| 606 | + $fichier = quete_fichier($row['id_vignette'], $connect); |
|
| 607 | + if ($url = document_spip_externe($fichier, $connect)) { |
|
| 608 | + return $url; |
|
| 609 | + } |
|
| 610 | + |
|
| 611 | + $f = get_spip_doc($fichier); |
|
| 612 | + if ($f and @file_exists($f)) { |
|
| 613 | + return $f; |
|
| 614 | + } |
|
| 615 | + if ($row['mode'] !== 'vignette') { |
|
| 616 | + return ''; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + return generer_objet_url($row['id_document'], 'document', '', '', null, '', $connect); |
|
| 620 | 620 | } |
| 621 | 621 | |
| 622 | 622 | /** |
@@ -632,66 +632,66 @@ discard block |
||
| 632 | 632 | * @return bool|string |
| 633 | 633 | */ |
| 634 | 634 | function calcul_exposer($id, $prim, $reference, $parent, $type, string $connect = '') { |
| 635 | - static $exposer = []; |
|
| 636 | - |
|
| 637 | - // Que faut-il exposer ? Tous les elements de $reference |
|
| 638 | - // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 639 | - // qu'une fois (par squelette) et on conserve le resultat |
|
| 640 | - // en static. |
|
| 641 | - if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 642 | - $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 643 | - // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 644 | - // il n'est donc pas utile |
|
| 645 | - $parent = 0; |
|
| 646 | - if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 647 | - $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 648 | - if (isset($enfants[$type])) { |
|
| 649 | - foreach ($enfants[$type] as $t) { |
|
| 650 | - if ( |
|
| 651 | - isset($reference[$t]) |
|
| 652 | - // cas de la reference donnee dynamiquement par la pagination |
|
| 653 | - or isset($reference["@$t"]) |
|
| 654 | - ) { |
|
| 655 | - $type = $t; |
|
| 656 | - $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 657 | - continue; |
|
| 658 | - } |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - $exposer[$m][$type] = []; |
|
| 663 | - if ($principal) { |
|
| 664 | - $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 665 | - foreach ($principaux as $principal) { |
|
| 666 | - $exposer[$m][$type][$principal] = true; |
|
| 667 | - if ($type == 'id_mot') { |
|
| 668 | - if (!$parent) { |
|
| 669 | - $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 670 | - } |
|
| 671 | - if ($parent) { |
|
| 672 | - $exposer[$m]['id_groupe'][$parent] = true; |
|
| 673 | - } |
|
| 674 | - } else { |
|
| 675 | - if ($type != 'id_groupe') { |
|
| 676 | - if (!$parent) { |
|
| 677 | - if ($type == 'id_rubrique') { |
|
| 678 | - $parent = $principal; |
|
| 679 | - } |
|
| 680 | - if ($type == 'id_article') { |
|
| 681 | - $parent = quete_rubrique($principal, $connect); |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - do { |
|
| 685 | - $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 686 | - } while ($parent = quete_parent($parent, $connect)); |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - } |
|
| 691 | - } |
|
| 692 | - |
|
| 693 | - // And the winner is... |
|
| 694 | - return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 635 | + static $exposer = []; |
|
| 636 | + |
|
| 637 | + // Que faut-il exposer ? Tous les elements de $reference |
|
| 638 | + // ainsi que leur hierarchie ; on ne fait donc ce calcul |
|
| 639 | + // qu'une fois (par squelette) et on conserve le resultat |
|
| 640 | + // en static. |
|
| 641 | + if (!isset($exposer[$m = md5(serialize($reference))][$prim])) { |
|
| 642 | + $principal = $reference[$type] ?? $reference["@$type"] ?? ''; |
|
| 643 | + // le parent fournit en argument est le parent de $id, pas celui de $principal |
|
| 644 | + // il n'est donc pas utile |
|
| 645 | + $parent = 0; |
|
| 646 | + if (!$principal) { // regarder si un enfant est dans le contexte, auquel cas il expose peut etre le parent courant |
|
| 647 | + $enfants = ['id_rubrique' => ['id_article'], 'id_groupe' => ['id_mot']]; |
|
| 648 | + if (isset($enfants[$type])) { |
|
| 649 | + foreach ($enfants[$type] as $t) { |
|
| 650 | + if ( |
|
| 651 | + isset($reference[$t]) |
|
| 652 | + // cas de la reference donnee dynamiquement par la pagination |
|
| 653 | + or isset($reference["@$t"]) |
|
| 654 | + ) { |
|
| 655 | + $type = $t; |
|
| 656 | + $principal = $reference[$type] ?? $reference["@$type"]; |
|
| 657 | + continue; |
|
| 658 | + } |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + $exposer[$m][$type] = []; |
|
| 663 | + if ($principal) { |
|
| 664 | + $principaux = is_array($principal) ? $principal : [$principal]; |
|
| 665 | + foreach ($principaux as $principal) { |
|
| 666 | + $exposer[$m][$type][$principal] = true; |
|
| 667 | + if ($type == 'id_mot') { |
|
| 668 | + if (!$parent) { |
|
| 669 | + $parent = sql_getfetsel('id_groupe', 'spip_mots', 'id_mot=' . intval($principal), '', '', '', '', $connect); |
|
| 670 | + } |
|
| 671 | + if ($parent) { |
|
| 672 | + $exposer[$m]['id_groupe'][$parent] = true; |
|
| 673 | + } |
|
| 674 | + } else { |
|
| 675 | + if ($type != 'id_groupe') { |
|
| 676 | + if (!$parent) { |
|
| 677 | + if ($type == 'id_rubrique') { |
|
| 678 | + $parent = $principal; |
|
| 679 | + } |
|
| 680 | + if ($type == 'id_article') { |
|
| 681 | + $parent = quete_rubrique($principal, $connect); |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + do { |
|
| 685 | + $exposer[$m]['id_rubrique'][$parent] = true; |
|
| 686 | + } while ($parent = quete_parent($parent, $connect)); |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + } |
|
| 691 | + } |
|
| 692 | + |
|
| 693 | + // And the winner is... |
|
| 694 | + return isset($exposer[$m][$prim]) ? isset($exposer[$m][$prim][$id]) : ''; |
|
| 695 | 695 | } |
| 696 | 696 | |
| 697 | 697 | /** |
@@ -706,23 +706,23 @@ discard block |
||
| 706 | 706 | * @return int |
| 707 | 707 | */ |
| 708 | 708 | function quete_debut_pagination($primary, $valeur, $pas, $iter) { |
| 709 | - // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 710 | - // ou composee, mais verifions |
|
| 711 | - if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 712 | - return 0; |
|
| 713 | - } |
|
| 714 | - |
|
| 715 | - $pos = 0; |
|
| 716 | - while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 717 | - $pos++; |
|
| 718 | - } |
|
| 719 | - // si on a pas trouve |
|
| 720 | - if (!$row or $row[$primary] != $valeur) { |
|
| 721 | - return 0; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - // sinon, calculer le bon numero de page |
|
| 725 | - return floor($pos / $pas) * $pas; |
|
| 709 | + // on ne devrait pas arriver ici si la cle primaire est inexistante |
|
| 710 | + // ou composee, mais verifions |
|
| 711 | + if (!$primary or preg_match('/[,\s]/', $primary)) { |
|
| 712 | + return 0; |
|
| 713 | + } |
|
| 714 | + |
|
| 715 | + $pos = 0; |
|
| 716 | + while ($row = $iter->fetch() and $row[$primary] != $valeur) { |
|
| 717 | + $pos++; |
|
| 718 | + } |
|
| 719 | + // si on a pas trouve |
|
| 720 | + if (!$row or $row[$primary] != $valeur) { |
|
| 721 | + return 0; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + // sinon, calculer le bon numero de page |
|
| 725 | + return floor($pos / $pas) * $pas; |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -733,11 +733,11 @@ discard block |
||
| 733 | 733 | * @return boolean |
| 734 | 734 | */ |
| 735 | 735 | function is_whereable($value): bool { |
| 736 | - if (is_array($value) && count($value)) { |
|
| 737 | - return true; |
|
| 738 | - } |
|
| 739 | - if (is_scalar($value) && strlen($value)) { |
|
| 740 | - return true; |
|
| 741 | - } |
|
| 742 | - return false; |
|
| 736 | + if (is_array($value) && count($value)) { |
|
| 737 | + return true; |
|
| 738 | + } |
|
| 739 | + if (is_scalar($value) && strlen($value)) { |
|
| 740 | + return true; |
|
| 741 | + } |
|
| 742 | + return false; |
|
| 743 | 743 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Langue |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -38,35 +38,35 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | - if (is_null($liste_langues)) { |
|
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | - } else { |
|
| 44 | - if (is_array($liste_langues)) { |
|
| 45 | - $liste_langues = implode(',', $liste_langues); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | - |
|
| 50 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | - if (!$lang) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( |
|
| 58 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 59 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 60 | - and str_contains($liste_langues, (string) ",$lang,")) |
|
| 61 | - ) { |
|
| 62 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 63 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 64 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 65 | - |
|
| 66 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 67 | - } else { |
|
| 68 | - return false; |
|
| 69 | - } |
|
| 41 | + if (is_null($liste_langues)) { |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | + } else { |
|
| 44 | + if (is_array($liste_langues)) { |
|
| 45 | + $liste_langues = implode(',', $liste_langues); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | + |
|
| 50 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | + if (!$lang) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( |
|
| 58 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 59 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 60 | + and str_contains($liste_langues, (string) ",$lang,")) |
|
| 61 | + ) { |
|
| 62 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 63 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 64 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 65 | + |
|
| 66 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 67 | + } else { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | // |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 80 | 80 | |
| 81 | 81 | function choisir_traduction($trads, $lang = '') { |
| 82 | - $k = approcher_langue($trads, $lang); |
|
| 82 | + $k = approcher_langue($trads, $lang); |
|
| 83 | 83 | |
| 84 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 84 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | // retourne son 2e argument si c'est un index du premier |
@@ -89,21 +89,21 @@ discard block |
||
| 89 | 89 | // la langue X etant consideree comme une approche de X_Y |
| 90 | 90 | function approcher_langue($trads, $lang = '') { |
| 91 | 91 | |
| 92 | - if (!$lang) { |
|
| 93 | - $lang = $GLOBALS['spip_lang']; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - if (isset($trads[$lang])) { |
|
| 97 | - return $lang; |
|
| 98 | - } // cas des langues xx_yy |
|
| 99 | - else { |
|
| 100 | - $r = explode('_', $lang); |
|
| 101 | - if (isset($trads[$r[0]])) { |
|
| 102 | - return $r[0]; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return ''; |
|
| 92 | + if (!$lang) { |
|
| 93 | + $lang = $GLOBALS['spip_lang']; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + if (isset($trads[$lang])) { |
|
| 97 | + return $lang; |
|
| 98 | + } // cas des langues xx_yy |
|
| 99 | + else { |
|
| 100 | + $r = explode('_', $lang); |
|
| 101 | + if (isset($trads[$r[0]])) { |
|
| 102 | + return $r[0]; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return ''; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -118,10 +118,10 @@ discard block |
||
| 118 | 118 | * Nom de la langue, sinon son code. |
| 119 | 119 | **/ |
| 120 | 120 | function traduire_nom_langue($lang) { |
| 121 | - include_spip('inc/lang_liste'); |
|
| 122 | - include_spip('inc/charsets'); |
|
| 121 | + include_spip('inc/lang_liste'); |
|
| 122 | + include_spip('inc/charsets'); |
|
| 123 | 123 | |
| 124 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 124 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | // |
@@ -134,10 +134,10 @@ discard block |
||
| 134 | 134 | // hebreu a priori), 'droitier' sinon. |
| 135 | 135 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 136 | 136 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 137 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 137 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | 138 | |
| 139 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 140 | - $gaucher : $droitier; |
|
| 139 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 140 | + $gaucher : $droitier; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | // typo francaise ou anglaise ? |
@@ -146,29 +146,29 @@ discard block |
||
| 146 | 146 | // sinon determiner la typo en fonction de la langue courante |
| 147 | 147 | |
| 148 | 148 | function lang_typo($lang = '') { |
| 149 | - if (!$lang) { |
|
| 150 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 151 | - } |
|
| 152 | - if ( |
|
| 153 | - $lang == 'eo' |
|
| 154 | - or $lang == 'fr' |
|
| 155 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 156 | - or $lang == 'cpf' |
|
| 157 | - ) { |
|
| 158 | - return 'fr'; |
|
| 159 | - } else { |
|
| 160 | - return 'en'; |
|
| 161 | - } |
|
| 149 | + if (!$lang) { |
|
| 150 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 151 | + } |
|
| 152 | + if ( |
|
| 153 | + $lang == 'eo' |
|
| 154 | + or $lang == 'fr' |
|
| 155 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 156 | + or $lang == 'cpf' |
|
| 157 | + ) { |
|
| 158 | + return 'fr'; |
|
| 159 | + } else { |
|
| 160 | + return 'en'; |
|
| 161 | + } |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 165 | 165 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 166 | 166 | function changer_typo($lang = '') { |
| 167 | - if ($lang) { |
|
| 168 | - $GLOBALS['lang_objet'] = $lang; |
|
| 169 | - } else { |
|
| 170 | - unset($GLOBALS['lang_objet']); |
|
| 171 | - } |
|
| 167 | + if ($lang) { |
|
| 168 | + $GLOBALS['lang_objet'] = $lang; |
|
| 169 | + } else { |
|
| 170 | + unset($GLOBALS['lang_objet']); |
|
| 171 | + } |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | // |
@@ -178,58 +178,58 @@ discard block |
||
| 178 | 178 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 179 | 179 | // |
| 180 | 180 | function menu_langues($nom_select, $default = '') { |
| 181 | - include_spip('inc/actions'); |
|
| 182 | - |
|
| 183 | - $langues = liste_options_langues($nom_select); |
|
| 184 | - $ret = ''; |
|
| 185 | - if (!count($langues)) { |
|
| 186 | - return ''; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - if (!$default) { |
|
| 190 | - $default = $GLOBALS['spip_lang']; |
|
| 191 | - } |
|
| 192 | - foreach ($langues as $l) { |
|
| 193 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 194 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - if (!test_espace_prive()) { |
|
| 198 | - $cible = self(); |
|
| 199 | - $base = ''; |
|
| 200 | - } else { |
|
| 201 | - $cible = self(); |
|
| 202 | - $base = spip_connect() ? 'base' : ''; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 206 | - |
|
| 207 | - return generer_action_auteur( |
|
| 208 | - 'converser', |
|
| 209 | - $base, |
|
| 210 | - $cible, |
|
| 211 | - (select_langues($nom_select, $change, $ret) |
|
| 212 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | - " method='post'" |
|
| 214 | - ); |
|
| 181 | + include_spip('inc/actions'); |
|
| 182 | + |
|
| 183 | + $langues = liste_options_langues($nom_select); |
|
| 184 | + $ret = ''; |
|
| 185 | + if (!count($langues)) { |
|
| 186 | + return ''; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + if (!$default) { |
|
| 190 | + $default = $GLOBALS['spip_lang']; |
|
| 191 | + } |
|
| 192 | + foreach ($langues as $l) { |
|
| 193 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 194 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + if (!test_espace_prive()) { |
|
| 198 | + $cible = self(); |
|
| 199 | + $base = ''; |
|
| 200 | + } else { |
|
| 201 | + $cible = self(); |
|
| 202 | + $base = spip_connect() ? 'base' : ''; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 206 | + |
|
| 207 | + return generer_action_auteur( |
|
| 208 | + 'converser', |
|
| 209 | + $base, |
|
| 210 | + $cible, |
|
| 211 | + (select_langues($nom_select, $change, $ret) |
|
| 212 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | + " method='post'" |
|
| 214 | + ); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | function select_langues($nom_select, $change, $options, $label = '') { |
| 218 | - static $cpt = 0; |
|
| 219 | - $id = 'menu_langues' . $cpt++; |
|
| 220 | - |
|
| 221 | - return |
|
| 222 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | - "<select name='$nom_select' id='$id' " |
|
| 224 | - . ((!test_espace_prive()) ? |
|
| 225 | - ("class='forml menu_langues'") : |
|
| 226 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 227 | - ("class='lang_ecrire'") : |
|
| 228 | - "class='fondl'")) |
|
| 229 | - . $change |
|
| 230 | - . ">\n" |
|
| 231 | - . $options |
|
| 232 | - . '</select>'; |
|
| 218 | + static $cpt = 0; |
|
| 219 | + $id = 'menu_langues' . $cpt++; |
|
| 220 | + |
|
| 221 | + return |
|
| 222 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | + "<select name='$nom_select' id='$id' " |
|
| 224 | + . ((!test_espace_prive()) ? |
|
| 225 | + ("class='forml menu_langues'") : |
|
| 226 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 227 | + ("class='lang_ecrire'") : |
|
| 228 | + "class='fondl'")) |
|
| 229 | + . $change |
|
| 230 | + . ">\n" |
|
| 231 | + . $options |
|
| 232 | + . '</select>'; |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -251,34 +251,34 @@ discard block |
||
| 251 | 251 | */ |
| 252 | 252 | function liste_options_langues($nom_select) { |
| 253 | 253 | |
| 254 | - switch ($nom_select) { |
|
| 255 | - # #MENU_LANG |
|
| 256 | - case 'var_lang': |
|
| 257 | - # menu de changement de la langue d'un article |
|
| 258 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 259 | - case 'changer_lang': |
|
| 260 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 261 | - break; |
|
| 262 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 263 | - # les langues presentes sous forme de fichiers de langue |
|
| 264 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 265 | - case 'var_lang_ecrire': |
|
| 266 | - default: |
|
| 267 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 268 | - init_langues(); |
|
| 269 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 270 | - break; |
|
| 254 | + switch ($nom_select) { |
|
| 255 | + # #MENU_LANG |
|
| 256 | + case 'var_lang': |
|
| 257 | + # menu de changement de la langue d'un article |
|
| 258 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 259 | + case 'changer_lang': |
|
| 260 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 261 | + break; |
|
| 262 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 263 | + # les langues presentes sous forme de fichiers de langue |
|
| 264 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 265 | + case 'var_lang_ecrire': |
|
| 266 | + default: |
|
| 267 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 268 | + init_langues(); |
|
| 269 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 270 | + break; |
|
| 271 | 271 | |
| 272 | 272 | # dernier choix possible : toutes les langues = langues_proposees |
| 273 | 273 | # + langues_multilingues ; mais, ne sert pas |
| 274 | 274 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 275 | - } |
|
| 276 | - if (count($langues) <= 1) { |
|
| 277 | - return []; |
|
| 278 | - } |
|
| 279 | - sort($langues); |
|
| 275 | + } |
|
| 276 | + if (count($langues) <= 1) { |
|
| 277 | + return []; |
|
| 278 | + } |
|
| 279 | + sort($langues); |
|
| 280 | 280 | |
| 281 | - return $langues; |
|
| 281 | + return $langues; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | |
@@ -293,39 +293,39 @@ discard block |
||
| 293 | 293 | **/ |
| 294 | 294 | function verifier_lang_url() { |
| 295 | 295 | |
| 296 | - // quelle langue est demandee ? |
|
| 297 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 298 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 299 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 300 | - } |
|
| 301 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 302 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 303 | - } |
|
| 304 | - if (isset($_GET['lang'])) { |
|
| 305 | - $lang_demandee = $_GET['lang']; |
|
| 306 | - } |
|
| 307 | - |
|
| 308 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 309 | - if ( |
|
| 310 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 311 | - and changer_langue($lang_demandee) |
|
| 312 | - and $lang_demandee != @$_GET['lang'] |
|
| 313 | - ) { |
|
| 314 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 315 | - // ici on a besoin des var_truc |
|
| 316 | - foreach ($_GET as $var => $val) { |
|
| 317 | - if (!strncmp('var_', $var, 4)) { |
|
| 318 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - include_spip('inc/headers'); |
|
| 322 | - redirige_par_entete($destination); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 326 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 327 | - // (pour criteres {lang}). |
|
| 328 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 296 | + // quelle langue est demandee ? |
|
| 297 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 298 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 299 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 300 | + } |
|
| 301 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 302 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 303 | + } |
|
| 304 | + if (isset($_GET['lang'])) { |
|
| 305 | + $lang_demandee = $_GET['lang']; |
|
| 306 | + } |
|
| 307 | + |
|
| 308 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 309 | + if ( |
|
| 310 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 311 | + and changer_langue($lang_demandee) |
|
| 312 | + and $lang_demandee != @$_GET['lang'] |
|
| 313 | + ) { |
|
| 314 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 315 | + // ici on a besoin des var_truc |
|
| 316 | + foreach ($_GET as $var => $val) { |
|
| 317 | + if (!strncmp('var_', $var, 4)) { |
|
| 318 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + include_spip('inc/headers'); |
|
| 322 | + redirige_par_entete($destination); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 326 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 327 | + // (pour criteres {lang}). |
|
| 328 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | |
@@ -343,22 +343,22 @@ discard block |
||
| 343 | 343 | * La langue sélectionnée |
| 344 | 344 | **/ |
| 345 | 345 | function utiliser_langue_site($liste_langues = null) { |
| 346 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 347 | - if ( |
|
| 348 | - isset($GLOBALS['meta']['langue_site']) |
|
| 349 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 350 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 351 | - and (!isset($GLOBALS['spip_lang']) |
|
| 352 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 353 | - ) { |
|
| 354 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 355 | - } |
|
| 356 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 357 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 358 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $GLOBALS['spip_lang']; |
|
| 346 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 347 | + if ( |
|
| 348 | + isset($GLOBALS['meta']['langue_site']) |
|
| 349 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 350 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 351 | + and (!isset($GLOBALS['spip_lang']) |
|
| 352 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 353 | + ) { |
|
| 354 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 355 | + } |
|
| 356 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 357 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 358 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $GLOBALS['spip_lang']; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | /** |
@@ -377,35 +377,35 @@ discard block |
||
| 377 | 377 | **/ |
| 378 | 378 | function utiliser_langue_visiteur($liste_langues = null) { |
| 379 | 379 | |
| 380 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 381 | - if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 382 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 386 | - if (isset($_COOKIE[$l])) { |
|
| 387 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 388 | - return $l; |
|
| 389 | - } |
|
| 390 | - } |
|
| 391 | - |
|
| 392 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 393 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 394 | - return $l; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - |
|
| 398 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 399 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 400 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 401 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 402 | - return $l; |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - |
|
| 408 | - return utiliser_langue_site($liste_langues); |
|
| 380 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 381 | + if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 382 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 386 | + if (isset($_COOKIE[$l])) { |
|
| 387 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 388 | + return $l; |
|
| 389 | + } |
|
| 390 | + } |
|
| 391 | + |
|
| 392 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 393 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 394 | + return $l; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + |
|
| 398 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 399 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 400 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 401 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 402 | + return $l; |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + |
|
| 408 | + return utiliser_langue_site($liste_langues); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -415,7 +415,7 @@ discard block |
||
| 415 | 415 | * @return int |
| 416 | 416 | */ |
| 417 | 417 | function match_langue($chaine) { |
| 418 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 418 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 419 | 419 | } |
| 420 | 420 | |
| 421 | 421 | /** |
@@ -433,36 +433,36 @@ discard block |
||
| 433 | 433 | **/ |
| 434 | 434 | function init_langues() { |
| 435 | 435 | |
| 436 | - // liste des langues dans les meta, sauf a l'install |
|
| 437 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 438 | - |
|
| 439 | - $tout = []; |
|
| 440 | - if (!$all_langs) { |
|
| 441 | - // trouver tous les modules lang/spip_xx.php |
|
| 442 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 443 | - foreach ($modules as $name => $path) { |
|
| 444 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 445 | - if (match_langue($regs[1])) { |
|
| 446 | - $tout[] = $regs[1]; |
|
| 447 | - } |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - sort($tout); |
|
| 451 | - $tout = join(',', $tout); |
|
| 452 | - // Si les langues n'ont pas change, ne rien faire |
|
| 453 | - if ($tout != $all_langs) { |
|
| 454 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 455 | - include_spip('inc/meta'); |
|
| 456 | - ecrire_meta('langues_proposees', $tout); |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 460 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 461 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 462 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 463 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 464 | - ecrire_meta('langue_site', $tout); |
|
| 465 | - } |
|
| 436 | + // liste des langues dans les meta, sauf a l'install |
|
| 437 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 438 | + |
|
| 439 | + $tout = []; |
|
| 440 | + if (!$all_langs) { |
|
| 441 | + // trouver tous les modules lang/spip_xx.php |
|
| 442 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 443 | + foreach ($modules as $name => $path) { |
|
| 444 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 445 | + if (match_langue($regs[1])) { |
|
| 446 | + $tout[] = $regs[1]; |
|
| 447 | + } |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + sort($tout); |
|
| 451 | + $tout = join(',', $tout); |
|
| 452 | + // Si les langues n'ont pas change, ne rien faire |
|
| 453 | + if ($tout != $all_langs) { |
|
| 454 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 455 | + include_spip('inc/meta'); |
|
| 456 | + ecrire_meta('langues_proposees', $tout); |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 460 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 461 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 462 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 463 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 464 | + ecrire_meta('langue_site', $tout); |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -476,10 +476,10 @@ discard block |
||
| 476 | 476 | * Code html de la balise <html> |
| 477 | 477 | **/ |
| 478 | 478 | function html_lang_attributes() { |
| 479 | - $lang = $GLOBALS['spip_lang']; |
|
| 480 | - $dir = lang_dir($lang); |
|
| 479 | + $lang = $GLOBALS['spip_lang']; |
|
| 480 | + $dir = lang_dir($lang); |
|
| 481 | 481 | |
| 482 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 482 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | |
@@ -493,7 +493,7 @@ discard block |
||
| 493 | 493 | * @return string |
| 494 | 494 | */ |
| 495 | 495 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 496 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 496 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Filtres |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | * Date au format SQL tel que `2008-04-01` sinon '' |
| 37 | 37 | **/ |
| 38 | 38 | function extraire_date($texte): string { |
| 39 | - // format = 2001-08 |
|
| 40 | - if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | - return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | - } |
|
| 43 | - return ''; |
|
| 39 | + // format = 2001-08 |
|
| 40 | + if (preg_match(',([1-2][0-9]{3})[^0-9]*(1[0-2]|0?[1-9]),', $texte, $regs)) { |
|
| 41 | + return $regs[1] . '-' . sprintf('%02d', $regs[2]) . '-01'; |
|
| 42 | + } |
|
| 43 | + return ''; |
|
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | |
@@ -62,29 +62,29 @@ discard block |
||
| 62 | 62 | * - une chaîne vide si la date est considérée nulle |
| 63 | 63 | **/ |
| 64 | 64 | function normaliser_date($date, $forcer_jour = false): string { |
| 65 | - $date = vider_date($date); |
|
| 66 | - if ($date) { |
|
| 67 | - if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 68 | - $date = date('Y-m-d H:i:s', $date); |
|
| 69 | - } |
|
| 70 | - if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 71 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 72 | - $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | - } else { |
|
| 74 | - if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 75 | - $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 76 | - $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | - } else { |
|
| 78 | - $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if ($forcer_jour) { |
|
| 83 | - $date = str_replace('-00', '-01', $date); |
|
| 84 | - } |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $date; |
|
| 65 | + $date = vider_date($date); |
|
| 66 | + if ($date) { |
|
| 67 | + if (preg_match('/^[0-9]{8,10}$/', $date)) { |
|
| 68 | + $date = date('Y-m-d H:i:s', $date); |
|
| 69 | + } |
|
| 70 | + if (preg_match('#^([12][0-9]{3})([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 71 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 72 | + $date = $regs[1] . '-00-00' . $regs[3]; |
|
| 73 | + } else { |
|
| 74 | + if (preg_match('#^([12][0-9]{3}[-/][01]?[0-9])([-/]00)?( [-0-9:]+)?$#', $date, $regs)) { |
|
| 75 | + $regs = array_pad($regs, 4, null); // eviter notice php |
|
| 76 | + $date = preg_replace('@/@', '-', $regs[1]) . '-00' . $regs[3]; |
|
| 77 | + } else { |
|
| 78 | + $date = date('Y-m-d H:i:s', strtotime($date)); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if ($forcer_jour) { |
|
| 83 | + $date = str_replace('-00', '-01', $date); |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $date; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,23 +97,23 @@ discard block |
||
| 97 | 97 | * - Une chaine vide |
| 98 | 98 | **/ |
| 99 | 99 | function vider_date($letexte, $verif_format_date = false): string { |
| 100 | - $letexte ??= ''; |
|
| 101 | - if ( |
|
| 102 | - !$verif_format_date |
|
| 103 | - or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | - preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 105 | - ) { |
|
| 106 | - if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 107 | - return ''; |
|
| 108 | - } |
|
| 109 | - if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 110 | - return ''; |
|
| 111 | - } |
|
| 112 | - if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 113 | - return ''; |
|
| 114 | - } // eviter le bug GMT-1 |
|
| 115 | - } |
|
| 116 | - return $letexte; |
|
| 100 | + $letexte ??= ''; |
|
| 101 | + if ( |
|
| 102 | + !$verif_format_date |
|
| 103 | + or (in_array(strlen($letexte), [10,19]) and |
|
| 104 | + preg_match('/^[0-9]{4}-[0-9]{2}-[0-9]{2}(\s[0-9]{2}:[0-9]{2}:[0-9]{2})?$/', $letexte)) |
|
| 105 | + ) { |
|
| 106 | + if (strncmp('0000-00-00', $letexte, 10) == 0) { |
|
| 107 | + return ''; |
|
| 108 | + } |
|
| 109 | + if (strncmp('0001-01-01', $letexte, 10) == 0) { |
|
| 110 | + return ''; |
|
| 111 | + } |
|
| 112 | + if (strncmp('1970-01-01', $letexte, 10) == 0) { |
|
| 113 | + return ''; |
|
| 114 | + } // eviter le bug GMT-1 |
|
| 115 | + } |
|
| 116 | + return $letexte; |
|
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
@@ -129,17 +129,17 @@ discard block |
||
| 129 | 129 | **/ |
| 130 | 130 | function recup_heure($date): array { |
| 131 | 131 | |
| 132 | - if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 133 | - array_shift($elements); |
|
| 134 | - if (!isset($elements[2])) { |
|
| 135 | - $elements[2] = 0; |
|
| 136 | - } |
|
| 137 | - $heure = $elements; |
|
| 138 | - } else { |
|
| 139 | - $heure = [0, 0, 0]; |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - return $heure; |
|
| 132 | + if (preg_match('#([0-9]{1,2}):([0-9]{1,2})(?::([0-9]{1,2}))?#', $date, $elements)) { |
|
| 133 | + array_shift($elements); |
|
| 134 | + if (!isset($elements[2])) { |
|
| 135 | + $elements[2] = 0; |
|
| 136 | + } |
|
| 137 | + $heure = $elements; |
|
| 138 | + } else { |
|
| 139 | + $heure = [0, 0, 0]; |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + return $heure; |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -153,13 +153,13 @@ discard block |
||
| 153 | 153 | * @return string heures, sinon 0 |
| 154 | 154 | **/ |
| 155 | 155 | function heures($numdate): string { |
| 156 | - $heures = null; |
|
| 157 | - $date_array = recup_heure($numdate); |
|
| 158 | - if ($date_array) { |
|
| 159 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 160 | - } |
|
| 156 | + $heures = null; |
|
| 157 | + $date_array = recup_heure($numdate); |
|
| 158 | + if ($date_array) { |
|
| 159 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $heures; |
|
| 162 | + return $heures; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -173,13 +173,13 @@ discard block |
||
| 173 | 173 | * @return string minutes, sinon 0 |
| 174 | 174 | **/ |
| 175 | 175 | function minutes($numdate): string { |
| 176 | - $minutes = null; |
|
| 177 | - $date_array = recup_heure($numdate); |
|
| 178 | - if ($date_array) { |
|
| 179 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 180 | - } |
|
| 176 | + $minutes = null; |
|
| 177 | + $date_array = recup_heure($numdate); |
|
| 178 | + if ($date_array) { |
|
| 179 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - return $minutes; |
|
| 182 | + return $minutes; |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | * @return string secondes, sinon 0 |
| 194 | 194 | **/ |
| 195 | 195 | function secondes($numdate): string { |
| 196 | - $secondes = null; |
|
| 197 | - $date_array = recup_heure($numdate); |
|
| 198 | - if ($date_array) { |
|
| 199 | - [$heures, $minutes, $secondes] = $date_array; |
|
| 200 | - } |
|
| 196 | + $secondes = null; |
|
| 197 | + $date_array = recup_heure($numdate); |
|
| 198 | + if ($date_array) { |
|
| 199 | + [$heures, $minutes, $secondes] = $date_array; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return $secondes; |
|
| 202 | + return $secondes; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -218,11 +218,11 @@ discard block |
||
| 218 | 218 | * @return string L'heure formatée dans la langue en cours. |
| 219 | 219 | **/ |
| 220 | 220 | function heures_minutes($numdate, $forme = ''): string { |
| 221 | - if ($forme !== 'abbr') { |
|
| 222 | - return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 223 | - } else { |
|
| 224 | - return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 225 | - } |
|
| 221 | + if ($forme !== 'abbr') { |
|
| 222 | + return _T('date_fmt_heures_minutes', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 223 | + } else { |
|
| 224 | + return _T('date_fmt_heures_minutes_court', ['h' => heures($numdate), 'm' => minutes($numdate)]); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | /** |
@@ -247,57 +247,57 @@ discard block |
||
| 247 | 247 | * @return array [année, mois, jour, heures, minutes, secondes] ou [] |
| 248 | 248 | **/ |
| 249 | 249 | function recup_date($numdate, $forcer_jour = true): array { |
| 250 | - if (!$numdate) { |
|
| 251 | - return []; |
|
| 252 | - } |
|
| 253 | - $heures = $minutes = $secondes = 0; |
|
| 254 | - if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 255 | - $jour = $regs[1]; |
|
| 256 | - $mois = $regs[2]; |
|
| 257 | - $annee = $regs[3]; |
|
| 258 | - if ($annee < 90) { |
|
| 259 | - $annee = 2000 + $annee; |
|
| 260 | - } elseif ($annee < 100) { |
|
| 261 | - $annee = 1900 + $annee; |
|
| 262 | - } |
|
| 263 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 264 | - } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 265 | - $annee = $regs[1]; |
|
| 266 | - $mois = $regs[2]; |
|
| 267 | - $jour = $regs[3]; |
|
| 268 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 269 | - } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 270 | - $annee = $regs[1]; |
|
| 271 | - $mois = $regs[2]; |
|
| 272 | - $jour = ''; |
|
| 273 | - [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 274 | - } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 275 | - $annee = $regs[1]; |
|
| 276 | - $mois = $regs[2]; |
|
| 277 | - $jour = $regs[3]; |
|
| 278 | - $heures = $regs[4]; |
|
| 279 | - $minutes = $regs[5]; |
|
| 280 | - $secondes = $regs[6]; |
|
| 281 | - } else { |
|
| 282 | - $annee = $mois = $jour = ''; |
|
| 283 | - } |
|
| 284 | - if ($annee > 4000) { |
|
| 285 | - $annee -= 9000; |
|
| 286 | - } |
|
| 287 | - if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 288 | - $jour = substr($jour, 1); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if ($forcer_jour and $jour == '0') { |
|
| 292 | - $jour = '1'; |
|
| 293 | - } |
|
| 294 | - if ($forcer_jour and $mois == '0') { |
|
| 295 | - $mois = '1'; |
|
| 296 | - } |
|
| 297 | - if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 298 | - return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 299 | - } |
|
| 300 | - return []; |
|
| 250 | + if (!$numdate) { |
|
| 251 | + return []; |
|
| 252 | + } |
|
| 253 | + $heures = $minutes = $secondes = 0; |
|
| 254 | + if (preg_match('#([0-9]{1,2})/([0-9]{1,2})/([0-9]{4}|[0-9]{1,2})#', $numdate, $regs)) { |
|
| 255 | + $jour = $regs[1]; |
|
| 256 | + $mois = $regs[2]; |
|
| 257 | + $annee = $regs[3]; |
|
| 258 | + if ($annee < 90) { |
|
| 259 | + $annee = 2000 + $annee; |
|
| 260 | + } elseif ($annee < 100) { |
|
| 261 | + $annee = 1900 + $annee; |
|
| 262 | + } |
|
| 263 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 264 | + } elseif (preg_match('#([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})#', $numdate, $regs)) { |
|
| 265 | + $annee = $regs[1]; |
|
| 266 | + $mois = $regs[2]; |
|
| 267 | + $jour = $regs[3]; |
|
| 268 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 269 | + } elseif (preg_match('#([0-9]{4})-([0-9]{2})#', $numdate, $regs)) { |
|
| 270 | + $annee = $regs[1]; |
|
| 271 | + $mois = $regs[2]; |
|
| 272 | + $jour = ''; |
|
| 273 | + [$heures, $minutes, $secondes] = recup_heure($numdate); |
|
| 274 | + } elseif (preg_match('#^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})$#', $numdate, $regs)) { |
|
| 275 | + $annee = $regs[1]; |
|
| 276 | + $mois = $regs[2]; |
|
| 277 | + $jour = $regs[3]; |
|
| 278 | + $heures = $regs[4]; |
|
| 279 | + $minutes = $regs[5]; |
|
| 280 | + $secondes = $regs[6]; |
|
| 281 | + } else { |
|
| 282 | + $annee = $mois = $jour = ''; |
|
| 283 | + } |
|
| 284 | + if ($annee > 4000) { |
|
| 285 | + $annee -= 9000; |
|
| 286 | + } |
|
| 287 | + if (strlen($jour) and substr($jour, 0, 1) == '0') { |
|
| 288 | + $jour = substr($jour, 1); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if ($forcer_jour and $jour == '0') { |
|
| 292 | + $jour = '1'; |
|
| 293 | + } |
|
| 294 | + if ($forcer_jour and $mois == '0') { |
|
| 295 | + $mois = '1'; |
|
| 296 | + } |
|
| 297 | + if ($annee or $mois or $jour or $heures or $minutes or $secondes) { |
|
| 298 | + return [$annee, $mois, $jour, $heures, $minutes, $secondes]; |
|
| 299 | + } |
|
| 300 | + return []; |
|
| 301 | 301 | } |
| 302 | 302 | |
| 303 | 303 | /** |
@@ -324,10 +324,10 @@ discard block |
||
| 324 | 324 | * La date relative ou complète |
| 325 | 325 | **/ |
| 326 | 326 | function date_interface($date, $decalage_maxi = 43200 /* 12*3600 */): string { |
| 327 | - return sinon( |
|
| 328 | - date_relative($date, $decalage_maxi), |
|
| 329 | - affdate_heure($date) |
|
| 330 | - ); |
|
| 327 | + return sinon( |
|
| 328 | + date_relative($date, $decalage_maxi), |
|
| 329 | + affdate_heure($date) |
|
| 330 | + ); |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | /** |
@@ -360,86 +360,86 @@ discard block |
||
| 360 | 360 | **/ |
| 361 | 361 | function date_relative($date, $decalage_maxi = 0, $ref_date = null): string { |
| 362 | 362 | |
| 363 | - if (!$date) { |
|
| 364 | - return ''; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - if (is_null($ref_date)) { |
|
| 368 | - $ref_time = time(); |
|
| 369 | - } else { |
|
| 370 | - $ref_time = strtotime($ref_date); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 374 | - |
|
| 375 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 376 | - return ''; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - if ($decal < 0) { |
|
| 380 | - $il_y_a = 'date_dans'; |
|
| 381 | - $decal = -1 * $decal; |
|
| 382 | - } else { |
|
| 383 | - $il_y_a = 'date_il_y_a'; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - if ($decal > 3600 * 24 * 30 * 6) { |
|
| 387 | - return affdate_court($date); |
|
| 388 | - } |
|
| 389 | - |
|
| 390 | - if ($decal > 3600 * 24 * 30) { |
|
| 391 | - $mois = floor($decal / (3600 * 24 * 30)); |
|
| 392 | - if ($mois < 2) { |
|
| 393 | - $delai = "$mois " . _T('date_un_mois'); |
|
| 394 | - } else { |
|
| 395 | - $delai = "$mois " . _T('date_mois'); |
|
| 396 | - } |
|
| 397 | - } else { |
|
| 398 | - if ($decal > 3600 * 24 * 7) { |
|
| 399 | - $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 400 | - if ($semaines < 2) { |
|
| 401 | - $delai = "$semaines " . _T('date_une_semaine'); |
|
| 402 | - } else { |
|
| 403 | - $delai = "$semaines " . _T('date_semaines'); |
|
| 404 | - } |
|
| 405 | - } else { |
|
| 406 | - if ($decal > 3600 * 24) { |
|
| 407 | - $jours = floor($decal / (3600 * 24)); |
|
| 408 | - if ($jours < 2) { |
|
| 409 | - return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 410 | - } else { |
|
| 411 | - $delai = "$jours " . _T('date_jours'); |
|
| 412 | - } |
|
| 413 | - } else { |
|
| 414 | - if ($decal >= 3600) { |
|
| 415 | - $heures = floor($decal / 3600); |
|
| 416 | - if ($heures < 2) { |
|
| 417 | - $delai = "$heures " . _T('date_une_heure'); |
|
| 418 | - } else { |
|
| 419 | - $delai = "$heures " . _T('date_heures'); |
|
| 420 | - } |
|
| 421 | - } else { |
|
| 422 | - if ($decal >= 60) { |
|
| 423 | - $minutes = floor($decal / 60); |
|
| 424 | - if ($minutes < 2) { |
|
| 425 | - $delai = "$minutes " . _T('date_une_minute'); |
|
| 426 | - } else { |
|
| 427 | - $delai = "$minutes " . _T('date_minutes'); |
|
| 428 | - } |
|
| 429 | - } else { |
|
| 430 | - $secondes = ceil($decal); |
|
| 431 | - if ($secondes < 2) { |
|
| 432 | - $delai = "$secondes " . _T('date_une_seconde'); |
|
| 433 | - } else { |
|
| 434 | - $delai = "$secondes " . _T('date_secondes'); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return _T($il_y_a, ['delai' => $delai]); |
|
| 363 | + if (!$date) { |
|
| 364 | + return ''; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + if (is_null($ref_date)) { |
|
| 368 | + $ref_time = time(); |
|
| 369 | + } else { |
|
| 370 | + $ref_time = strtotime($ref_date); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $decal = date('U', $ref_time) - date('U', strtotime($date)); |
|
| 374 | + |
|
| 375 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 376 | + return ''; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + if ($decal < 0) { |
|
| 380 | + $il_y_a = 'date_dans'; |
|
| 381 | + $decal = -1 * $decal; |
|
| 382 | + } else { |
|
| 383 | + $il_y_a = 'date_il_y_a'; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + if ($decal > 3600 * 24 * 30 * 6) { |
|
| 387 | + return affdate_court($date); |
|
| 388 | + } |
|
| 389 | + |
|
| 390 | + if ($decal > 3600 * 24 * 30) { |
|
| 391 | + $mois = floor($decal / (3600 * 24 * 30)); |
|
| 392 | + if ($mois < 2) { |
|
| 393 | + $delai = "$mois " . _T('date_un_mois'); |
|
| 394 | + } else { |
|
| 395 | + $delai = "$mois " . _T('date_mois'); |
|
| 396 | + } |
|
| 397 | + } else { |
|
| 398 | + if ($decal > 3600 * 24 * 7) { |
|
| 399 | + $semaines = floor($decal / (3600 * 24 * 7)); |
|
| 400 | + if ($semaines < 2) { |
|
| 401 | + $delai = "$semaines " . _T('date_une_semaine'); |
|
| 402 | + } else { |
|
| 403 | + $delai = "$semaines " . _T('date_semaines'); |
|
| 404 | + } |
|
| 405 | + } else { |
|
| 406 | + if ($decal > 3600 * 24) { |
|
| 407 | + $jours = floor($decal / (3600 * 24)); |
|
| 408 | + if ($jours < 2) { |
|
| 409 | + return $il_y_a == 'date_dans' ? _T('date_demain') : _T('date_hier'); |
|
| 410 | + } else { |
|
| 411 | + $delai = "$jours " . _T('date_jours'); |
|
| 412 | + } |
|
| 413 | + } else { |
|
| 414 | + if ($decal >= 3600) { |
|
| 415 | + $heures = floor($decal / 3600); |
|
| 416 | + if ($heures < 2) { |
|
| 417 | + $delai = "$heures " . _T('date_une_heure'); |
|
| 418 | + } else { |
|
| 419 | + $delai = "$heures " . _T('date_heures'); |
|
| 420 | + } |
|
| 421 | + } else { |
|
| 422 | + if ($decal >= 60) { |
|
| 423 | + $minutes = floor($decal / 60); |
|
| 424 | + if ($minutes < 2) { |
|
| 425 | + $delai = "$minutes " . _T('date_une_minute'); |
|
| 426 | + } else { |
|
| 427 | + $delai = "$minutes " . _T('date_minutes'); |
|
| 428 | + } |
|
| 429 | + } else { |
|
| 430 | + $secondes = ceil($decal); |
|
| 431 | + if ($secondes < 2) { |
|
| 432 | + $delai = "$secondes " . _T('date_une_seconde'); |
|
| 433 | + } else { |
|
| 434 | + $delai = "$secondes " . _T('date_secondes'); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return _T($il_y_a, ['delai' => $delai]); |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -465,32 +465,32 @@ discard block |
||
| 465 | 465 | **/ |
| 466 | 466 | function date_relativecourt($date, $decalage_maxi = 0): string { |
| 467 | 467 | |
| 468 | - if (!$date) { |
|
| 469 | - return ''; |
|
| 470 | - } |
|
| 471 | - $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 472 | - |
|
| 473 | - if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 474 | - return ''; |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - if ($decal < -24 * 3600) { |
|
| 478 | - $retour = date_relative($date, $decalage_maxi); |
|
| 479 | - } elseif ($decal < 0) { |
|
| 480 | - $retour = _T('date_demain'); |
|
| 481 | - } else { |
|
| 482 | - if ($decal < (3600 * 24)) { |
|
| 483 | - $retour = _T('date_aujourdhui'); |
|
| 484 | - } else { |
|
| 485 | - if ($decal < (3600 * 24 * 2)) { |
|
| 486 | - $retour = _T('date_hier'); |
|
| 487 | - } else { |
|
| 488 | - $retour = date_relative($date, $decalage_maxi); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - } |
|
| 492 | - |
|
| 493 | - return $retour; |
|
| 468 | + if (!$date) { |
|
| 469 | + return ''; |
|
| 470 | + } |
|
| 471 | + $decal = date('U', strtotime(date('Y-m-d')) - strtotime(date('Y-m-d', strtotime($date)))); |
|
| 472 | + |
|
| 473 | + if ($decalage_maxi and ($decal > $decalage_maxi or $decal < 0)) { |
|
| 474 | + return ''; |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + if ($decal < -24 * 3600) { |
|
| 478 | + $retour = date_relative($date, $decalage_maxi); |
|
| 479 | + } elseif ($decal < 0) { |
|
| 480 | + $retour = _T('date_demain'); |
|
| 481 | + } else { |
|
| 482 | + if ($decal < (3600 * 24)) { |
|
| 483 | + $retour = _T('date_aujourdhui'); |
|
| 484 | + } else { |
|
| 485 | + if ($decal < (3600 * 24 * 2)) { |
|
| 486 | + $retour = _T('date_hier'); |
|
| 487 | + } else { |
|
| 488 | + $retour = date_relative($date, $decalage_maxi); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + |
|
| 493 | + return $retour; |
|
| 494 | 494 | } |
| 495 | 495 | |
| 496 | 496 | /** |
@@ -507,174 +507,174 @@ discard block |
||
| 507 | 507 | * @return string |
| 508 | 508 | */ |
| 509 | 509 | function affdate_base($numdate, $vue, $options = []): string { |
| 510 | - if (is_string($options)) { |
|
| 511 | - $options = ['param' => $options]; |
|
| 512 | - } |
|
| 513 | - $date_array = recup_date($numdate, false); |
|
| 514 | - if (!$date_array) { |
|
| 515 | - return ''; |
|
| 516 | - } |
|
| 517 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 518 | - |
|
| 519 | - // 1er, 21st, etc. |
|
| 520 | - $journum = $jour; |
|
| 521 | - |
|
| 522 | - if ($jour == 0) { |
|
| 523 | - $jour = ''; |
|
| 524 | - $njour = 0; |
|
| 525 | - } else { |
|
| 526 | - $njour = intval($jour); |
|
| 527 | - if ($jourth = _T('date_jnum' . $jour)) { |
|
| 528 | - $jour = $jourth; |
|
| 529 | - } |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - $mois = intval($mois); |
|
| 533 | - if ($mois > 0 and $mois < 13) { |
|
| 534 | - /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 535 | - $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 536 | - $nommois = _T('date_mois_' . $mois . $param); |
|
| 537 | - if ($jour) { |
|
| 538 | - $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 539 | - } else { |
|
| 540 | - $jourmois = $nommois; |
|
| 541 | - } |
|
| 542 | - } else { |
|
| 543 | - $nommois = ''; |
|
| 544 | - $jourmois = ''; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - if ($annee < 0) { |
|
| 548 | - $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 549 | - $avjc = true; |
|
| 550 | - } else { |
|
| 551 | - $avjc = false; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - switch ($vue) { |
|
| 555 | - case 'saison': |
|
| 556 | - case 'saison_annee': |
|
| 557 | - $saison = ''; |
|
| 558 | - if ($mois > 0) { |
|
| 559 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 560 | - if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 561 | - $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 562 | - } |
|
| 563 | - if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 564 | - $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 565 | - } |
|
| 566 | - if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 567 | - $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 568 | - } |
|
| 569 | - if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 570 | - $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 571 | - } |
|
| 572 | - } |
|
| 573 | - if ($vue == 'saison') { |
|
| 574 | - return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 575 | - } else { |
|
| 576 | - return $saison ? trim(_T( |
|
| 577 | - 'date_fmt_saison_annee', |
|
| 578 | - ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 579 | - )) : ''; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - case 'court': |
|
| 583 | - if ($avjc) { |
|
| 584 | - return $annee; |
|
| 585 | - } |
|
| 586 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 587 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 588 | - return $annee; |
|
| 589 | - } |
|
| 590 | - if ($annee != $a) { |
|
| 591 | - return _T( |
|
| 592 | - 'date_fmt_mois_annee', |
|
| 593 | - ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return _T( |
|
| 598 | - 'date_fmt_jour_mois', |
|
| 599 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 600 | - ); |
|
| 601 | - |
|
| 602 | - case 'jourcourt': |
|
| 603 | - if ($avjc) { |
|
| 604 | - return $annee; |
|
| 605 | - } |
|
| 606 | - $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 607 | - if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 608 | - return $annee; |
|
| 609 | - } |
|
| 610 | - if ($annee != $a) { |
|
| 611 | - return _T( |
|
| 612 | - 'date_fmt_jour_mois_annee', |
|
| 613 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 614 | - ); |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return _T( |
|
| 618 | - 'date_fmt_jour_mois', |
|
| 619 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 620 | - ); |
|
| 621 | - |
|
| 622 | - case 'entier': |
|
| 623 | - if ($avjc) { |
|
| 624 | - return $annee; |
|
| 625 | - } |
|
| 626 | - if ($jour) { |
|
| 627 | - return _T( |
|
| 628 | - 'date_fmt_jour_mois_annee', |
|
| 629 | - ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 630 | - ); |
|
| 631 | - } elseif ($mois) { |
|
| 632 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 633 | - } else { |
|
| 634 | - return $annee; |
|
| 635 | - } |
|
| 636 | - |
|
| 637 | - case 'nom_mois': |
|
| 638 | - return $nommois; |
|
| 639 | - |
|
| 640 | - case 'mois': |
|
| 641 | - return sprintf('%02s', $mois); |
|
| 642 | - |
|
| 643 | - case 'jour': |
|
| 644 | - return $jour; |
|
| 645 | - |
|
| 646 | - case 'journum': |
|
| 647 | - return $journum; |
|
| 648 | - |
|
| 649 | - case 'nom_jour': |
|
| 650 | - if (!$mois or !$njour) { |
|
| 651 | - return ''; |
|
| 652 | - } |
|
| 653 | - $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 654 | - $nom = 1 + (int) date('w', $nom); |
|
| 655 | - $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 656 | - |
|
| 657 | - return _T('date_jour_' . $nom . $param); |
|
| 658 | - |
|
| 659 | - case 'mois_annee': |
|
| 660 | - if ($avjc) { |
|
| 661 | - return $annee; |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 665 | - |
|
| 666 | - case 'annee': |
|
| 667 | - return $annee; |
|
| 668 | - |
|
| 669 | - // Cas d'une vue non definie : retomber sur le format |
|
| 670 | - // de date propose par http://www.php.net/date |
|
| 671 | - default: |
|
| 672 | - [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 673 | - if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 674 | - $time = strtotime($numdate); |
|
| 675 | - } |
|
| 676 | - return date($vue, $time); |
|
| 677 | - } |
|
| 510 | + if (is_string($options)) { |
|
| 511 | + $options = ['param' => $options]; |
|
| 512 | + } |
|
| 513 | + $date_array = recup_date($numdate, false); |
|
| 514 | + if (!$date_array) { |
|
| 515 | + return ''; |
|
| 516 | + } |
|
| 517 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 518 | + |
|
| 519 | + // 1er, 21st, etc. |
|
| 520 | + $journum = $jour; |
|
| 521 | + |
|
| 522 | + if ($jour == 0) { |
|
| 523 | + $jour = ''; |
|
| 524 | + $njour = 0; |
|
| 525 | + } else { |
|
| 526 | + $njour = intval($jour); |
|
| 527 | + if ($jourth = _T('date_jnum' . $jour)) { |
|
| 528 | + $jour = $jourth; |
|
| 529 | + } |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + $mois = intval($mois); |
|
| 533 | + if ($mois > 0 and $mois < 13) { |
|
| 534 | + /* Traiter le cas "abbr" pour les noms de mois */ |
|
| 535 | + $param = ((isset($options['param']) and $options['param'] === 'abbr') ? '_' . $options['param'] : ''); |
|
| 536 | + $nommois = _T('date_mois_' . $mois . $param); |
|
| 537 | + if ($jour) { |
|
| 538 | + $jourmois = _T('date_de_mois_' . $mois, ['j' => $jour, 'nommois' => $nommois]); |
|
| 539 | + } else { |
|
| 540 | + $jourmois = $nommois; |
|
| 541 | + } |
|
| 542 | + } else { |
|
| 543 | + $nommois = ''; |
|
| 544 | + $jourmois = ''; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + if ($annee < 0) { |
|
| 548 | + $annee = -$annee . ' ' . _T('date_avant_jc'); |
|
| 549 | + $avjc = true; |
|
| 550 | + } else { |
|
| 551 | + $avjc = false; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + switch ($vue) { |
|
| 555 | + case 'saison': |
|
| 556 | + case 'saison_annee': |
|
| 557 | + $saison = ''; |
|
| 558 | + if ($mois > 0) { |
|
| 559 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 560 | + if (($mois == 3 and $jour >= 21) or $mois > 3) { |
|
| 561 | + $saison = ($options['param'] == 'sud') ? 4 : 2; |
|
| 562 | + } |
|
| 563 | + if (($mois == 6 and $jour >= 21) or $mois > 6) { |
|
| 564 | + $saison = ($options['param'] == 'sud') ? 1 : 3; |
|
| 565 | + } |
|
| 566 | + if (($mois == 9 and $jour >= 21) or $mois > 9) { |
|
| 567 | + $saison = ($options['param'] == 'sud') ? 2 : 4; |
|
| 568 | + } |
|
| 569 | + if (($mois == 12 and $jour >= 21) or $mois > 12) { |
|
| 570 | + $saison = ($options['param'] == 'sud') ? 3 : 1; |
|
| 571 | + } |
|
| 572 | + } |
|
| 573 | + if ($vue == 'saison') { |
|
| 574 | + return $saison ? _T('date_saison_' . $saison) : ''; |
|
| 575 | + } else { |
|
| 576 | + return $saison ? trim(_T( |
|
| 577 | + 'date_fmt_saison_annee', |
|
| 578 | + ['saison' => _T('date_saison_' . $saison), 'annee' => $annee] |
|
| 579 | + )) : ''; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + case 'court': |
|
| 583 | + if ($avjc) { |
|
| 584 | + return $annee; |
|
| 585 | + } |
|
| 586 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 587 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 588 | + return $annee; |
|
| 589 | + } |
|
| 590 | + if ($annee != $a) { |
|
| 591 | + return _T( |
|
| 592 | + 'date_fmt_mois_annee', |
|
| 593 | + ['mois' => $mois, 'nommois' => spip_ucfirst($nommois), 'annee' => $annee] |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return _T( |
|
| 598 | + 'date_fmt_jour_mois', |
|
| 599 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 600 | + ); |
|
| 601 | + |
|
| 602 | + case 'jourcourt': |
|
| 603 | + if ($avjc) { |
|
| 604 | + return $annee; |
|
| 605 | + } |
|
| 606 | + $a = ((isset($options['annee_courante']) and $options['annee_courante']) ? $options['annee_courante'] : date('Y')); |
|
| 607 | + if ($annee < ($a - 100) or $annee > ($a + 100)) { |
|
| 608 | + return $annee; |
|
| 609 | + } |
|
| 610 | + if ($annee != $a) { |
|
| 611 | + return _T( |
|
| 612 | + 'date_fmt_jour_mois_annee', |
|
| 613 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 614 | + ); |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return _T( |
|
| 618 | + 'date_fmt_jour_mois', |
|
| 619 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 620 | + ); |
|
| 621 | + |
|
| 622 | + case 'entier': |
|
| 623 | + if ($avjc) { |
|
| 624 | + return $annee; |
|
| 625 | + } |
|
| 626 | + if ($jour) { |
|
| 627 | + return _T( |
|
| 628 | + 'date_fmt_jour_mois_annee', |
|
| 629 | + ['jourmois' => $jourmois, 'jour' => $jour, 'mois' => $mois, 'nommois' => $nommois, 'annee' => $annee] |
|
| 630 | + ); |
|
| 631 | + } elseif ($mois) { |
|
| 632 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 633 | + } else { |
|
| 634 | + return $annee; |
|
| 635 | + } |
|
| 636 | + |
|
| 637 | + case 'nom_mois': |
|
| 638 | + return $nommois; |
|
| 639 | + |
|
| 640 | + case 'mois': |
|
| 641 | + return sprintf('%02s', $mois); |
|
| 642 | + |
|
| 643 | + case 'jour': |
|
| 644 | + return $jour; |
|
| 645 | + |
|
| 646 | + case 'journum': |
|
| 647 | + return $journum; |
|
| 648 | + |
|
| 649 | + case 'nom_jour': |
|
| 650 | + if (!$mois or !$njour) { |
|
| 651 | + return ''; |
|
| 652 | + } |
|
| 653 | + $nom = mktime(1, 1, 1, $mois, $njour, $annee); |
|
| 654 | + $nom = 1 + (int) date('w', $nom); |
|
| 655 | + $param = ((isset($options['param']) and $options['param']) ? '_' . $options['param'] : ''); |
|
| 656 | + |
|
| 657 | + return _T('date_jour_' . $nom . $param); |
|
| 658 | + |
|
| 659 | + case 'mois_annee': |
|
| 660 | + if ($avjc) { |
|
| 661 | + return $annee; |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + return trim(_T('date_fmt_mois_annee', ['mois' => $mois, 'nommois' => $nommois, 'annee' => $annee])); |
|
| 665 | + |
|
| 666 | + case 'annee': |
|
| 667 | + return $annee; |
|
| 668 | + |
|
| 669 | + // Cas d'une vue non definie : retomber sur le format |
|
| 670 | + // de date propose par http://www.php.net/date |
|
| 671 | + default: |
|
| 672 | + [$annee, $mois, $jour, $heures, $minutes, $secondes] = $date_array; |
|
| 673 | + if (!$time = mktime($heures, $minutes, $secondes, $mois, (int) $jour, $annee)) { |
|
| 674 | + $time = strtotime($numdate); |
|
| 675 | + } |
|
| 676 | + return date($vue, $time); |
|
| 677 | + } |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | |
@@ -701,11 +701,11 @@ discard block |
||
| 701 | 701 | * Nom du jour |
| 702 | 702 | **/ |
| 703 | 703 | function nom_jour($numdate, $forme = ''): string { |
| 704 | - if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 705 | - $forme = ''; |
|
| 706 | - } |
|
| 704 | + if (!($forme === 'abbr' or $forme === 'initiale')) { |
|
| 705 | + $forme = ''; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | - return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 708 | + return affdate_base($numdate, 'nom_jour', ['param' => $forme]); |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | /** |
@@ -727,7 +727,7 @@ discard block |
||
| 727 | 727 | * Numéro du jour |
| 728 | 728 | **/ |
| 729 | 729 | function jour($numdate): string { |
| 730 | - return affdate_base($numdate, 'jour'); |
|
| 730 | + return affdate_base($numdate, 'jour'); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -745,7 +745,7 @@ discard block |
||
| 745 | 745 | * Numéro du jour |
| 746 | 746 | **/ |
| 747 | 747 | function journum($numdate): string { |
| 748 | - return affdate_base($numdate, 'journum'); |
|
| 748 | + return affdate_base($numdate, 'journum'); |
|
| 749 | 749 | } |
| 750 | 750 | |
| 751 | 751 | /** |
@@ -763,7 +763,7 @@ discard block |
||
| 763 | 763 | * Numéro du mois (sur 2 chiffres) |
| 764 | 764 | **/ |
| 765 | 765 | function mois($numdate): string { |
| 766 | - return affdate_base($numdate, 'mois'); |
|
| 766 | + return affdate_base($numdate, 'mois'); |
|
| 767 | 767 | } |
| 768 | 768 | |
| 769 | 769 | /** |
@@ -787,11 +787,11 @@ discard block |
||
| 787 | 787 | * Nom du mois |
| 788 | 788 | **/ |
| 789 | 789 | function nom_mois($numdate, $forme = ''): string { |
| 790 | - if (!($forme === 'abbr')) { |
|
| 791 | - $forme = ''; |
|
| 792 | - } |
|
| 790 | + if (!($forme === 'abbr')) { |
|
| 791 | + $forme = ''; |
|
| 792 | + } |
|
| 793 | 793 | |
| 794 | - return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 794 | + return affdate_base($numdate, 'nom_mois', ['param' => $forme]); |
|
| 795 | 795 | } |
| 796 | 796 | |
| 797 | 797 | /** |
@@ -809,7 +809,7 @@ discard block |
||
| 809 | 809 | * Année (sur 4 chiffres) |
| 810 | 810 | **/ |
| 811 | 811 | function annee($numdate): string { |
| 812 | - return affdate_base($numdate, 'annee'); |
|
| 812 | + return affdate_base($numdate, 'annee'); |
|
| 813 | 813 | } |
| 814 | 814 | |
| 815 | 815 | |
@@ -839,11 +839,11 @@ discard block |
||
| 839 | 839 | * La date formatée |
| 840 | 840 | **/ |
| 841 | 841 | function saison($numdate, $hemisphere = 'nord'): string { |
| 842 | - if ($hemisphere !== 'sud') { |
|
| 843 | - $hemisphere = 'nord'; |
|
| 844 | - } |
|
| 842 | + if ($hemisphere !== 'sud') { |
|
| 843 | + $hemisphere = 'nord'; |
|
| 844 | + } |
|
| 845 | 845 | |
| 846 | - return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 846 | + return affdate_base($numdate, 'saison', ['param' => $hemisphere]); |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | |
@@ -872,11 +872,11 @@ discard block |
||
| 872 | 872 | * La date formatée |
| 873 | 873 | **/ |
| 874 | 874 | function saison_annee($numdate, $hemisphere = 'nord'): string { |
| 875 | - if ($hemisphere !== 'sud') { |
|
| 876 | - $hemisphere = 'nord'; |
|
| 877 | - } |
|
| 875 | + if ($hemisphere !== 'sud') { |
|
| 876 | + $hemisphere = 'nord'; |
|
| 877 | + } |
|
| 878 | 878 | |
| 879 | - return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 879 | + return affdate_base($numdate, 'saison_annee', ['param' => $hemisphere]); |
|
| 880 | 880 | } |
| 881 | 881 | |
| 882 | 882 | /** |
@@ -904,7 +904,7 @@ discard block |
||
| 904 | 904 | * La date formatée |
| 905 | 905 | **/ |
| 906 | 906 | function affdate($numdate, $format = 'entier'): string { |
| 907 | - return affdate_base($numdate, $format); |
|
| 907 | + return affdate_base($numdate, $format); |
|
| 908 | 908 | } |
| 909 | 909 | |
| 910 | 910 | |
@@ -931,7 +931,7 @@ discard block |
||
| 931 | 931 | * La date formatée |
| 932 | 932 | **/ |
| 933 | 933 | function affdate_court($numdate, $annee_courante = null): string { |
| 934 | - return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 934 | + return affdate_base($numdate, 'court', ['annee_courante' => $annee_courante]); |
|
| 935 | 935 | } |
| 936 | 936 | |
| 937 | 937 | |
@@ -958,7 +958,7 @@ discard block |
||
| 958 | 958 | * La date formatée |
| 959 | 959 | **/ |
| 960 | 960 | function affdate_jourcourt($numdate, $annee_courante = null): string { |
| 961 | - return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 961 | + return affdate_base($numdate, 'jourcourt', ['annee_courante' => $annee_courante]); |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | /** |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | * La date formatée |
| 977 | 977 | **/ |
| 978 | 978 | function affdate_mois_annee($numdate): string { |
| 979 | - return affdate_base($numdate, 'mois_annee'); |
|
| 979 | + return affdate_base($numdate, 'mois_annee'); |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | /** |
@@ -994,16 +994,16 @@ discard block |
||
| 994 | 994 | * La date formatée, sinon '' |
| 995 | 995 | **/ |
| 996 | 996 | function affdate_heure($numdate): string { |
| 997 | - $date_array = recup_date($numdate); |
|
| 998 | - if (!$date_array) { |
|
| 999 | - return ''; |
|
| 1000 | - } |
|
| 1001 | - [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1002 | - |
|
| 1003 | - return _T('date_fmt_jour_heure', [ |
|
| 1004 | - 'jour' => affdate($numdate), |
|
| 1005 | - 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1006 | - ]); |
|
| 997 | + $date_array = recup_date($numdate); |
|
| 998 | + if (!$date_array) { |
|
| 999 | + return ''; |
|
| 1000 | + } |
|
| 1001 | + [$annee, $mois, $jour, $heures, $minutes, $sec] = $date_array; |
|
| 1002 | + |
|
| 1003 | + return _T('date_fmt_jour_heure', [ |
|
| 1004 | + 'jour' => affdate($numdate), |
|
| 1005 | + 'heure' => _T('date_fmt_heures_minutes', ['h' => $heures, 'm' => $minutes]) |
|
| 1006 | + ]); |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1035,117 +1035,117 @@ discard block |
||
| 1035 | 1035 | * texte de la date |
| 1036 | 1036 | */ |
| 1037 | 1037 | function affdate_debut_fin($date_debut, $date_fin, $horaire = 'oui', $forme = ''): string { |
| 1038 | - $abbr = $jour = ''; |
|
| 1039 | - $affdate = 'affdate_jourcourt'; |
|
| 1040 | - if (strpos($forme, 'abbr') !== false) { |
|
| 1041 | - $abbr = 'abbr'; |
|
| 1042 | - } |
|
| 1043 | - if (strpos($forme, 'annee') !== false) { |
|
| 1044 | - $affdate = 'affdate'; |
|
| 1045 | - } |
|
| 1046 | - if (strpos($forme, 'jour') !== false) { |
|
| 1047 | - $jour = 'jour'; |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - $dtstart = $dtend = $dtabbr = ''; |
|
| 1051 | - if (strpos($forme, 'hcal') !== false) { |
|
| 1052 | - $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1053 | - $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1054 | - $dtabbr = '</abbr>'; |
|
| 1055 | - } |
|
| 1056 | - |
|
| 1057 | - $date_debut = strtotime($date_debut); |
|
| 1058 | - $date_fin = strtotime($date_fin); |
|
| 1059 | - $d = date('Y-m-d', $date_debut); |
|
| 1060 | - $f = date('Y-m-d', $date_fin); |
|
| 1061 | - $h = ($horaire === 'oui' or $horaire === true); |
|
| 1062 | - $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1063 | - $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1064 | - |
|
| 1065 | - if ($d == $f) { // meme jour |
|
| 1066 | - $nomjour = nom_jour($d, $abbr); |
|
| 1067 | - $s = $affdate($d); |
|
| 1068 | - $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1069 | - if ($h) { |
|
| 1070 | - if ($hd == $hf) { |
|
| 1071 | - // Lundi 20 fevrier a 18h25 |
|
| 1072 | - $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1073 | - $s = "$dtstart$s$dtabbr"; |
|
| 1074 | - } else { |
|
| 1075 | - // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1076 | - if ($dtabbr && $dtstart && $dtend) { |
|
| 1077 | - $s = _T( |
|
| 1078 | - 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1079 | - [ |
|
| 1080 | - 'jour' => spip_ucfirst($s), |
|
| 1081 | - 'heure_debut' => $hd, |
|
| 1082 | - 'heure_fin' => $hf, |
|
| 1083 | - 'dtstart' => $dtstart, |
|
| 1084 | - 'dtend' => $dtend, |
|
| 1085 | - 'dtabbr' => $dtabbr |
|
| 1086 | - ], |
|
| 1087 | - [ |
|
| 1088 | - 'sanitize' => false |
|
| 1089 | - ] |
|
| 1090 | - ); |
|
| 1091 | - } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1092 | - else { |
|
| 1093 | - $s = spip_ucfirst(_T( |
|
| 1094 | - 'date_fmt_jour_heure_debut_fin', |
|
| 1095 | - ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1096 | - )); |
|
| 1097 | - } |
|
| 1098 | - } |
|
| 1099 | - } else { |
|
| 1100 | - if ($dtabbr && $dtstart) { |
|
| 1101 | - $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1102 | - } else { |
|
| 1103 | - $s = spip_ucfirst($s); |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1106 | - } else { |
|
| 1107 | - if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1108 | - if (!$h) { |
|
| 1109 | - $date_debut = jour($d); |
|
| 1110 | - } else { |
|
| 1111 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1112 | - } |
|
| 1113 | - $date_fin = $affdate($f); |
|
| 1114 | - if ($jour) { |
|
| 1115 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1116 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1117 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1118 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1119 | - } |
|
| 1120 | - if ($h) { |
|
| 1121 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1122 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1123 | - } |
|
| 1124 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1125 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1126 | - |
|
| 1127 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1128 | - } else { |
|
| 1129 | - $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1130 | - $date_fin = $affdate($f); |
|
| 1131 | - if ($jour) { |
|
| 1132 | - $nomjour_debut = nom_jour($d, $abbr); |
|
| 1133 | - $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1134 | - $nomjour_fin = nom_jour($f, $abbr); |
|
| 1135 | - $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1136 | - } |
|
| 1137 | - if ($h) { |
|
| 1138 | - $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1139 | - $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1140 | - } |
|
| 1141 | - |
|
| 1142 | - $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1143 | - $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1144 | - $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1145 | - } |
|
| 1146 | - } |
|
| 1147 | - |
|
| 1148 | - return $s; |
|
| 1038 | + $abbr = $jour = ''; |
|
| 1039 | + $affdate = 'affdate_jourcourt'; |
|
| 1040 | + if (strpos($forme, 'abbr') !== false) { |
|
| 1041 | + $abbr = 'abbr'; |
|
| 1042 | + } |
|
| 1043 | + if (strpos($forme, 'annee') !== false) { |
|
| 1044 | + $affdate = 'affdate'; |
|
| 1045 | + } |
|
| 1046 | + if (strpos($forme, 'jour') !== false) { |
|
| 1047 | + $jour = 'jour'; |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + $dtstart = $dtend = $dtabbr = ''; |
|
| 1051 | + if (strpos($forme, 'hcal') !== false) { |
|
| 1052 | + $dtstart = "<abbr class='dtstart' title='" . date_iso($date_debut) . "'>"; |
|
| 1053 | + $dtend = "<abbr class='dtend' title='" . date_iso($date_fin) . "'>"; |
|
| 1054 | + $dtabbr = '</abbr>'; |
|
| 1055 | + } |
|
| 1056 | + |
|
| 1057 | + $date_debut = strtotime($date_debut); |
|
| 1058 | + $date_fin = strtotime($date_fin); |
|
| 1059 | + $d = date('Y-m-d', $date_debut); |
|
| 1060 | + $f = date('Y-m-d', $date_fin); |
|
| 1061 | + $h = ($horaire === 'oui' or $horaire === true); |
|
| 1062 | + $hd = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_debut), 'm' => date('i', $date_debut)]); |
|
| 1063 | + $hf = _T('date_fmt_heures_minutes_court', ['h' => date('H', $date_fin), 'm' => date('i', $date_fin)]); |
|
| 1064 | + |
|
| 1065 | + if ($d == $f) { // meme jour |
|
| 1066 | + $nomjour = nom_jour($d, $abbr); |
|
| 1067 | + $s = $affdate($d); |
|
| 1068 | + $s = _T('date_fmt_jour', ['nomjour' => $nomjour, 'jour' => $s]); |
|
| 1069 | + if ($h) { |
|
| 1070 | + if ($hd == $hf) { |
|
| 1071 | + // Lundi 20 fevrier a 18h25 |
|
| 1072 | + $s = spip_ucfirst(_T('date_fmt_jour_heure', ['jour' => $s, 'heure' => $hd])); |
|
| 1073 | + $s = "$dtstart$s$dtabbr"; |
|
| 1074 | + } else { |
|
| 1075 | + // Le <abbr...>lundi 20 fevrier de 18h00</abbr> a <abbr...>20h00</abbr> |
|
| 1076 | + if ($dtabbr && $dtstart && $dtend) { |
|
| 1077 | + $s = _T( |
|
| 1078 | + 'date_fmt_jour_heure_debut_fin_abbr', |
|
| 1079 | + [ |
|
| 1080 | + 'jour' => spip_ucfirst($s), |
|
| 1081 | + 'heure_debut' => $hd, |
|
| 1082 | + 'heure_fin' => $hf, |
|
| 1083 | + 'dtstart' => $dtstart, |
|
| 1084 | + 'dtend' => $dtend, |
|
| 1085 | + 'dtabbr' => $dtabbr |
|
| 1086 | + ], |
|
| 1087 | + [ |
|
| 1088 | + 'sanitize' => false |
|
| 1089 | + ] |
|
| 1090 | + ); |
|
| 1091 | + } // Le lundi 20 fevrier de 18h00 a 20h00 |
|
| 1092 | + else { |
|
| 1093 | + $s = spip_ucfirst(_T( |
|
| 1094 | + 'date_fmt_jour_heure_debut_fin', |
|
| 1095 | + ['jour' => $s, 'heure_debut' => $hd, 'heure_fin' => $hf] |
|
| 1096 | + )); |
|
| 1097 | + } |
|
| 1098 | + } |
|
| 1099 | + } else { |
|
| 1100 | + if ($dtabbr && $dtstart) { |
|
| 1101 | + $s = $dtstart . spip_ucfirst($s) . $dtabbr; |
|
| 1102 | + } else { |
|
| 1103 | + $s = spip_ucfirst($s); |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | + } else { |
|
| 1107 | + if ((date('Y-m', $date_debut)) == date('Y-m', $date_fin)) { // meme annee et mois, jours differents |
|
| 1108 | + if (!$h) { |
|
| 1109 | + $date_debut = jour($d); |
|
| 1110 | + } else { |
|
| 1111 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1112 | + } |
|
| 1113 | + $date_fin = $affdate($f); |
|
| 1114 | + if ($jour) { |
|
| 1115 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1116 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1117 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1118 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1119 | + } |
|
| 1120 | + if ($h) { |
|
| 1121 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1122 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1123 | + } |
|
| 1124 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1125 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1126 | + |
|
| 1127 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1128 | + } else { |
|
| 1129 | + $date_debut = affdate_jourcourt($d, date('Y', $date_fin)); |
|
| 1130 | + $date_fin = $affdate($f); |
|
| 1131 | + if ($jour) { |
|
| 1132 | + $nomjour_debut = nom_jour($d, $abbr); |
|
| 1133 | + $date_debut = _T('date_fmt_jour', ['nomjour' => $nomjour_debut, 'jour' => $date_debut]); |
|
| 1134 | + $nomjour_fin = nom_jour($f, $abbr); |
|
| 1135 | + $date_fin = _T('date_fmt_jour', ['nomjour' => $nomjour_fin, 'jour' => $date_fin]); |
|
| 1136 | + } |
|
| 1137 | + if ($h) { |
|
| 1138 | + $date_debut = _T('date_fmt_jour_heure', ['jour' => $date_debut, 'heure' => $hd]); |
|
| 1139 | + $date_fin = _T('date_fmt_jour_heure', ['jour' => $date_fin, 'heure' => $hf]); |
|
| 1140 | + } |
|
| 1141 | + |
|
| 1142 | + $date_debut = $dtstart . $date_debut . $dtabbr; |
|
| 1143 | + $date_fin = $dtend . $date_fin . $dtabbr; |
|
| 1144 | + $s = _T('date_fmt_periode', ['date_debut' => $date_debut, 'date_fin' => $date_fin]); |
|
| 1145 | + } |
|
| 1146 | + } |
|
| 1147 | + |
|
| 1148 | + return $s; |
|
| 1149 | 1149 | } |
| 1150 | 1150 | |
| 1151 | 1151 | /** |
@@ -1166,10 +1166,10 @@ discard block |
||
| 1166 | 1166 | * Date au format ical |
| 1167 | 1167 | **/ |
| 1168 | 1168 | function date_ical($date, $addminutes = 0): string { |
| 1169 | - [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1170 | - [$annee, $mois, $jour] = recup_date($date); |
|
| 1169 | + [$heures, $minutes, $secondes] = recup_heure($date); |
|
| 1170 | + [$annee, $mois, $jour] = recup_date($date); |
|
| 1171 | 1171 | |
| 1172 | - return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1172 | + return gmdate('Ymd\THis\Z', mktime($heures, $minutes + $addminutes, $secondes, $mois, $jour, $annee)); |
|
| 1173 | 1173 | } |
| 1174 | 1174 | |
| 1175 | 1175 | |
@@ -1193,14 +1193,14 @@ discard block |
||
| 1193 | 1193 | * La date formatée |
| 1194 | 1194 | **/ |
| 1195 | 1195 | function date_iso($date_heure): string { |
| 1196 | - $date = recup_date($date_heure); |
|
| 1197 | - $annee = $date[0] ?? null; |
|
| 1198 | - $mois = $date[1] ?? null; |
|
| 1199 | - $jour = $date[2] ?? null; |
|
| 1200 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1201 | - $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1202 | - |
|
| 1203 | - return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1196 | + $date = recup_date($date_heure); |
|
| 1197 | + $annee = $date[0] ?? null; |
|
| 1198 | + $mois = $date[1] ?? null; |
|
| 1199 | + $jour = $date[2] ?? null; |
|
| 1200 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1201 | + $time = @mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1202 | + |
|
| 1203 | + return gmdate('Y-m-d\TH:i:s\Z', $time); |
|
| 1204 | 1204 | } |
| 1205 | 1205 | |
| 1206 | 1206 | /** |
@@ -1223,11 +1223,11 @@ discard block |
||
| 1223 | 1223 | * La date formatée |
| 1224 | 1224 | **/ |
| 1225 | 1225 | function date_822($date_heure): string { |
| 1226 | - [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1227 | - [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1228 | - $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1226 | + [$annee, $mois, $jour] = recup_date($date_heure); |
|
| 1227 | + [$heures, $minutes, $secondes] = recup_heure($date_heure); |
|
| 1228 | + $time = mktime($heures, $minutes, $secondes, $mois, $jour, $annee); |
|
| 1229 | 1229 | |
| 1230 | - return date('r', $time); |
|
| 1230 | + return date('r', $time); |
|
| 1231 | 1231 | } |
| 1232 | 1232 | |
| 1233 | 1233 | /** |
@@ -1243,11 +1243,11 @@ discard block |
||
| 1243 | 1243 | * Date au format `Ymd` |
| 1244 | 1244 | **/ |
| 1245 | 1245 | function date_anneemoisjour($d): string { |
| 1246 | - if (!$d) { |
|
| 1247 | - $d = date('Y-m-d'); |
|
| 1248 | - } |
|
| 1246 | + if (!$d) { |
|
| 1247 | + $d = date('Y-m-d'); |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1250 | + return substr($d, 0, 4) . substr($d, 5, 2) . substr($d, 8, 2); |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | /** |
@@ -1263,11 +1263,11 @@ discard block |
||
| 1263 | 1263 | * Date au format `Ym` |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function date_anneemois($d): string { |
| 1266 | - if (!$d) { |
|
| 1267 | - $d = date('Y-m-d'); |
|
| 1268 | - } |
|
| 1266 | + if (!$d) { |
|
| 1267 | + $d = date('Y-m-d'); |
|
| 1268 | + } |
|
| 1269 | 1269 | |
| 1270 | - return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1270 | + return substr($d, 0, 4) . substr($d, 5, 2); |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | /** |
@@ -1283,13 +1283,13 @@ discard block |
||
| 1283 | 1283 | * Date au lundi de la même semaine au format `Ymd` |
| 1284 | 1284 | **/ |
| 1285 | 1285 | function date_debut_semaine($annee, $mois, $jour): string { |
| 1286 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1287 | - if ($w_day == 0) { |
|
| 1288 | - $w_day = 7; |
|
| 1289 | - } // Gaffe: le dimanche est zero |
|
| 1290 | - $debut = $jour - $w_day + 1; |
|
| 1286 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1287 | + if ($w_day == 0) { |
|
| 1288 | + $w_day = 7; |
|
| 1289 | + } // Gaffe: le dimanche est zero |
|
| 1290 | + $debut = $jour - $w_day + 1; |
|
| 1291 | 1291 | |
| 1292 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1292 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut, $annee)); |
|
| 1293 | 1293 | } |
| 1294 | 1294 | |
| 1295 | 1295 | /** |
@@ -1305,11 +1305,11 @@ discard block |
||
| 1305 | 1305 | * Date au dimanche de la même semaine au format `Ymd` |
| 1306 | 1306 | **/ |
| 1307 | 1307 | function date_fin_semaine($annee, $mois, $jour): string { |
| 1308 | - $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1309 | - if ($w_day == 0) { |
|
| 1310 | - $w_day = 7; |
|
| 1311 | - } // Gaffe: le dimanche est zero |
|
| 1312 | - $debut = $jour - $w_day + 1; |
|
| 1308 | + $w_day = date('w', mktime(0, 0, 0, $mois, $jour, $annee)); |
|
| 1309 | + if ($w_day == 0) { |
|
| 1310 | + $w_day = 7; |
|
| 1311 | + } // Gaffe: le dimanche est zero |
|
| 1312 | + $debut = $jour - $w_day + 1; |
|
| 1313 | 1313 | |
| 1314 | - return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1314 | + return date('Ymd', mktime(0, 0, 0, $mois, $debut + 6, $annee)); |
|
| 1315 | 1315 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('inc/filtres'); |
| 22 | 22 | include_spip('inc/lang'); |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function definir_puce() { |
| 40 | 40 | |
| 41 | - // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 42 | - // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 43 | - // celle du texte) et public (spip_lang est la langue du texte) |
|
| 44 | - $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 41 | + // Attention au sens, qui n'est pas defini de la meme facon dans |
|
| 42 | + // l'espace prive (spip_lang est la langue de l'interface, lang_dir |
|
| 43 | + // celle du texte) et public (spip_lang est la langue du texte) |
|
| 44 | + $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
|
| 45 | 45 | |
| 46 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | - if ($dir == 'rtl') { |
|
| 48 | - $p .= '_rtl'; |
|
| 49 | - } |
|
| 46 | + $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 47 | + if ($dir == 'rtl') { |
|
| 48 | + $p .= '_rtl'; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - if (!isset($GLOBALS[$p])) { |
|
| 52 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 53 | - } |
|
| 51 | + if (!isset($GLOBALS[$p])) { |
|
| 52 | + $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return $GLOBALS[$p]; |
|
| 55 | + return $GLOBALS[$p]; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -66,31 +66,31 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 68 | 68 | |
| 69 | - $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 70 | - $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | - if ($attributs) { |
|
| 72 | - $attributs = " " . trim($attributs); |
|
| 73 | - } |
|
| 74 | - if ($langage) { |
|
| 75 | - $class .= " language-$langage"; |
|
| 76 | - $attributs .= ' data-language="'. $langage .'"'; |
|
| 77 | - } |
|
| 78 | - if ($bloc) { |
|
| 79 | - $html = "<div class=\"precode\">" |
|
| 80 | - . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 81 | - . "<code>" |
|
| 82 | - . $echap |
|
| 83 | - . '</code>' |
|
| 84 | - . '</pre>' |
|
| 85 | - . '</div>'; |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - $echap = str_replace("\t", " ", $echap); |
|
| 89 | - $echap = str_replace(" ", " ", $echap); |
|
| 90 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - return $html; |
|
| 69 | + $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
|
| 70 | + $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | + if ($attributs) { |
|
| 72 | + $attributs = " " . trim($attributs); |
|
| 73 | + } |
|
| 74 | + if ($langage) { |
|
| 75 | + $class .= " language-$langage"; |
|
| 76 | + $attributs .= ' data-language="'. $langage .'"'; |
|
| 77 | + } |
|
| 78 | + if ($bloc) { |
|
| 79 | + $html = "<div class=\"precode\">" |
|
| 80 | + . "<pre class=\"$class\" dir=\"ltr\" style=\"text-align: left;\"$attributs>" |
|
| 81 | + . "<code>" |
|
| 82 | + . $echap |
|
| 83 | + . '</code>' |
|
| 84 | + . '</pre>' |
|
| 85 | + . '</div>'; |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + $echap = str_replace("\t", " ", $echap); |
|
| 89 | + $echap = str_replace(" ", " ", $echap); |
|
| 90 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + return $html; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | |
@@ -98,14 +98,14 @@ discard block |
||
| 98 | 98 | // dont on souhaite qu'ils provoquent un saut de paragraphe |
| 99 | 99 | |
| 100 | 100 | if (!defined('_BALISES_BLOCS')) { |
| 101 | - define( |
|
| 102 | - '_BALISES_BLOCS', |
|
| 103 | - 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 104 | - ); |
|
| 101 | + define( |
|
| 102 | + '_BALISES_BLOCS', |
|
| 103 | + 'address|applet|article|aside|blockquote|button|center|d[ltd]|div|fieldset|fig(ure|caption)|footer|form|h[1-6r]|hgroup|head|header|iframe|li|map|marquee|nav|noscript|object|ol|pre|section|t(able|[rdh]|body|foot|extarea)|ul|script|style' |
|
| 104 | + ); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 108 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 108 | + define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // |
@@ -116,100 +116,100 @@ discard block |
||
| 116 | 116 | // une $source differente ; le script detecte automagiquement si ce qu'on |
| 117 | 117 | // echappe est un div ou un span |
| 118 | 118 | function code_echappement($rempl, $source = '', $no_transform = false, $mode = null) { |
| 119 | - if (!strlen($rempl)) { |
|
| 120 | - return ''; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // Tester si on echappe en span ou en div |
|
| 124 | - if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 125 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 129 | - $taille = 30000; |
|
| 130 | - $return = ''; |
|
| 131 | - for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 132 | - // Convertir en base64 et cacher dans un attribut |
|
| 133 | - // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 134 | - $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 135 | - $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $return; |
|
| 119 | + if (!strlen($rempl)) { |
|
| 120 | + return ''; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // Tester si on echappe en span ou en div |
|
| 124 | + if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
|
| 125 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
|
| 129 | + $taille = 30000; |
|
| 130 | + $return = ''; |
|
| 131 | + for ($i = 0; $i < strlen($rempl); $i += $taille) { |
|
| 132 | + // Convertir en base64 et cacher dans un attribut |
|
| 133 | + // utiliser les " pour eviter le re-encodage de ' et ’ |
|
| 134 | + $base64 = base64_encode(substr($rempl, $i, $taille)); |
|
| 135 | + $return .= "<$mode class=\"base64$source\" title=\"$base64\"></$mode>"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $return; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | |
| 142 | 142 | // Echapper les <html>...</ html> |
| 143 | 143 | function traiter_echap_html_dist($regs, $options = []) { |
| 144 | - return $regs[3]; |
|
| 144 | + return $regs[3]; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | // Echapper les <pre>...</ pre> |
| 148 | 148 | function traiter_echap_pre_dist($regs, $options = []) { |
| 149 | - // echapper les <code> dans <pre> |
|
| 150 | - $pre = $regs[3]; |
|
| 151 | - |
|
| 152 | - // echapper les < dans <code> |
|
| 153 | - // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 154 | - if ( |
|
| 155 | - strpos($pre, '<') !== false |
|
| 156 | - and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 157 | - ) { |
|
| 158 | - foreach ($matches as $m) { |
|
| 159 | - if ($m[1] === 'code') { |
|
| 160 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 161 | - $pre = str_replace($m[0], $code, $pre); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 165 | - return "<pre>$pre</pre>"; |
|
| 149 | + // echapper les <code> dans <pre> |
|
| 150 | + $pre = $regs[3]; |
|
| 151 | + |
|
| 152 | + // echapper les < dans <code> |
|
| 153 | + // on utilise _PROTEGE_BLOCS pour simplifier le code et la maintenance, mais on est interesse que par <code> |
|
| 154 | + if ( |
|
| 155 | + strpos($pre, '<') !== false |
|
| 156 | + and preg_match_all(_PROTEGE_BLOCS, $pre, $matches, PREG_SET_ORDER) |
|
| 157 | + ) { |
|
| 158 | + foreach ($matches as $m) { |
|
| 159 | + if ($m[1] === 'code') { |
|
| 160 | + $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 161 | + $pre = str_replace($m[0], $code, $pre); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | + return "<pre>$pre</pre>"; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // Echapper les <code>...</ code> |
| 169 | 169 | function traiter_echap_code_dist($regs, $options = []) { |
| 170 | - [, , $att, $corps] = $regs; |
|
| 170 | + [, , $att, $corps] = $regs; |
|
| 171 | 171 | |
| 172 | - // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 173 | - if (strpos($corps, "\n") !== false) { |
|
| 174 | - // supprimer les sauts de ligne debut/fin |
|
| 175 | - // (mais pas les espaces => ascii art). |
|
| 176 | - $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 172 | + // ne pas mettre le <div...> s'il n'y a qu'une ligne |
|
| 173 | + if (strpos($corps, "\n") !== false) { |
|
| 174 | + // supprimer les sauts de ligne debut/fin |
|
| 175 | + // (mais pas les espaces => ascii art). |
|
| 176 | + $corps = preg_replace("/^[\n\r]+|[\n\r]+$/s", '', $corps); |
|
| 177 | 177 | |
| 178 | - $echap = spip_balisage_code($corps, true, $att); |
|
| 179 | - } else { |
|
| 180 | - $echap = spip_balisage_code($corps, false, $att); |
|
| 181 | - } |
|
| 178 | + $echap = spip_balisage_code($corps, true, $att); |
|
| 179 | + } else { |
|
| 180 | + $echap = spip_balisage_code($corps, false, $att); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $echap; |
|
| 183 | + return $echap; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | // Echapper les <cadre>...</ cadre> aka <frame>...</ frame> |
| 187 | 187 | function traiter_echap_cadre_dist($regs, $options = []) { |
| 188 | - $echap = trim(entites_html($regs[3])); |
|
| 189 | - // compter les lignes un peu plus finement qu'avec les \n |
|
| 190 | - $lignes = explode("\n", trim($echap)); |
|
| 191 | - $n = 0; |
|
| 192 | - foreach ($lignes as $l) { |
|
| 193 | - $n += floor(strlen($l) / 60) + 1; |
|
| 194 | - } |
|
| 195 | - $n = max($n, 2); |
|
| 196 | - $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 197 | - |
|
| 198 | - return $echap; |
|
| 188 | + $echap = trim(entites_html($regs[3])); |
|
| 189 | + // compter les lignes un peu plus finement qu'avec les \n |
|
| 190 | + $lignes = explode("\n", trim($echap)); |
|
| 191 | + $n = 0; |
|
| 192 | + foreach ($lignes as $l) { |
|
| 193 | + $n += floor(strlen($l) / 60) + 1; |
|
| 194 | + } |
|
| 195 | + $n = max($n, 2); |
|
| 196 | + $echap = "\n<textarea readonly='readonly' cols='40' rows='$n' class='spip_cadre spip_cadre_block' dir='ltr'>$echap</textarea>"; |
|
| 197 | + |
|
| 198 | + return $echap; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | function traiter_echap_frame_dist($regs, $options = []) { |
| 202 | - return traiter_echap_cadre_dist($regs); |
|
| 202 | + return traiter_echap_cadre_dist($regs); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | function traiter_echap_script_dist($regs, $options = []) { |
| 206 | - // rendre joli (et inactif) si c'est un script language=php |
|
| 207 | - if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 208 | - return highlight_string($regs[0], true); |
|
| 209 | - } |
|
| 206 | + // rendre joli (et inactif) si c'est un script language=php |
|
| 207 | + if (preg_match(',<script\b[^>]+php,ims', $regs[0])) { |
|
| 208 | + return highlight_string($regs[0], true); |
|
| 209 | + } |
|
| 210 | 210 | |
| 211 | - // Cas normal : le script passe tel quel |
|
| 212 | - return $regs[0]; |
|
| 211 | + // Cas normal : le script passe tel quel |
|
| 212 | + return $regs[0]; |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | define('_PROTEGE_BLOCS', ',<(html|pre|code|cadre|frame|script|style)(\b[^>]*)?>(.*)</\1>,UimsS'); |
@@ -228,74 +228,74 @@ discard block |
||
| 228 | 228 | * @return string|string[] |
| 229 | 229 | */ |
| 230 | 230 | function echappe_html( |
| 231 | - $letexte, |
|
| 232 | - $source = '', |
|
| 233 | - $no_transform = false, |
|
| 234 | - $preg = '', |
|
| 235 | - $callback_prefix = '', |
|
| 236 | - $callback_options = [] |
|
| 231 | + $letexte, |
|
| 232 | + $source = '', |
|
| 233 | + $no_transform = false, |
|
| 234 | + $preg = '', |
|
| 235 | + $callback_prefix = '', |
|
| 236 | + $callback_options = [] |
|
| 237 | 237 | ) { |
| 238 | - if (!is_string($letexte) or !strlen($letexte)) { |
|
| 239 | - return $letexte; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - if ( |
|
| 243 | - ($preg or str_contains($letexte, '<')) |
|
| 244 | - and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 245 | - ) { |
|
| 246 | - foreach ($matches as $regs) { |
|
| 247 | - $echap = ''; |
|
| 248 | - // echappements tels quels ? |
|
| 249 | - if ($no_transform) { |
|
| 250 | - $echap = $regs[0]; |
|
| 251 | - } else { |
|
| 252 | - // sinon les traiter selon le cas |
|
| 253 | - $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | - if ( |
|
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 257 | - or ($callback_secure_prefix and ( |
|
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 260 | - )) |
|
| 261 | - ) { |
|
| 262 | - $echap = $f($regs, $callback_options); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | - $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if ($no_transform) { |
|
| 272 | - return $letexte; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | - // seulement si on a echappe les <script> |
|
| 277 | - // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | - // dans une callback autonommee |
|
| 279 | - if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | - if ( |
|
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | - ',<[?].*($|[?]>),UisS', |
|
| 283 | - $letexte, |
|
| 284 | - $matches, |
|
| 285 | - PREG_SET_ORDER |
|
| 286 | - ) |
|
| 287 | - ) { |
|
| 288 | - foreach ($matches as $regs) { |
|
| 289 | - $letexte = str_replace( |
|
| 290 | - $regs[0], |
|
| 291 | - code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | - $letexte |
|
| 293 | - ); |
|
| 294 | - } |
|
| 295 | - } |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - return $letexte; |
|
| 238 | + if (!is_string($letexte) or !strlen($letexte)) { |
|
| 239 | + return $letexte; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + if ( |
|
| 243 | + ($preg or str_contains($letexte, '<')) |
|
| 244 | + and preg_match_all($preg ?: _PROTEGE_BLOCS, $letexte, $matches, PREG_SET_ORDER) |
|
| 245 | + ) { |
|
| 246 | + foreach ($matches as $regs) { |
|
| 247 | + $echap = ''; |
|
| 248 | + // echappements tels quels ? |
|
| 249 | + if ($no_transform) { |
|
| 250 | + $echap = $regs[0]; |
|
| 251 | + } else { |
|
| 252 | + // sinon les traiter selon le cas |
|
| 253 | + $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
|
| 254 | + if ( |
|
| 255 | + function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f . '_dist') |
|
| 257 | + or ($callback_secure_prefix and ( |
|
| 258 | + function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f . '_dist') |
|
| 260 | + )) |
|
| 261 | + ) { |
|
| 262 | + $echap = $f($regs, $callback_options); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + $p = strpos($letexte, (string) $regs[0]); |
|
| 267 | + $letexte = substr_replace($letexte, code_echappement($echap, $source, $no_transform), $p, strlen($regs[0])); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if ($no_transform) { |
|
| 272 | + return $letexte; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + // Echapper le php pour faire joli (ici, c'est pas pour la securite) |
|
| 276 | + // seulement si on a echappe les <script> |
|
| 277 | + // (derogatoire car on ne peut pas faire passer < ? ... ? > |
|
| 278 | + // dans une callback autonommee |
|
| 279 | + if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
|
| 280 | + if ( |
|
| 281 | + strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 282 | + ',<[?].*($|[?]>),UisS', |
|
| 283 | + $letexte, |
|
| 284 | + $matches, |
|
| 285 | + PREG_SET_ORDER |
|
| 286 | + ) |
|
| 287 | + ) { |
|
| 288 | + foreach ($matches as $regs) { |
|
| 289 | + $letexte = str_replace( |
|
| 290 | + $regs[0], |
|
| 291 | + code_echappement(highlight_string($regs[0], true), $source), |
|
| 292 | + $letexte |
|
| 293 | + ); |
|
| 294 | + } |
|
| 295 | + } |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + return $letexte; |
|
| 299 | 299 | } |
| 300 | 300 | |
| 301 | 301 | // |
@@ -303,57 +303,57 @@ discard block |
||
| 303 | 303 | // Rq: $source sert a faire des echappements "a soi" qui ne sont pas nettoyes |
| 304 | 304 | // par propre() : exemple dans multi et dans typo() |
| 305 | 305 | function echappe_retour($letexte, $source = '', $filtre = '') { |
| 306 | - if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | - # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | - $max_prof = 5; |
|
| 309 | - while ( |
|
| 310 | - strpos($letexte, '<') !== false |
|
| 311 | - and |
|
| 312 | - preg_match_all( |
|
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | - $letexte, |
|
| 315 | - $regs, |
|
| 316 | - PREG_SET_ORDER |
|
| 317 | - ) |
|
| 318 | - and $max_prof-- |
|
| 319 | - ) { |
|
| 320 | - foreach ($regs as $reg) { |
|
| 321 | - $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | - // recherche d'attributs supplementaires |
|
| 323 | - $at = []; |
|
| 324 | - foreach (['lang', 'dir'] as $attr) { |
|
| 325 | - if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | - $at[$attr] = $a; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if ($at) { |
|
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | - foreach ($at as $attr => $a) { |
|
| 332 | - $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | - } |
|
| 334 | - } |
|
| 335 | - if ($filtre) { |
|
| 336 | - $rempl = $filtre($rempl); |
|
| 337 | - } |
|
| 338 | - $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | - } |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - return $letexte; |
|
| 306 | + if (strpos($letexte, (string) "base64$source")) { |
|
| 307 | + # spip_log(spip_htmlspecialchars($letexte)); ## pour les curieux |
|
| 308 | + $max_prof = 5; |
|
| 309 | + while ( |
|
| 310 | + strpos($letexte, '<') !== false |
|
| 311 | + and |
|
| 312 | + preg_match_all( |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | + $letexte, |
|
| 315 | + $regs, |
|
| 316 | + PREG_SET_ORDER |
|
| 317 | + ) |
|
| 318 | + and $max_prof-- |
|
| 319 | + ) { |
|
| 320 | + foreach ($regs as $reg) { |
|
| 321 | + $rempl = base64_decode(extraire_attribut($reg[0], 'title')); |
|
| 322 | + // recherche d'attributs supplementaires |
|
| 323 | + $at = []; |
|
| 324 | + foreach (['lang', 'dir'] as $attr) { |
|
| 325 | + if ($a = extraire_attribut($reg[0], $attr)) { |
|
| 326 | + $at[$attr] = $a; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if ($at) { |
|
| 330 | + $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 331 | + foreach ($at as $attr => $a) { |
|
| 332 | + $rempl = inserer_attribut($rempl, $attr, $a); |
|
| 333 | + } |
|
| 334 | + } |
|
| 335 | + if ($filtre) { |
|
| 336 | + $rempl = $filtre($rempl); |
|
| 337 | + } |
|
| 338 | + $letexte = str_replace($reg[0], $rempl, $letexte); |
|
| 339 | + } |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + return $letexte; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | // Reinserer le javascript de confiance (venant des modeles) |
| 347 | 347 | |
| 348 | 348 | function echappe_retour_modeles($letexte, $interdire_scripts = false) { |
| 349 | - $letexte = echappe_retour($letexte); |
|
| 349 | + $letexte = echappe_retour($letexte); |
|
| 350 | 350 | |
| 351 | - // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | - if ($interdire_scripts) { |
|
| 353 | - $letexte = interdire_scripts($letexte); |
|
| 354 | - } |
|
| 351 | + // Dans les appels directs hors squelette, securiser aussi ici |
|
| 352 | + if ($interdire_scripts) { |
|
| 353 | + $letexte = interdire_scripts($letexte); |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return trim($letexte); |
|
| 356 | + return trim($letexte); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | |
@@ -381,128 +381,128 @@ discard block |
||
| 381 | 381 | * texte coupé |
| 382 | 382 | **/ |
| 383 | 383 | function couper($texte, $taille = 50, $suite = null) { |
| 384 | - if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | - return ''; |
|
| 386 | - } |
|
| 387 | - $offset = 400 + 2 * $taille; |
|
| 388 | - while ( |
|
| 389 | - $offset < $length |
|
| 390 | - and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | - ) { |
|
| 392 | - $offset = 2 * $offset; |
|
| 393 | - } |
|
| 394 | - if ( |
|
| 395 | - $offset < $length |
|
| 396 | - && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | - ) { |
|
| 398 | - $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | - if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | - $offset = $p_tag_fermant + 1; |
|
| 401 | - } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | - } |
|
| 403 | - $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | - |
|
| 405 | - if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | - include_spip('inc/lien'); |
|
| 407 | - } |
|
| 408 | - $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | - |
|
| 410 | - // balises de sauts de ligne et paragraphe |
|
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | - |
|
| 414 | - // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | - $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 416 | - |
|
| 417 | - // supprimer les tags |
|
| 418 | - $texte = supprimer_tags($texte); |
|
| 419 | - $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | - |
|
| 421 | - // tester s'il est nécessaire de couper le texte |
|
| 422 | - if (spip_strlen($texte) <= $taille) { |
|
| 423 | - $points = ''; |
|
| 424 | - } else { |
|
| 425 | - // points de suite |
|
| 426 | - if (is_null($suite)) { |
|
| 427 | - $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 428 | - } |
|
| 429 | - $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 430 | - |
|
| 431 | - // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 432 | - // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 433 | - // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 434 | - // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 435 | - $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 436 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 437 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 438 | - $points = $suite; |
|
| 439 | - |
|
| 440 | - // trop court ? ne pas faire de (...) |
|
| 441 | - if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 442 | - $points = ''; |
|
| 443 | - $long = spip_substr($texte, 0, $taille + 1); |
|
| 444 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 446 | - // encore trop court ? couper au caractere |
|
| 447 | - if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | - $texte = spip_substr($long, 0, $taille); |
|
| 449 | - } |
|
| 450 | - } else { |
|
| 451 | - $texte = $court; |
|
| 452 | - } |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - // remettre les paragraphes |
|
| 456 | - $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 457 | - |
|
| 458 | - // supprimer l'eventuelle entite finale mal coupee |
|
| 459 | - $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 460 | - |
|
| 461 | - return quote_amp(trim($texte)) . $points; |
|
| 384 | + if (!($length = strlen($texte)) or $taille <= 0) { |
|
| 385 | + return ''; |
|
| 386 | + } |
|
| 387 | + $offset = 400 + 2 * $taille; |
|
| 388 | + while ( |
|
| 389 | + $offset < $length |
|
| 390 | + and strlen(preg_replace(',<(!--|\w|/)[^>]+>,Uims', '', substr($texte, 0, $offset))) < $taille |
|
| 391 | + ) { |
|
| 392 | + $offset = 2 * $offset; |
|
| 393 | + } |
|
| 394 | + if ( |
|
| 395 | + $offset < $length |
|
| 396 | + && ($p_tag_ouvrant = strpos($texte, '<', $offset)) !== null |
|
| 397 | + ) { |
|
| 398 | + $p_tag_fermant = strpos($texte, '>', $offset); |
|
| 399 | + if ($p_tag_fermant && ($p_tag_fermant < $p_tag_ouvrant)) { |
|
| 400 | + $offset = $p_tag_fermant + 1; |
|
| 401 | + } // prolonger la coupe jusqu'au tag fermant suivant eventuel |
|
| 402 | + } |
|
| 403 | + $texte = substr($texte, 0, $offset); /* eviter de travailler sur 10ko pour extraire 150 caracteres */ |
|
| 404 | + |
|
| 405 | + if (!function_exists('nettoyer_raccourcis_typo')) { |
|
| 406 | + include_spip('inc/lien'); |
|
| 407 | + } |
|
| 408 | + $texte = nettoyer_raccourcis_typo($texte); |
|
| 409 | + |
|
| 410 | + // balises de sauts de ligne et paragraphe |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 413 | + |
|
| 414 | + // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
|
| 415 | + $texte = str_replace("\n\n", "\r\r", $texte); |
|
| 416 | + |
|
| 417 | + // supprimer les tags |
|
| 418 | + $texte = supprimer_tags($texte); |
|
| 419 | + $texte = trim(str_replace("\n", ' ', $texte)); |
|
| 420 | + |
|
| 421 | + // tester s'il est nécessaire de couper le texte |
|
| 422 | + if (spip_strlen($texte) <= $taille) { |
|
| 423 | + $points = ''; |
|
| 424 | + } else { |
|
| 425 | + // points de suite |
|
| 426 | + if (is_null($suite)) { |
|
| 427 | + $suite = (defined('_COUPER_SUITE') ? _COUPER_SUITE : ' (...)'); |
|
| 428 | + } |
|
| 429 | + $taille_suite = spip_strlen(filtrer_entites($suite)); |
|
| 430 | + |
|
| 431 | + // couper au mot precedent (ou au début de la chaîne si c'est le premier mot) |
|
| 432 | + // on coupe avec un caractère de plus que la taille demandée afin de pouvoir |
|
| 433 | + // détecter si le dernier mot du texte coupé est complet ou non. ce caractère |
|
| 434 | + // excédentaire est ensuite supprimé par l'appel à preg_replace() |
|
| 435 | + $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
|
| 436 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 437 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 438 | + $points = $suite; |
|
| 439 | + |
|
| 440 | + // trop court ? ne pas faire de (...) |
|
| 441 | + if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
|
| 442 | + $points = ''; |
|
| 443 | + $long = spip_substr($texte, 0, $taille + 1); |
|
| 444 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 446 | + // encore trop court ? couper au caractere |
|
| 447 | + if (spip_strlen($texte) < 0.75 * $taille) { |
|
| 448 | + $texte = spip_substr($long, 0, $taille); |
|
| 449 | + } |
|
| 450 | + } else { |
|
| 451 | + $texte = $court; |
|
| 452 | + } |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + // remettre les paragraphes |
|
| 456 | + $texte = preg_replace("/\r\r+/", "\n\n", $texte); |
|
| 457 | + |
|
| 458 | + // supprimer l'eventuelle entite finale mal coupee |
|
| 459 | + $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
|
| 460 | + |
|
| 461 | + return quote_amp(trim($texte)) . $points; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
| 465 | 465 | function protege_js_modeles($t) { |
| 466 | - if (isset($GLOBALS['visiteur_session'])) { |
|
| 467 | - if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 468 | - if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 469 | - include_spip('inc/acces'); |
|
| 470 | - define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 471 | - } |
|
| 472 | - foreach ($r as $regs) { |
|
| 473 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 474 | - } |
|
| 475 | - } |
|
| 476 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | - if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 478 | - include_spip('inc/acces'); |
|
| 479 | - define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 480 | - } |
|
| 481 | - foreach ($r as $regs) { |
|
| 482 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - |
|
| 487 | - return $t; |
|
| 466 | + if (isset($GLOBALS['visiteur_session'])) { |
|
| 467 | + if (preg_match_all(',<script.*?($|</script.),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 468 | + if (!defined('_PROTEGE_JS_MODELES')) { |
|
| 469 | + include_spip('inc/acces'); |
|
| 470 | + define('_PROTEGE_JS_MODELES', creer_uniqid()); |
|
| 471 | + } |
|
| 472 | + foreach ($r as $regs) { |
|
| 473 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 474 | + } |
|
| 475 | + } |
|
| 476 | + if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | + if (!defined('_PROTEGE_PHP_MODELES')) { |
|
| 478 | + include_spip('inc/acces'); |
|
| 479 | + define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
|
| 480 | + } |
|
| 481 | + foreach ($r as $regs) { |
|
| 482 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + |
|
| 487 | + return $t; |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | |
| 491 | 491 | function echapper_faux_tags($letexte) { |
| 492 | - if (strpos($letexte, '<') === false) { |
|
| 493 | - return $letexte; |
|
| 494 | - } |
|
| 495 | - $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 496 | - |
|
| 497 | - $letexte = ''; |
|
| 498 | - while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 499 | - // un texte a echapper |
|
| 500 | - $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 501 | - // un tag html qui a servit a faite le split |
|
| 502 | - $letexte .= array_shift($textMatches); |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - return $letexte; |
|
| 492 | + if (strpos($letexte, '<') === false) { |
|
| 493 | + return $letexte; |
|
| 494 | + } |
|
| 495 | + $textMatches = preg_split(',(</?[a-z!][^<>]*>),', $letexte, -1, PREG_SPLIT_DELIM_CAPTURE); |
|
| 496 | + |
|
| 497 | + $letexte = ''; |
|
| 498 | + while (is_countable($textMatches) ? count($textMatches) : 0) { |
|
| 499 | + // un texte a echapper |
|
| 500 | + $letexte .= str_replace('<', '<', array_shift($textMatches)); |
|
| 501 | + // un tag html qui a servit a faite le split |
|
| 502 | + $letexte .= array_shift($textMatches); |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + return $letexte; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -522,115 +522,115 @@ discard block |
||
| 522 | 522 | * @return string |
| 523 | 523 | */ |
| 524 | 524 | function echapper_html_suspect($texte, $options = [], $connect = null, $env = []) { |
| 525 | - static $echapper_html_suspect; |
|
| 526 | - if (!$texte or !is_string($texte)) { |
|
| 527 | - return $texte; |
|
| 528 | - } |
|
| 529 | - |
|
| 530 | - if (!isset($echapper_html_suspect)) { |
|
| 531 | - $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 532 | - } |
|
| 533 | - // si fonction personalisee, on delegue |
|
| 534 | - if ($echapper_html_suspect) { |
|
| 535 | - // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 536 | - $args = [$texte, $options]; |
|
| 537 | - if ($connect or !empty($env)) { |
|
| 538 | - $args[] = $connect; |
|
| 539 | - } |
|
| 540 | - if (!empty($env)) { |
|
| 541 | - $args[] = $env; |
|
| 542 | - } |
|
| 543 | - return $echapper_html_suspect(...$args); |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - if (is_bool($options)) { |
|
| 547 | - $options = ['strict' => $options]; |
|
| 548 | - } |
|
| 549 | - $strict = $options['strict'] ?? true; |
|
| 550 | - |
|
| 551 | - // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 552 | - if ( |
|
| 553 | - strpos($texte, '<') === false |
|
| 554 | - or !str_contains($texte, '=') |
|
| 555 | - ) { |
|
| 556 | - return $texte; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 560 | - if (!isset($env['espace_prive'])) { |
|
| 561 | - // conserver le comportement historique en cas d'appel court sans env |
|
| 562 | - $env['espace_prive'] = test_espace_prive(); |
|
| 563 | - } |
|
| 564 | - if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 565 | - |
|
| 566 | - // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 567 | - // car sinon on declenche sur les modeles ou ressources |
|
| 568 | - if ( |
|
| 569 | - !$strict and |
|
| 570 | - (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 571 | - ) { |
|
| 572 | - return $texte; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 576 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 577 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 578 | - $texte = $collecteurModeles->echapper($texte); |
|
| 579 | - $texte = echappe_js($texte); |
|
| 580 | - |
|
| 581 | - $texte_to_check = $texte; |
|
| 582 | - // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 583 | - // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 584 | - // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 585 | - if (!empty($options['expanser_liens'])) { |
|
| 586 | - $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 587 | - } |
|
| 588 | - if (!is_html_safe($texte_to_check)) { |
|
| 589 | - $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 590 | - $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 591 | - $texte = str_replace('<', '<', $texte); |
|
| 592 | - $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 593 | - $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 594 | - if (!function_exists('attribut_html')) { |
|
| 595 | - include_spip('inc/filtres'); |
|
| 596 | - } |
|
| 597 | - if (!empty($options['wrap_suspect'])) { |
|
| 598 | - $texte = wrap($texte, $options['wrap_suspect']); |
|
| 599 | - } |
|
| 600 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 601 | - } |
|
| 602 | - |
|
| 603 | - $texte = $collecteurModeles->retablir($texte); |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - // si on est là dans le public c'est le mode parano |
|
| 607 | - // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 608 | - else { |
|
| 609 | - $collecteurLiens = $collecteurModeles = null; |
|
| 610 | - if (!empty($options['expanser_liens'])) { |
|
| 611 | - $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 612 | - } |
|
| 613 | - else { |
|
| 614 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 615 | - include_spip("src/Texte/Collecteur/Liens"); |
|
| 616 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 617 | - |
|
| 618 | - $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 619 | - $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 620 | - |
|
| 621 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 622 | - $texte = $collecteurModeles->echapper($texte); |
|
| 623 | - } |
|
| 624 | - $texte = safehtml($texte); |
|
| 625 | - if ($collecteurModeles) { |
|
| 626 | - $texte = $collecteurModeles->retablir($texte); |
|
| 627 | - } |
|
| 628 | - if ($collecteurLiens) { |
|
| 629 | - $texte = $collecteurLiens->retablir($texte); |
|
| 630 | - } |
|
| 631 | - } |
|
| 632 | - |
|
| 633 | - return $texte; |
|
| 525 | + static $echapper_html_suspect; |
|
| 526 | + if (!$texte or !is_string($texte)) { |
|
| 527 | + return $texte; |
|
| 528 | + } |
|
| 529 | + |
|
| 530 | + if (!isset($echapper_html_suspect)) { |
|
| 531 | + $echapper_html_suspect = charger_fonction('echapper_html_suspect', 'inc', true); |
|
| 532 | + } |
|
| 533 | + // si fonction personalisee, on delegue |
|
| 534 | + if ($echapper_html_suspect) { |
|
| 535 | + // on collecte le tableau d'arg minimal pour ne pas casser un appel a une fonction inc_echapper_html_suspect() selon l'ancienne signature |
|
| 536 | + $args = [$texte, $options]; |
|
| 537 | + if ($connect or !empty($env)) { |
|
| 538 | + $args[] = $connect; |
|
| 539 | + } |
|
| 540 | + if (!empty($env)) { |
|
| 541 | + $args[] = $env; |
|
| 542 | + } |
|
| 543 | + return $echapper_html_suspect(...$args); |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + if (is_bool($options)) { |
|
| 547 | + $options = ['strict' => $options]; |
|
| 548 | + } |
|
| 549 | + $strict = $options['strict'] ?? true; |
|
| 550 | + |
|
| 551 | + // pas de balise html ou pas d'attribut sur les balises ? c'est OK |
|
| 552 | + if ( |
|
| 553 | + strpos($texte, '<') === false |
|
| 554 | + or !str_contains($texte, '=') |
|
| 555 | + ) { |
|
| 556 | + return $texte; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + // dans le prive, on veut afficher tout echappé pour la moderation |
|
| 560 | + if (!isset($env['espace_prive'])) { |
|
| 561 | + // conserver le comportement historique en cas d'appel court sans env |
|
| 562 | + $env['espace_prive'] = test_espace_prive(); |
|
| 563 | + } |
|
| 564 | + if (!empty($env['espace_prive']) or !empty($env['wysiwyg'])) { |
|
| 565 | + |
|
| 566 | + // quand c'est du texte qui passe par propre on est plus coulant tant qu'il y a pas d'attribut du type onxxx= |
|
| 567 | + // car sinon on declenche sur les modeles ou ressources |
|
| 568 | + if ( |
|
| 569 | + !$strict and |
|
| 570 | + (strpos($texte, 'on') === false or !preg_match(",<\w+.*\bon\w+\s*=,UimsS", $texte)) |
|
| 571 | + ) { |
|
| 572 | + return $texte; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 576 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 577 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 578 | + $texte = $collecteurModeles->echapper($texte); |
|
| 579 | + $texte = echappe_js($texte); |
|
| 580 | + |
|
| 581 | + $texte_to_check = $texte; |
|
| 582 | + // si les raccourcis liens vont etre interprétés, il faut les expanser avant de vérifier que le html est safe |
|
| 583 | + // car un raccourci peut etre utilisé pour faire un lien malin |
|
| 584 | + // et un raccourci est potentiellement modifié par safehtml, ce qui fait un faux positif dans is_html_safe |
|
| 585 | + if (!empty($options['expanser_liens'])) { |
|
| 586 | + $texte_to_check = expanser_liens($texte_to_check, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 587 | + } |
|
| 588 | + if (!is_html_safe($texte_to_check)) { |
|
| 589 | + $texte = $options['texte_source_affiche'] ?? $texte; |
|
| 590 | + $texte = preg_replace(",<(/?\w+\b[^>]*>),", "<tt><\\1</tt>", $texte); |
|
| 591 | + $texte = str_replace('<', '<', $texte); |
|
| 592 | + $texte = str_replace('<tt>', '<tt>', $texte); |
|
| 593 | + $texte = str_replace('</tt>', '</tt>', $texte); |
|
| 594 | + if (!function_exists('attribut_html')) { |
|
| 595 | + include_spip('inc/filtres'); |
|
| 596 | + } |
|
| 597 | + if (!empty($options['wrap_suspect'])) { |
|
| 598 | + $texte = wrap($texte, $options['wrap_suspect']); |
|
| 599 | + } |
|
| 600 | + $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 601 | + } |
|
| 602 | + |
|
| 603 | + $texte = $collecteurModeles->retablir($texte); |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + // si on est là dans le public c'est le mode parano |
|
| 607 | + // on veut donc un rendu propre et secure, et virer silencieusement ce qui est dangereux |
|
| 608 | + else { |
|
| 609 | + $collecteurLiens = $collecteurModeles = null; |
|
| 610 | + if (!empty($options['expanser_liens'])) { |
|
| 611 | + $texte = expanser_liens($texte, $env['connect'] ?? '', $env['env'] ?? []); |
|
| 612 | + } |
|
| 613 | + else { |
|
| 614 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 615 | + include_spip("src/Texte/Collecteur/Liens"); |
|
| 616 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 617 | + |
|
| 618 | + $collecteurLiens = new Spip\Texte\Collecteur\Liens(); |
|
| 619 | + $texte = $collecteurLiens->echapper($texte, ['sanitize_callback' => 'safehtml']); |
|
| 620 | + |
|
| 621 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 622 | + $texte = $collecteurModeles->echapper($texte); |
|
| 623 | + } |
|
| 624 | + $texte = safehtml($texte); |
|
| 625 | + if ($collecteurModeles) { |
|
| 626 | + $texte = $collecteurModeles->retablir($texte); |
|
| 627 | + } |
|
| 628 | + if ($collecteurLiens) { |
|
| 629 | + $texte = $collecteurLiens->retablir($texte); |
|
| 630 | + } |
|
| 631 | + } |
|
| 632 | + |
|
| 633 | + return $texte; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | |
@@ -651,52 +651,52 @@ discard block |
||
| 651 | 651 | * texte sécurisé |
| 652 | 652 | **/ |
| 653 | 653 | function safehtml($t) { |
| 654 | - static $safehtml; |
|
| 655 | - |
|
| 656 | - if (!$t or !is_string($t)) { |
|
| 657 | - return $t; |
|
| 658 | - } |
|
| 659 | - # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 660 | - if (strpos($t, '<') === false) { |
|
| 661 | - return str_replace("\x00", '', $t); |
|
| 662 | - } |
|
| 663 | - |
|
| 664 | - $collecteurIdiomes = null; |
|
| 665 | - if (stripos($t, '<:') !== false) { |
|
| 666 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 667 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 668 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 669 | - $t = $collecteurIdiomes->echapper($t); |
|
| 670 | - } |
|
| 671 | - $collecteurMultis = null; |
|
| 672 | - if (stripos($t, '<multi') !== false) { |
|
| 673 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 674 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 675 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 676 | - $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - if (!function_exists('interdire_scripts')) { |
|
| 680 | - include_spip('inc/texte'); |
|
| 681 | - } |
|
| 682 | - $t = interdire_scripts($t); // jolifier le php |
|
| 683 | - $t = echappe_js($t); |
|
| 684 | - |
|
| 685 | - if (!isset($safehtml)) { |
|
| 686 | - $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 687 | - } |
|
| 688 | - if ($safehtml) { |
|
| 689 | - $t = $safehtml($t); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - if ($collecteurMultis) { |
|
| 693 | - $t = $collecteurMultis->retablir($t); |
|
| 694 | - } |
|
| 695 | - if ($collecteurIdiomes) { |
|
| 696 | - $t = $collecteurIdiomes->retablir($t); |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 654 | + static $safehtml; |
|
| 655 | + |
|
| 656 | + if (!$t or !is_string($t)) { |
|
| 657 | + return $t; |
|
| 658 | + } |
|
| 659 | + # attention safehtml nettoie deux ou trois caracteres de plus. A voir |
|
| 660 | + if (strpos($t, '<') === false) { |
|
| 661 | + return str_replace("\x00", '', $t); |
|
| 662 | + } |
|
| 663 | + |
|
| 664 | + $collecteurIdiomes = null; |
|
| 665 | + if (stripos($t, '<:') !== false) { |
|
| 666 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 667 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 668 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 669 | + $t = $collecteurIdiomes->echapper($t); |
|
| 670 | + } |
|
| 671 | + $collecteurMultis = null; |
|
| 672 | + if (stripos($t, '<multi') !== false) { |
|
| 673 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 674 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 675 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 676 | + $t = $collecteurMultis->echapper($t, ['sanitize_callback' => 'safehtml']); |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + if (!function_exists('interdire_scripts')) { |
|
| 680 | + include_spip('inc/texte'); |
|
| 681 | + } |
|
| 682 | + $t = interdire_scripts($t); // jolifier le php |
|
| 683 | + $t = echappe_js($t); |
|
| 684 | + |
|
| 685 | + if (!isset($safehtml)) { |
|
| 686 | + $safehtml = charger_fonction('safehtml', 'inc', true); |
|
| 687 | + } |
|
| 688 | + if ($safehtml) { |
|
| 689 | + $t = $safehtml($t); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + if ($collecteurMultis) { |
|
| 693 | + $t = $collecteurMultis->retablir($t); |
|
| 694 | + } |
|
| 695 | + if ($collecteurIdiomes) { |
|
| 696 | + $t = $collecteurIdiomes->retablir($t); |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return interdire_scripts($t); // interdire le php (2 precautions) |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | |
@@ -704,25 +704,25 @@ discard block |
||
| 704 | 704 | * Detecter si un texte est "safe" ie non modifie significativement par safehtml() |
| 705 | 705 | */ |
| 706 | 706 | function is_html_safe(string $texte): bool { |
| 707 | - if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 708 | - return $is_html_safe($texte); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 712 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 713 | - // safehtml reduit aussi potentiellement les |
|
| 714 | - $texte = str_replace(" ", " ", $texte); |
|
| 715 | - // safehtml remplace les entités numériques |
|
| 716 | - if (strpos($texte, '&#') !== false) { |
|
| 717 | - $texte = unicode2charset($texte); |
|
| 718 | - } |
|
| 719 | - |
|
| 720 | - $texte_safe = safehtml($texte); |
|
| 721 | - |
|
| 722 | - // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 723 | - // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 724 | - // donc un test d'egalite est trop strict |
|
| 725 | - return strlen($texte_safe) === strlen($texte); |
|
| 707 | + if ($is_html_safe = charger_fonction('is_html_safe', 'inc', true)) { |
|
| 708 | + return $is_html_safe($texte); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + // simplifier les retour ligne pour etre certain de ce que l'on compare |
|
| 712 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 713 | + // safehtml reduit aussi potentiellement les |
|
| 714 | + $texte = str_replace(" ", " ", $texte); |
|
| 715 | + // safehtml remplace les entités numériques |
|
| 716 | + if (strpos($texte, '&#') !== false) { |
|
| 717 | + $texte = unicode2charset($texte); |
|
| 718 | + } |
|
| 719 | + |
|
| 720 | + $texte_safe = safehtml($texte); |
|
| 721 | + |
|
| 722 | + // on teste sur strlen car safehtml supprime le contenu dangereux |
|
| 723 | + // mais il peut aussi changer des ' en " sur les attributs html, |
|
| 724 | + // donc un test d'egalite est trop strict |
|
| 725 | + return strlen($texte_safe) === strlen($texte); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -743,13 +743,13 @@ discard block |
||
| 743 | 743 | * texte sans les modèles d'image |
| 744 | 744 | **/ |
| 745 | 745 | function supprime_img($letexte, $message = null) { |
| 746 | - if ($message === null) { |
|
| 747 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - return preg_replace( |
|
| 751 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 752 | - $message, |
|
| 753 | - $letexte |
|
| 754 | - ); |
|
| 746 | + if ($message === null) { |
|
| 747 | + $message = '(' . _T('img_indisponible') . ')'; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + return preg_replace( |
|
| 751 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 752 | + $message, |
|
| 753 | + $letexte |
|
| 754 | + ); |
|
| 755 | 755 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | // celle du texte) et public (spip_lang est la langue du texte) |
| 44 | 44 | $dir = _DIR_RESTREINT ? lang_dir() : lang_dir($GLOBALS['spip_lang']); |
| 45 | 45 | |
| 46 | - $p = 'puce' . (test_espace_prive() ? '_prive' : ''); |
|
| 46 | + $p = 'puce'.(test_espace_prive() ? '_prive' : ''); |
|
| 47 | 47 | if ($dir == 'rtl') { |
| 48 | 48 | $p .= '_rtl'; |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | if (!isset($GLOBALS[$p])) { |
| 52 | - $GLOBALS[$p] = '<span class="spip-puce ' . $dir . '"><b>–</b></span>'; |
|
| 52 | + $GLOBALS[$p] = '<span class="spip-puce '.$dir.'"><b>–</b></span>'; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return $GLOBALS[$p]; |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | function spip_balisage_code(string $corps, bool $bloc = false, string $attributs = '', string $langage = '') { |
| 68 | 68 | |
| 69 | 69 | $echap = spip_htmlspecialchars($corps); // il ne faut pas passer dans entites_html, ne pas transformer les &#xxx; du code ! |
| 70 | - $class = "spip_code " . ($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 70 | + $class = "spip_code ".($bloc ? 'spip_code_block' : 'spip_code_inline'); |
|
| 71 | 71 | if ($attributs) { |
| 72 | - $attributs = " " . trim($attributs); |
|
| 72 | + $attributs = " ".trim($attributs); |
|
| 73 | 73 | } |
| 74 | 74 | if ($langage) { |
| 75 | 75 | $class .= " language-$langage"; |
| 76 | - $attributs .= ' data-language="'. $langage .'"'; |
|
| 76 | + $attributs .= ' data-language="'.$langage.'"'; |
|
| 77 | 77 | } |
| 78 | 78 | if ($bloc) { |
| 79 | 79 | $html = "<div class=\"precode\">" |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | else { |
| 88 | 88 | $echap = str_replace("\t", " ", $echap); |
| 89 | 89 | $echap = str_replace(" ", " ", $echap); |
| 90 | - $html = "<code class=\"$class\" dir=\"ltr\"$attributs>" . $echap . '</code>'; |
|
| 90 | + $html = "<code class=\"$class\" dir=\"ltr\"$attributs>".$echap.'</code>'; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | return $html; |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | if (!defined('_BALISES_BLOCS_REGEXP')) { |
| 108 | - define('_BALISES_BLOCS_REGEXP', ',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS'); |
|
| 108 | + define('_BALISES_BLOCS_REGEXP', ',</?('._BALISES_BLOCS.')[>[:space:]],iS'); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | // |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | // Tester si on echappe en span ou en div |
| 124 | 124 | if (is_null($mode) or !in_array($mode, ['div', 'span'])) { |
| 125 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 125 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $rempl) ? 'div' : 'span'; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // Decouper en morceaux, base64 a des probleme selon la taille de la pile |
@@ -157,7 +157,7 @@ discard block |
||
| 157 | 157 | ) { |
| 158 | 158 | foreach ($matches as $m) { |
| 159 | 159 | if ($m[1] === 'code') { |
| 160 | - $code = '<code' . $m[2] . '>' . spip_htmlspecialchars($m[3]) . '</code>'; |
|
| 160 | + $code = '<code'.$m[2].'>'.spip_htmlspecialchars($m[3]).'</code>'; |
|
| 161 | 161 | $pre = str_replace($m[0], $code, $pre); |
| 162 | 162 | } |
| 163 | 163 | } |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | |
| 168 | 168 | // Echapper les <code>...</ code> |
| 169 | 169 | function traiter_echap_code_dist($regs, $options = []) { |
| 170 | - [, , $att, $corps] = $regs; |
|
| 170 | + [,, $att, $corps] = $regs; |
|
| 171 | 171 | |
| 172 | 172 | // ne pas mettre le <div...> s'il n'y a qu'une ligne |
| 173 | 173 | if (strpos($corps, "\n") !== false) { |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | // sinon les traiter selon le cas |
| 253 | 253 | $callback_secure_prefix = ($callback_options['secure_prefix'] ?? ''); |
| 254 | 254 | if ( |
| 255 | - function_exists($f = $callback_prefix . $callback_secure_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 256 | - or function_exists($f = $f . '_dist') |
|
| 255 | + function_exists($f = $callback_prefix.$callback_secure_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 256 | + or function_exists($f = $f.'_dist') |
|
| 257 | 257 | or ($callback_secure_prefix and ( |
| 258 | - function_exists($f = $callback_prefix . 'traiter_echap_' . strtolower($regs[1])) |
|
| 259 | - or function_exists($f = $f . '_dist') |
|
| 258 | + function_exists($f = $callback_prefix.'traiter_echap_'.strtolower($regs[1])) |
|
| 259 | + or function_exists($f = $f.'_dist') |
|
| 260 | 260 | )) |
| 261 | 261 | ) { |
| 262 | 262 | $echap = $f($regs, $callback_options); |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | // dans une callback autonommee |
| 279 | 279 | if (strpos($preg ?: _PROTEGE_BLOCS, 'script') !== false) { |
| 280 | 280 | if ( |
| 281 | - strpos($letexte, '<' . '?') !== false and preg_match_all( |
|
| 281 | + strpos($letexte, '<'.'?') !== false and preg_match_all( |
|
| 282 | 282 | ',<[?].*($|[?]>),UisS', |
| 283 | 283 | $letexte, |
| 284 | 284 | $matches, |
@@ -310,7 +310,7 @@ discard block |
||
| 310 | 310 | strpos($letexte, '<') !== false |
| 311 | 311 | and |
| 312 | 312 | preg_match_all( |
| 313 | - ',<(span|div)\sclass=[\'"]base64' . $source . '[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 313 | + ',<(span|div)\sclass=[\'"]base64'.$source.'[\'"]\s(.*)>\s*</\1>,UmsS', |
|
| 314 | 314 | $letexte, |
| 315 | 315 | $regs, |
| 316 | 316 | PREG_SET_ORDER |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | } |
| 328 | 328 | } |
| 329 | 329 | if ($at) { |
| 330 | - $rempl = '<' . $reg[1] . '>' . $rempl . '</' . $reg[1] . '>'; |
|
| 330 | + $rempl = '<'.$reg[1].'>'.$rempl.'</'.$reg[1].'>'; |
|
| 331 | 331 | foreach ($at as $attr => $a) { |
| 332 | 332 | $rempl = inserer_attribut($rempl, $attr, $a); |
| 333 | 333 | } |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | $texte = nettoyer_raccourcis_typo($texte); |
| 409 | 409 | |
| 410 | 410 | // balises de sauts de ligne et paragraphe |
| 411 | - $texte = preg_replace('/<p( [^>]*)?' . '>/', "\r\r", $texte); |
|
| 412 | - $texte = preg_replace('/<br( [^>]*)?' . '>/', "\n", $texte); |
|
| 411 | + $texte = preg_replace('/<p( [^>]*)?'.'>/', "\r\r", $texte); |
|
| 412 | + $texte = preg_replace('/<br( [^>]*)?'.'>/', "\n", $texte); |
|
| 413 | 413 | |
| 414 | 414 | // on repasse les doubles \n en \r que nettoyer_raccourcis_typo() a pu modifier |
| 415 | 415 | $texte = str_replace("\n\n", "\r\r", $texte); |
@@ -434,15 +434,15 @@ discard block |
||
| 434 | 434 | // excédentaire est ensuite supprimé par l'appel à preg_replace() |
| 435 | 435 | $long = spip_substr($texte, 0, max($taille + 1 - $taille_suite, 1)); |
| 436 | 436 | $u = $GLOBALS['meta']['pcre_u']; |
| 437 | - $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 437 | + $court = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 438 | 438 | $points = $suite; |
| 439 | 439 | |
| 440 | 440 | // trop court ? ne pas faire de (...) |
| 441 | 441 | if (spip_strlen($court) < max(0.75 * $taille, 2)) { |
| 442 | 442 | $points = ''; |
| 443 | 443 | $long = spip_substr($texte, 0, $taille + 1); |
| 444 | - preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, $long, $m); |
|
| 445 | - $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D' . $u, "\\2", $long); |
|
| 444 | + preg_match('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, $long, $m); |
|
| 445 | + $texte = preg_replace('/(^|([^\s ])[\s ]+)([\s ]|[^\s ]+)?$/D'.$u, "\\2", $long); |
|
| 446 | 446 | // encore trop court ? couper au caractere |
| 447 | 447 | if (spip_strlen($texte) < 0.75 * $taille) { |
| 448 | 448 | $texte = spip_substr($long, 0, $taille); |
@@ -458,7 +458,7 @@ discard block |
||
| 458 | 458 | // supprimer l'eventuelle entite finale mal coupee |
| 459 | 459 | $texte = preg_replace('/&#?[a-z0-9]*$/S', '', $texte); |
| 460 | 460 | |
| 461 | - return quote_amp(trim($texte)) . $points; |
|
| 461 | + return quote_amp(trim($texte)).$points; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -470,16 +470,16 @@ discard block |
||
| 470 | 470 | define('_PROTEGE_JS_MODELES', creer_uniqid()); |
| 471 | 471 | } |
| 472 | 472 | foreach ($r as $regs) { |
| 473 | - $t = str_replace($regs[0], code_echappement($regs[0], 'javascript' . _PROTEGE_JS_MODELES), $t); |
|
| 473 | + $t = str_replace($regs[0], code_echappement($regs[0], 'javascript'._PROTEGE_JS_MODELES), $t); |
|
| 474 | 474 | } |
| 475 | 475 | } |
| 476 | - if (preg_match_all(',<\?php.*?($|\?' . '>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 476 | + if (preg_match_all(',<\?php.*?($|\?'.'>),isS', $t, $r, PREG_SET_ORDER)) { |
|
| 477 | 477 | if (!defined('_PROTEGE_PHP_MODELES')) { |
| 478 | 478 | include_spip('inc/acces'); |
| 479 | 479 | define('_PROTEGE_PHP_MODELES', creer_uniqid()); |
| 480 | 480 | } |
| 481 | 481 | foreach ($r as $regs) { |
| 482 | - $t = str_replace($regs[0], code_echappement($regs[0], 'php' . _PROTEGE_PHP_MODELES), $t); |
|
| 482 | + $t = str_replace($regs[0], code_echappement($regs[0], 'php'._PROTEGE_PHP_MODELES), $t); |
|
| 483 | 483 | } |
| 484 | 484 | } |
| 485 | 485 | } |
@@ -597,7 +597,7 @@ discard block |
||
| 597 | 597 | if (!empty($options['wrap_suspect'])) { |
| 598 | 598 | $texte = wrap($texte, $options['wrap_suspect']); |
| 599 | 599 | } |
| 600 | - $texte = "<mark class='danger-js' title='" . attribut_html(_T('erreur_contenu_suspect')) . "'>⚠️</mark> " . $texte; |
|
| 600 | + $texte = "<mark class='danger-js' title='".attribut_html(_T('erreur_contenu_suspect'))."'>⚠️</mark> ".$texte; |
|
| 601 | 601 | } |
| 602 | 602 | |
| 603 | 603 | $texte = $collecteurModeles->retablir($texte); |
@@ -744,11 +744,11 @@ discard block |
||
| 744 | 744 | **/ |
| 745 | 745 | function supprime_img($letexte, $message = null) { |
| 746 | 746 | if ($message === null) { |
| 747 | - $message = '(' . _T('img_indisponible') . ')'; |
|
| 747 | + $message = '('._T('img_indisponible').')'; |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | return preg_replace( |
| 751 | - ',<(img|doc|emb)([0-9]+)(\|([^>]*))?' . '\s*/?' . '>,i', |
|
| 751 | + ',<(img|doc|emb)([0-9]+)(\|([^>]*))?'.'\s*/?'.'>,i', |
|
| 752 | 752 | $message, |
| 753 | 753 | $letexte |
| 754 | 754 | ); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -27,51 +27,51 @@ discard block |
||
| 27 | 27 | * @return void |
| 28 | 28 | */ |
| 29 | 29 | function action_confirmer_inscription_dist() { |
| 30 | - $jeton = _request('jeton'); |
|
| 31 | - $email = _request('email'); |
|
| 30 | + $jeton = _request('jeton'); |
|
| 31 | + $email = _request('email'); |
|
| 32 | 32 | |
| 33 | - include_spip('action/inscrire_auteur'); |
|
| 34 | - if ( |
|
| 35 | - $auteur = auteur_verifier_jeton($jeton) |
|
| 36 | - and $auteur['email'] == $email |
|
| 37 | - and $auteur['statut'] == 'nouveau' |
|
| 38 | - ) { |
|
| 39 | - // d'abord on confirme son statut |
|
| 40 | - $auteur = confirmer_statut_inscription($auteur); |
|
| 33 | + include_spip('action/inscrire_auteur'); |
|
| 34 | + if ( |
|
| 35 | + $auteur = auteur_verifier_jeton($jeton) |
|
| 36 | + and $auteur['email'] == $email |
|
| 37 | + and $auteur['statut'] == 'nouveau' |
|
| 38 | + ) { |
|
| 39 | + // d'abord on confirme son statut |
|
| 40 | + $auteur = confirmer_statut_inscription($auteur); |
|
| 41 | 41 | |
| 42 | - // OK c'est un nouvel inscrit qui confirme : |
|
| 43 | - // on le loge => ca va confirmer son statut et c'est plus sympa |
|
| 44 | - include_spip('inc/auth'); |
|
| 45 | - auth_loger($auteur); |
|
| 42 | + // OK c'est un nouvel inscrit qui confirme : |
|
| 43 | + // on le loge => ca va confirmer son statut et c'est plus sympa |
|
| 44 | + include_spip('inc/auth'); |
|
| 45 | + auth_loger($auteur); |
|
| 46 | 46 | |
| 47 | - // et on efface son jeton |
|
| 48 | - auteur_effacer_jeton($auteur['id_auteur']); |
|
| 47 | + // et on efface son jeton |
|
| 48 | + auteur_effacer_jeton($auteur['id_auteur']); |
|
| 49 | 49 | |
| 50 | - // si pas de redirection demandee, rediriger vers public ou prive selon le statut de l'auteur |
|
| 51 | - // TODO: ne semble pas marcher si inscrit non visiteur, a debug |
|
| 52 | - if (!_request('redirect')) { |
|
| 53 | - // on passe id_auteur explicite pour forcer une lecture en base de toutes les infos |
|
| 54 | - if (autoriser('ecrire', '', '', $auteur['id_auteur'])) { |
|
| 55 | - // poser un cookie admin aussi |
|
| 56 | - $cookie = charger_fonction('cookie', 'action'); |
|
| 57 | - $cookie('@' . $GLOBALS['visiteur_session']['login']); |
|
| 58 | - $GLOBALS['redirect'] = _DIR_RESTREINT_ABS; |
|
| 59 | - } else { |
|
| 60 | - $GLOBALS['redirect'] = $GLOBALS['meta']['adresse_site']; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } else { |
|
| 64 | - // lien perime : |
|
| 65 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 66 | - // on passe id_auteur explicite pour forcer une lecture en base de toutes les infos |
|
| 67 | - if (autoriser('ecrire', '', '', $GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 68 | - $GLOBALS['redirect'] = _DIR_RESTREINT_ABS; |
|
| 69 | - } else { |
|
| 70 | - $GLOBALS['redirect'] = $GLOBALS['meta']['adresse_site']; |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - // rediriger vers la page de login si pas encore loge |
|
| 74 | - $GLOBALS['redirect'] = parametre_url(generer_url_public('login', '', false), 'url', _request('redirect')); |
|
| 75 | - } |
|
| 76 | - } |
|
| 50 | + // si pas de redirection demandee, rediriger vers public ou prive selon le statut de l'auteur |
|
| 51 | + // TODO: ne semble pas marcher si inscrit non visiteur, a debug |
|
| 52 | + if (!_request('redirect')) { |
|
| 53 | + // on passe id_auteur explicite pour forcer une lecture en base de toutes les infos |
|
| 54 | + if (autoriser('ecrire', '', '', $auteur['id_auteur'])) { |
|
| 55 | + // poser un cookie admin aussi |
|
| 56 | + $cookie = charger_fonction('cookie', 'action'); |
|
| 57 | + $cookie('@' . $GLOBALS['visiteur_session']['login']); |
|
| 58 | + $GLOBALS['redirect'] = _DIR_RESTREINT_ABS; |
|
| 59 | + } else { |
|
| 60 | + $GLOBALS['redirect'] = $GLOBALS['meta']['adresse_site']; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } else { |
|
| 64 | + // lien perime : |
|
| 65 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 66 | + // on passe id_auteur explicite pour forcer une lecture en base de toutes les infos |
|
| 67 | + if (autoriser('ecrire', '', '', $GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 68 | + $GLOBALS['redirect'] = _DIR_RESTREINT_ABS; |
|
| 69 | + } else { |
|
| 70 | + $GLOBALS['redirect'] = $GLOBALS['meta']['adresse_site']; |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + // rediriger vers la page de login si pas encore loge |
|
| 74 | + $GLOBALS['redirect'] = parametre_url(generer_url_public('login', '', false), 'url', _request('redirect')); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | 77 | } |
@@ -12,498 +12,498 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class Data extends AbstractIterateur implements Iterator |
| 14 | 14 | { |
| 15 | - /** Tableau de données */ |
|
| 16 | - protected array $tableau = []; |
|
| 17 | - |
|
| 18 | - /** |
|
| 19 | - * Conditions de filtrage |
|
| 20 | - * ie criteres de selection |
|
| 21 | - */ |
|
| 22 | - protected array $filtre = []; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * Cle courante |
|
| 26 | - * |
|
| 27 | - * @var scalar |
|
| 28 | - */ |
|
| 29 | - protected $cle = null; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Valeur courante |
|
| 33 | - * |
|
| 34 | - * @var mixed |
|
| 35 | - */ |
|
| 36 | - protected $valeur = null; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Constructeur |
|
| 40 | - * |
|
| 41 | - * @param $command |
|
| 42 | - * @param array $info |
|
| 43 | - */ |
|
| 44 | - public function __construct(array $command, array $info = []) { |
|
| 45 | - include_spip('iterateur/data'); |
|
| 46 | - $this->type = 'DATA'; |
|
| 47 | - $this->command = $command; |
|
| 48 | - $this->info = $info; |
|
| 49 | - $this->select($command); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Revenir au depart |
|
| 54 | - * |
|
| 55 | - * @return void |
|
| 56 | - */ |
|
| 57 | - public function rewind(): void { |
|
| 58 | - reset($this->tableau); |
|
| 59 | - $this->cle = array_key_first($this->tableau); |
|
| 60 | - $this->valeur = current($this->tableau); |
|
| 61 | - next($this->tableau); |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Déclarer les critères exceptions |
|
| 66 | - * |
|
| 67 | - * @return array |
|
| 68 | - */ |
|
| 69 | - public function exception_des_criteres() { |
|
| 70 | - return ['tableau']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Récupérer depuis le cache si possible |
|
| 75 | - * |
|
| 76 | - * @param string $cle |
|
| 77 | - * @return mixed |
|
| 78 | - */ |
|
| 79 | - protected function cache_get($cle) { |
|
| 80 | - if (!$cle) { |
|
| 81 | - return; |
|
| 82 | - } |
|
| 83 | - # utiliser memoization si dispo |
|
| 84 | - if (!function_exists('cache_get')) { |
|
| 85 | - return; |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - return cache_get($cle); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Stocker en cache si possible |
|
| 93 | - * |
|
| 94 | - * @param string $cle |
|
| 95 | - * @param int $ttl |
|
| 96 | - * @param null|mixed $valeur |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 99 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 100 | - if (!$cle) { |
|
| 101 | - return; |
|
| 102 | - } |
|
| 103 | - if (is_null($valeur)) { |
|
| 104 | - $valeur = $this->tableau; |
|
| 105 | - } |
|
| 106 | - # utiliser memoization si dispo |
|
| 107 | - if (!function_exists('cache_set')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return cache_set( |
|
| 112 | - $cle, |
|
| 113 | - [ |
|
| 114 | - 'data' => $valeur, |
|
| 115 | - 'time' => time(), |
|
| 116 | - 'ttl' => $ttl |
|
| 117 | - ], |
|
| 118 | - 3600 + $ttl |
|
| 119 | - ); |
|
| 120 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 121 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Aller chercher les données de la boucle DATA |
|
| 126 | - * |
|
| 127 | - * @throws Exception |
|
| 128 | - * @param array $command |
|
| 129 | - * @return void |
|
| 130 | - */ |
|
| 131 | - protected function select($command) { |
|
| 132 | - |
|
| 133 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 134 | - // le type se retrouve dans la commande 'from' |
|
| 135 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 136 | - if (isset($this->command['from'][0])) { |
|
| 137 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 138 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 139 | - } |
|
| 140 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 144 | - // les commandes connues pour l'iterateur DATA |
|
| 145 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 146 | - |
|
| 147 | - // {source format, [URL], [arg2]...} |
|
| 148 | - if ( |
|
| 149 | - isset($this->command['source']) |
|
| 150 | - and isset($this->command['sourcemode']) |
|
| 151 | - ) { |
|
| 152 | - $this->select_source(); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // Critere {liste X1, X2, X3} |
|
| 156 | - if (isset($this->command['liste'])) { |
|
| 157 | - $this->select_liste(); |
|
| 158 | - } |
|
| 159 | - if (isset($this->command['enum'])) { |
|
| 160 | - $this->select_enum(); |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 164 | - if (!is_array($this->tableau)) { |
|
| 165 | - $this->err = true; |
|
| 166 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // {datapath query.results} |
|
| 170 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 171 | - if ( |
|
| 172 | - !$this->err |
|
| 173 | - and isset($this->command['datapath']) |
|
| 174 | - and is_array($this->command['datapath']) |
|
| 175 | - ) { |
|
| 176 | - $this->select_datapath(); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - // tri {par x} |
|
| 180 | - if ($this->command['orderby']) { |
|
| 181 | - $this->select_orderby(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 185 | - if ($this->command['groupby']) { |
|
| 186 | - $this->select_groupby(); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $this->rewind(); |
|
| 190 | - #var_dump($this->tableau); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * Aller chercher les donnees de la boucle DATA |
|
| 196 | - * depuis une source |
|
| 197 | - * {source format, [URL], [arg2]...} |
|
| 198 | - */ |
|
| 199 | - protected function select_source() { |
|
| 200 | - # un peu crado : avant de charger le cache il faut charger |
|
| 201 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 202 | - # l'objet en cache ; cf plugins/icalendar |
|
| 203 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 204 | - if ( |
|
| 205 | - isset($this->command['sourcemode']) |
|
| 206 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 207 | - ) { |
|
| 208 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - # le premier argument peut etre un array, une URL etc. |
|
| 212 | - $src = $this->command['source'][0] ?? null; |
|
| 213 | - |
|
| 214 | - # avons-nous un cache dispo ? |
|
| 215 | - $cle = null; |
|
| 216 | - if (is_string($src)) { |
|
| 217 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - $cache = $this->cache_get($cle); |
|
| 221 | - if (isset($this->command['datacache'])) { |
|
| 222 | - $ttl = intval($this->command['datacache']); |
|
| 223 | - } |
|
| 224 | - if ( |
|
| 225 | - $cache |
|
| 226 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 227 | - > time()) |
|
| 228 | - and !(_request('var_mode') === 'recalcul' |
|
| 229 | - and include_spip('inc/autoriser') |
|
| 230 | - and autoriser('recalcul') |
|
| 231 | - ) |
|
| 232 | - ) { |
|
| 233 | - $this->tableau = $cache['data']; |
|
| 234 | - } else { |
|
| 235 | - try { |
|
| 236 | - if ( |
|
| 237 | - isset($this->command['sourcemode']) |
|
| 238 | - and in_array( |
|
| 239 | - $this->command['sourcemode'], |
|
| 240 | - ['table', 'array', 'tableau'] |
|
| 241 | - ) |
|
| 242 | - ) { |
|
| 243 | - if ( |
|
| 244 | - is_array($a = $src) |
|
| 245 | - or (is_string($a) |
|
| 246 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 247 | - and is_array($a = @unserialize($a))) |
|
| 248 | - ) { |
|
| 249 | - $this->tableau = $a; |
|
| 250 | - } |
|
| 251 | - } else { |
|
| 252 | - $data = $src; |
|
| 253 | - if (is_string($src)) { |
|
| 254 | - if (tester_url_absolue($src)) { |
|
| 255 | - include_spip('inc/distant'); |
|
| 256 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 257 | - $data = $data['page'] ?? ''; |
|
| 258 | - if (!$data) { |
|
| 259 | - throw new Exception('404'); |
|
| 260 | - } |
|
| 261 | - if (!isset($ttl)) { |
|
| 262 | - $ttl = 24 * 3600; |
|
| 263 | - } |
|
| 264 | - } elseif (@is_dir($src)) { |
|
| 265 | - $data = $src; |
|
| 266 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 267 | - $data = spip_file_get_contents($src); |
|
| 268 | - } |
|
| 269 | - if (!isset($ttl)) { |
|
| 270 | - $ttl = 10; |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - if ( |
|
| 274 | - !$this->err |
|
| 275 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 276 | - ) { |
|
| 277 | - $args = $this->command['source']; |
|
| 278 | - $args[0] = $data; |
|
| 279 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 280 | - $this->tableau = $a; |
|
| 281 | - } |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - if (!is_array($this->tableau)) { |
|
| 286 | - $this->err = true; |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 290 | - $this->cache_set($cle, $ttl); |
|
| 291 | - } |
|
| 292 | - } catch (Exception $e) { |
|
| 293 | - $e = $e->getMessage(); |
|
| 294 | - $err = sprintf( |
|
| 295 | - "[%s, %s] $e", |
|
| 296 | - $src, |
|
| 297 | - $this->command['sourcemode'] |
|
| 298 | - ); |
|
| 299 | - erreur_squelette([$err, []]); |
|
| 300 | - $this->err = true; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 305 | - if ( |
|
| 306 | - $this->err |
|
| 307 | - and $cache |
|
| 308 | - ) { |
|
| 309 | - $this->tableau = $cache['data']; |
|
| 310 | - $this->err = false; |
|
| 311 | - } |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Retourne un tableau donne depuis un critère liste |
|
| 317 | - * |
|
| 318 | - * Critère `{liste X1, X2, X3}` |
|
| 319 | - * |
|
| 320 | - * @see critere_DATA_liste_dist() |
|
| 321 | - * |
|
| 322 | - **/ |
|
| 323 | - protected function select_liste() { |
|
| 324 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 325 | - if (!isset($this->command['liste'][1])) { |
|
| 326 | - if (!is_array($this->command['liste'][0])) { |
|
| 327 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 328 | - } else { |
|
| 329 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - $this->tableau = $this->command['liste']; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - /** |
|
| 336 | - * Retourne un tableau donne depuis un critere liste |
|
| 337 | - * Critere {enum Xmin, Xmax} |
|
| 338 | - * |
|
| 339 | - **/ |
|
| 340 | - protected function select_enum() { |
|
| 341 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 342 | - if (!isset($this->command['enum'][1])) { |
|
| 343 | - if (!is_array($this->command['enum'][0])) { |
|
| 344 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 345 | - } else { |
|
| 346 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 350 | - $enum = range( |
|
| 351 | - array_shift($this->command['enum']), |
|
| 352 | - array_shift($this->command['enum']), |
|
| 353 | - array_shift($this->command['enum']) |
|
| 354 | - ); |
|
| 355 | - } else { |
|
| 356 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 357 | - } |
|
| 358 | - $this->tableau = $enum; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - |
|
| 362 | - /** |
|
| 363 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 364 | - * {datapath query.results} |
|
| 365 | - * |
|
| 366 | - **/ |
|
| 367 | - protected function select_datapath() { |
|
| 368 | - $base = reset($this->command['datapath']); |
|
| 369 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 370 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 371 | - if (!is_array($this->tableau)) { |
|
| 372 | - $this->tableau = []; |
|
| 373 | - $this->err = true; |
|
| 374 | - spip_log("datapath '$base' absent"); |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - /** |
|
| 380 | - * Ordonner les resultats |
|
| 381 | - * {par x} |
|
| 382 | - * |
|
| 383 | - **/ |
|
| 384 | - protected function select_orderby() { |
|
| 385 | - $sortfunc = ''; |
|
| 386 | - $aleas = 0; |
|
| 387 | - foreach ($this->command['orderby'] as $tri) { |
|
| 388 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 389 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 390 | - $r = array_pad($r, 3, null); |
|
| 391 | - |
|
| 392 | - // tri par cle |
|
| 393 | - if ($r[1] == 'cle') { |
|
| 394 | - if (isset($r[2]) and $r[2]) { |
|
| 395 | - krsort($this->tableau); |
|
| 396 | - } else { |
|
| 397 | - ksort($this->tableau); |
|
| 398 | - } |
|
| 399 | - } # {par hasard} |
|
| 400 | - else { |
|
| 401 | - if ($r[1] == 'hasard') { |
|
| 402 | - $k = array_keys($this->tableau); |
|
| 403 | - shuffle($k); |
|
| 404 | - $v = []; |
|
| 405 | - foreach ($k as $cle) { |
|
| 406 | - $v[$cle] = $this->tableau[$cle]; |
|
| 407 | - } |
|
| 408 | - $this->tableau = $v; |
|
| 409 | - } else { |
|
| 410 | - # {par valeur} |
|
| 411 | - if ($r[1] == 'valeur') { |
|
| 412 | - $tv = '%s'; |
|
| 413 | - } # {par valeur/xx/yy} ?? |
|
| 414 | - else { |
|
| 415 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 416 | - } |
|
| 417 | - $sortfunc .= ' |
|
| 15 | + /** Tableau de données */ |
|
| 16 | + protected array $tableau = []; |
|
| 17 | + |
|
| 18 | + /** |
|
| 19 | + * Conditions de filtrage |
|
| 20 | + * ie criteres de selection |
|
| 21 | + */ |
|
| 22 | + protected array $filtre = []; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * Cle courante |
|
| 26 | + * |
|
| 27 | + * @var scalar |
|
| 28 | + */ |
|
| 29 | + protected $cle = null; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Valeur courante |
|
| 33 | + * |
|
| 34 | + * @var mixed |
|
| 35 | + */ |
|
| 36 | + protected $valeur = null; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Constructeur |
|
| 40 | + * |
|
| 41 | + * @param $command |
|
| 42 | + * @param array $info |
|
| 43 | + */ |
|
| 44 | + public function __construct(array $command, array $info = []) { |
|
| 45 | + include_spip('iterateur/data'); |
|
| 46 | + $this->type = 'DATA'; |
|
| 47 | + $this->command = $command; |
|
| 48 | + $this->info = $info; |
|
| 49 | + $this->select($command); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Revenir au depart |
|
| 54 | + * |
|
| 55 | + * @return void |
|
| 56 | + */ |
|
| 57 | + public function rewind(): void { |
|
| 58 | + reset($this->tableau); |
|
| 59 | + $this->cle = array_key_first($this->tableau); |
|
| 60 | + $this->valeur = current($this->tableau); |
|
| 61 | + next($this->tableau); |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Déclarer les critères exceptions |
|
| 66 | + * |
|
| 67 | + * @return array |
|
| 68 | + */ |
|
| 69 | + public function exception_des_criteres() { |
|
| 70 | + return ['tableau']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Récupérer depuis le cache si possible |
|
| 75 | + * |
|
| 76 | + * @param string $cle |
|
| 77 | + * @return mixed |
|
| 78 | + */ |
|
| 79 | + protected function cache_get($cle) { |
|
| 80 | + if (!$cle) { |
|
| 81 | + return; |
|
| 82 | + } |
|
| 83 | + # utiliser memoization si dispo |
|
| 84 | + if (!function_exists('cache_get')) { |
|
| 85 | + return; |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + return cache_get($cle); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Stocker en cache si possible |
|
| 93 | + * |
|
| 94 | + * @param string $cle |
|
| 95 | + * @param int $ttl |
|
| 96 | + * @param null|mixed $valeur |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 100 | + if (!$cle) { |
|
| 101 | + return; |
|
| 102 | + } |
|
| 103 | + if (is_null($valeur)) { |
|
| 104 | + $valeur = $this->tableau; |
|
| 105 | + } |
|
| 106 | + # utiliser memoization si dispo |
|
| 107 | + if (!function_exists('cache_set')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return cache_set( |
|
| 112 | + $cle, |
|
| 113 | + [ |
|
| 114 | + 'data' => $valeur, |
|
| 115 | + 'time' => time(), |
|
| 116 | + 'ttl' => $ttl |
|
| 117 | + ], |
|
| 118 | + 3600 + $ttl |
|
| 119 | + ); |
|
| 120 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 121 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Aller chercher les données de la boucle DATA |
|
| 126 | + * |
|
| 127 | + * @throws Exception |
|
| 128 | + * @param array $command |
|
| 129 | + * @return void |
|
| 130 | + */ |
|
| 131 | + protected function select($command) { |
|
| 132 | + |
|
| 133 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 134 | + // le type se retrouve dans la commande 'from' |
|
| 135 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 136 | + if (isset($this->command['from'][0])) { |
|
| 137 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 138 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 139 | + } |
|
| 140 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 144 | + // les commandes connues pour l'iterateur DATA |
|
| 145 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 146 | + |
|
| 147 | + // {source format, [URL], [arg2]...} |
|
| 148 | + if ( |
|
| 149 | + isset($this->command['source']) |
|
| 150 | + and isset($this->command['sourcemode']) |
|
| 151 | + ) { |
|
| 152 | + $this->select_source(); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // Critere {liste X1, X2, X3} |
|
| 156 | + if (isset($this->command['liste'])) { |
|
| 157 | + $this->select_liste(); |
|
| 158 | + } |
|
| 159 | + if (isset($this->command['enum'])) { |
|
| 160 | + $this->select_enum(); |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 164 | + if (!is_array($this->tableau)) { |
|
| 165 | + $this->err = true; |
|
| 166 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // {datapath query.results} |
|
| 170 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 171 | + if ( |
|
| 172 | + !$this->err |
|
| 173 | + and isset($this->command['datapath']) |
|
| 174 | + and is_array($this->command['datapath']) |
|
| 175 | + ) { |
|
| 176 | + $this->select_datapath(); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + // tri {par x} |
|
| 180 | + if ($this->command['orderby']) { |
|
| 181 | + $this->select_orderby(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 185 | + if ($this->command['groupby']) { |
|
| 186 | + $this->select_groupby(); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $this->rewind(); |
|
| 190 | + #var_dump($this->tableau); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * Aller chercher les donnees de la boucle DATA |
|
| 196 | + * depuis une source |
|
| 197 | + * {source format, [URL], [arg2]...} |
|
| 198 | + */ |
|
| 199 | + protected function select_source() { |
|
| 200 | + # un peu crado : avant de charger le cache il faut charger |
|
| 201 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 202 | + # l'objet en cache ; cf plugins/icalendar |
|
| 203 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 204 | + if ( |
|
| 205 | + isset($this->command['sourcemode']) |
|
| 206 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 207 | + ) { |
|
| 208 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + # le premier argument peut etre un array, une URL etc. |
|
| 212 | + $src = $this->command['source'][0] ?? null; |
|
| 213 | + |
|
| 214 | + # avons-nous un cache dispo ? |
|
| 215 | + $cle = null; |
|
| 216 | + if (is_string($src)) { |
|
| 217 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + $cache = $this->cache_get($cle); |
|
| 221 | + if (isset($this->command['datacache'])) { |
|
| 222 | + $ttl = intval($this->command['datacache']); |
|
| 223 | + } |
|
| 224 | + if ( |
|
| 225 | + $cache |
|
| 226 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 227 | + > time()) |
|
| 228 | + and !(_request('var_mode') === 'recalcul' |
|
| 229 | + and include_spip('inc/autoriser') |
|
| 230 | + and autoriser('recalcul') |
|
| 231 | + ) |
|
| 232 | + ) { |
|
| 233 | + $this->tableau = $cache['data']; |
|
| 234 | + } else { |
|
| 235 | + try { |
|
| 236 | + if ( |
|
| 237 | + isset($this->command['sourcemode']) |
|
| 238 | + and in_array( |
|
| 239 | + $this->command['sourcemode'], |
|
| 240 | + ['table', 'array', 'tableau'] |
|
| 241 | + ) |
|
| 242 | + ) { |
|
| 243 | + if ( |
|
| 244 | + is_array($a = $src) |
|
| 245 | + or (is_string($a) |
|
| 246 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 247 | + and is_array($a = @unserialize($a))) |
|
| 248 | + ) { |
|
| 249 | + $this->tableau = $a; |
|
| 250 | + } |
|
| 251 | + } else { |
|
| 252 | + $data = $src; |
|
| 253 | + if (is_string($src)) { |
|
| 254 | + if (tester_url_absolue($src)) { |
|
| 255 | + include_spip('inc/distant'); |
|
| 256 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 257 | + $data = $data['page'] ?? ''; |
|
| 258 | + if (!$data) { |
|
| 259 | + throw new Exception('404'); |
|
| 260 | + } |
|
| 261 | + if (!isset($ttl)) { |
|
| 262 | + $ttl = 24 * 3600; |
|
| 263 | + } |
|
| 264 | + } elseif (@is_dir($src)) { |
|
| 265 | + $data = $src; |
|
| 266 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 267 | + $data = spip_file_get_contents($src); |
|
| 268 | + } |
|
| 269 | + if (!isset($ttl)) { |
|
| 270 | + $ttl = 10; |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + if ( |
|
| 274 | + !$this->err |
|
| 275 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 276 | + ) { |
|
| 277 | + $args = $this->command['source']; |
|
| 278 | + $args[0] = $data; |
|
| 279 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 280 | + $this->tableau = $a; |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + if (!is_array($this->tableau)) { |
|
| 286 | + $this->err = true; |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 290 | + $this->cache_set($cle, $ttl); |
|
| 291 | + } |
|
| 292 | + } catch (Exception $e) { |
|
| 293 | + $e = $e->getMessage(); |
|
| 294 | + $err = sprintf( |
|
| 295 | + "[%s, %s] $e", |
|
| 296 | + $src, |
|
| 297 | + $this->command['sourcemode'] |
|
| 298 | + ); |
|
| 299 | + erreur_squelette([$err, []]); |
|
| 300 | + $this->err = true; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 305 | + if ( |
|
| 306 | + $this->err |
|
| 307 | + and $cache |
|
| 308 | + ) { |
|
| 309 | + $this->tableau = $cache['data']; |
|
| 310 | + $this->err = false; |
|
| 311 | + } |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Retourne un tableau donne depuis un critère liste |
|
| 317 | + * |
|
| 318 | + * Critère `{liste X1, X2, X3}` |
|
| 319 | + * |
|
| 320 | + * @see critere_DATA_liste_dist() |
|
| 321 | + * |
|
| 322 | + **/ |
|
| 323 | + protected function select_liste() { |
|
| 324 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 325 | + if (!isset($this->command['liste'][1])) { |
|
| 326 | + if (!is_array($this->command['liste'][0])) { |
|
| 327 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 328 | + } else { |
|
| 329 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + $this->tableau = $this->command['liste']; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + /** |
|
| 336 | + * Retourne un tableau donne depuis un critere liste |
|
| 337 | + * Critere {enum Xmin, Xmax} |
|
| 338 | + * |
|
| 339 | + **/ |
|
| 340 | + protected function select_enum() { |
|
| 341 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 342 | + if (!isset($this->command['enum'][1])) { |
|
| 343 | + if (!is_array($this->command['enum'][0])) { |
|
| 344 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 345 | + } else { |
|
| 346 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 350 | + $enum = range( |
|
| 351 | + array_shift($this->command['enum']), |
|
| 352 | + array_shift($this->command['enum']), |
|
| 353 | + array_shift($this->command['enum']) |
|
| 354 | + ); |
|
| 355 | + } else { |
|
| 356 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 357 | + } |
|
| 358 | + $this->tableau = $enum; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + |
|
| 362 | + /** |
|
| 363 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 364 | + * {datapath query.results} |
|
| 365 | + * |
|
| 366 | + **/ |
|
| 367 | + protected function select_datapath() { |
|
| 368 | + $base = reset($this->command['datapath']); |
|
| 369 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 370 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 371 | + if (!is_array($this->tableau)) { |
|
| 372 | + $this->tableau = []; |
|
| 373 | + $this->err = true; |
|
| 374 | + spip_log("datapath '$base' absent"); |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + /** |
|
| 380 | + * Ordonner les resultats |
|
| 381 | + * {par x} |
|
| 382 | + * |
|
| 383 | + **/ |
|
| 384 | + protected function select_orderby() { |
|
| 385 | + $sortfunc = ''; |
|
| 386 | + $aleas = 0; |
|
| 387 | + foreach ($this->command['orderby'] as $tri) { |
|
| 388 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 389 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 390 | + $r = array_pad($r, 3, null); |
|
| 391 | + |
|
| 392 | + // tri par cle |
|
| 393 | + if ($r[1] == 'cle') { |
|
| 394 | + if (isset($r[2]) and $r[2]) { |
|
| 395 | + krsort($this->tableau); |
|
| 396 | + } else { |
|
| 397 | + ksort($this->tableau); |
|
| 398 | + } |
|
| 399 | + } # {par hasard} |
|
| 400 | + else { |
|
| 401 | + if ($r[1] == 'hasard') { |
|
| 402 | + $k = array_keys($this->tableau); |
|
| 403 | + shuffle($k); |
|
| 404 | + $v = []; |
|
| 405 | + foreach ($k as $cle) { |
|
| 406 | + $v[$cle] = $this->tableau[$cle]; |
|
| 407 | + } |
|
| 408 | + $this->tableau = $v; |
|
| 409 | + } else { |
|
| 410 | + # {par valeur} |
|
| 411 | + if ($r[1] == 'valeur') { |
|
| 412 | + $tv = '%s'; |
|
| 413 | + } # {par valeur/xx/yy} ?? |
|
| 414 | + else { |
|
| 415 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 416 | + } |
|
| 417 | + $sortfunc .= ' |
|
| 418 | 418 | $a = ' . sprintf($tv, '$aa') . '; |
| 419 | 419 | $b = ' . sprintf($tv, '$bb') . '; |
| 420 | 420 | if ($a <> $b) |
| 421 | 421 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 422 | - } |
|
| 423 | - } |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if ($sortfunc) { |
|
| 428 | - $sortfunc .= "\n return 0;"; |
|
| 429 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 430 | - } |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - |
|
| 434 | - /** |
|
| 435 | - * Grouper les resultats |
|
| 436 | - * {fusion /x/y/z} |
|
| 437 | - * |
|
| 438 | - **/ |
|
| 439 | - protected function select_groupby() { |
|
| 440 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 441 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 442 | - $vu = []; |
|
| 443 | - foreach ($this->tableau as $k => $v) { |
|
| 444 | - $val = table_valeur($v, $fusion); |
|
| 445 | - if (isset($vu[$val])) { |
|
| 446 | - unset($this->tableau[$k]); |
|
| 447 | - } else { |
|
| 448 | - $vu[$val] = true; |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - |
|
| 455 | - /** |
|
| 456 | - * L'iterateur est-il encore valide ? |
|
| 457 | - * |
|
| 458 | - * @return bool |
|
| 459 | - */ |
|
| 460 | - public function valid(): bool { |
|
| 461 | - return !is_null($this->cle); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - /** |
|
| 465 | - * Retourner la valeur |
|
| 466 | - * |
|
| 467 | - * @return mixed |
|
| 468 | - */ |
|
| 469 | - #[\ReturnTypeWillChange] |
|
| 470 | - public function current() { |
|
| 471 | - return $this->valeur; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - /** |
|
| 475 | - * Retourner la cle |
|
| 476 | - * |
|
| 477 | - * @return mixed |
|
| 478 | - */ |
|
| 479 | - #[\ReturnTypeWillChange] |
|
| 480 | - public function key() { |
|
| 481 | - return $this->cle; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - /** |
|
| 485 | - * Passer a la valeur suivante |
|
| 486 | - * |
|
| 487 | - * @return void |
|
| 488 | - */ |
|
| 489 | - public function next(): void { |
|
| 490 | - if ($this->valid()) { |
|
| 491 | - $this->cle = key($this->tableau); |
|
| 492 | - $this->valeur = current($this->tableau); |
|
| 493 | - next($this->tableau); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Compter le nombre total de resultats |
|
| 499 | - * |
|
| 500 | - * @return int |
|
| 501 | - */ |
|
| 502 | - public function count() { |
|
| 503 | - if (is_null($this->total)) { |
|
| 504 | - $this->total = count($this->tableau); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - return $this->total; |
|
| 508 | - } |
|
| 422 | + } |
|
| 423 | + } |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if ($sortfunc) { |
|
| 428 | + $sortfunc .= "\n return 0;"; |
|
| 429 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 430 | + } |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + |
|
| 434 | + /** |
|
| 435 | + * Grouper les resultats |
|
| 436 | + * {fusion /x/y/z} |
|
| 437 | + * |
|
| 438 | + **/ |
|
| 439 | + protected function select_groupby() { |
|
| 440 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 441 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 442 | + $vu = []; |
|
| 443 | + foreach ($this->tableau as $k => $v) { |
|
| 444 | + $val = table_valeur($v, $fusion); |
|
| 445 | + if (isset($vu[$val])) { |
|
| 446 | + unset($this->tableau[$k]); |
|
| 447 | + } else { |
|
| 448 | + $vu[$val] = true; |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + |
|
| 455 | + /** |
|
| 456 | + * L'iterateur est-il encore valide ? |
|
| 457 | + * |
|
| 458 | + * @return bool |
|
| 459 | + */ |
|
| 460 | + public function valid(): bool { |
|
| 461 | + return !is_null($this->cle); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + /** |
|
| 465 | + * Retourner la valeur |
|
| 466 | + * |
|
| 467 | + * @return mixed |
|
| 468 | + */ |
|
| 469 | + #[\ReturnTypeWillChange] |
|
| 470 | + public function current() { |
|
| 471 | + return $this->valeur; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + /** |
|
| 475 | + * Retourner la cle |
|
| 476 | + * |
|
| 477 | + * @return mixed |
|
| 478 | + */ |
|
| 479 | + #[\ReturnTypeWillChange] |
|
| 480 | + public function key() { |
|
| 481 | + return $this->cle; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + /** |
|
| 485 | + * Passer a la valeur suivante |
|
| 486 | + * |
|
| 487 | + * @return void |
|
| 488 | + */ |
|
| 489 | + public function next(): void { |
|
| 490 | + if ($this->valid()) { |
|
| 491 | + $this->cle = key($this->tableau); |
|
| 492 | + $this->valeur = current($this->tableau); |
|
| 493 | + next($this->tableau); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Compter le nombre total de resultats |
|
| 499 | + * |
|
| 500 | + * @return int |
|
| 501 | + */ |
|
| 502 | + public function count() { |
|
| 503 | + if (is_null($this->total)) { |
|
| 504 | + $this->total = count($this->tableau); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + return $this->total; |
|
| 508 | + } |
|
| 509 | 509 | } |