@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 44 | 44 | */ |
| 45 | 45 | function generer_action_auteur($action, $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 46 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | 47 | |
| 48 | - return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 48 | + return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * Code HTML du formulaire |
| 79 | 79 | */ |
| 80 | 80 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 81 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 81 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 82 | 82 | |
| 83 | - return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 83 | + return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 106 | 106 | */ |
| 107 | 107 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') { |
| 108 | - $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 108 | + $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 109 | 109 | |
| 110 | - return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 110 | + return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -124,26 +124,26 @@ discard block |
||
| 124 | 124 | * passer "text/html" comme $content_type |
| 125 | 125 | */ |
| 126 | 126 | function ajax_retour($corps, $content_type = null): void { |
| 127 | - $xml = false; |
|
| 128 | - if (is_null($content_type) or $content_type === true) { |
|
| 129 | - $xml = true; |
|
| 130 | - $content_type = 'text/html'; |
|
| 131 | - } elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) { |
|
| 132 | - $content_type = 'text/html'; |
|
| 133 | - } |
|
| 127 | + $xml = false; |
|
| 128 | + if (is_null($content_type) or $content_type === true) { |
|
| 129 | + $xml = true; |
|
| 130 | + $content_type = 'text/html'; |
|
| 131 | + } elseif (!$content_type or !is_string($content_type) or strpos($content_type, '/') === false) { |
|
| 132 | + $content_type = 'text/html'; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - $e = ''; |
|
| 136 | - if ( |
|
| 137 | - isset($_COOKIE['spip_admin']) |
|
| 138 | - and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps'])) |
|
| 139 | - ) { |
|
| 140 | - $e = erreur_squelette(); |
|
| 141 | - } |
|
| 135 | + $e = ''; |
|
| 136 | + if ( |
|
| 137 | + isset($_COOKIE['spip_admin']) |
|
| 138 | + and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps'])) |
|
| 139 | + ) { |
|
| 140 | + $e = erreur_squelette(); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - $c = $GLOBALS['meta']['charset']; |
|
| 144 | - header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 145 | - $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 146 | - $fin = ''; |
|
| 143 | + $c = $GLOBALS['meta']['charset']; |
|
| 144 | + header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 145 | + $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 146 | + $fin = ''; |
|
| 147 | 147 | |
| 148 | - echo $debut, $corps, $fin, $e; |
|
| 148 | + echo $debut, $corps, $fin, $e; |
|
| 149 | 149 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | */ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/filtres_boites'); |
@@ -41,25 +41,25 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function parametres_css_prive() { |
| 43 | 43 | |
| 44 | - $args = []; |
|
| 45 | - $args['v'] = $GLOBALS['spip_version_code']; |
|
| 46 | - $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4); |
|
| 47 | - $args['themes'] = implode(',', lister_themes_prives()); |
|
| 48 | - $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 49 | - // un md5 des menus : si un menu change il faut maj la css |
|
| 50 | - $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 44 | + $args = []; |
|
| 45 | + $args['v'] = $GLOBALS['spip_version_code']; |
|
| 46 | + $args['p'] = substr(md5($GLOBALS['meta']['plugin']), 0, 4); |
|
| 47 | + $args['themes'] = implode(',', lister_themes_prives()); |
|
| 48 | + $args['ltr'] = $GLOBALS['spip_lang_left']; |
|
| 49 | + // un md5 des menus : si un menu change il faut maj la css |
|
| 50 | + $args['md5b'] = (function_exists('md5_boutons_plugins') ? md5_boutons_plugins() : ''); |
|
| 51 | 51 | |
| 52 | - $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 52 | + $c = $GLOBALS['visiteur_session']['prefs']['couleur'] ?? 2; |
|
| 53 | 53 | |
| 54 | - $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 55 | - parse_str($couleurs($c), $c); |
|
| 56 | - $args = array_merge($args, $c); |
|
| 54 | + $couleurs = charger_fonction('couleurs', 'inc'); |
|
| 55 | + parse_str($couleurs($c), $c); |
|
| 56 | + $args = array_merge($args, $c); |
|
| 57 | 57 | |
| 58 | - if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) { |
|
| 59 | - $args['var_mode'] = 'recalcul'; |
|
| 60 | - } |
|
| 58 | + if (_request('var_mode') == 'recalcul' or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul')) { |
|
| 59 | + $args['var_mode'] = 'recalcul'; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return http_build_query($args); |
|
| 62 | + return http_build_query($args); |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | |
@@ -82,91 +82,91 @@ discard block |
||
| 82 | 82 | * @return string |
| 83 | 83 | */ |
| 84 | 84 | function chercher_rubrique( |
| 85 | - $titre, |
|
| 86 | - $id_objet, |
|
| 87 | - $id_parent, |
|
| 88 | - $objet, |
|
| 89 | - $id_secteur, |
|
| 90 | - $restreint, |
|
| 91 | - $actionable = false, |
|
| 92 | - $retour_sans_cadre = false |
|
| 85 | + $titre, |
|
| 86 | + $id_objet, |
|
| 87 | + $id_parent, |
|
| 88 | + $objet, |
|
| 89 | + $id_secteur, |
|
| 90 | + $restreint, |
|
| 91 | + $actionable = false, |
|
| 92 | + $retour_sans_cadre = false |
|
| 93 | 93 | ) { |
| 94 | 94 | |
| 95 | - include_spip('inc/autoriser'); |
|
| 96 | - if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) { |
|
| 97 | - return ''; |
|
| 98 | - } |
|
| 99 | - if (!sql_countsel('spip_rubriques')) { |
|
| 100 | - return ''; |
|
| 101 | - } |
|
| 102 | - $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 103 | - $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 104 | - |
|
| 105 | - if ($id_parent == 0) { |
|
| 106 | - $logo = 'racine-24.png'; |
|
| 107 | - } elseif ($id_secteur == $id_parent) { |
|
| 108 | - $logo = 'secteur-24.png'; |
|
| 109 | - } else { |
|
| 110 | - $logo = 'rubrique-24.png'; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $confirm = ''; |
|
| 114 | - if ($objet == 'rubrique') { |
|
| 115 | - // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | - // confirmation du deplacement |
|
| 117 | - $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet)); |
|
| 118 | - |
|
| 119 | - if ($contient_breves > 0) { |
|
| 120 | - $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 121 | - $scb = _T( |
|
| 122 | - 'avis_deplacement_rubrique', |
|
| 123 | - [ |
|
| 124 | - 'contient_breves' => $contient_breves, |
|
| 125 | - 'scb' => $scb |
|
| 126 | - ] |
|
| 127 | - ); |
|
| 128 | - $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 129 | - . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 130 | - . $scb . |
|
| 131 | - "</label></div></div>\n"; |
|
| 132 | - } else { |
|
| 133 | - $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $form .= $confirm; |
|
| 137 | - if ($actionable) { |
|
| 138 | - if (strpos($form, '<select') !== false) { |
|
| 139 | - $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 140 | - . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 141 | - . '</div>'; |
|
| 142 | - } |
|
| 143 | - $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 144 | - if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 145 | - $form = generer_action_auteur( |
|
| 146 | - "editer_$objet", |
|
| 147 | - $id_objet, |
|
| 148 | - self(), |
|
| 149 | - $form, |
|
| 150 | - " method='post' class='submit_plongeur'" |
|
| 151 | - ); |
|
| 152 | - } else { |
|
| 153 | - $form = generer_action_auteur( |
|
| 154 | - 'editer_objet', |
|
| 155 | - "$objet/$id_objet", |
|
| 156 | - self(), |
|
| 157 | - $form, |
|
| 158 | - " method='post' class='submit_plongeur'" |
|
| 159 | - ); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ($retour_sans_cadre) { |
|
| 164 | - return $form; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - include_spip('inc/presentation'); |
|
| 168 | - |
|
| 169 | - return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 95 | + include_spip('inc/autoriser'); |
|
| 96 | + if (intval($id_objet) && !autoriser('modifier', $objet, $id_objet)) { |
|
| 97 | + return ''; |
|
| 98 | + } |
|
| 99 | + if (!sql_countsel('spip_rubriques')) { |
|
| 100 | + return ''; |
|
| 101 | + } |
|
| 102 | + $chercher_rubrique = charger_fonction('chercher_rubrique', 'inc'); |
|
| 103 | + $form = $chercher_rubrique($id_parent, $objet, $restreint, ($objet == 'rubrique') ? $id_objet : 0); |
|
| 104 | + |
|
| 105 | + if ($id_parent == 0) { |
|
| 106 | + $logo = 'racine-24.png'; |
|
| 107 | + } elseif ($id_secteur == $id_parent) { |
|
| 108 | + $logo = 'secteur-24.png'; |
|
| 109 | + } else { |
|
| 110 | + $logo = 'rubrique-24.png'; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $confirm = ''; |
|
| 114 | + if ($objet == 'rubrique') { |
|
| 115 | + // si c'est une rubrique-secteur contenant des breves, demander la |
|
| 116 | + // confirmation du deplacement |
|
| 117 | + $contient_breves = sql_countsel('spip_breves', 'id_rubrique=' . intval($id_objet)); |
|
| 118 | + |
|
| 119 | + if ($contient_breves > 0) { |
|
| 120 | + $scb = ($contient_breves > 1 ? 's' : ''); |
|
| 121 | + $scb = _T( |
|
| 122 | + 'avis_deplacement_rubrique', |
|
| 123 | + [ |
|
| 124 | + 'contient_breves' => $contient_breves, |
|
| 125 | + 'scb' => $scb |
|
| 126 | + ] |
|
| 127 | + ); |
|
| 128 | + $confirm .= "\n<div class='confirmer_deplacement verdana2'>" |
|
| 129 | + . "<div class='choix'><input type='checkbox' name='confirme_deplace' value='oui' id='confirme-deplace' /><label for='confirme-deplace'>" |
|
| 130 | + . $scb . |
|
| 131 | + "</label></div></div>\n"; |
|
| 132 | + } else { |
|
| 133 | + $confirm .= "<input type='hidden' name='confirme_deplace' value='oui' />\n"; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $form .= $confirm; |
|
| 137 | + if ($actionable) { |
|
| 138 | + if (strpos($form, '<select') !== false) { |
|
| 139 | + $form .= "<div style='text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 140 | + . '<input class="fondo submit btn" type="submit" value="' . _T('bouton_choisir') . '"/>' |
|
| 141 | + . '</div>'; |
|
| 142 | + } |
|
| 143 | + $form = "<input type='hidden' name='editer_$objet' value='oui' />\n" . $form; |
|
| 144 | + if ($action = charger_fonction("editer_$objet", 'action', true)) { |
|
| 145 | + $form = generer_action_auteur( |
|
| 146 | + "editer_$objet", |
|
| 147 | + $id_objet, |
|
| 148 | + self(), |
|
| 149 | + $form, |
|
| 150 | + " method='post' class='submit_plongeur'" |
|
| 151 | + ); |
|
| 152 | + } else { |
|
| 153 | + $form = generer_action_auteur( |
|
| 154 | + 'editer_objet', |
|
| 155 | + "$objet/$id_objet", |
|
| 156 | + self(), |
|
| 157 | + $form, |
|
| 158 | + " method='post' class='submit_plongeur'" |
|
| 159 | + ); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ($retour_sans_cadre) { |
|
| 164 | + return $form; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + include_spip('inc/presentation'); |
|
| 168 | + |
|
| 169 | + return debut_cadre_couleur($logo, true, '', $titre) . $form . fin_cadre_couleur(); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | |
@@ -180,24 +180,24 @@ discard block |
||
| 180 | 180 | * @return bool |
| 181 | 181 | */ |
| 182 | 182 | function avoir_visiteurs($past = false, $accepter = true) { |
| 183 | - if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 184 | - return true; |
|
| 185 | - } |
|
| 186 | - if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') { |
|
| 187 | - return true; |
|
| 188 | - } |
|
| 189 | - if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 190 | - return true; |
|
| 191 | - } |
|
| 192 | - if (!$past) { |
|
| 193 | - return false; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - return sql_countsel( |
|
| 197 | - 'spip_auteurs', |
|
| 198 | - "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 183 | + if ($GLOBALS['meta']['forums_publics'] == 'abo') { |
|
| 184 | + return true; |
|
| 185 | + } |
|
| 186 | + if ($accepter and $GLOBALS['meta']['accepter_visiteurs'] <> 'non') { |
|
| 187 | + return true; |
|
| 188 | + } |
|
| 189 | + if (sql_countsel('spip_articles', "accepter_forum='abo'")) { |
|
| 190 | + return true; |
|
| 191 | + } |
|
| 192 | + if (!$past) { |
|
| 193 | + return false; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + return sql_countsel( |
|
| 197 | + 'spip_auteurs', |
|
| 198 | + "statut NOT IN ('0minirezo','1comite', '5poubelle') |
|
| 199 | 199 | AND (statut<>'nouveau' OR prefs NOT IN ('0minirezo','1comite', '5poubelle'))" |
| 200 | - ); |
|
| 200 | + ); |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -213,18 +213,18 @@ discard block |
||
| 213 | 213 | * @return array |
| 214 | 214 | */ |
| 215 | 215 | function statuts_articles_visibles($statut_auteur) { |
| 216 | - static $auth = []; |
|
| 217 | - if (!isset($auth[$statut_auteur])) { |
|
| 218 | - $auth[$statut_auteur] = []; |
|
| 219 | - $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 220 | - foreach ($statuts as $s) { |
|
| 221 | - if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 222 | - $auth[$statut_auteur][] = $s; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - return $auth[$statut_auteur]; |
|
| 216 | + static $auth = []; |
|
| 217 | + if (!isset($auth[$statut_auteur])) { |
|
| 218 | + $auth[$statut_auteur] = []; |
|
| 219 | + $statuts = array_column(sql_allfetsel('distinct statut', 'spip_articles'), 'statut'); |
|
| 220 | + foreach ($statuts as $s) { |
|
| 221 | + if (autoriser('voir', 'article', 0, ['statut' => $statut_auteur], ['statut' => $s])) { |
|
| 222 | + $auth[$statut_auteur][] = $s; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + return $auth[$statut_auteur]; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -238,38 +238,38 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function traduire_statut_auteur($statut, $attente = '') { |
| 241 | - $plus = ''; |
|
| 242 | - if ($statut == 'nouveau') { |
|
| 243 | - if ($attente) { |
|
| 244 | - $statut = $attente; |
|
| 245 | - $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 246 | - } else { |
|
| 247 | - return _T('info_statut_auteur_a_confirmer'); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $recom = [ |
|
| 252 | - 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 253 | - 'info_redacteurs' => _T('intem_redacteur'), |
|
| 254 | - 'info_visiteurs' => _T('item_visiteur'), |
|
| 255 | - '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 256 | - ]; |
|
| 257 | - if (isset($recom[$statut])) { |
|
| 258 | - return $recom[$statut] . $plus; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // retrouver directement par le statut sinon |
|
| 262 | - if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 263 | - if (isset($recom[$t])) { |
|
| 264 | - return $recom[$t] . $plus; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - return _T($t) . $plus; |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 271 | - // c'est toujours plus informatif que rien du tout |
|
| 272 | - return $statut; |
|
| 241 | + $plus = ''; |
|
| 242 | + if ($statut == 'nouveau') { |
|
| 243 | + if ($attente) { |
|
| 244 | + $statut = $attente; |
|
| 245 | + $plus = ' (' . _T('info_statut_auteur_a_confirmer') . ')'; |
|
| 246 | + } else { |
|
| 247 | + return _T('info_statut_auteur_a_confirmer'); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $recom = [ |
|
| 252 | + 'info_administrateurs' => _T('item_administrateur_2'), |
|
| 253 | + 'info_redacteurs' => _T('intem_redacteur'), |
|
| 254 | + 'info_visiteurs' => _T('item_visiteur'), |
|
| 255 | + '5poubelle' => _T('texte_statut_poubelle'), // bouh |
|
| 256 | + ]; |
|
| 257 | + if (isset($recom[$statut])) { |
|
| 258 | + return $recom[$statut] . $plus; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // retrouver directement par le statut sinon |
|
| 262 | + if ($t = array_search($statut, $GLOBALS['liste_des_statuts'])) { |
|
| 263 | + if (isset($recom[$t])) { |
|
| 264 | + return $recom[$t] . $plus; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + return _T($t) . $plus; |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // si on a pas reussi a le traduire, retournons la chaine telle quelle |
|
| 271 | + // c'est toujours plus informatif que rien du tout |
|
| 272 | + return $statut; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -280,28 +280,28 @@ discard block |
||
| 280 | 280 | * @return string |
| 281 | 281 | */ |
| 282 | 282 | function afficher_qui_edite($id_objet, $objet) { |
| 283 | - static $qui = []; |
|
| 284 | - if (isset($qui[$objet][$id_objet])) { |
|
| 285 | - return $qui[$objet][$id_objet]; |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if ($GLOBALS['meta']['articles_modif'] == 'non') { |
|
| 289 | - return $qui[$objet][$id_objet] = ''; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - include_spip('inc/drapeau_edition'); |
|
| 293 | - $modif = mention_qui_edite($id_objet, $objet); |
|
| 294 | - if (!$modif) { |
|
| 295 | - return $qui[$objet][$id_objet] = ''; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - include_spip('base/objets'); |
|
| 299 | - $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 300 | - if (isset($infos['texte_signale_edition'])) { |
|
| 301 | - return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 283 | + static $qui = []; |
|
| 284 | + if (isset($qui[$objet][$id_objet])) { |
|
| 285 | + return $qui[$objet][$id_objet]; |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if ($GLOBALS['meta']['articles_modif'] == 'non') { |
|
| 289 | + return $qui[$objet][$id_objet] = ''; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + include_spip('inc/drapeau_edition'); |
|
| 293 | + $modif = mention_qui_edite($id_objet, $objet); |
|
| 294 | + if (!$modif) { |
|
| 295 | + return $qui[$objet][$id_objet] = ''; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + include_spip('base/objets'); |
|
| 299 | + $infos = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 300 | + if (isset($infos['texte_signale_edition'])) { |
|
| 301 | + return $qui[$objet][$id_objet] = _T($infos['texte_signale_edition'], $modif); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $qui[$objet][$id_objet] = _T('info_qui_edite', $modif); |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -319,57 +319,57 @@ discard block |
||
| 319 | 319 | * @return array |
| 320 | 320 | */ |
| 321 | 321 | function auteurs_lister_statuts($quoi = 'tous', $en_base = true) { |
| 322 | - if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 323 | - define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - switch ($quoi) { |
|
| 327 | - case 'redacteurs': |
|
| 328 | - $statut = AUTEURS_MIN_REDAC; |
|
| 329 | - $statut = explode(',', $statut); |
|
| 330 | - if ($en_base) { |
|
| 331 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 332 | - $retire = array_diff($statut, $check); |
|
| 333 | - $statut = array_diff($statut, $retire); |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - return array_unique($statut); |
|
| 337 | - break; |
|
| 338 | - case 'visiteurs': |
|
| 339 | - $statut = []; |
|
| 340 | - $exclus = AUTEURS_MIN_REDAC; |
|
| 341 | - $exclus = explode(',', $exclus); |
|
| 342 | - if (!$en_base) { |
|
| 343 | - // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 344 | - $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 345 | - } |
|
| 346 | - $s_complement = array_column( |
|
| 347 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 348 | - 'statut' |
|
| 349 | - ); |
|
| 350 | - |
|
| 351 | - return array_unique(array_merge($statut, $s_complement)); |
|
| 352 | - break; |
|
| 353 | - default: |
|
| 354 | - case 'tous': |
|
| 355 | - $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 356 | - $s_complement = array_column( |
|
| 357 | - sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 358 | - 'statut' |
|
| 359 | - ); |
|
| 360 | - $statut = array_merge($statut, $s_complement); |
|
| 361 | - if ($en_base) { |
|
| 362 | - $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 363 | - $retire = array_diff($statut, $check); |
|
| 364 | - $statut = array_diff($statut, $retire); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return array_unique($statut); |
|
| 368 | - break; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - // on arrive jamais ici |
|
| 372 | - return array_values($GLOBALS['liste_des_statuts']); |
|
| 322 | + if (!defined('AUTEURS_MIN_REDAC')) { |
|
| 323 | + define('AUTEURS_MIN_REDAC', '0minirezo,1comite,5poubelle'); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + switch ($quoi) { |
|
| 327 | + case 'redacteurs': |
|
| 328 | + $statut = AUTEURS_MIN_REDAC; |
|
| 329 | + $statut = explode(',', $statut); |
|
| 330 | + if ($en_base) { |
|
| 331 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 332 | + $retire = array_diff($statut, $check); |
|
| 333 | + $statut = array_diff($statut, $retire); |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + return array_unique($statut); |
|
| 337 | + break; |
|
| 338 | + case 'visiteurs': |
|
| 339 | + $statut = []; |
|
| 340 | + $exclus = AUTEURS_MIN_REDAC; |
|
| 341 | + $exclus = explode(',', $exclus); |
|
| 342 | + if (!$en_base) { |
|
| 343 | + // prendre aussi les statuts de la table des status qui ne sont pas dans le define |
|
| 344 | + $statut = array_diff(array_values($GLOBALS['liste_des_statuts']), $exclus); |
|
| 345 | + } |
|
| 346 | + $s_complement = array_column( |
|
| 347 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $exclus, 'NOT')), |
|
| 348 | + 'statut' |
|
| 349 | + ); |
|
| 350 | + |
|
| 351 | + return array_unique(array_merge($statut, $s_complement)); |
|
| 352 | + break; |
|
| 353 | + default: |
|
| 354 | + case 'tous': |
|
| 355 | + $statut = array_values($GLOBALS['liste_des_statuts']); |
|
| 356 | + $s_complement = array_column( |
|
| 357 | + sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut, 'NOT')), |
|
| 358 | + 'statut' |
|
| 359 | + ); |
|
| 360 | + $statut = array_merge($statut, $s_complement); |
|
| 361 | + if ($en_base) { |
|
| 362 | + $check = array_column(sql_allfetsel('DISTINCT statut', 'spip_auteurs', sql_in('statut', $statut)), 'statut'); |
|
| 363 | + $retire = array_diff($statut, $check); |
|
| 364 | + $statut = array_diff($statut, $retire); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return array_unique($statut); |
|
| 368 | + break; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + // on arrive jamais ici |
|
| 372 | + return array_values($GLOBALS['liste_des_statuts']); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -385,28 +385,28 @@ discard block |
||
| 385 | 385 | */ |
| 386 | 386 | function trouver_rubrique_creer_objet($id_rubrique, $objet) { |
| 387 | 387 | |
| 388 | - if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | - $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | - ? '' |
|
| 391 | - : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 392 | - |
|
| 393 | - // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | - if ($objet == 'rubrique') { |
|
| 395 | - $id_rubrique = 0; |
|
| 396 | - } else { |
|
| 397 | - $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | - while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | - $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return $id_rubrique; |
|
| 388 | + if (!$id_rubrique and defined('_CHOIX_RUBRIQUE_PAR_DEFAUT') and _CHOIX_RUBRIQUE_PAR_DEFAUT) { |
|
| 389 | + $in = !(is_countable($GLOBALS['connect_id_rubrique']) ? count($GLOBALS['connect_id_rubrique']) : 0) |
|
| 390 | + ? '' |
|
| 391 | + : (' AND ' . sql_in('id_rubrique', $GLOBALS['connect_id_rubrique'])); |
|
| 392 | + |
|
| 393 | + // on tente d'abord l'ecriture a la racine dans le cas des rubriques uniquement |
|
| 394 | + if ($objet == 'rubrique') { |
|
| 395 | + $id_rubrique = 0; |
|
| 396 | + } else { |
|
| 397 | + $id_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', "id_parent=0$in", '', 'id_rubrique DESC', 1); |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + if (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique)) { |
|
| 401 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 402 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 403 | + while (!autoriser("creer{$objet}dans", 'rubrique', $id_rubrique) && $row_rub = sql_fetch($res)) { |
|
| 404 | + $id_rubrique = $row_rub['id_rubrique']; |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return $id_rubrique; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | /** |
@@ -417,12 +417,12 @@ discard block |
||
| 417 | 417 | * @return string |
| 418 | 418 | */ |
| 419 | 419 | function lien_article_virtuel($virtuel) { |
| 420 | - include_spip('inc/lien'); |
|
| 421 | - if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | - return ''; |
|
| 423 | - } |
|
| 420 | + include_spip('inc/lien'); |
|
| 421 | + if (!$virtuel = virtuel_redirige($virtuel)) { |
|
| 422 | + return ''; |
|
| 423 | + } |
|
| 424 | 424 | |
| 425 | - return propre('[->' . $virtuel . ']'); |
|
| 425 | + return propre('[->' . $virtuel . ']'); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | |
@@ -445,11 +445,11 @@ discard block |
||
| 445 | 445 | * @filtre |
| 446 | 446 | */ |
| 447 | 447 | function bouton_spip_rss($op, $args = [], $lang = '', $title = 'RSS') { |
| 448 | - include_spip('inc/acces'); |
|
| 449 | - $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 448 | + include_spip('inc/acces'); |
|
| 449 | + $clic = http_img_pack('rss-16.png', 'RSS', '', $title); |
|
| 450 | 450 | |
| 451 | - $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 452 | - return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 451 | + $url = generer_url_api_low_sec('transmettre', 'rss', $op, '', http_build_query($args), false, true); |
|
| 452 | + return "<a style='float: " . $GLOBALS['spip_lang_right'] . ";' href='$url'>$clic</a>"; |
|
| 453 | 453 | } |
| 454 | 454 | |
| 455 | 455 | |
@@ -461,76 +461,76 @@ discard block |
||
| 461 | 461 | */ |
| 462 | 462 | function alertes_auteur($id_auteur): string { |
| 463 | 463 | |
| 464 | - $alertes = []; |
|
| 465 | - |
|
| 466 | - if ( |
|
| 467 | - isset($GLOBALS['meta']['message_crash_tables']) |
|
| 468 | - and autoriser('detruire', null, null, $id_auteur) |
|
| 469 | - ) { |
|
| 470 | - include_spip('genie/maintenance'); |
|
| 471 | - if ($msg = message_crash_tables()) { |
|
| 472 | - $alertes[] = $msg; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - if ( |
|
| 477 | - isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 478 | - and $GLOBALS['meta']['message_crash_plugins'] |
|
| 479 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 480 | - and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 481 | - ) { |
|
| 482 | - $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 483 | - $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 487 | - if ( |
|
| 488 | - $a |
|
| 489 | - and is_array($a = unserialize($a)) |
|
| 490 | - and count($a) |
|
| 491 | - ) { |
|
| 492 | - $update = false; |
|
| 493 | - if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 494 | - $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 495 | - unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 496 | - $update = true; |
|
| 497 | - } |
|
| 498 | - if (isset($a[''])) { |
|
| 499 | - $alertes = array_merge($alertes, $a['']); |
|
| 500 | - unset($a['']); |
|
| 501 | - $update = true; |
|
| 502 | - } |
|
| 503 | - if ($update) { |
|
| 504 | - ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - if ( |
|
| 509 | - isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 510 | - and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 511 | - ) { |
|
| 512 | - include_spip('inc/plugin'); |
|
| 513 | - $alertes[] = plugin_donne_erreurs(); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - $alertes = pipeline( |
|
| 517 | - 'alertes_auteur', |
|
| 518 | - [ |
|
| 519 | - 'args' => [ |
|
| 520 | - 'id_auteur' => $id_auteur, |
|
| 521 | - 'exec' => _request('exec'), |
|
| 522 | - ], |
|
| 523 | - 'data' => $alertes |
|
| 524 | - ] |
|
| 525 | - ); |
|
| 526 | - |
|
| 527 | - if ($alertes = array_filter($alertes)) { |
|
| 528 | - return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 529 | - join(' | ', $alertes) |
|
| 530 | - . '</div></div>'; |
|
| 531 | - } |
|
| 532 | - |
|
| 533 | - return ''; |
|
| 464 | + $alertes = []; |
|
| 465 | + |
|
| 466 | + if ( |
|
| 467 | + isset($GLOBALS['meta']['message_crash_tables']) |
|
| 468 | + and autoriser('detruire', null, null, $id_auteur) |
|
| 469 | + ) { |
|
| 470 | + include_spip('genie/maintenance'); |
|
| 471 | + if ($msg = message_crash_tables()) { |
|
| 472 | + $alertes[] = $msg; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + if ( |
|
| 477 | + isset($GLOBALS['meta']['message_crash_plugins']) |
|
| 478 | + and $GLOBALS['meta']['message_crash_plugins'] |
|
| 479 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 480 | + and is_array($msg = unserialize($GLOBALS['meta']['message_crash_plugins'])) |
|
| 481 | + ) { |
|
| 482 | + $msg = implode(', ', array_map('joli_repertoire', array_keys($msg))); |
|
| 483 | + $alertes[] = _T('plugins_erreur', ['plugins' => $msg]); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $a = $GLOBALS['meta']['message_alertes_auteurs'] ?? ''; |
|
| 487 | + if ( |
|
| 488 | + $a |
|
| 489 | + and is_array($a = unserialize($a)) |
|
| 490 | + and count($a) |
|
| 491 | + ) { |
|
| 492 | + $update = false; |
|
| 493 | + if (isset($a[$GLOBALS['visiteur_session']['statut']])) { |
|
| 494 | + $alertes = array_merge($alertes, $a[$GLOBALS['visiteur_session']['statut']]); |
|
| 495 | + unset($a[$GLOBALS['visiteur_session']['statut']]); |
|
| 496 | + $update = true; |
|
| 497 | + } |
|
| 498 | + if (isset($a[''])) { |
|
| 499 | + $alertes = array_merge($alertes, $a['']); |
|
| 500 | + unset($a['']); |
|
| 501 | + $update = true; |
|
| 502 | + } |
|
| 503 | + if ($update) { |
|
| 504 | + ecrire_meta('message_alertes_auteurs', serialize($a)); |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + if ( |
|
| 509 | + isset($GLOBALS['meta']['plugin_erreur_activation']) |
|
| 510 | + and autoriser('configurer', '_plugins', null, $id_auteur) |
|
| 511 | + ) { |
|
| 512 | + include_spip('inc/plugin'); |
|
| 513 | + $alertes[] = plugin_donne_erreurs(); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + $alertes = pipeline( |
|
| 517 | + 'alertes_auteur', |
|
| 518 | + [ |
|
| 519 | + 'args' => [ |
|
| 520 | + 'id_auteur' => $id_auteur, |
|
| 521 | + 'exec' => _request('exec'), |
|
| 522 | + ], |
|
| 523 | + 'data' => $alertes |
|
| 524 | + ] |
|
| 525 | + ); |
|
| 526 | + |
|
| 527 | + if ($alertes = array_filter($alertes)) { |
|
| 528 | + return "<div class='wrap-messages-alertes'><div class='messages-alertes'>" . |
|
| 529 | + join(' | ', $alertes) |
|
| 530 | + . '</div></div>'; |
|
| 531 | + } |
|
| 532 | + |
|
| 533 | + return ''; |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | /** |
@@ -540,9 +540,9 @@ discard block |
||
| 540 | 540 | * @return string |
| 541 | 541 | */ |
| 542 | 542 | function filtre_afficher_enfant_rub_dist($id_rubrique) { |
| 543 | - include_spip('inc/presenter_enfants'); |
|
| 543 | + include_spip('inc/presenter_enfants'); |
|
| 544 | 544 | |
| 545 | - return afficher_enfant_rub(intval($id_rubrique)); |
|
| 545 | + return afficher_enfant_rub(intval($id_rubrique)); |
|
| 546 | 546 | } |
| 547 | 547 | |
| 548 | 548 | /** |
@@ -560,15 +560,15 @@ discard block |
||
| 560 | 560 | * @return string |
| 561 | 561 | */ |
| 562 | 562 | function afficher_plus_info($lien, $titre = '+', $titre_lien = '') { |
| 563 | - $titre = attribut_html($titre); |
|
| 564 | - $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 565 | - http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 566 | - |
|
| 567 | - if (!$titre_lien) { |
|
| 568 | - return $icone; |
|
| 569 | - } else { |
|
| 570 | - return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 571 | - } |
|
| 563 | + $titre = attribut_html($titre); |
|
| 564 | + $icone = "\n<a href='$lien' title='$titre' class='plus_info'>" . |
|
| 565 | + http_img_pack('information-16.png', $titre) . '</a>'; |
|
| 566 | + |
|
| 567 | + if (!$titre_lien) { |
|
| 568 | + return $icone; |
|
| 569 | + } else { |
|
| 570 | + return $icone . "\n<a href='$lien'>$titre_lien</a>"; |
|
| 571 | + } |
|
| 572 | 572 | } |
| 573 | 573 | |
| 574 | 574 | |
@@ -587,17 +587,17 @@ discard block |
||
| 587 | 587 | * @return array |
| 588 | 588 | */ |
| 589 | 589 | function lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien) { |
| 590 | - $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 591 | - if (!(is_countable($res) ? count($res) : 0)) { |
|
| 592 | - return []; |
|
| 593 | - } |
|
| 594 | - $r = reset($res); |
|
| 595 | - if (isset($r['rang_lien'])) { |
|
| 596 | - $l = array_column($res, 'rang_lien', $objet_source); |
|
| 597 | - asort($l); |
|
| 598 | - $l = array_keys($l); |
|
| 599 | - } else { |
|
| 600 | - $l = array_column($res, $objet_source); |
|
| 601 | - } |
|
| 602 | - return $l; |
|
| 590 | + $res = lister_objets_liens($objet_source, $objet, $id_objet, $objet_lien); |
|
| 591 | + if (!(is_countable($res) ? count($res) : 0)) { |
|
| 592 | + return []; |
|
| 593 | + } |
|
| 594 | + $r = reset($res); |
|
| 595 | + if (isset($r['rang_lien'])) { |
|
| 596 | + $l = array_column($res, 'rang_lien', $objet_source); |
|
| 597 | + asort($l); |
|
| 598 | + $l = array_keys($l); |
|
| 599 | + } else { |
|
| 600 | + $l = array_column($res, $objet_source); |
|
| 601 | + } |
|
| 602 | + return $l; |
|
| 603 | 603 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @package SPIP\Core\Drapeaux\Edition |
| 31 | 31 | **/ |
| 32 | 32 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 33 | - return; |
|
| 33 | + return; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -45,46 +45,46 @@ discard block |
||
| 45 | 45 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 46 | 46 | **/ |
| 47 | 47 | function lire_tableau_edition() { |
| 48 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | - if (!$edition) { |
|
| 50 | - return []; |
|
| 51 | - } |
|
| 52 | - $changed = false; |
|
| 48 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | + if (!$edition) { |
|
| 50 | + return []; |
|
| 51 | + } |
|
| 52 | + $changed = false; |
|
| 53 | 53 | |
| 54 | - $bon_pour_le_service = time() - 3600; |
|
| 55 | - // parcourir le tableau et virer les vieux |
|
| 56 | - foreach ($edition as $objet => $data) { |
|
| 57 | - if (!is_array($data)) { |
|
| 58 | - unset($edition[$objet]); |
|
| 59 | - } // vieille version |
|
| 60 | - else { |
|
| 61 | - foreach ($data as $id => $tab) { |
|
| 62 | - if (!is_array($tab)) { |
|
| 63 | - unset($edition[$objet][$tab]); |
|
| 64 | - } // vieille version |
|
| 65 | - else { |
|
| 66 | - foreach ($tab as $n => $duo) { |
|
| 67 | - if (current($duo) < $bon_pour_le_service) { |
|
| 68 | - unset($edition[$objet][$id][$n]); |
|
| 69 | - $changed = true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - if (!$edition[$objet][$id]) { |
|
| 74 | - unset($edition[$objet][$id]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!$edition[$objet]) { |
|
| 79 | - unset($edition[$objet]); |
|
| 80 | - } |
|
| 81 | - } |
|
| 54 | + $bon_pour_le_service = time() - 3600; |
|
| 55 | + // parcourir le tableau et virer les vieux |
|
| 56 | + foreach ($edition as $objet => $data) { |
|
| 57 | + if (!is_array($data)) { |
|
| 58 | + unset($edition[$objet]); |
|
| 59 | + } // vieille version |
|
| 60 | + else { |
|
| 61 | + foreach ($data as $id => $tab) { |
|
| 62 | + if (!is_array($tab)) { |
|
| 63 | + unset($edition[$objet][$tab]); |
|
| 64 | + } // vieille version |
|
| 65 | + else { |
|
| 66 | + foreach ($tab as $n => $duo) { |
|
| 67 | + if (current($duo) < $bon_pour_le_service) { |
|
| 68 | + unset($edition[$objet][$id][$n]); |
|
| 69 | + $changed = true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + if (!$edition[$objet][$id]) { |
|
| 74 | + unset($edition[$objet][$id]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!$edition[$objet]) { |
|
| 79 | + unset($edition[$objet]); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - if ($changed) { |
|
| 84 | - ecrire_tableau_edition($edition); |
|
| 85 | - } |
|
| 83 | + if ($changed) { |
|
| 84 | + ecrire_tableau_edition($edition); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - return $edition; |
|
| 87 | + return $edition; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 98 | 98 | **/ |
| 99 | 99 | function ecrire_tableau_edition($edition) { |
| 100 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -117,24 +117,24 @@ discard block |
||
| 117 | 117 | * Type d'objet édité |
| 118 | 118 | */ |
| 119 | 119 | function signale_edition($id, $auteur, $type = 'article') { |
| 120 | - include_spip('base/objets'); |
|
| 121 | - include_spip('inc/filtres'); |
|
| 122 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | - return; |
|
| 124 | - } |
|
| 120 | + include_spip('base/objets'); |
|
| 121 | + include_spip('inc/filtres'); |
|
| 122 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $edition = lire_tableau_edition(); |
|
| 127 | - if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur']) { |
|
| 128 | - $nom = $auteur['nom']; |
|
| 129 | - } else { |
|
| 130 | - $nom = $id_a = $GLOBALS['ip']; |
|
| 131 | - } |
|
| 126 | + $edition = lire_tableau_edition(); |
|
| 127 | + if (isset($auteur['id_auteur']) and $id_a = $auteur['id_auteur']) { |
|
| 128 | + $nom = $auteur['nom']; |
|
| 129 | + } else { |
|
| 130 | + $nom = $id_a = $GLOBALS['ip']; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 134 | - $edition[$type][$id] = []; |
|
| 135 | - } |
|
| 136 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 137 | - ecrire_tableau_edition($edition); |
|
| 133 | + if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 134 | + $edition[$type][$id] = []; |
|
| 135 | + } |
|
| 136 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 137 | + ecrire_tableau_edition($edition); |
|
| 138 | 138 | } |
| 139 | 139 | |
| 140 | 140 | /** |
@@ -151,9 +151,9 @@ discard block |
||
| 151 | 151 | */ |
| 152 | 152 | function qui_edite($id, $type = 'article') { |
| 153 | 153 | |
| 154 | - $edition = lire_tableau_edition(); |
|
| 154 | + $edition = lire_tableau_edition(); |
|
| 155 | 155 | |
| 156 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 156 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -167,23 +167,23 @@ discard block |
||
| 167 | 167 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 168 | 168 | */ |
| 169 | 169 | function mention_qui_edite($id, $type = 'article'): array { |
| 170 | - $modif = qui_edite($id, $type); |
|
| 171 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 170 | + $modif = qui_edite($id, $type); |
|
| 171 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 172 | 172 | |
| 173 | - if ($modif) { |
|
| 174 | - $quand = 0; |
|
| 175 | - foreach ($modif as $duo) { |
|
| 176 | - $auteurs[] = typo(key($duo)); |
|
| 177 | - $quand = max($quand, current($duo)); |
|
| 178 | - } |
|
| 173 | + if ($modif) { |
|
| 174 | + $quand = 0; |
|
| 175 | + foreach ($modif as $duo) { |
|
| 176 | + $auteurs[] = typo(key($duo)); |
|
| 177 | + $quand = max($quand, current($duo)); |
|
| 178 | + } |
|
| 179 | 179 | |
| 180 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 181 | - return [ |
|
| 182 | - 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 183 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 184 | - ]; |
|
| 185 | - } |
|
| 186 | - return []; |
|
| 180 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 181 | + return [ |
|
| 182 | + 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 183 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 184 | + ]; |
|
| 185 | + } |
|
| 186 | + return []; |
|
| 187 | 187 | } |
| 188 | 188 | |
| 189 | 189 | /** |
@@ -197,25 +197,25 @@ discard block |
||
| 197 | 197 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 198 | 198 | */ |
| 199 | 199 | function liste_drapeau_edition($id_auteur) { |
| 200 | - $edition = lire_tableau_edition(); |
|
| 201 | - $objets_ouverts = []; |
|
| 200 | + $edition = lire_tableau_edition(); |
|
| 201 | + $objets_ouverts = []; |
|
| 202 | 202 | |
| 203 | - foreach ($edition as $objet => $data) { |
|
| 204 | - foreach ($data as $id => $auteurs) { |
|
| 205 | - if ( |
|
| 206 | - isset($auteurs[$id_auteur]) |
|
| 207 | - and is_array($auteurs[$id_auteur]) // precaution |
|
| 208 | - and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 209 | - ) { |
|
| 210 | - $objets_ouverts[] = [ |
|
| 211 | - 'objet' => $objet, |
|
| 212 | - 'id_objet' => $id, |
|
| 213 | - ]; |
|
| 214 | - } |
|
| 215 | - } |
|
| 216 | - } |
|
| 203 | + foreach ($edition as $objet => $data) { |
|
| 204 | + foreach ($data as $id => $auteurs) { |
|
| 205 | + if ( |
|
| 206 | + isset($auteurs[$id_auteur]) |
|
| 207 | + and is_array($auteurs[$id_auteur]) // precaution |
|
| 208 | + and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 209 | + ) { |
|
| 210 | + $objets_ouverts[] = [ |
|
| 211 | + 'objet' => $objet, |
|
| 212 | + 'id_objet' => $id, |
|
| 213 | + ]; |
|
| 214 | + } |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - return $objets_ouverts; |
|
| 218 | + return $objets_ouverts; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -228,15 +228,15 @@ discard block |
||
| 228 | 228 | * @return void |
| 229 | 229 | */ |
| 230 | 230 | function debloquer_tous($id_auteur) { |
| 231 | - $edition = lire_tableau_edition(); |
|
| 232 | - foreach ($edition as $objet => $data) { |
|
| 233 | - foreach ($data as $id => $auteurs) { |
|
| 234 | - if (isset($auteurs[$id_auteur])) { |
|
| 235 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 236 | - ecrire_tableau_edition($edition); |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 231 | + $edition = lire_tableau_edition(); |
|
| 232 | + foreach ($edition as $objet => $data) { |
|
| 233 | + foreach ($data as $id => $auteurs) { |
|
| 234 | + if (isset($auteurs[$id_auteur])) { |
|
| 235 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 236 | + ecrire_tableau_edition($edition); |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -254,19 +254,19 @@ discard block |
||
| 254 | 254 | * @return void |
| 255 | 255 | */ |
| 256 | 256 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 257 | - $edition = lire_tableau_edition(); |
|
| 257 | + $edition = lire_tableau_edition(); |
|
| 258 | 258 | |
| 259 | - foreach ($edition as $objet => $data) { |
|
| 260 | - if ($objet == $type) { |
|
| 261 | - foreach ($data as $id => $auteurs) { |
|
| 262 | - if ( |
|
| 263 | - $id == $id_objet |
|
| 264 | - and isset($auteurs[$id_auteur]) |
|
| 265 | - ) { |
|
| 266 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 267 | - ecrire_tableau_edition($edition); |
|
| 268 | - } |
|
| 269 | - } |
|
| 270 | - } |
|
| 271 | - } |
|
| 259 | + foreach ($edition as $objet => $data) { |
|
| 260 | + if ($objet == $type) { |
|
| 261 | + foreach ($data as $id => $auteurs) { |
|
| 262 | + if ( |
|
| 263 | + $id == $id_objet |
|
| 264 | + and isset($auteurs[$id_auteur]) |
|
| 265 | + ) { |
|
| 266 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 267 | + ecrire_tableau_edition($edition); |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/boutons'); |
@@ -37,33 +37,33 @@ discard block |
||
| 37 | 37 | * Contexte |
| 38 | 38 | **/ |
| 39 | 39 | function definir_barre_contexte($contexte = null) { |
| 40 | - if (is_null($contexte)) { |
|
| 41 | - $contexte = $_GET; |
|
| 42 | - } elseif (is_string($contexte)) { |
|
| 43 | - $contexte = unserialize($contexte); |
|
| 44 | - } |
|
| 45 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | - if (!function_exists('trouver_objet_exec')) { |
|
| 47 | - include_spip('inc/pipelines_ecrire'); |
|
| 48 | - } |
|
| 49 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | - $_id = $e['id_table_objet']; |
|
| 51 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | - $table = $e['table_objet_sql']; |
|
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | - if (isset($row['id_rubrique'])) { |
|
| 55 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | - if (isset($row['id_secteur'])) { |
|
| 57 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | - } |
|
| 59 | - } elseif (isset($row['id_groupe'])) { |
|
| 60 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - return $contexte; |
|
| 40 | + if (is_null($contexte)) { |
|
| 41 | + $contexte = $_GET; |
|
| 42 | + } elseif (is_string($contexte)) { |
|
| 43 | + $contexte = unserialize($contexte); |
|
| 44 | + } |
|
| 45 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 46 | + if (!function_exists('trouver_objet_exec')) { |
|
| 47 | + include_spip('inc/pipelines_ecrire'); |
|
| 48 | + } |
|
| 49 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 50 | + $_id = $e['id_table_objet']; |
|
| 51 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 52 | + $table = $e['table_objet_sql']; |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 54 | + if (isset($row['id_rubrique'])) { |
|
| 55 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 56 | + if (isset($row['id_secteur'])) { |
|
| 57 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 58 | + } |
|
| 59 | + } elseif (isset($row['id_groupe'])) { |
|
| 60 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 61 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + return $contexte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -79,89 +79,89 @@ discard block |
||
| 79 | 79 | * @return array |
| 80 | 80 | */ |
| 81 | 81 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 82 | - include_spip('inc/autoriser'); |
|
| 83 | - $boutons_admin = []; |
|
| 82 | + include_spip('inc/autoriser'); |
|
| 83 | + $boutons_admin = []; |
|
| 84 | 84 | |
| 85 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | - $liste_boutons = []; |
|
| 85 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 86 | + $liste_boutons = []; |
|
| 87 | 87 | |
| 88 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | - if ( |
|
| 90 | - function_exists('boutons_plugins') |
|
| 91 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | - ) { |
|
| 93 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | - } |
|
| 88 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 89 | + if ( |
|
| 90 | + function_exists('boutons_plugins') |
|
| 91 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 92 | + ) { |
|
| 93 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - foreach ($liste_boutons as $id => $infos) { |
|
| 97 | - $parent = ''; |
|
| 98 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | - if ( |
|
| 100 | - !isset($infos['parent']) |
|
| 101 | - or !($parent = $infos['parent']) |
|
| 102 | - or !$autorise |
|
| 103 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | - ) { |
|
| 105 | - if ( |
|
| 106 | - $parent |
|
| 107 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | - and isset($boutons_admin[$parent]) |
|
| 109 | - ) { |
|
| 110 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | - if ($position < 0) { |
|
| 112 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | - } |
|
| 114 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | - + [ |
|
| 116 | - $id => new Bouton( |
|
| 117 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | - $infos['titre'], // titre |
|
| 119 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | - ) |
|
| 122 | - ] |
|
| 123 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | - } |
|
| 125 | - if ( |
|
| 126 | - !$parent |
|
| 127 | - // provisoire, eviter les vieux boutons |
|
| 128 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 129 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 130 | - ) { |
|
| 131 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 132 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 133 | - + [ |
|
| 134 | - $id => new Bouton( |
|
| 135 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | - $infos['titre'], // titre |
|
| 137 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 138 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 139 | - ) |
|
| 140 | - ] |
|
| 141 | - + array_slice($boutons_admin, $position, 100); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 96 | + foreach ($liste_boutons as $id => $infos) { |
|
| 97 | + $parent = ''; |
|
| 98 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 99 | + if ( |
|
| 100 | + !isset($infos['parent']) |
|
| 101 | + or !($parent = $infos['parent']) |
|
| 102 | + or !$autorise |
|
| 103 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 104 | + ) { |
|
| 105 | + if ( |
|
| 106 | + $parent |
|
| 107 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 108 | + and isset($boutons_admin[$parent]) |
|
| 109 | + ) { |
|
| 110 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 111 | + if ($position < 0) { |
|
| 112 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 113 | + } |
|
| 114 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 115 | + + [ |
|
| 116 | + $id => new Bouton( |
|
| 117 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | + $infos['titre'], // titre |
|
| 119 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 120 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 121 | + ) |
|
| 122 | + ] |
|
| 123 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 124 | + } |
|
| 125 | + if ( |
|
| 126 | + !$parent |
|
| 127 | + // provisoire, eviter les vieux boutons |
|
| 128 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 129 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 130 | + ) { |
|
| 131 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 132 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 133 | + + [ |
|
| 134 | + $id => new Bouton( |
|
| 135 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | + $infos['titre'], // titre |
|
| 137 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 138 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 139 | + ) |
|
| 140 | + ] |
|
| 141 | + + array_slice($boutons_admin, $position, 100); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 146 | 146 | |
| 147 | - // définir les favoris et positions d’origine |
|
| 148 | - if ($boutons_admin) { |
|
| 149 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 150 | - $i = 1; |
|
| 151 | - foreach ($boutons_admin as $key => $menu) { |
|
| 152 | - $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 153 | - $menu->position = $i++; |
|
| 154 | - if ($menu->sousmenu) { |
|
| 155 | - $j = 1; |
|
| 156 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 157 | - $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 158 | - $bouton->position = $j++; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - } |
|
| 147 | + // définir les favoris et positions d’origine |
|
| 148 | + if ($boutons_admin) { |
|
| 149 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 150 | + $i = 1; |
|
| 151 | + foreach ($boutons_admin as $key => $menu) { |
|
| 152 | + $menu->favori = table_valeur($menus_favoris, $key, false); |
|
| 153 | + $menu->position = $i++; |
|
| 154 | + if ($menu->sousmenu) { |
|
| 155 | + $j = 1; |
|
| 156 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 157 | + $bouton->favori = table_valeur($menus_favoris, $key, false); |
|
| 158 | + $bouton->position = $j++; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | 163 | |
| 164 | - return $boutons_admin; |
|
| 164 | + return $boutons_admin; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return Bouton[] |
| 174 | 174 | */ |
| 175 | 175 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 176 | - foreach ($menus as $menu) { |
|
| 177 | - if ($menu->sousmenu) { |
|
| 178 | - $libelles = $isfavoris = $favoris = []; |
|
| 179 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 180 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 181 | - $isfavoris[$key] = (bool)$item->favori; |
|
| 182 | - $favoris[$key] = $item->favori; |
|
| 183 | - } |
|
| 184 | - if ($avec_favoris) { |
|
| 185 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 186 | - } else { |
|
| 187 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - return $menus; |
|
| 176 | + foreach ($menus as $menu) { |
|
| 177 | + if ($menu->sousmenu) { |
|
| 178 | + $libelles = $isfavoris = $favoris = []; |
|
| 179 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 180 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 181 | + $isfavoris[$key] = (bool)$item->favori; |
|
| 182 | + $favoris[$key] = $item->favori; |
|
| 183 | + } |
|
| 184 | + if ($avec_favoris) { |
|
| 185 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 186 | + } else { |
|
| 187 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + return $menus; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -199,7 +199,7 @@ discard block |
||
| 199 | 199 | * @return Bouton[] |
| 200 | 200 | */ |
| 201 | 201 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 202 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 202 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
@@ -212,23 +212,23 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 215 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 216 | - $url = generer_url_ecrire($url, $args, true); |
|
| 217 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 218 | - // &truc=@machin@ |
|
| 219 | - // @machin@ etant remplace par _request('machin') |
|
| 220 | - $url = str_replace('&', '&', $url); |
|
| 221 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 222 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 223 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 224 | - } |
|
| 225 | - $val = _request($matches[2], $contexte); |
|
| 226 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 227 | - } |
|
| 228 | - $url = str_replace('&', '&', $url); |
|
| 229 | - } |
|
| 215 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 216 | + $url = generer_url_ecrire($url, $args, true); |
|
| 217 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 218 | + // &truc=@machin@ |
|
| 219 | + // @machin@ etant remplace par _request('machin') |
|
| 220 | + $url = str_replace('&', '&', $url); |
|
| 221 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 222 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 223 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 224 | + } |
|
| 225 | + $val = _request($matches[2], $contexte); |
|
| 226 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 227 | + } |
|
| 228 | + $url = str_replace('&', '&', $url); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - return $url; |
|
| 231 | + return $url; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | /** |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | * Code HTML du bandeau |
| 239 | 239 | */ |
| 240 | 240 | function inc_bandeau_dist() { |
| 241 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 241 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | |
@@ -247,13 +247,13 @@ discard block |
||
| 247 | 247 | * @return array |
| 248 | 248 | */ |
| 249 | 249 | function obtenir_menus_favoris() { |
| 250 | - if ( |
|
| 251 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 254 | - ) { |
|
| 255 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 256 | - } |
|
| 257 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 258 | - return $definir_menus_favoris(); |
|
| 250 | + if ( |
|
| 251 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 252 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 253 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 254 | + ) { |
|
| 255 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 256 | + } |
|
| 257 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 258 | + return $definir_menus_favoris(); |
|
| 259 | 259 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - // fonction ou name\space\fonction |
|
| 102 | - if (is_callable($f)) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | - elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | - return $f; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + // fonction ou name\space\fonction |
|
| 102 | + if (is_callable($f)) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | + elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | + return $f; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $default; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Chaîne vide sinon. |
| 153 | 153 | **/ |
| 154 | 154 | function appliquer_filtre($arg, $filtre) { |
| 155 | - $args = func_get_args(); |
|
| 156 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 155 | + $args = func_get_args(); |
|
| 156 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * Texte d'origine sinon |
| 179 | 179 | **/ |
| 180 | 180 | function appliquer_si_filtre($arg, $filtre) { |
| 181 | - $args = func_get_args(); |
|
| 182 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 181 | + $args = func_get_args(); |
|
| 182 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * Version de SPIP |
| 196 | 196 | **/ |
| 197 | 197 | function spip_version() { |
| 198 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | - $version .= " $vcs_version"; |
|
| 201 | - } |
|
| 198 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | + $version .= " $vcs_version"; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $version; |
|
| 203 | + return $version; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,11 +212,11 @@ discard block |
||
| 212 | 212 | * @return string |
| 213 | 213 | */ |
| 214 | 214 | function header_silencieux($version): string { |
| 215 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | - $version = ''; |
|
| 217 | - } |
|
| 215 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 216 | + $version = ''; |
|
| 217 | + } |
|
| 218 | 218 | |
| 219 | - return (string) $version; |
|
| 219 | + return (string) $version; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -229,19 +229,19 @@ discard block |
||
| 229 | 229 | * - string|null si $raw = false |
| 230 | 230 | */ |
| 231 | 231 | function version_vcs_courante($dir, $raw = false) { |
| 232 | - $desc = decrire_version_git($dir); |
|
| 233 | - if ($desc === null) { |
|
| 234 | - $desc = decrire_version_svn($dir); |
|
| 235 | - } |
|
| 236 | - if ($desc === null or $raw) { |
|
| 237 | - return $desc; |
|
| 238 | - } |
|
| 239 | - // affichage "GIT [master: abcdef]" |
|
| 240 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | - if ($desc['branch']) { |
|
| 242 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | - } |
|
| 244 | - return "{$desc['vcs']} [$commit]"; |
|
| 232 | + $desc = decrire_version_git($dir); |
|
| 233 | + if ($desc === null) { |
|
| 234 | + $desc = decrire_version_svn($dir); |
|
| 235 | + } |
|
| 236 | + if ($desc === null or $raw) { |
|
| 237 | + return $desc; |
|
| 238 | + } |
|
| 239 | + // affichage "GIT [master: abcdef]" |
|
| 240 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 241 | + if ($desc['branch']) { |
|
| 242 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 243 | + } |
|
| 244 | + return "{$desc['vcs']} [$commit]"; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -253,24 +253,24 @@ discard block |
||
| 253 | 253 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 254 | 254 | **/ |
| 255 | 255 | function decrire_version_git($dir) { |
| 256 | - if (!$dir) { |
|
| 257 | - $dir = '.'; |
|
| 258 | - } |
|
| 256 | + if (!$dir) { |
|
| 257 | + $dir = '.'; |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - // version installee par GIT |
|
| 261 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | - $currentHead = trim(substr($c, 4)); |
|
| 263 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | - return [ |
|
| 265 | - 'vcs' => 'GIT', |
|
| 266 | - 'branch' => basename($currentHead), |
|
| 267 | - 'commit' => trim($hash), |
|
| 268 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | - ]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 260 | + // version installee par GIT |
|
| 261 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 262 | + $currentHead = trim(substr($c, 4)); |
|
| 263 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 264 | + return [ |
|
| 265 | + 'vcs' => 'GIT', |
|
| 266 | + 'branch' => basename($currentHead), |
|
| 267 | + 'commit' => trim($hash), |
|
| 268 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 269 | + ]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | 272 | |
| 273 | - return null; |
|
| 273 | + return null; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -283,25 +283,25 @@ discard block |
||
| 283 | 283 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 284 | 284 | **/ |
| 285 | 285 | function decrire_version_svn($dir) { |
| 286 | - if (!$dir) { |
|
| 287 | - $dir = '.'; |
|
| 288 | - } |
|
| 289 | - // version installee par SVN |
|
| 290 | - if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | - if ($result) { |
|
| 294 | - $row = $result->fetchArray(); |
|
| 295 | - if ($row['changed_revision'] != '') { |
|
| 296 | - return [ |
|
| 297 | - 'vcs' => 'SVN', |
|
| 298 | - 'branch' => '', |
|
| 299 | - 'commit' => $row['changed_revision'], |
|
| 300 | - ]; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - return null; |
|
| 286 | + if (!$dir) { |
|
| 287 | + $dir = '.'; |
|
| 288 | + } |
|
| 289 | + // version installee par SVN |
|
| 290 | + if (file_exists($dir . '/.svn/wc.db') && class_exists(\SQLite3::class)) { |
|
| 291 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 292 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 293 | + if ($result) { |
|
| 294 | + $row = $result->fetchArray(); |
|
| 295 | + if ($row['changed_revision'] != '') { |
|
| 296 | + return [ |
|
| 297 | + 'vcs' => 'SVN', |
|
| 298 | + 'branch' => '', |
|
| 299 | + 'commit' => $row['changed_revision'], |
|
| 300 | + ]; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + return null; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | * Code HTML retourné par le filtre |
| 349 | 349 | **/ |
| 350 | 350 | function filtrer($filtre) { |
| 351 | - $tous = func_get_args(); |
|
| 352 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | - return image_filtrer($tous); |
|
| 354 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | - array_shift($tous); |
|
| 356 | - return $f(...$tous); |
|
| 357 | - } else { |
|
| 358 | - // le filtre n'existe pas, on provoque une erreur |
|
| 359 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | - erreur_squelette($msg); |
|
| 361 | - return ''; |
|
| 362 | - } |
|
| 351 | + $tous = func_get_args(); |
|
| 352 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 353 | + return image_filtrer($tous); |
|
| 354 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 355 | + array_shift($tous); |
|
| 356 | + return $f(...$tous); |
|
| 357 | + } else { |
|
| 358 | + // le filtre n'existe pas, on provoque une erreur |
|
| 359 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 360 | + erreur_squelette($msg); |
|
| 361 | + return ''; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 377 | 377 | */ |
| 378 | 378 | function trouver_filtre_matrice($filtre) { |
| 379 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | - find_in_path($f, '', true); |
|
| 381 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | - } |
|
| 383 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 379 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 380 | + find_in_path($f, '', true); |
|
| 381 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 382 | + } |
|
| 383 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -408,8 +408,8 @@ discard block |
||
| 408 | 408 | * @return mixed |
| 409 | 409 | */ |
| 410 | 410 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 411 | - $Pile['vars'][$key] = $val; |
|
| 412 | - return $continue ? $val : ''; |
|
| 411 | + $Pile['vars'][$key] = $val; |
|
| 412 | + return $continue ? $val : ''; |
|
| 413 | 413 | } |
| 414 | 414 | |
| 415 | 415 | /** |
@@ -435,8 +435,8 @@ discard block |
||
| 435 | 435 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 436 | 436 | */ |
| 437 | 437 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 438 | - $Pile[0][$key] = $val; |
|
| 439 | - return $continue ? $val : ''; |
|
| 438 | + $Pile[0][$key] = $val; |
|
| 439 | + return $continue ? $val : ''; |
|
| 440 | 440 | } |
| 441 | 441 | |
| 442 | 442 | /** |
@@ -445,8 +445,8 @@ discard block |
||
| 445 | 445 | * @return string |
| 446 | 446 | */ |
| 447 | 447 | function filtre_sanitize_env(&$Pile, $keys) { |
| 448 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | - return ''; |
|
| 448 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | |
@@ -469,18 +469,18 @@ discard block |
||
| 469 | 469 | * @return mixed Retourne la valeur (sans la modifier). |
| 470 | 470 | */ |
| 471 | 471 | function filtre_debug($val, $key = null) { |
| 472 | - $debug = ( |
|
| 473 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | - ) . var_export($val, true); |
|
| 472 | + $debug = ( |
|
| 473 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 474 | + ) . var_export($val, true); |
|
| 475 | 475 | |
| 476 | - include_spip('inc/autoriser'); |
|
| 477 | - if (autoriser('webmestre')) { |
|
| 478 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | - } |
|
| 476 | + include_spip('inc/autoriser'); |
|
| 477 | + if (autoriser('webmestre')) { |
|
| 478 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 479 | + } |
|
| 480 | 480 | |
| 481 | - spip_log($debug, 'debug'); |
|
| 481 | + spip_log($debug, 'debug'); |
|
| 482 | 482 | |
| 483 | - return $val; |
|
| 483 | + return $val; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -510,84 +510,84 @@ discard block |
||
| 510 | 510 | * Texte qui a reçu les filtres |
| 511 | 511 | **/ |
| 512 | 512 | function image_filtrer($args) { |
| 513 | - $filtre = array_shift($args); # enlever $filtre |
|
| 514 | - $texte = array_shift($args); |
|
| 515 | - if ($texte === null || !strlen($texte)) { |
|
| 516 | - return ''; |
|
| 517 | - } |
|
| 518 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 519 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 520 | - // Cas du nom de fichier local |
|
| 521 | - $is_file = trim($texte); |
|
| 522 | - if ( |
|
| 523 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 524 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 525 | - or strpos($is_file, '/') === 0 |
|
| 526 | - ) { |
|
| 527 | - $is_file = false; |
|
| 528 | - } |
|
| 529 | - if ($is_file) { |
|
| 530 | - $is_local_file = function ($path) { |
|
| 531 | - if (strpos($path, '?') !== false) { |
|
| 532 | - $path = supprimer_timestamp($path); |
|
| 533 | - // remove ?24px added by find_in_theme on .svg files |
|
| 534 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 535 | - } |
|
| 536 | - return file_exists($path); |
|
| 537 | - }; |
|
| 538 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 539 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 540 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 541 | - return $res; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 546 | - if ( |
|
| 547 | - preg_match_all( |
|
| 548 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 549 | - $texte, |
|
| 550 | - $tags, |
|
| 551 | - PREG_SET_ORDER |
|
| 552 | - ) |
|
| 553 | - ) { |
|
| 554 | - foreach ($tags as $tag) { |
|
| 555 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 556 | - if ( |
|
| 557 | - !$class or |
|
| 558 | - (strpos($class, 'filtre_inactif') === false |
|
| 559 | - // compat historique a virer en 3.2 |
|
| 560 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 561 | - ) { |
|
| 562 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 563 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | - if ($tag[1]) { |
|
| 565 | - $w = extraire_attribut($reduit, 'width'); |
|
| 566 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | - $w = $regs[1]; |
|
| 568 | - } |
|
| 569 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | - $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - // traiter aussi un eventuel mouseover |
|
| 576 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | - $srcover = $match[1]; |
|
| 579 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 580 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 581 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 585 | - } |
|
| 586 | - } |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 590 | - return $texte; |
|
| 513 | + $filtre = array_shift($args); # enlever $filtre |
|
| 514 | + $texte = array_shift($args); |
|
| 515 | + if ($texte === null || !strlen($texte)) { |
|
| 516 | + return ''; |
|
| 517 | + } |
|
| 518 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 519 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 520 | + // Cas du nom de fichier local |
|
| 521 | + $is_file = trim($texte); |
|
| 522 | + if ( |
|
| 523 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 524 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 525 | + or strpos($is_file, '/') === 0 |
|
| 526 | + ) { |
|
| 527 | + $is_file = false; |
|
| 528 | + } |
|
| 529 | + if ($is_file) { |
|
| 530 | + $is_local_file = function ($path) { |
|
| 531 | + if (strpos($path, '?') !== false) { |
|
| 532 | + $path = supprimer_timestamp($path); |
|
| 533 | + // remove ?24px added by find_in_theme on .svg files |
|
| 534 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 535 | + } |
|
| 536 | + return file_exists($path); |
|
| 537 | + }; |
|
| 538 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 539 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 540 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 541 | + return $res; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 546 | + if ( |
|
| 547 | + preg_match_all( |
|
| 548 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 549 | + $texte, |
|
| 550 | + $tags, |
|
| 551 | + PREG_SET_ORDER |
|
| 552 | + ) |
|
| 553 | + ) { |
|
| 554 | + foreach ($tags as $tag) { |
|
| 555 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 556 | + if ( |
|
| 557 | + !$class or |
|
| 558 | + (strpos($class, 'filtre_inactif') === false |
|
| 559 | + // compat historique a virer en 3.2 |
|
| 560 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 561 | + ) { |
|
| 562 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 563 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 564 | + if ($tag[1]) { |
|
| 565 | + $w = extraire_attribut($reduit, 'width'); |
|
| 566 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 567 | + $w = $regs[1]; |
|
| 568 | + } |
|
| 569 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 570 | + $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 571 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 572 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + // traiter aussi un eventuel mouseover |
|
| 576 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 577 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 578 | + $srcover = $match[1]; |
|
| 579 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 580 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 581 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 585 | + } |
|
| 586 | + } |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 590 | + return $texte; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -604,91 +604,91 @@ discard block |
||
| 604 | 604 | **/ |
| 605 | 605 | function infos_image($img, $force_refresh = false) { |
| 606 | 606 | |
| 607 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 608 | - $srcWidth = 0; |
|
| 609 | - $srcHeight = 0; |
|
| 610 | - $srcSize = null; |
|
| 611 | - |
|
| 612 | - $src = extraire_attribut($img, 'src'); |
|
| 613 | - |
|
| 614 | - if (!$src) { |
|
| 615 | - $src = $img; |
|
| 616 | - } else { |
|
| 617 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 618 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 622 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 623 | - if (tester_url_absolue($src)) { |
|
| 624 | - include_spip('inc/distant'); |
|
| 625 | - $fichier = copie_locale($src); |
|
| 626 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 627 | - } |
|
| 628 | - if (($p = strpos($src, '?')) !== false) { |
|
| 629 | - $src = substr($src, 0, $p); |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - $imagesize = false; |
|
| 633 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 634 | - $srcWidth = $largeur_img[$src]; |
|
| 635 | - } |
|
| 636 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 637 | - $srcHeight = $hauteur_img[$src]; |
|
| 638 | - } |
|
| 639 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 640 | - $srcSize = $poids_img[$src]; |
|
| 641 | - } |
|
| 642 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 643 | - if ( |
|
| 644 | - file_exists($src) |
|
| 645 | - and $imagesize = spip_getimagesize($src) |
|
| 646 | - ) { |
|
| 647 | - if (!$srcWidth) { |
|
| 648 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 649 | - } |
|
| 650 | - if (!$srcHeight) { |
|
| 651 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 652 | - } |
|
| 653 | - if (!$srcSize) { |
|
| 654 | - $poids_img[$src] = filesize($src); |
|
| 655 | - } |
|
| 656 | - } |
|
| 657 | - elseif (strpos($src, '<svg') !== false) { |
|
| 658 | - include_spip('inc/svg'); |
|
| 659 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 660 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 661 | - if (!$srcWidth) { |
|
| 662 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 663 | - } |
|
| 664 | - if (!$srcHeight) { |
|
| 665 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 666 | - } |
|
| 667 | - if (!$srcSize) { |
|
| 668 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 669 | - } |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 673 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 674 | - elseif ( |
|
| 675 | - @file_exists($f = "$src.src") |
|
| 676 | - and lire_fichier($f, $valeurs) |
|
| 677 | - and $valeurs = unserialize($valeurs) |
|
| 678 | - ) { |
|
| 679 | - if (!$srcWidth) { |
|
| 680 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 681 | - } |
|
| 682 | - if (!$srcHeight) { |
|
| 683 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 684 | - } |
|
| 685 | - if (!$srcSize) { |
|
| 686 | - $poids_img[$src] = $srcSize = 0; |
|
| 687 | - } |
|
| 688 | - } |
|
| 689 | - } |
|
| 690 | - |
|
| 691 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 607 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 608 | + $srcWidth = 0; |
|
| 609 | + $srcHeight = 0; |
|
| 610 | + $srcSize = null; |
|
| 611 | + |
|
| 612 | + $src = extraire_attribut($img, 'src'); |
|
| 613 | + |
|
| 614 | + if (!$src) { |
|
| 615 | + $src = $img; |
|
| 616 | + } else { |
|
| 617 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 618 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 622 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 623 | + if (tester_url_absolue($src)) { |
|
| 624 | + include_spip('inc/distant'); |
|
| 625 | + $fichier = copie_locale($src); |
|
| 626 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 627 | + } |
|
| 628 | + if (($p = strpos($src, '?')) !== false) { |
|
| 629 | + $src = substr($src, 0, $p); |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + $imagesize = false; |
|
| 633 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 634 | + $srcWidth = $largeur_img[$src]; |
|
| 635 | + } |
|
| 636 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 637 | + $srcHeight = $hauteur_img[$src]; |
|
| 638 | + } |
|
| 639 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 640 | + $srcSize = $poids_img[$src]; |
|
| 641 | + } |
|
| 642 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 643 | + if ( |
|
| 644 | + file_exists($src) |
|
| 645 | + and $imagesize = spip_getimagesize($src) |
|
| 646 | + ) { |
|
| 647 | + if (!$srcWidth) { |
|
| 648 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 649 | + } |
|
| 650 | + if (!$srcHeight) { |
|
| 651 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 652 | + } |
|
| 653 | + if (!$srcSize) { |
|
| 654 | + $poids_img[$src] = filesize($src); |
|
| 655 | + } |
|
| 656 | + } |
|
| 657 | + elseif (strpos($src, '<svg') !== false) { |
|
| 658 | + include_spip('inc/svg'); |
|
| 659 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 660 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 661 | + if (!$srcWidth) { |
|
| 662 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 663 | + } |
|
| 664 | + if (!$srcHeight) { |
|
| 665 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 666 | + } |
|
| 667 | + if (!$srcSize) { |
|
| 668 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 669 | + } |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 673 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 674 | + elseif ( |
|
| 675 | + @file_exists($f = "$src.src") |
|
| 676 | + and lire_fichier($f, $valeurs) |
|
| 677 | + and $valeurs = unserialize($valeurs) |
|
| 678 | + ) { |
|
| 679 | + if (!$srcWidth) { |
|
| 680 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 681 | + } |
|
| 682 | + if (!$srcHeight) { |
|
| 683 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 684 | + } |
|
| 685 | + if (!$srcSize) { |
|
| 686 | + $poids_img[$src] = $srcSize = 0; |
|
| 687 | + } |
|
| 688 | + } |
|
| 689 | + } |
|
| 690 | + |
|
| 691 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 692 | 692 | } |
| 693 | 693 | |
| 694 | 694 | /** |
@@ -704,13 +704,13 @@ discard block |
||
| 704 | 704 | * poids |
| 705 | 705 | **/ |
| 706 | 706 | function poids_image($img, $force_refresh = false) { |
| 707 | - $infos = infos_image($img, $force_refresh); |
|
| 708 | - return $infos['poids']; |
|
| 707 | + $infos = infos_image($img, $force_refresh); |
|
| 708 | + return $infos['poids']; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | function taille_image($img, $force_refresh = false) { |
| 712 | - $infos = infos_image($img, $force_refresh); |
|
| 713 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 712 | + $infos = infos_image($img, $force_refresh); |
|
| 713 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 714 | 714 | } |
| 715 | 715 | |
| 716 | 716 | /** |
@@ -727,12 +727,12 @@ discard block |
||
| 727 | 727 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 728 | 728 | **/ |
| 729 | 729 | function largeur($img) { |
| 730 | - if (!$img) { |
|
| 731 | - return; |
|
| 732 | - } |
|
| 733 | - [$h, $l] = taille_image($img); |
|
| 730 | + if (!$img) { |
|
| 731 | + return; |
|
| 732 | + } |
|
| 733 | + [$h, $l] = taille_image($img); |
|
| 734 | 734 | |
| 735 | - return $l; |
|
| 735 | + return $l; |
|
| 736 | 736 | } |
| 737 | 737 | |
| 738 | 738 | /** |
@@ -749,12 +749,12 @@ discard block |
||
| 749 | 749 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 750 | 750 | **/ |
| 751 | 751 | function hauteur($img) { |
| 752 | - if (!$img) { |
|
| 753 | - return; |
|
| 754 | - } |
|
| 755 | - [$h, $l] = taille_image($img); |
|
| 752 | + if (!$img) { |
|
| 753 | + return; |
|
| 754 | + } |
|
| 755 | + [$h, $l] = taille_image($img); |
|
| 756 | 756 | |
| 757 | - return $h; |
|
| 757 | + return $h; |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | |
@@ -774,11 +774,11 @@ discard block |
||
| 774 | 774 | * @return string |
| 775 | 775 | **/ |
| 776 | 776 | function corriger_entites_html($texte) { |
| 777 | - if (strpos($texte, '&') === false) { |
|
| 778 | - return $texte; |
|
| 779 | - } |
|
| 777 | + if (strpos($texte, '&') === false) { |
|
| 778 | + return $texte; |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 781 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 782 | 782 | } |
| 783 | 783 | |
| 784 | 784 | /** |
@@ -793,11 +793,11 @@ discard block |
||
| 793 | 793 | * @return string |
| 794 | 794 | **/ |
| 795 | 795 | function corriger_toutes_entites_html($texte) { |
| 796 | - if (strpos($texte, '&') === false) { |
|
| 797 | - return $texte; |
|
| 798 | - } |
|
| 796 | + if (strpos($texte, '&') === false) { |
|
| 797 | + return $texte; |
|
| 798 | + } |
|
| 799 | 799 | |
| 800 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 800 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 801 | 801 | } |
| 802 | 802 | |
| 803 | 803 | /** |
@@ -807,7 +807,7 @@ discard block |
||
| 807 | 807 | * @return string |
| 808 | 808 | **/ |
| 809 | 809 | function proteger_amp($texte) { |
| 810 | - return str_replace('&', '&', $texte); |
|
| 810 | + return str_replace('&', '&', $texte); |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
@@ -838,21 +838,21 @@ discard block |
||
| 838 | 838 | * @return mixed|string |
| 839 | 839 | */ |
| 840 | 840 | function entites_html($texte, $tout = false, $quote = true) { |
| 841 | - if ( |
|
| 842 | - !is_string($texte) or !$texte |
|
| 843 | - or strpbrk($texte, "&\"'<>") == false |
|
| 844 | - ) { |
|
| 845 | - return $texte; |
|
| 846 | - } |
|
| 847 | - include_spip('inc/texte'); |
|
| 848 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 849 | - $flags |= ENT_HTML401; |
|
| 850 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 851 | - if ($tout) { |
|
| 852 | - return corriger_toutes_entites_html($texte); |
|
| 853 | - } else { |
|
| 854 | - return corriger_entites_html($texte); |
|
| 855 | - } |
|
| 841 | + if ( |
|
| 842 | + !is_string($texte) or !$texte |
|
| 843 | + or strpbrk($texte, "&\"'<>") == false |
|
| 844 | + ) { |
|
| 845 | + return $texte; |
|
| 846 | + } |
|
| 847 | + include_spip('inc/texte'); |
|
| 848 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 849 | + $flags |= ENT_HTML401; |
|
| 850 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 851 | + if ($tout) { |
|
| 852 | + return corriger_toutes_entites_html($texte); |
|
| 853 | + } else { |
|
| 854 | + return corriger_entites_html($texte); |
|
| 855 | + } |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | /** |
@@ -871,37 +871,37 @@ discard block |
||
| 871 | 871 | * Texte converti |
| 872 | 872 | **/ |
| 873 | 873 | function filtrer_entites($texte) { |
| 874 | - if (strpos($texte, '&') === false) { |
|
| 875 | - return $texte; |
|
| 876 | - } |
|
| 877 | - // filtrer |
|
| 878 | - $texte = html2unicode($texte); |
|
| 879 | - // remettre le tout dans le charset cible |
|
| 880 | - $texte = unicode2charset($texte); |
|
| 881 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 882 | - // (on le faisait deja avec un ") |
|
| 883 | - if (strpos($texte, '&#') !== false) { |
|
| 884 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 885 | - } |
|
| 874 | + if (strpos($texte, '&') === false) { |
|
| 875 | + return $texte; |
|
| 876 | + } |
|
| 877 | + // filtrer |
|
| 878 | + $texte = html2unicode($texte); |
|
| 879 | + // remettre le tout dans le charset cible |
|
| 880 | + $texte = unicode2charset($texte); |
|
| 881 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 882 | + // (on le faisait deja avec un ") |
|
| 883 | + if (strpos($texte, '&#') !== false) { |
|
| 884 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 885 | + } |
|
| 886 | 886 | |
| 887 | - return $texte; |
|
| 887 | + return $texte; |
|
| 888 | 888 | } |
| 889 | 889 | |
| 890 | 890 | |
| 891 | 891 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 892 | - /** |
|
| 893 | - * Version sécurisée de filtrer_entites |
|
| 894 | - * |
|
| 895 | - * @uses interdire_scripts() |
|
| 896 | - * @uses filtrer_entites() |
|
| 897 | - * |
|
| 898 | - * @param string $t |
|
| 899 | - * @return string |
|
| 900 | - */ |
|
| 901 | - function filtre_filtrer_entites_dist($t) { |
|
| 902 | - include_spip('inc/texte'); |
|
| 903 | - return interdire_scripts(filtrer_entites($t)); |
|
| 904 | - } |
|
| 892 | + /** |
|
| 893 | + * Version sécurisée de filtrer_entites |
|
| 894 | + * |
|
| 895 | + * @uses interdire_scripts() |
|
| 896 | + * @uses filtrer_entites() |
|
| 897 | + * |
|
| 898 | + * @param string $t |
|
| 899 | + * @return string |
|
| 900 | + */ |
|
| 901 | + function filtre_filtrer_entites_dist($t) { |
|
| 902 | + include_spip('inc/texte'); |
|
| 903 | + return interdire_scripts(filtrer_entites($t)); |
|
| 904 | + } |
|
| 905 | 905 | } |
| 906 | 906 | |
| 907 | 907 | |
@@ -916,18 +916,18 @@ discard block |
||
| 916 | 916 | * @return string|array |
| 917 | 917 | **/ |
| 918 | 918 | function supprimer_caracteres_illegaux($texte) { |
| 919 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 920 | - static $to = null; |
|
| 919 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 920 | + static $to = null; |
|
| 921 | 921 | |
| 922 | - if (is_array($texte)) { |
|
| 923 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 924 | - } |
|
| 922 | + if (is_array($texte)) { |
|
| 923 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 924 | + } |
|
| 925 | 925 | |
| 926 | - if (!$to) { |
|
| 927 | - $to = str_repeat('-', strlen($from)); |
|
| 928 | - } |
|
| 926 | + if (!$to) { |
|
| 927 | + $to = str_repeat('-', strlen($from)); |
|
| 928 | + } |
|
| 929 | 929 | |
| 930 | - return strtr($texte, $from, $to); |
|
| 930 | + return strtr($texte, $from, $to); |
|
| 931 | 931 | } |
| 932 | 932 | |
| 933 | 933 | /** |
@@ -939,10 +939,10 @@ discard block |
||
| 939 | 939 | * @return string|array |
| 940 | 940 | **/ |
| 941 | 941 | function corriger_caracteres($texte) { |
| 942 | - $texte = corriger_caracteres_windows($texte); |
|
| 943 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 942 | + $texte = corriger_caracteres_windows($texte); |
|
| 943 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 944 | 944 | |
| 945 | - return $texte; |
|
| 945 | + return $texte; |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | /** |
@@ -959,44 +959,44 @@ discard block |
||
| 959 | 959 | * Texte encodé pour XML |
| 960 | 960 | */ |
| 961 | 961 | function texte_backend(string $texte): string { |
| 962 | - if ($texte === '') { |
|
| 963 | - return ''; |
|
| 964 | - } |
|
| 962 | + if ($texte === '') { |
|
| 963 | + return ''; |
|
| 964 | + } |
|
| 965 | 965 | |
| 966 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 966 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 967 | 967 | |
| 968 | - // si on a des liens ou des images, les passer en absolu |
|
| 969 | - $texte = liens_absolus($texte); |
|
| 968 | + // si on a des liens ou des images, les passer en absolu |
|
| 969 | + $texte = liens_absolus($texte); |
|
| 970 | 970 | |
| 971 | - // echapper les tags > < |
|
| 972 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 971 | + // echapper les tags > < |
|
| 972 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 973 | 973 | |
| 974 | - // importer les é |
|
| 975 | - $texte = filtrer_entites($texte); |
|
| 974 | + // importer les é |
|
| 975 | + $texte = filtrer_entites($texte); |
|
| 976 | 976 | |
| 977 | - // " -> " et tout ce genre de choses |
|
| 978 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 979 | - $texte = str_replace(' ', ' ', $texte); |
|
| 980 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 981 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 982 | - $texte = entites_html($texte, false, false); |
|
| 983 | - // mais bien echapper les double quotes ! |
|
| 984 | - $texte = str_replace('"', '"', $texte); |
|
| 977 | + // " -> " et tout ce genre de choses |
|
| 978 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 979 | + $texte = str_replace(' ', ' ', $texte); |
|
| 980 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 981 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 982 | + $texte = entites_html($texte, false, false); |
|
| 983 | + // mais bien echapper les double quotes ! |
|
| 984 | + $texte = str_replace('"', '"', $texte); |
|
| 985 | 985 | |
| 986 | - // verifier le charset |
|
| 987 | - $texte = charset2unicode($texte); |
|
| 986 | + // verifier le charset |
|
| 987 | + $texte = charset2unicode($texte); |
|
| 988 | 988 | |
| 989 | - // Caracteres problematiques en iso-latin 1 |
|
| 990 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 991 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 992 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 993 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 994 | - } |
|
| 989 | + // Caracteres problematiques en iso-latin 1 |
|
| 990 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 991 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 992 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 993 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 994 | + } |
|
| 995 | 995 | |
| 996 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 997 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 998 | - // ==> on les remplace par l'entite HTML |
|
| 999 | - return str_replace($apostrophe, "'", $texte); |
|
| 996 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 997 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 998 | + // ==> on les remplace par l'entite HTML |
|
| 999 | + return str_replace($apostrophe, "'", $texte); |
|
| 1000 | 1000 | } |
| 1001 | 1001 | |
| 1002 | 1002 | /** |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | * Texte encodé et quote pour XML |
| 1014 | 1014 | */ |
| 1015 | 1015 | function texte_backendq(string $texte): string { |
| 1016 | - return addslashes(texte_backend($texte)); |
|
| 1016 | + return addslashes(texte_backend($texte)); |
|
| 1017 | 1017 | } |
| 1018 | 1018 | |
| 1019 | 1019 | |
@@ -1036,11 +1036,11 @@ discard block |
||
| 1036 | 1036 | * Numéro de titre, sinon chaîne vide |
| 1037 | 1037 | **/ |
| 1038 | 1038 | function supprimer_numero($texte) { |
| 1039 | - return preg_replace( |
|
| 1040 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1041 | - '', |
|
| 1042 | - $texte |
|
| 1043 | - ); |
|
| 1039 | + return preg_replace( |
|
| 1040 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1041 | + '', |
|
| 1042 | + $texte |
|
| 1043 | + ); |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1063,17 +1063,17 @@ discard block |
||
| 1063 | 1063 | * Numéro de titre, sinon chaîne vide |
| 1064 | 1064 | **/ |
| 1065 | 1065 | function recuperer_numero($texte) { |
| 1066 | - if ( |
|
| 1067 | - preg_match( |
|
| 1068 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1069 | - $texte, |
|
| 1070 | - $regs |
|
| 1071 | - ) |
|
| 1072 | - ) { |
|
| 1073 | - return strval($regs[1]); |
|
| 1074 | - } else { |
|
| 1075 | - return ''; |
|
| 1076 | - } |
|
| 1066 | + if ( |
|
| 1067 | + preg_match( |
|
| 1068 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1069 | + $texte, |
|
| 1070 | + $regs |
|
| 1071 | + ) |
|
| 1072 | + ) { |
|
| 1073 | + return strval($regs[1]); |
|
| 1074 | + } else { |
|
| 1075 | + return ''; |
|
| 1076 | + } |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | /** |
@@ -1100,16 +1100,16 @@ discard block |
||
| 1100 | 1100 | * Texte ou tableau de textes converti |
| 1101 | 1101 | **/ |
| 1102 | 1102 | function supprimer_tags($texte, $rempl = '') { |
| 1103 | - if ($texte === null) { |
|
| 1104 | - return ''; |
|
| 1105 | - } |
|
| 1106 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1107 | - // ne pas oublier un < final non ferme car coupe |
|
| 1108 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1109 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1110 | - $texte = str_replace('<', '<', $texte); |
|
| 1103 | + if ($texte === null) { |
|
| 1104 | + return ''; |
|
| 1105 | + } |
|
| 1106 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1107 | + // ne pas oublier un < final non ferme car coupe |
|
| 1108 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1109 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1110 | + $texte = str_replace('<', '<', $texte); |
|
| 1111 | 1111 | |
| 1112 | - return $texte; |
|
| 1112 | + return $texte; |
|
| 1113 | 1113 | } |
| 1114 | 1114 | |
| 1115 | 1115 | /** |
@@ -1132,9 +1132,9 @@ discard block |
||
| 1132 | 1132 | * Texte converti |
| 1133 | 1133 | **/ |
| 1134 | 1134 | function echapper_tags($texte, $rempl = '') { |
| 1135 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1135 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1136 | 1136 | |
| 1137 | - return $texte; |
|
| 1137 | + return $texte; |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | /** |
@@ -1155,18 +1155,18 @@ discard block |
||
| 1155 | 1155 | * Texte converti |
| 1156 | 1156 | **/ |
| 1157 | 1157 | function textebrut($texte) { |
| 1158 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1159 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1160 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1161 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1162 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1163 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1164 | - $texte = supprimer_tags($texte); |
|
| 1165 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1166 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1167 | - $texte = str_replace('’', "'", $texte); |
|
| 1158 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1159 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1160 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1161 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1162 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1163 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1164 | + $texte = supprimer_tags($texte); |
|
| 1165 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1166 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1167 | + $texte = str_replace('’', "'", $texte); |
|
| 1168 | 1168 | |
| 1169 | - return $texte; |
|
| 1169 | + return $texte; |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | |
@@ -1182,23 +1182,23 @@ discard block |
||
| 1182 | 1182 | * Texte avec liens ouvrants |
| 1183 | 1183 | **/ |
| 1184 | 1184 | function liens_ouvrants($texte) { |
| 1185 | - if ( |
|
| 1186 | - preg_match_all( |
|
| 1187 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1188 | - $texte, |
|
| 1189 | - $liens, |
|
| 1190 | - PREG_PATTERN_ORDER |
|
| 1191 | - ) |
|
| 1192 | - ) { |
|
| 1193 | - foreach ($liens[0] as $a) { |
|
| 1194 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1195 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1196 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1197 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1198 | - } |
|
| 1199 | - } |
|
| 1200 | - |
|
| 1201 | - return $texte; |
|
| 1185 | + if ( |
|
| 1186 | + preg_match_all( |
|
| 1187 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1188 | + $texte, |
|
| 1189 | + $liens, |
|
| 1190 | + PREG_PATTERN_ORDER |
|
| 1191 | + ) |
|
| 1192 | + ) { |
|
| 1193 | + foreach ($liens[0] as $a) { |
|
| 1194 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1195 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1196 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1197 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1198 | + } |
|
| 1199 | + } |
|
| 1200 | + |
|
| 1201 | + return $texte; |
|
| 1202 | 1202 | } |
| 1203 | 1203 | |
| 1204 | 1204 | /** |
@@ -1208,22 +1208,22 @@ discard block |
||
| 1208 | 1208 | * @return string |
| 1209 | 1209 | */ |
| 1210 | 1210 | function liens_nofollow($texte) { |
| 1211 | - if (stripos($texte, '<a') === false) { |
|
| 1212 | - return $texte; |
|
| 1213 | - } |
|
| 1211 | + if (stripos($texte, '<a') === false) { |
|
| 1212 | + return $texte; |
|
| 1213 | + } |
|
| 1214 | 1214 | |
| 1215 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1216 | - foreach ($regs[0] as $a) { |
|
| 1217 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1218 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1219 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1220 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1221 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1222 | - } |
|
| 1223 | - } |
|
| 1224 | - } |
|
| 1215 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1216 | + foreach ($regs[0] as $a) { |
|
| 1217 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1218 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1219 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1220 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1221 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1222 | + } |
|
| 1223 | + } |
|
| 1224 | + } |
|
| 1225 | 1225 | |
| 1226 | - return $texte; |
|
| 1226 | + return $texte; |
|
| 1227 | 1227 | } |
| 1228 | 1228 | |
| 1229 | 1229 | /** |
@@ -1242,12 +1242,12 @@ discard block |
||
| 1242 | 1242 | * Texte sans paraghaphes |
| 1243 | 1243 | **/ |
| 1244 | 1244 | function PtoBR($texte) { |
| 1245 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1246 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1247 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1248 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1245 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1246 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1247 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1248 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1249 | 1249 | |
| 1250 | - return $texte; |
|
| 1250 | + return $texte; |
|
| 1251 | 1251 | } |
| 1252 | 1252 | |
| 1253 | 1253 | |
@@ -1272,14 +1272,14 @@ discard block |
||
| 1272 | 1272 | * @return string Texte encadré du style CSS |
| 1273 | 1273 | */ |
| 1274 | 1274 | function lignes_longues($texte) { |
| 1275 | - if (!strlen(trim($texte))) { |
|
| 1276 | - return $texte; |
|
| 1277 | - } |
|
| 1278 | - include_spip('inc/texte'); |
|
| 1279 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1280 | - 'div' : 'span'; |
|
| 1275 | + if (!strlen(trim($texte))) { |
|
| 1276 | + return $texte; |
|
| 1277 | + } |
|
| 1278 | + include_spip('inc/texte'); |
|
| 1279 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1280 | + 'div' : 'span'; |
|
| 1281 | 1281 | |
| 1282 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1282 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1283 | 1283 | } |
| 1284 | 1284 | |
| 1285 | 1285 | /** |
@@ -1298,30 +1298,30 @@ discard block |
||
| 1298 | 1298 | * @return string Texte en majuscule |
| 1299 | 1299 | */ |
| 1300 | 1300 | function majuscules($texte) { |
| 1301 | - if (!strlen($texte)) { |
|
| 1302 | - return ''; |
|
| 1303 | - } |
|
| 1301 | + if (!strlen($texte)) { |
|
| 1302 | + return ''; |
|
| 1303 | + } |
|
| 1304 | 1304 | |
| 1305 | - // Cas du turc |
|
| 1306 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1307 | - # remplacer hors des tags et des entites |
|
| 1308 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1309 | - foreach ($regs as $n => $match) { |
|
| 1310 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1311 | - } |
|
| 1312 | - } |
|
| 1305 | + // Cas du turc |
|
| 1306 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1307 | + # remplacer hors des tags et des entites |
|
| 1308 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1309 | + foreach ($regs as $n => $match) { |
|
| 1310 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1311 | + } |
|
| 1312 | + } |
|
| 1313 | 1313 | |
| 1314 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1314 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1315 | 1315 | |
| 1316 | - if ($regs) { |
|
| 1317 | - foreach ($regs as $n => $match) { |
|
| 1318 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1319 | - } |
|
| 1320 | - } |
|
| 1321 | - } |
|
| 1316 | + if ($regs) { |
|
| 1317 | + foreach ($regs as $n => $match) { |
|
| 1318 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1319 | + } |
|
| 1320 | + } |
|
| 1321 | + } |
|
| 1322 | 1322 | |
| 1323 | - // Cas general |
|
| 1324 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1323 | + // Cas general |
|
| 1324 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1325 | 1325 | } |
| 1326 | 1326 | |
| 1327 | 1327 | /** |
@@ -1339,29 +1339,29 @@ discard block |
||
| 1339 | 1339 | * @return string |
| 1340 | 1340 | **/ |
| 1341 | 1341 | function taille_en_octets($taille) { |
| 1342 | - if (!defined('_KILOBYTE')) { |
|
| 1343 | - /** |
|
| 1344 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1345 | - * |
|
| 1346 | - * @var int |
|
| 1347 | - **/ |
|
| 1348 | - define('_KILOBYTE', 1024); |
|
| 1349 | - } |
|
| 1342 | + if (!defined('_KILOBYTE')) { |
|
| 1343 | + /** |
|
| 1344 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1345 | + * |
|
| 1346 | + * @var int |
|
| 1347 | + **/ |
|
| 1348 | + define('_KILOBYTE', 1024); |
|
| 1349 | + } |
|
| 1350 | 1350 | |
| 1351 | - if ($taille < 1) { |
|
| 1352 | - return ''; |
|
| 1353 | - } |
|
| 1354 | - if ($taille < _KILOBYTE) { |
|
| 1355 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1356 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1357 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1358 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1359 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1360 | - } else { |
|
| 1361 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1362 | - } |
|
| 1351 | + if ($taille < 1) { |
|
| 1352 | + return ''; |
|
| 1353 | + } |
|
| 1354 | + if ($taille < _KILOBYTE) { |
|
| 1355 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1356 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1357 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1358 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1359 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1360 | + } else { |
|
| 1361 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1362 | + } |
|
| 1363 | 1363 | |
| 1364 | - return $taille; |
|
| 1364 | + return $taille; |
|
| 1365 | 1365 | } |
| 1366 | 1366 | |
| 1367 | 1367 | |
@@ -1383,21 +1383,21 @@ discard block |
||
| 1383 | 1383 | * Texte prêt pour être utilisé en attribut HTML |
| 1384 | 1384 | **/ |
| 1385 | 1385 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1386 | - if ($texte === null) { |
|
| 1387 | - return ''; |
|
| 1388 | - } |
|
| 1389 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1390 | - if ($textebrut) { |
|
| 1391 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1392 | - } |
|
| 1393 | - $texte = texte_backend($texte); |
|
| 1394 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1386 | + if ($texte === null) { |
|
| 1387 | + return ''; |
|
| 1388 | + } |
|
| 1389 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1390 | + if ($textebrut) { |
|
| 1391 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1392 | + } |
|
| 1393 | + $texte = texte_backend($texte); |
|
| 1394 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1395 | 1395 | |
| 1396 | - return preg_replace( |
|
| 1397 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1398 | - ['&', '&'], |
|
| 1399 | - $texte |
|
| 1400 | - ); |
|
| 1396 | + return preg_replace( |
|
| 1397 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1398 | + ['&', '&'], |
|
| 1399 | + $texte |
|
| 1400 | + ); |
|
| 1401 | 1401 | } |
| 1402 | 1402 | |
| 1403 | 1403 | |
@@ -1417,15 +1417,15 @@ discard block |
||
| 1417 | 1417 | * URL ou chaîne vide |
| 1418 | 1418 | **/ |
| 1419 | 1419 | function vider_url(?string $url, $entites = true): string { |
| 1420 | - if ($url === null) { |
|
| 1421 | - return ''; |
|
| 1422 | - } |
|
| 1423 | - # un message pour abs_url |
|
| 1424 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1425 | - $url = trim($url); |
|
| 1426 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1420 | + if ($url === null) { |
|
| 1421 | + return ''; |
|
| 1422 | + } |
|
| 1423 | + # un message pour abs_url |
|
| 1424 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1425 | + $url = trim($url); |
|
| 1426 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1427 | 1427 | |
| 1428 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1428 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1429 | 1429 | } |
| 1430 | 1430 | |
| 1431 | 1431 | |
@@ -1440,10 +1440,10 @@ discard block |
||
| 1440 | 1440 | * @return string Adresse email maquillée |
| 1441 | 1441 | **/ |
| 1442 | 1442 | function antispam($texte) { |
| 1443 | - include_spip('inc/acces'); |
|
| 1444 | - $masque = creer_pass_aleatoire(3); |
|
| 1443 | + include_spip('inc/acces'); |
|
| 1444 | + $masque = creer_pass_aleatoire(3); |
|
| 1445 | 1445 | |
| 1446 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1446 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1447 | 1447 | } |
| 1448 | 1448 | |
| 1449 | 1449 | /** |
@@ -1475,8 +1475,8 @@ discard block |
||
| 1475 | 1475 | * True si on a le droit d'accès, false sinon. |
| 1476 | 1476 | **/ |
| 1477 | 1477 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1478 | - include_spip('inc/acces'); |
|
| 1479 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1478 | + include_spip('inc/acces'); |
|
| 1479 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1480 | 1480 | } |
| 1481 | 1481 | |
| 1482 | 1482 | /** |
@@ -1501,13 +1501,13 @@ discard block |
||
| 1501 | 1501 | * Retourne $texte, sinon $sinon. |
| 1502 | 1502 | **/ |
| 1503 | 1503 | function sinon($texte, $sinon = '') { |
| 1504 | - if ($texte) { |
|
| 1505 | - return $texte; |
|
| 1506 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1507 | - return $texte; |
|
| 1508 | - } else { |
|
| 1509 | - return $sinon; |
|
| 1510 | - } |
|
| 1504 | + if ($texte) { |
|
| 1505 | + return $texte; |
|
| 1506 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1507 | + return $texte; |
|
| 1508 | + } else { |
|
| 1509 | + return $sinon; |
|
| 1510 | + } |
|
| 1511 | 1511 | } |
| 1512 | 1512 | |
| 1513 | 1513 | /** |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | * @return mixed |
| 1532 | 1532 | **/ |
| 1533 | 1533 | function choixsivide($a, $vide, $pasvide) { |
| 1534 | - return $a ? $pasvide : $vide; |
|
| 1534 | + return $a ? $pasvide : $vide; |
|
| 1535 | 1535 | } |
| 1536 | 1536 | |
| 1537 | 1537 | /** |
@@ -1555,7 +1555,7 @@ discard block |
||
| 1555 | 1555 | * @return mixed |
| 1556 | 1556 | **/ |
| 1557 | 1557 | function choixsiegal($a1, $a2, $v, $f) { |
| 1558 | - return ($a1 == $a2) ? $v : $f; |
|
| 1558 | + return ($a1 == $a2) ? $v : $f; |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | // |
@@ -1574,13 +1574,13 @@ discard block |
||
| 1574 | 1574 | * @return string |
| 1575 | 1575 | **/ |
| 1576 | 1576 | function filtrer_ical($texte) { |
| 1577 | - #include_spip('inc/charsets'); |
|
| 1578 | - $texte = html2unicode($texte); |
|
| 1579 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1580 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1581 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1577 | + #include_spip('inc/charsets'); |
|
| 1578 | + $texte = html2unicode($texte); |
|
| 1579 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1580 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1581 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1582 | 1582 | |
| 1583 | - return $texte; |
|
| 1583 | + return $texte; |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | |
@@ -1605,54 +1605,54 @@ discard block |
||
| 1605 | 1605 | * @return string |
| 1606 | 1606 | **/ |
| 1607 | 1607 | function post_autobr($texte, $delim = "\n_ ") { |
| 1608 | - if (!function_exists('echappe_html')) { |
|
| 1609 | - include_spip('inc/texte_mini'); |
|
| 1610 | - } |
|
| 1611 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1612 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1613 | - |
|
| 1614 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1615 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1616 | - } else { |
|
| 1617 | - $fin = ''; |
|
| 1618 | - } |
|
| 1619 | - |
|
| 1620 | - $texte = echappe_html($texte, '', true); |
|
| 1621 | - |
|
| 1622 | - // echapper les modeles |
|
| 1623 | - if (strpos($texte, '<') !== false) { |
|
| 1624 | - include_spip('inc/lien'); |
|
| 1625 | - if (defined('_PREG_MODELE')) { |
|
| 1626 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1627 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1628 | - } |
|
| 1629 | - } |
|
| 1630 | - |
|
| 1631 | - $debut = ''; |
|
| 1632 | - $suite = $texte; |
|
| 1633 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1634 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1635 | - $suite = substr($suite, $t); |
|
| 1636 | - $car = substr($suite, 0, 1); |
|
| 1637 | - if ( |
|
| 1638 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1639 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1640 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1641 | - ) { |
|
| 1642 | - $debut .= $delim; |
|
| 1643 | - } else { |
|
| 1644 | - $debut .= "\n"; |
|
| 1645 | - } |
|
| 1646 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1647 | - $debut .= $regs[0]; |
|
| 1648 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1649 | - } |
|
| 1650 | - } |
|
| 1651 | - $texte = $debut . $suite; |
|
| 1652 | - |
|
| 1653 | - $texte = echappe_retour($texte); |
|
| 1654 | - |
|
| 1655 | - return $texte . $fin; |
|
| 1608 | + if (!function_exists('echappe_html')) { |
|
| 1609 | + include_spip('inc/texte_mini'); |
|
| 1610 | + } |
|
| 1611 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1612 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1613 | + |
|
| 1614 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1615 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1616 | + } else { |
|
| 1617 | + $fin = ''; |
|
| 1618 | + } |
|
| 1619 | + |
|
| 1620 | + $texte = echappe_html($texte, '', true); |
|
| 1621 | + |
|
| 1622 | + // echapper les modeles |
|
| 1623 | + if (strpos($texte, '<') !== false) { |
|
| 1624 | + include_spip('inc/lien'); |
|
| 1625 | + if (defined('_PREG_MODELE')) { |
|
| 1626 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1627 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1628 | + } |
|
| 1629 | + } |
|
| 1630 | + |
|
| 1631 | + $debut = ''; |
|
| 1632 | + $suite = $texte; |
|
| 1633 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1634 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1635 | + $suite = substr($suite, $t); |
|
| 1636 | + $car = substr($suite, 0, 1); |
|
| 1637 | + if ( |
|
| 1638 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1639 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1640 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1641 | + ) { |
|
| 1642 | + $debut .= $delim; |
|
| 1643 | + } else { |
|
| 1644 | + $debut .= "\n"; |
|
| 1645 | + } |
|
| 1646 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1647 | + $debut .= $regs[0]; |
|
| 1648 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1649 | + } |
|
| 1650 | + } |
|
| 1651 | + $texte = $debut . $suite; |
|
| 1652 | + |
|
| 1653 | + $texte = echappe_retour($texte); |
|
| 1654 | + |
|
| 1655 | + return $texte . $fin; |
|
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | |
@@ -1693,47 +1693,47 @@ discard block |
||
| 1693 | 1693 | * @return string |
| 1694 | 1694 | **/ |
| 1695 | 1695 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1696 | - static $traduire = false; |
|
| 1697 | - if ( |
|
| 1698 | - $letexte |
|
| 1699 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1700 | - ) { |
|
| 1701 | - if (!$traduire) { |
|
| 1702 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1703 | - include_spip('inc/lang'); |
|
| 1704 | - } |
|
| 1705 | - if (!$lang) { |
|
| 1706 | - $lang = $GLOBALS['spip_lang']; |
|
| 1707 | - } |
|
| 1708 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1709 | - if (is_bool($options)) { |
|
| 1710 | - $options = ['echappe_span' => $options]; |
|
| 1711 | - } |
|
| 1712 | - if (!isset($options['echappe_span'])) { |
|
| 1713 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1714 | - } |
|
| 1715 | - |
|
| 1716 | - foreach ($regs as $reg) { |
|
| 1717 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1718 | - $desc = $traduire($cle, $lang, true); |
|
| 1719 | - $l = $desc->langue; |
|
| 1720 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1721 | - if (strlen($desc->texte ?? '')) { |
|
| 1722 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1723 | - if ($l !== $lang) { |
|
| 1724 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1725 | - } |
|
| 1726 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1727 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1728 | - } |
|
| 1729 | - if (!$options['echappe_span']) { |
|
| 1730 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1731 | - } |
|
| 1732 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1733 | - } |
|
| 1734 | - } |
|
| 1735 | - } |
|
| 1736 | - return $letexte; |
|
| 1696 | + static $traduire = false; |
|
| 1697 | + if ( |
|
| 1698 | + $letexte |
|
| 1699 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1700 | + ) { |
|
| 1701 | + if (!$traduire) { |
|
| 1702 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1703 | + include_spip('inc/lang'); |
|
| 1704 | + } |
|
| 1705 | + if (!$lang) { |
|
| 1706 | + $lang = $GLOBALS['spip_lang']; |
|
| 1707 | + } |
|
| 1708 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1709 | + if (is_bool($options)) { |
|
| 1710 | + $options = ['echappe_span' => $options]; |
|
| 1711 | + } |
|
| 1712 | + if (!isset($options['echappe_span'])) { |
|
| 1713 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1714 | + } |
|
| 1715 | + |
|
| 1716 | + foreach ($regs as $reg) { |
|
| 1717 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1718 | + $desc = $traduire($cle, $lang, true); |
|
| 1719 | + $l = $desc->langue; |
|
| 1720 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1721 | + if (strlen($desc->texte ?? '')) { |
|
| 1722 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1723 | + if ($l !== $lang) { |
|
| 1724 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1725 | + } |
|
| 1726 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1727 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1728 | + } |
|
| 1729 | + if (!$options['echappe_span']) { |
|
| 1730 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1731 | + } |
|
| 1732 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1733 | + } |
|
| 1734 | + } |
|
| 1735 | + } |
|
| 1736 | + return $letexte; |
|
| 1737 | 1737 | } |
| 1738 | 1738 | |
| 1739 | 1739 | /** |
@@ -1785,68 +1785,68 @@ discard block |
||
| 1785 | 1785 | **/ |
| 1786 | 1786 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1787 | 1787 | |
| 1788 | - if ( |
|
| 1789 | - $letexte |
|
| 1790 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1791 | - ) { |
|
| 1792 | - if (!$lang) { |
|
| 1793 | - $lang = $GLOBALS['spip_lang']; |
|
| 1794 | - } |
|
| 1795 | - |
|
| 1796 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1797 | - if (is_bool($options)) { |
|
| 1798 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1799 | - } |
|
| 1800 | - if (!isset($options['echappe_span'])) { |
|
| 1801 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1802 | - } |
|
| 1803 | - if (!isset($options['lang_defaut'])) { |
|
| 1804 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1805 | - } |
|
| 1806 | - |
|
| 1807 | - include_spip('inc/lang'); |
|
| 1808 | - foreach ($regs as $reg) { |
|
| 1809 | - // chercher la version de la langue courante |
|
| 1810 | - $trads = extraire_trads($reg[1]); |
|
| 1811 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1812 | - $trad = $trads[$l]; |
|
| 1813 | - } else { |
|
| 1814 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1815 | - $trad = ''; |
|
| 1816 | - } else { |
|
| 1817 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1818 | - // ou la premiere dispo |
|
| 1819 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1820 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1821 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1822 | - $l = key($trads); |
|
| 1823 | - } |
|
| 1824 | - $trad = $trads[$l]; |
|
| 1825 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1826 | - $trad = $typographie($trad); |
|
| 1827 | - // Tester si on echappe en span ou en div |
|
| 1828 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1829 | - include_spip('inc/texte'); |
|
| 1830 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1831 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1832 | - if ($mode === 'div') { |
|
| 1833 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1834 | - } |
|
| 1835 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1836 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1837 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1838 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1839 | - } |
|
| 1840 | - if (!$options['echappe_span']) { |
|
| 1841 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1842 | - } |
|
| 1843 | - } |
|
| 1844 | - } |
|
| 1845 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1846 | - } |
|
| 1847 | - } |
|
| 1848 | - |
|
| 1849 | - return $letexte; |
|
| 1788 | + if ( |
|
| 1789 | + $letexte |
|
| 1790 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1791 | + ) { |
|
| 1792 | + if (!$lang) { |
|
| 1793 | + $lang = $GLOBALS['spip_lang']; |
|
| 1794 | + } |
|
| 1795 | + |
|
| 1796 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1797 | + if (is_bool($options)) { |
|
| 1798 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1799 | + } |
|
| 1800 | + if (!isset($options['echappe_span'])) { |
|
| 1801 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1802 | + } |
|
| 1803 | + if (!isset($options['lang_defaut'])) { |
|
| 1804 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1805 | + } |
|
| 1806 | + |
|
| 1807 | + include_spip('inc/lang'); |
|
| 1808 | + foreach ($regs as $reg) { |
|
| 1809 | + // chercher la version de la langue courante |
|
| 1810 | + $trads = extraire_trads($reg[1]); |
|
| 1811 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1812 | + $trad = $trads[$l]; |
|
| 1813 | + } else { |
|
| 1814 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1815 | + $trad = ''; |
|
| 1816 | + } else { |
|
| 1817 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1818 | + // ou la premiere dispo |
|
| 1819 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1820 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1821 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1822 | + $l = key($trads); |
|
| 1823 | + } |
|
| 1824 | + $trad = $trads[$l]; |
|
| 1825 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1826 | + $trad = $typographie($trad); |
|
| 1827 | + // Tester si on echappe en span ou en div |
|
| 1828 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1829 | + include_spip('inc/texte'); |
|
| 1830 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1831 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1832 | + if ($mode === 'div') { |
|
| 1833 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1834 | + } |
|
| 1835 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1836 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1837 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1838 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1839 | + } |
|
| 1840 | + if (!$options['echappe_span']) { |
|
| 1841 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1842 | + } |
|
| 1843 | + } |
|
| 1844 | + } |
|
| 1845 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1846 | + } |
|
| 1847 | + } |
|
| 1848 | + |
|
| 1849 | + return $letexte; |
|
| 1850 | 1850 | } |
| 1851 | 1851 | |
| 1852 | 1852 | /** |
@@ -1862,21 +1862,21 @@ discard block |
||
| 1862 | 1862 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1863 | 1863 | **/ |
| 1864 | 1864 | function extraire_trads($bloc) { |
| 1865 | - $trads = []; |
|
| 1866 | - $lang = ''; |
|
| 1865 | + $trads = []; |
|
| 1866 | + $lang = ''; |
|
| 1867 | 1867 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1868 | 1868 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1869 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1870 | - $texte = trim($regs[1]); |
|
| 1871 | - if ($texte or $lang) { |
|
| 1872 | - $trads[$lang] = $texte; |
|
| 1873 | - } |
|
| 1874 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1875 | - $lang = $regs[2]; |
|
| 1876 | - } |
|
| 1877 | - $trads[$lang] = $bloc; |
|
| 1869 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1870 | + $texte = trim($regs[1]); |
|
| 1871 | + if ($texte or $lang) { |
|
| 1872 | + $trads[$lang] = $texte; |
|
| 1873 | + } |
|
| 1874 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1875 | + $lang = $regs[2]; |
|
| 1876 | + } |
|
| 1877 | + $trads[$lang] = $bloc; |
|
| 1878 | 1878 | |
| 1879 | - return $trads; |
|
| 1879 | + return $trads; |
|
| 1880 | 1880 | } |
| 1881 | 1881 | |
| 1882 | 1882 | |
@@ -1887,7 +1887,7 @@ discard block |
||
| 1887 | 1887 | * @return string L'initiale en majuscule |
| 1888 | 1888 | */ |
| 1889 | 1889 | function filtre_initiale($nom) { |
| 1890 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1890 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1891 | 1891 | } |
| 1892 | 1892 | |
| 1893 | 1893 | |
@@ -1932,33 +1932,33 @@ discard block |
||
| 1932 | 1932 | * - null (interne) : si on empile |
| 1933 | 1933 | **/ |
| 1934 | 1934 | function unique($donnee, $famille = '', $cpt = false) { |
| 1935 | - static $mem = []; |
|
| 1936 | - // permettre de vider la pile et de la restaurer |
|
| 1937 | - // pour le calcul de introduction... |
|
| 1938 | - if ($famille == '_spip_raz_') { |
|
| 1939 | - $tmp = $mem; |
|
| 1940 | - $mem = []; |
|
| 1941 | - |
|
| 1942 | - return $tmp; |
|
| 1943 | - } elseif ($famille == '_spip_set_') { |
|
| 1944 | - $mem = $donnee; |
|
| 1945 | - |
|
| 1946 | - return; |
|
| 1947 | - } |
|
| 1948 | - // eviter une notice |
|
| 1949 | - if (!isset($mem[$famille])) { |
|
| 1950 | - $mem[$famille] = []; |
|
| 1951 | - } |
|
| 1952 | - if ($cpt) { |
|
| 1953 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1954 | - } |
|
| 1955 | - // eviter une notice |
|
| 1956 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1957 | - $mem[$famille][$donnee] = 0; |
|
| 1958 | - } |
|
| 1959 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1960 | - return $donnee; |
|
| 1961 | - } |
|
| 1935 | + static $mem = []; |
|
| 1936 | + // permettre de vider la pile et de la restaurer |
|
| 1937 | + // pour le calcul de introduction... |
|
| 1938 | + if ($famille == '_spip_raz_') { |
|
| 1939 | + $tmp = $mem; |
|
| 1940 | + $mem = []; |
|
| 1941 | + |
|
| 1942 | + return $tmp; |
|
| 1943 | + } elseif ($famille == '_spip_set_') { |
|
| 1944 | + $mem = $donnee; |
|
| 1945 | + |
|
| 1946 | + return; |
|
| 1947 | + } |
|
| 1948 | + // eviter une notice |
|
| 1949 | + if (!isset($mem[$famille])) { |
|
| 1950 | + $mem[$famille] = []; |
|
| 1951 | + } |
|
| 1952 | + if ($cpt) { |
|
| 1953 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1954 | + } |
|
| 1955 | + // eviter une notice |
|
| 1956 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1957 | + $mem[$famille][$donnee] = 0; |
|
| 1958 | + } |
|
| 1959 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1960 | + return $donnee; |
|
| 1961 | + } |
|
| 1962 | 1962 | } |
| 1963 | 1963 | |
| 1964 | 1964 | |
@@ -1988,20 +1988,20 @@ discard block |
||
| 1988 | 1988 | * Une des valeurs en fonction du compteur. |
| 1989 | 1989 | **/ |
| 1990 | 1990 | function alterner($i, ...$args) { |
| 1991 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1992 | - $num = count($args); |
|
| 1991 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1992 | + $num = count($args); |
|
| 1993 | 1993 | |
| 1994 | - if ($num === 1 && is_array($args[0])) { |
|
| 1995 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1996 | - $args = array_values($args[0]); |
|
| 1997 | - $num = count($args); |
|
| 1998 | - } |
|
| 1994 | + if ($num === 1 && is_array($args[0])) { |
|
| 1995 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1996 | + $args = array_values($args[0]); |
|
| 1997 | + $num = count($args); |
|
| 1998 | + } |
|
| 1999 | 1999 | |
| 2000 | - // un index compris entre 0 et num exclus |
|
| 2001 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 2002 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 2003 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2004 | - return $args[$i]; |
|
| 2000 | + // un index compris entre 0 et num exclus |
|
| 2001 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 2002 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 2003 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 2004 | + return $args[$i]; |
|
| 2005 | 2005 | } |
| 2006 | 2006 | |
| 2007 | 2007 | |
@@ -2027,51 +2027,51 @@ discard block |
||
| 2027 | 2027 | * - null lorsque l’attribut n’existe pas. |
| 2028 | 2028 | **/ |
| 2029 | 2029 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 2030 | - if (is_array($balise)) { |
|
| 2031 | - array_walk( |
|
| 2032 | - $balise, |
|
| 2033 | - function (&$a, $key, $t) { |
|
| 2034 | - $a = extraire_attribut($a, $t); |
|
| 2035 | - }, |
|
| 2036 | - $attribut |
|
| 2037 | - ); |
|
| 2038 | - |
|
| 2039 | - return $balise; |
|
| 2040 | - } |
|
| 2041 | - if ( |
|
| 2042 | - $balise |
|
| 2043 | - && preg_match( |
|
| 2044 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2045 | - . $attribut |
|
| 2046 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2047 | - $balise, |
|
| 2048 | - $r |
|
| 2049 | - ) |
|
| 2050 | - ) { |
|
| 2051 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2052 | - $r[4] = substr($r[3], 1, -1); |
|
| 2053 | - $r[3] = $r[3][0]; |
|
| 2054 | - } elseif ($r[3] !== '') { |
|
| 2055 | - $r[4] = $r[3]; |
|
| 2056 | - $r[3] = ''; |
|
| 2057 | - } else { |
|
| 2058 | - $r[4] = trim($r[2]); |
|
| 2059 | - } |
|
| 2060 | - $att = $r[4]; |
|
| 2061 | - if (strpos($att, '&#') !== false) { |
|
| 2062 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2063 | - } |
|
| 2064 | - $att = filtrer_entites($att); |
|
| 2065 | - } else { |
|
| 2066 | - $att = null; |
|
| 2067 | - $r = []; |
|
| 2068 | - } |
|
| 2069 | - |
|
| 2070 | - if ($complet) { |
|
| 2071 | - return [$att, $r]; |
|
| 2072 | - } else { |
|
| 2073 | - return $att; |
|
| 2074 | - } |
|
| 2030 | + if (is_array($balise)) { |
|
| 2031 | + array_walk( |
|
| 2032 | + $balise, |
|
| 2033 | + function (&$a, $key, $t) { |
|
| 2034 | + $a = extraire_attribut($a, $t); |
|
| 2035 | + }, |
|
| 2036 | + $attribut |
|
| 2037 | + ); |
|
| 2038 | + |
|
| 2039 | + return $balise; |
|
| 2040 | + } |
|
| 2041 | + if ( |
|
| 2042 | + $balise |
|
| 2043 | + && preg_match( |
|
| 2044 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 2045 | + . $attribut |
|
| 2046 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 2047 | + $balise, |
|
| 2048 | + $r |
|
| 2049 | + ) |
|
| 2050 | + ) { |
|
| 2051 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 2052 | + $r[4] = substr($r[3], 1, -1); |
|
| 2053 | + $r[3] = $r[3][0]; |
|
| 2054 | + } elseif ($r[3] !== '') { |
|
| 2055 | + $r[4] = $r[3]; |
|
| 2056 | + $r[3] = ''; |
|
| 2057 | + } else { |
|
| 2058 | + $r[4] = trim($r[2]); |
|
| 2059 | + } |
|
| 2060 | + $att = $r[4]; |
|
| 2061 | + if (strpos($att, '&#') !== false) { |
|
| 2062 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 2063 | + } |
|
| 2064 | + $att = filtrer_entites($att); |
|
| 2065 | + } else { |
|
| 2066 | + $att = null; |
|
| 2067 | + $r = []; |
|
| 2068 | + } |
|
| 2069 | + |
|
| 2070 | + if ($complet) { |
|
| 2071 | + return [$att, $r]; |
|
| 2072 | + } else { |
|
| 2073 | + return $att; |
|
| 2074 | + } |
|
| 2075 | 2075 | } |
| 2076 | 2076 | |
| 2077 | 2077 | /** |
@@ -2104,41 +2104,41 @@ discard block |
||
| 2104 | 2104 | **/ |
| 2105 | 2105 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 2106 | 2106 | |
| 2107 | - if ($balise === null or $balise === '') { |
|
| 2108 | - return ''; |
|
| 2109 | - } |
|
| 2107 | + if ($balise === null or $balise === '') { |
|
| 2108 | + return ''; |
|
| 2109 | + } |
|
| 2110 | 2110 | |
| 2111 | - // preparer l'attribut |
|
| 2112 | - // supprimer les etc mais pas les balises html |
|
| 2113 | - // qui ont un sens dans un attribut value d'un input |
|
| 2114 | - if ($proteger) { |
|
| 2115 | - $val = attribut_html($val, false); |
|
| 2116 | - } |
|
| 2111 | + // preparer l'attribut |
|
| 2112 | + // supprimer les etc mais pas les balises html |
|
| 2113 | + // qui ont un sens dans un attribut value d'un input |
|
| 2114 | + if ($proteger) { |
|
| 2115 | + $val = attribut_html($val, false); |
|
| 2116 | + } |
|
| 2117 | 2117 | |
| 2118 | - // echapper les ' pour eviter tout bug |
|
| 2119 | - $val = str_replace("'", ''', $val); |
|
| 2120 | - if ($vider and strlen($val) === 0) { |
|
| 2121 | - $insert = ''; |
|
| 2122 | - } else { |
|
| 2123 | - $insert = " $attribut='$val'"; |
|
| 2124 | - } |
|
| 2118 | + // echapper les ' pour eviter tout bug |
|
| 2119 | + $val = str_replace("'", ''', $val); |
|
| 2120 | + if ($vider and strlen($val) === 0) { |
|
| 2121 | + $insert = ''; |
|
| 2122 | + } else { |
|
| 2123 | + $insert = " $attribut='$val'"; |
|
| 2124 | + } |
|
| 2125 | 2125 | |
| 2126 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2126 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2127 | 2127 | |
| 2128 | - if ($old !== null) { |
|
| 2129 | - // Remplacer l'ancien attribut du meme nom |
|
| 2130 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2131 | - } else { |
|
| 2132 | - // preferer une balise " />" (comme <img />) |
|
| 2133 | - if (preg_match(',/>,', $balise)) { |
|
| 2134 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2135 | - } // sinon une balise <a ...> ... </a> |
|
| 2136 | - else { |
|
| 2137 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2138 | - } |
|
| 2139 | - } |
|
| 2128 | + if ($old !== null) { |
|
| 2129 | + // Remplacer l'ancien attribut du meme nom |
|
| 2130 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2131 | + } else { |
|
| 2132 | + // preferer une balise " />" (comme <img />) |
|
| 2133 | + if (preg_match(',/>,', $balise)) { |
|
| 2134 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2135 | + } // sinon une balise <a ...> ... </a> |
|
| 2136 | + else { |
|
| 2137 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2138 | + } |
|
| 2139 | + } |
|
| 2140 | 2140 | |
| 2141 | - return $balise; |
|
| 2141 | + return $balise; |
|
| 2142 | 2142 | } |
| 2143 | 2143 | |
| 2144 | 2144 | /** |
@@ -2156,7 +2156,7 @@ discard block |
||
| 2156 | 2156 | * @return string Code HTML sans l'attribut |
| 2157 | 2157 | **/ |
| 2158 | 2158 | function vider_attribut(?string $balise, string $attribut): string { |
| 2159 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2159 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2160 | 2160 | } |
| 2161 | 2161 | |
| 2162 | 2162 | /** |
@@ -2168,53 +2168,53 @@ discard block |
||
| 2168 | 2168 | * @return string |
| 2169 | 2169 | */ |
| 2170 | 2170 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2171 | - if (is_string($class)) { |
|
| 2172 | - $class = explode(' ', trim($class)); |
|
| 2173 | - } |
|
| 2174 | - $class = array_filter($class); |
|
| 2175 | - $class = array_unique($class); |
|
| 2176 | - if (!$class) { |
|
| 2177 | - return $balise; |
|
| 2178 | - } |
|
| 2179 | - |
|
| 2180 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2181 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2182 | - return $balise; |
|
| 2183 | - } |
|
| 2184 | - |
|
| 2185 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2186 | - $class_new = $class_courante; |
|
| 2187 | - foreach ($class as $c) { |
|
| 2188 | - $is_class_presente = false; |
|
| 2189 | - if ( |
|
| 2190 | - $class_courante |
|
| 2191 | - and strpos($class_courante, (string) $c) !== false |
|
| 2192 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2193 | - ) { |
|
| 2194 | - $is_class_presente = true; |
|
| 2195 | - } |
|
| 2196 | - if ( |
|
| 2197 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2198 | - and !$is_class_presente |
|
| 2199 | - ) { |
|
| 2200 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2201 | - } elseif ( |
|
| 2202 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2203 | - and $is_class_presente |
|
| 2204 | - ) { |
|
| 2205 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2206 | - } |
|
| 2207 | - } |
|
| 2208 | - |
|
| 2209 | - if ($class_new !== $class_courante) { |
|
| 2210 | - if (strlen($class_new)) { |
|
| 2211 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2212 | - } elseif ($class_courante) { |
|
| 2213 | - $balise = vider_attribut($balise, 'class'); |
|
| 2214 | - } |
|
| 2215 | - } |
|
| 2216 | - |
|
| 2217 | - return $balise; |
|
| 2171 | + if (is_string($class)) { |
|
| 2172 | + $class = explode(' ', trim($class)); |
|
| 2173 | + } |
|
| 2174 | + $class = array_filter($class); |
|
| 2175 | + $class = array_unique($class); |
|
| 2176 | + if (!$class) { |
|
| 2177 | + return $balise; |
|
| 2178 | + } |
|
| 2179 | + |
|
| 2180 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2181 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2182 | + return $balise; |
|
| 2183 | + } |
|
| 2184 | + |
|
| 2185 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2186 | + $class_new = $class_courante; |
|
| 2187 | + foreach ($class as $c) { |
|
| 2188 | + $is_class_presente = false; |
|
| 2189 | + if ( |
|
| 2190 | + $class_courante |
|
| 2191 | + and strpos($class_courante, (string) $c) !== false |
|
| 2192 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2193 | + ) { |
|
| 2194 | + $is_class_presente = true; |
|
| 2195 | + } |
|
| 2196 | + if ( |
|
| 2197 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2198 | + and !$is_class_presente |
|
| 2199 | + ) { |
|
| 2200 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2201 | + } elseif ( |
|
| 2202 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2203 | + and $is_class_presente |
|
| 2204 | + ) { |
|
| 2205 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2206 | + } |
|
| 2207 | + } |
|
| 2208 | + |
|
| 2209 | + if ($class_new !== $class_courante) { |
|
| 2210 | + if (strlen($class_new)) { |
|
| 2211 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2212 | + } elseif ($class_courante) { |
|
| 2213 | + $balise = vider_attribut($balise, 'class'); |
|
| 2214 | + } |
|
| 2215 | + } |
|
| 2216 | + |
|
| 2217 | + return $balise; |
|
| 2218 | 2218 | } |
| 2219 | 2219 | |
| 2220 | 2220 | /** |
@@ -2224,7 +2224,7 @@ discard block |
||
| 2224 | 2224 | * @return string |
| 2225 | 2225 | */ |
| 2226 | 2226 | function ajouter_class($balise, $class) { |
| 2227 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2227 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2228 | 2228 | } |
| 2229 | 2229 | |
| 2230 | 2230 | /** |
@@ -2234,7 +2234,7 @@ discard block |
||
| 2234 | 2234 | * @return string |
| 2235 | 2235 | */ |
| 2236 | 2236 | function supprimer_class($balise, $class) { |
| 2237 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2237 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2238 | 2238 | } |
| 2239 | 2239 | |
| 2240 | 2240 | /** |
@@ -2245,7 +2245,7 @@ discard block |
||
| 2245 | 2245 | * @return string |
| 2246 | 2246 | */ |
| 2247 | 2247 | function commuter_class($balise, $class) { |
| 2248 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2248 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | 2251 | /** |
@@ -2256,19 +2256,19 @@ discard block |
||
| 2256 | 2256 | * @return string |
| 2257 | 2257 | */ |
| 2258 | 2258 | function tester_config($id, $mode = '') { |
| 2259 | - include_spip('action/inscrire_auteur'); |
|
| 2259 | + include_spip('action/inscrire_auteur'); |
|
| 2260 | 2260 | |
| 2261 | - return tester_statut_inscription($mode, $id); |
|
| 2261 | + return tester_statut_inscription($mode, $id); |
|
| 2262 | 2262 | } |
| 2263 | 2263 | |
| 2264 | 2264 | // |
| 2265 | 2265 | // Quelques fonctions de calcul arithmetique |
| 2266 | 2266 | // |
| 2267 | 2267 | function floatstr($a) { |
| 2268 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2268 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2269 | 2269 | } |
| 2270 | 2270 | function strize($f, $a, $b) { |
| 2271 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2271 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | 2274 | /** |
@@ -2287,7 +2287,7 @@ discard block |
||
| 2287 | 2287 | * @return int $a+$b |
| 2288 | 2288 | **/ |
| 2289 | 2289 | function plus($a, $b) { |
| 2290 | - return $a + $b; |
|
| 2290 | + return $a + $b; |
|
| 2291 | 2291 | } |
| 2292 | 2292 | function strplus($a, $b) { |
| 2293 | 2293 | return strize('plus', $a, $b); |
@@ -2308,7 +2308,7 @@ discard block |
||
| 2308 | 2308 | * @return int $a-$b |
| 2309 | 2309 | **/ |
| 2310 | 2310 | function moins($a, $b) { |
| 2311 | - return $a - $b; |
|
| 2311 | + return $a - $b; |
|
| 2312 | 2312 | } |
| 2313 | 2313 | function strmoins($a, $b) { |
| 2314 | 2314 | return strize('moins', $a, $b); |
@@ -2331,7 +2331,7 @@ discard block |
||
| 2331 | 2331 | * @return int $a*$b |
| 2332 | 2332 | **/ |
| 2333 | 2333 | function mult($a, $b) { |
| 2334 | - return $a * $b; |
|
| 2334 | + return $a * $b; |
|
| 2335 | 2335 | } |
| 2336 | 2336 | function strmult($a, $b) { |
| 2337 | 2337 | return strize('mult', $a, $b); |
@@ -2354,7 +2354,7 @@ discard block |
||
| 2354 | 2354 | * @return int $a/$b (ou 0 si $b est nul) |
| 2355 | 2355 | **/ |
| 2356 | 2356 | function div($a, $b) { |
| 2357 | - return $b ? $a / $b : 0; |
|
| 2357 | + return $b ? $a / $b : 0; |
|
| 2358 | 2358 | } |
| 2359 | 2359 | function strdiv($a, $b) { |
| 2360 | 2360 | return strize('div', $a, $b); |
@@ -2378,7 +2378,7 @@ discard block |
||
| 2378 | 2378 | * @return int ($nb % $mod) + $add |
| 2379 | 2379 | **/ |
| 2380 | 2380 | function modulo($nb, $mod, $add = 0) { |
| 2381 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2381 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2382 | 2382 | } |
| 2383 | 2383 | |
| 2384 | 2384 | |
@@ -2393,26 +2393,26 @@ discard block |
||
| 2393 | 2393 | * - true sinon |
| 2394 | 2394 | **/ |
| 2395 | 2395 | function nom_acceptable($nom) { |
| 2396 | - $remp2 = []; |
|
| 2397 | - $remp1 = []; |
|
| 2398 | - if (!is_string($nom)) { |
|
| 2399 | - return false; |
|
| 2400 | - } |
|
| 2401 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2402 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2403 | - } |
|
| 2404 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2405 | - foreach ($tags_acceptes as $tag) { |
|
| 2406 | - if (strlen($tag)) { |
|
| 2407 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2408 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2409 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2410 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2411 | - } |
|
| 2412 | - } |
|
| 2413 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2414 | - |
|
| 2415 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2396 | + $remp2 = []; |
|
| 2397 | + $remp1 = []; |
|
| 2398 | + if (!is_string($nom)) { |
|
| 2399 | + return false; |
|
| 2400 | + } |
|
| 2401 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2402 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2403 | + } |
|
| 2404 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2405 | + foreach ($tags_acceptes as $tag) { |
|
| 2406 | + if (strlen($tag)) { |
|
| 2407 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2408 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2409 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2410 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2411 | + } |
|
| 2412 | + } |
|
| 2413 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2414 | + |
|
| 2415 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2416 | 2416 | } |
| 2417 | 2417 | |
| 2418 | 2418 | |
@@ -2428,14 +2428,14 @@ discard block |
||
| 2428 | 2428 | * - renvoie un tableau si l'entree est un tableau |
| 2429 | 2429 | **/ |
| 2430 | 2430 | function email_valide($adresses) { |
| 2431 | - if (is_array($adresses)) { |
|
| 2432 | - $adresses = array_map('email_valide', $adresses); |
|
| 2433 | - $adresses = array_filter($adresses); |
|
| 2434 | - return $adresses; |
|
| 2435 | - } |
|
| 2431 | + if (is_array($adresses)) { |
|
| 2432 | + $adresses = array_map('email_valide', $adresses); |
|
| 2433 | + $adresses = array_filter($adresses); |
|
| 2434 | + return $adresses; |
|
| 2435 | + } |
|
| 2436 | 2436 | |
| 2437 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2438 | - return $email_valide($adresses); |
|
| 2437 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2438 | + return $email_valide($adresses); |
|
| 2439 | 2439 | } |
| 2440 | 2440 | |
| 2441 | 2441 | /** |
@@ -2449,27 +2449,27 @@ discard block |
||
| 2449 | 2449 | * @return string Texte |
| 2450 | 2450 | **/ |
| 2451 | 2451 | function afficher_enclosures($tags) { |
| 2452 | - $s = []; |
|
| 2453 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2454 | - if ( |
|
| 2455 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2456 | - and $t = extraire_attribut($tag, 'href') |
|
| 2457 | - ) { |
|
| 2458 | - $s[] = preg_replace( |
|
| 2459 | - ',>[^<]+</a>,S', |
|
| 2460 | - '>' |
|
| 2461 | - . http_img_pack( |
|
| 2462 | - 'attachment-16.png', |
|
| 2463 | - $t, |
|
| 2464 | - 'title="' . attribut_html($t) . '"' |
|
| 2465 | - ) |
|
| 2466 | - . '</a>', |
|
| 2467 | - $tag |
|
| 2468 | - ); |
|
| 2469 | - } |
|
| 2470 | - } |
|
| 2471 | - |
|
| 2472 | - return join(' ', $s); |
|
| 2452 | + $s = []; |
|
| 2453 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2454 | + if ( |
|
| 2455 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2456 | + and $t = extraire_attribut($tag, 'href') |
|
| 2457 | + ) { |
|
| 2458 | + $s[] = preg_replace( |
|
| 2459 | + ',>[^<]+</a>,S', |
|
| 2460 | + '>' |
|
| 2461 | + . http_img_pack( |
|
| 2462 | + 'attachment-16.png', |
|
| 2463 | + $t, |
|
| 2464 | + 'title="' . attribut_html($t) . '"' |
|
| 2465 | + ) |
|
| 2466 | + . '</a>', |
|
| 2467 | + $tag |
|
| 2468 | + ); |
|
| 2469 | + } |
|
| 2470 | + } |
|
| 2471 | + |
|
| 2472 | + return join(' ', $s); |
|
| 2473 | 2473 | } |
| 2474 | 2474 | |
| 2475 | 2475 | /** |
@@ -2484,15 +2484,15 @@ discard block |
||
| 2484 | 2484 | * @return string Liens trouvés |
| 2485 | 2485 | **/ |
| 2486 | 2486 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2487 | - $s = []; |
|
| 2488 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2489 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2490 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2491 | - $s[] = $tag; |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2487 | + $s = []; |
|
| 2488 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2489 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2490 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2491 | + $s[] = $tag; |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | 2494 | |
| 2495 | - return join(', ', $s); |
|
| 2495 | + return join(', ', $s); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | |
@@ -2514,21 +2514,21 @@ discard block |
||
| 2514 | 2514 | * @return string Tag HTML `<a>` avec microformat. |
| 2515 | 2515 | **/ |
| 2516 | 2516 | function enclosure2microformat($e) { |
| 2517 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2518 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2519 | - } |
|
| 2520 | - $type = extraire_attribut($e, 'type'); |
|
| 2521 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2522 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2523 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2524 | - } |
|
| 2525 | - $fichier = basename($url); |
|
| 2517 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2518 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2519 | + } |
|
| 2520 | + $type = extraire_attribut($e, 'type'); |
|
| 2521 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2522 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2523 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2524 | + } |
|
| 2525 | + $fichier = basename($url); |
|
| 2526 | 2526 | |
| 2527 | - return '<a rel="enclosure"' |
|
| 2528 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2529 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2530 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2531 | - . '>' . $fichier . '</a>'; |
|
| 2527 | + return '<a rel="enclosure"' |
|
| 2528 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2529 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2530 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2531 | + . '>' . $fichier . '</a>'; |
|
| 2532 | 2532 | } |
| 2533 | 2533 | |
| 2534 | 2534 | /** |
@@ -2546,24 +2546,24 @@ discard block |
||
| 2546 | 2546 | * @return string Tags RSS `<enclosure>`. |
| 2547 | 2547 | **/ |
| 2548 | 2548 | function microformat2enclosure($tags) { |
| 2549 | - $enclosures = []; |
|
| 2550 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2551 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2552 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2553 | - $type = extraire_attribut($e, 'type'); |
|
| 2554 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2555 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2556 | - } # vieux data |
|
| 2557 | - $fichier = basename($url); |
|
| 2558 | - $enclosures[] = '<enclosure' |
|
| 2559 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2560 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2561 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2562 | - . ' />'; |
|
| 2563 | - } |
|
| 2564 | - } |
|
| 2549 | + $enclosures = []; |
|
| 2550 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2551 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2552 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2553 | + $type = extraire_attribut($e, 'type'); |
|
| 2554 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2555 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2556 | + } # vieux data |
|
| 2557 | + $fichier = basename($url); |
|
| 2558 | + $enclosures[] = '<enclosure' |
|
| 2559 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2560 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2561 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2562 | + . ' />'; |
|
| 2563 | + } |
|
| 2564 | + } |
|
| 2565 | 2565 | |
| 2566 | - return join("\n", $enclosures); |
|
| 2566 | + return join("\n", $enclosures); |
|
| 2567 | 2567 | } |
| 2568 | 2568 | |
| 2569 | 2569 | |
@@ -2579,16 +2579,16 @@ discard block |
||
| 2579 | 2579 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2580 | 2580 | **/ |
| 2581 | 2581 | function tags2dcsubject($tags) { |
| 2582 | - $subjects = ''; |
|
| 2583 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2584 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2585 | - $subjects .= '<dc:subject>' |
|
| 2586 | - . texte_backend(textebrut($e)) |
|
| 2587 | - . '</dc:subject>' . "\n"; |
|
| 2588 | - } |
|
| 2589 | - } |
|
| 2582 | + $subjects = ''; |
|
| 2583 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2584 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2585 | + $subjects .= '<dc:subject>' |
|
| 2586 | + . texte_backend(textebrut($e)) |
|
| 2587 | + . '</dc:subject>' . "\n"; |
|
| 2588 | + } |
|
| 2589 | + } |
|
| 2590 | 2590 | |
| 2591 | - return $subjects; |
|
| 2591 | + return $subjects; |
|
| 2592 | 2592 | } |
| 2593 | 2593 | |
| 2594 | 2594 | /** |
@@ -2617,27 +2617,27 @@ discard block |
||
| 2617 | 2617 | * - Tableau de résultats, si tableau en entrée. |
| 2618 | 2618 | **/ |
| 2619 | 2619 | function extraire_balise($texte, $tag = 'a') { |
| 2620 | - if (is_array($texte)) { |
|
| 2621 | - array_walk( |
|
| 2622 | - $texte, |
|
| 2623 | - function (&$a, $key, $t) { |
|
| 2624 | - $a = extraire_balise($a, $t); |
|
| 2625 | - }, |
|
| 2626 | - $tag |
|
| 2627 | - ); |
|
| 2628 | - |
|
| 2629 | - return $texte; |
|
| 2630 | - } |
|
| 2631 | - |
|
| 2632 | - if ( |
|
| 2633 | - preg_match( |
|
| 2634 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2635 | - $texte, |
|
| 2636 | - $regs |
|
| 2637 | - ) |
|
| 2638 | - ) { |
|
| 2639 | - return $regs[0]; |
|
| 2640 | - } |
|
| 2620 | + if (is_array($texte)) { |
|
| 2621 | + array_walk( |
|
| 2622 | + $texte, |
|
| 2623 | + function (&$a, $key, $t) { |
|
| 2624 | + $a = extraire_balise($a, $t); |
|
| 2625 | + }, |
|
| 2626 | + $tag |
|
| 2627 | + ); |
|
| 2628 | + |
|
| 2629 | + return $texte; |
|
| 2630 | + } |
|
| 2631 | + |
|
| 2632 | + if ( |
|
| 2633 | + preg_match( |
|
| 2634 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2635 | + $texte, |
|
| 2636 | + $regs |
|
| 2637 | + ) |
|
| 2638 | + ) { |
|
| 2639 | + return $regs[0]; |
|
| 2640 | + } |
|
| 2641 | 2641 | } |
| 2642 | 2642 | |
| 2643 | 2643 | /** |
@@ -2665,30 +2665,30 @@ discard block |
||
| 2665 | 2665 | * - Tableau de résultats, si tableau en entrée. |
| 2666 | 2666 | **/ |
| 2667 | 2667 | function extraire_balises($texte, $tag = 'a') { |
| 2668 | - if (is_array($texte)) { |
|
| 2669 | - array_walk( |
|
| 2670 | - $texte, |
|
| 2671 | - function (&$a, $key, $t) { |
|
| 2672 | - $a = extraire_balises($a, $t); |
|
| 2673 | - }, |
|
| 2674 | - $tag |
|
| 2675 | - ); |
|
| 2676 | - |
|
| 2677 | - return $texte; |
|
| 2678 | - } |
|
| 2679 | - |
|
| 2680 | - if ( |
|
| 2681 | - preg_match_all( |
|
| 2682 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2683 | - $texte, |
|
| 2684 | - $regs, |
|
| 2685 | - PREG_PATTERN_ORDER |
|
| 2686 | - ) |
|
| 2687 | - ) { |
|
| 2688 | - return $regs[0]; |
|
| 2689 | - } else { |
|
| 2690 | - return []; |
|
| 2691 | - } |
|
| 2668 | + if (is_array($texte)) { |
|
| 2669 | + array_walk( |
|
| 2670 | + $texte, |
|
| 2671 | + function (&$a, $key, $t) { |
|
| 2672 | + $a = extraire_balises($a, $t); |
|
| 2673 | + }, |
|
| 2674 | + $tag |
|
| 2675 | + ); |
|
| 2676 | + |
|
| 2677 | + return $texte; |
|
| 2678 | + } |
|
| 2679 | + |
|
| 2680 | + if ( |
|
| 2681 | + preg_match_all( |
|
| 2682 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2683 | + $texte, |
|
| 2684 | + $regs, |
|
| 2685 | + PREG_PATTERN_ORDER |
|
| 2686 | + ) |
|
| 2687 | + ) { |
|
| 2688 | + return $regs[0]; |
|
| 2689 | + } else { |
|
| 2690 | + return []; |
|
| 2691 | + } |
|
| 2692 | 2692 | } |
| 2693 | 2693 | |
| 2694 | 2694 | /** |
@@ -2717,11 +2717,11 @@ discard block |
||
| 2717 | 2717 | * - `$def` si on n'a pas transmis de tableau |
| 2718 | 2718 | **/ |
| 2719 | 2719 | function in_any($val, $vals, $def = '') { |
| 2720 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2721 | - $vals = $v; |
|
| 2722 | - } |
|
| 2720 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2721 | + $vals = $v; |
|
| 2722 | + } |
|
| 2723 | 2723 | |
| 2724 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2724 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2725 | 2725 | } |
| 2726 | 2726 | |
| 2727 | 2727 | |
@@ -2742,12 +2742,12 @@ discard block |
||
| 2742 | 2742 | * Résultat du calcul |
| 2743 | 2743 | **/ |
| 2744 | 2744 | function valeur_numerique($expr) { |
| 2745 | - $a = 0; |
|
| 2746 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2747 | - eval("\$a = $expr;"); |
|
| 2748 | - } |
|
| 2745 | + $a = 0; |
|
| 2746 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2747 | + eval("\$a = $expr;"); |
|
| 2748 | + } |
|
| 2749 | 2749 | |
| 2750 | - return intval($a); |
|
| 2750 | + return intval($a); |
|
| 2751 | 2751 | } |
| 2752 | 2752 | |
| 2753 | 2753 | /** |
@@ -2766,7 +2766,7 @@ discard block |
||
| 2766 | 2766 | * Retourne `$a*$b/$c` |
| 2767 | 2767 | **/ |
| 2768 | 2768 | function regledetrois($a, $b, $c) { |
| 2769 | - return round($a * $b / $c); |
|
| 2769 | + return round($a * $b / $c); |
|
| 2770 | 2770 | } |
| 2771 | 2771 | |
| 2772 | 2772 | |
@@ -2789,79 +2789,79 @@ discard block |
||
| 2789 | 2789 | * @return string Suite de champs input hidden |
| 2790 | 2790 | **/ |
| 2791 | 2791 | function form_hidden(?string $action = ''): string { |
| 2792 | - $action ??= ''; |
|
| 2793 | - |
|
| 2794 | - $contexte = []; |
|
| 2795 | - include_spip('inc/urls'); |
|
| 2796 | - if ( |
|
| 2797 | - $p = urls_decoder_url($action, '') |
|
| 2798 | - and reset($p) |
|
| 2799 | - ) { |
|
| 2800 | - $fond = array_shift($p); |
|
| 2801 | - if ($fond != '404') { |
|
| 2802 | - $contexte = array_shift($p); |
|
| 2803 | - $contexte['page'] = $fond; |
|
| 2804 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2805 | - } |
|
| 2806 | - } |
|
| 2807 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2808 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2809 | - unset($contexte['type']); |
|
| 2810 | - } |
|
| 2811 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2812 | - unset($contexte['type-page']); |
|
| 2813 | - } |
|
| 2814 | - |
|
| 2815 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2816 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2817 | - $values = []; |
|
| 2818 | - |
|
| 2819 | - // d'abord avec celles de l'url |
|
| 2820 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2821 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2822 | - $c = explode('=', $c, 2); |
|
| 2823 | - $var = array_shift($c); |
|
| 2824 | - $val = array_shift($c) ?? ''; |
|
| 2825 | - if ($var) { |
|
| 2826 | - $val = rawurldecode($val); |
|
| 2827 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2828 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2829 | - $values[] = [$var, $val]; |
|
| 2830 | - } else { |
|
| 2831 | - if (!isset($values[$var])) { |
|
| 2832 | - $values[$var] = [$var, $val]; |
|
| 2833 | - } |
|
| 2834 | - } |
|
| 2835 | - } |
|
| 2836 | - } |
|
| 2837 | - } |
|
| 2838 | - |
|
| 2839 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2840 | - foreach ($contexte as $var => $val) { |
|
| 2841 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2842 | - $values[] = [$var, $val]; |
|
| 2843 | - } else { |
|
| 2844 | - if (!isset($values[$var])) { |
|
| 2845 | - $values[$var] = [$var, $val]; |
|
| 2846 | - } |
|
| 2847 | - } |
|
| 2848 | - } |
|
| 2849 | - |
|
| 2850 | - // puis on rassemble le tout |
|
| 2851 | - $hidden = []; |
|
| 2852 | - foreach ($values as $value) { |
|
| 2853 | - [$var, $val] = $value; |
|
| 2854 | - $hidden[] = '<input name="' |
|
| 2855 | - . entites_html($var) |
|
| 2856 | - . '"' |
|
| 2857 | - . (is_null($val) |
|
| 2858 | - ? '' |
|
| 2859 | - : ' value="' . entites_html($val) . '"' |
|
| 2860 | - ) |
|
| 2861 | - . ' type="hidden"' . "\n/>"; |
|
| 2862 | - } |
|
| 2863 | - |
|
| 2864 | - return join('', $hidden); |
|
| 2792 | + $action ??= ''; |
|
| 2793 | + |
|
| 2794 | + $contexte = []; |
|
| 2795 | + include_spip('inc/urls'); |
|
| 2796 | + if ( |
|
| 2797 | + $p = urls_decoder_url($action, '') |
|
| 2798 | + and reset($p) |
|
| 2799 | + ) { |
|
| 2800 | + $fond = array_shift($p); |
|
| 2801 | + if ($fond != '404') { |
|
| 2802 | + $contexte = array_shift($p); |
|
| 2803 | + $contexte['page'] = $fond; |
|
| 2804 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2805 | + } |
|
| 2806 | + } |
|
| 2807 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2808 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2809 | + unset($contexte['type']); |
|
| 2810 | + } |
|
| 2811 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2812 | + unset($contexte['type-page']); |
|
| 2813 | + } |
|
| 2814 | + |
|
| 2815 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2816 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2817 | + $values = []; |
|
| 2818 | + |
|
| 2819 | + // d'abord avec celles de l'url |
|
| 2820 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2821 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2822 | + $c = explode('=', $c, 2); |
|
| 2823 | + $var = array_shift($c); |
|
| 2824 | + $val = array_shift($c) ?? ''; |
|
| 2825 | + if ($var) { |
|
| 2826 | + $val = rawurldecode($val); |
|
| 2827 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2828 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2829 | + $values[] = [$var, $val]; |
|
| 2830 | + } else { |
|
| 2831 | + if (!isset($values[$var])) { |
|
| 2832 | + $values[$var] = [$var, $val]; |
|
| 2833 | + } |
|
| 2834 | + } |
|
| 2835 | + } |
|
| 2836 | + } |
|
| 2837 | + } |
|
| 2838 | + |
|
| 2839 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2840 | + foreach ($contexte as $var => $val) { |
|
| 2841 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2842 | + $values[] = [$var, $val]; |
|
| 2843 | + } else { |
|
| 2844 | + if (!isset($values[$var])) { |
|
| 2845 | + $values[$var] = [$var, $val]; |
|
| 2846 | + } |
|
| 2847 | + } |
|
| 2848 | + } |
|
| 2849 | + |
|
| 2850 | + // puis on rassemble le tout |
|
| 2851 | + $hidden = []; |
|
| 2852 | + foreach ($values as $value) { |
|
| 2853 | + [$var, $val] = $value; |
|
| 2854 | + $hidden[] = '<input name="' |
|
| 2855 | + . entites_html($var) |
|
| 2856 | + . '"' |
|
| 2857 | + . (is_null($val) |
|
| 2858 | + ? '' |
|
| 2859 | + : ' value="' . entites_html($val) . '"' |
|
| 2860 | + ) |
|
| 2861 | + . ' type="hidden"' . "\n/>"; |
|
| 2862 | + } |
|
| 2863 | + |
|
| 2864 | + return join('', $hidden); |
|
| 2865 | 2865 | } |
| 2866 | 2866 | |
| 2867 | 2867 | |
@@ -2883,7 +2883,7 @@ discard block |
||
| 2883 | 2883 | * - la première valeur du tableau sinon. |
| 2884 | 2884 | **/ |
| 2885 | 2885 | function filtre_reset($array) { |
| 2886 | - return !is_array($array) ? null : reset($array); |
|
| 2886 | + return !is_array($array) ? null : reset($array); |
|
| 2887 | 2887 | } |
| 2888 | 2888 | |
| 2889 | 2889 | /** |
@@ -2904,7 +2904,7 @@ discard block |
||
| 2904 | 2904 | * - la dernière valeur du tableau sinon. |
| 2905 | 2905 | **/ |
| 2906 | 2906 | function filtre_end($array) { |
| 2907 | - return !is_array($array) ? null : end($array); |
|
| 2907 | + return !is_array($array) ? null : end($array); |
|
| 2908 | 2908 | } |
| 2909 | 2909 | |
| 2910 | 2910 | /** |
@@ -2924,11 +2924,11 @@ discard block |
||
| 2924 | 2924 | * |
| 2925 | 2925 | **/ |
| 2926 | 2926 | function filtre_push($array, $val) { |
| 2927 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2928 | - return ''; |
|
| 2929 | - } |
|
| 2927 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2928 | + return ''; |
|
| 2929 | + } |
|
| 2930 | 2930 | |
| 2931 | - return $array; |
|
| 2931 | + return $array; |
|
| 2932 | 2932 | } |
| 2933 | 2933 | |
| 2934 | 2934 | /** |
@@ -2947,7 +2947,7 @@ discard block |
||
| 2947 | 2947 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2948 | 2948 | **/ |
| 2949 | 2949 | function filtre_find($array, $val) { |
| 2950 | - return (is_array($array) and in_array($val, $array)); |
|
| 2950 | + return (is_array($array) and in_array($val, $array)); |
|
| 2951 | 2951 | } |
| 2952 | 2952 | |
| 2953 | 2953 | |
@@ -2964,13 +2964,13 @@ discard block |
||
| 2964 | 2964 | * Contenu avec urls en absolus |
| 2965 | 2965 | **/ |
| 2966 | 2966 | function urls_absolues_css($contenu, $source) { |
| 2967 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2967 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2968 | 2968 | |
| 2969 | - return preg_replace_callback( |
|
| 2970 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2971 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2972 | - $contenu |
|
| 2973 | - ); |
|
| 2969 | + return preg_replace_callback( |
|
| 2970 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2971 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2972 | + $contenu |
|
| 2973 | + ); |
|
| 2974 | 2974 | } |
| 2975 | 2975 | |
| 2976 | 2976 | |
@@ -2999,119 +2999,119 @@ discard block |
||
| 2999 | 2999 | * Chemin du fichier CSS inversé |
| 3000 | 3000 | **/ |
| 3001 | 3001 | function direction_css($css, $voulue = '') { |
| 3002 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3003 | - return $css; |
|
| 3004 | - } |
|
| 3005 | - include_spip('inc/lang'); |
|
| 3006 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3007 | - if ($voulue = strtolower($voulue)) { |
|
| 3008 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3009 | - $voulue = lang_dir($voulue); |
|
| 3010 | - } |
|
| 3011 | - } else { |
|
| 3012 | - $voulue = lang_dir(); |
|
| 3013 | - } |
|
| 3014 | - |
|
| 3015 | - $r = count($r) > 1; |
|
| 3016 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3017 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 3018 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3019 | - |
|
| 3020 | - if ($voulue == $dir) { |
|
| 3021 | - return $css; |
|
| 3022 | - } |
|
| 3023 | - |
|
| 3024 | - if ( |
|
| 3025 | - // url absolue |
|
| 3026 | - preg_match(',^https?:,i', $css) |
|
| 3027 | - // ou qui contient un ? |
|
| 3028 | - or (($p = strpos($css, '?')) !== false) |
|
| 3029 | - ) { |
|
| 3030 | - $distant = true; |
|
| 3031 | - $cssf = parse_url($css); |
|
| 3032 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3033 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3034 | - } else { |
|
| 3035 | - $distant = false; |
|
| 3036 | - $cssf = $css; |
|
| 3037 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3038 | - //propose (rien a faire dans ce cas) |
|
| 3039 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3040 | - if (@file_exists($f)) { |
|
| 3041 | - return $f; |
|
| 3042 | - } |
|
| 3043 | - } |
|
| 3044 | - |
|
| 3045 | - // 2. |
|
| 3046 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3047 | - $f = $dir_var |
|
| 3048 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3049 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3050 | - |
|
| 3051 | - // la css peut etre distante (url absolue !) |
|
| 3052 | - if ($distant) { |
|
| 3053 | - include_spip('inc/distant'); |
|
| 3054 | - $res = recuperer_url($css); |
|
| 3055 | - if (!$res or !$contenu = $res['page']) { |
|
| 3056 | - return $css; |
|
| 3057 | - } |
|
| 3058 | - } else { |
|
| 3059 | - if ( |
|
| 3060 | - (@filemtime($f) > @filemtime($css)) |
|
| 3061 | - and (_VAR_MODE != 'recalcul') |
|
| 3062 | - ) { |
|
| 3063 | - return $f; |
|
| 3064 | - } |
|
| 3065 | - if (!lire_fichier($css, $contenu)) { |
|
| 3066 | - return $css; |
|
| 3067 | - } |
|
| 3068 | - } |
|
| 3069 | - |
|
| 3070 | - |
|
| 3071 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3072 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3073 | - $parser = new csstidy(); |
|
| 3074 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3075 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3076 | - $parser->parse($contenu); |
|
| 3077 | - |
|
| 3078 | - $contenu = $parser->print->plain(); |
|
| 3079 | - |
|
| 3080 | - |
|
| 3081 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3082 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3083 | - $src = []; |
|
| 3084 | - $src_direction_css = []; |
|
| 3085 | - $src_faux_abs = []; |
|
| 3086 | - $d = dirname($css); |
|
| 3087 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3088 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3089 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3090 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3091 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3092 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3093 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3094 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3095 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3096 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3097 | - } |
|
| 3098 | - $src[] = $regs[0][$k]; |
|
| 3099 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3100 | - } |
|
| 3101 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3102 | - |
|
| 3103 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3104 | - |
|
| 3105 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3106 | - if (count($src_faux_abs)) { |
|
| 3107 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3108 | - } |
|
| 3109 | - |
|
| 3110 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3111 | - return $css; |
|
| 3112 | - } |
|
| 3113 | - |
|
| 3114 | - return $f; |
|
| 3002 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 3003 | + return $css; |
|
| 3004 | + } |
|
| 3005 | + include_spip('inc/lang'); |
|
| 3006 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 3007 | + if ($voulue = strtolower($voulue)) { |
|
| 3008 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 3009 | + $voulue = lang_dir($voulue); |
|
| 3010 | + } |
|
| 3011 | + } else { |
|
| 3012 | + $voulue = lang_dir(); |
|
| 3013 | + } |
|
| 3014 | + |
|
| 3015 | + $r = count($r) > 1; |
|
| 3016 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 3017 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 3018 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 3019 | + |
|
| 3020 | + if ($voulue == $dir) { |
|
| 3021 | + return $css; |
|
| 3022 | + } |
|
| 3023 | + |
|
| 3024 | + if ( |
|
| 3025 | + // url absolue |
|
| 3026 | + preg_match(',^https?:,i', $css) |
|
| 3027 | + // ou qui contient un ? |
|
| 3028 | + or (($p = strpos($css, '?')) !== false) |
|
| 3029 | + ) { |
|
| 3030 | + $distant = true; |
|
| 3031 | + $cssf = parse_url($css); |
|
| 3032 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 3033 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 3034 | + } else { |
|
| 3035 | + $distant = false; |
|
| 3036 | + $cssf = $css; |
|
| 3037 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 3038 | + //propose (rien a faire dans ce cas) |
|
| 3039 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 3040 | + if (@file_exists($f)) { |
|
| 3041 | + return $f; |
|
| 3042 | + } |
|
| 3043 | + } |
|
| 3044 | + |
|
| 3045 | + // 2. |
|
| 3046 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 3047 | + $f = $dir_var |
|
| 3048 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 3049 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 3050 | + |
|
| 3051 | + // la css peut etre distante (url absolue !) |
|
| 3052 | + if ($distant) { |
|
| 3053 | + include_spip('inc/distant'); |
|
| 3054 | + $res = recuperer_url($css); |
|
| 3055 | + if (!$res or !$contenu = $res['page']) { |
|
| 3056 | + return $css; |
|
| 3057 | + } |
|
| 3058 | + } else { |
|
| 3059 | + if ( |
|
| 3060 | + (@filemtime($f) > @filemtime($css)) |
|
| 3061 | + and (_VAR_MODE != 'recalcul') |
|
| 3062 | + ) { |
|
| 3063 | + return $f; |
|
| 3064 | + } |
|
| 3065 | + if (!lire_fichier($css, $contenu)) { |
|
| 3066 | + return $css; |
|
| 3067 | + } |
|
| 3068 | + } |
|
| 3069 | + |
|
| 3070 | + |
|
| 3071 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3072 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3073 | + $parser = new csstidy(); |
|
| 3074 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3075 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3076 | + $parser->parse($contenu); |
|
| 3077 | + |
|
| 3078 | + $contenu = $parser->print->plain(); |
|
| 3079 | + |
|
| 3080 | + |
|
| 3081 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3082 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3083 | + $src = []; |
|
| 3084 | + $src_direction_css = []; |
|
| 3085 | + $src_faux_abs = []; |
|
| 3086 | + $d = dirname($css); |
|
| 3087 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3088 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3089 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3090 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3091 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3092 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3093 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3094 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3095 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3096 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3097 | + } |
|
| 3098 | + $src[] = $regs[0][$k]; |
|
| 3099 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3100 | + } |
|
| 3101 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3102 | + |
|
| 3103 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3104 | + |
|
| 3105 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3106 | + if (count($src_faux_abs)) { |
|
| 3107 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3108 | + } |
|
| 3109 | + |
|
| 3110 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3111 | + return $css; |
|
| 3112 | + } |
|
| 3113 | + |
|
| 3114 | + return $f; |
|
| 3115 | 3115 | } |
| 3116 | 3116 | |
| 3117 | 3117 | |
@@ -3134,46 +3134,46 @@ discard block |
||
| 3134 | 3134 | * - Chemin ou URL du fichier CSS source sinon. |
| 3135 | 3135 | **/ |
| 3136 | 3136 | function url_absolue_css($css) { |
| 3137 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3138 | - return $css; |
|
| 3139 | - } |
|
| 3137 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3138 | + return $css; |
|
| 3139 | + } |
|
| 3140 | 3140 | |
| 3141 | - $url_absolue_css = url_absolue($css); |
|
| 3141 | + $url_absolue_css = url_absolue($css); |
|
| 3142 | 3142 | |
| 3143 | - $f = basename($css, '.css'); |
|
| 3144 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3145 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3146 | - . '.css'; |
|
| 3143 | + $f = basename($css, '.css'); |
|
| 3144 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3145 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3146 | + . '.css'; |
|
| 3147 | 3147 | |
| 3148 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3149 | - return $f; |
|
| 3150 | - } |
|
| 3148 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3149 | + return $f; |
|
| 3150 | + } |
|
| 3151 | 3151 | |
| 3152 | - if ($url_absolue_css == $css) { |
|
| 3153 | - if ( |
|
| 3154 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3155 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3156 | - ) { |
|
| 3157 | - include_spip('inc/distant'); |
|
| 3158 | - $contenu = recuperer_url($css); |
|
| 3159 | - $contenu = $contenu['page'] ?? ''; |
|
| 3160 | - if (!$contenu) { |
|
| 3161 | - return $css; |
|
| 3162 | - } |
|
| 3163 | - } |
|
| 3164 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3165 | - return $css; |
|
| 3166 | - } |
|
| 3152 | + if ($url_absolue_css == $css) { |
|
| 3153 | + if ( |
|
| 3154 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3155 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3156 | + ) { |
|
| 3157 | + include_spip('inc/distant'); |
|
| 3158 | + $contenu = recuperer_url($css); |
|
| 3159 | + $contenu = $contenu['page'] ?? ''; |
|
| 3160 | + if (!$contenu) { |
|
| 3161 | + return $css; |
|
| 3162 | + } |
|
| 3163 | + } |
|
| 3164 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3165 | + return $css; |
|
| 3166 | + } |
|
| 3167 | 3167 | |
| 3168 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3169 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3168 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3169 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3170 | 3170 | |
| 3171 | - // ecrire la css |
|
| 3172 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3173 | - return $css; |
|
| 3174 | - } |
|
| 3171 | + // ecrire la css |
|
| 3172 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3173 | + return $css; |
|
| 3174 | + } |
|
| 3175 | 3175 | |
| 3176 | - return $f; |
|
| 3176 | + return $f; |
|
| 3177 | 3177 | } |
| 3178 | 3178 | |
| 3179 | 3179 | |
@@ -3207,24 +3207,24 @@ discard block |
||
| 3207 | 3207 | * Valeur trouvée ou valeur par défaut. |
| 3208 | 3208 | **/ |
| 3209 | 3209 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3210 | - foreach (explode('/', $cle) as $k) { |
|
| 3211 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3210 | + foreach (explode('/', $cle) as $k) { |
|
| 3211 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3212 | 3212 | |
| 3213 | - if (is_object($table)) { |
|
| 3214 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3215 | - } elseif (is_array($table)) { |
|
| 3216 | - if ($conserver_null) { |
|
| 3217 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3218 | - } else { |
|
| 3219 | - $table = ($table[$k] ?? $defaut); |
|
| 3220 | - } |
|
| 3221 | - } else { |
|
| 3222 | - $table = $defaut; |
|
| 3223 | - break; |
|
| 3224 | - } |
|
| 3225 | - } |
|
| 3213 | + if (is_object($table)) { |
|
| 3214 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3215 | + } elseif (is_array($table)) { |
|
| 3216 | + if ($conserver_null) { |
|
| 3217 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3218 | + } else { |
|
| 3219 | + $table = ($table[$k] ?? $defaut); |
|
| 3220 | + } |
|
| 3221 | + } else { |
|
| 3222 | + $table = $defaut; |
|
| 3223 | + break; |
|
| 3224 | + } |
|
| 3225 | + } |
|
| 3226 | 3226 | |
| 3227 | - return $table; |
|
| 3227 | + return $table; |
|
| 3228 | 3228 | } |
| 3229 | 3229 | |
| 3230 | 3230 | /** |
@@ -3257,22 +3257,22 @@ discard block |
||
| 3257 | 3257 | * - string : expression trouvée. |
| 3258 | 3258 | **/ |
| 3259 | 3259 | function filtre_match_dist(?string $texte, $expression, $modif = 'UimsS', $capte = 0) { |
| 3260 | - if (intval($modif) and $capte == 0) { |
|
| 3261 | - $capte = $modif; |
|
| 3262 | - $modif = 'UimsS'; |
|
| 3263 | - } |
|
| 3264 | - $expression = str_replace('\/', '/', $expression); |
|
| 3265 | - $expression = str_replace('/', '\/', $expression); |
|
| 3260 | + if (intval($modif) and $capte == 0) { |
|
| 3261 | + $capte = $modif; |
|
| 3262 | + $modif = 'UimsS'; |
|
| 3263 | + } |
|
| 3264 | + $expression = str_replace('\/', '/', $expression); |
|
| 3265 | + $expression = str_replace('/', '\/', $expression); |
|
| 3266 | 3266 | |
| 3267 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3268 | - if (isset($r[$capte])) { |
|
| 3269 | - return $r[$capte]; |
|
| 3270 | - } else { |
|
| 3271 | - return true; |
|
| 3272 | - } |
|
| 3273 | - } |
|
| 3267 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3268 | + if (isset($r[$capte])) { |
|
| 3269 | + return $r[$capte]; |
|
| 3270 | + } else { |
|
| 3271 | + return true; |
|
| 3272 | + } |
|
| 3273 | + } |
|
| 3274 | 3274 | |
| 3275 | - return false; |
|
| 3275 | + return false; |
|
| 3276 | 3276 | } |
| 3277 | 3277 | |
| 3278 | 3278 | |
@@ -3299,10 +3299,10 @@ discard block |
||
| 3299 | 3299 | * Texte |
| 3300 | 3300 | **/ |
| 3301 | 3301 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3302 | - $expression = str_replace('\/', '/', $expression); |
|
| 3303 | - $expression = str_replace('/', '\/', $expression); |
|
| 3302 | + $expression = str_replace('\/', '/', $expression); |
|
| 3303 | + $expression = str_replace('/', '\/', $expression); |
|
| 3304 | 3304 | |
| 3305 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3305 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3306 | 3306 | } |
| 3307 | 3307 | |
| 3308 | 3308 | |
@@ -3320,25 +3320,25 @@ discard block |
||
| 3320 | 3320 | **/ |
| 3321 | 3321 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3322 | 3322 | |
| 3323 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3324 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3323 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3324 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3325 | 3325 | |
| 3326 | - if ( |
|
| 3327 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3328 | - and preg_match_all( |
|
| 3329 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3330 | - $t, |
|
| 3331 | - $matches, |
|
| 3332 | - PREG_PATTERN_ORDER |
|
| 3333 | - ) |
|
| 3334 | - ) { |
|
| 3335 | - if (!isset($doublons['documents'])) { |
|
| 3336 | - $doublons['documents'] = ''; |
|
| 3337 | - } |
|
| 3338 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3339 | - } |
|
| 3326 | + if ( |
|
| 3327 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3328 | + and preg_match_all( |
|
| 3329 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3330 | + $t, |
|
| 3331 | + $matches, |
|
| 3332 | + PREG_PATTERN_ORDER |
|
| 3333 | + ) |
|
| 3334 | + ) { |
|
| 3335 | + if (!isset($doublons['documents'])) { |
|
| 3336 | + $doublons['documents'] = ''; |
|
| 3337 | + } |
|
| 3338 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3339 | + } |
|
| 3340 | 3340 | |
| 3341 | - return $letexte; |
|
| 3341 | + return $letexte; |
|
| 3342 | 3342 | } |
| 3343 | 3343 | |
| 3344 | 3344 | /** |
@@ -3352,7 +3352,7 @@ discard block |
||
| 3352 | 3352 | * @return string Chaîne vide |
| 3353 | 3353 | **/ |
| 3354 | 3354 | function vide($texte) { |
| 3355 | - return ''; |
|
| 3355 | + return ''; |
|
| 3356 | 3356 | } |
| 3357 | 3357 | |
| 3358 | 3358 | // |
@@ -3381,23 +3381,23 @@ discard block |
||
| 3381 | 3381 | * Code HTML résultant |
| 3382 | 3382 | **/ |
| 3383 | 3383 | function env_to_params($env, $ignore_params = []) { |
| 3384 | - $ignore_params = array_merge( |
|
| 3385 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3386 | - $ignore_params |
|
| 3387 | - ); |
|
| 3388 | - if (!is_array($env)) { |
|
| 3389 | - $env = unserialize($env); |
|
| 3390 | - } |
|
| 3391 | - $texte = ''; |
|
| 3392 | - if ($env) { |
|
| 3393 | - foreach ($env as $i => $j) { |
|
| 3394 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3395 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3396 | - } |
|
| 3397 | - } |
|
| 3398 | - } |
|
| 3399 | - |
|
| 3400 | - return $texte; |
|
| 3384 | + $ignore_params = array_merge( |
|
| 3385 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3386 | + $ignore_params |
|
| 3387 | + ); |
|
| 3388 | + if (!is_array($env)) { |
|
| 3389 | + $env = unserialize($env); |
|
| 3390 | + } |
|
| 3391 | + $texte = ''; |
|
| 3392 | + if ($env) { |
|
| 3393 | + foreach ($env as $i => $j) { |
|
| 3394 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3395 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3396 | + } |
|
| 3397 | + } |
|
| 3398 | + } |
|
| 3399 | + |
|
| 3400 | + return $texte; |
|
| 3401 | 3401 | } |
| 3402 | 3402 | |
| 3403 | 3403 | /** |
@@ -3420,23 +3420,23 @@ discard block |
||
| 3420 | 3420 | * Code HTML résultant |
| 3421 | 3421 | **/ |
| 3422 | 3422 | function env_to_attributs($env, $ignore_params = []) { |
| 3423 | - $ignore_params = array_merge( |
|
| 3424 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3425 | - $ignore_params |
|
| 3426 | - ); |
|
| 3427 | - if (!is_array($env)) { |
|
| 3428 | - $env = unserialize($env); |
|
| 3429 | - } |
|
| 3430 | - $texte = ''; |
|
| 3431 | - if ($env) { |
|
| 3432 | - foreach ($env as $i => $j) { |
|
| 3433 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3434 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3435 | - } |
|
| 3436 | - } |
|
| 3437 | - } |
|
| 3423 | + $ignore_params = array_merge( |
|
| 3424 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3425 | + $ignore_params |
|
| 3426 | + ); |
|
| 3427 | + if (!is_array($env)) { |
|
| 3428 | + $env = unserialize($env); |
|
| 3429 | + } |
|
| 3430 | + $texte = ''; |
|
| 3431 | + if ($env) { |
|
| 3432 | + foreach ($env as $i => $j) { |
|
| 3433 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3434 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3435 | + } |
|
| 3436 | + } |
|
| 3437 | + } |
|
| 3438 | 3438 | |
| 3439 | - return $texte; |
|
| 3439 | + return $texte; |
|
| 3440 | 3440 | } |
| 3441 | 3441 | |
| 3442 | 3442 | |
@@ -3454,7 +3454,7 @@ discard block |
||
| 3454 | 3454 | * @return string Chaînes concaténés |
| 3455 | 3455 | **/ |
| 3456 | 3456 | function concat(...$args): string { |
| 3457 | - return join('', $args); |
|
| 3457 | + return join('', $args); |
|
| 3458 | 3458 | } |
| 3459 | 3459 | |
| 3460 | 3460 | |
@@ -3474,23 +3474,23 @@ discard block |
||
| 3474 | 3474 | * Contenu du ou des fichiers, concaténé |
| 3475 | 3475 | **/ |
| 3476 | 3476 | function charge_scripts($files, $script = true) { |
| 3477 | - $flux = ''; |
|
| 3478 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3479 | - if (!is_string($file)) { |
|
| 3480 | - continue; |
|
| 3481 | - } |
|
| 3482 | - if ($script) { |
|
| 3483 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3484 | - } |
|
| 3485 | - if ($file) { |
|
| 3486 | - $path = find_in_path($file); |
|
| 3487 | - if ($path) { |
|
| 3488 | - $flux .= spip_file_get_contents($path); |
|
| 3489 | - } |
|
| 3490 | - } |
|
| 3491 | - } |
|
| 3492 | - |
|
| 3493 | - return $flux; |
|
| 3477 | + $flux = ''; |
|
| 3478 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3479 | + if (!is_string($file)) { |
|
| 3480 | + continue; |
|
| 3481 | + } |
|
| 3482 | + if ($script) { |
|
| 3483 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3484 | + } |
|
| 3485 | + if ($file) { |
|
| 3486 | + $path = find_in_path($file); |
|
| 3487 | + if ($path) { |
|
| 3488 | + $flux .= spip_file_get_contents($path); |
|
| 3489 | + } |
|
| 3490 | + } |
|
| 3491 | + } |
|
| 3492 | + |
|
| 3493 | + return $flux; |
|
| 3494 | 3494 | } |
| 3495 | 3495 | |
| 3496 | 3496 | /** |
@@ -3501,22 +3501,22 @@ discard block |
||
| 3501 | 3501 | * @return string |
| 3502 | 3502 | */ |
| 3503 | 3503 | function http_img_variante_svg_si_possible($img_file) { |
| 3504 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3505 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3506 | - if ( |
|
| 3507 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3508 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3509 | - and file_exists($variante_svg_generique) |
|
| 3510 | - ) { |
|
| 3511 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3512 | - $img_file = $variante_svg_size; |
|
| 3513 | - } |
|
| 3514 | - else { |
|
| 3515 | - $img_file = $variante_svg_generique; |
|
| 3516 | - } |
|
| 3517 | - } |
|
| 3504 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3505 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3506 | + if ( |
|
| 3507 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3508 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3509 | + and file_exists($variante_svg_generique) |
|
| 3510 | + ) { |
|
| 3511 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3512 | + $img_file = $variante_svg_size; |
|
| 3513 | + } |
|
| 3514 | + else { |
|
| 3515 | + $img_file = $variante_svg_generique; |
|
| 3516 | + } |
|
| 3517 | + } |
|
| 3518 | 3518 | |
| 3519 | - return $img_file; |
|
| 3519 | + return $img_file; |
|
| 3520 | 3520 | } |
| 3521 | 3521 | |
| 3522 | 3522 | /** |
@@ -3537,54 +3537,54 @@ discard block |
||
| 3537 | 3537 | */ |
| 3538 | 3538 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3539 | 3539 | |
| 3540 | - $img_file = $img; |
|
| 3541 | - if ($p = strpos($img_file, '?')) { |
|
| 3542 | - $img_file = substr($img_file, 0, $p); |
|
| 3543 | - } |
|
| 3544 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3545 | - $img_file = chemin_image($img); |
|
| 3546 | - } |
|
| 3547 | - else { |
|
| 3548 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3549 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3550 | - } |
|
| 3551 | - } |
|
| 3552 | - if (stripos($atts, 'width') === false) { |
|
| 3553 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3554 | - if ( |
|
| 3555 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3556 | - or $options['utiliser_suffixe_size'] == true |
|
| 3557 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3558 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3559 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3560 | - ) { |
|
| 3561 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3562 | - } else { |
|
| 3563 | - $taille = taille_image($img_file); |
|
| 3564 | - [$hauteur, $largeur] = $taille; |
|
| 3565 | - if (!$hauteur or !$largeur) { |
|
| 3566 | - return ''; |
|
| 3567 | - } |
|
| 3568 | - } |
|
| 3569 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3570 | - } |
|
| 3571 | - |
|
| 3572 | - if (file_exists($img_file)) { |
|
| 3573 | - $img_file = timestamp($img_file); |
|
| 3574 | - } |
|
| 3575 | - if ($alt === false) { |
|
| 3576 | - $alt = ''; |
|
| 3577 | - } |
|
| 3578 | - elseif ($alt or $alt === '') { |
|
| 3579 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3580 | - } |
|
| 3581 | - else { |
|
| 3582 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3583 | - } |
|
| 3584 | - return "<img src='$img_file'$alt" |
|
| 3585 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3586 | - . ' ' . ltrim($atts) |
|
| 3587 | - . ' />'; |
|
| 3540 | + $img_file = $img; |
|
| 3541 | + if ($p = strpos($img_file, '?')) { |
|
| 3542 | + $img_file = substr($img_file, 0, $p); |
|
| 3543 | + } |
|
| 3544 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3545 | + $img_file = chemin_image($img); |
|
| 3546 | + } |
|
| 3547 | + else { |
|
| 3548 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3549 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3550 | + } |
|
| 3551 | + } |
|
| 3552 | + if (stripos($atts, 'width') === false) { |
|
| 3553 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3554 | + if ( |
|
| 3555 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3556 | + or $options['utiliser_suffixe_size'] == true |
|
| 3557 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3558 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3559 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3560 | + ) { |
|
| 3561 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3562 | + } else { |
|
| 3563 | + $taille = taille_image($img_file); |
|
| 3564 | + [$hauteur, $largeur] = $taille; |
|
| 3565 | + if (!$hauteur or !$largeur) { |
|
| 3566 | + return ''; |
|
| 3567 | + } |
|
| 3568 | + } |
|
| 3569 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3570 | + } |
|
| 3571 | + |
|
| 3572 | + if (file_exists($img_file)) { |
|
| 3573 | + $img_file = timestamp($img_file); |
|
| 3574 | + } |
|
| 3575 | + if ($alt === false) { |
|
| 3576 | + $alt = ''; |
|
| 3577 | + } |
|
| 3578 | + elseif ($alt or $alt === '') { |
|
| 3579 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3580 | + } |
|
| 3581 | + else { |
|
| 3582 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3583 | + } |
|
| 3584 | + return "<img src='$img_file'$alt" |
|
| 3585 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3586 | + . ' ' . ltrim($atts) |
|
| 3587 | + . ' />'; |
|
| 3588 | 3588 | } |
| 3589 | 3589 | |
| 3590 | 3590 | /** |
@@ -3596,70 +3596,70 @@ discard block |
||
| 3596 | 3596 | * @return string |
| 3597 | 3597 | */ |
| 3598 | 3598 | function http_style_background($img, $att = '', $size = null) { |
| 3599 | - if ($size and is_numeric($size)) { |
|
| 3600 | - $size = trim($size) . 'px'; |
|
| 3601 | - } |
|
| 3602 | - return " style='background" . |
|
| 3603 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3604 | - . ($size ? "background-size:{$size};" : '') |
|
| 3605 | - . "'"; |
|
| 3599 | + if ($size and is_numeric($size)) { |
|
| 3600 | + $size = trim($size) . 'px'; |
|
| 3601 | + } |
|
| 3602 | + return " style='background" . |
|
| 3603 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3604 | + . ($size ? "background-size:{$size};" : '') |
|
| 3605 | + . "'"; |
|
| 3606 | 3606 | } |
| 3607 | 3607 | |
| 3608 | 3608 | |
| 3609 | 3609 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3610 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3611 | - while (is_null(end($args)) and count($args)) { |
|
| 3612 | - array_pop($args); |
|
| 3613 | - } |
|
| 3614 | - if (!count($args)) { |
|
| 3615 | - return [null, null, null]; |
|
| 3616 | - } |
|
| 3617 | - if (count($args) < 3) { |
|
| 3618 | - $maybe_size = array_pop($args); |
|
| 3619 | - // @2x |
|
| 3620 | - // @1.5x |
|
| 3621 | - // 512 |
|
| 3622 | - // 512x* |
|
| 3623 | - // 512x300 |
|
| 3624 | - if ( |
|
| 3625 | - !strlen($maybe_size) |
|
| 3626 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3627 | - ) { |
|
| 3628 | - $args[] = $maybe_size; |
|
| 3629 | - $maybe_size = null; |
|
| 3630 | - } |
|
| 3631 | - while (count($args) < 2) { |
|
| 3632 | - $args[] = null; // default alt or class |
|
| 3633 | - } |
|
| 3634 | - $args[] = $maybe_size; |
|
| 3635 | - } |
|
| 3636 | - return $args; |
|
| 3610 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3611 | + while (is_null(end($args)) and count($args)) { |
|
| 3612 | + array_pop($args); |
|
| 3613 | + } |
|
| 3614 | + if (!count($args)) { |
|
| 3615 | + return [null, null, null]; |
|
| 3616 | + } |
|
| 3617 | + if (count($args) < 3) { |
|
| 3618 | + $maybe_size = array_pop($args); |
|
| 3619 | + // @2x |
|
| 3620 | + // @1.5x |
|
| 3621 | + // 512 |
|
| 3622 | + // 512x* |
|
| 3623 | + // 512x300 |
|
| 3624 | + if ( |
|
| 3625 | + !strlen($maybe_size) |
|
| 3626 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3627 | + ) { |
|
| 3628 | + $args[] = $maybe_size; |
|
| 3629 | + $maybe_size = null; |
|
| 3630 | + } |
|
| 3631 | + while (count($args) < 2) { |
|
| 3632 | + $args[] = null; // default alt or class |
|
| 3633 | + } |
|
| 3634 | + $args[] = $maybe_size; |
|
| 3635 | + } |
|
| 3636 | + return $args; |
|
| 3637 | 3637 | } |
| 3638 | 3638 | |
| 3639 | 3639 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3640 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3641 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3642 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3643 | - [$h, $w] = taille_image($img); |
|
| 3644 | - $height = intval(round($h / $coef)); |
|
| 3645 | - $width = intval(round($w / $coef)); |
|
| 3646 | - } |
|
| 3647 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3648 | - else { |
|
| 3649 | - $size = explode('x', $size, 2); |
|
| 3650 | - $size = array_map('trim', $size); |
|
| 3651 | - $height = $width = intval(array_shift($size)); |
|
| 3652 | - |
|
| 3653 | - if (count($size) and reset($size)) { |
|
| 3654 | - $height = array_shift($size); |
|
| 3655 | - if ($height === '*') { |
|
| 3656 | - [$h, $w] = taille_image($img); |
|
| 3657 | - $height = intval(round($h * $width / $w)); |
|
| 3658 | - } |
|
| 3659 | - } |
|
| 3660 | - } |
|
| 3661 | - |
|
| 3662 | - return [$width, $height]; |
|
| 3640 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3641 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3642 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3643 | + [$h, $w] = taille_image($img); |
|
| 3644 | + $height = intval(round($h / $coef)); |
|
| 3645 | + $width = intval(round($w / $coef)); |
|
| 3646 | + } |
|
| 3647 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3648 | + else { |
|
| 3649 | + $size = explode('x', $size, 2); |
|
| 3650 | + $size = array_map('trim', $size); |
|
| 3651 | + $height = $width = intval(array_shift($size)); |
|
| 3652 | + |
|
| 3653 | + if (count($size) and reset($size)) { |
|
| 3654 | + $height = array_shift($size); |
|
| 3655 | + if ($height === '*') { |
|
| 3656 | + [$h, $w] = taille_image($img); |
|
| 3657 | + $height = intval(round($h * $width / $w)); |
|
| 3658 | + } |
|
| 3659 | + } |
|
| 3660 | + } |
|
| 3661 | + |
|
| 3662 | + return [$width, $height]; |
|
| 3663 | 3663 | } |
| 3664 | 3664 | |
| 3665 | 3665 | /** |
@@ -3695,43 +3695,43 @@ discard block |
||
| 3695 | 3695 | */ |
| 3696 | 3696 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3697 | 3697 | |
| 3698 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3699 | - |
|
| 3700 | - $img = trim((string) $img); |
|
| 3701 | - if (strpos($img, '<img') === 0) { |
|
| 3702 | - if (!is_null($alt)) { |
|
| 3703 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3704 | - } |
|
| 3705 | - if (!is_null($class)) { |
|
| 3706 | - if (strlen($class)) { |
|
| 3707 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3708 | - } |
|
| 3709 | - else { |
|
| 3710 | - $img = vider_attribut($img, 'class'); |
|
| 3711 | - } |
|
| 3712 | - } |
|
| 3713 | - } |
|
| 3714 | - else { |
|
| 3715 | - $img = http_img_pack( |
|
| 3716 | - $img, |
|
| 3717 | - $alt, |
|
| 3718 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3719 | - '', |
|
| 3720 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3721 | - ); |
|
| 3722 | - if (is_null($alt)) { |
|
| 3723 | - $img = vider_attribut($img, 'alt'); |
|
| 3724 | - } |
|
| 3725 | - } |
|
| 3726 | - |
|
| 3727 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3728 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3729 | - |
|
| 3730 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3731 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3732 | - } |
|
| 3733 | - |
|
| 3734 | - return $img; |
|
| 3698 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3699 | + |
|
| 3700 | + $img = trim((string) $img); |
|
| 3701 | + if (strpos($img, '<img') === 0) { |
|
| 3702 | + if (!is_null($alt)) { |
|
| 3703 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3704 | + } |
|
| 3705 | + if (!is_null($class)) { |
|
| 3706 | + if (strlen($class)) { |
|
| 3707 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3708 | + } |
|
| 3709 | + else { |
|
| 3710 | + $img = vider_attribut($img, 'class'); |
|
| 3711 | + } |
|
| 3712 | + } |
|
| 3713 | + } |
|
| 3714 | + else { |
|
| 3715 | + $img = http_img_pack( |
|
| 3716 | + $img, |
|
| 3717 | + $alt, |
|
| 3718 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3719 | + '', |
|
| 3720 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3721 | + ); |
|
| 3722 | + if (is_null($alt)) { |
|
| 3723 | + $img = vider_attribut($img, 'alt'); |
|
| 3724 | + } |
|
| 3725 | + } |
|
| 3726 | + |
|
| 3727 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3728 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3729 | + |
|
| 3730 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3731 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3732 | + } |
|
| 3733 | + |
|
| 3734 | + return $img; |
|
| 3735 | 3735 | } |
| 3736 | 3736 | |
| 3737 | 3737 | |
@@ -3765,80 +3765,80 @@ discard block |
||
| 3765 | 3765 | */ |
| 3766 | 3766 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3767 | 3767 | |
| 3768 | - $svg = null; |
|
| 3769 | - $img = trim($img); |
|
| 3770 | - $img_file = $img; |
|
| 3771 | - if (strpos($img, '<svg') === false) { |
|
| 3772 | - if ($p = strpos($img_file, '?')) { |
|
| 3773 | - $img_file = substr($img_file, 0, $p); |
|
| 3774 | - } |
|
| 3775 | - |
|
| 3776 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3777 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3778 | - if (tester_url_absolue($img_file)) { |
|
| 3779 | - include_spip('inc/distant'); |
|
| 3780 | - $fichier = copie_locale($img_file); |
|
| 3781 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3782 | - } |
|
| 3783 | - |
|
| 3784 | - if ( |
|
| 3785 | - !$img_file |
|
| 3786 | - or !file_exists($img_file) |
|
| 3787 | - or !$svg = file_get_contents($img_file) |
|
| 3788 | - ) { |
|
| 3789 | - return ''; |
|
| 3790 | - } |
|
| 3791 | - } |
|
| 3792 | - |
|
| 3793 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3794 | - return ''; |
|
| 3795 | - } |
|
| 3796 | - |
|
| 3797 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3798 | - |
|
| 3799 | - $balise_svg = $match[0]; |
|
| 3800 | - $balise_svg_source = $balise_svg; |
|
| 3801 | - |
|
| 3802 | - // entete XML à supprimer |
|
| 3803 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3804 | - |
|
| 3805 | - // IE est toujours mon ami |
|
| 3806 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3807 | - |
|
| 3808 | - // regler la classe |
|
| 3809 | - if (!is_null($class)) { |
|
| 3810 | - if (strlen($class)) { |
|
| 3811 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3812 | - } |
|
| 3813 | - else { |
|
| 3814 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3815 | - } |
|
| 3816 | - } |
|
| 3817 | - |
|
| 3818 | - // regler le alt |
|
| 3819 | - if ($alt) { |
|
| 3820 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3821 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3822 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3823 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3824 | - $balise_svg .= $title; |
|
| 3825 | - } |
|
| 3826 | - else { |
|
| 3827 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3828 | - } |
|
| 3829 | - |
|
| 3830 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3831 | - |
|
| 3832 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3833 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3834 | - |
|
| 3835 | - if (!function_exists('svg_redimensionner')) { |
|
| 3836 | - include_spip('inc/svg'); |
|
| 3837 | - } |
|
| 3838 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3839 | - } |
|
| 3840 | - |
|
| 3841 | - return $svg; |
|
| 3768 | + $svg = null; |
|
| 3769 | + $img = trim($img); |
|
| 3770 | + $img_file = $img; |
|
| 3771 | + if (strpos($img, '<svg') === false) { |
|
| 3772 | + if ($p = strpos($img_file, '?')) { |
|
| 3773 | + $img_file = substr($img_file, 0, $p); |
|
| 3774 | + } |
|
| 3775 | + |
|
| 3776 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3777 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3778 | + if (tester_url_absolue($img_file)) { |
|
| 3779 | + include_spip('inc/distant'); |
|
| 3780 | + $fichier = copie_locale($img_file); |
|
| 3781 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3782 | + } |
|
| 3783 | + |
|
| 3784 | + if ( |
|
| 3785 | + !$img_file |
|
| 3786 | + or !file_exists($img_file) |
|
| 3787 | + or !$svg = file_get_contents($img_file) |
|
| 3788 | + ) { |
|
| 3789 | + return ''; |
|
| 3790 | + } |
|
| 3791 | + } |
|
| 3792 | + |
|
| 3793 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3794 | + return ''; |
|
| 3795 | + } |
|
| 3796 | + |
|
| 3797 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3798 | + |
|
| 3799 | + $balise_svg = $match[0]; |
|
| 3800 | + $balise_svg_source = $balise_svg; |
|
| 3801 | + |
|
| 3802 | + // entete XML à supprimer |
|
| 3803 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3804 | + |
|
| 3805 | + // IE est toujours mon ami |
|
| 3806 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3807 | + |
|
| 3808 | + // regler la classe |
|
| 3809 | + if (!is_null($class)) { |
|
| 3810 | + if (strlen($class)) { |
|
| 3811 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3812 | + } |
|
| 3813 | + else { |
|
| 3814 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3815 | + } |
|
| 3816 | + } |
|
| 3817 | + |
|
| 3818 | + // regler le alt |
|
| 3819 | + if ($alt) { |
|
| 3820 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3821 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3822 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3823 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3824 | + $balise_svg .= $title; |
|
| 3825 | + } |
|
| 3826 | + else { |
|
| 3827 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3828 | + } |
|
| 3829 | + |
|
| 3830 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3831 | + |
|
| 3832 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3833 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3834 | + |
|
| 3835 | + if (!function_exists('svg_redimensionner')) { |
|
| 3836 | + include_spip('inc/svg'); |
|
| 3837 | + } |
|
| 3838 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3839 | + } |
|
| 3840 | + |
|
| 3841 | + return $svg; |
|
| 3842 | 3842 | } |
| 3843 | 3843 | |
| 3844 | 3844 | |
@@ -3864,18 +3864,18 @@ discard block |
||
| 3864 | 3864 | * Code HTML résultant |
| 3865 | 3865 | **/ |
| 3866 | 3866 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3867 | - $texte = ''; |
|
| 3868 | - if (is_array($tableau)) { |
|
| 3869 | - foreach ($tableau as $k => $v) { |
|
| 3870 | - $res = recuperer_fond( |
|
| 3871 | - 'modeles/' . $modele, |
|
| 3872 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3873 | - ); |
|
| 3874 | - $texte .= $res; |
|
| 3875 | - } |
|
| 3876 | - } |
|
| 3867 | + $texte = ''; |
|
| 3868 | + if (is_array($tableau)) { |
|
| 3869 | + foreach ($tableau as $k => $v) { |
|
| 3870 | + $res = recuperer_fond( |
|
| 3871 | + 'modeles/' . $modele, |
|
| 3872 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3873 | + ); |
|
| 3874 | + $texte .= $res; |
|
| 3875 | + } |
|
| 3876 | + } |
|
| 3877 | 3877 | |
| 3878 | - return $texte; |
|
| 3878 | + return $texte; |
|
| 3879 | 3879 | } |
| 3880 | 3880 | |
| 3881 | 3881 | |
@@ -3900,37 +3900,37 @@ discard block |
||
| 3900 | 3900 | * - tout : retourne toutes les informations du plugin actif |
| 3901 | 3901 | **/ |
| 3902 | 3902 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3903 | - include_spip('inc/plugin'); |
|
| 3904 | - $plugin = strtoupper($plugin); |
|
| 3905 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3906 | - |
|
| 3907 | - if (!$plugin) { |
|
| 3908 | - return serialize(array_keys($plugins_actifs)); |
|
| 3909 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3910 | - return ''; |
|
| 3911 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3912 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3913 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3914 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3915 | - } else { |
|
| 3916 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3917 | - // On prend en compte les extensions |
|
| 3918 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3919 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3920 | - } else { |
|
| 3921 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3922 | - } |
|
| 3923 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3924 | - return ''; |
|
| 3925 | - } |
|
| 3926 | - if ($type_info == 'tout') { |
|
| 3927 | - return $infos; |
|
| 3928 | - } elseif ($type_info == 'est_actif') { |
|
| 3929 | - return $infos ? 1 : 0; |
|
| 3930 | - } else { |
|
| 3931 | - return strval($infos[$type_info]); |
|
| 3932 | - } |
|
| 3933 | - } |
|
| 3903 | + include_spip('inc/plugin'); |
|
| 3904 | + $plugin = strtoupper($plugin); |
|
| 3905 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3906 | + |
|
| 3907 | + if (!$plugin) { |
|
| 3908 | + return serialize(array_keys($plugins_actifs)); |
|
| 3909 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3910 | + return ''; |
|
| 3911 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3912 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3913 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3914 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3915 | + } else { |
|
| 3916 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3917 | + // On prend en compte les extensions |
|
| 3918 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3919 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3920 | + } else { |
|
| 3921 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3922 | + } |
|
| 3923 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3924 | + return ''; |
|
| 3925 | + } |
|
| 3926 | + if ($type_info == 'tout') { |
|
| 3927 | + return $infos; |
|
| 3928 | + } elseif ($type_info == 'est_actif') { |
|
| 3929 | + return $infos ? 1 : 0; |
|
| 3930 | + } else { |
|
| 3931 | + return strval($infos[$type_info]); |
|
| 3932 | + } |
|
| 3933 | + } |
|
| 3934 | 3934 | } |
| 3935 | 3935 | |
| 3936 | 3936 | |
@@ -3957,9 +3957,9 @@ discard block |
||
| 3957 | 3957 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3958 | 3958 | */ |
| 3959 | 3959 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3960 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3960 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3961 | 3961 | |
| 3962 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3962 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3963 | 3963 | } |
| 3964 | 3964 | |
| 3965 | 3965 | |
@@ -3989,19 +3989,19 @@ discard block |
||
| 3989 | 3989 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3990 | 3990 | */ |
| 3991 | 3991 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3992 | - static $puce_statut = null; |
|
| 3993 | - if (!$puce_statut) { |
|
| 3994 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3995 | - } |
|
| 3992 | + static $puce_statut = null; |
|
| 3993 | + if (!$puce_statut) { |
|
| 3994 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3995 | + } |
|
| 3996 | 3996 | |
| 3997 | - return $puce_statut( |
|
| 3998 | - $id_objet, |
|
| 3999 | - $statut, |
|
| 4000 | - $id_parent, |
|
| 4001 | - $objet, |
|
| 4002 | - false, |
|
| 4003 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4004 | - ); |
|
| 3997 | + return $puce_statut( |
|
| 3998 | + $id_objet, |
|
| 3999 | + $statut, |
|
| 4000 | + $id_parent, |
|
| 4001 | + $objet, |
|
| 4002 | + false, |
|
| 4003 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 4004 | + ); |
|
| 4005 | 4005 | } |
| 4006 | 4006 | |
| 4007 | 4007 | |
@@ -4028,98 +4028,98 @@ discard block |
||
| 4028 | 4028 | * hash du contexte |
| 4029 | 4029 | */ |
| 4030 | 4030 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 4031 | - $env = null; |
|
| 4032 | - if ( |
|
| 4033 | - is_string($c) |
|
| 4034 | - and @unserialize($c) !== false |
|
| 4035 | - ) { |
|
| 4036 | - $c = unserialize($c); |
|
| 4037 | - } |
|
| 4038 | - |
|
| 4039 | - // supprimer les parametres debut_x |
|
| 4040 | - // pour que la pagination ajax ne soit pas plantee |
|
| 4041 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4042 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4043 | - if (is_array($c)) { |
|
| 4044 | - foreach ($c as $k => $v) { |
|
| 4045 | - if (strpos($k, 'debut_') === 0) { |
|
| 4046 | - unset($c[$k]); |
|
| 4047 | - } |
|
| 4048 | - } |
|
| 4049 | - } |
|
| 4050 | - |
|
| 4051 | - if (!function_exists('calculer_cle_action')) { |
|
| 4052 | - include_spip('inc/securiser_action'); |
|
| 4053 | - } |
|
| 4054 | - |
|
| 4055 | - $c = serialize($c); |
|
| 4056 | - $cle = calculer_cle_action($form . $c); |
|
| 4057 | - $c = "$cle:$c"; |
|
| 4058 | - |
|
| 4059 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4060 | - // par defaut, sauf si cette configuration a été forcée |
|
| 4061 | - // OU que la longueur de l’argument géneré est plus long |
|
| 4062 | - // que ce qui est toléré. |
|
| 4063 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4064 | - if (!$cache_contextes_ajax) { |
|
| 4065 | - $env = $c; |
|
| 4066 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4067 | - $env = gzdeflate($env); |
|
| 4068 | - } |
|
| 4069 | - $env = _xor($env); |
|
| 4070 | - $env = base64_encode($env); |
|
| 4071 | - $len = strlen($env); |
|
| 4072 | - // Si l’url est trop longue pour le navigateur |
|
| 4073 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4074 | - if ($len > $max_len) { |
|
| 4075 | - $cache_contextes_ajax = true; |
|
| 4076 | - spip_log( |
|
| 4077 | - 'Contextes AJAX forces en fichiers !' |
|
| 4078 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4079 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4080 | - _LOG_AVERTISSEMENT |
|
| 4081 | - ); |
|
| 4082 | - } |
|
| 4083 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4084 | - elseif ( |
|
| 4085 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4086 | - and $max_len < $len |
|
| 4087 | - ) { |
|
| 4088 | - $cache_contextes_ajax = true; |
|
| 4089 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4090 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4091 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4092 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4093 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4094 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4095 | - } |
|
| 4096 | - } |
|
| 4097 | - |
|
| 4098 | - if ($cache_contextes_ajax) { |
|
| 4099 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4100 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4101 | - $md5 = md5($c); |
|
| 4102 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4103 | - $env = $md5; |
|
| 4104 | - } |
|
| 4105 | - |
|
| 4106 | - if ($emboite === null) { |
|
| 4107 | - return $env; |
|
| 4108 | - } |
|
| 4109 | - if (!trim($emboite)) { |
|
| 4110 | - return ''; |
|
| 4111 | - } |
|
| 4112 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4113 | - $r = self(); |
|
| 4114 | - $r = ' data-origin="' . $r . '"'; |
|
| 4115 | - $class = 'ajaxbloc'; |
|
| 4116 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4117 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4118 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4119 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4120 | - } |
|
| 4121 | - |
|
| 4122 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4031 | + $env = null; |
|
| 4032 | + if ( |
|
| 4033 | + is_string($c) |
|
| 4034 | + and @unserialize($c) !== false |
|
| 4035 | + ) { |
|
| 4036 | + $c = unserialize($c); |
|
| 4037 | + } |
|
| 4038 | + |
|
| 4039 | + // supprimer les parametres debut_x |
|
| 4040 | + // pour que la pagination ajax ne soit pas plantee |
|
| 4041 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 4042 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 4043 | + if (is_array($c)) { |
|
| 4044 | + foreach ($c as $k => $v) { |
|
| 4045 | + if (strpos($k, 'debut_') === 0) { |
|
| 4046 | + unset($c[$k]); |
|
| 4047 | + } |
|
| 4048 | + } |
|
| 4049 | + } |
|
| 4050 | + |
|
| 4051 | + if (!function_exists('calculer_cle_action')) { |
|
| 4052 | + include_spip('inc/securiser_action'); |
|
| 4053 | + } |
|
| 4054 | + |
|
| 4055 | + $c = serialize($c); |
|
| 4056 | + $cle = calculer_cle_action($form . $c); |
|
| 4057 | + $c = "$cle:$c"; |
|
| 4058 | + |
|
| 4059 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 4060 | + // par defaut, sauf si cette configuration a été forcée |
|
| 4061 | + // OU que la longueur de l’argument géneré est plus long |
|
| 4062 | + // que ce qui est toléré. |
|
| 4063 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 4064 | + if (!$cache_contextes_ajax) { |
|
| 4065 | + $env = $c; |
|
| 4066 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4067 | + $env = gzdeflate($env); |
|
| 4068 | + } |
|
| 4069 | + $env = _xor($env); |
|
| 4070 | + $env = base64_encode($env); |
|
| 4071 | + $len = strlen($env); |
|
| 4072 | + // Si l’url est trop longue pour le navigateur |
|
| 4073 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4074 | + if ($len > $max_len) { |
|
| 4075 | + $cache_contextes_ajax = true; |
|
| 4076 | + spip_log( |
|
| 4077 | + 'Contextes AJAX forces en fichiers !' |
|
| 4078 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4079 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4080 | + _LOG_AVERTISSEMENT |
|
| 4081 | + ); |
|
| 4082 | + } |
|
| 4083 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4084 | + elseif ( |
|
| 4085 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4086 | + and $max_len < $len |
|
| 4087 | + ) { |
|
| 4088 | + $cache_contextes_ajax = true; |
|
| 4089 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4090 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4091 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4092 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4093 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4094 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4095 | + } |
|
| 4096 | + } |
|
| 4097 | + |
|
| 4098 | + if ($cache_contextes_ajax) { |
|
| 4099 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4100 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4101 | + $md5 = md5($c); |
|
| 4102 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4103 | + $env = $md5; |
|
| 4104 | + } |
|
| 4105 | + |
|
| 4106 | + if ($emboite === null) { |
|
| 4107 | + return $env; |
|
| 4108 | + } |
|
| 4109 | + if (!trim($emboite)) { |
|
| 4110 | + return ''; |
|
| 4111 | + } |
|
| 4112 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4113 | + $r = self(); |
|
| 4114 | + $r = ' data-origin="' . $r . '"'; |
|
| 4115 | + $class = 'ajaxbloc'; |
|
| 4116 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4117 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4118 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4119 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4120 | + } |
|
| 4121 | + |
|
| 4122 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4123 | 4123 | } |
| 4124 | 4124 | |
| 4125 | 4125 | /** |
@@ -4139,37 +4139,37 @@ discard block |
||
| 4139 | 4139 | * - false : erreur de décodage |
| 4140 | 4140 | */ |
| 4141 | 4141 | function decoder_contexte_ajax($c, $form = '') { |
| 4142 | - if (!function_exists('calculer_cle_action')) { |
|
| 4143 | - include_spip('inc/securiser_action'); |
|
| 4144 | - } |
|
| 4145 | - if ( |
|
| 4146 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4147 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4148 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4149 | - ) { |
|
| 4150 | - $c = $contexte; |
|
| 4151 | - } else { |
|
| 4152 | - $c = @base64_decode($c); |
|
| 4153 | - $c = _xor($c); |
|
| 4154 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4155 | - $c = @gzinflate($c); |
|
| 4156 | - } |
|
| 4157 | - } |
|
| 4158 | - |
|
| 4159 | - // extraire la signature en debut de contexte |
|
| 4160 | - // et la verifier avant de deserializer |
|
| 4161 | - // format : signature:donneesserializees |
|
| 4162 | - if ($p = strpos($c, ':')) { |
|
| 4163 | - $cle = substr($c, 0, $p); |
|
| 4164 | - $c = substr($c, $p + 1); |
|
| 4165 | - |
|
| 4166 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4167 | - $env = @unserialize($c); |
|
| 4168 | - return $env; |
|
| 4169 | - } |
|
| 4170 | - } |
|
| 4171 | - |
|
| 4172 | - return false; |
|
| 4142 | + if (!function_exists('calculer_cle_action')) { |
|
| 4143 | + include_spip('inc/securiser_action'); |
|
| 4144 | + } |
|
| 4145 | + if ( |
|
| 4146 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4147 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4148 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4149 | + ) { |
|
| 4150 | + $c = $contexte; |
|
| 4151 | + } else { |
|
| 4152 | + $c = @base64_decode($c); |
|
| 4153 | + $c = _xor($c); |
|
| 4154 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4155 | + $c = @gzinflate($c); |
|
| 4156 | + } |
|
| 4157 | + } |
|
| 4158 | + |
|
| 4159 | + // extraire la signature en debut de contexte |
|
| 4160 | + // et la verifier avant de deserializer |
|
| 4161 | + // format : signature:donneesserializees |
|
| 4162 | + if ($p = strpos($c, ':')) { |
|
| 4163 | + $cle = substr($c, 0, $p); |
|
| 4164 | + $c = substr($c, $p + 1); |
|
| 4165 | + |
|
| 4166 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4167 | + $env = @unserialize($c); |
|
| 4168 | + return $env; |
|
| 4169 | + } |
|
| 4170 | + } |
|
| 4171 | + |
|
| 4172 | + return false; |
|
| 4173 | 4173 | } |
| 4174 | 4174 | |
| 4175 | 4175 | |
@@ -4187,20 +4187,20 @@ discard block |
||
| 4187 | 4187 | * Message décrypté ou encrypté |
| 4188 | 4188 | **/ |
| 4189 | 4189 | function _xor($message, $key = null) { |
| 4190 | - if (is_null($key)) { |
|
| 4191 | - if (!function_exists('calculer_cle_action')) { |
|
| 4192 | - include_spip('inc/securiser_action'); |
|
| 4193 | - } |
|
| 4194 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4195 | - } |
|
| 4190 | + if (is_null($key)) { |
|
| 4191 | + if (!function_exists('calculer_cle_action')) { |
|
| 4192 | + include_spip('inc/securiser_action'); |
|
| 4193 | + } |
|
| 4194 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4195 | + } |
|
| 4196 | 4196 | |
| 4197 | - $keylen = strlen($key); |
|
| 4198 | - $messagelen = strlen($message); |
|
| 4199 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4200 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4201 | - } |
|
| 4197 | + $keylen = strlen($key); |
|
| 4198 | + $messagelen = strlen($message); |
|
| 4199 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4200 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4201 | + } |
|
| 4202 | 4202 | |
| 4203 | - return $message; |
|
| 4203 | + return $message; |
|
| 4204 | 4204 | } |
| 4205 | 4205 | |
| 4206 | 4206 | /** |
@@ -4214,7 +4214,7 @@ discard block |
||
| 4214 | 4214 | * @return string |
| 4215 | 4215 | */ |
| 4216 | 4216 | function url_reponse_forum($texte) { |
| 4217 | - return $texte; |
|
| 4217 | + return $texte; |
|
| 4218 | 4218 | } |
| 4219 | 4219 | |
| 4220 | 4220 | /** |
@@ -4228,7 +4228,7 @@ discard block |
||
| 4228 | 4228 | * @return string |
| 4229 | 4229 | */ |
| 4230 | 4230 | function url_rss_forum($texte) { |
| 4231 | - return $texte; |
|
| 4231 | + return $texte; |
|
| 4232 | 4232 | } |
| 4233 | 4233 | |
| 4234 | 4234 | |
@@ -4267,37 +4267,37 @@ discard block |
||
| 4267 | 4267 | * Code HTML |
| 4268 | 4268 | */ |
| 4269 | 4269 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4270 | - if ($on) { |
|
| 4271 | - $bal = 'strong'; |
|
| 4272 | - $class = ''; |
|
| 4273 | - $att = ''; |
|
| 4274 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4275 | - // a.active span.selected.active etc.... |
|
| 4276 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4277 | - $on = explode('.', $on); |
|
| 4278 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4279 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4280 | - $bal = array_shift($on); |
|
| 4281 | - $class = implode(' ', $on); |
|
| 4282 | - if ($bal == 'a') { |
|
| 4283 | - $att = 'href="#" '; |
|
| 4284 | - } |
|
| 4285 | - } |
|
| 4286 | - } |
|
| 4287 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4288 | - } else { |
|
| 4289 | - $bal = 'a'; |
|
| 4290 | - $att = "href='$url'" |
|
| 4291 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4292 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4293 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4294 | - . $evt; |
|
| 4295 | - } |
|
| 4296 | - if ($libelle === null) { |
|
| 4297 | - $libelle = $url; |
|
| 4298 | - } |
|
| 4299 | - |
|
| 4300 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4270 | + if ($on) { |
|
| 4271 | + $bal = 'strong'; |
|
| 4272 | + $class = ''; |
|
| 4273 | + $att = ''; |
|
| 4274 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4275 | + // a.active span.selected.active etc.... |
|
| 4276 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4277 | + $on = explode('.', $on); |
|
| 4278 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4279 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4280 | + $bal = array_shift($on); |
|
| 4281 | + $class = implode(' ', $on); |
|
| 4282 | + if ($bal == 'a') { |
|
| 4283 | + $att = 'href="#" '; |
|
| 4284 | + } |
|
| 4285 | + } |
|
| 4286 | + } |
|
| 4287 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4288 | + } else { |
|
| 4289 | + $bal = 'a'; |
|
| 4290 | + $att = "href='$url'" |
|
| 4291 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4292 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4293 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4294 | + . $evt; |
|
| 4295 | + } |
|
| 4296 | + if ($libelle === null) { |
|
| 4297 | + $libelle = $url; |
|
| 4298 | + } |
|
| 4299 | + |
|
| 4300 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4301 | 4301 | } |
| 4302 | 4302 | |
| 4303 | 4303 | |
@@ -4314,39 +4314,39 @@ discard block |
||
| 4314 | 4314 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4315 | 4315 | */ |
| 4316 | 4316 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4317 | - static $local_singulier_ou_pluriel = []; |
|
| 4318 | - |
|
| 4319 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4320 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4321 | - return ''; |
|
| 4322 | - } |
|
| 4323 | - if (!is_array($vars)) { |
|
| 4324 | - return ''; |
|
| 4325 | - } |
|
| 4326 | - |
|
| 4327 | - $langue = $GLOBALS['spip_lang']; |
|
| 4328 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4329 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4330 | - if ( |
|
| 4331 | - $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4332 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4333 | - ) { |
|
| 4334 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4335 | - } |
|
| 4336 | - } |
|
| 4337 | - |
|
| 4338 | - // si on a une surcharge on l'utilise |
|
| 4339 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4340 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4341 | - } |
|
| 4342 | - |
|
| 4343 | - // sinon traitement par defaut |
|
| 4344 | - $vars[$var] = $nb; |
|
| 4345 | - if ($nb >= 2) { |
|
| 4346 | - return _T($chaine_plusieurs, $vars); |
|
| 4347 | - } else { |
|
| 4348 | - return _T($chaine_un, $vars); |
|
| 4349 | - } |
|
| 4317 | + static $local_singulier_ou_pluriel = []; |
|
| 4318 | + |
|
| 4319 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4320 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4321 | + return ''; |
|
| 4322 | + } |
|
| 4323 | + if (!is_array($vars)) { |
|
| 4324 | + return ''; |
|
| 4325 | + } |
|
| 4326 | + |
|
| 4327 | + $langue = $GLOBALS['spip_lang']; |
|
| 4328 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4329 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4330 | + if ( |
|
| 4331 | + $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4332 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4333 | + ) { |
|
| 4334 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4335 | + } |
|
| 4336 | + } |
|
| 4337 | + |
|
| 4338 | + // si on a une surcharge on l'utilise |
|
| 4339 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4340 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4341 | + } |
|
| 4342 | + |
|
| 4343 | + // sinon traitement par defaut |
|
| 4344 | + $vars[$var] = $nb; |
|
| 4345 | + if ($nb >= 2) { |
|
| 4346 | + return _T($chaine_plusieurs, $vars); |
|
| 4347 | + } else { |
|
| 4348 | + return _T($chaine_un, $vars); |
|
| 4349 | + } |
|
| 4350 | 4350 | } |
| 4351 | 4351 | |
| 4352 | 4352 | |
@@ -4374,73 +4374,73 @@ discard block |
||
| 4374 | 4374 | */ |
| 4375 | 4375 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4376 | 4376 | |
| 4377 | - $class_lien = $class_bouton = $class; |
|
| 4378 | - |
|
| 4379 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4380 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4381 | - $class_lien .= ' danger'; |
|
| 4382 | - $class_bouton .= ' btn_danger'; |
|
| 4383 | - } elseif ($fonction == 'rien.gif') { |
|
| 4384 | - $fonction = ''; |
|
| 4385 | - } elseif ($fonction == 'delsafe') { |
|
| 4386 | - $fonction = 'del'; |
|
| 4387 | - } |
|
| 4388 | - |
|
| 4389 | - $fond_origine = $fond; |
|
| 4390 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4391 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4392 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4393 | - } |
|
| 4394 | - |
|
| 4395 | - // Ajouter le type d'objet dans la classe |
|
| 4396 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4397 | - $class_lien .= " $objet_type"; |
|
| 4398 | - $class_bouton .= " $objet_type"; |
|
| 4399 | - |
|
| 4400 | - // Texte |
|
| 4401 | - $alt = attribut_html($texte); |
|
| 4402 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4403 | - |
|
| 4404 | - // Liens : préparer les classes ajax |
|
| 4405 | - $ajax = ''; |
|
| 4406 | - if ($type === 'lien') { |
|
| 4407 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4408 | - $ajax = 'ajax'; |
|
| 4409 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4410 | - $ajax .= ' preload'; |
|
| 4411 | - } |
|
| 4412 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4413 | - $ajax .= ' nocache'; |
|
| 4414 | - } |
|
| 4415 | - $ajax = " class='$ajax'"; |
|
| 4416 | - } |
|
| 4417 | - } |
|
| 4418 | - |
|
| 4419 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4420 | - $size = 24; |
|
| 4421 | - if ( |
|
| 4422 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4423 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4424 | - ) { |
|
| 4425 | - $size = $match[1]; |
|
| 4426 | - } |
|
| 4427 | - $class_lien .= " s$size"; |
|
| 4428 | - $class_bouton .= " s$size"; |
|
| 4429 | - |
|
| 4430 | - // Icône |
|
| 4431 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4432 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4433 | - |
|
| 4434 | - // Markup final |
|
| 4435 | - if ($type == 'lien') { |
|
| 4436 | - return "<span class='icone $class_lien'>" |
|
| 4437 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4438 | - . $icone |
|
| 4439 | - . "<b>$texte</b>" |
|
| 4440 | - . "</a></span>\n"; |
|
| 4441 | - } else { |
|
| 4442 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4443 | - } |
|
| 4377 | + $class_lien = $class_bouton = $class; |
|
| 4378 | + |
|
| 4379 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4380 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4381 | + $class_lien .= ' danger'; |
|
| 4382 | + $class_bouton .= ' btn_danger'; |
|
| 4383 | + } elseif ($fonction == 'rien.gif') { |
|
| 4384 | + $fonction = ''; |
|
| 4385 | + } elseif ($fonction == 'delsafe') { |
|
| 4386 | + $fonction = 'del'; |
|
| 4387 | + } |
|
| 4388 | + |
|
| 4389 | + $fond_origine = $fond; |
|
| 4390 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4391 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4392 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4393 | + } |
|
| 4394 | + |
|
| 4395 | + // Ajouter le type d'objet dans la classe |
|
| 4396 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4397 | + $class_lien .= " $objet_type"; |
|
| 4398 | + $class_bouton .= " $objet_type"; |
|
| 4399 | + |
|
| 4400 | + // Texte |
|
| 4401 | + $alt = attribut_html($texte); |
|
| 4402 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4403 | + |
|
| 4404 | + // Liens : préparer les classes ajax |
|
| 4405 | + $ajax = ''; |
|
| 4406 | + if ($type === 'lien') { |
|
| 4407 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4408 | + $ajax = 'ajax'; |
|
| 4409 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4410 | + $ajax .= ' preload'; |
|
| 4411 | + } |
|
| 4412 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4413 | + $ajax .= ' nocache'; |
|
| 4414 | + } |
|
| 4415 | + $ajax = " class='$ajax'"; |
|
| 4416 | + } |
|
| 4417 | + } |
|
| 4418 | + |
|
| 4419 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4420 | + $size = 24; |
|
| 4421 | + if ( |
|
| 4422 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4423 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4424 | + ) { |
|
| 4425 | + $size = $match[1]; |
|
| 4426 | + } |
|
| 4427 | + $class_lien .= " s$size"; |
|
| 4428 | + $class_bouton .= " s$size"; |
|
| 4429 | + |
|
| 4430 | + // Icône |
|
| 4431 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4432 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4433 | + |
|
| 4434 | + // Markup final |
|
| 4435 | + if ($type == 'lien') { |
|
| 4436 | + return "<span class='icone $class_lien'>" |
|
| 4437 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4438 | + . $icone |
|
| 4439 | + . "<b>$texte</b>" |
|
| 4440 | + . "</a></span>\n"; |
|
| 4441 | + } else { |
|
| 4442 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4443 | + } |
|
| 4444 | 4444 | } |
| 4445 | 4445 | |
| 4446 | 4446 | /** |
@@ -4464,7 +4464,7 @@ discard block |
||
| 4464 | 4464 | * Code HTML du lien |
| 4465 | 4465 | **/ |
| 4466 | 4466 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4467 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4467 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4468 | 4468 | } |
| 4469 | 4469 | |
| 4470 | 4470 | /** |
@@ -4499,7 +4499,7 @@ discard block |
||
| 4499 | 4499 | * Code HTML du lien |
| 4500 | 4500 | **/ |
| 4501 | 4501 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4502 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4502 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4503 | 4503 | } |
| 4504 | 4504 | |
| 4505 | 4505 | /** |
@@ -4544,7 +4544,7 @@ discard block |
||
| 4544 | 4544 | * Code HTML du lien |
| 4545 | 4545 | **/ |
| 4546 | 4546 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4547 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4547 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4548 | 4548 | } |
| 4549 | 4549 | |
| 4550 | 4550 | /** |
@@ -4575,7 +4575,7 @@ discard block |
||
| 4575 | 4575 | * Code HTML du lien |
| 4576 | 4576 | **/ |
| 4577 | 4577 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4578 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4578 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4579 | 4579 | } |
| 4580 | 4580 | |
| 4581 | 4581 | /** |
@@ -4606,7 +4606,7 @@ discard block |
||
| 4606 | 4606 | * Code HTML du lien |
| 4607 | 4607 | */ |
| 4608 | 4608 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4609 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4609 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4610 | 4610 | } |
| 4611 | 4611 | |
| 4612 | 4612 | |
@@ -4628,7 +4628,7 @@ discard block |
||
| 4628 | 4628 | * @return array Liste des éléments |
| 4629 | 4629 | */ |
| 4630 | 4630 | function filtre_explode_dist($a, $b) { |
| 4631 | - return explode($b, (string) $a); |
|
| 4631 | + return explode($b, (string) $a); |
|
| 4632 | 4632 | } |
| 4633 | 4633 | |
| 4634 | 4634 | /** |
@@ -4649,7 +4649,7 @@ discard block |
||
| 4649 | 4649 | * @return string Texte |
| 4650 | 4650 | */ |
| 4651 | 4651 | function filtre_implode_dist($a, $b) { |
| 4652 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4652 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4653 | 4653 | } |
| 4654 | 4654 | |
| 4655 | 4655 | /** |
@@ -4658,22 +4658,22 @@ discard block |
||
| 4658 | 4658 | * @return string Code CSS |
| 4659 | 4659 | */ |
| 4660 | 4660 | function bando_images_background() { |
| 4661 | - include_spip('inc/bandeau'); |
|
| 4662 | - // recuperer tous les boutons et leurs images |
|
| 4663 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4661 | + include_spip('inc/bandeau'); |
|
| 4662 | + // recuperer tous les boutons et leurs images |
|
| 4663 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4664 | 4664 | |
| 4665 | - $res = ''; |
|
| 4666 | - foreach ($boutons as $page => $detail) { |
|
| 4667 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4668 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4669 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4670 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4671 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4672 | - } |
|
| 4673 | - } |
|
| 4674 | - } |
|
| 4665 | + $res = ''; |
|
| 4666 | + foreach ($boutons as $page => $detail) { |
|
| 4667 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4668 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4669 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4670 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4671 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4672 | + } |
|
| 4673 | + } |
|
| 4674 | + } |
|
| 4675 | 4675 | |
| 4676 | - return $res; |
|
| 4676 | + return $res; |
|
| 4677 | 4677 | } |
| 4678 | 4678 | |
| 4679 | 4679 | /** |
@@ -4698,27 +4698,27 @@ discard block |
||
| 4698 | 4698 | */ |
| 4699 | 4699 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4700 | 4700 | |
| 4701 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4702 | - $class_form = ''; |
|
| 4703 | - if (strpos($class, 'ajax') !== false) { |
|
| 4704 | - $class_form = 'ajax'; |
|
| 4705 | - $class = str_replace('ajax', '', $class); |
|
| 4706 | - } |
|
| 4707 | - $class_btn = 'submit ' . trim($class); |
|
| 4701 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4702 | + $class_form = ''; |
|
| 4703 | + if (strpos($class, 'ajax') !== false) { |
|
| 4704 | + $class_form = 'ajax'; |
|
| 4705 | + $class = str_replace('ajax', '', $class); |
|
| 4706 | + } |
|
| 4707 | + $class_btn = 'submit ' . trim($class); |
|
| 4708 | 4708 | |
| 4709 | - if ($confirm) { |
|
| 4710 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4711 | - if ($callback) { |
|
| 4712 | - $callback = "$confirm?($callback):false"; |
|
| 4713 | - } else { |
|
| 4714 | - $callback = $confirm; |
|
| 4715 | - } |
|
| 4716 | - } |
|
| 4717 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4718 | - $title = $title ? " title='$title'" : ''; |
|
| 4709 | + if ($confirm) { |
|
| 4710 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4711 | + if ($callback) { |
|
| 4712 | + $callback = "$confirm?($callback):false"; |
|
| 4713 | + } else { |
|
| 4714 | + $callback = $confirm; |
|
| 4715 | + } |
|
| 4716 | + } |
|
| 4717 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4718 | + $title = $title ? " title='$title'" : ''; |
|
| 4719 | 4719 | |
| 4720 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4721 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4720 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4721 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4722 | 4722 | } |
| 4723 | 4723 | |
| 4724 | 4724 | /** |
@@ -4741,101 +4741,101 @@ discard block |
||
| 4741 | 4741 | * @return string |
| 4742 | 4742 | */ |
| 4743 | 4743 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4744 | - static $trouver_table = null; |
|
| 4745 | - static $objets; |
|
| 4746 | - |
|
| 4747 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4748 | - $id_objet = intval($id_objet); |
|
| 4749 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4750 | - return ''; |
|
| 4751 | - } |
|
| 4752 | - |
|
| 4753 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4754 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4755 | - return ''; |
|
| 4756 | - } |
|
| 4757 | - |
|
| 4758 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4759 | - if ($info == 'url') { |
|
| 4760 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4761 | - } |
|
| 4762 | - |
|
| 4763 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4764 | - $demande_titre = ($info === 'titre'); |
|
| 4765 | - $demande_introduction = ($info === 'introduction'); |
|
| 4766 | - |
|
| 4767 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4768 | - if ( |
|
| 4769 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4770 | - or |
|
| 4771 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4772 | - ) { |
|
| 4773 | - if (!$trouver_table) { |
|
| 4774 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4775 | - } |
|
| 4776 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4777 | - if (!$desc) { |
|
| 4778 | - return $objets[$type_objet] = false; |
|
| 4779 | - } |
|
| 4780 | - |
|
| 4781 | - // Si on demande le titre, on le gere en interne |
|
| 4782 | - $champ_titre = ''; |
|
| 4783 | - if ($demande_titre) { |
|
| 4784 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4785 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4786 | - } |
|
| 4787 | - include_spip('base/abstract_sql'); |
|
| 4788 | - include_spip('base/connect_sql'); |
|
| 4789 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4790 | - '*' . $champ_titre, |
|
| 4791 | - $desc['table_sql'], |
|
| 4792 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4793 | - ); |
|
| 4794 | - |
|
| 4795 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4796 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4797 | - } |
|
| 4798 | - |
|
| 4799 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4800 | - // ajouter la longueur au début des params supplémentaires |
|
| 4801 | - if ($demande_introduction) { |
|
| 4802 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4803 | - array_unshift($params, $introduction_longueur); |
|
| 4804 | - } |
|
| 4805 | - |
|
| 4806 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4807 | - if ( |
|
| 4808 | - $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4809 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4810 | - or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4811 | - ) { |
|
| 4812 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4813 | - } |
|
| 4814 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4815 | - elseif ( |
|
| 4816 | - $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4817 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4818 | - or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4819 | - ) { |
|
| 4820 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4821 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4822 | - else { |
|
| 4823 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4824 | - } |
|
| 4825 | - |
|
| 4826 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4827 | - if (!$etoile) { |
|
| 4828 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4829 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4830 | - $info_generee = appliquer_traitement_champ( |
|
| 4831 | - $info_generee, |
|
| 4832 | - $info, |
|
| 4833 | - table_objet($type_objet), |
|
| 4834 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4835 | - ); |
|
| 4836 | - } |
|
| 4837 | - |
|
| 4838 | - return $info_generee; |
|
| 4744 | + static $trouver_table = null; |
|
| 4745 | + static $objets; |
|
| 4746 | + |
|
| 4747 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4748 | + $id_objet = intval($id_objet); |
|
| 4749 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4750 | + return ''; |
|
| 4751 | + } |
|
| 4752 | + |
|
| 4753 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4754 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4755 | + return ''; |
|
| 4756 | + } |
|
| 4757 | + |
|
| 4758 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4759 | + if ($info == 'url') { |
|
| 4760 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4761 | + } |
|
| 4762 | + |
|
| 4763 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4764 | + $demande_titre = ($info === 'titre'); |
|
| 4765 | + $demande_introduction = ($info === 'introduction'); |
|
| 4766 | + |
|
| 4767 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4768 | + if ( |
|
| 4769 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4770 | + or |
|
| 4771 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4772 | + ) { |
|
| 4773 | + if (!$trouver_table) { |
|
| 4774 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4775 | + } |
|
| 4776 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4777 | + if (!$desc) { |
|
| 4778 | + return $objets[$type_objet] = false; |
|
| 4779 | + } |
|
| 4780 | + |
|
| 4781 | + // Si on demande le titre, on le gere en interne |
|
| 4782 | + $champ_titre = ''; |
|
| 4783 | + if ($demande_titre) { |
|
| 4784 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4785 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4786 | + } |
|
| 4787 | + include_spip('base/abstract_sql'); |
|
| 4788 | + include_spip('base/connect_sql'); |
|
| 4789 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4790 | + '*' . $champ_titre, |
|
| 4791 | + $desc['table_sql'], |
|
| 4792 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4793 | + ); |
|
| 4794 | + |
|
| 4795 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4796 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4797 | + } |
|
| 4798 | + |
|
| 4799 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4800 | + // ajouter la longueur au début des params supplémentaires |
|
| 4801 | + if ($demande_introduction) { |
|
| 4802 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4803 | + array_unshift($params, $introduction_longueur); |
|
| 4804 | + } |
|
| 4805 | + |
|
| 4806 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4807 | + if ( |
|
| 4808 | + $generer = charger_fonction("generer_${type_objet}_${info}", '', true) |
|
| 4809 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4810 | + or $generer = charger_fonction("generer_${info}_${type_objet}", '', true) |
|
| 4811 | + ) { |
|
| 4812 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4813 | + } |
|
| 4814 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4815 | + elseif ( |
|
| 4816 | + $generer = charger_fonction("generer_objet_${info}", '', true) |
|
| 4817 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4818 | + or $generer = charger_fonction("generer_${info}_entite", '', true) |
|
| 4819 | + ) { |
|
| 4820 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4821 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4822 | + else { |
|
| 4823 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4824 | + } |
|
| 4825 | + |
|
| 4826 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4827 | + if (!$etoile) { |
|
| 4828 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4829 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4830 | + $info_generee = appliquer_traitement_champ( |
|
| 4831 | + $info_generee, |
|
| 4832 | + $info, |
|
| 4833 | + table_objet($type_objet), |
|
| 4834 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4835 | + ); |
|
| 4836 | + } |
|
| 4837 | + |
|
| 4838 | + return $info_generee; |
|
| 4839 | 4839 | } |
| 4840 | 4840 | |
| 4841 | 4841 | /** |
@@ -4843,7 +4843,7 @@ discard block |
||
| 4843 | 4843 | * @see generer_objet_info |
| 4844 | 4844 | */ |
| 4845 | 4845 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4846 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4846 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4847 | 4847 | } |
| 4848 | 4848 | |
| 4849 | 4849 | /** |
@@ -4876,36 +4876,36 @@ discard block |
||
| 4876 | 4876 | */ |
| 4877 | 4877 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4878 | 4878 | |
| 4879 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4880 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4881 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4882 | - if (isset($ligne_sql['chapo'])) { |
|
| 4883 | - $chapo = $ligne_sql['chapo']; |
|
| 4884 | - $texte = strlen($descriptif) ? |
|
| 4885 | - '' : |
|
| 4886 | - "$chapo \n\n $texte"; |
|
| 4887 | - } |
|
| 4879 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4880 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4881 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4882 | + if (isset($ligne_sql['chapo'])) { |
|
| 4883 | + $chapo = $ligne_sql['chapo']; |
|
| 4884 | + $texte = strlen($descriptif) ? |
|
| 4885 | + '' : |
|
| 4886 | + "$chapo \n\n $texte"; |
|
| 4887 | + } |
|
| 4888 | 4888 | |
| 4889 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4890 | - if (!intval($longueur_ou_suite)) { |
|
| 4891 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4892 | - } else { |
|
| 4893 | - $longueur = intval($longueur_ou_suite); |
|
| 4894 | - } |
|
| 4889 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4890 | + if (!intval($longueur_ou_suite)) { |
|
| 4891 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4892 | + } else { |
|
| 4893 | + $longueur = intval($longueur_ou_suite); |
|
| 4894 | + } |
|
| 4895 | 4895 | |
| 4896 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4897 | - // Ex : #INTRODUCTION{...} |
|
| 4898 | - if ( |
|
| 4899 | - is_null($suite) |
|
| 4900 | - and !intval($longueur_ou_suite) |
|
| 4901 | - ) { |
|
| 4902 | - $suite = $longueur_ou_suite; |
|
| 4903 | - } |
|
| 4896 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4897 | + // Ex : #INTRODUCTION{...} |
|
| 4898 | + if ( |
|
| 4899 | + is_null($suite) |
|
| 4900 | + and !intval($longueur_ou_suite) |
|
| 4901 | + ) { |
|
| 4902 | + $suite = $longueur_ou_suite; |
|
| 4903 | + } |
|
| 4904 | 4904 | |
| 4905 | - $f = chercher_filtre('introduction'); |
|
| 4906 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4905 | + $f = chercher_filtre('introduction'); |
|
| 4906 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4907 | 4907 | |
| 4908 | - return $introduction; |
|
| 4908 | + return $introduction; |
|
| 4909 | 4909 | } |
| 4910 | 4910 | |
| 4911 | 4911 | /** |
@@ -4913,7 +4913,7 @@ discard block |
||
| 4913 | 4913 | * @see generer_objet_introduction |
| 4914 | 4914 | */ |
| 4915 | 4915 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4916 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4916 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4917 | 4917 | } |
| 4918 | 4918 | |
| 4919 | 4919 | /** |
@@ -4927,44 +4927,44 @@ discard block |
||
| 4927 | 4927 | * @return string |
| 4928 | 4928 | */ |
| 4929 | 4929 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4930 | - if (!$champ) { |
|
| 4931 | - return $texte; |
|
| 4932 | - } |
|
| 4930 | + if (!$champ) { |
|
| 4931 | + return $texte; |
|
| 4932 | + } |
|
| 4933 | 4933 | |
| 4934 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4935 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4936 | - include_fichiers_fonctions(); |
|
| 4934 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4935 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4936 | + include_fichiers_fonctions(); |
|
| 4937 | 4937 | |
| 4938 | - $champ = strtoupper($champ); |
|
| 4939 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4940 | - if (!$traitements or !is_array($traitements)) { |
|
| 4941 | - return $texte; |
|
| 4942 | - } |
|
| 4938 | + $champ = strtoupper($champ); |
|
| 4939 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4940 | + if (!$traitements or !is_array($traitements)) { |
|
| 4941 | + return $texte; |
|
| 4942 | + } |
|
| 4943 | 4943 | |
| 4944 | - $traitement = ''; |
|
| 4945 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4946 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4947 | - $table_objet = table_objet($table_objet); |
|
| 4948 | - if (isset($traitements[$table_objet])) { |
|
| 4949 | - $traitement = $traitements[$table_objet]; |
|
| 4950 | - } |
|
| 4951 | - } |
|
| 4952 | - if (!$traitement and isset($traitements[0])) { |
|
| 4953 | - $traitement = $traitements[0]; |
|
| 4954 | - } |
|
| 4955 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4944 | + $traitement = ''; |
|
| 4945 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4946 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4947 | + $table_objet = table_objet($table_objet); |
|
| 4948 | + if (isset($traitements[$table_objet])) { |
|
| 4949 | + $traitement = $traitements[$table_objet]; |
|
| 4950 | + } |
|
| 4951 | + } |
|
| 4952 | + if (!$traitement and isset($traitements[0])) { |
|
| 4953 | + $traitement = $traitements[0]; |
|
| 4954 | + } |
|
| 4955 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4956 | 4956 | |
| 4957 | - if (!$traitement) { |
|
| 4958 | - return $texte; |
|
| 4959 | - } |
|
| 4957 | + if (!$traitement) { |
|
| 4958 | + return $texte; |
|
| 4959 | + } |
|
| 4960 | 4960 | |
| 4961 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4961 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4962 | 4962 | |
| 4963 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4964 | - $Pile = [0 => $env]; |
|
| 4965 | - eval("\$texte = $traitement;"); |
|
| 4963 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4964 | + $Pile = [0 => $env]; |
|
| 4965 | + eval("\$texte = $traitement;"); |
|
| 4966 | 4966 | |
| 4967 | - return $texte; |
|
| 4967 | + return $texte; |
|
| 4968 | 4968 | } |
| 4969 | 4969 | |
| 4970 | 4970 | |
@@ -4978,21 +4978,21 @@ discard block |
||
| 4978 | 4978 | * @return string |
| 4979 | 4979 | */ |
| 4980 | 4980 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4981 | - include_spip('inc/liens'); |
|
| 4982 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4983 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4984 | - // le raccourcis n'est plus valide |
|
| 4985 | - $titre = typo($titre['titre']) ?? ''; |
|
| 4986 | - // on essaye avec generer_info_entite ? |
|
| 4987 | - if (!strlen($titre) and !$connect) { |
|
| 4988 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4989 | - } |
|
| 4990 | - if (!strlen($titre)) { |
|
| 4991 | - $titre = _T('info_sans_titre'); |
|
| 4992 | - } |
|
| 4993 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4981 | + include_spip('inc/liens'); |
|
| 4982 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4983 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4984 | + // le raccourcis n'est plus valide |
|
| 4985 | + $titre = typo($titre['titre']) ?? ''; |
|
| 4986 | + // on essaye avec generer_info_entite ? |
|
| 4987 | + if (!strlen($titre) and !$connect) { |
|
| 4988 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4989 | + } |
|
| 4990 | + if (!strlen($titre)) { |
|
| 4991 | + $titre = _T('info_sans_titre'); |
|
| 4992 | + } |
|
| 4993 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4994 | 4994 | |
| 4995 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4995 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4996 | 4996 | } |
| 4997 | 4997 | |
| 4998 | 4998 | /** |
@@ -5000,7 +5000,7 @@ discard block |
||
| 5000 | 5000 | * @see generer_objet_lien |
| 5001 | 5001 | */ |
| 5002 | 5002 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 5003 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5003 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 5004 | 5004 | } |
| 5005 | 5005 | |
| 5006 | 5006 | /** |
@@ -5016,15 +5016,15 @@ discard block |
||
| 5016 | 5016 | * @return string |
| 5017 | 5017 | */ |
| 5018 | 5018 | function wrap($texte, $wrap) { |
| 5019 | - $balises = extraire_balises($wrap); |
|
| 5020 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5021 | - $texte = $wrap . $texte; |
|
| 5022 | - $regs = array_reverse($regs[1]); |
|
| 5023 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5024 | - $texte = $texte . $wrap; |
|
| 5025 | - } |
|
| 5019 | + $balises = extraire_balises($wrap); |
|
| 5020 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 5021 | + $texte = $wrap . $texte; |
|
| 5022 | + $regs = array_reverse($regs[1]); |
|
| 5023 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 5024 | + $texte = $texte . $wrap; |
|
| 5025 | + } |
|
| 5026 | 5026 | |
| 5027 | - return $texte; |
|
| 5027 | + return $texte; |
|
| 5028 | 5028 | } |
| 5029 | 5029 | |
| 5030 | 5030 | |
@@ -5044,44 +5044,44 @@ discard block |
||
| 5044 | 5044 | * @return array|mixed|string |
| 5045 | 5045 | */ |
| 5046 | 5046 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 5047 | - if (is_string($u)) { |
|
| 5048 | - $u = typo($u); |
|
| 5047 | + if (is_string($u)) { |
|
| 5048 | + $u = typo($u); |
|
| 5049 | 5049 | |
| 5050 | - return $u; |
|
| 5051 | - } |
|
| 5050 | + return $u; |
|
| 5051 | + } |
|
| 5052 | 5052 | |
| 5053 | - // caster $u en array si besoin |
|
| 5054 | - if (is_object($u)) { |
|
| 5055 | - $u = (array)$u; |
|
| 5056 | - } |
|
| 5053 | + // caster $u en array si besoin |
|
| 5054 | + if (is_object($u)) { |
|
| 5055 | + $u = (array)$u; |
|
| 5056 | + } |
|
| 5057 | 5057 | |
| 5058 | - if (is_array($u)) { |
|
| 5059 | - $out = ''; |
|
| 5060 | - // toutes les cles sont numeriques ? |
|
| 5061 | - // et aucun enfant n'est un tableau |
|
| 5062 | - // liste simple separee par des virgules |
|
| 5063 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5064 | - $array_values = array_map('is_array', $u); |
|
| 5065 | - $object_values = array_map('is_object', $u); |
|
| 5066 | - if ( |
|
| 5067 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 5068 | - and !array_sum($array_values) |
|
| 5069 | - and !array_sum($object_values) |
|
| 5070 | - ) { |
|
| 5071 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5072 | - } |
|
| 5058 | + if (is_array($u)) { |
|
| 5059 | + $out = ''; |
|
| 5060 | + // toutes les cles sont numeriques ? |
|
| 5061 | + // et aucun enfant n'est un tableau |
|
| 5062 | + // liste simple separee par des virgules |
|
| 5063 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 5064 | + $array_values = array_map('is_array', $u); |
|
| 5065 | + $object_values = array_map('is_object', $u); |
|
| 5066 | + if ( |
|
| 5067 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 5068 | + and !array_sum($array_values) |
|
| 5069 | + and !array_sum($object_values) |
|
| 5070 | + ) { |
|
| 5071 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 5072 | + } |
|
| 5073 | 5073 | |
| 5074 | - // sinon on passe a la ligne et on indente |
|
| 5075 | - $i_str = str_pad('', $indent, ' '); |
|
| 5076 | - foreach ($u as $k => $v) { |
|
| 5077 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5078 | - } |
|
| 5074 | + // sinon on passe a la ligne et on indente |
|
| 5075 | + $i_str = str_pad('', $indent, ' '); |
|
| 5076 | + foreach ($u as $k => $v) { |
|
| 5077 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 5078 | + } |
|
| 5079 | 5079 | |
| 5080 | - return $out; |
|
| 5081 | - } |
|
| 5080 | + return $out; |
|
| 5081 | + } |
|
| 5082 | 5082 | |
| 5083 | - // on sait pas quoi faire... |
|
| 5084 | - return $u; |
|
| 5083 | + // on sait pas quoi faire... |
|
| 5084 | + return $u; |
|
| 5085 | 5085 | } |
| 5086 | 5086 | |
| 5087 | 5087 | |
@@ -5094,10 +5094,10 @@ discard block |
||
| 5094 | 5094 | * @return string|array |
| 5095 | 5095 | */ |
| 5096 | 5096 | function objet_info($objet, $info) { |
| 5097 | - $table = table_objet_sql($objet); |
|
| 5098 | - $infos = lister_tables_objets_sql($table); |
|
| 5097 | + $table = table_objet_sql($objet); |
|
| 5098 | + $infos = lister_tables_objets_sql($table); |
|
| 5099 | 5099 | |
| 5100 | - return ($infos[$info] ?? ''); |
|
| 5100 | + return ($infos[$info] ?? ''); |
|
| 5101 | 5101 | } |
| 5102 | 5102 | |
| 5103 | 5103 | /** |
@@ -5112,11 +5112,11 @@ discard block |
||
| 5112 | 5112 | * Texte traduit du comptage, tel que '3 articles' |
| 5113 | 5113 | */ |
| 5114 | 5114 | function objet_afficher_nb($nb, $objet) { |
| 5115 | - if (!$nb) { |
|
| 5116 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5117 | - } else { |
|
| 5118 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5119 | - } |
|
| 5115 | + if (!$nb) { |
|
| 5116 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5117 | + } else { |
|
| 5118 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5119 | + } |
|
| 5120 | 5120 | } |
| 5121 | 5121 | |
| 5122 | 5122 | /** |
@@ -5128,11 +5128,11 @@ discard block |
||
| 5128 | 5128 | * @return string |
| 5129 | 5129 | */ |
| 5130 | 5130 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5131 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5132 | - $icone = chemin_image($icone); |
|
| 5133 | - $balise_img = charger_filtre('balise_img'); |
|
| 5131 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5132 | + $icone = chemin_image($icone); |
|
| 5133 | + $balise_img = charger_filtre('balise_img'); |
|
| 5134 | 5134 | |
| 5135 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5135 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5136 | 5136 | } |
| 5137 | 5137 | |
| 5138 | 5138 | /** |
@@ -5153,12 +5153,12 @@ discard block |
||
| 5153 | 5153 | * @return string |
| 5154 | 5154 | */ |
| 5155 | 5155 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5156 | - $chaine = explode(':', $chaine); |
|
| 5157 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5158 | - return $t; |
|
| 5159 | - } |
|
| 5160 | - $chaine = implode(':', $chaine); |
|
| 5161 | - return _T($chaine, $args, $options); |
|
| 5156 | + $chaine = explode(':', $chaine); |
|
| 5157 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5158 | + return $t; |
|
| 5159 | + } |
|
| 5160 | + $chaine = implode(':', $chaine); |
|
| 5161 | + return _T($chaine, $args, $options); |
|
| 5162 | 5162 | } |
| 5163 | 5163 | |
| 5164 | 5164 | /** |
@@ -5172,18 +5172,18 @@ discard block |
||
| 5172 | 5172 | * @return string Code HTML |
| 5173 | 5173 | */ |
| 5174 | 5174 | function insert_head_css_conditionnel($flux) { |
| 5175 | - if ( |
|
| 5176 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5177 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5178 | - ) { |
|
| 5179 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5180 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5181 | - $p = $p1; |
|
| 5182 | - } |
|
| 5183 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5184 | - } |
|
| 5175 | + if ( |
|
| 5176 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5177 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5178 | + ) { |
|
| 5179 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5180 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5181 | + $p = $p1; |
|
| 5182 | + } |
|
| 5183 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5184 | + } |
|
| 5185 | 5185 | |
| 5186 | - return $flux; |
|
| 5186 | + return $flux; |
|
| 5187 | 5187 | } |
| 5188 | 5188 | |
| 5189 | 5189 | /** |
@@ -5206,72 +5206,72 @@ discard block |
||
| 5206 | 5206 | * @return string |
| 5207 | 5207 | */ |
| 5208 | 5208 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5209 | - if (isset($contexte['format'])) { |
|
| 5210 | - $extension = $contexte['format']; |
|
| 5211 | - unset($contexte['format']); |
|
| 5212 | - } else { |
|
| 5213 | - $extension = 'html'; |
|
| 5214 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5215 | - $extension = $m[1]; |
|
| 5216 | - } |
|
| 5217 | - } |
|
| 5218 | - // recuperer le contenu produit par le squelette |
|
| 5219 | - $options['raw'] = true; |
|
| 5220 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5221 | - |
|
| 5222 | - // calculer le nom de la css |
|
| 5223 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5224 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5225 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5226 | - |
|
| 5227 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5228 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5229 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5230 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5231 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5232 | - } |
|
| 5233 | - else { |
|
| 5234 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5235 | - ksort($contexte); |
|
| 5236 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5237 | - } |
|
| 5238 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5239 | - |
|
| 5240 | - // mettre a jour le fichier si il n'existe pas |
|
| 5241 | - // ou trop ancien |
|
| 5242 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5243 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5244 | - if ( |
|
| 5245 | - !file_exists($filename) |
|
| 5246 | - or !file_exists($filename . '.last') |
|
| 5247 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5248 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5249 | - ) { |
|
| 5250 | - $contenu = $cache['texte']; |
|
| 5251 | - // passer les urls en absolu si c'est une css |
|
| 5252 | - if ($extension == 'css') { |
|
| 5253 | - $contenu = urls_absolues_css( |
|
| 5254 | - $contenu, |
|
| 5255 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5256 | - ); |
|
| 5257 | - } |
|
| 5258 | - |
|
| 5259 | - $comment = ''; |
|
| 5260 | - // ne pas insérer de commentaire sur certains formats |
|
| 5261 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5262 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5263 | - foreach ($contexte as $k => $v) { |
|
| 5264 | - $comment .= ",$k=$v"; |
|
| 5265 | - } |
|
| 5266 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5267 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5268 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5269 | - } |
|
| 5270 | - // et ecrire le fichier si il change |
|
| 5271 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5272 | - } |
|
| 5273 | - |
|
| 5274 | - return timestamp($filename); |
|
| 5209 | + if (isset($contexte['format'])) { |
|
| 5210 | + $extension = $contexte['format']; |
|
| 5211 | + unset($contexte['format']); |
|
| 5212 | + } else { |
|
| 5213 | + $extension = 'html'; |
|
| 5214 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5215 | + $extension = $m[1]; |
|
| 5216 | + } |
|
| 5217 | + } |
|
| 5218 | + // recuperer le contenu produit par le squelette |
|
| 5219 | + $options['raw'] = true; |
|
| 5220 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5221 | + |
|
| 5222 | + // calculer le nom de la css |
|
| 5223 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5224 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5225 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5226 | + |
|
| 5227 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5228 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5229 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5230 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5231 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5232 | + } |
|
| 5233 | + else { |
|
| 5234 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5235 | + ksort($contexte); |
|
| 5236 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5237 | + } |
|
| 5238 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5239 | + |
|
| 5240 | + // mettre a jour le fichier si il n'existe pas |
|
| 5241 | + // ou trop ancien |
|
| 5242 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5243 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5244 | + if ( |
|
| 5245 | + !file_exists($filename) |
|
| 5246 | + or !file_exists($filename . '.last') |
|
| 5247 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5248 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5249 | + ) { |
|
| 5250 | + $contenu = $cache['texte']; |
|
| 5251 | + // passer les urls en absolu si c'est une css |
|
| 5252 | + if ($extension == 'css') { |
|
| 5253 | + $contenu = urls_absolues_css( |
|
| 5254 | + $contenu, |
|
| 5255 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5256 | + ); |
|
| 5257 | + } |
|
| 5258 | + |
|
| 5259 | + $comment = ''; |
|
| 5260 | + // ne pas insérer de commentaire sur certains formats |
|
| 5261 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5262 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5263 | + foreach ($contexte as $k => $v) { |
|
| 5264 | + $comment .= ",$k=$v"; |
|
| 5265 | + } |
|
| 5266 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5267 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5268 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5269 | + } |
|
| 5270 | + // et ecrire le fichier si il change |
|
| 5271 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5272 | + } |
|
| 5273 | + |
|
| 5274 | + return timestamp($filename); |
|
| 5275 | 5275 | } |
| 5276 | 5276 | |
| 5277 | 5277 | /** |
@@ -5284,15 +5284,15 @@ discard block |
||
| 5284 | 5284 | * $fichier auquel on a ajouté le timestamp |
| 5285 | 5285 | */ |
| 5286 | 5286 | function timestamp($fichier) { |
| 5287 | - if ( |
|
| 5288 | - !$fichier |
|
| 5289 | - or !file_exists($fichier) |
|
| 5290 | - or !$m = filemtime($fichier) |
|
| 5291 | - ) { |
|
| 5292 | - return $fichier; |
|
| 5293 | - } |
|
| 5287 | + if ( |
|
| 5288 | + !$fichier |
|
| 5289 | + or !file_exists($fichier) |
|
| 5290 | + or !$m = filemtime($fichier) |
|
| 5291 | + ) { |
|
| 5292 | + return $fichier; |
|
| 5293 | + } |
|
| 5294 | 5294 | |
| 5295 | - return "$fichier?$m"; |
|
| 5295 | + return "$fichier?$m"; |
|
| 5296 | 5296 | } |
| 5297 | 5297 | |
| 5298 | 5298 | /** |
@@ -5302,11 +5302,11 @@ discard block |
||
| 5302 | 5302 | * @return string |
| 5303 | 5303 | */ |
| 5304 | 5304 | function supprimer_timestamp($url) { |
| 5305 | - if (strpos($url, '?') === false) { |
|
| 5306 | - return $url; |
|
| 5307 | - } |
|
| 5305 | + if (strpos($url, '?') === false) { |
|
| 5306 | + return $url; |
|
| 5307 | + } |
|
| 5308 | 5308 | |
| 5309 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5309 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5310 | 5310 | } |
| 5311 | 5311 | |
| 5312 | 5312 | /** |
@@ -5321,9 +5321,9 @@ discard block |
||
| 5321 | 5321 | * @return string |
| 5322 | 5322 | */ |
| 5323 | 5323 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5324 | - include_spip('inc/envoyer_mail'); |
|
| 5324 | + include_spip('inc/envoyer_mail'); |
|
| 5325 | 5325 | |
| 5326 | - return nettoyer_titre_email($titre); |
|
| 5326 | + return nettoyer_titre_email($titre); |
|
| 5327 | 5327 | } |
| 5328 | 5328 | |
| 5329 | 5329 | /** |
@@ -5345,27 +5345,27 @@ discard block |
||
| 5345 | 5345 | * @return string |
| 5346 | 5346 | */ |
| 5347 | 5347 | function filtre_chercher_rubrique_dist( |
| 5348 | - $titre, |
|
| 5349 | - $id_objet, |
|
| 5350 | - $id_parent, |
|
| 5351 | - $objet, |
|
| 5352 | - $id_secteur, |
|
| 5353 | - $restreint, |
|
| 5354 | - $actionable = false, |
|
| 5355 | - $retour_sans_cadre = false |
|
| 5348 | + $titre, |
|
| 5349 | + $id_objet, |
|
| 5350 | + $id_parent, |
|
| 5351 | + $objet, |
|
| 5352 | + $id_secteur, |
|
| 5353 | + $restreint, |
|
| 5354 | + $actionable = false, |
|
| 5355 | + $retour_sans_cadre = false |
|
| 5356 | 5356 | ) { |
| 5357 | - include_spip('inc/filtres_ecrire'); |
|
| 5357 | + include_spip('inc/filtres_ecrire'); |
|
| 5358 | 5358 | |
| 5359 | - return chercher_rubrique( |
|
| 5360 | - $titre, |
|
| 5361 | - $id_objet, |
|
| 5362 | - $id_parent, |
|
| 5363 | - $objet, |
|
| 5364 | - $id_secteur, |
|
| 5365 | - $restreint, |
|
| 5366 | - $actionable, |
|
| 5367 | - $retour_sans_cadre |
|
| 5368 | - ); |
|
| 5359 | + return chercher_rubrique( |
|
| 5360 | + $titre, |
|
| 5361 | + $id_objet, |
|
| 5362 | + $id_parent, |
|
| 5363 | + $objet, |
|
| 5364 | + $id_secteur, |
|
| 5365 | + $restreint, |
|
| 5366 | + $actionable, |
|
| 5367 | + $retour_sans_cadre |
|
| 5368 | + ); |
|
| 5369 | 5369 | } |
| 5370 | 5370 | |
| 5371 | 5371 | /** |
@@ -5394,56 +5394,56 @@ discard block |
||
| 5394 | 5394 | * Chaîne vide si l'accès est autorisé |
| 5395 | 5395 | */ |
| 5396 | 5396 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5397 | - if ($ok) { |
|
| 5398 | - return ''; |
|
| 5399 | - } |
|
| 5400 | - |
|
| 5401 | - // Vider tous les tampons |
|
| 5402 | - $level = @ob_get_level(); |
|
| 5403 | - while ($level--) { |
|
| 5404 | - @ob_end_clean(); |
|
| 5405 | - } |
|
| 5406 | - |
|
| 5407 | - include_spip('inc/headers'); |
|
| 5408 | - |
|
| 5409 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5410 | - if ($url) { |
|
| 5411 | - redirige_par_entete($url, '', $statut); |
|
| 5412 | - } |
|
| 5413 | - |
|
| 5414 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5415 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5416 | - $message = $statut; |
|
| 5417 | - $statut = 0; |
|
| 5418 | - } |
|
| 5419 | - if (!$message) { |
|
| 5420 | - $message = ''; |
|
| 5421 | - } |
|
| 5422 | - $statut = intval($statut); |
|
| 5423 | - |
|
| 5424 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5425 | - if (test_espace_prive()) { |
|
| 5426 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5427 | - $statut = 403; |
|
| 5428 | - } |
|
| 5429 | - http_response_code(403); |
|
| 5430 | - $echec = charger_fonction('403', 'exec'); |
|
| 5431 | - $echec($message); |
|
| 5432 | - } else { |
|
| 5433 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5434 | - if (!$statut) { |
|
| 5435 | - $statut = 404; |
|
| 5436 | - } |
|
| 5437 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5438 | - http_response_code($statut); |
|
| 5439 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5440 | - if ($statut >= 400) { |
|
| 5441 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5442 | - } |
|
| 5443 | - } |
|
| 5444 | - |
|
| 5445 | - |
|
| 5446 | - exit; |
|
| 5397 | + if ($ok) { |
|
| 5398 | + return ''; |
|
| 5399 | + } |
|
| 5400 | + |
|
| 5401 | + // Vider tous les tampons |
|
| 5402 | + $level = @ob_get_level(); |
|
| 5403 | + while ($level--) { |
|
| 5404 | + @ob_end_clean(); |
|
| 5405 | + } |
|
| 5406 | + |
|
| 5407 | + include_spip('inc/headers'); |
|
| 5408 | + |
|
| 5409 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5410 | + if ($url) { |
|
| 5411 | + redirige_par_entete($url, '', $statut); |
|
| 5412 | + } |
|
| 5413 | + |
|
| 5414 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5415 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5416 | + $message = $statut; |
|
| 5417 | + $statut = 0; |
|
| 5418 | + } |
|
| 5419 | + if (!$message) { |
|
| 5420 | + $message = ''; |
|
| 5421 | + } |
|
| 5422 | + $statut = intval($statut); |
|
| 5423 | + |
|
| 5424 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5425 | + if (test_espace_prive()) { |
|
| 5426 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5427 | + $statut = 403; |
|
| 5428 | + } |
|
| 5429 | + http_response_code(403); |
|
| 5430 | + $echec = charger_fonction('403', 'exec'); |
|
| 5431 | + $echec($message); |
|
| 5432 | + } else { |
|
| 5433 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5434 | + if (!$statut) { |
|
| 5435 | + $statut = 404; |
|
| 5436 | + } |
|
| 5437 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5438 | + http_response_code($statut); |
|
| 5439 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5440 | + if ($statut >= 400) { |
|
| 5441 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5442 | + } |
|
| 5443 | + } |
|
| 5444 | + |
|
| 5445 | + |
|
| 5446 | + exit; |
|
| 5447 | 5447 | } |
| 5448 | 5448 | |
| 5449 | 5449 | /** |
@@ -5454,11 +5454,11 @@ discard block |
||
| 5454 | 5454 | * @return string |
| 5455 | 5455 | */ |
| 5456 | 5456 | function filtre_compacte_dist($source, $format = null) { |
| 5457 | - if (function_exists('minifier')) { |
|
| 5458 | - return minifier($source, $format); |
|
| 5459 | - } |
|
| 5457 | + if (function_exists('minifier')) { |
|
| 5458 | + return minifier($source, $format); |
|
| 5459 | + } |
|
| 5460 | 5460 | |
| 5461 | - return $source; |
|
| 5461 | + return $source; |
|
| 5462 | 5462 | } |
| 5463 | 5463 | |
| 5464 | 5464 | |
@@ -5470,31 +5470,31 @@ discard block |
||
| 5470 | 5470 | * @return string |
| 5471 | 5471 | */ |
| 5472 | 5472 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 5473 | - $l = strlen($passe); |
|
| 5474 | - |
|
| 5475 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5476 | - if (!$l) { |
|
| 5477 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5478 | - } |
|
| 5479 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5480 | - } |
|
| 5481 | - |
|
| 5482 | - if (is_null($portion_pourcent)) { |
|
| 5483 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5484 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5485 | - } |
|
| 5486 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5487 | - } |
|
| 5488 | - if ($portion_pourcent >= 100) { |
|
| 5489 | - return $passe; |
|
| 5490 | - } |
|
| 5491 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5492 | - $e = max($e, 0); |
|
| 5493 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5494 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5495 | - $mid = '***...***'; |
|
| 5496 | - } |
|
| 5497 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5473 | + $l = strlen($passe); |
|
| 5474 | + |
|
| 5475 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5476 | + if (!$l) { |
|
| 5477 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5478 | + } |
|
| 5479 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5480 | + } |
|
| 5481 | + |
|
| 5482 | + if (is_null($portion_pourcent)) { |
|
| 5483 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5484 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5485 | + } |
|
| 5486 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5487 | + } |
|
| 5488 | + if ($portion_pourcent >= 100) { |
|
| 5489 | + return $passe; |
|
| 5490 | + } |
|
| 5491 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5492 | + $e = max($e, 0); |
|
| 5493 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5494 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5495 | + $mid = '***...***'; |
|
| 5496 | + } |
|
| 5497 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5498 | 5498 | } |
| 5499 | 5499 | |
| 5500 | 5500 | |
@@ -5515,64 +5515,64 @@ discard block |
||
| 5515 | 5515 | */ |
| 5516 | 5516 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5517 | 5517 | |
| 5518 | - $original = $texte; |
|
| 5519 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5520 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5521 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5518 | + $original = $texte; |
|
| 5519 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5520 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5521 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5522 | 5522 | |
| 5523 | - if (!function_exists('translitteration')) { |
|
| 5524 | - include_spip('inc/charsets'); |
|
| 5525 | - } |
|
| 5523 | + if (!function_exists('translitteration')) { |
|
| 5524 | + include_spip('inc/charsets'); |
|
| 5525 | + } |
|
| 5526 | 5526 | |
| 5527 | - // pas de balise html |
|
| 5528 | - if (strpos($texte, '<') !== false) { |
|
| 5529 | - $texte = strip_tags($texte); |
|
| 5530 | - } |
|
| 5531 | - if (strpos($texte, '&') !== false) { |
|
| 5532 | - $texte = unicode2charset($texte); |
|
| 5533 | - } |
|
| 5534 | - // On enlève les espaces indésirables |
|
| 5535 | - $texte = trim($texte); |
|
| 5527 | + // pas de balise html |
|
| 5528 | + if (strpos($texte, '<') !== false) { |
|
| 5529 | + $texte = strip_tags($texte); |
|
| 5530 | + } |
|
| 5531 | + if (strpos($texte, '&') !== false) { |
|
| 5532 | + $texte = unicode2charset($texte); |
|
| 5533 | + } |
|
| 5534 | + // On enlève les espaces indésirables |
|
| 5535 | + $texte = trim($texte); |
|
| 5536 | 5536 | |
| 5537 | - // On enlève les accents et cie |
|
| 5538 | - $texte = translitteration($texte); |
|
| 5537 | + // On enlève les accents et cie |
|
| 5538 | + $texte = translitteration($texte); |
|
| 5539 | 5539 | |
| 5540 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5541 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5540 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5541 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5542 | 5542 | |
| 5543 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5544 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5545 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5546 | - } |
|
| 5543 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5544 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5545 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5546 | + } |
|
| 5547 | 5547 | |
| 5548 | - // pas de separateur au debut ni a la fin |
|
| 5549 | - $texte = trim($texte, $separateur); |
|
| 5548 | + // pas de separateur au debut ni a la fin |
|
| 5549 | + $texte = trim($texte, $separateur); |
|
| 5550 | 5550 | |
| 5551 | - // en minuscules |
|
| 5552 | - $texte = strtolower($texte); |
|
| 5551 | + // en minuscules |
|
| 5552 | + $texte = strtolower($texte); |
|
| 5553 | 5553 | |
| 5554 | - switch ($type) { |
|
| 5555 | - case 'class': |
|
| 5556 | - case 'id': |
|
| 5557 | - case 'anchor': |
|
| 5558 | - if (preg_match(',^\d,', $texte)) { |
|
| 5559 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5560 | - } |
|
| 5561 | - } |
|
| 5554 | + switch ($type) { |
|
| 5555 | + case 'class': |
|
| 5556 | + case 'id': |
|
| 5557 | + case 'anchor': |
|
| 5558 | + if (preg_match(',^\d,', $texte)) { |
|
| 5559 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5560 | + } |
|
| 5561 | + } |
|
| 5562 | 5562 | |
| 5563 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5564 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5565 | - } |
|
| 5563 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5564 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5565 | + } |
|
| 5566 | 5566 | |
| 5567 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5568 | - if (preg_match(',^\d,', $texte)) { |
|
| 5569 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5570 | - } |
|
| 5571 | - $texte .= $separateur . md5($original); |
|
| 5572 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5573 | - } |
|
| 5567 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5568 | + if (preg_match(',^\d,', $texte)) { |
|
| 5569 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5570 | + } |
|
| 5571 | + $texte .= $separateur . md5($original); |
|
| 5572 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5573 | + } |
|
| 5574 | 5574 | |
| 5575 | - return $texte; |
|
| 5575 | + return $texte; |
|
| 5576 | 5576 | } |
| 5577 | 5577 | |
| 5578 | 5578 | |
@@ -5593,11 +5593,11 @@ discard block |
||
| 5593 | 5593 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5594 | 5594 | */ |
| 5595 | 5595 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5596 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5597 | - if ($ucfirst) { |
|
| 5598 | - $label = spip_ucfirst($label); |
|
| 5599 | - } |
|
| 5600 | - return $label; |
|
| 5596 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5597 | + if ($ucfirst) { |
|
| 5598 | + $label = spip_ucfirst($label); |
|
| 5599 | + } |
|
| 5600 | + return $label; |
|
| 5601 | 5601 | } |
| 5602 | 5602 | |
| 5603 | 5603 | /** |
@@ -5610,8 +5610,8 @@ discard block |
||
| 5610 | 5610 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5611 | 5611 | */ |
| 5612 | 5612 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5613 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5614 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5613 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5614 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5615 | 5615 | } |
| 5616 | 5616 | |
| 5617 | 5617 | |
@@ -5624,19 +5624,19 @@ discard block |
||
| 5624 | 5624 | * @return array |
| 5625 | 5625 | */ |
| 5626 | 5626 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5627 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5628 | - return []; |
|
| 5629 | - } |
|
| 5627 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5628 | + return []; |
|
| 5629 | + } |
|
| 5630 | 5630 | |
| 5631 | - // compatibilite signature inversee |
|
| 5632 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5633 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5634 | - } |
|
| 5631 | + // compatibilite signature inversee |
|
| 5632 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5633 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5634 | + } |
|
| 5635 | 5635 | |
| 5636 | - if (!function_exists($fonction)) { |
|
| 5637 | - include_spip('base/objets'); |
|
| 5638 | - } |
|
| 5639 | - return $fonction($objet, $id_objet); |
|
| 5636 | + if (!function_exists($fonction)) { |
|
| 5637 | + include_spip('base/objets'); |
|
| 5638 | + } |
|
| 5639 | + return $fonction($objet, $id_objet); |
|
| 5640 | 5640 | } |
| 5641 | 5641 | |
| 5642 | 5642 | |
@@ -5651,7 +5651,7 @@ discard block |
||
| 5651 | 5651 | * @return array |
| 5652 | 5652 | */ |
| 5653 | 5653 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5654 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5654 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5655 | 5655 | } |
| 5656 | 5656 | |
| 5657 | 5657 | /** |
@@ -5665,7 +5665,7 @@ discard block |
||
| 5665 | 5665 | * @return array |
| 5666 | 5666 | */ |
| 5667 | 5667 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5668 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5668 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5669 | 5669 | } |
| 5670 | 5670 | |
| 5671 | 5671 | /** |
@@ -5679,7 +5679,7 @@ discard block |
||
| 5679 | 5679 | * @return array |
| 5680 | 5680 | */ |
| 5681 | 5681 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5682 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5682 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5683 | 5683 | } |
| 5684 | 5684 | |
| 5685 | 5685 | /** |
@@ -5693,5 +5693,5 @@ discard block |
||
| 5693 | 5693 | * @return array |
| 5694 | 5694 | */ |
| 5695 | 5695 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5696 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5696 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5697 | 5697 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -31,46 +31,46 @@ discard block |
||
| 31 | 31 | * Mot de passe |
| 32 | 32 | **/ |
| 33 | 33 | function creer_pass_aleatoire($longueur = 16, $sel = '') { |
| 34 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | - |
|
| 36 | - mt_srand($seed); |
|
| 37 | - $s = ''; |
|
| 38 | - $pass = ''; |
|
| 39 | - for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | - if (!$s) { |
|
| 41 | - $s = random_int(0, mt_getrandmax()); |
|
| 42 | - if (!$s) { |
|
| 43 | - $s = random_int(0, mt_getrandmax()); |
|
| 44 | - } |
|
| 45 | - $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | - } |
|
| 47 | - $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | - $x = $r['r'] & 63; |
|
| 49 | - if ($x < 10) { |
|
| 50 | - $x = chr($x + 48); |
|
| 51 | - } else { |
|
| 52 | - if ($x < 36) { |
|
| 53 | - $x = chr($x + 55); |
|
| 54 | - } else { |
|
| 55 | - if ($x < 62) { |
|
| 56 | - $x = chr($x + 61); |
|
| 57 | - } else { |
|
| 58 | - if ($x == 63) { |
|
| 59 | - $x = '/'; |
|
| 60 | - } else { |
|
| 61 | - $x = '.'; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - $pass .= $x; |
|
| 67 | - $s = substr($s, 2); |
|
| 68 | - } |
|
| 69 | - $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | - $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | - $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | - |
|
| 73 | - return $pass; |
|
| 34 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 35 | + |
|
| 36 | + mt_srand($seed); |
|
| 37 | + $s = ''; |
|
| 38 | + $pass = ''; |
|
| 39 | + for ($i = 0; $i < $longueur; $i++) { |
|
| 40 | + if (!$s) { |
|
| 41 | + $s = random_int(0, mt_getrandmax()); |
|
| 42 | + if (!$s) { |
|
| 43 | + $s = random_int(0, mt_getrandmax()); |
|
| 44 | + } |
|
| 45 | + $s = substr(md5(uniqid($s) . $sel), 0, 16); |
|
| 46 | + } |
|
| 47 | + $r = unpack('Cr', pack('H2', $s . $s)); |
|
| 48 | + $x = $r['r'] & 63; |
|
| 49 | + if ($x < 10) { |
|
| 50 | + $x = chr($x + 48); |
|
| 51 | + } else { |
|
| 52 | + if ($x < 36) { |
|
| 53 | + $x = chr($x + 55); |
|
| 54 | + } else { |
|
| 55 | + if ($x < 62) { |
|
| 56 | + $x = chr($x + 61); |
|
| 57 | + } else { |
|
| 58 | + if ($x == 63) { |
|
| 59 | + $x = '/'; |
|
| 60 | + } else { |
|
| 61 | + $x = '.'; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + $pass .= $x; |
|
| 67 | + $s = substr($s, 2); |
|
| 68 | + } |
|
| 69 | + $pass = preg_replace('@[./]@', 'a', $pass); |
|
| 70 | + $pass = preg_replace('@[I1l]@', 'L', $pass); |
|
| 71 | + $pass = preg_replace('@[0O]@', 'o', $pass); |
|
| 72 | + |
|
| 73 | + return $pass; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -79,20 +79,20 @@ discard block |
||
| 79 | 79 | * @return string Identifiant |
| 80 | 80 | */ |
| 81 | 81 | function creer_uniqid() { |
| 82 | - static $seeded; |
|
| 82 | + static $seeded; |
|
| 83 | 83 | |
| 84 | - if (!$seeded) { |
|
| 85 | - $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | - mt_srand($seed); |
|
| 87 | - $seeded = true; |
|
| 88 | - } |
|
| 84 | + if (!$seeded) { |
|
| 85 | + $seed = (int)round(((float)microtime() + 1) * time()); |
|
| 86 | + mt_srand($seed); |
|
| 87 | + $seeded = true; |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - $s = random_int(0, mt_getrandmax()); |
|
| 91 | - if (!$s) { |
|
| 92 | - $s = random_int(0, mt_getrandmax()); |
|
| 93 | - } |
|
| 90 | + $s = random_int(0, mt_getrandmax()); |
|
| 91 | + if (!$s) { |
|
| 92 | + $s = random_int(0, mt_getrandmax()); |
|
| 93 | + } |
|
| 94 | 94 | |
| 95 | - return uniqid($s, 1); |
|
| 95 | + return uniqid($s, 1); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -106,42 +106,42 @@ discard block |
||
| 106 | 106 | * @return string Retourne l'alea éphemère actuel au passage |
| 107 | 107 | */ |
| 108 | 108 | function charger_aleas() { |
| 109 | - if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | - include_spip('base/abstract_sql'); |
|
| 111 | - $aleas = sql_allfetsel( |
|
| 112 | - ['nom', 'valeur'], |
|
| 113 | - 'spip_meta', |
|
| 114 | - sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | - '', |
|
| 116 | - '', |
|
| 117 | - '', |
|
| 118 | - '', |
|
| 119 | - '', |
|
| 120 | - 'continue' |
|
| 121 | - ); |
|
| 122 | - if ($aleas) { |
|
| 123 | - foreach ($aleas as $a) { |
|
| 124 | - $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | - } |
|
| 126 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | - } else { |
|
| 128 | - spip_log('aleas indisponibles', 'session'); |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - return $GLOBALS['meta']['alea_ephemere']; |
|
| 109 | + if (!isset($GLOBALS['meta']['alea_ephemere'])) { |
|
| 110 | + include_spip('base/abstract_sql'); |
|
| 111 | + $aleas = sql_allfetsel( |
|
| 112 | + ['nom', 'valeur'], |
|
| 113 | + 'spip_meta', |
|
| 114 | + sql_in('nom', ['alea_ephemere', 'alea_ephemere_ancien']), |
|
| 115 | + '', |
|
| 116 | + '', |
|
| 117 | + '', |
|
| 118 | + '', |
|
| 119 | + '', |
|
| 120 | + 'continue' |
|
| 121 | + ); |
|
| 122 | + if ($aleas) { |
|
| 123 | + foreach ($aleas as $a) { |
|
| 124 | + $GLOBALS['meta'][$a['nom']] = $a['valeur']; |
|
| 125 | + } |
|
| 126 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 127 | + } else { |
|
| 128 | + spip_log('aleas indisponibles', 'session'); |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + return $GLOBALS['meta']['alea_ephemere']; |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | /** |
| 136 | 136 | * Renouveller l'alea (utilisé pour sécuriser les scripts du répertoire `action/`) |
| 137 | 137 | **/ |
| 138 | 138 | function renouvelle_alea() { |
| 139 | - charger_aleas(); |
|
| 140 | - ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | - $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | - ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | - ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | - spip_log("renouvellement de l'alea_ephemere"); |
|
| 139 | + charger_aleas(); |
|
| 140 | + ecrire_meta('alea_ephemere_ancien', @$GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 141 | + $GLOBALS['meta']['alea_ephemere'] = md5(creer_uniqid()); |
|
| 142 | + ecrire_meta('alea_ephemere', $GLOBALS['meta']['alea_ephemere'], 'non'); |
|
| 143 | + ecrire_meta('alea_ephemere_date', time(), 'non'); |
|
| 144 | + spip_log("renouvellement de l'alea_ephemere"); |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | |
@@ -161,21 +161,21 @@ discard block |
||
| 161 | 161 | * Clé de sécurité. |
| 162 | 162 | **/ |
| 163 | 163 | function low_sec($id_auteur) { |
| 164 | - // Pas d'id_auteur : low_sec |
|
| 165 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | - include_spip('inc/config'); |
|
| 167 | - if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | - ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | - } |
|
| 170 | - } else { |
|
| 171 | - $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | - if (!$low_sec) { |
|
| 173 | - $low_sec = creer_pass_aleatoire(); |
|
| 174 | - sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $low_sec; |
|
| 164 | + // Pas d'id_auteur : low_sec |
|
| 165 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 166 | + include_spip('inc/config'); |
|
| 167 | + if (!$low_sec = lire_config('low_sec')) { |
|
| 168 | + ecrire_meta('low_sec', $low_sec = creer_pass_aleatoire()); |
|
| 169 | + } |
|
| 170 | + } else { |
|
| 171 | + $low_sec = sql_getfetsel('low_sec', 'spip_auteurs', 'id_auteur = ' . intval($id_auteur)); |
|
| 172 | + if (!$low_sec) { |
|
| 173 | + $low_sec = creer_pass_aleatoire(); |
|
| 174 | + sql_updateq('spip_auteurs', ['low_sec' => $low_sec], 'id_auteur = ' . intval($id_auteur)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $low_sec; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | |
@@ -208,11 +208,11 @@ discard block |
||
| 208 | 208 | * @filtre |
| 209 | 209 | */ |
| 210 | 210 | function securiser_acces_low_sec($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 211 | - if ($op) { |
|
| 212 | - $dir .= " $op $args"; |
|
| 213 | - } |
|
| 211 | + if ($op) { |
|
| 212 | + $dir .= " $op $args"; |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 215 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -227,11 +227,11 @@ discard block |
||
| 227 | 227 | * @return string |
| 228 | 228 | */ |
| 229 | 229 | function generer_url_api_low_sec(string $script, string $format, string $fond, string $path, string $args, bool $no_entities = false, ?bool $public = null) { |
| 230 | - $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | - $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | - $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 230 | + $id_auteur = $GLOBALS['visiteur_session']['id_auteur'] ?? 0; |
|
| 231 | + $cle = afficher_low_sec($id_auteur, "$script/$format $fond $args"); |
|
| 232 | + $path = "$id_auteur/$cle/$format/$fond" . ($path ? "/$path" : ''); |
|
| 233 | 233 | |
| 234 | - return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 234 | + return generer_url_api($script, $path, $args, $no_entities = false, $public); |
|
| 235 | 235 | } |
| 236 | 236 | |
| 237 | 237 | |
@@ -249,27 +249,27 @@ discard block |
||
| 249 | 249 | * @deprecated 4.1 |
| 250 | 250 | */ |
| 251 | 251 | function param_low_sec($op, $args = [], $lang = '', $mime = 'rss') { |
| 252 | - $a = $b = ''; |
|
| 253 | - foreach ($args as $val => $var) { |
|
| 254 | - if ($var) { |
|
| 255 | - if ($val <> 'statut') { |
|
| 256 | - $a .= ':' . $val . '-' . $var; |
|
| 257 | - } |
|
| 258 | - $b .= $val . '=' . $var . '&'; |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - $a = substr($a, 1); |
|
| 262 | - $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | - |
|
| 264 | - return $b |
|
| 265 | - . 'op=' |
|
| 266 | - . $op |
|
| 267 | - . '&id=' |
|
| 268 | - . $id |
|
| 269 | - . '&cle=' |
|
| 270 | - . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | - . (!$a ? '' : "&args=$a") |
|
| 272 | - . (!$lang ? '' : "&lang=$lang"); |
|
| 252 | + $a = $b = ''; |
|
| 253 | + foreach ($args as $val => $var) { |
|
| 254 | + if ($var) { |
|
| 255 | + if ($val <> 'statut') { |
|
| 256 | + $a .= ':' . $val . '-' . $var; |
|
| 257 | + } |
|
| 258 | + $b .= $val . '=' . $var . '&'; |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + $a = substr($a, 1); |
|
| 262 | + $id = intval(@$GLOBALS['connect_id_auteur']); |
|
| 263 | + |
|
| 264 | + return $b |
|
| 265 | + . 'op=' |
|
| 266 | + . $op |
|
| 267 | + . '&id=' |
|
| 268 | + . $id |
|
| 269 | + . '&cle=' |
|
| 270 | + . afficher_low_sec($id, "$mime $op $a") |
|
| 271 | + . (!$a ? '' : "&args=$a") |
|
| 272 | + . (!$lang ? '' : "&lang=$lang"); |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | /** |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | * Clé |
| 286 | 286 | **/ |
| 287 | 287 | function afficher_low_sec($id_auteur, $action = '') { |
| 288 | - return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 288 | + return substr(md5($action . low_sec($id_auteur)), 0, 8); |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -303,7 +303,7 @@ discard block |
||
| 303 | 303 | * true si les clés corresponde, false sinon |
| 304 | 304 | **/ |
| 305 | 305 | function verifier_low_sec($id_auteur, $cle, $action = '') { |
| 306 | - return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 306 | + return ($cle == afficher_low_sec($id_auteur, $action)); |
|
| 307 | 307 | } |
| 308 | 308 | |
| 309 | 309 | /** |
@@ -313,10 +313,10 @@ discard block |
||
| 313 | 313 | * Identifiant de l'auteur |
| 314 | 314 | **/ |
| 315 | 315 | function effacer_low_sec($id_auteur) { |
| 316 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | - return; |
|
| 318 | - } // jamais trop prudent ;) |
|
| 319 | - sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 316 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 317 | + return; |
|
| 318 | + } // jamais trop prudent ;) |
|
| 319 | + sql_updateq('spip_auteurs', ['low_sec' => ''], 'id_auteur = ' . intval($id_auteur)); |
|
| 320 | 320 | } |
| 321 | 321 | |
| 322 | 322 | /** |
@@ -325,10 +325,10 @@ discard block |
||
| 325 | 325 | * @return void|bool |
| 326 | 326 | */ |
| 327 | 327 | function initialiser_sel() { |
| 328 | - if (!isset($GLOBALS['htsalt'])) { |
|
| 329 | - $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 330 | - } |
|
| 331 | - return $GLOBALS['htsalt']; |
|
| 328 | + if (!isset($GLOBALS['htsalt'])) { |
|
| 329 | + $GLOBALS['htsalt'] = '$1$' . creer_pass_aleatoire(); |
|
| 330 | + } |
|
| 331 | + return $GLOBALS['htsalt']; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -345,31 +345,31 @@ discard block |
||
| 345 | 345 | * - void sinon. |
| 346 | 346 | **/ |
| 347 | 347 | function ecrire_acces() { |
| 348 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 349 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 350 | - |
|
| 351 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 352 | - // par exemple acces_restreint ; |
|
| 353 | - // si .htaccess existe, outrepasser spip_meta |
|
| 354 | - if ( |
|
| 355 | - (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 356 | - or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 357 | - and !@file_exists($htaccess) |
|
| 358 | - ) { |
|
| 359 | - spip_unlink($htpasswd); |
|
| 360 | - spip_unlink($htpasswd . '-admin'); |
|
| 361 | - return; |
|
| 362 | - } |
|
| 363 | - |
|
| 364 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 365 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 366 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 367 | - // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 368 | - if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 369 | - return; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 348 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 349 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 350 | + |
|
| 351 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 352 | + // par exemple acces_restreint ; |
|
| 353 | + // si .htaccess existe, outrepasser spip_meta |
|
| 354 | + if ( |
|
| 355 | + (!isset($GLOBALS['meta']['creer_htpasswd']) |
|
| 356 | + or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 357 | + and !@file_exists($htaccess) |
|
| 358 | + ) { |
|
| 359 | + spip_unlink($htpasswd); |
|
| 360 | + spip_unlink($htpasswd . '-admin'); |
|
| 361 | + return; |
|
| 362 | + } |
|
| 363 | + |
|
| 364 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 365 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 366 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 367 | + // TODO: factoriser avec auth/spip qui fait deja ce job et generaliser le test auth_ldap_connect() |
|
| 368 | + if (include_spip('auth/ldap') and auth_ldap_connect()) { |
|
| 369 | + return; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + generer_htpasswd_files($htpasswd, "$htpasswd-admin"); |
|
| 373 | 373 | } |
| 374 | 374 | |
| 375 | 375 | /** |
@@ -378,29 +378,29 @@ discard block |
||
| 378 | 378 | * @param $htpasswd_admin |
| 379 | 379 | */ |
| 380 | 380 | function generer_htpasswd_files($htpasswd, $htpasswd_admin) { |
| 381 | - if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 382 | - $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - $pwd_all = ''; // login:htpass pour tous |
|
| 386 | - $pwd_admin = ''; // login:htpass pour les admins |
|
| 387 | - |
|
| 388 | - $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 389 | - while ($row = sql_fetch($res)) { |
|
| 390 | - if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 391 | - $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 392 | - $pwd_all .= $ligne; |
|
| 393 | - if ($row['statut'] == '0minirezo') { |
|
| 394 | - $pwd_admin .= $ligne; |
|
| 395 | - } |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if ($pwd_all) { |
|
| 400 | - ecrire_fichier($htpasswd, $pwd_all); |
|
| 401 | - ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 402 | - spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 403 | - } |
|
| 381 | + if ($generer_htpasswd = charger_fonction('generer_htpasswd_files', 'inc', true)) { |
|
| 382 | + $generer_htpasswd($htpasswd, $htpasswd_admin); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + $pwd_all = ''; // login:htpass pour tous |
|
| 386 | + $pwd_admin = ''; // login:htpass pour les admins |
|
| 387 | + |
|
| 388 | + $res = sql_select('login, htpass, statut', 'spip_auteurs', "htpass!='' AND login!='' AND " . sql_in('statut', ['1comite', '0minirezo', 'nouveau'])); |
|
| 389 | + while ($row = sql_fetch($res)) { |
|
| 390 | + if (strlen($row['login']) and strlen($row['htpass'])) { |
|
| 391 | + $ligne = $row['login'] . ':' . $row['htpass'] . "\n"; |
|
| 392 | + $pwd_all .= $ligne; |
|
| 393 | + if ($row['statut'] == '0minirezo') { |
|
| 394 | + $pwd_admin .= $ligne; |
|
| 395 | + } |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if ($pwd_all) { |
|
| 400 | + ecrire_fichier($htpasswd, $pwd_all); |
|
| 401 | + ecrire_fichier($htpasswd_admin, $pwd_admin); |
|
| 402 | + spip_log("Ecriture de $htpasswd et $htpasswd_admin", 'htpass'); |
|
| 403 | + } |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -414,13 +414,13 @@ discard block |
||
| 414 | 414 | * La chaîne hachée si fonction crypt présente, rien sinon. |
| 415 | 415 | */ |
| 416 | 416 | function generer_htpass($pass) { |
| 417 | - if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 418 | - return $generer_htpass($pass); |
|
| 419 | - } |
|
| 420 | - elseif (function_exists('crypt')) { |
|
| 421 | - return crypt($pass, initialiser_sel()); |
|
| 422 | - } |
|
| 423 | - return ''; |
|
| 417 | + if ($generer_htpass = charger_fonction('generer_htpass', 'inc', true)) { |
|
| 418 | + return $generer_htpass($pass); |
|
| 419 | + } |
|
| 420 | + elseif (function_exists('crypt')) { |
|
| 421 | + return crypt($pass, initialiser_sel()); |
|
| 422 | + } |
|
| 423 | + return ''; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -433,14 +433,14 @@ discard block |
||
| 433 | 433 | * @return boolean |
| 434 | 434 | */ |
| 435 | 435 | function verifier_htaccess($rep, $force = false) { |
| 436 | - $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 437 | - if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 438 | - return true; |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - // directive deny compatible Apache 2.0+ |
|
| 442 | - $deny = |
|
| 443 | - '# Deny all requests from Apache 2.4+. |
|
| 436 | + $htaccess = rtrim($rep, '/') . '/' . _ACCESS_FILE_NAME; |
|
| 437 | + if (((@file_exists($htaccess)) or defined('_TEST_DIRS')) and !$force) { |
|
| 438 | + return true; |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + // directive deny compatible Apache 2.0+ |
|
| 442 | + $deny = |
|
| 443 | + '# Deny all requests from Apache 2.4+. |
|
| 444 | 444 | <IfModule mod_authz_core.c> |
| 445 | 445 | Require all denied |
| 446 | 446 | </IfModule> |
@@ -449,32 +449,32 @@ discard block |
||
| 449 | 449 | Deny from all |
| 450 | 450 | </IfModule> |
| 451 | 451 | '; |
| 452 | - // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 453 | - if ( |
|
| 454 | - function_exists('apache_get_version') |
|
| 455 | - and $v = apache_get_version() |
|
| 456 | - and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 457 | - ) { |
|
| 458 | - $deny = "deny from all\n"; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - if ($ht = @fopen($htaccess, 'w')) { |
|
| 462 | - fputs($ht, $deny); |
|
| 463 | - fclose($ht); |
|
| 464 | - @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 465 | - $t = rtrim($rep, '/') . '/.ok'; |
|
| 466 | - if ($ht = @fopen($t, 'w')) { |
|
| 467 | - @fclose($ht); |
|
| 468 | - include_spip('inc/distant'); |
|
| 469 | - $t = substr($t, strlen(_DIR_RACINE)); |
|
| 470 | - $t = url_de_base() . $t; |
|
| 471 | - $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 472 | - $ht = ($ht['status'] ?? null) === 403; |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 476 | - |
|
| 477 | - return $ht; |
|
| 452 | + // support des vieilles versions Apache 1.x mais uniquement si elles l'annoncent (pas en mode PROD) |
|
| 453 | + if ( |
|
| 454 | + function_exists('apache_get_version') |
|
| 455 | + and $v = apache_get_version() |
|
| 456 | + and strncmp($v, 'Apache/1.', 9) == 0 |
|
| 457 | + ) { |
|
| 458 | + $deny = "deny from all\n"; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if ($ht = @fopen($htaccess, 'w')) { |
|
| 462 | + fputs($ht, $deny); |
|
| 463 | + fclose($ht); |
|
| 464 | + @chmod($htaccess, _SPIP_CHMOD & 0666); |
|
| 465 | + $t = rtrim($rep, '/') . '/.ok'; |
|
| 466 | + if ($ht = @fopen($t, 'w')) { |
|
| 467 | + @fclose($ht); |
|
| 468 | + include_spip('inc/distant'); |
|
| 469 | + $t = substr($t, strlen(_DIR_RACINE)); |
|
| 470 | + $t = url_de_base() . $t; |
|
| 471 | + $ht = recuperer_url($t, ['methode' => 'HEAD', 'taille_max' => 0, 'follow_location' => false]); |
|
| 472 | + $ht = ($ht['status'] ?? null) === 403; |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + spip_log("Creation de $htaccess " . ($ht ? ' reussie' : ' manquee')); |
|
| 476 | + |
|
| 477 | + return $ht; |
|
| 478 | 478 | } |
| 479 | 479 | |
| 480 | 480 | /** |
@@ -492,20 +492,20 @@ discard block |
||
| 492 | 492 | * Valeur de la configuration `creer_htaccess` |
| 493 | 493 | */ |
| 494 | 494 | function gerer_htaccess() { |
| 495 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 496 | - // par exemple acces_restreint |
|
| 497 | - $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 498 | - $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 499 | - $dirs[] = ['extension' => 'distant']; |
|
| 500 | - foreach ($dirs as $e) { |
|
| 501 | - if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 502 | - if ($f) { |
|
| 503 | - verifier_htaccess($dir); |
|
| 504 | - } else { |
|
| 505 | - spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 506 | - } |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 495 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 496 | + // par exemple acces_restreint |
|
| 497 | + $f = (isset($GLOBALS['meta']['creer_htaccess']) and ($GLOBALS['meta']['creer_htaccess'] === 'oui')); |
|
| 498 | + $dirs = sql_allfetsel('extension', 'spip_types_documents'); |
|
| 499 | + $dirs[] = ['extension' => 'distant']; |
|
| 500 | + foreach ($dirs as $e) { |
|
| 501 | + if (is_dir($dir = _DIR_IMG . $e['extension'])) { |
|
| 502 | + if ($f) { |
|
| 503 | + verifier_htaccess($dir); |
|
| 504 | + } else { |
|
| 505 | + spip_unlink($dir . '/' . _ACCESS_FILE_NAME); |
|
| 506 | + } |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + return $GLOBALS['meta']['creer_htaccess'] ?? ''; |
|
| 511 | 511 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | require_once _ROOT_RESTREINT . 'base/objets.php'; |
| 22 | 22 | |
@@ -42,118 +42,118 @@ discard block |
||
| 42 | 42 | **/ |
| 43 | 43 | function spip_connect($serveur = '', $version = '') { |
| 44 | 44 | |
| 45 | - $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | - $index = $serveur ?: 0; |
|
| 47 | - if (!$version) { |
|
| 48 | - $version = $GLOBALS['spip_sql_version']; |
|
| 49 | - } |
|
| 50 | - if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | - return $GLOBALS['connexions'][$index]; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - include_spip('base/abstract_sql'); |
|
| 55 | - $install = (_request('exec') == 'install'); |
|
| 56 | - |
|
| 57 | - // Premiere connexion ? |
|
| 58 | - if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | - $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | - ? '' // nom de serveur mal ecrit |
|
| 61 | - : ($serveur ? |
|
| 62 | - (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | - : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 64 | - : ''))); // installation pas faite |
|
| 65 | - |
|
| 66 | - unset($GLOBALS['db_ok']); |
|
| 67 | - unset($GLOBALS['spip_connect_version']); |
|
| 68 | - if ($f) { |
|
| 69 | - if (is_readable($f)) { |
|
| 70 | - include($f); |
|
| 71 | - } elseif ($serveur and !$install) { |
|
| 72 | - // chercher une declaration de serveur dans le path |
|
| 73 | - // qui pourra un jour servir a declarer des bases sqlite |
|
| 74 | - // par des plugins. Et sert aussi aux boucles POUR. |
|
| 75 | - find_in_path("$serveur.php", 'connect/', true); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!isset($GLOBALS['db_ok'])) { |
|
| 79 | - // fera mieux la prochaine fois |
|
| 80 | - if ($install) { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - if ($f and is_readable($f)) { |
|
| 84 | - spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 85 | - } else { |
|
| 86 | - spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 87 | - } |
|
| 88 | - spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 89 | - |
|
| 90 | - // ne plus reessayer si ce n'est pas l'install |
|
| 91 | - return $GLOBALS['connexions'][$index] = false; |
|
| 92 | - } |
|
| 93 | - $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 94 | - } |
|
| 95 | - // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 96 | - if (!$GLOBALS['connexions'][$index]) { |
|
| 97 | - return false; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // la connexion a reussi ou etait deja faite. |
|
| 101 | - // chargement de la version du jeu de fonctions |
|
| 102 | - // si pas dans le fichier par defaut |
|
| 103 | - $type = $GLOBALS['db_ok']['type']; |
|
| 104 | - $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | - if (!isset($GLOBALS[$jeu])) { |
|
| 106 | - if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | - spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 108 | - |
|
| 109 | - // ne plus reessayer |
|
| 110 | - return $GLOBALS['connexions'][$index][$version] = []; |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 114 | - if ($old) { |
|
| 115 | - return $GLOBALS['connexions'][$index]; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 119 | - |
|
| 120 | - // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 121 | - // si l'installation l'a determine. |
|
| 122 | - // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 123 | - // s'ils le connaissent |
|
| 124 | - |
|
| 125 | - if (!$serveur) { |
|
| 126 | - $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 127 | - if (!$charset) { |
|
| 128 | - unset($GLOBALS['connexions'][$index]); |
|
| 129 | - spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 130 | - |
|
| 131 | - return false; |
|
| 132 | - } |
|
| 133 | - } else { |
|
| 134 | - if ($GLOBALS['db_ok']['charset']) { |
|
| 135 | - $charset = $GLOBALS['db_ok']['charset']; |
|
| 136 | - } |
|
| 137 | - // spip_meta n'existe pas toujours dans la base |
|
| 138 | - // C'est le cas d'un dump sqlite par exemple |
|
| 139 | - elseif ( |
|
| 140 | - $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | - and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | - and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | - ) { |
|
| 144 | - $charset = $r; |
|
| 145 | - } else { |
|
| 146 | - $charset = -1; |
|
| 147 | - } |
|
| 148 | - } |
|
| 149 | - if ($charset != -1) { |
|
| 150 | - $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | - if (function_exists($f)) { |
|
| 152 | - $f($charset, $serveur); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $GLOBALS['connexions'][$index]; |
|
| 45 | + $serveur = !is_string($serveur) ? '' : strtolower($serveur); |
|
| 46 | + $index = $serveur ?: 0; |
|
| 47 | + if (!$version) { |
|
| 48 | + $version = $GLOBALS['spip_sql_version']; |
|
| 49 | + } |
|
| 50 | + if (isset($GLOBALS['connexions'][$index][$version])) { |
|
| 51 | + return $GLOBALS['connexions'][$index]; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + include_spip('base/abstract_sql'); |
|
| 55 | + $install = (_request('exec') == 'install'); |
|
| 56 | + |
|
| 57 | + // Premiere connexion ? |
|
| 58 | + if (!($old = isset($GLOBALS['connexions'][$index]))) { |
|
| 59 | + $f = (!preg_match('/^[\w\.]*$/', $serveur)) |
|
| 60 | + ? '' // nom de serveur mal ecrit |
|
| 61 | + : ($serveur ? |
|
| 62 | + (_DIR_CONNECT . $serveur . '.php') // serveur externe |
|
| 63 | + : (_FILE_CONNECT ?: ($install ? _FILE_CONNECT_TMP // init du serveur principal |
|
| 64 | + : ''))); // installation pas faite |
|
| 65 | + |
|
| 66 | + unset($GLOBALS['db_ok']); |
|
| 67 | + unset($GLOBALS['spip_connect_version']); |
|
| 68 | + if ($f) { |
|
| 69 | + if (is_readable($f)) { |
|
| 70 | + include($f); |
|
| 71 | + } elseif ($serveur and !$install) { |
|
| 72 | + // chercher une declaration de serveur dans le path |
|
| 73 | + // qui pourra un jour servir a declarer des bases sqlite |
|
| 74 | + // par des plugins. Et sert aussi aux boucles POUR. |
|
| 75 | + find_in_path("$serveur.php", 'connect/', true); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!isset($GLOBALS['db_ok'])) { |
|
| 79 | + // fera mieux la prochaine fois |
|
| 80 | + if ($install) { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + if ($f and is_readable($f)) { |
|
| 84 | + spip_log("spip_connect: fichier de connexion '$f' OK.", _LOG_INFO_IMPORTANTE); |
|
| 85 | + } else { |
|
| 86 | + spip_log("spip_connect: fichier de connexion '$f' non trouve", _LOG_INFO_IMPORTANTE); |
|
| 87 | + } |
|
| 88 | + spip_log("spip_connect: echec connexion ou serveur $index mal defini dans '$f'.", _LOG_HS); |
|
| 89 | + |
|
| 90 | + // ne plus reessayer si ce n'est pas l'install |
|
| 91 | + return $GLOBALS['connexions'][$index] = false; |
|
| 92 | + } |
|
| 93 | + $GLOBALS['connexions'][$index] = $GLOBALS['db_ok']; |
|
| 94 | + } |
|
| 95 | + // si la connexion a deja ete tentee mais a echoue, le dire! |
|
| 96 | + if (!$GLOBALS['connexions'][$index]) { |
|
| 97 | + return false; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // la connexion a reussi ou etait deja faite. |
|
| 101 | + // chargement de la version du jeu de fonctions |
|
| 102 | + // si pas dans le fichier par defaut |
|
| 103 | + $type = $GLOBALS['db_ok']['type']; |
|
| 104 | + $jeu = 'spip_' . $type . '_functions_' . $version; |
|
| 105 | + if (!isset($GLOBALS[$jeu])) { |
|
| 106 | + if (!find_in_path($type . '_' . $version . '.php', 'req/', true)) { |
|
| 107 | + spip_log("spip_connect: serveur $index version '$version' non defini pour '$type'", _LOG_HS); |
|
| 108 | + |
|
| 109 | + // ne plus reessayer |
|
| 110 | + return $GLOBALS['connexions'][$index][$version] = []; |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + $GLOBALS['connexions'][$index][$version] = $GLOBALS[$jeu]; |
|
| 114 | + if ($old) { |
|
| 115 | + return $GLOBALS['connexions'][$index]; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + $GLOBALS['connexions'][$index]['spip_connect_version'] = $GLOBALS['spip_connect_version'] ?? 0; |
|
| 119 | + |
|
| 120 | + // initialisation de l'alphabet utilise dans les connexions SQL |
|
| 121 | + // si l'installation l'a determine. |
|
| 122 | + // Celui du serveur principal l'impose aux serveurs secondaires |
|
| 123 | + // s'ils le connaissent |
|
| 124 | + |
|
| 125 | + if (!$serveur) { |
|
| 126 | + $charset = spip_connect_main($GLOBALS[$jeu], $GLOBALS['db_ok']['charset']); |
|
| 127 | + if (!$charset) { |
|
| 128 | + unset($GLOBALS['connexions'][$index]); |
|
| 129 | + spip_log('spip_connect: absence de charset', _LOG_AVERTISSEMENT); |
|
| 130 | + |
|
| 131 | + return false; |
|
| 132 | + } |
|
| 133 | + } else { |
|
| 134 | + if ($GLOBALS['db_ok']['charset']) { |
|
| 135 | + $charset = $GLOBALS['db_ok']['charset']; |
|
| 136 | + } |
|
| 137 | + // spip_meta n'existe pas toujours dans la base |
|
| 138 | + // C'est le cas d'un dump sqlite par exemple |
|
| 139 | + elseif ( |
|
| 140 | + $GLOBALS['connexions'][$index]['spip_connect_version'] |
|
| 141 | + and sql_showtable('spip_meta', true, $serveur) |
|
| 142 | + and $r = sql_getfetsel('valeur', 'spip_meta', "nom='charset_sql_connexion'", '', '', '', '', $serveur) |
|
| 143 | + ) { |
|
| 144 | + $charset = $r; |
|
| 145 | + } else { |
|
| 146 | + $charset = -1; |
|
| 147 | + } |
|
| 148 | + } |
|
| 149 | + if ($charset != -1) { |
|
| 150 | + $f = $GLOBALS[$jeu]['set_charset']; |
|
| 151 | + if (function_exists($f)) { |
|
| 152 | + $f($charset, $serveur); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $GLOBALS['connexions'][$index]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @param string $serveur Nom du connecteur de bdd utilisé |
| 163 | 163 | **/ |
| 164 | 164 | function spip_sql_erreur($serveur = '') { |
| 165 | - $connexion = spip_connect($serveur); |
|
| 166 | - $e = sql_errno($serveur); |
|
| 167 | - $t = ($connexion['type'] ?? 'sql'); |
|
| 168 | - $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | - $f = $t . $serveur; |
|
| 170 | - spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 165 | + $connexion = spip_connect($serveur); |
|
| 166 | + $e = sql_errno($serveur); |
|
| 167 | + $t = ($connexion['type'] ?? 'sql'); |
|
| 168 | + $m = "Erreur $e de $t: " . sql_error($serveur) . "\nin " . sql_error_backtrace() . "\n" . trim($connexion['last']); |
|
| 169 | + $f = $t . $serveur; |
|
| 170 | + spip_log($m, $f . '.' . _LOG_ERREUR); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -189,23 +189,23 @@ discard block |
||
| 189 | 189 | * - array : description de la connexion, si l'instruction sql est indisponible pour cette connexion |
| 190 | 190 | **/ |
| 191 | 191 | function spip_connect_sql($version, $ins = '', $serveur = '', $continue = false) { |
| 192 | - $desc = spip_connect($serveur, $version); |
|
| 193 | - if ( |
|
| 194 | - $desc |
|
| 195 | - and $f = ($desc[$version][$ins] ?? '') |
|
| 196 | - and function_exists($f) |
|
| 197 | - ) { |
|
| 198 | - return $f; |
|
| 199 | - } |
|
| 200 | - if ($continue) { |
|
| 201 | - return $desc; |
|
| 202 | - } |
|
| 203 | - if ($ins) { |
|
| 204 | - spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 205 | - } |
|
| 206 | - include_spip('inc/minipres'); |
|
| 207 | - echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 208 | - exit; |
|
| 192 | + $desc = spip_connect($serveur, $version); |
|
| 193 | + if ( |
|
| 194 | + $desc |
|
| 195 | + and $f = ($desc[$version][$ins] ?? '') |
|
| 196 | + and function_exists($f) |
|
| 197 | + ) { |
|
| 198 | + return $f; |
|
| 199 | + } |
|
| 200 | + if ($continue) { |
|
| 201 | + return $desc; |
|
| 202 | + } |
|
| 203 | + if ($ins) { |
|
| 204 | + spip_log("Le serveur '$serveur' version $version n'a pas '$ins'", _LOG_ERREUR); |
|
| 205 | + } |
|
| 206 | + include_spip('inc/minipres'); |
|
| 207 | + echo minipres(_T('info_travaux_titre'), _T('titre_probleme_technique'), ['status' => 503]); |
|
| 208 | + exit; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -231,70 +231,70 @@ discard block |
||
| 231 | 231 | * @return array|null Description de la connexion |
| 232 | 232 | */ |
| 233 | 233 | function spip_connect_db( |
| 234 | - $host, |
|
| 235 | - $port, |
|
| 236 | - $login, |
|
| 237 | - $pass, |
|
| 238 | - $db = '', |
|
| 239 | - $type = 'mysql', |
|
| 240 | - $prefixe = '', |
|
| 241 | - $auth = '', |
|
| 242 | - $charset = '' |
|
| 234 | + $host, |
|
| 235 | + $port, |
|
| 236 | + $login, |
|
| 237 | + $pass, |
|
| 238 | + $db = '', |
|
| 239 | + $type = 'mysql', |
|
| 240 | + $prefixe = '', |
|
| 241 | + $auth = '', |
|
| 242 | + $charset = '' |
|
| 243 | 243 | ) { |
| 244 | - // temps avant nouvelle tentative de connexion |
|
| 245 | - // suite a une connection echouee |
|
| 246 | - if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 247 | - define('_CONNECT_RETRY_DELAY', 30); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - $f = ''; |
|
| 251 | - // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 252 | - // pour ne pas declarer tout indisponible d'un coup |
|
| 253 | - // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 254 | - // car c'est un test de connexion |
|
| 255 | - if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 256 | - $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 257 | - } elseif ($db == '@test@') { |
|
| 258 | - $db = ''; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - $f |
|
| 263 | - and @file_exists($f) |
|
| 264 | - and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 265 | - ) { |
|
| 266 | - spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 267 | - |
|
| 268 | - return null; |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - if (!$prefixe) { |
|
| 272 | - $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 273 | - } |
|
| 274 | - $h = charger_fonction($type, 'req', true); |
|
| 275 | - if (!$h) { |
|
| 276 | - spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 277 | - |
|
| 278 | - return null; |
|
| 279 | - } |
|
| 280 | - if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 281 | - if (!is_array($auth)) { |
|
| 282 | - // compatibilite version 0.7 initiale |
|
| 283 | - $g['ldap'] = $auth; |
|
| 284 | - $auth = ['ldap' => $auth]; |
|
| 285 | - } |
|
| 286 | - $g['authentification'] = $auth; |
|
| 287 | - $g['type'] = $type; |
|
| 288 | - $g['charset'] = $charset; |
|
| 289 | - |
|
| 290 | - return $GLOBALS['db_ok'] = $g; |
|
| 291 | - } |
|
| 292 | - // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 293 | - if ($f) { |
|
| 294 | - @touch($f); |
|
| 295 | - spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 296 | - } |
|
| 297 | - return null; |
|
| 244 | + // temps avant nouvelle tentative de connexion |
|
| 245 | + // suite a une connection echouee |
|
| 246 | + if (!defined('_CONNECT_RETRY_DELAY')) { |
|
| 247 | + define('_CONNECT_RETRY_DELAY', 30); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + $f = ''; |
|
| 251 | + // un fichier de identifiant par combinaison (type,host,port,db) |
|
| 252 | + // pour ne pas declarer tout indisponible d'un coup |
|
| 253 | + // si en cours d'installation ou si db=@test@ on ne pose rien |
|
| 254 | + // car c'est un test de connexion |
|
| 255 | + if (!defined('_ECRIRE_INSTALL') and $db !== '@test@') { |
|
| 256 | + $f = _DIR_TMP . $type . '.' . substr(md5($host . $port . $db), 0, 8) . '.out'; |
|
| 257 | + } elseif ($db == '@test@') { |
|
| 258 | + $db = ''; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + $f |
|
| 263 | + and @file_exists($f) |
|
| 264 | + and (time() - @filemtime($f) < _CONNECT_RETRY_DELAY) |
|
| 265 | + ) { |
|
| 266 | + spip_log("Echec : $f recent. Pas de tentative de connexion", _LOG_HS); |
|
| 267 | + |
|
| 268 | + return null; |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + if (!$prefixe) { |
|
| 272 | + $prefixe = $GLOBALS['table_prefix'] ?? $db; |
|
| 273 | + } |
|
| 274 | + $h = charger_fonction($type, 'req', true); |
|
| 275 | + if (!$h) { |
|
| 276 | + spip_log("les requetes $type ne sont pas fournies", _LOG_HS); |
|
| 277 | + |
|
| 278 | + return null; |
|
| 279 | + } |
|
| 280 | + if ($g = $h($host, $port, $login, $pass, $db, $prefixe)) { |
|
| 281 | + if (!is_array($auth)) { |
|
| 282 | + // compatibilite version 0.7 initiale |
|
| 283 | + $g['ldap'] = $auth; |
|
| 284 | + $auth = ['ldap' => $auth]; |
|
| 285 | + } |
|
| 286 | + $g['authentification'] = $auth; |
|
| 287 | + $g['type'] = $type; |
|
| 288 | + $g['charset'] = $charset; |
|
| 289 | + |
|
| 290 | + return $GLOBALS['db_ok'] = $g; |
|
| 291 | + } |
|
| 292 | + // En cas d'indisponibilite du serveur, eviter de le bombarder |
|
| 293 | + if ($f) { |
|
| 294 | + @touch($f); |
|
| 295 | + spip_log("Echec connexion serveur $type : host[$host] port[$port] login[$login] base[$db]", $type . '.' . _LOG_HS); |
|
| 296 | + } |
|
| 297 | + return null; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -326,32 +326,32 @@ discard block |
||
| 326 | 326 | * - nom du charset sinon |
| 327 | 327 | **/ |
| 328 | 328 | function spip_connect_main($connexion, $charset_sql_connexion = '') { |
| 329 | - if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 330 | - include_spip('inc/headers'); |
|
| 331 | - redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 332 | - } |
|
| 333 | - |
|
| 334 | - if (!($f = $connexion['select'])) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - // si le charset est fourni, l'utiliser |
|
| 338 | - if ($charset_sql_connexion) { |
|
| 339 | - return $charset_sql_connexion; |
|
| 340 | - } |
|
| 341 | - // sinon on regarde la table spip_meta |
|
| 342 | - // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 343 | - if ( |
|
| 344 | - !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 345 | - or is_string($r) |
|
| 346 | - ) { |
|
| 347 | - return false; |
|
| 348 | - } |
|
| 349 | - if (!($f = $connexion['fetch'])) { |
|
| 350 | - return false; |
|
| 351 | - } |
|
| 352 | - $r = $f($r); |
|
| 353 | - |
|
| 354 | - return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 329 | + if ($GLOBALS['spip_connect_version'] < 0.1 and _DIR_RESTREINT) { |
|
| 330 | + include_spip('inc/headers'); |
|
| 331 | + redirige_url_ecrire('upgrade', 'reinstall=oui'); |
|
| 332 | + } |
|
| 333 | + |
|
| 334 | + if (!($f = $connexion['select'])) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + // si le charset est fourni, l'utiliser |
|
| 338 | + if ($charset_sql_connexion) { |
|
| 339 | + return $charset_sql_connexion; |
|
| 340 | + } |
|
| 341 | + // sinon on regarde la table spip_meta |
|
| 342 | + // en cas d'erreur select retourne la requette (is_string=true donc) |
|
| 343 | + if ( |
|
| 344 | + !$r = $f('valeur', 'spip_meta', "nom='charset_sql_connexion'") |
|
| 345 | + or is_string($r) |
|
| 346 | + ) { |
|
| 347 | + return false; |
|
| 348 | + } |
|
| 349 | + if (!($f = $connexion['fetch'])) { |
|
| 350 | + return false; |
|
| 351 | + } |
|
| 352 | + $r = $f($r); |
|
| 353 | + |
|
| 354 | + return (isset($r['valeur']) && $r['valeur']) ? $r['valeur'] : -1; |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -367,8 +367,8 @@ discard block |
||
| 367 | 367 | * @return array |
| 368 | 368 | */ |
| 369 | 369 | function spip_connect_ldap($serveur = '') { |
| 370 | - include_spip('auth/ldap'); |
|
| 371 | - return auth_ldap_connect($serveur); |
|
| 370 | + include_spip('auth/ldap'); |
|
| 371 | + return auth_ldap_connect($serveur); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | /** |
@@ -384,16 +384,16 @@ discard block |
||
| 384 | 384 | * @return string Valeur échappée. |
| 385 | 385 | **/ |
| 386 | 386 | function _q($a): string { |
| 387 | - if (is_numeric($a)) { |
|
| 388 | - return strval($a); |
|
| 389 | - } elseif (is_array($a)) { |
|
| 390 | - return join(',', array_map('_q', $a)); |
|
| 391 | - } elseif (is_scalar($a)) { |
|
| 392 | - return ("'" . addslashes($a) . "'"); |
|
| 393 | - } elseif ($a === null) { |
|
| 394 | - return "''"; |
|
| 395 | - } |
|
| 396 | - throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 387 | + if (is_numeric($a)) { |
|
| 388 | + return strval($a); |
|
| 389 | + } elseif (is_array($a)) { |
|
| 390 | + return join(',', array_map('_q', $a)); |
|
| 391 | + } elseif (is_scalar($a)) { |
|
| 392 | + return ("'" . addslashes($a) . "'"); |
|
| 393 | + } elseif ($a === null) { |
|
| 394 | + return "''"; |
|
| 395 | + } |
|
| 396 | + throw new \RuntimeException('Can’t use _q with ' . gettype($a)); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -409,75 +409,75 @@ discard block |
||
| 409 | 409 | * @return array |
| 410 | 410 | */ |
| 411 | 411 | function query_echappe_textes($query, $uniqid = null) { |
| 412 | - static $codeEchappements = null; |
|
| 413 | - if (is_null($codeEchappements) or $uniqid) { |
|
| 414 | - if (is_null($uniqid)) { |
|
| 415 | - $uniqid = uniqid(); |
|
| 416 | - } |
|
| 417 | - $uniqid = substr(md5($uniqid), 0, 4); |
|
| 418 | - $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 419 | - } |
|
| 420 | - if ($query === null) { |
|
| 421 | - return $codeEchappements; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 425 | - // ce n'est pas un cas legitime |
|
| 426 | - foreach ($codeEchappements as $codeEchappement) { |
|
| 427 | - if (strpos($query, (string) $codeEchappement) !== false) { |
|
| 428 | - return [$query, []]; |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 433 | - if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 434 | - $textes = reset($textes); |
|
| 435 | - |
|
| 436 | - $parts = []; |
|
| 437 | - $currentpos = 0; |
|
| 438 | - $k = 0; |
|
| 439 | - while (count($textes)) { |
|
| 440 | - $part = array_shift($textes); |
|
| 441 | - $nextpos = strpos($query_echappees, $part, $currentpos); |
|
| 442 | - // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 443 | - while (count($textes) and substr($part, -1) === "'") { |
|
| 444 | - $next = reset($textes); |
|
| 445 | - if ( |
|
| 446 | - strpos($next, "'") === 0 |
|
| 447 | - and strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 448 | - ) { |
|
| 449 | - $part .= array_shift($textes); |
|
| 450 | - } |
|
| 451 | - else { |
|
| 452 | - break; |
|
| 453 | - } |
|
| 454 | - } |
|
| 455 | - $k++; |
|
| 456 | - $parts[$k] = [ |
|
| 457 | - 'texte' => $part, |
|
| 458 | - 'position' => $nextpos, |
|
| 459 | - 'placeholder' => '%' . $k . '$s', |
|
| 460 | - ]; |
|
| 461 | - $currentpos = $nextpos + strlen($part); |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - // et on replace les parts une par une en commencant par la fin |
|
| 465 | - while ($k > 0) { |
|
| 466 | - $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen($parts[$k]['texte'])); |
|
| 467 | - $k--; |
|
| 468 | - } |
|
| 469 | - $textes = array_column($parts, 'texte'); |
|
| 470 | - } else { |
|
| 471 | - $textes = []; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 475 | - // dans le doute on ne touche a rien |
|
| 476 | - if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 477 | - return [$query, []]; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - return [$query_echappees, $textes]; |
|
| 412 | + static $codeEchappements = null; |
|
| 413 | + if (is_null($codeEchappements) or $uniqid) { |
|
| 414 | + if (is_null($uniqid)) { |
|
| 415 | + $uniqid = uniqid(); |
|
| 416 | + } |
|
| 417 | + $uniqid = substr(md5($uniqid), 0, 4); |
|
| 418 | + $codeEchappements = ['\\\\' => "\x1@#{$uniqid}#@\x1", "\\'" => "\x2@#{$uniqid}#@\x2", '\\"' => "\x3@#{$uniqid}#@\x3", '%' => "\x4@#{$uniqid}#@\x4"]; |
|
| 419 | + } |
|
| 420 | + if ($query === null) { |
|
| 421 | + return $codeEchappements; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // si la query contient deja des codes d'echappement on va s'emmeler les pinceaux et donc on ne touche a rien |
|
| 425 | + // ce n'est pas un cas legitime |
|
| 426 | + foreach ($codeEchappements as $codeEchappement) { |
|
| 427 | + if (strpos($query, (string) $codeEchappement) !== false) { |
|
| 428 | + return [$query, []]; |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + $query_echappees = str_replace(array_keys($codeEchappements), array_values($codeEchappements), $query); |
|
| 433 | + if (preg_match_all("/('[^']*')|(\"[^\"]*\")/S", $query_echappees, $textes)) { |
|
| 434 | + $textes = reset($textes); |
|
| 435 | + |
|
| 436 | + $parts = []; |
|
| 437 | + $currentpos = 0; |
|
| 438 | + $k = 0; |
|
| 439 | + while (count($textes)) { |
|
| 440 | + $part = array_shift($textes); |
|
| 441 | + $nextpos = strpos($query_echappees, $part, $currentpos); |
|
| 442 | + // si besoin recoller ensemble les doubles '' de sqlite (echappement des ') |
|
| 443 | + while (count($textes) and substr($part, -1) === "'") { |
|
| 444 | + $next = reset($textes); |
|
| 445 | + if ( |
|
| 446 | + strpos($next, "'") === 0 |
|
| 447 | + and strpos($query_echappees, $part . $next, $currentpos) === $nextpos |
|
| 448 | + ) { |
|
| 449 | + $part .= array_shift($textes); |
|
| 450 | + } |
|
| 451 | + else { |
|
| 452 | + break; |
|
| 453 | + } |
|
| 454 | + } |
|
| 455 | + $k++; |
|
| 456 | + $parts[$k] = [ |
|
| 457 | + 'texte' => $part, |
|
| 458 | + 'position' => $nextpos, |
|
| 459 | + 'placeholder' => '%' . $k . '$s', |
|
| 460 | + ]; |
|
| 461 | + $currentpos = $nextpos + strlen($part); |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + // et on replace les parts une par une en commencant par la fin |
|
| 465 | + while ($k > 0) { |
|
| 466 | + $query_echappees = substr_replace($query_echappees, $parts[$k]['placeholder'], $parts[$k]['position'], strlen($parts[$k]['texte'])); |
|
| 467 | + $k--; |
|
| 468 | + } |
|
| 469 | + $textes = array_column($parts, 'texte'); |
|
| 470 | + } else { |
|
| 471 | + $textes = []; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // si il reste des quotes simples ou doubles, c'est qu'on s'est emmelle les pinceaux |
|
| 475 | + // dans le doute on ne touche a rien |
|
| 476 | + if (strpbrk($query_echappees, "'\"") !== false) { |
|
| 477 | + return [$query, []]; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + return [$query_echappees, $textes]; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -491,16 +491,16 @@ discard block |
||
| 491 | 491 | * @return string |
| 492 | 492 | */ |
| 493 | 493 | function query_reinjecte_textes($query, $textes) { |
| 494 | - // recuperer les codes echappements |
|
| 495 | - $codeEchappements = query_echappe_textes(null); |
|
| 494 | + // recuperer les codes echappements |
|
| 495 | + $codeEchappements = query_echappe_textes(null); |
|
| 496 | 496 | |
| 497 | - if (!empty($textes)) { |
|
| 498 | - $query = sprintf($query, ...$textes); |
|
| 499 | - } |
|
| 497 | + if (!empty($textes)) { |
|
| 498 | + $query = sprintf($query, ...$textes); |
|
| 499 | + } |
|
| 500 | 500 | |
| 501 | - $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 501 | + $query = str_replace(array_values($codeEchappements), array_keys($codeEchappements), $query); |
|
| 502 | 502 | |
| 503 | - return $query; |
|
| 503 | + return $query; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | |
@@ -519,7 +519,7 @@ discard block |
||
| 519 | 519 | **/ |
| 520 | 520 | function spip_query($query, $serveur = '') { |
| 521 | 521 | |
| 522 | - $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 522 | + $f = spip_connect_sql($GLOBALS['spip_sql_version'], 'query', $serveur, true); |
|
| 523 | 523 | |
| 524 | - return function_exists($f) ? $f($query, $serveur) : false; |
|
| 524 | + return function_exists($f) ? $f($query, $serveur) : false; |
|
| 525 | 525 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -35,18 +35,18 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
| 38 | - // (re)mettre .htaccess avec deny from all |
|
| 39 | - // dans les deux repertoires dits inaccessibles par http |
|
| 40 | - include_spip('inc/acces'); |
|
| 41 | - verifier_htaccess(_DIR_ETC); |
|
| 42 | - verifier_htaccess(_DIR_TMP); |
|
| 38 | + // (re)mettre .htaccess avec deny from all |
|
| 39 | + // dans les deux repertoires dits inaccessibles par http |
|
| 40 | + include_spip('inc/acces'); |
|
| 41 | + verifier_htaccess(_DIR_ETC); |
|
| 42 | + verifier_htaccess(_DIR_TMP); |
|
| 43 | 43 | |
| 44 | - // Verifier qu'aucune table n'est crashee |
|
| 45 | - if (!_request('reinstall')) { |
|
| 46 | - verifier_crash_tables(); |
|
| 47 | - } |
|
| 44 | + // Verifier qu'aucune table n'est crashee |
|
| 45 | + if (!_request('reinstall')) { |
|
| 46 | + verifier_crash_tables(); |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - return 1; |
|
| 49 | + return 1; |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | |
@@ -63,33 +63,33 @@ discard block |
||
| 63 | 63 | * des tables qui ont crashé. |
| 64 | 64 | */ |
| 65 | 65 | function verifier_crash_tables() { |
| 66 | - if (spip_connect()) { |
|
| 67 | - include_spip('base/serial'); |
|
| 68 | - include_spip('base/auxiliaires'); |
|
| 69 | - $crash = []; |
|
| 70 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | - if ( |
|
| 73 | - !sql_select('*', $table, '', '', '', 1) |
|
| 74 | - and !defined('spip_interdire_cache') |
|
| 75 | - ) { # cas "LOST CONNECTION" |
|
| 76 | - $crash[] = $table; |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - #$crash[] = 'test'; |
|
| 81 | - if ($crash) { |
|
| 82 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | - spip_log('crash des tables', 'err'); |
|
| 84 | - spip_log($crash, 'err'); |
|
| 85 | - } else { |
|
| 86 | - effacer_meta('message_crash_tables'); |
|
| 87 | - } |
|
| 66 | + if (spip_connect()) { |
|
| 67 | + include_spip('base/serial'); |
|
| 68 | + include_spip('base/auxiliaires'); |
|
| 69 | + $crash = []; |
|
| 70 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 71 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 72 | + if ( |
|
| 73 | + !sql_select('*', $table, '', '', '', 1) |
|
| 74 | + and !defined('spip_interdire_cache') |
|
| 75 | + ) { # cas "LOST CONNECTION" |
|
| 76 | + $crash[] = $table; |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + #$crash[] = 'test'; |
|
| 81 | + if ($crash) { |
|
| 82 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 83 | + spip_log('crash des tables', 'err'); |
|
| 84 | + spip_log($crash, 'err'); |
|
| 85 | + } else { |
|
| 86 | + effacer_meta('message_crash_tables'); |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - return $crash; |
|
| 90 | - } |
|
| 89 | + return $crash; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - return false; |
|
| 92 | + return false; |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -105,16 +105,16 @@ discard block |
||
| 105 | 105 | * @return string |
| 106 | 106 | */ |
| 107 | 107 | function message_crash_tables() { |
| 108 | - if ($crash = verifier_crash_tables()) { |
|
| 109 | - return |
|
| 110 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 112 | - . generer_form_ecrire( |
|
| 113 | - 'base_repair', |
|
| 114 | - _T('texte_crash_base'), |
|
| 115 | - '', |
|
| 116 | - _T('bouton_tenter_recuperation') |
|
| 117 | - ); |
|
| 118 | - } |
|
| 119 | - return ''; |
|
| 108 | + if ($crash = verifier_crash_tables()) { |
|
| 109 | + return |
|
| 110 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 111 | + . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 112 | + . generer_form_ecrire( |
|
| 113 | + 'base_repair', |
|
| 114 | + _T('texte_crash_base'), |
|
| 115 | + '', |
|
| 116 | + _T('bouton_tenter_recuperation') |
|
| 117 | + ); |
|
| 118 | + } |
|
| 119 | + return ''; |
|
| 120 | 120 | } |