@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Appels incomplets (sans $c) |
| 115 | 115 | if (!is_array($c)) { |
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 117 | 117 | |
| 118 | 118 | return _T('erreur_technique_enregistrement_impossible'); |
| 119 | 119 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | // N'accepter que les champs qui existent dans la table |
| 141 | 141 | $champs = array_intersect_key($c, $desc['field']); |
| 142 | 142 | // et dont la valeur n'est pas null |
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 143 | + $champs = array_filter($champs, static function($var) { |
|
| 144 | 144 | return $var !== null; |
| 145 | 145 | }); |
| 146 | 146 | // TODO: ici aussi on peut valider les contenus |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $champs = array_map('corriger_caracteres', $champs); |
| 151 | 151 | |
| 152 | 152 | // On récupère l'état avant toute modification |
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet); |
|
| 154 | 154 | |
| 155 | 155 | // Envoyer aux plugins |
| 156 | 156 | $champs = pipeline( |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $id_rubrique = 0; |
| 206 | 206 | if (isset($desc['field']['id_rubrique'])) { |
| 207 | 207 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet)); |
|
| 209 | 209 | } |
| 210 | 210 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 211 | 211 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // allez on commit la modif |
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), [], $serveur); |
|
| 231 | 231 | |
| 232 | 232 | // on verifie si elle est bien passee |
| 233 | 233 | $moof = sql_fetsel( |
| 234 | 234 | array_keys($champs), |
| 235 | 235 | $spip_table_objet, |
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 236 | + "$id_table_objet=".intval($id_objet), |
|
| 237 | 237 | [], |
| 238 | 238 | [], |
| 239 | 239 | '', |
@@ -269,13 +269,13 @@ discard block |
||
| 269 | 269 | // c'est un cas exceptionnel |
| 270 | 270 | if (count($liste)) { |
| 271 | 271 | spip_log( |
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 273 | + 'modifier.'._LOG_CRITIQUE |
|
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | 276 | return _T( |
| 277 | 277 | 'erreur_technique_enregistrement_champs', |
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 278 | + ['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"] |
|
| 279 | 279 | ); |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -317,18 +317,18 @@ discard block |
||
| 317 | 317 | include_spip('inc/filtres_mini'); |
| 318 | 318 | $qui = ''; |
| 319 | 319 | if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
| 320 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 320 | + $qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#'; |
|
| 321 | 321 | } |
| 322 | 322 | if (!empty($GLOBALS['visiteur_session']['nom'])) { |
| 323 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 323 | + $qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#'; |
|
| 324 | 324 | } |
| 325 | 325 | if ($qui == '') { |
| 326 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 326 | + $qui = '#ip:'.$GLOBALS['ip'].'#'; |
|
| 327 | 327 | } |
| 328 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 328 | + journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.join( |
|
| 329 | 329 | '+', |
| 330 | 330 | array_diff(array_keys($champs), ['date_modif']) |
| 331 | - ) . ')'), [ |
|
| 331 | + ).')'), [ |
|
| 332 | 332 | 'faire' => 'modifier', |
| 333 | 333 | 'quoi' => $objet, |
| 334 | 334 | 'id' => $id_objet |
@@ -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 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = []; |
|
| 45 | - foreach ($include_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($exclude_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = []; |
|
| 45 | + foreach ($include_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($exclude_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,262 +97,262 @@ discard block |
||
| 97 | 97 | * - chaîne : texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // N'accepter que les champs qui existent dans la table |
|
| 141 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | - // et dont la valeur n'est pas null |
|
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 144 | - return $var !== null; |
|
| 145 | - }); |
|
| 146 | - // TODO: ici aussi on peut valider les contenus |
|
| 147 | - // en fonction du type |
|
| 148 | - |
|
| 149 | - // Nettoyer les valeurs |
|
| 150 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | - |
|
| 152 | - // On récupère l'état avant toute modification |
|
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | - |
|
| 155 | - // Envoyer aux plugins |
|
| 156 | - $champs = pipeline( |
|
| 157 | - 'pre_edition', |
|
| 158 | - [ |
|
| 159 | - 'args' => [ |
|
| 160 | - 'table' => $spip_table_objet, // compatibilite |
|
| 161 | - 'table_objet' => $table_objet, |
|
| 162 | - 'spip_table_objet' => $spip_table_objet, |
|
| 163 | - 'desc' => $desc, |
|
| 164 | - 'type' => $objet, |
|
| 165 | - 'id_objet' => $id_objet, |
|
| 166 | - 'data' => $options['data'] ?? null, |
|
| 167 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | - 'serveur' => $serveur, |
|
| 170 | - 'action' => $options['action'] ?? 'modifier' |
|
| 171 | - ], |
|
| 172 | - 'data' => $champs |
|
| 173 | - ] |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - if (!$champs) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | - include_spip('inc/config'); |
|
| 183 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | - include_spip('inc/drapeau_edition'); |
|
| 185 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | - include_spip('inc/editer'); |
|
| 190 | - if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | - $options['data'] = &$_POST; |
|
| 192 | - } |
|
| 193 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | - // et gere l'interface |
|
| 196 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | - if ($conflits) { |
|
| 198 | - return _T('titre_conflit_edition'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($champs) { |
|
| 202 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | - if (isset($champs['lang'])) { |
|
| 204 | - if ($changer_lang = $champs['lang']) { |
|
| 205 | - $id_rubrique = 0; |
|
| 206 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | - } |
|
| 210 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | - } |
|
| 213 | - // on laisse 'lang' dans $champs, |
|
| 214 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | - // deja pris en compte |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // la modif peut avoir lieu |
|
| 220 | - |
|
| 221 | - // faut-il ajouter date_modif ? |
|
| 222 | - if ( |
|
| 223 | - !empty($options['date_modif']) |
|
| 224 | - and !isset($champs[$options['date_modif']]) |
|
| 225 | - ) { |
|
| 226 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // allez on commit la modif |
|
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | - |
|
| 232 | - // on verifie si elle est bien passee |
|
| 233 | - $moof = sql_fetsel( |
|
| 234 | - array_keys($champs), |
|
| 235 | - $spip_table_objet, |
|
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 237 | - [], |
|
| 238 | - [], |
|
| 239 | - '', |
|
| 240 | - [], |
|
| 241 | - $serveur |
|
| 242 | - ); |
|
| 243 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | - if ($moof != $champs) { |
|
| 245 | - $liste = []; |
|
| 246 | - foreach ($moof as $k => $v) { |
|
| 247 | - if ( |
|
| 248 | - $v !== $champs[$k] |
|
| 249 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | - ) { |
|
| 254 | - $liste[] = $k; |
|
| 255 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | - $conflits[$k]['save'] = $v; |
|
| 257 | - |
|
| 258 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | - include_spip('inc/charsets'); |
|
| 262 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | - array_pop($liste); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | - // c'est un cas exceptionnel |
|
| 270 | - if (count($liste)) { |
|
| 271 | - spip_log( |
|
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return _T( |
|
| 277 | - 'erreur_technique_enregistrement_champs', |
|
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Invalider les caches |
|
| 284 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | - include_spip('inc/invalideur'); |
|
| 286 | - if (is_array($options['invalideur'])) { |
|
| 287 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | - } else { |
|
| 289 | - suivre_invalideur($options['invalideur']); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Notifications, gestion des revisions... |
|
| 294 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | - pipeline( |
|
| 296 | - 'post_edition', |
|
| 297 | - [ |
|
| 298 | - 'args' => [ |
|
| 299 | - 'table' => $spip_table_objet, |
|
| 300 | - 'table_objet' => $table_objet, |
|
| 301 | - 'spip_table_objet' => $spip_table_objet, |
|
| 302 | - 'desc' => $desc, |
|
| 303 | - 'type' => $objet, |
|
| 304 | - 'id_objet' => $id_objet, |
|
| 305 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | - 'serveur' => $serveur, |
|
| 308 | - 'action' => $options['action'] ?? 'modifier' |
|
| 309 | - ], |
|
| 310 | - 'data' => $champs |
|
| 311 | - ] |
|
| 312 | - ); |
|
| 313 | - } |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // N'accepter que les champs qui existent dans la table |
|
| 141 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | + // et dont la valeur n'est pas null |
|
| 143 | + $champs = array_filter($champs, static function ($var) { |
|
| 144 | + return $var !== null; |
|
| 145 | + }); |
|
| 146 | + // TODO: ici aussi on peut valider les contenus |
|
| 147 | + // en fonction du type |
|
| 148 | + |
|
| 149 | + // Nettoyer les valeurs |
|
| 150 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | + |
|
| 152 | + // On récupère l'état avant toute modification |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | + |
|
| 155 | + // Envoyer aux plugins |
|
| 156 | + $champs = pipeline( |
|
| 157 | + 'pre_edition', |
|
| 158 | + [ |
|
| 159 | + 'args' => [ |
|
| 160 | + 'table' => $spip_table_objet, // compatibilite |
|
| 161 | + 'table_objet' => $table_objet, |
|
| 162 | + 'spip_table_objet' => $spip_table_objet, |
|
| 163 | + 'desc' => $desc, |
|
| 164 | + 'type' => $objet, |
|
| 165 | + 'id_objet' => $id_objet, |
|
| 166 | + 'data' => $options['data'] ?? null, |
|
| 167 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | + 'serveur' => $serveur, |
|
| 170 | + 'action' => $options['action'] ?? 'modifier' |
|
| 171 | + ], |
|
| 172 | + 'data' => $champs |
|
| 173 | + ] |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + if (!$champs) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | + include_spip('inc/config'); |
|
| 183 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | + include_spip('inc/drapeau_edition'); |
|
| 185 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | + include_spip('inc/editer'); |
|
| 190 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | + $options['data'] = &$_POST; |
|
| 192 | + } |
|
| 193 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | + // et gere l'interface |
|
| 196 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | + if ($conflits) { |
|
| 198 | + return _T('titre_conflit_edition'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($champs) { |
|
| 202 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | + if (isset($champs['lang'])) { |
|
| 204 | + if ($changer_lang = $champs['lang']) { |
|
| 205 | + $id_rubrique = 0; |
|
| 206 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | + } |
|
| 210 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | + } |
|
| 213 | + // on laisse 'lang' dans $champs, |
|
| 214 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | + // deja pris en compte |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // la modif peut avoir lieu |
|
| 220 | + |
|
| 221 | + // faut-il ajouter date_modif ? |
|
| 222 | + if ( |
|
| 223 | + !empty($options['date_modif']) |
|
| 224 | + and !isset($champs[$options['date_modif']]) |
|
| 225 | + ) { |
|
| 226 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // allez on commit la modif |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | + |
|
| 232 | + // on verifie si elle est bien passee |
|
| 233 | + $moof = sql_fetsel( |
|
| 234 | + array_keys($champs), |
|
| 235 | + $spip_table_objet, |
|
| 236 | + "$id_table_objet=" . intval($id_objet), |
|
| 237 | + [], |
|
| 238 | + [], |
|
| 239 | + '', |
|
| 240 | + [], |
|
| 241 | + $serveur |
|
| 242 | + ); |
|
| 243 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | + if ($moof != $champs) { |
|
| 245 | + $liste = []; |
|
| 246 | + foreach ($moof as $k => $v) { |
|
| 247 | + if ( |
|
| 248 | + $v !== $champs[$k] |
|
| 249 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | + ) { |
|
| 254 | + $liste[] = $k; |
|
| 255 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | + $conflits[$k]['save'] = $v; |
|
| 257 | + |
|
| 258 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | + include_spip('inc/charsets'); |
|
| 262 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | + array_pop($liste); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | + // c'est un cas exceptionnel |
|
| 270 | + if (count($liste)) { |
|
| 271 | + spip_log( |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | + 'modifier.' . _LOG_CRITIQUE |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return _T( |
|
| 277 | + 'erreur_technique_enregistrement_champs', |
|
| 278 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Invalider les caches |
|
| 284 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | + include_spip('inc/invalideur'); |
|
| 286 | + if (is_array($options['invalideur'])) { |
|
| 287 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | + } else { |
|
| 289 | + suivre_invalideur($options['invalideur']); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Notifications, gestion des revisions... |
|
| 294 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | + pipeline( |
|
| 296 | + 'post_edition', |
|
| 297 | + [ |
|
| 298 | + 'args' => [ |
|
| 299 | + 'table' => $spip_table_objet, |
|
| 300 | + 'table_objet' => $table_objet, |
|
| 301 | + 'spip_table_objet' => $spip_table_objet, |
|
| 302 | + 'desc' => $desc, |
|
| 303 | + 'type' => $objet, |
|
| 304 | + 'id_objet' => $id_objet, |
|
| 305 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | + 'serveur' => $serveur, |
|
| 308 | + 'action' => $options['action'] ?? 'modifier' |
|
| 309 | + ], |
|
| 310 | + 'data' => $champs |
|
| 311 | + ] |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Appeler une notification |
|
| 316 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 317 | - $notifications( |
|
| 318 | - "{$objet}_modifier", |
|
| 319 | - $id_objet, |
|
| 320 | - [ |
|
| 321 | - 'champs' => $champs, |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - $notifications( |
|
| 325 | - 'objet_modifier', |
|
| 326 | - $id_objet, |
|
| 327 | - [ |
|
| 328 | - 'objet' => $objet, |
|
| 329 | - 'id_objet' => $id_objet, |
|
| 330 | - 'champs' => $champs, |
|
| 331 | - ] |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // journaliser l'affaire |
|
| 336 | - // message a affiner :-) |
|
| 337 | - include_spip('inc/filtres_mini'); |
|
| 338 | - $qui = ''; |
|
| 339 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 340 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 341 | - } |
|
| 342 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 343 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 344 | - } |
|
| 345 | - if ($qui == '') { |
|
| 346 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 347 | - } |
|
| 348 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 349 | - '+', |
|
| 350 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 351 | - ) . ')'), [ |
|
| 352 | - 'faire' => 'modifier', |
|
| 353 | - 'quoi' => $objet, |
|
| 354 | - 'id' => $id_objet |
|
| 355 | - ]); |
|
| 356 | - |
|
| 357 | - return ''; |
|
| 315 | + // Appeler une notification |
|
| 316 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 317 | + $notifications( |
|
| 318 | + "{$objet}_modifier", |
|
| 319 | + $id_objet, |
|
| 320 | + [ |
|
| 321 | + 'champs' => $champs, |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + $notifications( |
|
| 325 | + 'objet_modifier', |
|
| 326 | + $id_objet, |
|
| 327 | + [ |
|
| 328 | + 'objet' => $objet, |
|
| 329 | + 'id_objet' => $id_objet, |
|
| 330 | + 'champs' => $champs, |
|
| 331 | + ] |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // journaliser l'affaire |
|
| 336 | + // message a affiner :-) |
|
| 337 | + include_spip('inc/filtres_mini'); |
|
| 338 | + $qui = ''; |
|
| 339 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 340 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 341 | + } |
|
| 342 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 343 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 344 | + } |
|
| 345 | + if ($qui == '') { |
|
| 346 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 347 | + } |
|
| 348 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 349 | + '+', |
|
| 350 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 351 | + ) . ')'), [ |
|
| 352 | + 'faire' => 'modifier', |
|
| 353 | + 'quoi' => $objet, |
|
| 354 | + 'id' => $id_objet |
|
| 355 | + ]); |
|
| 356 | + |
|
| 357 | + return ''; |
|
| 358 | 358 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $row = sql_fetsel( |
| 50 | 50 | '*', |
| 51 | 51 | 'spip_auteurs', |
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | + 'login='.sql_quote($login, $serveur, 'text')." AND statut<>'5poubelle'", |
|
| 53 | 53 | '', |
| 54 | 54 | '', |
| 55 | 55 | '', |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | // legacy = md5 ou sha256 |
| 78 | 78 | case 32: |
| 79 | 79 | // tres anciens mots de passe encodes en md5(alea.pass) |
| 80 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $hash = md5($row['alea_actuel'].$pass); |
|
| 81 | 81 | $methode = 'md5'; |
| 82 | 82 | case 64: |
| 83 | 83 | if (empty($hash)) { |
| 84 | 84 | // anciens mots de passe encodes en sha256(alea.pass) |
| 85 | 85 | include_spip('auth/sha256.inc'); |
| 86 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | + $hash = spip_sha256($row['alea_actuel'].$pass); |
|
| 87 | 87 | $methode = 'sha256'; |
| 88 | 88 | } |
| 89 | 89 | if ($row['pass'] === $hash) { |
| 90 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode", 'auth'._LOG_DEBUG); |
|
| 91 | 91 | // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
| 92 | 92 | if (!empty($row['backup_cles'])) { |
| 93 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur'])); |
|
| 94 | 94 | } |
| 95 | 95 | break; |
| 96 | 96 | } |
@@ -108,19 +108,19 @@ discard block |
||
| 108 | 108 | and !empty($row['backup_cles']) |
| 109 | 109 | ) { |
| 110 | 110 | if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
| 111 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur'], 'auth'._LOG_INFO_IMPORTANTE); |
|
| 112 | 112 | if ($cles->save()) { |
| 113 | 113 | $secret = $cles->getSecretAuth(); |
| 114 | 114 | } |
| 115 | 115 | else { |
| 116 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 117 | 117 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 118 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | else { |
| 122 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 123 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 122 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide", 'auth'._LOG_ERREUR); |
|
| 123 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur'])); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | unset($row); |
| 129 | 129 | } |
| 130 | 130 | else { |
| 131 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier", 'auth'._LOG_DEBUG); |
|
| 132 | 132 | } |
| 133 | 133 | break; |
| 134 | 134 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | @sql_update( |
| 176 | 176 | 'spip_auteurs', |
| 177 | 177 | $set, |
| 178 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | + 'id_auteur='.intval($row['id_auteur']).' AND pass='.sql_quote( |
|
| 179 | 179 | $row['pass'], |
| 180 | 180 | $serveur, |
| 181 | 181 | 'text' |
@@ -223,24 +223,24 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | // si force, on ne verifie pas la presence d'un backup chez un webmestre |
| 225 | 225 | if ($force) { |
| 226 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 226 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth'._LOG_INFO_IMPORTANTE); |
|
| 227 | 227 | $secret = $cles->getSecretAuth(true); |
| 228 | 228 | return true; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 231 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''"); |
|
| 232 | 232 | $has_backup = array_column($has_backup, 'id_auteur'); |
| 233 | 233 | if (empty($has_backup)) { |
| 234 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 234 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth'._LOG_INFO_IMPORTANTE); |
|
| 235 | 235 | if ($secret = $cles->getSecretAuth(true)) { |
| 236 | 236 | return true; |
| 237 | 237 | } |
| 238 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 238 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 239 | 239 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 240 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 240 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 241 | 241 | } |
| 242 | 242 | else { |
| 243 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 243 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #'.implode(', #', $has_backup).' doit se connecter pour restaurer son backup des cles', 'auth'._LOG_ERREUR); |
|
| 244 | 244 | } |
| 245 | 245 | return false; |
| 246 | 246 | } |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | $flux['data'] .= |
| 258 | 258 | '<script type="text/javascript">/*<![CDATA[*/' |
| 259 | 259 | . "$js\n" |
| 260 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 261 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | + . "var login_info={'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 261 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 262 | 262 | . "'informe_auteur_en_cours':false," |
| 263 | 263 | . "'attente_informe':0};" |
| 264 | 264 | . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | } else { |
| 302 | 302 | $n = sql_countsel( |
| 303 | 303 | 'spip_auteurs', |
| 304 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 304 | + 'login='.sql_quote($new_login).' AND id_auteur!='.intval($id_auteur)." AND statut!='5poubelle'", |
|
| 305 | 305 | '', |
| 306 | 306 | '', |
| 307 | 307 | $serveur |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | if ( |
| 331 | 331 | !$id_auteur = intval($id_auteur) |
| 332 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 332 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 333 | 333 | ) { |
| 334 | 334 | return false; |
| 335 | 335 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | $anciens = sql_allfetsel( |
| 345 | 345 | 'id_auteur', |
| 346 | 346 | 'spip_auteurs', |
| 347 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 347 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", |
|
| 348 | 348 | '', |
| 349 | 349 | '', |
| 350 | 350 | '', |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | $r = sql_getfetsel( |
| 379 | 379 | 'login', |
| 380 | 380 | 'spip_auteurs', |
| 381 | - "statut<>'5poubelle'" . |
|
| 382 | - ' AND (length(pass)>0)' . |
|
| 381 | + "statut<>'5poubelle'". |
|
| 382 | + ' AND (length(pass)>0)'. |
|
| 383 | 383 | " AND (login=$l)", |
| 384 | 384 | '', |
| 385 | 385 | '', |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | return sql_getfetsel( |
| 399 | 399 | 'login', |
| 400 | 400 | 'spip_auteurs', |
| 401 | - "statut<>'5poubelle'" . |
|
| 402 | - ' AND (length(pass)>0)' . |
|
| 401 | + "statut<>'5poubelle'". |
|
| 402 | + ' AND (length(pass)>0)'. |
|
| 403 | 403 | " AND (login<>'' AND (nom=$l OR email=$l))", |
| 404 | 404 | '', |
| 405 | 405 | '', |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | |
| 469 | 469 | if ( |
| 470 | 470 | !$id_auteur = intval($id_auteur) |
| 471 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 471 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 472 | 472 | ) { |
| 473 | 473 | return false; |
| 474 | 474 | } |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | or isset($champs['statut']) |
| 530 | 530 | or (isset($options['all']) and $options['all']) |
| 531 | 531 | ) { |
| 532 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 533 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 532 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 533 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 534 | 534 | |
| 535 | 535 | // Cette variable de configuration peut etre posee par un plugin |
| 536 | 536 | // par exemple acces_restreint ; |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | and !@file_exists($htaccess) |
| 541 | 541 | ) { |
| 542 | 542 | spip_unlink($htpasswd); |
| 543 | - spip_unlink($htpasswd . '-admin'); |
|
| 543 | + spip_unlink($htpasswd.'-admin'); |
|
| 544 | 544 | |
| 545 | 545 | return; |
| 546 | 546 | } |
@@ -558,16 +558,16 @@ discard block |
||
| 558 | 558 | ); |
| 559 | 559 | while ($t = sql_fetch($s)) { |
| 560 | 560 | if (strlen($t['login']) and strlen($t['htpass'])) { |
| 561 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 562 | 562 | if ($t['statut'] == '0minirezo') { |
| 563 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 563 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | sql_free($s); |
| 568 | 568 | if ($p1) { |
| 569 | 569 | ecrire_fichier($htpasswd, $p1); |
| 570 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 570 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 571 | 571 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 572 | 572 | } |
| 573 | 573 | } |
@@ -111,14 +111,12 @@ discard block |
||
| 111 | 111 | spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
| 112 | 112 | if ($cles->save()) { |
| 113 | 113 | $secret = $cles->getSecretAuth(); |
| 114 | - } |
|
| 115 | - else { |
|
| 114 | + } else { |
|
| 116 | 115 | spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 117 | 116 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 118 | 117 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 119 | 118 | } |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
| 123 | 121 | sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
| 124 | 122 | } |
@@ -126,8 +124,7 @@ discard block |
||
| 126 | 124 | |
| 127 | 125 | if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
| 128 | 126 | unset($row); |
| 129 | - } |
|
| 130 | - else { |
|
| 127 | + } else { |
|
| 131 | 128 | spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
| 132 | 129 | } |
| 133 | 130 | break; |
@@ -238,8 +235,7 @@ discard block |
||
| 238 | 235 | spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 239 | 236 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 240 | 237 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 241 | - } |
|
| 242 | - else { |
|
| 238 | + } else { |
|
| 243 | 239 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
| 244 | 240 | } |
| 245 | 241 | return false; |
@@ -479,8 +475,7 @@ discard block |
||
| 479 | 475 | if (!$secret) { |
| 480 | 476 | if (auth_spip_initialiser_secret()) { |
| 481 | 477 | $secret = $cles->getSecretAuth(); |
| 482 | - } |
|
| 483 | - else { |
|
| 478 | + } else { |
|
| 484 | 479 | return false; |
| 485 | 480 | } |
| 486 | 481 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | use Spip\Chiffrer\SpipCles; |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -34,169 +34,169 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 36 | 36 | |
| 37 | - // retrouver le login |
|
| 38 | - $login = auth_spip_retrouver_login($login); |
|
| 39 | - // login inconnu, n'allons pas plus loin |
|
| 40 | - if (!$login) { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $md5pass = ''; |
|
| 45 | - $shapass = $shanext = ''; |
|
| 46 | - $auteur_peut_sauver_cles = false; |
|
| 47 | - |
|
| 48 | - if ($pass) { |
|
| 49 | - $row = sql_fetsel( |
|
| 50 | - '*', |
|
| 51 | - 'spip_auteurs', |
|
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | - '', |
|
| 54 | - '', |
|
| 55 | - '', |
|
| 56 | - '', |
|
| 57 | - $serveur |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - // lever un flag si cet auteur peut sauver les cles |
|
| 61 | - if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | - $auteur_peut_sauver_cles = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // login inexistant ou mot de passe vide |
|
| 67 | - if (!$pass or !$row) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $cles = SpipCles::instance(); |
|
| 72 | - $secret = $cles->getSecretAuth(); |
|
| 73 | - |
|
| 74 | - $hash = null; |
|
| 75 | - switch (strlen($row['pass'])) { |
|
| 76 | - // legacy = md5 ou sha256 |
|
| 77 | - case 32: |
|
| 78 | - // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | - $methode = 'md5'; |
|
| 81 | - case 64: |
|
| 82 | - if (empty($hash)) { |
|
| 83 | - // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | - include_spip('auth/sha256.inc'); |
|
| 85 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | - $methode = 'sha256'; |
|
| 87 | - } |
|
| 88 | - if ($row['pass'] === $hash) { |
|
| 89 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | - // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 91 | - if (!empty($row['backup_cles'])) { |
|
| 92 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | - } |
|
| 94 | - break; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 98 | - |
|
| 99 | - case 60: |
|
| 100 | - case 98: |
|
| 101 | - default: |
|
| 102 | - // doit-on restaurer un backup des cles ? |
|
| 103 | - // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 104 | - if ( |
|
| 105 | - !$secret |
|
| 106 | - and $auteur_peut_sauver_cles |
|
| 107 | - and !empty($row['backup_cles']) |
|
| 108 | - ) { |
|
| 109 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 110 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | - if ($cles->save()) { |
|
| 112 | - $secret = $cles->getSecretAuth(); |
|
| 113 | - } |
|
| 114 | - else { |
|
| 115 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 117 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - else { |
|
| 121 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 127 | - unset($row); |
|
| 128 | - } |
|
| 129 | - else { |
|
| 130 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | - } |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 136 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 137 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 138 | - // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 139 | - if (!$secret and $auteur_peut_sauver_cles) { |
|
| 140 | - if (auth_spip_initialiser_secret()) { |
|
| 141 | - $secret = $cles->getSecretAuth(); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // login/mot de passe incorrect |
|
| 146 | - if (empty($row)) { |
|
| 147 | - return []; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // fait tourner le codage du pass dans la base |
|
| 151 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 152 | - if (!$phpauth and $secret) { |
|
| 153 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 154 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 155 | - if ($pass_hash_next) { |
|
| 156 | - $set = [ |
|
| 157 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 158 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 159 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 160 | - ]; |
|
| 161 | - |
|
| 162 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 163 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 164 | - $htpass = generer_htpass($pass); |
|
| 165 | - if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 166 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 170 | - if ($auteur_peut_sauver_cles) { |
|
| 171 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - @sql_update( |
|
| 175 | - 'spip_auteurs', |
|
| 176 | - $set, |
|
| 177 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | - $row['pass'], |
|
| 179 | - $serveur, |
|
| 180 | - 'text' |
|
| 181 | - ), |
|
| 182 | - [], |
|
| 183 | - $serveur |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 187 | - if (isset($set['htpass'])) { |
|
| 188 | - ecrire_acces(); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // En profiter pour verifier la securite de tmp/ |
|
| 193 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 194 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $row; |
|
| 37 | + // retrouver le login |
|
| 38 | + $login = auth_spip_retrouver_login($login); |
|
| 39 | + // login inconnu, n'allons pas plus loin |
|
| 40 | + if (!$login) { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $md5pass = ''; |
|
| 45 | + $shapass = $shanext = ''; |
|
| 46 | + $auteur_peut_sauver_cles = false; |
|
| 47 | + |
|
| 48 | + if ($pass) { |
|
| 49 | + $row = sql_fetsel( |
|
| 50 | + '*', |
|
| 51 | + 'spip_auteurs', |
|
| 52 | + 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | + '', |
|
| 54 | + '', |
|
| 55 | + '', |
|
| 56 | + '', |
|
| 57 | + $serveur |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + // lever un flag si cet auteur peut sauver les cles |
|
| 61 | + if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | + $auteur_peut_sauver_cles = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // login inexistant ou mot de passe vide |
|
| 67 | + if (!$pass or !$row) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $cles = SpipCles::instance(); |
|
| 72 | + $secret = $cles->getSecretAuth(); |
|
| 73 | + |
|
| 74 | + $hash = null; |
|
| 75 | + switch (strlen($row['pass'])) { |
|
| 76 | + // legacy = md5 ou sha256 |
|
| 77 | + case 32: |
|
| 78 | + // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | + $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $methode = 'md5'; |
|
| 81 | + case 64: |
|
| 82 | + if (empty($hash)) { |
|
| 83 | + // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | + include_spip('auth/sha256.inc'); |
|
| 85 | + $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | + $methode = 'sha256'; |
|
| 87 | + } |
|
| 88 | + if ($row['pass'] === $hash) { |
|
| 89 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | + // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 91 | + if (!empty($row['backup_cles'])) { |
|
| 92 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | + } |
|
| 94 | + break; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 98 | + |
|
| 99 | + case 60: |
|
| 100 | + case 98: |
|
| 101 | + default: |
|
| 102 | + // doit-on restaurer un backup des cles ? |
|
| 103 | + // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 104 | + if ( |
|
| 105 | + !$secret |
|
| 106 | + and $auteur_peut_sauver_cles |
|
| 107 | + and !empty($row['backup_cles']) |
|
| 108 | + ) { |
|
| 109 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 110 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | + if ($cles->save()) { |
|
| 112 | + $secret = $cles->getSecretAuth(); |
|
| 113 | + } |
|
| 114 | + else { |
|
| 115 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 117 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + else { |
|
| 121 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 127 | + unset($row); |
|
| 128 | + } |
|
| 129 | + else { |
|
| 130 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | + } |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 136 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 137 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 138 | + // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 139 | + if (!$secret and $auteur_peut_sauver_cles) { |
|
| 140 | + if (auth_spip_initialiser_secret()) { |
|
| 141 | + $secret = $cles->getSecretAuth(); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // login/mot de passe incorrect |
|
| 146 | + if (empty($row)) { |
|
| 147 | + return []; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // fait tourner le codage du pass dans la base |
|
| 151 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 152 | + if (!$phpauth and $secret) { |
|
| 153 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 154 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 155 | + if ($pass_hash_next) { |
|
| 156 | + $set = [ |
|
| 157 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 158 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 159 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 160 | + ]; |
|
| 161 | + |
|
| 162 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 163 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 164 | + $htpass = generer_htpass($pass); |
|
| 165 | + if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 166 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 170 | + if ($auteur_peut_sauver_cles) { |
|
| 171 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + @sql_update( |
|
| 175 | + 'spip_auteurs', |
|
| 176 | + $set, |
|
| 177 | + 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | + $row['pass'], |
|
| 179 | + $serveur, |
|
| 180 | + 'text' |
|
| 181 | + ), |
|
| 182 | + [], |
|
| 183 | + $serveur |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 187 | + if (isset($set['htpass'])) { |
|
| 188 | + ecrire_acces(); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // En profiter pour verifier la securite de tmp/ |
|
| 193 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 194 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $row; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -211,36 +211,36 @@ discard block |
||
| 211 | 211 | * @return bool |
| 212 | 212 | */ |
| 213 | 213 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 214 | - $cles = SpipCles::instance(); |
|
| 215 | - $secret = $cles->getSecretAuth(); |
|
| 216 | - |
|
| 217 | - // on ne fait rien si on a un secret dispo |
|
| 218 | - if ($secret) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 223 | - if ($force) { |
|
| 224 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 225 | - $secret = $cles->getSecretAuth(true); |
|
| 226 | - return true; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 230 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 231 | - if (empty($has_backup)) { |
|
| 232 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 233 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 234 | - return true; |
|
| 235 | - } |
|
| 236 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 237 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 238 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 239 | - } |
|
| 240 | - else { |
|
| 241 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 242 | - } |
|
| 243 | - return false; |
|
| 214 | + $cles = SpipCles::instance(); |
|
| 215 | + $secret = $cles->getSecretAuth(); |
|
| 216 | + |
|
| 217 | + // on ne fait rien si on a un secret dispo |
|
| 218 | + if ($secret) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 223 | + if ($force) { |
|
| 224 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 225 | + $secret = $cles->getSecretAuth(true); |
|
| 226 | + return true; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 230 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 231 | + if (empty($has_backup)) { |
|
| 232 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 233 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 234 | + return true; |
|
| 235 | + } |
|
| 236 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 237 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 238 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 239 | + } |
|
| 240 | + else { |
|
| 241 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 242 | + } |
|
| 243 | + return false; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -250,19 +250,19 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function auth_spip_formulaire_login($flux) { |
| 253 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 254 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 255 | - $flux['data'] .= |
|
| 256 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 257 | - . "$js\n" |
|
| 258 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 259 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | - . "'informe_auteur_en_cours':false," |
|
| 261 | - . "'attente_informe':0};" |
|
| 262 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 263 | - . '/*]]>*/</script>'; |
|
| 264 | - |
|
| 265 | - return $flux; |
|
| 253 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 254 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 255 | + $flux['data'] .= |
|
| 256 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 257 | + . "$js\n" |
|
| 258 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 259 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | + . "'informe_auteur_en_cours':false," |
|
| 261 | + . "'attente_informe':0};" |
|
| 262 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 263 | + . '/*]]>*/</script>'; |
|
| 264 | + |
|
| 265 | + return $flux; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -274,11 +274,11 @@ discard block |
||
| 274 | 274 | * toujours true pour un auteur cree dans SPIP |
| 275 | 275 | */ |
| 276 | 276 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 277 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 278 | - if (strlen($serveur)) { |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - return true; |
|
| 277 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 278 | + if (strlen($serveur)) { |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + return true; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -292,25 +292,25 @@ discard block |
||
| 292 | 292 | * message d'erreur si login non valide, chaine vide sinon |
| 293 | 293 | */ |
| 294 | 294 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 295 | - // login et mot de passe |
|
| 296 | - if (strlen($new_login)) { |
|
| 297 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 298 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 299 | - } else { |
|
| 300 | - $n = sql_countsel( |
|
| 301 | - 'spip_auteurs', |
|
| 302 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 303 | - '', |
|
| 304 | - '', |
|
| 305 | - $serveur |
|
| 306 | - ); |
|
| 307 | - if ($n) { |
|
| 308 | - return _T('info_login_existant'); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return ''; |
|
| 295 | + // login et mot de passe |
|
| 296 | + if (strlen($new_login)) { |
|
| 297 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 298 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 299 | + } else { |
|
| 300 | + $n = sql_countsel( |
|
| 301 | + 'spip_auteurs', |
|
| 302 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 303 | + '', |
|
| 304 | + '', |
|
| 305 | + $serveur |
|
| 306 | + ); |
|
| 307 | + if ($n) { |
|
| 308 | + return _T('info_login_existant'); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return ''; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -322,41 +322,41 @@ discard block |
||
| 322 | 322 | * @return bool |
| 323 | 323 | */ |
| 324 | 324 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 325 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - if ( |
|
| 329 | - !$id_auteur = intval($id_auteur) |
|
| 330 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 331 | - ) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if ($new_login == $auteur['login']) { |
|
| 335 | - return true; |
|
| 336 | - } // on a rien fait mais c'est bon ! |
|
| 337 | - |
|
| 338 | - include_spip('action/editer_auteur'); |
|
| 339 | - |
|
| 340 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 341 | - if (strlen($new_login)) { |
|
| 342 | - $anciens = sql_allfetsel( |
|
| 343 | - 'id_auteur', |
|
| 344 | - 'spip_auteurs', |
|
| 345 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 346 | - '', |
|
| 347 | - '', |
|
| 348 | - '', |
|
| 349 | - '', |
|
| 350 | - $serveur |
|
| 351 | - ); |
|
| 352 | - while ($row = array_pop($anciens)) { |
|
| 353 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 358 | - |
|
| 359 | - return true; |
|
| 325 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + if ( |
|
| 329 | + !$id_auteur = intval($id_auteur) |
|
| 330 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 331 | + ) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if ($new_login == $auteur['login']) { |
|
| 335 | + return true; |
|
| 336 | + } // on a rien fait mais c'est bon ! |
|
| 337 | + |
|
| 338 | + include_spip('action/editer_auteur'); |
|
| 339 | + |
|
| 340 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 341 | + if (strlen($new_login)) { |
|
| 342 | + $anciens = sql_allfetsel( |
|
| 343 | + 'id_auteur', |
|
| 344 | + 'spip_auteurs', |
|
| 345 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 346 | + '', |
|
| 347 | + '', |
|
| 348 | + '', |
|
| 349 | + '', |
|
| 350 | + $serveur |
|
| 351 | + ); |
|
| 352 | + while ($row = array_pop($anciens)) { |
|
| 353 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 358 | + |
|
| 359 | + return true; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -368,44 +368,44 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 371 | - if (!strlen($login)) { |
|
| 372 | - return null; |
|
| 373 | - } // pas la peine de requeter |
|
| 374 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 375 | - if ( |
|
| 376 | - $r = sql_getfetsel( |
|
| 377 | - 'login', |
|
| 378 | - 'spip_auteurs', |
|
| 379 | - "statut<>'5poubelle'" . |
|
| 380 | - ' AND (length(pass)>0)' . |
|
| 381 | - " AND (login=$l)", |
|
| 382 | - '', |
|
| 383 | - '', |
|
| 384 | - '', |
|
| 385 | - '', |
|
| 386 | - $serveur |
|
| 387 | - ) |
|
| 388 | - ) { |
|
| 389 | - return $r; |
|
| 390 | - } |
|
| 391 | - // Si pas d'auteur avec ce login |
|
| 392 | - // regarder s'il a saisi son nom ou son mail. |
|
| 393 | - // Ne pas fusionner avec la requete precedente |
|
| 394 | - // car un nom peut etre homonyme d'un autre login |
|
| 395 | - else { |
|
| 396 | - return sql_getfetsel( |
|
| 397 | - 'login', |
|
| 398 | - 'spip_auteurs', |
|
| 399 | - "statut<>'5poubelle'" . |
|
| 400 | - ' AND (length(pass)>0)' . |
|
| 401 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 402 | - '', |
|
| 403 | - '', |
|
| 404 | - '', |
|
| 405 | - '', |
|
| 406 | - $serveur |
|
| 407 | - ); |
|
| 408 | - } |
|
| 371 | + if (!strlen($login)) { |
|
| 372 | + return null; |
|
| 373 | + } // pas la peine de requeter |
|
| 374 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 375 | + if ( |
|
| 376 | + $r = sql_getfetsel( |
|
| 377 | + 'login', |
|
| 378 | + 'spip_auteurs', |
|
| 379 | + "statut<>'5poubelle'" . |
|
| 380 | + ' AND (length(pass)>0)' . |
|
| 381 | + " AND (login=$l)", |
|
| 382 | + '', |
|
| 383 | + '', |
|
| 384 | + '', |
|
| 385 | + '', |
|
| 386 | + $serveur |
|
| 387 | + ) |
|
| 388 | + ) { |
|
| 389 | + return $r; |
|
| 390 | + } |
|
| 391 | + // Si pas d'auteur avec ce login |
|
| 392 | + // regarder s'il a saisi son nom ou son mail. |
|
| 393 | + // Ne pas fusionner avec la requete precedente |
|
| 394 | + // car un nom peut etre homonyme d'un autre login |
|
| 395 | + else { |
|
| 396 | + return sql_getfetsel( |
|
| 397 | + 'login', |
|
| 398 | + 'spip_auteurs', |
|
| 399 | + "statut<>'5poubelle'" . |
|
| 400 | + ' AND (length(pass)>0)' . |
|
| 401 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 402 | + '', |
|
| 403 | + '', |
|
| 404 | + '', |
|
| 405 | + '', |
|
| 406 | + $serveur |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -416,11 +416,11 @@ discard block |
||
| 416 | 416 | * toujours true pour un auteur cree dans SPIP |
| 417 | 417 | */ |
| 418 | 418 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 419 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 420 | - if (strlen($serveur)) { |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - return true; |
|
| 419 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 420 | + if (strlen($serveur)) { |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + return true; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -441,12 +441,12 @@ discard block |
||
| 441 | 441 | * message d'erreur si login non valide, chaine vide sinon |
| 442 | 442 | */ |
| 443 | 443 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 444 | - // login et mot de passe |
|
| 445 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 446 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 447 | - } |
|
| 444 | + // login et mot de passe |
|
| 445 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 446 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - return ''; |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -460,47 +460,47 @@ discard block |
||
| 460 | 460 | * @return bool |
| 461 | 461 | */ |
| 462 | 462 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 463 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 464 | - return false; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - if ( |
|
| 468 | - !$id_auteur = intval($id_auteur) |
|
| 469 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 470 | - ) { |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $cles = SpipCles::instance(); |
|
| 475 | - $secret = $cles->getSecretAuth(); |
|
| 476 | - if (!$secret) { |
|
| 477 | - if (auth_spip_initialiser_secret()) { |
|
| 478 | - $secret = $cles->getSecretAuth(); |
|
| 479 | - } |
|
| 480 | - else { |
|
| 481 | - return false; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - include_spip('inc/acces'); |
|
| 487 | - $set = [ |
|
| 488 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 489 | - 'htpass' => generer_htpass($new_pass), |
|
| 490 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 492 | - 'low_sec' => '', |
|
| 493 | - ]; |
|
| 494 | - |
|
| 495 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 496 | - if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 497 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - include_spip('action/editer_auteur'); |
|
| 501 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 502 | - |
|
| 503 | - return true; // on a bien modifie le pass |
|
| 463 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 464 | + return false; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if ( |
|
| 468 | + !$id_auteur = intval($id_auteur) |
|
| 469 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 470 | + ) { |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $cles = SpipCles::instance(); |
|
| 475 | + $secret = $cles->getSecretAuth(); |
|
| 476 | + if (!$secret) { |
|
| 477 | + if (auth_spip_initialiser_secret()) { |
|
| 478 | + $secret = $cles->getSecretAuth(); |
|
| 479 | + } |
|
| 480 | + else { |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + include_spip('inc/acces'); |
|
| 487 | + $set = [ |
|
| 488 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 489 | + 'htpass' => generer_htpass($new_pass), |
|
| 490 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 492 | + 'low_sec' => '', |
|
| 493 | + ]; |
|
| 494 | + |
|
| 495 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 496 | + if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 497 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + include_spip('action/editer_auteur'); |
|
| 501 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 502 | + |
|
| 503 | + return true; // on a bien modifie le pass |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -514,58 +514,58 @@ discard block |
||
| 514 | 514 | * @return void |
| 515 | 515 | */ |
| 516 | 516 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 517 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 518 | - if (strlen($serveur)) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - // si un login, pass ou statut a ete modifie |
|
| 522 | - // regenerer les fichier htpass |
|
| 523 | - if ( |
|
| 524 | - isset($champs['login']) |
|
| 525 | - or isset($champs['pass']) |
|
| 526 | - or isset($champs['statut']) |
|
| 527 | - or (isset($options['all']) and $options['all']) |
|
| 528 | - ) { |
|
| 529 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 530 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 531 | - |
|
| 532 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 533 | - // par exemple acces_restreint ; |
|
| 534 | - // si .htaccess existe, outrepasser spip_meta |
|
| 535 | - if ( |
|
| 536 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 537 | - and !@file_exists($htaccess) |
|
| 538 | - ) { |
|
| 539 | - spip_unlink($htpasswd); |
|
| 540 | - spip_unlink($htpasswd . '-admin'); |
|
| 541 | - |
|
| 542 | - return; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 546 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 547 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 548 | - |
|
| 549 | - $p1 = ''; // login:htpass pour tous |
|
| 550 | - $p2 = ''; // login:htpass pour les admins |
|
| 551 | - $s = sql_select( |
|
| 552 | - 'login, htpass, statut', |
|
| 553 | - 'spip_auteurs', |
|
| 554 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 555 | - ); |
|
| 556 | - while ($t = sql_fetch($s)) { |
|
| 557 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 558 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 559 | - if ($t['statut'] == '0minirezo') { |
|
| 560 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - sql_free($s); |
|
| 565 | - if ($p1) { |
|
| 566 | - ecrire_fichier($htpasswd, $p1); |
|
| 567 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 568 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 569 | - } |
|
| 570 | - } |
|
| 517 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 518 | + if (strlen($serveur)) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + // si un login, pass ou statut a ete modifie |
|
| 522 | + // regenerer les fichier htpass |
|
| 523 | + if ( |
|
| 524 | + isset($champs['login']) |
|
| 525 | + or isset($champs['pass']) |
|
| 526 | + or isset($champs['statut']) |
|
| 527 | + or (isset($options['all']) and $options['all']) |
|
| 528 | + ) { |
|
| 529 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 530 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 531 | + |
|
| 532 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 533 | + // par exemple acces_restreint ; |
|
| 534 | + // si .htaccess existe, outrepasser spip_meta |
|
| 535 | + if ( |
|
| 536 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 537 | + and !@file_exists($htaccess) |
|
| 538 | + ) { |
|
| 539 | + spip_unlink($htpasswd); |
|
| 540 | + spip_unlink($htpasswd . '-admin'); |
|
| 541 | + |
|
| 542 | + return; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 546 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 547 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 548 | + |
|
| 549 | + $p1 = ''; // login:htpass pour tous |
|
| 550 | + $p2 = ''; // login:htpass pour les admins |
|
| 551 | + $s = sql_select( |
|
| 552 | + 'login, htpass, statut', |
|
| 553 | + 'spip_auteurs', |
|
| 554 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 555 | + ); |
|
| 556 | + while ($t = sql_fetch($s)) { |
|
| 557 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 558 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 559 | + if ($t['statut'] == '0minirezo') { |
|
| 560 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + sql_free($s); |
|
| 565 | + if ($p1) { |
|
| 566 | + ecrire_fichier($htpasswd, $p1); |
|
| 567 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 568 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
@@ -11,77 +11,77 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 18 | 18 | |
| 19 | 19 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 20 | - include_spip('inc/texte'); |
|
| 21 | - $titre = $descriptif = ''; |
|
| 22 | - if ($type === 'rubrique') { |
|
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | - if ($row) { |
|
| 25 | - $titre = typo($row['titre']); |
|
| 26 | - $descriptif = propre($row['descriptif']); |
|
| 27 | - } else { |
|
| 28 | - $titre = _T('info_racine_site'); |
|
| 29 | - } |
|
| 30 | - } |
|
| 20 | + include_spip('inc/texte'); |
|
| 21 | + $titre = $descriptif = ''; |
|
| 22 | + if ($type === 'rubrique') { |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | + if ($row) { |
|
| 25 | + $titre = typo($row['titre']); |
|
| 26 | + $descriptif = propre($row['descriptif']); |
|
| 27 | + } else { |
|
| 28 | + $titre = _T('info_racine_site'); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $res = ''; |
|
| 33 | - if ( |
|
| 34 | - $type === 'rubrique' |
|
| 35 | - and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | - and isset($GLOBALS['meta']['image_process']) |
|
| 37 | - ) { |
|
| 38 | - if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | - [$fid, $dir, $nom, $format] = $res; |
|
| 42 | - include_spip('inc/filtres_images_mini'); |
|
| 43 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | - if ($res) { |
|
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 32 | + $res = ''; |
|
| 33 | + if ( |
|
| 34 | + $type === 'rubrique' |
|
| 35 | + and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | + and isset($GLOBALS['meta']['image_process']) |
|
| 37 | + ) { |
|
| 38 | + if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | + [$fid, $dir, $nom, $format] = $res; |
|
| 42 | + include_spip('inc/filtres_images_mini'); |
|
| 43 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | + if ($res) { |
|
| 45 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | - $id = intval($id); |
|
| 51 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | + $id = intval($id); |
|
| 54 | 54 | |
| 55 | 55 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 56 | 56 | # et l'affichage de son titre dans le bandeau |
| 57 | - $titre = strtr( |
|
| 58 | - str_replace( |
|
| 59 | - "'", |
|
| 60 | - '’', |
|
| 61 | - str_replace('"', '"', textebrut($titre)) |
|
| 62 | - ), |
|
| 63 | - "\n\r", |
|
| 64 | - ' ' |
|
| 65 | - ); |
|
| 57 | + $titre = strtr( |
|
| 58 | + str_replace( |
|
| 59 | + "'", |
|
| 60 | + '’', |
|
| 61 | + str_replace('"', '"', textebrut($titre)) |
|
| 62 | + ), |
|
| 63 | + "\n\r", |
|
| 64 | + ' ' |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do . '_selection_titre'; |
|
| 68 | 68 | |
| 69 | - return "<div style='display: none;'>" |
|
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | - . entites_html($titre) |
|
| 73 | - . '" />' |
|
| 74 | - . '</div>' |
|
| 75 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | - . '<div class="informer__item">' |
|
| 77 | - . (!$res ? '' : $res) |
|
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | - . '</div>' |
|
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | - . _T('bouton_choisir') |
|
| 84 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | - . '</div>' |
|
| 86 | - . '</div>'; |
|
| 69 | + return "<div style='display: none;'>" |
|
| 70 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | + . entites_html($titre) |
|
| 73 | + . '" />' |
|
| 74 | + . '</div>' |
|
| 75 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | + . '<div class="informer__item">' |
|
| 77 | + . (!$res ? '' : $res) |
|
| 78 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | + . '</div>' |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | + . _T('bouton_choisir') |
|
| 84 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | + . '</div>' |
|
| 86 | + . '</div>'; |
|
| 87 | 87 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | include_spip('inc/texte'); |
| 21 | 21 | $titre = $descriptif = ''; |
| 22 | 22 | if ($type === 'rubrique') { |
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id)); |
|
| 24 | 24 | if ($row) { |
| 25 | 25 | $titre = typo($row['titre']); |
| 26 | 26 | $descriptif = propre($row['descriptif']); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | include_spip('inc/filtres_images_mini'); |
| 43 | 43 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 44 | 44 | if ($res) { |
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | ' ' |
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do.'_selection_titre'; |
|
| 68 | 68 | |
| 69 | 69 | return "<div style='display: none;'>" |
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 72 | 72 | . entites_html($titre) |
| 73 | 73 | . '" />' |
| 74 | 74 | . '</div>' |
| 75 | 75 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 76 | 76 | . '<div class="informer__item">' |
| 77 | 77 | . (!$res ? '' : $res) |
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 78 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>') |
|
| 80 | 80 | . '</div>' |
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 82 | 82 | . "<input type='submit' class='fondo btn submit' value='" |
| 83 | 83 | . _T('bouton_choisir') |
| 84 | 84 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -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,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return string Code HTML |
| 44 | 44 | **/ |
| 45 | 45 | function inc_commencer_page_dist( |
| 46 | - $titre = '', |
|
| 47 | - $rubrique = 'accueil', |
|
| 48 | - $sous_rubrique = 'accueil', |
|
| 49 | - $id_rubrique = '', |
|
| 50 | - $menu = true, |
|
| 51 | - $minipres = false, |
|
| 52 | - $alertes = true |
|
| 46 | + $titre = '', |
|
| 47 | + $rubrique = 'accueil', |
|
| 48 | + $sous_rubrique = 'accueil', |
|
| 49 | + $id_rubrique = '', |
|
| 50 | + $menu = true, |
|
| 51 | + $minipres = false, |
|
| 52 | + $alertes = true |
|
| 53 | 53 | ) { |
| 54 | 54 | |
| 55 | - include_spip('inc/headers'); |
|
| 55 | + include_spip('inc/headers'); |
|
| 56 | 56 | |
| 57 | - http_no_cache(); |
|
| 57 | + http_no_cache(); |
|
| 58 | 58 | |
| 59 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | - . "<div id='page'>" |
|
| 62 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | - . '<div class="largeur">'; |
|
| 59 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | + . "<div id='page'>" |
|
| 62 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | + . '<div class="largeur">'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | * Entête du fichier HTML avec le DOCTYPE |
| 83 | 83 | */ |
| 84 | 84 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 85 | - include_spip('inc/texte'); |
|
| 86 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $titre = '[' |
|
| 91 | - . $nom_site_spip |
|
| 92 | - . ']' |
|
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | - |
|
| 95 | - return _DOCTYPE_ECRIRE |
|
| 96 | - . html_lang_attributes() |
|
| 97 | - . "<head>\n" |
|
| 98 | - . init_head($titre, $dummy, $minipres) |
|
| 99 | - . "</head>\n"; |
|
| 85 | + include_spip('inc/texte'); |
|
| 86 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $titre = '[' |
|
| 91 | + . $nom_site_spip |
|
| 92 | + . ']' |
|
| 93 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | + |
|
| 95 | + return _DOCTYPE_ECRIRE |
|
| 96 | + . html_lang_attributes() |
|
| 97 | + . "<head>\n" |
|
| 98 | + . init_head($titre, $dummy, $minipres) |
|
| 99 | + . "</head>\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 113 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,20 +132,20 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | - $res = pipeline('body_prive', "<body class='" |
|
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | - . '>'); |
|
| 135 | + $res = pipeline('body_prive', "<body class='" |
|
| 136 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | + . '>'); |
|
| 139 | 139 | |
| 140 | - if (!$menu) { |
|
| 141 | - return $res; |
|
| 142 | - } |
|
| 140 | + if (!$menu) { |
|
| 141 | + return $res; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 146 | 146 | |
| 147 | - return $res |
|
| 148 | - . $bandeau(); |
|
| 147 | + return $res |
|
| 148 | + . $bandeau(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,23 +157,23 @@ discard block |
||
| 157 | 157 | * @return string Classes CSS (séparées par des espaces) |
| 158 | 158 | */ |
| 159 | 159 | function init_body_class() { |
| 160 | - $display_modes = [ |
|
| 161 | - 0 => 'icones_img_texte' // défaut. |
|
| 162 | - /*init*/, |
|
| 163 | - 1 => 'icones_texte', |
|
| 164 | - 2 => 'icones_img_texte', |
|
| 165 | - 3 => 'icones_img' |
|
| 166 | - ]; |
|
| 160 | + $display_modes = [ |
|
| 161 | + 0 => 'icones_img_texte' // défaut. |
|
| 162 | + /*init*/, |
|
| 163 | + 1 => 'icones_texte', |
|
| 164 | + 2 => 'icones_img_texte', |
|
| 165 | + 3 => 'icones_img' |
|
| 166 | + ]; |
|
| 167 | 167 | |
| 168 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 168 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 169 | 169 | |
| 170 | - $display_mode = $display_modes[intval($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 171 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 170 | + $display_mode = $display_modes[intval($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 171 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 172 | 172 | |
| 173 | - $couleur = intval($prefs['couleur'] ?? 2); |
|
| 173 | + $couleur = intval($prefs['couleur'] ?? 2); |
|
| 174 | 174 | |
| 175 | - $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 176 | - return spip_sanitize_classname($classes); |
|
| 175 | + $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 176 | + return spip_sanitize_classname($classes); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -184,5 +184,5 @@ discard block |
||
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | 186 | function auteurs_recemment_connectes($id_auteur) { |
| 187 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 187 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 188 | 188 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** Drapeau indiquant que l'on est dans l'espace privé */ |
| 20 | 20 | define('_ESPACE_PRIVE', true); |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - include 'inc_version.php'; |
|
| 22 | + include 'inc_version.php'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/cookie'); |
@@ -35,18 +35,18 @@ discard block |
||
| 35 | 35 | // alors il faut blinder les variables d'URL |
| 36 | 36 | // |
| 37 | 37 | if (autoriser_sans_cookie($exec, false)) { |
| 38 | - if (!isset($reinstall)) { |
|
| 39 | - $reinstall = 'non'; |
|
| 40 | - } |
|
| 41 | - $var_auth = true; |
|
| 38 | + if (!isset($reinstall)) { |
|
| 39 | + $reinstall = 'non'; |
|
| 40 | + } |
|
| 41 | + $var_auth = true; |
|
| 42 | 42 | } else { |
| 43 | - // Authentification, redefinissable |
|
| 44 | - $auth = charger_fonction('auth', 'inc'); |
|
| 45 | - $var_auth = $auth(); |
|
| 46 | - if ($var_auth) { |
|
| 47 | - echo auth_echec($var_auth); |
|
| 48 | - exit; |
|
| 49 | - } |
|
| 43 | + // Authentification, redefinissable |
|
| 44 | + $auth = charger_fonction('auth', 'inc'); |
|
| 45 | + $var_auth = $auth(); |
|
| 46 | + if ($var_auth) { |
|
| 47 | + echo auth_echec($var_auth); |
|
| 48 | + exit; |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // initialiser a la langue par defaut |
@@ -57,29 +57,29 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
| 60 | - if (!autoriser_sans_cookie($exec)) { |
|
| 61 | - // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 62 | - include_spip('public/aiguiller'); |
|
| 63 | - if ( |
|
| 64 | - // cas des appels actions ?action=xxx |
|
| 65 | - traiter_appels_actions() |
|
| 66 | - or |
|
| 67 | - // cas des hits ajax sur les inclusions ajax |
|
| 68 | - traiter_appels_inclusions_ajax() |
|
| 69 | - or |
|
| 70 | - // cas des formulaires charger/verifier/traiter |
|
| 71 | - traiter_formulaires_dynamiques() |
|
| 72 | - ) { |
|
| 73 | - exit; |
|
| 74 | - } // le hit est fini ! |
|
| 75 | - } |
|
| 60 | + if (!autoriser_sans_cookie($exec)) { |
|
| 61 | + // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 62 | + include_spip('public/aiguiller'); |
|
| 63 | + if ( |
|
| 64 | + // cas des appels actions ?action=xxx |
|
| 65 | + traiter_appels_actions() |
|
| 66 | + or |
|
| 67 | + // cas des hits ajax sur les inclusions ajax |
|
| 68 | + traiter_appels_inclusions_ajax() |
|
| 69 | + or |
|
| 70 | + // cas des formulaires charger/verifier/traiter |
|
| 71 | + traiter_formulaires_dynamiques() |
|
| 72 | + ) { |
|
| 73 | + exit; |
|
| 74 | + } // le hit est fini ! |
|
| 75 | + } |
|
| 76 | 76 | } |
| 77 | 77 | // securiser les redirect du back-office |
| 78 | 78 | if (_request('redirect')) { |
| 79 | - if (!function_exists('securiser_redirect_action')) { |
|
| 80 | - include_spip('public/aiguiller'); |
|
| 81 | - } |
|
| 82 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 79 | + if (!function_exists('securiser_redirect_action')) { |
|
| 80 | + include_spip('public/aiguiller'); |
|
| 81 | + } |
|
| 82 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | // Controle de la version, sauf si on est deja en train de s'en occuper |
| 91 | 91 | if ( |
| 92 | - !$reinstall == 'oui' |
|
| 93 | - and !_AJAX |
|
| 94 | - and isset($GLOBALS['meta']['version_installee']) |
|
| 95 | - and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 92 | + !$reinstall == 'oui' |
|
| 93 | + and !_AJAX |
|
| 94 | + and isset($GLOBALS['meta']['version_installee']) |
|
| 95 | + and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 96 | 96 | ) { |
| 97 | - $exec = 'demande_mise_a_jour'; |
|
| 97 | + $exec = 'demande_mise_a_jour'; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Quand une action d'administration est en cours (meta "admin"), |
@@ -104,39 +104,39 @@ discard block |
||
| 104 | 104 | // sinon c'est qu'elle a ete interrompue et il faut la reprendre |
| 105 | 105 | |
| 106 | 106 | elseif (isset($GLOBALS['meta']['admin'])) { |
| 107 | - if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 108 | - [, $var_f, $n] = $l; |
|
| 109 | - } |
|
| 110 | - if ( |
|
| 111 | - _AJAX |
|
| 112 | - or !( |
|
| 113 | - isset($_COOKIE['spip_admin']) |
|
| 114 | - or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 115 | - ) |
|
| 116 | - ) { |
|
| 117 | - spip_log('Quand la meta admin vaut ' . |
|
| 118 | - $GLOBALS['meta']['admin'] . |
|
| 119 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 120 | - ' En cas de probleme, detruire cette meta.'); |
|
| 121 | - die(_T('info_travaux_texte')); |
|
| 122 | - } |
|
| 123 | - if ($n) { |
|
| 124 | - [, $var_f, $n] = $l; |
|
| 125 | - if (tester_url_ecrire("base_$var_f")) { |
|
| 126 | - $var_f = "base_$var_f"; |
|
| 127 | - } |
|
| 128 | - if ($var_f != $exec) { |
|
| 129 | - spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 130 | - $exec = $var_f; |
|
| 131 | - set_request('exec', $exec); |
|
| 132 | - } |
|
| 133 | - } |
|
| 107 | + if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 108 | + [, $var_f, $n] = $l; |
|
| 109 | + } |
|
| 110 | + if ( |
|
| 111 | + _AJAX |
|
| 112 | + or !( |
|
| 113 | + isset($_COOKIE['spip_admin']) |
|
| 114 | + or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 115 | + ) |
|
| 116 | + ) { |
|
| 117 | + spip_log('Quand la meta admin vaut ' . |
|
| 118 | + $GLOBALS['meta']['admin'] . |
|
| 119 | + ' seul un admin peut se connecter et sans AJAX.' . |
|
| 120 | + ' En cas de probleme, detruire cette meta.'); |
|
| 121 | + die(_T('info_travaux_texte')); |
|
| 122 | + } |
|
| 123 | + if ($n) { |
|
| 124 | + [, $var_f, $n] = $l; |
|
| 125 | + if (tester_url_ecrire("base_$var_f")) { |
|
| 126 | + $var_f = "base_$var_f"; |
|
| 127 | + } |
|
| 128 | + if ($var_f != $exec) { |
|
| 129 | + spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 130 | + $exec = $var_f; |
|
| 131 | + set_request('exec', $exec); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | // si nom pas plausible, prendre le script par defaut |
| 136 | 136 | // attention aux deux cas 404/403 qui commencent par un 4 ! |
| 137 | 137 | elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) { |
| 138 | - $exec = 'accueil'; |
|
| 139 | - set_request('exec', $exec); |
|
| 138 | + $exec = 'accueil'; |
|
| 139 | + set_request('exec', $exec); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // si la langue est specifiee par cookie et ne correspond pas |
@@ -144,19 +144,19 @@ discard block |
||
| 144 | 144 | // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie |
| 145 | 145 | // si le cookie n'est pas pose correctement dans l'action |
| 146 | 146 | if ( |
| 147 | - !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 148 | - and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 147 | + !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 148 | + and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 149 | 149 | ) { |
| 150 | - include_spip('action/converser'); |
|
| 151 | - action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 150 | + include_spip('action/converser'); |
|
| 151 | + action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ($var_f = tester_url_ecrire($exec)) { |
| 155 | - $var_f = charger_fonction($var_f); |
|
| 156 | - $var_f(); // at last |
|
| 155 | + $var_f = charger_fonction($var_f); |
|
| 156 | + $var_f(); // at last |
|
| 157 | 157 | } else { |
| 158 | - // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 159 | - // ce qui permet de laisser la main a un plugin |
|
| 160 | - $var_f = charger_fonction('404'); |
|
| 161 | - $var_f($exec); |
|
| 158 | + // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 159 | + // ce qui permet de laisser la main a un plugin |
|
| 160 | + $var_f = charger_fonction('404'); |
|
| 161 | + $var_f($exec); |
|
| 162 | 162 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * Ce programme est un logiciel libre distribué sous licence GNU/GPL. * |
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 12 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Fichier d'exécution de l'interface privée |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | // Determiner l'action demandee |
| 30 | 30 | // |
| 31 | 31 | |
| 32 | -$exec = (string)_request('exec'); |
|
| 32 | +$exec = (string) _request('exec'); |
|
| 33 | 33 | $reinstall = (!is_null(_request('reinstall'))) ? _request('reinstall') : ($exec == 'install' ? 'oui' : null); |
| 34 | 34 | // |
| 35 | 35 | // Les scripts d'insallation n'authentifient pas, forcement, |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
| 116 | 116 | ) |
| 117 | 117 | ) { |
| 118 | - spip_log('Quand la meta admin vaut ' . |
|
| 119 | - $GLOBALS['meta']['admin'] . |
|
| 120 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 118 | + spip_log('Quand la meta admin vaut '. |
|
| 119 | + $GLOBALS['meta']['admin']. |
|
| 120 | + ' seul un admin peut se connecter et sans AJAX.'. |
|
| 121 | 121 | ' En cas de probleme, detruire cette meta.'); |
| 122 | 122 | die(_T('info_travaux_texte')); |
| 123 | 123 | } |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | 78 | if (($t = objet_type($objet)) !== $objet) { |
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 80 | 80 | $objet = $t; |
| 81 | 81 | } |
| 82 | 82 | if ( |
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 83 | + include_spip('action/editer_'.$objet) |
|
| 84 | + and function_exists($modifier = $objet.'_modifier') |
|
| 85 | 85 | ) { |
| 86 | 86 | return $modifier($id, $set); |
| 87 | 87 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 91 | 91 | $desc = $trouver_table($table_sql); |
| 92 | 92 | if (!$desc or !isset($desc['field'])) { |
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer'._LOG_ERREUR); |
|
| 94 | 94 | |
| 95 | 95 | return _L("Erreur objet $objet inconnu"); |
| 96 | 96 | } |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | 171 | $d = null; |
| 172 | 172 | if (($t = objet_type($objet)) !== $objet) { |
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 174 | 174 | $objet = $t; |
| 175 | 175 | } |
| 176 | 176 | if ( |
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 177 | + include_spip('action/editer_'.$objet) |
|
| 178 | + and function_exists($inserer = $objet.'_inserer') |
|
| 179 | 179 | ) { |
| 180 | 180 | return $inserer($id_parent, $set); |
| 181 | 181 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
| 197 | 197 | $id_rubrique = $row['id_rubrique']; |
| 198 | 198 | } else { |
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $champs['id_rubrique'] = $id_rubrique; |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 316 | 316 | if (($t = objet_type($objet)) !== $objet) { |
| 317 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 317 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 318 | 318 | $objet = $t; |
| 319 | 319 | } |
| 320 | 320 | if ( |
| 321 | - include_spip('action/editer_' . $objet) |
|
| 322 | - and function_exists($instituer = $objet . '_instituer') |
|
| 321 | + include_spip('action/editer_'.$objet) |
|
| 322 | + and function_exists($instituer = $objet.'_instituer') |
|
| 323 | 323 | ) { |
| 324 | 324 | return $instituer($id, $c, $calcul_rub); |
| 325 | 325 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
| 349 | 349 | $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
| 350 | 350 | |
| 351 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 351 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id)); |
|
| 352 | 352 | |
| 353 | 353 | $id_rubrique = $row['id_rubrique']; |
| 354 | 354 | $statut_ancien = $statut = $row['statut']; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
| 372 | 372 | $statut = $champs['statut'] = $s; |
| 373 | 373 | } else { |
| 374 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 374 | + spip_log("editer_objet $objet #$id refus ".json_encode($c, JSON_THROW_ON_ERROR), 'editer'._LOG_INFO_IMPORTANTE); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | and isset($c['id_parent']) |
| 402 | 402 | and $id_parent = $c['id_parent'] |
| 403 | 403 | and $id_parent != $id_rubrique |
| 404 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 404 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique='.intval($id_parent))) |
|
| 405 | 405 | ) { |
| 406 | 406 | $champs['id_rubrique'] = $id_parent; |
| 407 | 407 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | // Si on deplace l'objet |
| 501 | 501 | // changer aussi son secteur et sa langue (si heritee) |
| 502 | 502 | if (isset($champs['id_rubrique'])) { |
| 503 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 503 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique='.sql_quote($champs['id_rubrique'])); |
|
| 504 | 504 | $langue = $row_rub['lang']; |
| 505 | 505 | |
| 506 | 506 | if (isset($desc['field']['id_secteur'])) { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | sql_fetsel( |
| 513 | 513 | '1', |
| 514 | 514 | $table_sql, |
| 515 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 515 | + id_table_objet($objet).'='.intval($id)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue) |
|
| 516 | 516 | ) |
| 517 | 517 | ) { |
| 518 | 518 | $champs['lang'] = $langue; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | if (!$champs) { |
| 524 | 524 | return; |
| 525 | 525 | } |
| 526 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 526 | + sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id)); |
|
| 527 | 527 | |
| 528 | 528 | // Changer le statut des rubriques concernees |
| 529 | 529 | if ($cond) { |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | function objet_lire($objet, $valeur_id, $options = []) { |
| 569 | 569 | if (($t = objet_type($objet)) !== $objet) { |
| 570 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 570 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 571 | 571 | $objet = $t; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | ) { |
| 590 | 590 | // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
| 591 | 591 | if ( |
| 592 | - include_spip('action/editer_' . $objet) |
|
| 592 | + include_spip('action/editer_'.$objet) |
|
| 593 | 593 | and function_exists($lire = "{$objet}_lire_champs") |
| 594 | 594 | ) { |
| 595 | 595 | $valeurs = $lire($objet, $valeur_id, $champ_id); |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | // La condition est appliquée sur le champ désigné par l'utilisateur. |
| 601 | 601 | $where = [ |
| 602 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 602 | + $champ_id.'='.sql_quote($valeur_id) |
|
| 603 | 603 | ]; |
| 604 | 604 | |
| 605 | 605 | // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
@@ -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 | /** |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 35 | 35 | |
| 36 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | - if (is_null($id) or is_null($objet)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | - if (is_null($id) or is_null($objet)) { |
|
| 45 | - include_spip('inc/minipres'); |
|
| 46 | - echo minipres(_T('info_acces_interdit')); |
|
| 47 | - die(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id = intval($id)) { |
|
| 53 | - // on ne sait pas si un parent existe mais on essaye |
|
| 54 | - $id_parent = _request('id_parent'); |
|
| 55 | - $id = objet_inserer($objet, $id_parent); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!($id = intval($id)) > 0) { |
|
| 59 | - return [$id, _L('echec enregistrement en base')]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = objet_modifier($objet, $id, $set); |
|
| 64 | - |
|
| 65 | - return [$id, $err]; |
|
| 36 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | + if (is_null($id) or is_null($objet)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | + if (is_null($id) or is_null($objet)) { |
|
| 45 | + include_spip('inc/minipres'); |
|
| 46 | + echo minipres(_T('info_acces_interdit')); |
|
| 47 | + die(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id = intval($id)) { |
|
| 53 | + // on ne sait pas si un parent existe mais on essaye |
|
| 54 | + $id_parent = _request('id_parent'); |
|
| 55 | + $id = objet_inserer($objet, $id_parent); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!($id = intval($id)) > 0) { |
|
| 59 | + return [$id, _L('echec enregistrement en base')]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = objet_modifier($objet, $id, $set); |
|
| 64 | + |
|
| 65 | + return [$id, $err]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,85 +75,85 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | - $objet = $t; |
|
| 81 | - } |
|
| 82 | - if ( |
|
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 85 | - ) { |
|
| 86 | - return $modifier($id, $set); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $table_sql = table_objet_sql($objet); |
|
| 90 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | - $desc = $trouver_table($table_sql); |
|
| 92 | - if (!$desc or !isset($desc['field'])) { |
|
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | - |
|
| 95 | - return _L("Erreur objet $objet inconnu"); |
|
| 96 | - } |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - |
|
| 99 | - $champ_date = ''; |
|
| 100 | - if (isset($desc['date']) and $desc['date']) { |
|
| 101 | - $champ_date = $desc['date']; |
|
| 102 | - } elseif (isset($desc['field']['date'])) { |
|
| 103 | - $champ_date = 'date'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $include_list = array_keys($desc['field']); |
|
| 107 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | - |
|
| 111 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | - $include_list = $desc['champs_editables']; |
|
| 113 | - } |
|
| 114 | - $c = collecter_requests( |
|
| 115 | - // include list |
|
| 116 | - $include_list, |
|
| 117 | - // exclude list |
|
| 118 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | - // donnees eventuellement fournies |
|
| 120 | - $set |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | - if (objet_test_si_publie($objet, $id)) { |
|
| 125 | - $invalideur = "id='$objet/$id'"; |
|
| 126 | - $indexation = true; |
|
| 127 | - } else { |
|
| 128 | - $invalideur = ''; |
|
| 129 | - $indexation = false; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ( |
|
| 133 | - $err = objet_modifier_champs( |
|
| 134 | - $objet, |
|
| 135 | - $id, |
|
| 136 | - [ |
|
| 137 | - 'data' => $set, |
|
| 138 | - 'nonvide' => '', |
|
| 139 | - 'invalideur' => $invalideur, |
|
| 140 | - 'indexation' => $indexation, |
|
| 141 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | - ], |
|
| 144 | - $c |
|
| 145 | - ) |
|
| 146 | - ) { |
|
| 147 | - return $err; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Modification de statut, changement de rubrique ? |
|
| 151 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | - $err = objet_instituer($objet, $id, $c); |
|
| 155 | - |
|
| 156 | - return $err; |
|
| 78 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | + $objet = $t; |
|
| 81 | + } |
|
| 82 | + if ( |
|
| 83 | + include_spip('action/editer_' . $objet) |
|
| 84 | + and function_exists($modifier = $objet . '_modifier') |
|
| 85 | + ) { |
|
| 86 | + return $modifier($id, $set); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $table_sql = table_objet_sql($objet); |
|
| 90 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | + $desc = $trouver_table($table_sql); |
|
| 92 | + if (!$desc or !isset($desc['field'])) { |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | + |
|
| 95 | + return _L("Erreur objet $objet inconnu"); |
|
| 96 | + } |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + |
|
| 99 | + $champ_date = ''; |
|
| 100 | + if (isset($desc['date']) and $desc['date']) { |
|
| 101 | + $champ_date = $desc['date']; |
|
| 102 | + } elseif (isset($desc['field']['date'])) { |
|
| 103 | + $champ_date = 'date'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $include_list = array_keys($desc['field']); |
|
| 107 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | + |
|
| 111 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | + $include_list = $desc['champs_editables']; |
|
| 113 | + } |
|
| 114 | + $c = collecter_requests( |
|
| 115 | + // include list |
|
| 116 | + $include_list, |
|
| 117 | + // exclude list |
|
| 118 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | + // donnees eventuellement fournies |
|
| 120 | + $set |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | + if (objet_test_si_publie($objet, $id)) { |
|
| 125 | + $invalideur = "id='$objet/$id'"; |
|
| 126 | + $indexation = true; |
|
| 127 | + } else { |
|
| 128 | + $invalideur = ''; |
|
| 129 | + $indexation = false; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ( |
|
| 133 | + $err = objet_modifier_champs( |
|
| 134 | + $objet, |
|
| 135 | + $id, |
|
| 136 | + [ |
|
| 137 | + 'data' => $set, |
|
| 138 | + 'nonvide' => '', |
|
| 139 | + 'invalideur' => $invalideur, |
|
| 140 | + 'indexation' => $indexation, |
|
| 141 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | + ], |
|
| 144 | + $c |
|
| 145 | + ) |
|
| 146 | + ) { |
|
| 147 | + return $err; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Modification de statut, changement de rubrique ? |
|
| 151 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | + $err = objet_instituer($objet, $id, $c); |
|
| 155 | + |
|
| 156 | + return $err; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -168,157 +168,157 @@ discard block |
||
| 168 | 168 | * @return bool|int |
| 169 | 169 | */ |
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | - $d = null; |
|
| 172 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | - $objet = $t; |
|
| 175 | - } |
|
| 176 | - if ( |
|
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 179 | - ) { |
|
| 180 | - return $inserer($id_parent, $set); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $table_sql = table_objet_sql($objet); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $desc = $trouver_table($table_sql); |
|
| 186 | - if (!$desc or !isset($desc['field'])) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $lang_rub = ''; |
|
| 191 | - $champs = []; |
|
| 192 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | - // dans la premiere rubrique racine |
|
| 195 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | - $id_rubrique = $row['id_rubrique']; |
|
| 198 | - } else { |
|
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | - if (isset($desc['field']['id_secteur'])) { |
|
| 204 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | - } |
|
| 206 | - $lang_rub = $row['lang']; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | - // ou a defaut celle de la rubrique |
|
| 212 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | - if ( |
|
| 214 | - isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | - $table_sql, |
|
| 216 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | - ) |
|
| 218 | - ) { |
|
| 219 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | - if ( |
|
| 221 | - in_array( |
|
| 222 | - $GLOBALS['spip_lang'], |
|
| 223 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | - ) |
|
| 225 | - ) { |
|
| 226 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | - $champs['langue_choisie'] = 'oui'; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | - $champs['langue_choisie'] = 'non'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (isset($desc['field']['statut'])) { |
|
| 237 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | - $champs['statut'] = reset($cles_statut); |
|
| 240 | - } else { |
|
| 241 | - $champs['statut'] = 'prepa'; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($set) { |
|
| 251 | - $champs = array_merge($champs, $set); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // Envoyer aux plugins |
|
| 255 | - $champs = pipeline( |
|
| 256 | - 'pre_insertion', |
|
| 257 | - [ |
|
| 258 | - 'args' => [ |
|
| 259 | - 'table' => $table_sql, |
|
| 260 | - 'id_parent' => $id_parent, |
|
| 261 | - ], |
|
| 262 | - 'data' => $champs |
|
| 263 | - ] |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - $id = sql_insertq($table_sql, $champs); |
|
| 267 | - |
|
| 268 | - if ($id) { |
|
| 269 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | - // et associer l'auteur sinon |
|
| 271 | - // si la table n'a pas deja un champ id_auteur |
|
| 272 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | - if ( |
|
| 274 | - $id > 0 |
|
| 275 | - and !isset($desc['field']['id_auteur']) |
|
| 276 | - ) { |
|
| 277 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | - : _request('id_auteur')); |
|
| 280 | - if ($id_auteur) { |
|
| 281 | - include_spip('action/editer_auteur'); |
|
| 282 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - pipeline( |
|
| 287 | - 'post_insertion', |
|
| 288 | - [ |
|
| 289 | - 'args' => [ |
|
| 290 | - 'table' => $table_sql, |
|
| 291 | - 'id_parent' => $id_parent, |
|
| 292 | - 'id_objet' => $id, |
|
| 293 | - ], |
|
| 294 | - 'data' => $champs |
|
| 295 | - ] |
|
| 296 | - ); |
|
| 297 | - } |
|
| 171 | + $d = null; |
|
| 172 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | + $objet = $t; |
|
| 175 | + } |
|
| 176 | + if ( |
|
| 177 | + include_spip('action/editer_' . $objet) |
|
| 178 | + and function_exists($inserer = $objet . '_inserer') |
|
| 179 | + ) { |
|
| 180 | + return $inserer($id_parent, $set); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $table_sql = table_objet_sql($objet); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $desc = $trouver_table($table_sql); |
|
| 186 | + if (!$desc or !isset($desc['field'])) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $lang_rub = ''; |
|
| 191 | + $champs = []; |
|
| 192 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | + // dans la premiere rubrique racine |
|
| 195 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | + $id_rubrique = $row['id_rubrique']; |
|
| 198 | + } else { |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | + if (isset($desc['field']['id_secteur'])) { |
|
| 204 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | + } |
|
| 206 | + $lang_rub = $row['lang']; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | + // ou a defaut celle de la rubrique |
|
| 212 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | + if ( |
|
| 214 | + isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | + $table_sql, |
|
| 216 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | + ) |
|
| 218 | + ) { |
|
| 219 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | + if ( |
|
| 221 | + in_array( |
|
| 222 | + $GLOBALS['spip_lang'], |
|
| 223 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | + ) |
|
| 225 | + ) { |
|
| 226 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | + $champs['langue_choisie'] = 'oui'; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | + $champs['langue_choisie'] = 'non'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (isset($desc['field']['statut'])) { |
|
| 237 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | + $champs['statut'] = reset($cles_statut); |
|
| 240 | + } else { |
|
| 241 | + $champs['statut'] = 'prepa'; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($set) { |
|
| 251 | + $champs = array_merge($champs, $set); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // Envoyer aux plugins |
|
| 255 | + $champs = pipeline( |
|
| 256 | + 'pre_insertion', |
|
| 257 | + [ |
|
| 258 | + 'args' => [ |
|
| 259 | + 'table' => $table_sql, |
|
| 260 | + 'id_parent' => $id_parent, |
|
| 261 | + ], |
|
| 262 | + 'data' => $champs |
|
| 263 | + ] |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + $id = sql_insertq($table_sql, $champs); |
|
| 267 | + |
|
| 268 | + if ($id) { |
|
| 269 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | + // et associer l'auteur sinon |
|
| 271 | + // si la table n'a pas deja un champ id_auteur |
|
| 272 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | + if ( |
|
| 274 | + $id > 0 |
|
| 275 | + and !isset($desc['field']['id_auteur']) |
|
| 276 | + ) { |
|
| 277 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | + : _request('id_auteur')); |
|
| 280 | + if ($id_auteur) { |
|
| 281 | + include_spip('action/editer_auteur'); |
|
| 282 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + pipeline( |
|
| 287 | + 'post_insertion', |
|
| 288 | + [ |
|
| 289 | + 'args' => [ |
|
| 290 | + 'table' => $table_sql, |
|
| 291 | + 'id_parent' => $id_parent, |
|
| 292 | + 'id_objet' => $id, |
|
| 293 | + ], |
|
| 294 | + 'data' => $champs |
|
| 295 | + ] |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Appeler une notification |
|
| 300 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 301 | - $notifications( |
|
| 302 | - "{$objet}_inserer", |
|
| 303 | - $id, |
|
| 304 | - [ |
|
| 305 | - 'id_parent' => $id_parent, |
|
| 306 | - 'champs' => $champs, |
|
| 307 | - ] |
|
| 308 | - ); |
|
| 309 | - $notifications( |
|
| 310 | - 'objet_inserer', |
|
| 311 | - $id, |
|
| 312 | - [ |
|
| 313 | - 'objet' => $objet, |
|
| 314 | - 'id_objet' => $id, |
|
| 315 | - 'id_parent' => $id_parent, |
|
| 316 | - 'champs' => $champs, |
|
| 317 | - ] |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - return $id; |
|
| 299 | + // Appeler une notification |
|
| 300 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 301 | + $notifications( |
|
| 302 | + "{$objet}_inserer", |
|
| 303 | + $id, |
|
| 304 | + [ |
|
| 305 | + 'id_parent' => $id_parent, |
|
| 306 | + 'champs' => $champs, |
|
| 307 | + ] |
|
| 308 | + ); |
|
| 309 | + $notifications( |
|
| 310 | + 'objet_inserer', |
|
| 311 | + $id, |
|
| 312 | + [ |
|
| 313 | + 'objet' => $objet, |
|
| 314 | + 'id_objet' => $id, |
|
| 315 | + 'id_parent' => $id_parent, |
|
| 316 | + 'champs' => $champs, |
|
| 317 | + ] |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + return $id; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -335,138 +335,138 @@ discard block |
||
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | 337 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 338 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 339 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 340 | - $objet = $t; |
|
| 341 | - } |
|
| 342 | - if ( |
|
| 343 | - include_spip('action/editer_' . $objet) |
|
| 344 | - and function_exists($instituer = $objet . '_instituer') |
|
| 345 | - ) { |
|
| 346 | - return $instituer($id, $c, $calcul_rub); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $table_sql = table_objet_sql($objet); |
|
| 350 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 351 | - $desc = $trouver_table($table_sql); |
|
| 352 | - if (!$desc or !isset($desc['field'])) { |
|
| 353 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - include_spip('inc/autoriser'); |
|
| 357 | - include_spip('inc/rubriques'); |
|
| 358 | - include_spip('inc/modifier'); |
|
| 359 | - |
|
| 360 | - $sel = []; |
|
| 361 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 362 | - |
|
| 363 | - $champ_date = ''; |
|
| 364 | - if (isset($desc['date']) and $desc['date']) { |
|
| 365 | - $champ_date = $desc['date']; |
|
| 366 | - } elseif (isset($desc['field']['date'])) { |
|
| 367 | - $champ_date = 'date'; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 371 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 372 | - |
|
| 373 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 374 | - |
|
| 375 | - $id_rubrique = $row['id_rubrique']; |
|
| 376 | - $statut_ancien = $statut = $row['statut']; |
|
| 377 | - $date_ancienne = $date = $row['date']; |
|
| 378 | - $champs = []; |
|
| 379 | - |
|
| 380 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 381 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 382 | - |
|
| 383 | - // cf autorisations dans inc/instituer_objet |
|
| 384 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 385 | - if ( |
|
| 386 | - $id_rubrique ? |
|
| 387 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 388 | - : |
|
| 389 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 390 | - ) { |
|
| 391 | - $statut = $champs['statut'] = $s; |
|
| 392 | - } else { |
|
| 393 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 394 | - $statut = $champs['statut'] = $s; |
|
| 395 | - } else { |
|
| 396 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // En cas de publication, fixer la date a "maintenant" |
|
| 401 | - // sauf si $c commande autre chose |
|
| 402 | - // ou si l'objet est deja date dans le futur |
|
| 403 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 404 | - if ($champ_date) { |
|
| 405 | - if ( |
|
| 406 | - $champs['statut'] == 'publie' |
|
| 407 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 408 | - or $d |
|
| 409 | - ) { |
|
| 410 | - if ($d or strtotime($d = $date) > time()) { |
|
| 411 | - $champs[$champ_date] = $date = $d; |
|
| 412 | - } else { |
|
| 413 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // Verifier que la rubrique demandee existe et est differente |
|
| 420 | - // de la rubrique actuelle |
|
| 421 | - if ( |
|
| 422 | - $id_rubrique |
|
| 423 | - and isset($c['id_parent']) |
|
| 424 | - and $id_parent = $c['id_parent'] |
|
| 425 | - and $id_parent != $id_rubrique |
|
| 426 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 427 | - ) { |
|
| 428 | - $champs['id_rubrique'] = $id_parent; |
|
| 429 | - |
|
| 430 | - // si l'objet etait publie |
|
| 431 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 432 | - // repasser l'objet en statut 'propose'. |
|
| 433 | - if ( |
|
| 434 | - $statut == 'publie' |
|
| 435 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 436 | - ) { |
|
| 437 | - $champs['statut'] = 'prop'; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - // Envoyer aux plugins |
|
| 443 | - $champs = pipeline( |
|
| 444 | - 'pre_edition', |
|
| 445 | - [ |
|
| 446 | - 'args' => [ |
|
| 447 | - 'table' => $table_sql, |
|
| 448 | - 'id_objet' => $id, |
|
| 449 | - 'action' => 'instituer', |
|
| 450 | - 'statut_ancien' => $statut_ancien, |
|
| 451 | - 'date_ancienne' => $date_ancienne, |
|
| 452 | - 'id_parent_ancien' => $id_rubrique, |
|
| 453 | - ], |
|
| 454 | - 'data' => $champs |
|
| 455 | - ] |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 459 | - return ''; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - // Envoyer les modifs. |
|
| 463 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 464 | - |
|
| 465 | - // Invalider les caches |
|
| 466 | - include_spip('inc/invalideur'); |
|
| 467 | - suivre_invalideur("id='$objet/$id'"); |
|
| 468 | - |
|
| 469 | - /* |
|
| 338 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 339 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 340 | + $objet = $t; |
|
| 341 | + } |
|
| 342 | + if ( |
|
| 343 | + include_spip('action/editer_' . $objet) |
|
| 344 | + and function_exists($instituer = $objet . '_instituer') |
|
| 345 | + ) { |
|
| 346 | + return $instituer($id, $c, $calcul_rub); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $table_sql = table_objet_sql($objet); |
|
| 350 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 351 | + $desc = $trouver_table($table_sql); |
|
| 352 | + if (!$desc or !isset($desc['field'])) { |
|
| 353 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + include_spip('inc/autoriser'); |
|
| 357 | + include_spip('inc/rubriques'); |
|
| 358 | + include_spip('inc/modifier'); |
|
| 359 | + |
|
| 360 | + $sel = []; |
|
| 361 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 362 | + |
|
| 363 | + $champ_date = ''; |
|
| 364 | + if (isset($desc['date']) and $desc['date']) { |
|
| 365 | + $champ_date = $desc['date']; |
|
| 366 | + } elseif (isset($desc['field']['date'])) { |
|
| 367 | + $champ_date = 'date'; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 371 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 372 | + |
|
| 373 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 374 | + |
|
| 375 | + $id_rubrique = $row['id_rubrique']; |
|
| 376 | + $statut_ancien = $statut = $row['statut']; |
|
| 377 | + $date_ancienne = $date = $row['date']; |
|
| 378 | + $champs = []; |
|
| 379 | + |
|
| 380 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 381 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 382 | + |
|
| 383 | + // cf autorisations dans inc/instituer_objet |
|
| 384 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 385 | + if ( |
|
| 386 | + $id_rubrique ? |
|
| 387 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 388 | + : |
|
| 389 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 390 | + ) { |
|
| 391 | + $statut = $champs['statut'] = $s; |
|
| 392 | + } else { |
|
| 393 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 394 | + $statut = $champs['statut'] = $s; |
|
| 395 | + } else { |
|
| 396 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // En cas de publication, fixer la date a "maintenant" |
|
| 401 | + // sauf si $c commande autre chose |
|
| 402 | + // ou si l'objet est deja date dans le futur |
|
| 403 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 404 | + if ($champ_date) { |
|
| 405 | + if ( |
|
| 406 | + $champs['statut'] == 'publie' |
|
| 407 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 408 | + or $d |
|
| 409 | + ) { |
|
| 410 | + if ($d or strtotime($d = $date) > time()) { |
|
| 411 | + $champs[$champ_date] = $date = $d; |
|
| 412 | + } else { |
|
| 413 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // Verifier que la rubrique demandee existe et est differente |
|
| 420 | + // de la rubrique actuelle |
|
| 421 | + if ( |
|
| 422 | + $id_rubrique |
|
| 423 | + and isset($c['id_parent']) |
|
| 424 | + and $id_parent = $c['id_parent'] |
|
| 425 | + and $id_parent != $id_rubrique |
|
| 426 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 427 | + ) { |
|
| 428 | + $champs['id_rubrique'] = $id_parent; |
|
| 429 | + |
|
| 430 | + // si l'objet etait publie |
|
| 431 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 432 | + // repasser l'objet en statut 'propose'. |
|
| 433 | + if ( |
|
| 434 | + $statut == 'publie' |
|
| 435 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 436 | + ) { |
|
| 437 | + $champs['statut'] = 'prop'; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + // Envoyer aux plugins |
|
| 443 | + $champs = pipeline( |
|
| 444 | + 'pre_edition', |
|
| 445 | + [ |
|
| 446 | + 'args' => [ |
|
| 447 | + 'table' => $table_sql, |
|
| 448 | + 'id_objet' => $id, |
|
| 449 | + 'action' => 'instituer', |
|
| 450 | + 'statut_ancien' => $statut_ancien, |
|
| 451 | + 'date_ancienne' => $date_ancienne, |
|
| 452 | + 'id_parent_ancien' => $id_rubrique, |
|
| 453 | + ], |
|
| 454 | + 'data' => $champs |
|
| 455 | + ] |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 459 | + return ''; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + // Envoyer les modifs. |
|
| 463 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 464 | + |
|
| 465 | + // Invalider les caches |
|
| 466 | + include_spip('inc/invalideur'); |
|
| 467 | + suivre_invalideur("id='$objet/$id'"); |
|
| 468 | + |
|
| 469 | + /* |
|
| 470 | 470 | if ($date) { |
| 471 | 471 | $t = strtotime($date); |
| 472 | 472 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -475,60 +475,60 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | }*/ |
| 477 | 477 | |
| 478 | - // Pipeline |
|
| 479 | - pipeline( |
|
| 480 | - 'post_edition', |
|
| 481 | - [ |
|
| 482 | - 'args' => [ |
|
| 483 | - 'table' => $table_sql, |
|
| 484 | - 'id_objet' => $id, |
|
| 485 | - 'action' => 'instituer', |
|
| 486 | - 'statut_ancien' => $statut_ancien, |
|
| 487 | - 'date_ancienne' => $date_ancienne, |
|
| 488 | - 'id_parent_ancien' => $id_rubrique, |
|
| 489 | - ], |
|
| 490 | - 'data' => $champs |
|
| 491 | - ] |
|
| 492 | - ); |
|
| 493 | - |
|
| 494 | - // Notifications |
|
| 495 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 496 | - $notifications( |
|
| 497 | - "{$objet}_instituer", |
|
| 498 | - $id, |
|
| 499 | - [ |
|
| 500 | - 'statut' => $statut, |
|
| 501 | - 'statut_ancien' => $statut_ancien, |
|
| 502 | - 'date' => $date, |
|
| 503 | - 'date_ancienne' => $date_ancienne, |
|
| 504 | - 'id_parent_ancien' => $id_rubrique, |
|
| 505 | - 'champs' => $champs, |
|
| 506 | - ] |
|
| 507 | - ); |
|
| 508 | - $notifications( |
|
| 509 | - 'objet_instituer', |
|
| 510 | - $id, |
|
| 511 | - [ |
|
| 512 | - 'objet' => $objet, |
|
| 513 | - 'id_objet' => $id, |
|
| 514 | - 'statut' => $statut, |
|
| 515 | - 'statut_ancien' => $statut_ancien, |
|
| 516 | - 'date' => $date, |
|
| 517 | - 'date_ancienne' => $date_ancienne, |
|
| 518 | - 'id_parent_ancien' => $id_rubrique, |
|
| 519 | - 'champs' => $champs, |
|
| 520 | - ] |
|
| 521 | - ); |
|
| 478 | + // Pipeline |
|
| 479 | + pipeline( |
|
| 480 | + 'post_edition', |
|
| 481 | + [ |
|
| 482 | + 'args' => [ |
|
| 483 | + 'table' => $table_sql, |
|
| 484 | + 'id_objet' => $id, |
|
| 485 | + 'action' => 'instituer', |
|
| 486 | + 'statut_ancien' => $statut_ancien, |
|
| 487 | + 'date_ancienne' => $date_ancienne, |
|
| 488 | + 'id_parent_ancien' => $id_rubrique, |
|
| 489 | + ], |
|
| 490 | + 'data' => $champs |
|
| 491 | + ] |
|
| 492 | + ); |
|
| 493 | + |
|
| 494 | + // Notifications |
|
| 495 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 496 | + $notifications( |
|
| 497 | + "{$objet}_instituer", |
|
| 498 | + $id, |
|
| 499 | + [ |
|
| 500 | + 'statut' => $statut, |
|
| 501 | + 'statut_ancien' => $statut_ancien, |
|
| 502 | + 'date' => $date, |
|
| 503 | + 'date_ancienne' => $date_ancienne, |
|
| 504 | + 'id_parent_ancien' => $id_rubrique, |
|
| 505 | + 'champs' => $champs, |
|
| 506 | + ] |
|
| 507 | + ); |
|
| 508 | + $notifications( |
|
| 509 | + 'objet_instituer', |
|
| 510 | + $id, |
|
| 511 | + [ |
|
| 512 | + 'objet' => $objet, |
|
| 513 | + 'id_objet' => $id, |
|
| 514 | + 'statut' => $statut, |
|
| 515 | + 'statut_ancien' => $statut_ancien, |
|
| 516 | + 'date' => $date, |
|
| 517 | + 'date_ancienne' => $date_ancienne, |
|
| 518 | + 'id_parent_ancien' => $id_rubrique, |
|
| 519 | + 'champs' => $champs, |
|
| 520 | + ] |
|
| 521 | + ); |
|
| 522 | 522 | |
| 523 | - // Rétro-compat |
|
| 524 | - $notifications( |
|
| 525 | - "instituer$objet", |
|
| 526 | - $id, |
|
| 527 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - return ''; // pas d'erreur |
|
| 523 | + // Rétro-compat |
|
| 524 | + $notifications( |
|
| 525 | + "instituer$objet", |
|
| 526 | + $id, |
|
| 527 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + return ''; // pas d'erreur |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -543,51 +543,51 @@ discard block |
||
| 543 | 543 | * @return void |
| 544 | 544 | */ |
| 545 | 545 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 546 | - $table_sql = table_objet_sql($objet); |
|
| 547 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | - $desc = $trouver_table($table_sql); |
|
| 549 | - |
|
| 550 | - // Si on deplace l'objet |
|
| 551 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 552 | - if (isset($champs['id_rubrique'])) { |
|
| 553 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 554 | - $langue = $row_rub['lang']; |
|
| 555 | - |
|
| 556 | - if (isset($desc['field']['id_secteur'])) { |
|
| 557 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 561 | - if ( |
|
| 562 | - sql_fetsel( |
|
| 563 | - '1', |
|
| 564 | - $table_sql, |
|
| 565 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 566 | - ) |
|
| 567 | - ) { |
|
| 568 | - $champs['lang'] = $langue; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - if (!$champs) { |
|
| 574 | - return; |
|
| 575 | - } |
|
| 576 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 577 | - |
|
| 578 | - // Changer le statut des rubriques concernees |
|
| 579 | - if ($cond) { |
|
| 580 | - include_spip('inc/rubriques'); |
|
| 581 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 582 | - $postdate = false; |
|
| 583 | - // On rajoute les infos de l'objet |
|
| 584 | - $infos = [ |
|
| 585 | - 'objet' => $objet, |
|
| 586 | - 'id_objet' => $id, |
|
| 587 | - 'statut_ancien' => $statut, |
|
| 588 | - ]; |
|
| 589 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 590 | - } |
|
| 546 | + $table_sql = table_objet_sql($objet); |
|
| 547 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | + $desc = $trouver_table($table_sql); |
|
| 549 | + |
|
| 550 | + // Si on deplace l'objet |
|
| 551 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 552 | + if (isset($champs['id_rubrique'])) { |
|
| 553 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 554 | + $langue = $row_rub['lang']; |
|
| 555 | + |
|
| 556 | + if (isset($desc['field']['id_secteur'])) { |
|
| 557 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 561 | + if ( |
|
| 562 | + sql_fetsel( |
|
| 563 | + '1', |
|
| 564 | + $table_sql, |
|
| 565 | + id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 566 | + ) |
|
| 567 | + ) { |
|
| 568 | + $champs['lang'] = $langue; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + if (!$champs) { |
|
| 574 | + return; |
|
| 575 | + } |
|
| 576 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 577 | + |
|
| 578 | + // Changer le statut des rubriques concernees |
|
| 579 | + if ($cond) { |
|
| 580 | + include_spip('inc/rubriques'); |
|
| 581 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 582 | + $postdate = false; |
|
| 583 | + // On rajoute les infos de l'objet |
|
| 584 | + $infos = [ |
|
| 585 | + 'objet' => $objet, |
|
| 586 | + 'id_objet' => $id, |
|
| 587 | + 'statut_ancien' => $statut, |
|
| 588 | + ]; |
|
| 589 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | |
@@ -616,75 +616,75 @@ discard block |
||
| 616 | 616 | * string|int : valeur du champ demande pour l'objet demande |
| 617 | 617 | */ |
| 618 | 618 | function objet_lire($objet, $valeur_id, $options = []) { |
| 619 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 620 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 621 | - $objet = $t; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 625 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 626 | - static $descriptions = []; |
|
| 627 | - |
|
| 628 | - // On détermine le nom du champ id de la table. |
|
| 629 | - include_spip('base/objets'); |
|
| 630 | - $primary = id_table_objet($objet); |
|
| 631 | - |
|
| 632 | - // On détermine l'id à utiliser. |
|
| 633 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 634 | - |
|
| 635 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 636 | - if ( |
|
| 637 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 638 | - or (isset($options['force']) and $options['force']) |
|
| 639 | - ) { |
|
| 640 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 641 | - if ( |
|
| 642 | - include_spip('action/editer_' . $objet) |
|
| 643 | - and function_exists($lire = "{$objet}_lire_champs") |
|
| 644 | - ) { |
|
| 645 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 646 | - } else { |
|
| 647 | - // On récupère la table SQL à partir du type d'objet. |
|
| 648 | - $table = table_objet_sql($objet); |
|
| 649 | - |
|
| 650 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 651 | - $where = [ |
|
| 652 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 653 | - ]; |
|
| 654 | - |
|
| 655 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 656 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - if (!$valeurs) { |
|
| 660 | - $valeurs = false; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 664 | - |
|
| 665 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 666 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 667 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 672 | - |
|
| 673 | - // On ne retourne maintenant que les champs demandés. |
|
| 674 | - // - on détermine les informations à renvoyer. |
|
| 675 | - if ($retour and !empty($options['champs'])) { |
|
| 676 | - $champs = $options['champs']; |
|
| 677 | - // Extraction des seules informations demandées. |
|
| 678 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 679 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 680 | - if (is_array($champs)) { |
|
| 681 | - // Tableau des informations valides |
|
| 682 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 683 | - } else { |
|
| 684 | - // Valeur unique demandée. |
|
| 685 | - $retour = ($retour[$champs] ?? false); |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - return $retour; |
|
| 619 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 620 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 621 | + $objet = $t; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 625 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 626 | + static $descriptions = []; |
|
| 627 | + |
|
| 628 | + // On détermine le nom du champ id de la table. |
|
| 629 | + include_spip('base/objets'); |
|
| 630 | + $primary = id_table_objet($objet); |
|
| 631 | + |
|
| 632 | + // On détermine l'id à utiliser. |
|
| 633 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 634 | + |
|
| 635 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 636 | + if ( |
|
| 637 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 638 | + or (isset($options['force']) and $options['force']) |
|
| 639 | + ) { |
|
| 640 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 641 | + if ( |
|
| 642 | + include_spip('action/editer_' . $objet) |
|
| 643 | + and function_exists($lire = "{$objet}_lire_champs") |
|
| 644 | + ) { |
|
| 645 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 646 | + } else { |
|
| 647 | + // On récupère la table SQL à partir du type d'objet. |
|
| 648 | + $table = table_objet_sql($objet); |
|
| 649 | + |
|
| 650 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 651 | + $where = [ |
|
| 652 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 653 | + ]; |
|
| 654 | + |
|
| 655 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 656 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + if (!$valeurs) { |
|
| 660 | + $valeurs = false; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 664 | + |
|
| 665 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 666 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 667 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 672 | + |
|
| 673 | + // On ne retourne maintenant que les champs demandés. |
|
| 674 | + // - on détermine les informations à renvoyer. |
|
| 675 | + if ($retour and !empty($options['champs'])) { |
|
| 676 | + $champs = $options['champs']; |
|
| 677 | + // Extraction des seules informations demandées. |
|
| 678 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 679 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 680 | + if (is_array($champs)) { |
|
| 681 | + // Tableau des informations valides |
|
| 682 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 683 | + } else { |
|
| 684 | + // Valeur unique demandée. |
|
| 685 | + $retour = ($retour[$champs] ?? false); |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + return $retour; |
|
| 690 | 690 | } |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | $_id = $e['id_table_objet']; |
| 51 | 51 | if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
| 52 | 52 | $table = $e['table_objet_sql']; |
| 53 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 53 | + $row = sql_fetsel('*', $table, "$_id=".intval($id)); |
|
| 54 | 54 | if (isset($row['id_rubrique'])) { |
| 55 | 55 | $contexte['id_rubrique'] = $row['id_rubrique']; |
| 56 | 56 | if (isset($row['id_secteur'])) { |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
| 115 | 115 | + [ |
| 116 | 116 | $id => new Bouton( |
| 117 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | - $infos['titre'], // titre |
|
| 117 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 118 | + $infos['titre'], // titre |
|
| 119 | 119 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 120 | 120 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 121 | 121 | ) |
@@ -132,8 +132,8 @@ discard block |
||
| 132 | 132 | $boutons_admin = array_slice($boutons_admin, 0, $position) |
| 133 | 133 | + [ |
| 134 | 134 | $id => new Bouton( |
| 135 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | - $infos['titre'], // titre |
|
| 135 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 136 | + $infos['titre'], // titre |
|
| 137 | 137 | (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
| 138 | 138 | (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
| 139 | 139 | ) |
@@ -220,7 +220,7 @@ discard block |
||
| 220 | 220 | $url = str_replace('&', '&', $url); |
| 221 | 221 | while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
| 222 | 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'])); |
|
| 223 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.intval($contexte['id_rubrique'])); |
|
| 224 | 224 | } |
| 225 | 225 | $val = _request($matches[2], $contexte); |
| 226 | 226 | $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/boutons'); |
@@ -39,33 +39,33 @@ discard block |
||
| 39 | 39 | * contexte |
| 40 | 40 | **/ |
| 41 | 41 | function definir_barre_contexte($contexte = null) { |
| 42 | - if (is_null($contexte)) { |
|
| 43 | - $contexte = $_GET; |
|
| 44 | - } elseif (is_string($contexte)) { |
|
| 45 | - $contexte = unserialize($contexte); |
|
| 46 | - } |
|
| 47 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 48 | - if (!function_exists('trouver_objet_exec')) { |
|
| 49 | - include_spip('inc/pipelines_ecrire'); |
|
| 50 | - } |
|
| 51 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 52 | - $_id = $e['id_table_objet']; |
|
| 53 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 54 | - $table = $e['table_objet_sql']; |
|
| 55 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 56 | - if (isset($row['id_rubrique'])) { |
|
| 57 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 58 | - if (isset($row['id_secteur'])) { |
|
| 59 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 60 | - } |
|
| 61 | - } elseif (isset($row['id_groupe'])) { |
|
| 62 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 63 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - return $contexte; |
|
| 42 | + if (is_null($contexte)) { |
|
| 43 | + $contexte = $_GET; |
|
| 44 | + } elseif (is_string($contexte)) { |
|
| 45 | + $contexte = unserialize($contexte); |
|
| 46 | + } |
|
| 47 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 48 | + if (!function_exists('trouver_objet_exec')) { |
|
| 49 | + include_spip('inc/pipelines_ecrire'); |
|
| 50 | + } |
|
| 51 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 52 | + $_id = $e['id_table_objet']; |
|
| 53 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 54 | + $table = $e['table_objet_sql']; |
|
| 55 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 56 | + if (isset($row['id_rubrique'])) { |
|
| 57 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 58 | + if (isset($row['id_secteur'])) { |
|
| 59 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 60 | + } |
|
| 61 | + } elseif (isset($row['id_groupe'])) { |
|
| 62 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 63 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + return $contexte; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -81,89 +81,89 @@ discard block |
||
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | 83 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 84 | - include_spip('inc/autoriser'); |
|
| 85 | - $boutons_admin = []; |
|
| 84 | + include_spip('inc/autoriser'); |
|
| 85 | + $boutons_admin = []; |
|
| 86 | 86 | |
| 87 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 88 | - $liste_boutons = []; |
|
| 87 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 88 | + $liste_boutons = []; |
|
| 89 | 89 | |
| 90 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 91 | - if ( |
|
| 92 | - function_exists('boutons_plugins') |
|
| 93 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 94 | - ) { |
|
| 95 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 96 | - } |
|
| 90 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 91 | + if ( |
|
| 92 | + function_exists('boutons_plugins') |
|
| 93 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 94 | + ) { |
|
| 95 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - foreach ($liste_boutons as $id => $infos) { |
|
| 99 | - $parent = ''; |
|
| 100 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 101 | - if ( |
|
| 102 | - !isset($infos['parent']) |
|
| 103 | - or !($parent = $infos['parent']) |
|
| 104 | - or !$autorise |
|
| 105 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 106 | - ) { |
|
| 107 | - if ( |
|
| 108 | - $parent |
|
| 109 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 110 | - and isset($boutons_admin[$parent]) |
|
| 111 | - ) { |
|
| 112 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 113 | - if ($position < 0) { |
|
| 114 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 115 | - } |
|
| 116 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 117 | - + [ |
|
| 118 | - $id => new Bouton( |
|
| 119 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 120 | - $infos['titre'], // titre |
|
| 121 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 122 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 123 | - ) |
|
| 124 | - ] |
|
| 125 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 126 | - } |
|
| 127 | - if ( |
|
| 128 | - !$parent |
|
| 129 | - // provisoire, eviter les vieux boutons |
|
| 130 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 131 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 132 | - ) { |
|
| 133 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 134 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 135 | - + [ |
|
| 136 | - $id => new Bouton( |
|
| 137 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 138 | - $infos['titre'], // titre |
|
| 139 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 140 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 141 | - ) |
|
| 142 | - ] |
|
| 143 | - + array_slice($boutons_admin, $position, 100); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 98 | + foreach ($liste_boutons as $id => $infos) { |
|
| 99 | + $parent = ''; |
|
| 100 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 101 | + if ( |
|
| 102 | + !isset($infos['parent']) |
|
| 103 | + or !($parent = $infos['parent']) |
|
| 104 | + or !$autorise |
|
| 105 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 106 | + ) { |
|
| 107 | + if ( |
|
| 108 | + $parent |
|
| 109 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 110 | + and isset($boutons_admin[$parent]) |
|
| 111 | + ) { |
|
| 112 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 113 | + if ($position < 0) { |
|
| 114 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 115 | + } |
|
| 116 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 117 | + + [ |
|
| 118 | + $id => new Bouton( |
|
| 119 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 120 | + $infos['titre'], // titre |
|
| 121 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 122 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 123 | + ) |
|
| 124 | + ] |
|
| 125 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 126 | + } |
|
| 127 | + if ( |
|
| 128 | + !$parent |
|
| 129 | + // provisoire, eviter les vieux boutons |
|
| 130 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 131 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 132 | + ) { |
|
| 133 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 134 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 135 | + + [ |
|
| 136 | + $id => new Bouton( |
|
| 137 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 138 | + $infos['titre'], // titre |
|
| 139 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 140 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 141 | + ) |
|
| 142 | + ] |
|
| 143 | + + array_slice($boutons_admin, $position, 100); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 148 | 148 | |
| 149 | - // définir les favoris et positions d’origine |
|
| 150 | - if ($boutons_admin) { |
|
| 151 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 152 | - $i = 1; |
|
| 153 | - foreach ($boutons_admin as $key => $menu) { |
|
| 154 | - $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 155 | - $menu->position = $i++; |
|
| 156 | - if ($menu->sousmenu) { |
|
| 157 | - $j = 1; |
|
| 158 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 159 | - $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 160 | - $bouton->position = $j++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 149 | + // définir les favoris et positions d’origine |
|
| 150 | + if ($boutons_admin) { |
|
| 151 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 152 | + $i = 1; |
|
| 153 | + foreach ($boutons_admin as $key => $menu) { |
|
| 154 | + $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 155 | + $menu->position = $i++; |
|
| 156 | + if ($menu->sousmenu) { |
|
| 157 | + $j = 1; |
|
| 158 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 159 | + $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 160 | + $bouton->position = $j++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return $boutons_admin; |
|
| 166 | + return $boutons_admin; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -175,22 +175,22 @@ discard block |
||
| 175 | 175 | * @return Bouton[] |
| 176 | 176 | */ |
| 177 | 177 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 178 | - foreach ($menus as $menu) { |
|
| 179 | - if ($menu->sousmenu) { |
|
| 180 | - $libelles = $isfavoris = $favoris = []; |
|
| 181 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 182 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 183 | - $isfavoris[$key] = (bool) $item->favori; |
|
| 184 | - $favoris[$key] = $item->favori; |
|
| 185 | - } |
|
| 186 | - if ($avec_favoris) { |
|
| 187 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | - } else { |
|
| 189 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - return $menus; |
|
| 178 | + foreach ($menus as $menu) { |
|
| 179 | + if ($menu->sousmenu) { |
|
| 180 | + $libelles = $isfavoris = $favoris = []; |
|
| 181 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 182 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 183 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 184 | + $favoris[$key] = $item->favori; |
|
| 185 | + } |
|
| 186 | + if ($avec_favoris) { |
|
| 187 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | + } else { |
|
| 189 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + return $menus; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return Bouton[] |
| 202 | 202 | */ |
| 203 | 203 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 204 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 204 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
@@ -214,23 +214,23 @@ discard block |
||
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | 216 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 217 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 218 | - $url = generer_url_ecrire($url, $args, true); |
|
| 219 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 220 | - // &truc=@machin@ |
|
| 221 | - // @machin@ etant remplace par _request('machin') |
|
| 222 | - $url = str_replace('&', '&', $url); |
|
| 223 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 224 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 225 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | - } |
|
| 227 | - $val = _request($matches[2], $contexte); |
|
| 228 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 229 | - } |
|
| 230 | - $url = str_replace('&', '&', $url); |
|
| 231 | - } |
|
| 217 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 218 | + $url = generer_url_ecrire($url, $args, true); |
|
| 219 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 220 | + // &truc=@machin@ |
|
| 221 | + // @machin@ etant remplace par _request('machin') |
|
| 222 | + $url = str_replace('&', '&', $url); |
|
| 223 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 224 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 225 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | + } |
|
| 227 | + $val = _request($matches[2], $contexte); |
|
| 228 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 229 | + } |
|
| 230 | + $url = str_replace('&', '&', $url); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - return $url; |
|
| 233 | + return $url; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * Code HTML du bandeau |
| 241 | 241 | */ |
| 242 | 242 | function inc_bandeau_dist() { |
| 243 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 243 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | 251 | function obtenir_menus_favoris() { |
| 252 | - if ( |
|
| 253 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 256 | - ) { |
|
| 257 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 258 | - } |
|
| 259 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 260 | - return $definir_menus_favoris(); |
|
| 252 | + if ( |
|
| 253 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 256 | + ) { |
|
| 257 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 258 | + } |
|
| 259 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 260 | + return $definir_menus_favoris(); |
|
| 261 | 261 | } |
@@ -40,13 +40,13 @@ discard block |
||
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | 42 | if (is_null($liste_langues)) { |
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '').','.($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | 44 | } else { |
| 45 | 45 | if (is_array($liste_langues)) { |
| 46 | 46 | $liste_langues = implode(',', $liste_langues); |
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | + $liste_langues = ','.$liste_langues.','; |
|
| 50 | 50 | |
| 51 | 51 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 52 | 52 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | } |
| 193 | 193 | foreach ($langues as $l) { |
| 194 | 194 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 195 | + $ret .= "<option value='$l'$selected>[".$l.'] '.traduire_nom_langue($l)."</option>\n"; |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | if (!test_espace_prive()) { |
@@ -210,23 +210,21 @@ discard block |
||
| 210 | 210 | $base, |
| 211 | 211 | $cible, |
| 212 | 212 | (select_langues($nom_select, $change, $ret) |
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 214 | 214 | " method='post'" |
| 215 | 215 | ); |
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | 219 | static $cpt = 0; |
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 220 | + $id = 'menu_langues'.$cpt++; |
|
| 221 | 221 | |
| 222 | 222 | return |
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 223 | + "<label for='$id'>".($label ?: _T('info_langues')).'</label> '. |
|
| 224 | 224 | "<select name='$nom_select' id='$id' " |
| 225 | 225 | . ((!test_espace_prive()) ? |
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 226 | + ("class='forml menu_langues'") : (($nom_select == 'var_lang_ecrire') ? |
|
| 227 | + ("class='lang_ecrire'") : "class='fondl'")) |
|
| 230 | 228 | . $change |
| 231 | 229 | . ">\n" |
| 232 | 230 | . $options |
@@ -352,7 +350,7 @@ discard block |
||
| 352 | 350 | and (!isset($GLOBALS['spip_lang']) |
| 353 | 351 | or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 354 | 352 | ) { |
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 353 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 356 | 354 | } |
| 357 | 355 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 358 | 356 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -455,7 +453,7 @@ discard block |
||
| 455 | 453 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 456 | 454 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 457 | 455 | $GLOBALS['meta']['langue_site'] = $tout = |
| 458 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 456 | + (!$all_langs or (strpos(','._LANGUE_PAR_DEFAUT.',', (string) ",$all_langs,") !== false)) |
|
| 459 | 457 | ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
| 460 | 458 | ecrire_meta('langue_site', $tout); |
| 461 | 459 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,35 +39,35 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | - } else { |
|
| 45 | - if (is_array($liste_langues)) { |
|
| 46 | - $liste_langues = implode(',', $liste_langues); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | - |
|
| 51 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | - if (!$lang) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | - and str_contains($liste_langues, (string) ",$lang,")) |
|
| 62 | - ) { |
|
| 63 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | - |
|
| 67 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | + } else { |
|
| 45 | + if (is_array($liste_langues)) { |
|
| 46 | + $liste_langues = implode(',', $liste_langues); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | + |
|
| 51 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | + if (!$lang) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | + and str_contains($liste_langues, (string) ",$lang,")) |
|
| 62 | + ) { |
|
| 63 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | + |
|
| 67 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 81 | 81 | |
| 82 | 82 | function choisir_traduction($trads, $lang = '') { |
| 83 | - $k = approcher_langue($trads, $lang); |
|
| 83 | + $k = approcher_langue($trads, $lang); |
|
| 84 | 84 | |
| 85 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // retourne son 2e argument si c'est un index du premier |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | // la langue X etant consideree comme une approche de X_Y |
| 91 | 91 | function approcher_langue($trads, $lang = '') { |
| 92 | 92 | |
| 93 | - if (!$lang) { |
|
| 94 | - $lang = $GLOBALS['spip_lang']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (isset($trads[$lang])) { |
|
| 98 | - return $lang; |
|
| 99 | - } // cas des langues xx_yy |
|
| 100 | - else { |
|
| 101 | - $r = explode('_', $lang); |
|
| 102 | - if (isset($trads[$r[0]])) { |
|
| 103 | - return $r[0]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return ''; |
|
| 93 | + if (!$lang) { |
|
| 94 | + $lang = $GLOBALS['spip_lang']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (isset($trads[$lang])) { |
|
| 98 | + return $lang; |
|
| 99 | + } // cas des langues xx_yy |
|
| 100 | + else { |
|
| 101 | + $r = explode('_', $lang); |
|
| 102 | + if (isset($trads[$r[0]])) { |
|
| 103 | + return $r[0]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * Nom de la langue, sinon son code. |
| 120 | 120 | **/ |
| 121 | 121 | function traduire_nom_langue($lang) { |
| 122 | - include_spip('inc/lang_liste'); |
|
| 123 | - include_spip('inc/charsets'); |
|
| 122 | + include_spip('inc/lang_liste'); |
|
| 123 | + include_spip('inc/charsets'); |
|
| 124 | 124 | |
| 125 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | // hebreu a priori), 'droitier' sinon. |
| 136 | 136 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 137 | 137 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 138 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 139 | 139 | |
| 140 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | - $gaucher : $droitier; |
|
| 140 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | + $gaucher : $droitier; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // typo francaise ou anglaise ? |
@@ -147,29 +147,29 @@ discard block |
||
| 147 | 147 | // sinon determiner la typo en fonction de la langue courante |
| 148 | 148 | |
| 149 | 149 | function lang_typo($lang = '') { |
| 150 | - if (!$lang) { |
|
| 151 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | - } |
|
| 153 | - if ( |
|
| 154 | - $lang == 'eo' |
|
| 155 | - or $lang == 'fr' |
|
| 156 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | - or $lang == 'cpf' |
|
| 158 | - ) { |
|
| 159 | - return 'fr'; |
|
| 160 | - } else { |
|
| 161 | - return 'en'; |
|
| 162 | - } |
|
| 150 | + if (!$lang) { |
|
| 151 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | + } |
|
| 153 | + if ( |
|
| 154 | + $lang == 'eo' |
|
| 155 | + or $lang == 'fr' |
|
| 156 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | + or $lang == 'cpf' |
|
| 158 | + ) { |
|
| 159 | + return 'fr'; |
|
| 160 | + } else { |
|
| 161 | + return 'en'; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 166 | 166 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 167 | 167 | function changer_typo($lang = '') { |
| 168 | - if ($lang) { |
|
| 169 | - $GLOBALS['lang_objet'] = $lang; |
|
| 170 | - } else { |
|
| 171 | - unset($GLOBALS['lang_objet']); |
|
| 172 | - } |
|
| 168 | + if ($lang) { |
|
| 169 | + $GLOBALS['lang_objet'] = $lang; |
|
| 170 | + } else { |
|
| 171 | + unset($GLOBALS['lang_objet']); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // |
@@ -179,58 +179,58 @@ discard block |
||
| 179 | 179 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 180 | 180 | // |
| 181 | 181 | function menu_langues($nom_select, $default = '') { |
| 182 | - include_spip('inc/actions'); |
|
| 183 | - |
|
| 184 | - $langues = liste_options_langues($nom_select); |
|
| 185 | - $ret = ''; |
|
| 186 | - if (!count($langues)) { |
|
| 187 | - return ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (!$default) { |
|
| 191 | - $default = $GLOBALS['spip_lang']; |
|
| 192 | - } |
|
| 193 | - foreach ($langues as $l) { |
|
| 194 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (!test_espace_prive()) { |
|
| 199 | - $cible = self(); |
|
| 200 | - $base = ''; |
|
| 201 | - } else { |
|
| 202 | - $cible = self(); |
|
| 203 | - $base = spip_connect() ? 'base' : ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | - |
|
| 208 | - return generer_action_auteur( |
|
| 209 | - 'converser', |
|
| 210 | - $base, |
|
| 211 | - $cible, |
|
| 212 | - (select_langues($nom_select, $change, $ret) |
|
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | - " method='post'" |
|
| 215 | - ); |
|
| 182 | + include_spip('inc/actions'); |
|
| 183 | + |
|
| 184 | + $langues = liste_options_langues($nom_select); |
|
| 185 | + $ret = ''; |
|
| 186 | + if (!count($langues)) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (!$default) { |
|
| 191 | + $default = $GLOBALS['spip_lang']; |
|
| 192 | + } |
|
| 193 | + foreach ($langues as $l) { |
|
| 194 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (!test_espace_prive()) { |
|
| 199 | + $cible = self(); |
|
| 200 | + $base = ''; |
|
| 201 | + } else { |
|
| 202 | + $cible = self(); |
|
| 203 | + $base = spip_connect() ? 'base' : ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | + |
|
| 208 | + return generer_action_auteur( |
|
| 209 | + 'converser', |
|
| 210 | + $base, |
|
| 211 | + $cible, |
|
| 212 | + (select_langues($nom_select, $change, $ret) |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | + " method='post'" |
|
| 215 | + ); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | - static $cpt = 0; |
|
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 221 | - |
|
| 222 | - return |
|
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | - "<select name='$nom_select' id='$id' " |
|
| 225 | - . ((!test_espace_prive()) ? |
|
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 230 | - . $change |
|
| 231 | - . ">\n" |
|
| 232 | - . $options |
|
| 233 | - . '</select>'; |
|
| 219 | + static $cpt = 0; |
|
| 220 | + $id = 'menu_langues' . $cpt++; |
|
| 221 | + |
|
| 222 | + return |
|
| 223 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | + "<select name='$nom_select' id='$id' " |
|
| 225 | + . ((!test_espace_prive()) ? |
|
| 226 | + ("class='forml menu_langues'") : |
|
| 227 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | + ("class='lang_ecrire'") : |
|
| 229 | + "class='fondl'")) |
|
| 230 | + . $change |
|
| 231 | + . ">\n" |
|
| 232 | + . $options |
|
| 233 | + . '</select>'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -252,34 +252,34 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function liste_options_langues($nom_select) { |
| 254 | 254 | |
| 255 | - switch ($nom_select) { |
|
| 256 | - # #MENU_LANG |
|
| 257 | - case 'var_lang': |
|
| 258 | - # menu de changement de la langue d'un article |
|
| 259 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | - case 'changer_lang': |
|
| 261 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | - break; |
|
| 263 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | - # les langues presentes sous forme de fichiers de langue |
|
| 265 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | - case 'var_lang_ecrire': |
|
| 267 | - default: |
|
| 268 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | - init_langues(); |
|
| 270 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | - break; |
|
| 255 | + switch ($nom_select) { |
|
| 256 | + # #MENU_LANG |
|
| 257 | + case 'var_lang': |
|
| 258 | + # menu de changement de la langue d'un article |
|
| 259 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | + case 'changer_lang': |
|
| 261 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | + break; |
|
| 263 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | + # les langues presentes sous forme de fichiers de langue |
|
| 265 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | + case 'var_lang_ecrire': |
|
| 267 | + default: |
|
| 268 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | + init_langues(); |
|
| 270 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | + break; |
|
| 272 | 272 | |
| 273 | 273 | # dernier choix possible : toutes les langues = langues_proposees |
| 274 | 274 | # + langues_multilingues ; mais, ne sert pas |
| 275 | 275 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 276 | - } |
|
| 277 | - if (count($langues) <= 1) { |
|
| 278 | - return []; |
|
| 279 | - } |
|
| 280 | - sort($langues); |
|
| 276 | + } |
|
| 277 | + if (count($langues) <= 1) { |
|
| 278 | + return []; |
|
| 279 | + } |
|
| 280 | + sort($langues); |
|
| 281 | 281 | |
| 282 | - return $langues; |
|
| 282 | + return $langues; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -294,39 +294,39 @@ discard block |
||
| 294 | 294 | **/ |
| 295 | 295 | function verifier_lang_url() { |
| 296 | 296 | |
| 297 | - // quelle langue est demandee ? |
|
| 298 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | - } |
|
| 302 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | - } |
|
| 305 | - if (isset($_GET['lang'])) { |
|
| 306 | - $lang_demandee = $_GET['lang']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | - if ( |
|
| 311 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | - and changer_langue($lang_demandee) |
|
| 313 | - and $lang_demandee != @$_GET['lang'] |
|
| 314 | - ) { |
|
| 315 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | - // ici on a besoin des var_truc |
|
| 317 | - foreach ($_GET as $var => $val) { |
|
| 318 | - if (!strncmp('var_', $var, 4)) { |
|
| 319 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - include_spip('inc/headers'); |
|
| 323 | - redirige_par_entete($destination); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | - // (pour criteres {lang}). |
|
| 329 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 297 | + // quelle langue est demandee ? |
|
| 298 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | + } |
|
| 302 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | + } |
|
| 305 | + if (isset($_GET['lang'])) { |
|
| 306 | + $lang_demandee = $_GET['lang']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | + if ( |
|
| 311 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | + and changer_langue($lang_demandee) |
|
| 313 | + and $lang_demandee != @$_GET['lang'] |
|
| 314 | + ) { |
|
| 315 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | + // ici on a besoin des var_truc |
|
| 317 | + foreach ($_GET as $var => $val) { |
|
| 318 | + if (!strncmp('var_', $var, 4)) { |
|
| 319 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + include_spip('inc/headers'); |
|
| 323 | + redirige_par_entete($destination); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | + // (pour criteres {lang}). |
|
| 329 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -344,22 +344,22 @@ discard block |
||
| 344 | 344 | * La langue sélectionnée |
| 345 | 345 | **/ |
| 346 | 346 | function utiliser_langue_site($liste_langues = null) { |
| 347 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | - if ( |
|
| 349 | - isset($GLOBALS['meta']['langue_site']) |
|
| 350 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | - and (!isset($GLOBALS['spip_lang']) |
|
| 353 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | - ) { |
|
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | - } |
|
| 357 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $GLOBALS['spip_lang']; |
|
| 347 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | + if ( |
|
| 349 | + isset($GLOBALS['meta']['langue_site']) |
|
| 350 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | + and (!isset($GLOBALS['spip_lang']) |
|
| 353 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | + ) { |
|
| 355 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | + } |
|
| 357 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $GLOBALS['spip_lang']; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,35 +378,35 @@ discard block |
||
| 378 | 378 | **/ |
| 379 | 379 | function utiliser_langue_visiteur($liste_langues = null) { |
| 380 | 380 | |
| 381 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | - if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | - if (isset($_COOKIE[$l])) { |
|
| 388 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | - return $l; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | - return $l; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | - return $l; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return utiliser_langue_site($liste_langues); |
|
| 381 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | + if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | + if (isset($_COOKIE[$l])) { |
|
| 388 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | + return $l; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | + return $l; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | + return $l; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return utiliser_langue_site($liste_langues); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return int |
| 417 | 417 | */ |
| 418 | 418 | function match_langue($chaine) { |
| 419 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 419 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -434,36 +434,36 @@ discard block |
||
| 434 | 434 | **/ |
| 435 | 435 | function init_langues() { |
| 436 | 436 | |
| 437 | - // liste des langues dans les meta, sauf a l'install |
|
| 438 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | - |
|
| 440 | - $tout = []; |
|
| 441 | - if (!$all_langs) { |
|
| 442 | - // trouver tous les modules lang/spip_xx.php |
|
| 443 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | - foreach ($modules as $name => $path) { |
|
| 445 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | - if (match_langue($regs[1])) { |
|
| 447 | - $tout[] = $regs[1]; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - sort($tout); |
|
| 452 | - $tout = join(',', $tout); |
|
| 453 | - // Si les langues n'ont pas change, ne rien faire |
|
| 454 | - if ($tout != $all_langs) { |
|
| 455 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | - include_spip('inc/meta'); |
|
| 457 | - ecrire_meta('langues_proposees', $tout); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | - ecrire_meta('langue_site', $tout); |
|
| 466 | - } |
|
| 437 | + // liste des langues dans les meta, sauf a l'install |
|
| 438 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | + |
|
| 440 | + $tout = []; |
|
| 441 | + if (!$all_langs) { |
|
| 442 | + // trouver tous les modules lang/spip_xx.php |
|
| 443 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | + foreach ($modules as $name => $path) { |
|
| 445 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | + if (match_langue($regs[1])) { |
|
| 447 | + $tout[] = $regs[1]; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + sort($tout); |
|
| 452 | + $tout = join(',', $tout); |
|
| 453 | + // Si les langues n'ont pas change, ne rien faire |
|
| 454 | + if ($tout != $all_langs) { |
|
| 455 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | + include_spip('inc/meta'); |
|
| 457 | + ecrire_meta('langues_proposees', $tout); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | + ecrire_meta('langue_site', $tout); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | * Code html de la balise <html> |
| 478 | 478 | **/ |
| 479 | 479 | function html_lang_attributes() { |
| 480 | - $lang = $GLOBALS['spip_lang']; |
|
| 481 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 480 | + $lang = $GLOBALS['spip_lang']; |
|
| 481 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 482 | 482 | |
| 483 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | 496 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 497 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 497 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -381,8 +381,7 @@ |
||
| 381 | 381 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 382 | 382 | if (test_espace_prive()) { |
| 383 | 383 | return executer_balise_dynamique(...$args); |
| 384 | - } |
|
| 385 | - else { |
|
| 384 | + } else { |
|
| 386 | 385 | $str_args = base64_encode(serialize($args)); |
| 387 | 386 | return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
| 388 | 387 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -41,234 +41,234 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 43 | 43 | |
| 44 | - $skel = null; |
|
| 45 | - $boucle = null; |
|
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - eval("return true; $f ;"); |
|
| 96 | - } catch (\ParseError $e) { |
|
| 97 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | - erreur_squelette($msg, $boucle); |
|
| 100 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | - // mais prevenir que c'est mort |
|
| 102 | - $nom = ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // contexte de compil inutile a present |
|
| 106 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | - $skel_code[$id] = $f; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $code = ''; |
|
| 111 | - if ($nom) { |
|
| 112 | - // Si le code est bon, concatener et mettre en cache |
|
| 113 | - if (function_exists($nom)) { |
|
| 114 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | - } else { |
|
| 116 | - // code semantiquement faux: bug du compilateur |
|
| 117 | - // $boucle est en fait ici la fct principale du squelette |
|
| 118 | - $msg = _T('zbug_erreur_compilation'); |
|
| 119 | - erreur_squelette($msg, $boucle); |
|
| 120 | - $nom = ''; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | - // Tracer ce qui vient d'etre compile |
|
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | - |
|
| 128 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | - if ( |
|
| 130 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | - and (_request('var_mode_objet') == $nom) |
|
| 132 | - and (_request('var_mode_affiche') == 'code') |
|
| 133 | - ) { |
|
| 134 | - erreur_squelette(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $nom ?: false; |
|
| 44 | + $skel = null; |
|
| 45 | + $boucle = null; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + eval("return true; $f ;"); |
|
| 96 | + } catch (\ParseError $e) { |
|
| 97 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + erreur_squelette($msg, $boucle); |
|
| 100 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | + // mais prevenir que c'est mort |
|
| 102 | + $nom = ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // contexte de compil inutile a present |
|
| 106 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | + $skel_code[$id] = $f; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $code = ''; |
|
| 111 | + if ($nom) { |
|
| 112 | + // Si le code est bon, concatener et mettre en cache |
|
| 113 | + if (function_exists($nom)) { |
|
| 114 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | + } else { |
|
| 116 | + // code semantiquement faux: bug du compilateur |
|
| 117 | + // $boucle est en fait ici la fct principale du squelette |
|
| 118 | + $msg = _T('zbug_erreur_compilation'); |
|
| 119 | + erreur_squelette($msg, $boucle); |
|
| 120 | + $nom = ''; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | + // Tracer ce qui vient d'etre compile |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + |
|
| 128 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | + if ( |
|
| 130 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | + and (_request('var_mode_objet') == $nom) |
|
| 132 | + and (_request('var_mode_affiche') == 'code') |
|
| 133 | + ) { |
|
| 134 | + erreur_squelette(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $nom ?: false; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 142 | 142 | |
| 143 | - $code = null; |
|
| 144 | - // Le dernier index est '' (fonction principale) |
|
| 145 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 146 | - if (CODE_COMMENTE) { |
|
| 147 | - $code = " |
|
| 143 | + $code = null; |
|
| 144 | + // Le dernier index est '' (fonction principale) |
|
| 145 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 146 | + if (CODE_COMMENTE) { |
|
| 147 | + $code = " |
|
| 148 | 148 | /* |
| 149 | 149 | * Squelette : $sourcefile |
| 150 | 150 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 151 | 151 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 152 | 152 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 153 | 153 | */ '; |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 158 | - ecrire_fichier($phpfile, $code); |
|
| 159 | - } |
|
| 156 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 158 | + ecrire_fichier($phpfile, $code); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - return $code; |
|
| 161 | + return $code; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Le squelette compile est-il trop vieux ? |
| 165 | 165 | function squelette_obsolete($skel, $squelette) { |
| 166 | - static $date_change = null; |
|
| 167 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | - // par hit |
|
| 169 | - if (is_null($date_change)) { |
|
| 170 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | - $date_change = @filemtime($fonc); |
|
| 172 | - } # compatibilite |
|
| 173 | - if (defined('_FILE_OPTIONS')) { |
|
| 174 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return ( |
|
| 179 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | - or !@file_exists($skel) |
|
| 181 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | - > ($date = @filemtime($skel))) |
|
| 183 | - or ($date_change > $date) |
|
| 184 | - ); |
|
| 166 | + static $date_change = null; |
|
| 167 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | + // par hit |
|
| 169 | + if (is_null($date_change)) { |
|
| 170 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | + $date_change = @filemtime($fonc); |
|
| 172 | + } # compatibilite |
|
| 173 | + if (defined('_FILE_OPTIONS')) { |
|
| 174 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return ( |
|
| 179 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | + or !@file_exists($skel) |
|
| 181 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | + > ($date = @filemtime($skel))) |
|
| 183 | + or ($date_change > $date) |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | function invalideur_session(&$Cache, $code = null) { |
| 189 | - $Cache['session'] = spip_session(); |
|
| 189 | + $Cache['session'] = spip_session(); |
|
| 190 | 190 | |
| 191 | - return $code; |
|
| 191 | + return $code; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 196 | - static $filtres = []; |
|
| 197 | - $headers = []; |
|
| 198 | - $corps ??= ''; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - and preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - strpos($corps, '<' . '?') === false |
|
| 227 | - or |
|
| 228 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | - ) |
|
| 231 | - ? 'html' |
|
| 232 | - : 'php'; |
|
| 233 | - |
|
| 234 | - $skel = [ |
|
| 235 | - 'squelette' => $nom, |
|
| 236 | - 'source' => $source, |
|
| 237 | - 'process_ins' => $process_ins, |
|
| 238 | - 'invalideurs' => $cache, |
|
| 239 | - 'entetes' => $headers, |
|
| 240 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | - ]; |
|
| 242 | - |
|
| 243 | - // traiter #FILTRE{} et filtres |
|
| 244 | - if (!isset($filtres[$nom])) { |
|
| 245 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | - } |
|
| 247 | - $filtres_headers = []; |
|
| 248 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | - unset($headers['X-Spip-Filtre']); |
|
| 251 | - } |
|
| 252 | - if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | - include_spip('public/sandbox'); |
|
| 254 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | - |
|
| 256 | - if ($process_ins == 'html') { |
|
| 257 | - $skel['process_ins'] = ( |
|
| 258 | - strpos($corps, '<' . '?') === false |
|
| 259 | - or |
|
| 260 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | - ) |
|
| 263 | - ? 'html' |
|
| 264 | - : 'php'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $skel['entetes'] = $headers; |
|
| 269 | - $skel['texte'] = $corps; |
|
| 270 | - |
|
| 271 | - return $skel; |
|
| 196 | + static $filtres = []; |
|
| 197 | + $headers = []; |
|
| 198 | + $corps ??= ''; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + and preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + strpos($corps, '<' . '?') === false |
|
| 227 | + or |
|
| 228 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | + ) |
|
| 231 | + ? 'html' |
|
| 232 | + : 'php'; |
|
| 233 | + |
|
| 234 | + $skel = [ |
|
| 235 | + 'squelette' => $nom, |
|
| 236 | + 'source' => $source, |
|
| 237 | + 'process_ins' => $process_ins, |
|
| 238 | + 'invalideurs' => $cache, |
|
| 239 | + 'entetes' => $headers, |
|
| 240 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | + ]; |
|
| 242 | + |
|
| 243 | + // traiter #FILTRE{} et filtres |
|
| 244 | + if (!isset($filtres[$nom])) { |
|
| 245 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | + } |
|
| 247 | + $filtres_headers = []; |
|
| 248 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | + unset($headers['X-Spip-Filtre']); |
|
| 251 | + } |
|
| 252 | + if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | + include_spip('public/sandbox'); |
|
| 254 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | + |
|
| 256 | + if ($process_ins == 'html') { |
|
| 257 | + $skel['process_ins'] = ( |
|
| 258 | + strpos($corps, '<' . '?') === false |
|
| 259 | + or |
|
| 260 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | + ) |
|
| 263 | + ? 'html' |
|
| 264 | + : 'php'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $skel['entetes'] = $headers; |
|
| 269 | + $skel['texte'] = $corps; |
|
| 270 | + |
|
| 271 | + return $skel; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 283 | 283 | if ($lang_select) lang_select(); |
| 284 | 284 | ?' |
| 285 | - . '>'); |
|
| 285 | + . '>'); |
|
| 286 | 286 | |
| 287 | 287 | /** |
| 288 | 288 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -302,35 +302,35 @@ discard block |
||
| 302 | 302 | * Code PHP pour inclure le squelette de la balise dynamique |
| 303 | 303 | **/ |
| 304 | 304 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 305 | - if ( |
|
| 306 | - strncmp($file, '/', 1) !== 0 |
|
| 307 | - // pas de lien symbolique sous Windows |
|
| 308 | - and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
|
| 309 | - ) { |
|
| 310 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $lang = $context_compil[4]; |
|
| 314 | - if (preg_match(',\W,', $lang)) { |
|
| 315 | - $lang = ''; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $args = array_map('argumenter_squelette', $args); |
|
| 319 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | - } |
|
| 322 | - $args = join(', ', $args); |
|
| 323 | - |
|
| 324 | - $r = sprintf( |
|
| 325 | - CODE_INCLURE_BALISE, |
|
| 326 | - $file, |
|
| 327 | - $lang, |
|
| 328 | - $nom, |
|
| 329 | - $args, |
|
| 330 | - join(', ', array_map('_q', $context_compil)) |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - return $r; |
|
| 305 | + if ( |
|
| 306 | + strncmp($file, '/', 1) !== 0 |
|
| 307 | + // pas de lien symbolique sous Windows |
|
| 308 | + and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
|
| 309 | + ) { |
|
| 310 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $lang = $context_compil[4]; |
|
| 314 | + if (preg_match(',\W,', $lang)) { |
|
| 315 | + $lang = ''; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $args = array_map('argumenter_squelette', $args); |
|
| 319 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + } |
|
| 322 | + $args = join(', ', $args); |
|
| 323 | + |
|
| 324 | + $r = sprintf( |
|
| 325 | + CODE_INCLURE_BALISE, |
|
| 326 | + $file, |
|
| 327 | + $lang, |
|
| 328 | + $nom, |
|
| 329 | + $args, |
|
| 330 | + join(', ', array_map('_q', $context_compil)) |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + return $r; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | **/ |
| 349 | 349 | function argumenter_squelette($v) { |
| 350 | 350 | |
| 351 | - if (is_object($v)) { |
|
| 352 | - return var_export($v, true); |
|
| 353 | - } elseif (!is_array($v)) { |
|
| 354 | - return "'" . texte_script((string) $v) . "'"; |
|
| 355 | - } else { |
|
| 356 | - $out = []; |
|
| 357 | - foreach ($v as $k => $val) { |
|
| 358 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | - } |
|
| 351 | + if (is_object($v)) { |
|
| 352 | + return var_export($v, true); |
|
| 353 | + } elseif (!is_array($v)) { |
|
| 354 | + return "'" . texte_script((string) $v) . "'"; |
|
| 355 | + } else { |
|
| 356 | + $out = []; |
|
| 357 | + foreach ($v as $k => $val) { |
|
| 358 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,13 +378,13 @@ discard block |
||
| 378 | 378 | * @return string |
| 379 | 379 | */ |
| 380 | 380 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 381 | - if (test_espace_prive()) { |
|
| 382 | - return executer_balise_dynamique(...$args); |
|
| 383 | - } |
|
| 384 | - else { |
|
| 385 | - $str_args = base64_encode(serialize($args)); |
|
| 386 | - return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | - } |
|
| 381 | + if (test_espace_prive()) { |
|
| 382 | + return executer_balise_dynamique(...$args); |
|
| 383 | + } |
|
| 384 | + else { |
|
| 385 | + $str_args = base64_encode(serialize($args)); |
|
| 386 | + return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | + } |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -415,87 +415,87 @@ discard block |
||
| 415 | 415 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 416 | 416 | **/ |
| 417 | 417 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 418 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 419 | - $nom_balise = $nom; |
|
| 420 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 421 | - $nom_balise_generique = ''; |
|
| 422 | - |
|
| 423 | - $appel_php_depuis_modele = false; |
|
| 424 | - if ( |
|
| 425 | - is_array($context_compil) |
|
| 426 | - and !is_numeric($context_compil[3]) |
|
| 427 | - and empty($context_compil[0]) |
|
| 428 | - and empty($context_compil[1]) |
|
| 429 | - and empty($context_compil[2]) |
|
| 430 | - and empty($context_compil[3]) |
|
| 431 | - ) { |
|
| 432 | - $appel_php_depuis_modele = true; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 436 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 437 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 438 | - // injecter en premier arg le nom de la balise |
|
| 439 | - array_unshift($args, $nom); |
|
| 440 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 441 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 442 | - $nom_balise = $nom_balise_generique; |
|
| 443 | - } |
|
| 444 | - unset($balise_generique); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (!$fonction_balise) { |
|
| 448 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 449 | - erreur_squelette($msg, $context_compil); |
|
| 450 | - |
|
| 451 | - return ''; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // retrouver le fichier qui a déclaré la fonction |
|
| 455 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 456 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 457 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 458 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 459 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 460 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 464 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | - |
|
| 466 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 467 | - |
|
| 468 | - if (!is_array($r)) { |
|
| 469 | - return $r; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - // verifier que la fonction dyn est la, |
|
| 473 | - // sinon se replier sur la generique si elle existe |
|
| 474 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | - if ( |
|
| 476 | - $balise_generique = chercher_balise_generique($nom) |
|
| 477 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 478 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 480 | - ) { |
|
| 481 | - // et lui injecter en premier arg le nom de la balise |
|
| 482 | - array_unshift($r, $nom); |
|
| 483 | - $nom_balise = $nom_balise_generique; |
|
| 484 | - if (!_DIR_RESTREINT) { |
|
| 485 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | - } |
|
| 487 | - } else { |
|
| 488 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 489 | - erreur_squelette($msg, $context_compil); |
|
| 490 | - |
|
| 491 | - return ''; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ($appel_php_depuis_modele) { |
|
| 496 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 497 | - } |
|
| 498 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 418 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 419 | + $nom_balise = $nom; |
|
| 420 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 421 | + $nom_balise_generique = ''; |
|
| 422 | + |
|
| 423 | + $appel_php_depuis_modele = false; |
|
| 424 | + if ( |
|
| 425 | + is_array($context_compil) |
|
| 426 | + and !is_numeric($context_compil[3]) |
|
| 427 | + and empty($context_compil[0]) |
|
| 428 | + and empty($context_compil[1]) |
|
| 429 | + and empty($context_compil[2]) |
|
| 430 | + and empty($context_compil[3]) |
|
| 431 | + ) { |
|
| 432 | + $appel_php_depuis_modele = true; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 436 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 437 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 438 | + // injecter en premier arg le nom de la balise |
|
| 439 | + array_unshift($args, $nom); |
|
| 440 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 441 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 442 | + $nom_balise = $nom_balise_generique; |
|
| 443 | + } |
|
| 444 | + unset($balise_generique); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (!$fonction_balise) { |
|
| 448 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 449 | + erreur_squelette($msg, $context_compil); |
|
| 450 | + |
|
| 451 | + return ''; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // retrouver le fichier qui a déclaré la fonction |
|
| 455 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 456 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 457 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 458 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 459 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 460 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 464 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | + |
|
| 466 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 467 | + |
|
| 468 | + if (!is_array($r)) { |
|
| 469 | + return $r; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + // verifier que la fonction dyn est la, |
|
| 473 | + // sinon se replier sur la generique si elle existe |
|
| 474 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | + if ( |
|
| 476 | + $balise_generique = chercher_balise_generique($nom) |
|
| 477 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 478 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 480 | + ) { |
|
| 481 | + // et lui injecter en premier arg le nom de la balise |
|
| 482 | + array_unshift($r, $nom); |
|
| 483 | + $nom_balise = $nom_balise_generique; |
|
| 484 | + if (!_DIR_RESTREINT) { |
|
| 485 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | + } |
|
| 487 | + } else { |
|
| 488 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 489 | + erreur_squelette($msg, $context_compil); |
|
| 490 | + |
|
| 491 | + return ''; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ($appel_php_depuis_modele) { |
|
| 496 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 497 | + } |
|
| 498 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -510,23 +510,23 @@ discard block |
||
| 510 | 510 | * @return array|null |
| 511 | 511 | */ |
| 512 | 512 | function chercher_balise_generique($nom) { |
| 513 | - if (!str_contains($nom, '_')) { |
|
| 514 | - return null; |
|
| 515 | - } |
|
| 516 | - $nom_generique = $nom; |
|
| 517 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 518 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 519 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 520 | - if ($fonction_generique) { |
|
| 521 | - return [ |
|
| 522 | - 'nom' => $nom, |
|
| 523 | - 'nom_generique' => $nom_generique, |
|
| 524 | - 'fonction_generique' => $fonction_generique, |
|
| 525 | - ]; |
|
| 526 | - } |
|
| 527 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 528 | - } |
|
| 529 | - return null; |
|
| 513 | + if (!str_contains($nom, '_')) { |
|
| 514 | + return null; |
|
| 515 | + } |
|
| 516 | + $nom_generique = $nom; |
|
| 517 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 518 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 519 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 520 | + if ($fonction_generique) { |
|
| 521 | + return [ |
|
| 522 | + 'nom' => $nom, |
|
| 523 | + 'nom_generique' => $nom_generique, |
|
| 524 | + 'fonction_generique' => $fonction_generique, |
|
| 525 | + ]; |
|
| 526 | + } |
|
| 527 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 528 | + } |
|
| 529 | + return null; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | |
@@ -550,50 +550,50 @@ discard block |
||
| 550 | 550 | * @return null; |
| 551 | 551 | **/ |
| 552 | 552 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 553 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 554 | - if ( |
|
| 555 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 556 | - and $lang_select !== 'oui' |
|
| 557 | - ) { |
|
| 558 | - $lang = $GLOBALS['spip_lang']; |
|
| 559 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 560 | - elseif (!strlen($lang)) { |
|
| 561 | - $lang = $GLOBALS['spip_lang']; |
|
| 562 | - } // Cas 3. l'objet est multilingue ! |
|
| 563 | - elseif ( |
|
| 564 | - $lang_select !== 'oui' |
|
| 565 | - and strlen($titre) > 10 |
|
| 566 | - and str_contains($titre, '<multi>') |
|
| 567 | - and str_contains(echappe_html($titre), '<multi>') |
|
| 568 | - ) { |
|
| 569 | - $lang = $GLOBALS['spip_lang']; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 573 | - lang_select($lang); |
|
| 574 | - |
|
| 575 | - return; |
|
| 553 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 554 | + if ( |
|
| 555 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 556 | + and $lang_select !== 'oui' |
|
| 557 | + ) { |
|
| 558 | + $lang = $GLOBALS['spip_lang']; |
|
| 559 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 560 | + elseif (!strlen($lang)) { |
|
| 561 | + $lang = $GLOBALS['spip_lang']; |
|
| 562 | + } // Cas 3. l'objet est multilingue ! |
|
| 563 | + elseif ( |
|
| 564 | + $lang_select !== 'oui' |
|
| 565 | + and strlen($titre) > 10 |
|
| 566 | + and str_contains($titre, '<multi>') |
|
| 567 | + and str_contains(echappe_html($titre), '<multi>') |
|
| 568 | + ) { |
|
| 569 | + $lang = $GLOBALS['spip_lang']; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 573 | + lang_select($lang); |
|
| 574 | + |
|
| 575 | + return; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
| 579 | 579 | // Si un tableau &doublons[articles] est passe en parametre, |
| 580 | 580 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 581 | 581 | function nettoyer_env_doublons($envd) { |
| 582 | - foreach ($envd as $table => $liste) { |
|
| 583 | - $n = ''; |
|
| 584 | - foreach (explode(',', $liste) as $val) { |
|
| 585 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 586 | - $n .= ',' . $val; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - if (strlen($n)) { |
|
| 590 | - $envd[$table] = $n; |
|
| 591 | - } else { |
|
| 592 | - unset($envd[$table]); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $envd; |
|
| 582 | + foreach ($envd as $table => $liste) { |
|
| 583 | + $n = ''; |
|
| 584 | + foreach (explode(',', $liste) as $val) { |
|
| 585 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 586 | + $n .= ',' . $val; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + if (strlen($n)) { |
|
| 590 | + $envd[$table] = $n; |
|
| 591 | + } else { |
|
| 592 | + unset($envd[$table]); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $envd; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -612,21 +612,21 @@ discard block |
||
| 612 | 612 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 613 | 613 | **/ |
| 614 | 614 | function match_self($w) { |
| 615 | - if (is_string($w)) { |
|
| 616 | - return false; |
|
| 617 | - } |
|
| 618 | - if (is_array($w)) { |
|
| 619 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 620 | - return $w; |
|
| 621 | - } |
|
| 622 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 623 | - if ($m = match_self($sw)) { |
|
| 624 | - return $m; |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - return false; |
|
| 615 | + if (is_string($w)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 618 | + if (is_array($w)) { |
|
| 619 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 620 | + return $w; |
|
| 621 | + } |
|
| 622 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 623 | + if ($m = match_self($sw)) { |
|
| 624 | + return $m; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + return false; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -642,16 +642,16 @@ discard block |
||
| 642 | 642 | * est remplacée par son code. |
| 643 | 643 | **/ |
| 644 | 644 | function remplace_sous_requete($w, $sousrequete) { |
| 645 | - if (is_array($w)) { |
|
| 646 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 647 | - return $sousrequete; |
|
| 648 | - } |
|
| 649 | - foreach ($w as $k => $sw) { |
|
| 650 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $w; |
|
| 645 | + if (is_array($w)) { |
|
| 646 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 647 | + return $sousrequete; |
|
| 648 | + } |
|
| 649 | + foreach ($w as $k => $sw) { |
|
| 650 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $w; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -665,17 +665,17 @@ discard block |
||
| 665 | 665 | * - Conditions avec des sous requêtes |
| 666 | 666 | **/ |
| 667 | 667 | function trouver_sous_requetes($where) { |
| 668 | - $where_simples = []; |
|
| 669 | - $where_sous = []; |
|
| 670 | - foreach ($where as $k => $w) { |
|
| 671 | - if (match_self($w)) { |
|
| 672 | - $where_sous[$k] = $w; |
|
| 673 | - } else { |
|
| 674 | - $where_simples[$k] = $w; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return [$where_simples, $where_sous]; |
|
| 668 | + $where_simples = []; |
|
| 669 | + $where_sous = []; |
|
| 670 | + foreach ($where as $k => $w) { |
|
| 671 | + if (match_self($w)) { |
|
| 672 | + $where_sous[$k] = $w; |
|
| 673 | + } else { |
|
| 674 | + $where_simples[$k] = $w; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return [$where_simples, $where_sous]; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -701,292 +701,292 @@ discard block |
||
| 701 | 701 | * @return resource |
| 702 | 702 | */ |
| 703 | 703 | function calculer_select( |
| 704 | - $select = [], |
|
| 705 | - $from = [], |
|
| 706 | - $from_type = [], |
|
| 707 | - $where = [], |
|
| 708 | - $join = [], |
|
| 709 | - $groupby = [], |
|
| 710 | - $orderby = [], |
|
| 711 | - $limit = '', |
|
| 712 | - $having = [], |
|
| 713 | - $table = '', |
|
| 714 | - $id = '', |
|
| 715 | - $serveur = '', |
|
| 716 | - $requeter = true |
|
| 704 | + $select = [], |
|
| 705 | + $from = [], |
|
| 706 | + $from_type = [], |
|
| 707 | + $where = [], |
|
| 708 | + $join = [], |
|
| 709 | + $groupby = [], |
|
| 710 | + $orderby = [], |
|
| 711 | + $limit = '', |
|
| 712 | + $having = [], |
|
| 713 | + $table = '', |
|
| 714 | + $id = '', |
|
| 715 | + $serveur = '', |
|
| 716 | + $requeter = true |
|
| 717 | 717 | ) { |
| 718 | 718 | |
| 719 | - // retirer les criteres vides: |
|
| 720 | - // {X ?} avec X absent de l'URL |
|
| 721 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 722 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 723 | - $menage = false; |
|
| 724 | - foreach ($where as $k => $v) { |
|
| 725 | - if (is_array($v) and count($v)) { |
|
| 726 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 727 | - $op = false; |
|
| 728 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 729 | - $op = false; |
|
| 730 | - } else { |
|
| 731 | - $op = $v[0] ?: $v; |
|
| 732 | - } |
|
| 733 | - } else { |
|
| 734 | - $op = $v; |
|
| 735 | - } |
|
| 736 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 737 | - unset($where[$k]); |
|
| 738 | - $menage = true; |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 743 | - $groupby = array_diff($groupby, ['']); |
|
| 744 | - |
|
| 745 | - // remplacer les sous requetes recursives au calcul |
|
| 746 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 747 | - foreach ($where_sous as $k => $w) { |
|
| 748 | - $menage = true; |
|
| 749 | - // on recupere la sous requete |
|
| 750 | - $sous = match_self($w); |
|
| 751 | - if ($sous[0] == 'SELF') { |
|
| 752 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 753 | - array_push($where_simples, $sous[2]); |
|
| 754 | - $wheresub = [ |
|
| 755 | - $sous[2], |
|
| 756 | - '0=0' |
|
| 757 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 758 | - $jsub = $join; |
|
| 759 | - // trouver les jointures utiles a |
|
| 760 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 761 | - // ie L1.objet='article' |
|
| 762 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 763 | - $i = 0; |
|
| 764 | - do { |
|
| 765 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | - [$sous[1] . ' AS id'], |
|
| 767 | - $from, |
|
| 768 | - $from_type, |
|
| 769 | - $wheresub, |
|
| 770 | - $jsub, |
|
| 771 | - [], |
|
| 772 | - [], |
|
| 773 | - '', |
|
| 774 | - $having, |
|
| 775 | - $table, |
|
| 776 | - $id, |
|
| 777 | - $serveur, |
|
| 778 | - false |
|
| 779 | - ) . ')'); |
|
| 780 | - if (!$i) { |
|
| 781 | - $i = 1; |
|
| 782 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 783 | - foreach ($join as $cle => $wj) { |
|
| 784 | - if ( |
|
| 785 | - (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 786 | - and str_contains($wherestring, (string) "{$cle}.") |
|
| 787 | - ) { |
|
| 788 | - $i = 0; |
|
| 789 | - $wheresub[] = $wj[3]; |
|
| 790 | - unset($jsub[$cle][3]); |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } while ($i++ < 1); |
|
| 795 | - } |
|
| 796 | - if ($sous[0] == 'SUBSELECT') { |
|
| 797 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 798 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 799 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | - $sous[1], # select |
|
| 801 | - $sous[2], #from |
|
| 802 | - [], #from_type |
|
| 803 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 804 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 805 | - [], #join |
|
| 806 | - $sous[4] ?: [], #groupby |
|
| 807 | - $sous[5] ?: [], #orderby |
|
| 808 | - $sous[6], #limit |
|
| 809 | - $sous[7] ?: [], #having |
|
| 810 | - $table, |
|
| 811 | - $id, |
|
| 812 | - $serveur, |
|
| 813 | - false |
|
| 814 | - ) . ')'); |
|
| 815 | - } |
|
| 816 | - array_pop($where_simples); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - foreach ($having as $k => $v) { |
|
| 820 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 821 | - unset($having[$k]); |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - // Installer les jointures. |
|
| 826 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 827 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 828 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 829 | - |
|
| 830 | - $afrom = []; |
|
| 831 | - $equiv = []; |
|
| 832 | - $k = count($join); |
|
| 833 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 834 | - $cle = $cledef; |
|
| 835 | - // le format de join est : |
|
| 836 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 837 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 838 | - if (count($join[$cle]) == 2) { |
|
| 839 | - $join[$cle][] = $join[$cle][1]; |
|
| 840 | - } |
|
| 841 | - if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 842 | - $join[$cle][] = ''; |
|
| 843 | - } |
|
| 844 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 845 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 846 | - // pour compat avec ancienne convention |
|
| 847 | - if (is_numeric($cle)) { |
|
| 848 | - $cle = "L$k"; |
|
| 849 | - } |
|
| 850 | - $cle_where_lie = "JOIN-$cle"; |
|
| 851 | - if ( |
|
| 852 | - !$menage |
|
| 853 | - or isset($afrom[$cle]) |
|
| 854 | - or calculer_jointnul($cle, $select) |
|
| 855 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 856 | - or calculer_jointnul($cle, $having) |
|
| 857 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 858 | - ) { |
|
| 859 | - // corriger les references non explicites dans select |
|
| 860 | - // ou groupby |
|
| 861 | - foreach ($select as $i => $s) { |
|
| 862 | - if ($s == $c) { |
|
| 863 | - $select[$i] = "$cle.$c AS $c"; |
|
| 864 | - break; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - foreach ($groupby as $i => $g) { |
|
| 868 | - if ($g == $c) { |
|
| 869 | - $groupby[$i] = "$cle.$c"; |
|
| 870 | - break; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 874 | - // sans recours a preg_match |
|
| 875 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 876 | - $afrom[$t][$cle] = [ |
|
| 877 | - "\n" . |
|
| 878 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 879 | - $from[$cle], |
|
| 880 | - "AS $cle", |
|
| 881 | - 'ON (', |
|
| 882 | - "$cle.$c", |
|
| 883 | - '=', |
|
| 884 | - "$t.$carr", |
|
| 885 | - ($and ? 'AND ' . $and : '') . |
|
| 886 | - ')' |
|
| 887 | - ]; |
|
| 888 | - if (isset($afrom[$cle])) { |
|
| 889 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 890 | - unset($afrom[$cle]); |
|
| 891 | - } |
|
| 892 | - $equiv[] = $carr; |
|
| 893 | - } else { |
|
| 894 | - unset($join[$cledef]); |
|
| 895 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 896 | - unset($where_simples[$cle_where_lie]); |
|
| 897 | - unset($where[$cle_where_lie]); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - unset($from[$cle]); |
|
| 901 | - $k--; |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - if (count($afrom)) { |
|
| 905 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 906 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 907 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 908 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 909 | - // ou dans |
|
| 910 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 911 | - // qui comporte plusieurs jointures |
|
| 912 | - // ou dans |
|
| 913 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 914 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 915 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 916 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 917 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 918 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 919 | - |
|
| 920 | - $t = key($from); |
|
| 921 | - $c = current($from); |
|
| 922 | - reset($from); |
|
| 923 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | - if ( |
|
| 925 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 926 | - calculer_jointnul($t, $select, $e) or |
|
| 927 | - calculer_jointnul($t, $join, $e) or |
|
| 928 | - calculer_jointnul($t, $where, $e) or |
|
| 929 | - calculer_jointnul($t, $orderby, $e) or |
|
| 930 | - calculer_jointnul($t, $groupby, $e) or |
|
| 931 | - calculer_jointnul($t, $having, $e)) |
|
| 932 | - && count($afrom[$t]) |
|
| 933 | - ) { |
|
| 934 | - $nfrom = reset($afrom[$t]); |
|
| 935 | - $nt = array_key_first($afrom[$t]); |
|
| 936 | - unset($from[$t]); |
|
| 937 | - $from[$nt] = $nfrom[1]; |
|
| 938 | - unset($afrom[$t][$nt]); |
|
| 939 | - $afrom[$nt] = $afrom[$t]; |
|
| 940 | - unset($afrom[$t]); |
|
| 941 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | - $t = $nfrom[4]; |
|
| 943 | - $alias = ''; |
|
| 944 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 945 | - $oldcle = explode('.', $nfrom[6]); |
|
| 946 | - $oldcle = end($oldcle); |
|
| 947 | - $newcle = explode('.', $nfrom[4]); |
|
| 948 | - $newcle = end($newcle); |
|
| 949 | - if ($newcle != $oldcle) { |
|
| 950 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 951 | - // reprendre simplement ce AS |
|
| 952 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 954 | - $alias = ''; |
|
| 955 | - } else { |
|
| 956 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 961 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 962 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 963 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 964 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 965 | - } |
|
| 966 | - $from = reinjecte_joint($afrom, $from); |
|
| 967 | - } |
|
| 968 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 969 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 970 | - $GLOBALS['debug'] = []; |
|
| 971 | - if ($wasdebug) { |
|
| 972 | - $GLOBALS['debug']['debug'] = true; |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 976 | - $r = sql_select( |
|
| 977 | - $select, |
|
| 978 | - $from, |
|
| 979 | - $where, |
|
| 980 | - $groupby, |
|
| 981 | - array_filter($orderby), |
|
| 982 | - $limit, |
|
| 983 | - $having, |
|
| 984 | - $serveur, |
|
| 985 | - $requeter |
|
| 986 | - ); |
|
| 987 | - unset($GLOBALS['debug']['aucasou']); |
|
| 988 | - |
|
| 989 | - return $r; |
|
| 719 | + // retirer les criteres vides: |
|
| 720 | + // {X ?} avec X absent de l'URL |
|
| 721 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 722 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 723 | + $menage = false; |
|
| 724 | + foreach ($where as $k => $v) { |
|
| 725 | + if (is_array($v) and count($v)) { |
|
| 726 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 727 | + $op = false; |
|
| 728 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 729 | + $op = false; |
|
| 730 | + } else { |
|
| 731 | + $op = $v[0] ?: $v; |
|
| 732 | + } |
|
| 733 | + } else { |
|
| 734 | + $op = $v; |
|
| 735 | + } |
|
| 736 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 737 | + unset($where[$k]); |
|
| 738 | + $menage = true; |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 743 | + $groupby = array_diff($groupby, ['']); |
|
| 744 | + |
|
| 745 | + // remplacer les sous requetes recursives au calcul |
|
| 746 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 747 | + foreach ($where_sous as $k => $w) { |
|
| 748 | + $menage = true; |
|
| 749 | + // on recupere la sous requete |
|
| 750 | + $sous = match_self($w); |
|
| 751 | + if ($sous[0] == 'SELF') { |
|
| 752 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 753 | + array_push($where_simples, $sous[2]); |
|
| 754 | + $wheresub = [ |
|
| 755 | + $sous[2], |
|
| 756 | + '0=0' |
|
| 757 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 758 | + $jsub = $join; |
|
| 759 | + // trouver les jointures utiles a |
|
| 760 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 761 | + // ie L1.objet='article' |
|
| 762 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 763 | + $i = 0; |
|
| 764 | + do { |
|
| 765 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | + [$sous[1] . ' AS id'], |
|
| 767 | + $from, |
|
| 768 | + $from_type, |
|
| 769 | + $wheresub, |
|
| 770 | + $jsub, |
|
| 771 | + [], |
|
| 772 | + [], |
|
| 773 | + '', |
|
| 774 | + $having, |
|
| 775 | + $table, |
|
| 776 | + $id, |
|
| 777 | + $serveur, |
|
| 778 | + false |
|
| 779 | + ) . ')'); |
|
| 780 | + if (!$i) { |
|
| 781 | + $i = 1; |
|
| 782 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 783 | + foreach ($join as $cle => $wj) { |
|
| 784 | + if ( |
|
| 785 | + (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 786 | + and str_contains($wherestring, (string) "{$cle}.") |
|
| 787 | + ) { |
|
| 788 | + $i = 0; |
|
| 789 | + $wheresub[] = $wj[3]; |
|
| 790 | + unset($jsub[$cle][3]); |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } while ($i++ < 1); |
|
| 795 | + } |
|
| 796 | + if ($sous[0] == 'SUBSELECT') { |
|
| 797 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 798 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 799 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | + $sous[1], # select |
|
| 801 | + $sous[2], #from |
|
| 802 | + [], #from_type |
|
| 803 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 804 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 805 | + [], #join |
|
| 806 | + $sous[4] ?: [], #groupby |
|
| 807 | + $sous[5] ?: [], #orderby |
|
| 808 | + $sous[6], #limit |
|
| 809 | + $sous[7] ?: [], #having |
|
| 810 | + $table, |
|
| 811 | + $id, |
|
| 812 | + $serveur, |
|
| 813 | + false |
|
| 814 | + ) . ')'); |
|
| 815 | + } |
|
| 816 | + array_pop($where_simples); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + foreach ($having as $k => $v) { |
|
| 820 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 821 | + unset($having[$k]); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + // Installer les jointures. |
|
| 826 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 827 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 828 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 829 | + |
|
| 830 | + $afrom = []; |
|
| 831 | + $equiv = []; |
|
| 832 | + $k = count($join); |
|
| 833 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 834 | + $cle = $cledef; |
|
| 835 | + // le format de join est : |
|
| 836 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 837 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 838 | + if (count($join[$cle]) == 2) { |
|
| 839 | + $join[$cle][] = $join[$cle][1]; |
|
| 840 | + } |
|
| 841 | + if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 842 | + $join[$cle][] = ''; |
|
| 843 | + } |
|
| 844 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 845 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 846 | + // pour compat avec ancienne convention |
|
| 847 | + if (is_numeric($cle)) { |
|
| 848 | + $cle = "L$k"; |
|
| 849 | + } |
|
| 850 | + $cle_where_lie = "JOIN-$cle"; |
|
| 851 | + if ( |
|
| 852 | + !$menage |
|
| 853 | + or isset($afrom[$cle]) |
|
| 854 | + or calculer_jointnul($cle, $select) |
|
| 855 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 856 | + or calculer_jointnul($cle, $having) |
|
| 857 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 858 | + ) { |
|
| 859 | + // corriger les references non explicites dans select |
|
| 860 | + // ou groupby |
|
| 861 | + foreach ($select as $i => $s) { |
|
| 862 | + if ($s == $c) { |
|
| 863 | + $select[$i] = "$cle.$c AS $c"; |
|
| 864 | + break; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + foreach ($groupby as $i => $g) { |
|
| 868 | + if ($g == $c) { |
|
| 869 | + $groupby[$i] = "$cle.$c"; |
|
| 870 | + break; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 874 | + // sans recours a preg_match |
|
| 875 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 876 | + $afrom[$t][$cle] = [ |
|
| 877 | + "\n" . |
|
| 878 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 879 | + $from[$cle], |
|
| 880 | + "AS $cle", |
|
| 881 | + 'ON (', |
|
| 882 | + "$cle.$c", |
|
| 883 | + '=', |
|
| 884 | + "$t.$carr", |
|
| 885 | + ($and ? 'AND ' . $and : '') . |
|
| 886 | + ')' |
|
| 887 | + ]; |
|
| 888 | + if (isset($afrom[$cle])) { |
|
| 889 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 890 | + unset($afrom[$cle]); |
|
| 891 | + } |
|
| 892 | + $equiv[] = $carr; |
|
| 893 | + } else { |
|
| 894 | + unset($join[$cledef]); |
|
| 895 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 896 | + unset($where_simples[$cle_where_lie]); |
|
| 897 | + unset($where[$cle_where_lie]); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + unset($from[$cle]); |
|
| 901 | + $k--; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + if (count($afrom)) { |
|
| 905 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 906 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 907 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 908 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 909 | + // ou dans |
|
| 910 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 911 | + // qui comporte plusieurs jointures |
|
| 912 | + // ou dans |
|
| 913 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 914 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 915 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 916 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 917 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 918 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 919 | + |
|
| 920 | + $t = key($from); |
|
| 921 | + $c = current($from); |
|
| 922 | + reset($from); |
|
| 923 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | + if ( |
|
| 925 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 926 | + calculer_jointnul($t, $select, $e) or |
|
| 927 | + calculer_jointnul($t, $join, $e) or |
|
| 928 | + calculer_jointnul($t, $where, $e) or |
|
| 929 | + calculer_jointnul($t, $orderby, $e) or |
|
| 930 | + calculer_jointnul($t, $groupby, $e) or |
|
| 931 | + calculer_jointnul($t, $having, $e)) |
|
| 932 | + && count($afrom[$t]) |
|
| 933 | + ) { |
|
| 934 | + $nfrom = reset($afrom[$t]); |
|
| 935 | + $nt = array_key_first($afrom[$t]); |
|
| 936 | + unset($from[$t]); |
|
| 937 | + $from[$nt] = $nfrom[1]; |
|
| 938 | + unset($afrom[$t][$nt]); |
|
| 939 | + $afrom[$nt] = $afrom[$t]; |
|
| 940 | + unset($afrom[$t]); |
|
| 941 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | + $t = $nfrom[4]; |
|
| 943 | + $alias = ''; |
|
| 944 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 945 | + $oldcle = explode('.', $nfrom[6]); |
|
| 946 | + $oldcle = end($oldcle); |
|
| 947 | + $newcle = explode('.', $nfrom[4]); |
|
| 948 | + $newcle = end($newcle); |
|
| 949 | + if ($newcle != $oldcle) { |
|
| 950 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 951 | + // reprendre simplement ce AS |
|
| 952 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 954 | + $alias = ''; |
|
| 955 | + } else { |
|
| 956 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 961 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 962 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 963 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 964 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 965 | + } |
|
| 966 | + $from = reinjecte_joint($afrom, $from); |
|
| 967 | + } |
|
| 968 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 969 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 970 | + $GLOBALS['debug'] = []; |
|
| 971 | + if ($wasdebug) { |
|
| 972 | + $GLOBALS['debug']['debug'] = true; |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 976 | + $r = sql_select( |
|
| 977 | + $select, |
|
| 978 | + $from, |
|
| 979 | + $where, |
|
| 980 | + $groupby, |
|
| 981 | + array_filter($orderby), |
|
| 982 | + $limit, |
|
| 983 | + $having, |
|
| 984 | + $serveur, |
|
| 985 | + $requeter |
|
| 986 | + ); |
|
| 987 | + unset($GLOBALS['debug']['aucasou']); |
|
| 988 | + |
|
| 989 | + return $r; |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | /** |
@@ -997,79 +997,79 @@ discard block |
||
| 997 | 997 | * @return string |
| 998 | 998 | */ |
| 999 | 999 | function calculer_where_to_string($v, $join = 'AND') { |
| 1000 | - if (empty($v)) { |
|
| 1001 | - return ''; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - if (!is_array($v)) { |
|
| 1005 | - return $v; |
|
| 1006 | - } else { |
|
| 1007 | - $exp = ''; |
|
| 1008 | - if (strtoupper($join) === 'AND') { |
|
| 1009 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | - } else { |
|
| 1011 | - return $exp . join($join, $v); |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 1000 | + if (empty($v)) { |
|
| 1001 | + return ''; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + if (!is_array($v)) { |
|
| 1005 | + return $v; |
|
| 1006 | + } else { |
|
| 1007 | + $exp = ''; |
|
| 1008 | + if (strtoupper($join) === 'AND') { |
|
| 1009 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | + } else { |
|
| 1011 | + return $exp . join($join, $v); |
|
| 1012 | + } |
|
| 1013 | + } |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | |
| 1017 | 1017 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1018 | 1018 | |
| 1019 | 1019 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1020 | - if (!is_array($exp)) { |
|
| 1021 | - if ($equiv) { |
|
| 1022 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1026 | - } else { |
|
| 1027 | - foreach ($exp as $v) { |
|
| 1028 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1029 | - return true; |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - return false; |
|
| 1034 | - } |
|
| 1020 | + if (!is_array($exp)) { |
|
| 1021 | + if ($equiv) { |
|
| 1022 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1026 | + } else { |
|
| 1027 | + foreach ($exp as $v) { |
|
| 1028 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1029 | + return true; |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + return false; |
|
| 1034 | + } |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | function reinjecte_joint($afrom, $from) { |
| 1038 | - $from_synth = []; |
|
| 1039 | - foreach ($from as $k => $v) { |
|
| 1040 | - $from_synth[$k] = $from[$k]; |
|
| 1041 | - if (isset($afrom[$k])) { |
|
| 1042 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1043 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1044 | - } |
|
| 1045 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1046 | - unset($afrom[$k]); |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - return $from_synth; |
|
| 1038 | + $from_synth = []; |
|
| 1039 | + foreach ($from as $k => $v) { |
|
| 1040 | + $from_synth[$k] = $from[$k]; |
|
| 1041 | + if (isset($afrom[$k])) { |
|
| 1042 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1043 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1044 | + } |
|
| 1045 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1046 | + unset($afrom[$k]); |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + return $from_synth; |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1054 | - if (!is_array($exp)) { |
|
| 1055 | - return preg_replace($equiv, $cle, $exp); |
|
| 1056 | - } else { |
|
| 1057 | - foreach ($exp as $k => $v) { |
|
| 1058 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - return $exp; |
|
| 1062 | - } |
|
| 1054 | + if (!is_array($exp)) { |
|
| 1055 | + return preg_replace($equiv, $cle, $exp); |
|
| 1056 | + } else { |
|
| 1057 | + foreach ($exp as $k => $v) { |
|
| 1058 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + return $exp; |
|
| 1062 | + } |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // calcul du nom du squelette |
| 1066 | 1066 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1067 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1068 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1069 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return $mime_type |
|
| 1073 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1067 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1068 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1069 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return $mime_type |
|
| 1073 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1075 | 1075 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 58 | 58 | |
| 59 | 59 | // si squelette est deja compile et perenne, le charger |
| 60 | 60 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | #} |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 71 | 71 | include_once $lib; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | eval("return true; $f ;"); |
| 96 | 96 | } catch (\ParseError $e) { |
| 97 | 97 | // Code syntaxiquement faux (critere etc mal programme') |
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 98 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 99 | 99 | erreur_squelette($msg, $boucle); |
| 100 | 100 | // continuer pour trouver d'autres fautes eventuelles |
| 101 | 101 | // mais prevenir que c'est mort |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 125 | 125 | // Tracer ce qui vient d'etre compile |
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 127 | 127 | |
| 128 | 128 | // si c'est ce que demande le debusqueur, lui passer la main |
| 129 | 129 | if ( |
@@ -147,13 +147,13 @@ discard block |
||
| 147 | 147 | $code = " |
| 148 | 148 | /* |
| 149 | 149 | * Squelette : $sourcefile |
| 150 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 151 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 152 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 150 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 151 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 152 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 153 | 153 | */ '; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 156 | + $code = '<'."?php\n".$code.join('', $boucles)."\n"; |
|
| 157 | 157 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 158 | 158 | ecrire_fichier($phpfile, $code); |
| 159 | 159 | } |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 216 | 216 | |
| 217 | 217 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 218 | + $headers[$j] .= '|'.$r[3]; |
|
| 219 | 219 | } else { |
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 220 | + $headers[$j] = str_replace(['\\\\', "\\'", '\\"'], ['\\', "'", '"'], $r[3]); |
|
| 221 | 221 | } |
| 222 | 222 | } |
| 223 | 223 | } |
| 224 | 224 | // S'agit-il d'un resultat constant ou contenant du code php |
| 225 | 225 | $process_ins = ( |
| 226 | - strpos($corps, '<' . '?') === false |
|
| 226 | + strpos($corps, '<'.'?') === false |
|
| 227 | 227 | or |
| 228 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 228 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 229 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 230 | 230 | ) |
| 231 | 231 | ? 'html' |
| 232 | 232 | : 'php'; |
@@ -255,10 +255,10 @@ discard block |
||
| 255 | 255 | |
| 256 | 256 | if ($process_ins == 'html') { |
| 257 | 257 | $skel['process_ins'] = ( |
| 258 | - strpos($corps, '<' . '?') === false |
|
| 258 | + strpos($corps, '<'.'?') === false |
|
| 259 | 259 | or |
| 260 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 260 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 261 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 262 | 262 | ) |
| 263 | 263 | ? 'html' |
| 264 | 264 | : 'php'; |
@@ -276,7 +276,7 @@ discard block |
||
| 276 | 276 | // |
| 277 | 277 | |
| 278 | 278 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 279 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 279 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 280 | 280 | include_once("%s"); |
| 281 | 281 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 282 | 282 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | // pas de lien symbolique sous Windows |
| 308 | 308 | and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
| 309 | 309 | ) { |
| 310 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 310 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | $lang = $context_compil[4]; |
@@ -317,7 +317,7 @@ discard block |
||
| 317 | 317 | |
| 318 | 318 | $args = array_map('argumenter_squelette', $args); |
| 319 | 319 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 320 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 320 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 321 | 321 | } |
| 322 | 322 | $args = join(', ', $args); |
| 323 | 323 | |
@@ -351,14 +351,14 @@ discard block |
||
| 351 | 351 | if (is_object($v)) { |
| 352 | 352 | return var_export($v, true); |
| 353 | 353 | } elseif (!is_array($v)) { |
| 354 | - return "'" . texte_script((string) $v) . "'"; |
|
| 354 | + return "'".texte_script((string) $v)."'"; |
|
| 355 | 355 | } else { |
| 356 | 356 | $out = []; |
| 357 | 357 | foreach ($v as $k => $val) { |
| 358 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 358 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - return 'array(' . join(', ', $out) . ')'; |
|
| 361 | + return 'array('.join(', ', $out).')'; |
|
| 362 | 362 | } |
| 363 | 363 | } |
| 364 | 364 | |
@@ -383,7 +383,7 @@ discard block |
||
| 383 | 383 | } |
| 384 | 384 | else { |
| 385 | 385 | $str_args = base64_encode(serialize($args)); |
| 386 | - return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 386 | + return "<?"."php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | |
@@ -461,7 +461,7 @@ discard block |
||
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | // Y a-t-il une fonction de traitement des arguments ? |
| 464 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 464 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 465 | 465 | |
| 466 | 466 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 467 | 467 | |
@@ -471,18 +471,18 @@ discard block |
||
| 471 | 471 | |
| 472 | 472 | // verifier que la fonction dyn est la, |
| 473 | 473 | // sinon se replier sur la generique si elle existe |
| 474 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 474 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 475 | 475 | if ( |
| 476 | 476 | $balise_generique = chercher_balise_generique($nom) |
| 477 | 477 | and $nom_balise_generique = $balise_generique['nom_generique'] |
| 478 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 478 | + and $file = include_spip('balise/'.strtolower($nom_balise_generique)) |
|
| 479 | + and function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 480 | 480 | ) { |
| 481 | 481 | // et lui injecter en premier arg le nom de la balise |
| 482 | 482 | array_unshift($r, $nom); |
| 483 | 483 | $nom_balise = $nom_balise_generique; |
| 484 | 484 | if (!_DIR_RESTREINT) { |
| 485 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 485 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 486 | 486 | } |
| 487 | 487 | } else { |
| 488 | 488 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -583,7 +583,7 @@ discard block |
||
| 583 | 583 | $n = ''; |
| 584 | 584 | foreach (explode(',', $liste) as $val) { |
| 585 | 585 | if ($a = intval($val) and $val === strval($a)) { |
| 586 | - $n .= ',' . $val; |
|
| 586 | + $n .= ','.$val; |
|
| 587 | 587 | } |
| 588 | 588 | } |
| 589 | 589 | if (strlen($n)) { |
@@ -762,8 +762,8 @@ discard block |
||
| 762 | 762 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 763 | 763 | $i = 0; |
| 764 | 764 | do { |
| 765 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | - [$sous[1] . ' AS id'], |
|
| 765 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 766 | + [$sous[1].' AS id'], |
|
| 767 | 767 | $from, |
| 768 | 768 | $from_type, |
| 769 | 769 | $wheresub, |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | $id, |
| 777 | 777 | $serveur, |
| 778 | 778 | false |
| 779 | - ) . ')'); |
|
| 779 | + ).')'); |
|
| 780 | 780 | if (!$i) { |
| 781 | 781 | $i = 1; |
| 782 | 782 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | if ($sous[0] == 'SUBSELECT') { |
| 797 | 797 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 798 | 798 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 799 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 799 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 800 | 800 | $sous[1], # select |
| 801 | 801 | $sous[2], #from |
| 802 | 802 | [], #from_type |
@@ -811,7 +811,7 @@ discard block |
||
| 811 | 811 | $id, |
| 812 | 812 | $serveur, |
| 813 | 813 | false |
| 814 | - ) . ')'); |
|
| 814 | + ).')'); |
|
| 815 | 815 | } |
| 816 | 816 | array_pop($where_simples); |
| 817 | 817 | } |
@@ -874,15 +874,15 @@ discard block |
||
| 874 | 874 | // sans recours a preg_match |
| 875 | 875 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 876 | 876 | $afrom[$t][$cle] = [ |
| 877 | - "\n" . |
|
| 878 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 877 | + "\n". |
|
| 878 | + ($from_type[$cle] ?? 'INNER').' JOIN', |
|
| 879 | 879 | $from[$cle], |
| 880 | 880 | "AS $cle", |
| 881 | 881 | 'ON (', |
| 882 | 882 | "$cle.$c", |
| 883 | 883 | '=', |
| 884 | 884 | "$t.$carr", |
| 885 | - ($and ? 'AND ' . $and : '') . |
|
| 885 | + ($and ? 'AND '.$and : ''). |
|
| 886 | 886 | ')' |
| 887 | 887 | ]; |
| 888 | 888 | if (isset($afrom[$cle])) { |
@@ -920,7 +920,7 @@ discard block |
||
| 920 | 920 | $t = key($from); |
| 921 | 921 | $c = current($from); |
| 922 | 922 | reset($from); |
| 923 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 923 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 924 | 924 | if ( |
| 925 | 925 | !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 926 | 926 | calculer_jointnul($t, $select, $e) or |
@@ -938,7 +938,7 @@ discard block |
||
| 938 | 938 | unset($afrom[$t][$nt]); |
| 939 | 939 | $afrom[$nt] = $afrom[$t]; |
| 940 | 940 | unset($afrom[$t]); |
| 941 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 941 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 942 | 942 | $t = $nfrom[4]; |
| 943 | 943 | $alias = ''; |
| 944 | 944 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -949,14 +949,14 @@ discard block |
||
| 949 | 949 | if ($newcle != $oldcle) { |
| 950 | 950 | // si l'ancienne cle etait deja dans le select avec un AS |
| 951 | 951 | // reprendre simplement ce AS |
| 952 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 952 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 953 | 953 | if (preg_match($as, implode(',', $select), $m)) { |
| 954 | 954 | $alias = ''; |
| 955 | 955 | } else { |
| 956 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 956 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 957 | 957 | } |
| 958 | 958 | } |
| 959 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 959 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 960 | 960 | $join = remplacer_jointnul($t, $join, $e); |
| 961 | 961 | $where = remplacer_jointnul($t, $where, $e); |
| 962 | 962 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1006,9 +1006,9 @@ discard block |
||
| 1006 | 1006 | } else { |
| 1007 | 1007 | $exp = ''; |
| 1008 | 1008 | if (strtoupper($join) === 'AND') { |
| 1009 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1009 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | 1010 | } else { |
| 1011 | - return $exp . join($join, $v); |
|
| 1011 | + return $exp.join($join, $v); |
|
| 1012 | 1012 | } |
| 1013 | 1013 | } |
| 1014 | 1014 | } |
@@ -1070,6 +1070,6 @@ discard block |
||
| 1070 | 1070 | } |
| 1071 | 1071 | |
| 1072 | 1072 | return $mime_type |
| 1073 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1073 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1074 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1075 | 1075 | } |