@@ -90,9 +90,9 @@ discard block |
||
| 90 | 90 | // de connexion, et tout risque d'ambiguite |
| 91 | 91 | if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
| 92 | 92 | $nom_cache_desc_sql[$serveur][$objets_sql] = |
| 93 | - _DIR_CACHE . 'sql_desc_' |
|
| 93 | + _DIR_CACHE.'sql_desc_' |
|
| 94 | 94 | . ($serveur ? "{$serveur}_" : '') |
| 95 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 95 | + . substr(md5($connexion['db'].':'.$connexion['prefixe'].":$objets_sql"), 0, 8) |
|
| 96 | 96 | . '.txt'; |
| 97 | 97 | // nouveau nom de cache = nouvelle version en memoire |
| 98 | 98 | unset($connexion['tables']); |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | if ($connexion['spip_connect_version']) { |
| 121 | 121 | if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
| 122 | 122 | $nom = $GLOBALS['table_des_tables'][$nom]; |
| 123 | - $nom_sql = 'spip_' . $nom; |
|
| 123 | + $nom_sql = 'spip_'.$nom; |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -147,12 +147,12 @@ discard block |
||
| 147 | 147 | // meme si pas d'abreviation declaree, trouver la table spip_$nom |
| 148 | 148 | // si c'est une table principale, |
| 149 | 149 | // puisqu'on le fait aussi pour les tables auxiliaires |
| 150 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 151 | - $nom_sql = 'spip_' . $nom; |
|
| 150 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_'.$nom])) { |
|
| 151 | + $nom_sql = 'spip_'.$nom; |
|
| 152 | 152 | $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
| 153 | 153 | } elseif ( |
| 154 | 154 | isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
| 155 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 155 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_'.$nom]) |
|
| 156 | 156 | ) { |
| 157 | 157 | $nom_sql = $n; |
| 158 | 158 | $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | ) { |
| 169 | 169 | if (!$fdesc) { |
| 170 | 170 | $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
| 171 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 171 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base'.$log_level); |
|
| 172 | 172 | |
| 173 | 173 | return null; |
| 174 | 174 | } |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | $desc['exist'] = true; |
| 181 | 181 | // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
| 182 | 182 | // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
| 183 | - if (! $desc['key']) { |
|
| 183 | + if (!$desc['key']) { |
|
| 184 | 184 | spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
| 185 | 185 | unset($desc['key']); |
| 186 | 186 | } |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | if (!isset($desc['key']) && !empty($fdesc['key'])) { |
| 198 | 198 | $desc['key'] = $fdesc['key']; |
| 199 | 199 | } |
| 200 | - if (! isset($desc['key'])) { |
|
| 200 | + if (!isset($desc['key'])) { |
|
| 201 | 201 | $desc['key'] = []; |
| 202 | 202 | } |
| 203 | 203 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\SQL\Tables |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | include_spip('base/objets'); |
| 22 | 22 | |
@@ -68,154 +68,154 @@ discard block |
||
| 68 | 68 | * |
| 69 | 69 | **/ |
| 70 | 70 | function base_trouver_table_dist($nom, $serveur = '', $table_spip = true, array $options = []) { |
| 71 | - $desc_cache = null; |
|
| 72 | - static $nom_cache_desc_sql = []; |
|
| 73 | - |
|
| 74 | - if ( |
|
| 75 | - !spip_connect($serveur) |
|
| 76 | - or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 77 | - ) { |
|
| 78 | - return null; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $options = $options + [ |
|
| 82 | - // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 83 | - 'log_missing' => true, |
|
| 84 | - ]; |
|
| 85 | - |
|
| 86 | - $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 87 | - $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 88 | - |
|
| 89 | - // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 90 | - // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 91 | - // de connexion, et tout risque d'ambiguite |
|
| 92 | - if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 93 | - $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 94 | - _DIR_CACHE . 'sql_desc_' |
|
| 95 | - . ($serveur ? "{$serveur}_" : '') |
|
| 96 | - . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 97 | - . '.txt'; |
|
| 98 | - // nouveau nom de cache = nouvelle version en memoire |
|
| 99 | - unset($connexion['tables']); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 103 | - if (!$nom) { |
|
| 104 | - spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 105 | - $connexion['tables'] = []; |
|
| 106 | - |
|
| 107 | - return null; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $nom_sql = $nom; |
|
| 111 | - if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 112 | - $nom_sql = $s[1]; |
|
| 113 | - } else { |
|
| 114 | - $nom_sql = $nom; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - $fdesc = $desc = ''; |
|
| 118 | - $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 119 | - |
|
| 120 | - // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 121 | - if ($connexion['spip_connect_version']) { |
|
| 122 | - if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 123 | - $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 124 | - $nom_sql = 'spip_' . $nom; |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - // si c'est la premiere table qu'on cherche |
|
| 129 | - // et si on est pas explicitement en recalcul |
|
| 130 | - // on essaye de recharger le cache des decriptions de ce serveur |
|
| 131 | - // dans le fichier cache |
|
| 132 | - if ( |
|
| 133 | - !isset($connexion['tables'][$nom_sql]) |
|
| 134 | - and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 135 | - and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 136 | - ) { |
|
| 137 | - if ( |
|
| 138 | - lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 139 | - and $desc_cache = unserialize($desc_cache) |
|
| 140 | - ) { |
|
| 141 | - $connexion['tables'] = $desc_cache; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 145 | - if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 146 | - $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 147 | - } |
|
| 148 | - // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 149 | - // si c'est une table principale, |
|
| 150 | - // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 151 | - elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 152 | - $nom_sql = 'spip_' . $nom; |
|
| 153 | - $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 154 | - } elseif ( |
|
| 155 | - isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 156 | - or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 157 | - ) { |
|
| 158 | - $nom_sql = $n; |
|
| 159 | - $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 160 | - } # table locale a cote de SPIP, comme non SPIP: |
|
| 161 | - } |
|
| 162 | - if (!isset($connexion['tables'][$nom_sql])) { |
|
| 163 | - // La *vraie* base a la priorite |
|
| 164 | - $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 165 | - if ( |
|
| 166 | - !$exists |
|
| 167 | - or !$desc = sql_showtable($nom_sql, $table_spip, $serveur) |
|
| 168 | - or !$desc['field'] |
|
| 169 | - ) { |
|
| 170 | - if (!$fdesc) { |
|
| 171 | - $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 172 | - spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 173 | - |
|
| 174 | - return null; |
|
| 175 | - } |
|
| 176 | - // on ne sait pas lire la structure de la table : |
|
| 177 | - // on retombe sur la description donnee dans les fichiers spip |
|
| 178 | - $desc = $fdesc; |
|
| 179 | - $desc['exist'] = false; |
|
| 180 | - } else { |
|
| 181 | - $desc['exist'] = true; |
|
| 182 | - // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 183 | - // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 184 | - if (! $desc['key']) { |
|
| 185 | - spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 186 | - unset($desc['key']); |
|
| 187 | - } |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 191 | - $desc['connexion'] = $serveur; |
|
| 192 | - |
|
| 193 | - // charger les infos declarees pour cette table |
|
| 194 | - // en lui passant les infos connues |
|
| 195 | - // $desc est prioritaire pour la description de la table |
|
| 196 | - $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 197 | - // s'assurer qu'on a toujours un 'key' |
|
| 198 | - if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 199 | - $desc['key'] = $fdesc['key']; |
|
| 200 | - } |
|
| 201 | - if (! isset($desc['key'])) { |
|
| 202 | - $desc['key'] = []; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 206 | - $connexion['tables'][$nom_sql] = $desc; |
|
| 207 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 208 | - // une nouvelle table a ete decrite |
|
| 209 | - // mettons donc a jour le cache des descriptions de ce serveur |
|
| 210 | - if (is_writeable(_DIR_CACHE)) { |
|
| 211 | - ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 212 | - } |
|
| 213 | - } else { |
|
| 214 | - $res = &$connexion['tables'][$nom_sql]; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // toujours retourner $nom dans id_table |
|
| 218 | - $res['id_table'] = $nom; |
|
| 219 | - |
|
| 220 | - return $res; |
|
| 71 | + $desc_cache = null; |
|
| 72 | + static $nom_cache_desc_sql = []; |
|
| 73 | + |
|
| 74 | + if ( |
|
| 75 | + !spip_connect($serveur) |
|
| 76 | + or !preg_match('/^[a-zA-Z0-9._-]*/', $nom) |
|
| 77 | + ) { |
|
| 78 | + return null; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $options = $options + [ |
|
| 82 | + // si false, baissera le niveau de log si une table demandée n’existe pas |
|
| 83 | + 'log_missing' => true, |
|
| 84 | + ]; |
|
| 85 | + |
|
| 86 | + $connexion = &$GLOBALS['connexions'][$serveur ? strtolower($serveur) : 0]; |
|
| 87 | + $objets_sql = lister_tables_objets_sql('::md5'); |
|
| 88 | + |
|
| 89 | + // le nom du cache depend du serveur mais aussi du nom de la db et du prefixe |
|
| 90 | + // ce qui permet une auto invalidation en cas de modif manuelle du fichier |
|
| 91 | + // de connexion, et tout risque d'ambiguite |
|
| 92 | + if (!isset($nom_cache_desc_sql[$serveur][$objets_sql])) { |
|
| 93 | + $nom_cache_desc_sql[$serveur][$objets_sql] = |
|
| 94 | + _DIR_CACHE . 'sql_desc_' |
|
| 95 | + . ($serveur ? "{$serveur}_" : '') |
|
| 96 | + . substr(md5($connexion['db'] . ':' . $connexion['prefixe'] . ":$objets_sql"), 0, 8) |
|
| 97 | + . '.txt'; |
|
| 98 | + // nouveau nom de cache = nouvelle version en memoire |
|
| 99 | + unset($connexion['tables']); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + // un appel avec $nom vide est une demande explicite de vidange du cache des descriptions |
|
| 103 | + if (!$nom) { |
|
| 104 | + spip_unlink($nom_cache_desc_sql[$serveur][$objets_sql]); |
|
| 105 | + $connexion['tables'] = []; |
|
| 106 | + |
|
| 107 | + return null; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $nom_sql = $nom; |
|
| 111 | + if (preg_match('/\.(.*)$/', $nom, $s)) { |
|
| 112 | + $nom_sql = $s[1]; |
|
| 113 | + } else { |
|
| 114 | + $nom_sql = $nom; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + $fdesc = $desc = ''; |
|
| 118 | + $connexion = &$GLOBALS['connexions'][$serveur ?: 0]; |
|
| 119 | + |
|
| 120 | + // base sous SPIP: gerer les abreviations explicites des noms de table |
|
| 121 | + if ($connexion['spip_connect_version']) { |
|
| 122 | + if ($table_spip and isset($GLOBALS['table_des_tables'][$nom])) { |
|
| 123 | + $nom = $GLOBALS['table_des_tables'][$nom]; |
|
| 124 | + $nom_sql = 'spip_' . $nom; |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + // si c'est la premiere table qu'on cherche |
|
| 129 | + // et si on est pas explicitement en recalcul |
|
| 130 | + // on essaye de recharger le cache des decriptions de ce serveur |
|
| 131 | + // dans le fichier cache |
|
| 132 | + if ( |
|
| 133 | + !isset($connexion['tables'][$nom_sql]) |
|
| 134 | + and defined('_VAR_MODE') and _VAR_MODE !== 'recalcul' |
|
| 135 | + and (!isset($connexion['tables']) or !$connexion['tables']) |
|
| 136 | + ) { |
|
| 137 | + if ( |
|
| 138 | + lire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], $desc_cache) |
|
| 139 | + and $desc_cache = unserialize($desc_cache) |
|
| 140 | + ) { |
|
| 141 | + $connexion['tables'] = $desc_cache; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + if ($table_spip and !isset($connexion['tables'][$nom_sql])) { |
|
| 145 | + if (isset($GLOBALS['tables_principales'][$nom_sql])) { |
|
| 146 | + $fdesc = $GLOBALS['tables_principales'][$nom_sql]; |
|
| 147 | + } |
|
| 148 | + // meme si pas d'abreviation declaree, trouver la table spip_$nom |
|
| 149 | + // si c'est une table principale, |
|
| 150 | + // puisqu'on le fait aussi pour les tables auxiliaires |
|
| 151 | + elseif ($nom_sql == $nom and isset($GLOBALS['tables_principales']['spip_' . $nom])) { |
|
| 152 | + $nom_sql = 'spip_' . $nom; |
|
| 153 | + $fdesc = &$GLOBALS['tables_principales'][$nom_sql]; |
|
| 154 | + } elseif ( |
|
| 155 | + isset($GLOBALS['tables_auxiliaires'][$n = $nom]) |
|
| 156 | + or isset($GLOBALS['tables_auxiliaires'][$n = 'spip_' . $nom]) |
|
| 157 | + ) { |
|
| 158 | + $nom_sql = $n; |
|
| 159 | + $fdesc = &$GLOBALS['tables_auxiliaires'][$n]; |
|
| 160 | + } # table locale a cote de SPIP, comme non SPIP: |
|
| 161 | + } |
|
| 162 | + if (!isset($connexion['tables'][$nom_sql])) { |
|
| 163 | + // La *vraie* base a la priorite |
|
| 164 | + $exists = sql_table_exists($nom_sql, $table_spip, $serveur); |
|
| 165 | + if ( |
|
| 166 | + !$exists |
|
| 167 | + or !$desc = sql_showtable($nom_sql, $table_spip, $serveur) |
|
| 168 | + or !$desc['field'] |
|
| 169 | + ) { |
|
| 170 | + if (!$fdesc) { |
|
| 171 | + $log_level = $options['log_missing'] ? _LOG_INFO_IMPORTANTE : _LOG_DEBUG; |
|
| 172 | + spip_log("trouver_table: table inconnue '$serveur' '$nom'", 'base' . $log_level); |
|
| 173 | + |
|
| 174 | + return null; |
|
| 175 | + } |
|
| 176 | + // on ne sait pas lire la structure de la table : |
|
| 177 | + // on retombe sur la description donnee dans les fichiers spip |
|
| 178 | + $desc = $fdesc; |
|
| 179 | + $desc['exist'] = false; |
|
| 180 | + } else { |
|
| 181 | + $desc['exist'] = true; |
|
| 182 | + // gerer le cas des cles vides (echec de l'analyse sur une vue par exemple) |
|
| 183 | + // pour recuperer la declaration de lister_tables_objets_sql() si il y en a une |
|
| 184 | + if (! $desc['key']) { |
|
| 185 | + spip_log("trouver_table: table sans cle '$serveur' '$nom'", 'base'); |
|
| 186 | + unset($desc['key']); |
|
| 187 | + } |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $desc['table'] = $desc['table_sql'] = $nom_sql; |
|
| 191 | + $desc['connexion'] = $serveur; |
|
| 192 | + |
|
| 193 | + // charger les infos declarees pour cette table |
|
| 194 | + // en lui passant les infos connues |
|
| 195 | + // $desc est prioritaire pour la description de la table |
|
| 196 | + $desc = array_merge(lister_tables_objets_sql($nom_sql, $desc), $desc); |
|
| 197 | + // s'assurer qu'on a toujours un 'key' |
|
| 198 | + if (!isset($desc['key']) && !empty($fdesc['key'])) { |
|
| 199 | + $desc['key'] = $fdesc['key']; |
|
| 200 | + } |
|
| 201 | + if (! isset($desc['key'])) { |
|
| 202 | + $desc['key'] = []; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // si tables_objets_sql est bien fini d'init, on peut cacher |
|
| 206 | + $connexion['tables'][$nom_sql] = $desc; |
|
| 207 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 208 | + // une nouvelle table a ete decrite |
|
| 209 | + // mettons donc a jour le cache des descriptions de ce serveur |
|
| 210 | + if (is_writeable(_DIR_CACHE)) { |
|
| 211 | + ecrire_fichier($nom_cache_desc_sql[$serveur][$objets_sql], serialize($connexion['tables']), true); |
|
| 212 | + } |
|
| 213 | + } else { |
|
| 214 | + $res = &$connexion['tables'][$nom_sql]; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // toujours retourner $nom dans id_table |
|
| 218 | + $res['id_table'] = $nom; |
|
| 219 | + |
|
| 220 | + return $res; |
|
| 221 | 221 | } |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ); |
| 107 | 107 | |
| 108 | 108 | // Si l'article est publie, invalider les caches et demander sa reindexation |
| 109 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 109 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article='.intval($id_article)); |
|
| 110 | 110 | $invalideur = $indexation = false; |
| 111 | 111 | if ($t == 'publie') { |
| 112 | 112 | $invalideur = "id='article/$id_article'"; |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | $id_article, |
| 120 | 120 | [ |
| 121 | 121 | 'data' => $set, |
| 122 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 122 | + 'nonvide' => ['titre' => _T('info_nouvel_article').' '._T('info_numero_abbreviation').$id_article], |
|
| 123 | 123 | 'invalideur' => $invalideur, |
| 124 | 124 | 'indexation' => $indexation, |
| 125 | 125 | 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
| 310 | 310 | $statut = $champs['statut'] = $s; |
| 311 | 311 | } else { |
| 312 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 312 | + spip_log("editer_article $id_article refus ".join(' ', $c)); |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | // En cas de publication, fixer la date a "maintenant" |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | isset($c['id_parent']) |
| 335 | 335 | and $id_parent = $c['id_parent'] |
| 336 | 336 | and $id_parent != $id_rubrique |
| 337 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 337 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique='.intval($id_parent))) |
|
| 338 | 338 | ) { |
| 339 | 339 | $champs['id_rubrique'] = $id_parent; |
| 340 | 340 | |
@@ -435,7 +435,7 @@ discard block |
||
| 435 | 435 | // Si on deplace l'article |
| 436 | 436 | // changer aussi son secteur et sa langue (si heritee) |
| 437 | 437 | if (isset($champs['id_rubrique'])) { |
| 438 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 438 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique='.sql_quote($champs['id_rubrique'])); |
|
| 439 | 439 | |
| 440 | 440 | $langue = $row_rub['lang']; |
| 441 | 441 | $champs['id_secteur'] = $row_rub['id_secteur']; |
@@ -443,7 +443,7 @@ discard block |
||
| 443 | 443 | sql_fetsel( |
| 444 | 444 | '1', |
| 445 | 445 | 'spip_articles', |
| 446 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 446 | + 'id_article='.intval($id_article)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue) |
|
| 447 | 447 | ) |
| 448 | 448 | ) { |
| 449 | 449 | $champs['lang'] = $langue; |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | return; |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 457 | + sql_updateq('spip_articles', $champs, 'id_article='.intval($id_article)); |
|
| 458 | 458 | |
| 459 | 459 | // Changer le statut des rubriques concernees |
| 460 | 460 | |
@@ -475,6 +475,6 @@ discard block |
||
| 475 | 475 | foreach ($plus as $n => $t) { |
| 476 | 476 | $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
| 477 | 477 | } |
| 478 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 478 | + set_request('texte', join('', $plus)._request('texte')); |
|
| 479 | 479 | } |
| 480 | 480 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -38,36 +38,36 @@ discard block |
||
| 38 | 38 | * Liste (identifiant de l'article, texte d'erreur éventuel) |
| 39 | 39 | */ |
| 40 | 40 | function action_editer_article_dist($arg = null) { |
| 41 | - include_spip('inc/autoriser'); |
|
| 42 | - $err = ''; |
|
| 43 | - if (is_null($arg)) { |
|
| 44 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 45 | - $arg = $securiser_action(); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // si id_article n'est pas un nombre, c'est une creation |
|
| 49 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 50 | - if (!$id_article = intval($arg)) { |
|
| 51 | - $id_parent = _request('id_parent'); |
|
| 52 | - if (!$id_parent) { |
|
| 53 | - $err = _L("creation interdite d'un article sans rubrique"); |
|
| 54 | - } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 55 | - $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 56 | - } else { |
|
| 57 | - $id_article = article_inserer($id_parent); |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Enregistre l'envoi dans la BD |
|
| 62 | - if ($id_article > 0) { |
|
| 63 | - $err = article_modifier($id_article); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - if ($err) { |
|
| 67 | - spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [$id_article, $err]; |
|
| 41 | + include_spip('inc/autoriser'); |
|
| 42 | + $err = ''; |
|
| 43 | + if (is_null($arg)) { |
|
| 44 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 45 | + $arg = $securiser_action(); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // si id_article n'est pas un nombre, c'est une creation |
|
| 49 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 50 | + if (!$id_article = intval($arg)) { |
|
| 51 | + $id_parent = _request('id_parent'); |
|
| 52 | + if (!$id_parent) { |
|
| 53 | + $err = _L("creation interdite d'un article sans rubrique"); |
|
| 54 | + } elseif (!autoriser('creerarticledans', 'rubrique', $id_parent)) { |
|
| 55 | + $err = _T('info_creerdansrubrique_non_autorise'); |
|
| 56 | + } else { |
|
| 57 | + $id_article = article_inserer($id_parent); |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Enregistre l'envoi dans la BD |
|
| 62 | + if ($id_article > 0) { |
|
| 63 | + $err = article_modifier($id_article); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + if ($err) { |
|
| 67 | + spip_log("echec editeur article: $err", _LOG_ERREUR); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [$id_article, $err]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -89,50 +89,50 @@ discard block |
||
| 89 | 89 | */ |
| 90 | 90 | function article_modifier($id_article, $set = null) { |
| 91 | 91 | |
| 92 | - // unifier $texte en cas de texte trop long |
|
| 93 | - trop_longs_articles(); |
|
| 94 | - |
|
| 95 | - include_spip('inc/modifier'); |
|
| 96 | - include_spip('inc/filtres'); |
|
| 97 | - $c = collecter_requests( |
|
| 98 | - // include list |
|
| 99 | - objet_info('article', 'champs_editables'), |
|
| 100 | - // exclude list |
|
| 101 | - ['date', 'statut', 'id_parent'], |
|
| 102 | - // donnees eventuellement fournies |
|
| 103 | - $set |
|
| 104 | - ); |
|
| 105 | - |
|
| 106 | - // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 107 | - $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 108 | - $invalideur = $indexation = false; |
|
| 109 | - if ($t == 'publie') { |
|
| 110 | - $invalideur = "id='article/$id_article'"; |
|
| 111 | - $indexation = true; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - if ( |
|
| 115 | - $err = objet_modifier_champs( |
|
| 116 | - 'article', |
|
| 117 | - $id_article, |
|
| 118 | - [ |
|
| 119 | - 'data' => $set, |
|
| 120 | - 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 121 | - 'invalideur' => $invalideur, |
|
| 122 | - 'indexation' => $indexation, |
|
| 123 | - 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 124 | - ], |
|
| 125 | - $c |
|
| 126 | - ) |
|
| 127 | - ) { |
|
| 128 | - return $err; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // Modification de statut, changement de rubrique ? |
|
| 132 | - $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 133 | - $err = article_instituer($id_article, $c); |
|
| 134 | - |
|
| 135 | - return $err; |
|
| 92 | + // unifier $texte en cas de texte trop long |
|
| 93 | + trop_longs_articles(); |
|
| 94 | + |
|
| 95 | + include_spip('inc/modifier'); |
|
| 96 | + include_spip('inc/filtres'); |
|
| 97 | + $c = collecter_requests( |
|
| 98 | + // include list |
|
| 99 | + objet_info('article', 'champs_editables'), |
|
| 100 | + // exclude list |
|
| 101 | + ['date', 'statut', 'id_parent'], |
|
| 102 | + // donnees eventuellement fournies |
|
| 103 | + $set |
|
| 104 | + ); |
|
| 105 | + |
|
| 106 | + // Si l'article est publie, invalider les caches et demander sa reindexation |
|
| 107 | + $t = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id_article)); |
|
| 108 | + $invalideur = $indexation = false; |
|
| 109 | + if ($t == 'publie') { |
|
| 110 | + $invalideur = "id='article/$id_article'"; |
|
| 111 | + $indexation = true; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + if ( |
|
| 115 | + $err = objet_modifier_champs( |
|
| 116 | + 'article', |
|
| 117 | + $id_article, |
|
| 118 | + [ |
|
| 119 | + 'data' => $set, |
|
| 120 | + 'nonvide' => ['titre' => _T('info_nouvel_article') . ' ' . _T('info_numero_abbreviation') . $id_article], |
|
| 121 | + 'invalideur' => $invalideur, |
|
| 122 | + 'indexation' => $indexation, |
|
| 123 | + 'date_modif' => 'date_modif' // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 124 | + ], |
|
| 125 | + $c |
|
| 126 | + ) |
|
| 127 | + ) { |
|
| 128 | + return $err; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // Modification de statut, changement de rubrique ? |
|
| 132 | + $c = collecter_requests(['date', 'statut', 'id_parent'], [], $set); |
|
| 133 | + $err = article_instituer($id_article, $c); |
|
| 134 | + |
|
| 135 | + return $err; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -168,120 +168,120 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | function article_inserer($id_rubrique, $set = null) { |
| 170 | 170 | |
| 171 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 172 | - // dans la premiere rubrique racine |
|
| 173 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 174 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 175 | - $id_rubrique = $row['id_rubrique']; |
|
| 176 | - } else { |
|
| 177 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 181 | - // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 182 | - $id_secteur = $row['id_secteur'] ?? 0; |
|
| 183 | - $lang_rub = $row['lang'] ?? ''; |
|
| 184 | - |
|
| 185 | - $lang = ''; |
|
| 186 | - $choisie = 'non'; |
|
| 187 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 188 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 189 | - // ou a defaut celle de la rubrique |
|
| 190 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 191 | - if ( |
|
| 192 | - !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 193 | - 'spip_articles', |
|
| 194 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 195 | - ) |
|
| 196 | - ) { |
|
| 197 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 198 | - if ( |
|
| 199 | - in_array( |
|
| 200 | - $GLOBALS['spip_lang'], |
|
| 201 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 202 | - ) |
|
| 203 | - ) { |
|
| 204 | - $lang = $GLOBALS['spip_lang']; |
|
| 205 | - $choisie = 'oui'; |
|
| 206 | - } |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (!$lang) { |
|
| 210 | - $choisie = 'non'; |
|
| 211 | - $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - $champs = [ |
|
| 215 | - 'id_rubrique' => $id_rubrique, |
|
| 216 | - 'id_secteur' => $id_secteur, |
|
| 217 | - 'statut' => 'prepa', |
|
| 218 | - 'date' => date('Y-m-d H:i:s'), |
|
| 219 | - 'lang' => $lang, |
|
| 220 | - 'langue_choisie' => $choisie |
|
| 221 | - ]; |
|
| 222 | - |
|
| 223 | - if ($set) { |
|
| 224 | - $champs = array_merge($champs, $set); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - // Envoyer aux plugins |
|
| 228 | - $champs = pipeline( |
|
| 229 | - 'pre_insertion', |
|
| 230 | - [ |
|
| 231 | - 'args' => [ |
|
| 232 | - 'table' => 'spip_articles', |
|
| 233 | - ], |
|
| 234 | - 'data' => $champs |
|
| 235 | - ] |
|
| 236 | - ); |
|
| 237 | - |
|
| 238 | - $id_article = sql_insertq('spip_articles', $champs); |
|
| 239 | - |
|
| 240 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 241 | - if ($id_article > 0) { |
|
| 242 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 243 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 244 | - : _request('id_auteur')); |
|
| 245 | - if ($id_auteur) { |
|
| 246 | - include_spip('action/editer_auteur'); |
|
| 247 | - auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 248 | - } |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - pipeline( |
|
| 252 | - 'post_insertion', |
|
| 253 | - [ |
|
| 254 | - 'args' => [ |
|
| 255 | - 'table' => 'spip_articles', |
|
| 256 | - 'id_objet' => $id_article |
|
| 257 | - ], |
|
| 258 | - 'data' => $champs |
|
| 259 | - ] |
|
| 260 | - ); |
|
| 261 | - |
|
| 262 | - // Appeler une notification |
|
| 263 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 264 | - $notifications( |
|
| 265 | - 'article_inserer', |
|
| 266 | - $id_article, |
|
| 267 | - [ |
|
| 268 | - 'id_parent' => $id_rubrique, |
|
| 269 | - 'champs' => $champs, |
|
| 270 | - ] |
|
| 271 | - ); |
|
| 272 | - $notifications( |
|
| 273 | - 'objet_inserer', |
|
| 274 | - $id_article, |
|
| 275 | - [ |
|
| 276 | - 'objet' => 'article', |
|
| 277 | - 'id_objet' => $id_article, |
|
| 278 | - 'id_parent' => $id_rubrique, |
|
| 279 | - 'champs' => $champs, |
|
| 280 | - ] |
|
| 281 | - ); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $id_article; |
|
| 171 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'article |
|
| 172 | + // dans la premiere rubrique racine |
|
| 173 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 174 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 175 | + $id_rubrique = $row['id_rubrique']; |
|
| 176 | + } else { |
|
| 177 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', "id_rubrique=$id_rubrique"); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // eviter $id_secteur = NULL (erreur sqlite) si la requete precedente echoue |
|
| 181 | + // cas de id_rubrique = -1 par exemple avec plugin "pages" |
|
| 182 | + $id_secteur = $row['id_secteur'] ?? 0; |
|
| 183 | + $lang_rub = $row['lang'] ?? ''; |
|
| 184 | + |
|
| 185 | + $lang = ''; |
|
| 186 | + $choisie = 'non'; |
|
| 187 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 188 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 189 | + // ou a defaut celle de la rubrique |
|
| 190 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 191 | + if ( |
|
| 192 | + !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 193 | + 'spip_articles', |
|
| 194 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 195 | + ) |
|
| 196 | + ) { |
|
| 197 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 198 | + if ( |
|
| 199 | + in_array( |
|
| 200 | + $GLOBALS['spip_lang'], |
|
| 201 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 202 | + ) |
|
| 203 | + ) { |
|
| 204 | + $lang = $GLOBALS['spip_lang']; |
|
| 205 | + $choisie = 'oui'; |
|
| 206 | + } |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (!$lang) { |
|
| 210 | + $choisie = 'non'; |
|
| 211 | + $lang = $lang_rub ?: $GLOBALS['meta']['langue_site']; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + $champs = [ |
|
| 215 | + 'id_rubrique' => $id_rubrique, |
|
| 216 | + 'id_secteur' => $id_secteur, |
|
| 217 | + 'statut' => 'prepa', |
|
| 218 | + 'date' => date('Y-m-d H:i:s'), |
|
| 219 | + 'lang' => $lang, |
|
| 220 | + 'langue_choisie' => $choisie |
|
| 221 | + ]; |
|
| 222 | + |
|
| 223 | + if ($set) { |
|
| 224 | + $champs = array_merge($champs, $set); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + // Envoyer aux plugins |
|
| 228 | + $champs = pipeline( |
|
| 229 | + 'pre_insertion', |
|
| 230 | + [ |
|
| 231 | + 'args' => [ |
|
| 232 | + 'table' => 'spip_articles', |
|
| 233 | + ], |
|
| 234 | + 'data' => $champs |
|
| 235 | + ] |
|
| 236 | + ); |
|
| 237 | + |
|
| 238 | + $id_article = sql_insertq('spip_articles', $champs); |
|
| 239 | + |
|
| 240 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 241 | + if ($id_article > 0) { |
|
| 242 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 243 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 244 | + : _request('id_auteur')); |
|
| 245 | + if ($id_auteur) { |
|
| 246 | + include_spip('action/editer_auteur'); |
|
| 247 | + auteur_associer($id_auteur, ['article' => $id_article]); |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + pipeline( |
|
| 252 | + 'post_insertion', |
|
| 253 | + [ |
|
| 254 | + 'args' => [ |
|
| 255 | + 'table' => 'spip_articles', |
|
| 256 | + 'id_objet' => $id_article |
|
| 257 | + ], |
|
| 258 | + 'data' => $champs |
|
| 259 | + ] |
|
| 260 | + ); |
|
| 261 | + |
|
| 262 | + // Appeler une notification |
|
| 263 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 264 | + $notifications( |
|
| 265 | + 'article_inserer', |
|
| 266 | + $id_article, |
|
| 267 | + [ |
|
| 268 | + 'id_parent' => $id_rubrique, |
|
| 269 | + 'champs' => $champs, |
|
| 270 | + ] |
|
| 271 | + ); |
|
| 272 | + $notifications( |
|
| 273 | + 'objet_inserer', |
|
| 274 | + $id_article, |
|
| 275 | + [ |
|
| 276 | + 'objet' => 'article', |
|
| 277 | + 'id_objet' => $id_article, |
|
| 278 | + 'id_parent' => $id_rubrique, |
|
| 279 | + 'champs' => $champs, |
|
| 280 | + ] |
|
| 281 | + ); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $id_article; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -309,153 +309,153 @@ discard block |
||
| 309 | 309 | */ |
| 310 | 310 | function article_instituer($id_article, $c, $calcul_rub = true) { |
| 311 | 311 | |
| 312 | - include_spip('inc/autoriser'); |
|
| 313 | - include_spip('inc/rubriques'); |
|
| 314 | - include_spip('inc/modifier'); |
|
| 315 | - |
|
| 316 | - $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 317 | - $id_rubrique = $row['id_rubrique']; |
|
| 318 | - $statut_ancien = $statut = $row['statut']; |
|
| 319 | - $date_ancienne = $date = $row['date']; |
|
| 320 | - $champs = []; |
|
| 321 | - |
|
| 322 | - $d = $c['date'] ?? null; |
|
| 323 | - $s = $c['statut'] ?? $statut; |
|
| 324 | - |
|
| 325 | - // cf autorisations dans inc/instituer_article |
|
| 326 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 327 | - if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 328 | - $statut = $champs['statut'] = $s; |
|
| 329 | - } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 330 | - $statut = $champs['statut'] = $s; |
|
| 331 | - } else { |
|
| 332 | - spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // En cas de publication, fixer la date a "maintenant" |
|
| 336 | - // sauf si $c commande autre chose |
|
| 337 | - // ou si l'article est deja date dans le futur |
|
| 338 | - // En cas de proposition d'un article (mais pas depublication), idem |
|
| 339 | - if ( |
|
| 340 | - $champs['statut'] == 'publie' |
|
| 341 | - or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 342 | - ) { |
|
| 343 | - if ($d or strtotime($d = $date) > time()) { |
|
| 344 | - $champs['date'] = $date = $d; |
|
| 345 | - } else { |
|
| 346 | - $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Verifier que la rubrique demandee existe et est differente |
|
| 352 | - // de la rubrique actuelle |
|
| 353 | - if ( |
|
| 354 | - isset($c['id_parent']) |
|
| 355 | - and $id_parent = $c['id_parent'] |
|
| 356 | - and $id_parent != $id_rubrique |
|
| 357 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 358 | - ) { |
|
| 359 | - $champs['id_rubrique'] = $id_parent; |
|
| 360 | - |
|
| 361 | - // si l'article etait publie |
|
| 362 | - // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 363 | - // repasser l'article en statut 'propose'. |
|
| 364 | - if ( |
|
| 365 | - $statut == 'publie' |
|
| 366 | - and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 367 | - ) { |
|
| 368 | - $champs['statut'] = 'prop'; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - // Envoyer aux plugins |
|
| 373 | - $champs = pipeline( |
|
| 374 | - 'pre_edition', |
|
| 375 | - [ |
|
| 376 | - 'args' => [ |
|
| 377 | - 'table' => 'spip_articles', |
|
| 378 | - 'id_objet' => $id_article, |
|
| 379 | - 'action' => 'instituer', |
|
| 380 | - 'statut_ancien' => $statut_ancien, |
|
| 381 | - 'date_ancienne' => $date_ancienne, |
|
| 382 | - ], |
|
| 383 | - 'data' => $champs |
|
| 384 | - ] |
|
| 385 | - ); |
|
| 386 | - |
|
| 387 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 388 | - return ''; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - // Envoyer les modifs. |
|
| 392 | - editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 393 | - |
|
| 394 | - // Invalider les caches |
|
| 395 | - include_spip('inc/invalideur'); |
|
| 396 | - suivre_invalideur("id='article/$id_article'"); |
|
| 397 | - |
|
| 398 | - if ($date) { |
|
| 399 | - $t = strtotime($date); |
|
| 400 | - $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 401 | - if ($t > time() and (!$p or ($t < $p))) { |
|
| 402 | - ecrire_meta('date_prochain_postdate', $t); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - // Pipeline |
|
| 407 | - pipeline( |
|
| 408 | - 'post_edition', |
|
| 409 | - [ |
|
| 410 | - 'args' => [ |
|
| 411 | - 'table' => 'spip_articles', |
|
| 412 | - 'id_objet' => $id_article, |
|
| 413 | - 'action' => 'instituer', |
|
| 414 | - 'statut_ancien' => $statut_ancien, |
|
| 415 | - 'date_ancienne' => $date_ancienne, |
|
| 416 | - ], |
|
| 417 | - 'data' => $champs |
|
| 418 | - ] |
|
| 419 | - ); |
|
| 420 | - |
|
| 421 | - // Notifications |
|
| 422 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 423 | - $notifications( |
|
| 424 | - 'article_instituer', |
|
| 425 | - $id_article, |
|
| 426 | - [ |
|
| 427 | - 'statut' => $statut, |
|
| 428 | - 'statut_ancien' => $statut_ancien, |
|
| 429 | - 'date' => $date, |
|
| 430 | - 'date_ancienne' => $date_ancienne, |
|
| 431 | - 'id_parent_ancien' => $id_rubrique, |
|
| 432 | - 'champs' => $champs, |
|
| 433 | - ] |
|
| 434 | - ); |
|
| 435 | - $notifications( |
|
| 436 | - 'objet_instituer', |
|
| 437 | - $id_article, |
|
| 438 | - [ |
|
| 439 | - 'objet' => 'article', |
|
| 440 | - 'id_objet' => $id_article, |
|
| 441 | - 'statut' => $statut, |
|
| 442 | - 'statut_ancien' => $statut_ancien, |
|
| 443 | - 'date' => $date, |
|
| 444 | - 'date_ancienne' => $date_ancienne, |
|
| 445 | - 'id_parent_ancien' => $id_rubrique, |
|
| 446 | - 'champs' => $champs, |
|
| 447 | - ] |
|
| 448 | - ); |
|
| 449 | - |
|
| 450 | - // Rétro-compat |
|
| 451 | - $notifications( |
|
| 452 | - 'instituerarticle', |
|
| 453 | - $id_article, |
|
| 454 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 455 | - ); |
|
| 456 | - } |
|
| 457 | - |
|
| 458 | - return ''; // pas d'erreur |
|
| 312 | + include_spip('inc/autoriser'); |
|
| 313 | + include_spip('inc/rubriques'); |
|
| 314 | + include_spip('inc/modifier'); |
|
| 315 | + |
|
| 316 | + $row = sql_fetsel('statut, date, id_rubrique', 'spip_articles', "id_article=$id_article"); |
|
| 317 | + $id_rubrique = $row['id_rubrique']; |
|
| 318 | + $statut_ancien = $statut = $row['statut']; |
|
| 319 | + $date_ancienne = $date = $row['date']; |
|
| 320 | + $champs = []; |
|
| 321 | + |
|
| 322 | + $d = $c['date'] ?? null; |
|
| 323 | + $s = $c['statut'] ?? $statut; |
|
| 324 | + |
|
| 325 | + // cf autorisations dans inc/instituer_article |
|
| 326 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 327 | + if (autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 328 | + $statut = $champs['statut'] = $s; |
|
| 329 | + } elseif (autoriser('modifier', 'article', $id_article) and $s != 'publie') { |
|
| 330 | + $statut = $champs['statut'] = $s; |
|
| 331 | + } else { |
|
| 332 | + spip_log("editer_article $id_article refus " . join(' ', $c)); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // En cas de publication, fixer la date a "maintenant" |
|
| 336 | + // sauf si $c commande autre chose |
|
| 337 | + // ou si l'article est deja date dans le futur |
|
| 338 | + // En cas de proposition d'un article (mais pas depublication), idem |
|
| 339 | + if ( |
|
| 340 | + $champs['statut'] == 'publie' |
|
| 341 | + or ($champs['statut'] == 'prop' and ($d or !in_array($statut_ancien, ['publie', 'prop']))) |
|
| 342 | + ) { |
|
| 343 | + if ($d or strtotime($d = $date) > time()) { |
|
| 344 | + $champs['date'] = $date = $d; |
|
| 345 | + } else { |
|
| 346 | + $champs['date'] = $date = date('Y-m-d H:i:s'); |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Verifier que la rubrique demandee existe et est differente |
|
| 352 | + // de la rubrique actuelle |
|
| 353 | + if ( |
|
| 354 | + isset($c['id_parent']) |
|
| 355 | + and $id_parent = $c['id_parent'] |
|
| 356 | + and $id_parent != $id_rubrique |
|
| 357 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 358 | + ) { |
|
| 359 | + $champs['id_rubrique'] = $id_parent; |
|
| 360 | + |
|
| 361 | + // si l'article etait publie |
|
| 362 | + // et que le demandeur n'est pas admin de la rubrique de destination |
|
| 363 | + // repasser l'article en statut 'propose'. |
|
| 364 | + if ( |
|
| 365 | + $statut == 'publie' |
|
| 366 | + and !autoriser('publierdans', 'rubrique', $id_parent) |
|
| 367 | + ) { |
|
| 368 | + $champs['statut'] = 'prop'; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + // Envoyer aux plugins |
|
| 373 | + $champs = pipeline( |
|
| 374 | + 'pre_edition', |
|
| 375 | + [ |
|
| 376 | + 'args' => [ |
|
| 377 | + 'table' => 'spip_articles', |
|
| 378 | + 'id_objet' => $id_article, |
|
| 379 | + 'action' => 'instituer', |
|
| 380 | + 'statut_ancien' => $statut_ancien, |
|
| 381 | + 'date_ancienne' => $date_ancienne, |
|
| 382 | + ], |
|
| 383 | + 'data' => $champs |
|
| 384 | + ] |
|
| 385 | + ); |
|
| 386 | + |
|
| 387 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 388 | + return ''; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + // Envoyer les modifs. |
|
| 392 | + editer_article_heritage($id_article, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 393 | + |
|
| 394 | + // Invalider les caches |
|
| 395 | + include_spip('inc/invalideur'); |
|
| 396 | + suivre_invalideur("id='article/$id_article'"); |
|
| 397 | + |
|
| 398 | + if ($date) { |
|
| 399 | + $t = strtotime($date); |
|
| 400 | + $p = @$GLOBALS['meta']['date_prochain_postdate']; |
|
| 401 | + if ($t > time() and (!$p or ($t < $p))) { |
|
| 402 | + ecrire_meta('date_prochain_postdate', $t); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + // Pipeline |
|
| 407 | + pipeline( |
|
| 408 | + 'post_edition', |
|
| 409 | + [ |
|
| 410 | + 'args' => [ |
|
| 411 | + 'table' => 'spip_articles', |
|
| 412 | + 'id_objet' => $id_article, |
|
| 413 | + 'action' => 'instituer', |
|
| 414 | + 'statut_ancien' => $statut_ancien, |
|
| 415 | + 'date_ancienne' => $date_ancienne, |
|
| 416 | + ], |
|
| 417 | + 'data' => $champs |
|
| 418 | + ] |
|
| 419 | + ); |
|
| 420 | + |
|
| 421 | + // Notifications |
|
| 422 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 423 | + $notifications( |
|
| 424 | + 'article_instituer', |
|
| 425 | + $id_article, |
|
| 426 | + [ |
|
| 427 | + 'statut' => $statut, |
|
| 428 | + 'statut_ancien' => $statut_ancien, |
|
| 429 | + 'date' => $date, |
|
| 430 | + 'date_ancienne' => $date_ancienne, |
|
| 431 | + 'id_parent_ancien' => $id_rubrique, |
|
| 432 | + 'champs' => $champs, |
|
| 433 | + ] |
|
| 434 | + ); |
|
| 435 | + $notifications( |
|
| 436 | + 'objet_instituer', |
|
| 437 | + $id_article, |
|
| 438 | + [ |
|
| 439 | + 'objet' => 'article', |
|
| 440 | + 'id_objet' => $id_article, |
|
| 441 | + 'statut' => $statut, |
|
| 442 | + 'statut_ancien' => $statut_ancien, |
|
| 443 | + 'date' => $date, |
|
| 444 | + 'date_ancienne' => $date_ancienne, |
|
| 445 | + 'id_parent_ancien' => $id_rubrique, |
|
| 446 | + 'champs' => $champs, |
|
| 447 | + ] |
|
| 448 | + ); |
|
| 449 | + |
|
| 450 | + // Rétro-compat |
|
| 451 | + $notifications( |
|
| 452 | + 'instituerarticle', |
|
| 453 | + $id_article, |
|
| 454 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 455 | + ); |
|
| 456 | + } |
|
| 457 | + |
|
| 458 | + return ''; // pas d'erreur |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -480,37 +480,37 @@ discard block |
||
| 480 | 480 | */ |
| 481 | 481 | function editer_article_heritage($id_article, $id_rubrique, $statut, $champs, $cond = true) { |
| 482 | 482 | |
| 483 | - // Si on deplace l'article |
|
| 484 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 485 | - if (isset($champs['id_rubrique'])) { |
|
| 486 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 487 | - |
|
| 488 | - $langue = $row_rub['lang']; |
|
| 489 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 490 | - if ( |
|
| 491 | - sql_fetsel( |
|
| 492 | - '1', |
|
| 493 | - 'spip_articles', |
|
| 494 | - 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 495 | - ) |
|
| 496 | - ) { |
|
| 497 | - $champs['lang'] = $langue; |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - if (!$champs) { |
|
| 502 | - return; |
|
| 503 | - } |
|
| 504 | - |
|
| 505 | - sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 506 | - |
|
| 507 | - // Changer le statut des rubriques concernees |
|
| 508 | - |
|
| 509 | - if ($cond) { |
|
| 510 | - include_spip('inc/rubriques'); |
|
| 511 | - $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 512 | - calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 513 | - } |
|
| 483 | + // Si on deplace l'article |
|
| 484 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 485 | + if (isset($champs['id_rubrique'])) { |
|
| 486 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 487 | + |
|
| 488 | + $langue = $row_rub['lang']; |
|
| 489 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 490 | + if ( |
|
| 491 | + sql_fetsel( |
|
| 492 | + '1', |
|
| 493 | + 'spip_articles', |
|
| 494 | + 'id_article=' . intval($id_article) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 495 | + ) |
|
| 496 | + ) { |
|
| 497 | + $champs['lang'] = $langue; |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + if (!$champs) { |
|
| 502 | + return; |
|
| 503 | + } |
|
| 504 | + |
|
| 505 | + sql_updateq('spip_articles', $champs, 'id_article=' . intval($id_article)); |
|
| 506 | + |
|
| 507 | + // Changer le statut des rubriques concernees |
|
| 508 | + |
|
| 509 | + if ($cond) { |
|
| 510 | + include_spip('inc/rubriques'); |
|
| 511 | + $postdate = ($GLOBALS['meta']['post_dates'] == 'non' and isset($champs['date']) and (strtotime($champs['date']) < time())) ? $champs['date'] : false; |
|
| 512 | + calculer_rubriques_if($id_rubrique, $champs, ['statut_ancien' => $statut], $postdate); |
|
| 513 | + } |
|
| 514 | 514 | } |
| 515 | 515 | |
| 516 | 516 | /** |
@@ -519,10 +519,10 @@ discard block |
||
| 519 | 519 | * @return void |
| 520 | 520 | */ |
| 521 | 521 | function trop_longs_articles() { |
| 522 | - if (is_array($plus = _request('texte_plus'))) { |
|
| 523 | - foreach ($plus as $n => $t) { |
|
| 524 | - $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 525 | - } |
|
| 526 | - set_request('texte', join('', $plus) . _request('texte')); |
|
| 527 | - } |
|
| 522 | + if (is_array($plus = _request('texte_plus'))) { |
|
| 523 | + foreach ($plus as $n => $t) { |
|
| 524 | + $plus[$n] = preg_replace(",<!--SPIP-->[\n\r]*,", '', $t); |
|
| 525 | + } |
|
| 526 | + set_request('texte', join('', $plus) . _request('texte')); |
|
| 527 | + } |
|
| 528 | 528 | } |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
| 69 | 69 | |
| 70 | 70 | // Si l'utilisateur figure deja dans la base, y recuperer les infos |
| 71 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + $r = sql_fetsel('*', 'spip_auteurs', 'login='.sql_quote($login)." AND source='ldap'", '', '', '', '', $serveur); |
|
| 72 | 72 | |
| 73 | 73 | if ($r) { |
| 74 | 74 | return array_merge($r, $credentials_ldap); |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | if ($r) { |
| 93 | 93 | return array_merge( |
| 94 | 94 | $credentials_ldap, |
| 95 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 95 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur='.intval($r), '', '', '', '', $serveur) |
|
| 96 | 96 | ); |
| 97 | 97 | } |
| 98 | 98 | |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | $connexion = spip_connect($serveur); |
| 122 | 122 | if (!is_array($connexion['ldap'])) { |
| 123 | 123 | if ($connexion['authentification']['ldap']) { |
| 124 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | + $f = _DIR_CONNECT.$connexion['authentification']['ldap']; |
|
| 125 | 125 | unset($GLOBALS['ldap_link']); |
| 126 | 126 | if (is_readable($f)) { |
| 127 | 127 | include_once($f); |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
| 335 | 335 | return false; |
| 336 | 336 | } |
| 337 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 337 | + $encoded_pass = '{MD5}'.base64_encode(pack('H*', md5($new_pass))); |
|
| 338 | 338 | $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
| 339 | 339 | |
| 340 | 340 | return $success; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | // Authentifie via LDAP et retourne la ligne SQL decrivant l'utilisateur si ok |
@@ -24,12 +24,12 @@ discard block |
||
| 24 | 24 | // Attributs LDAP correspondants a ceux de SPIP, notamment pour le login |
| 25 | 25 | // ne pas ecraser une definition perso dans mes_options |
| 26 | 26 | if (!isset($GLOBALS['ldap_attributes']) or !is_array($GLOBALS['ldap_attributes'])) { |
| 27 | - $GLOBALS['ldap_attributes'] = [ |
|
| 28 | - 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | - 'nom' => 'cn', |
|
| 30 | - 'email' => 'mail', |
|
| 31 | - 'bio' => 'description' |
|
| 32 | - ]; |
|
| 27 | + $GLOBALS['ldap_attributes'] = [ |
|
| 28 | + 'login' => ['sAMAccountName', 'uid', 'login', 'userid', 'cn', 'sn'], |
|
| 29 | + 'nom' => 'cn', |
|
| 30 | + 'email' => 'mail', |
|
| 31 | + 'bio' => 'description' |
|
| 32 | + ]; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,50 +55,50 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function auth_ldap_dist($login, #[\SensitiveParameter] $pass, $serveur = '', $phpauth = false) { |
| 57 | 57 | |
| 58 | - #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | - |
|
| 60 | - // Utilisateur connu ? |
|
| 61 | - // si http auth, inutile de reauthentifier: cela |
|
| 62 | - // ne marchera pas avec auth http autre que basic. |
|
| 63 | - $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 64 | - if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | - return []; |
|
| 66 | - } |
|
| 67 | - $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | - |
|
| 69 | - // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | - $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | - |
|
| 72 | - if ($r) { |
|
| 73 | - return array_merge($r, $credentials_ldap); |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // sinon importer les infos depuis LDAP, |
|
| 77 | - |
|
| 78 | - if ( |
|
| 79 | - $GLOBALS['meta']['ldap_statut_import'] |
|
| 80 | - and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 81 | - ) { |
|
| 82 | - // rajouter le statut indique a l'install |
|
| 83 | - $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 84 | - $desc['login'] = $login; |
|
| 85 | - $desc['source'] = 'ldap'; |
|
| 86 | - $desc['pass'] = ''; |
|
| 87 | - |
|
| 88 | - $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - if ($r) { |
|
| 92 | - return array_merge( |
|
| 93 | - $credentials_ldap, |
|
| 94 | - sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 95 | - ); |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - // sinon echec |
|
| 99 | - spip_log("Creation de l'auteur '$login' impossible"); |
|
| 100 | - |
|
| 101 | - return []; |
|
| 58 | + #spip_log("ldap $login " . ($pass ? "mdp fourni" : "mdp absent")); |
|
| 59 | + |
|
| 60 | + // Utilisateur connu ? |
|
| 61 | + // si http auth, inutile de reauthentifier: cela |
|
| 62 | + // ne marchera pas avec auth http autre que basic. |
|
| 63 | + $checkpass = isset($_SERVER['REMOTE_USER']) ? false : true; |
|
| 64 | + if (!($dn = auth_ldap_search($login, $pass, $checkpass, $serveur))) { |
|
| 65 | + return []; |
|
| 66 | + } |
|
| 67 | + $credentials_ldap = ['ldap_dn' => $dn, 'ldap_password' => $pass]; |
|
| 68 | + |
|
| 69 | + // Si l'utilisateur figure deja dans la base, y recuperer les infos |
|
| 70 | + $r = sql_fetsel('*', 'spip_auteurs', 'login=' . sql_quote($login) . " AND source='ldap'", '', '', '', '', $serveur); |
|
| 71 | + |
|
| 72 | + if ($r) { |
|
| 73 | + return array_merge($r, $credentials_ldap); |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // sinon importer les infos depuis LDAP, |
|
| 77 | + |
|
| 78 | + if ( |
|
| 79 | + $GLOBALS['meta']['ldap_statut_import'] |
|
| 80 | + and $desc = auth_ldap_retrouver($dn, [], $serveur) |
|
| 81 | + ) { |
|
| 82 | + // rajouter le statut indique a l'install |
|
| 83 | + $desc['statut'] = $GLOBALS['meta']['ldap_statut_import']; |
|
| 84 | + $desc['login'] = $login; |
|
| 85 | + $desc['source'] = 'ldap'; |
|
| 86 | + $desc['pass'] = ''; |
|
| 87 | + |
|
| 88 | + $r = sql_insertq('spip_auteurs', $desc, [], $serveur); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + if ($r) { |
|
| 92 | + return array_merge( |
|
| 93 | + $credentials_ldap, |
|
| 94 | + sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . intval($r), '', '', '', '', $serveur) |
|
| 95 | + ); |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + // sinon echec |
|
| 99 | + spip_log("Creation de l'auteur '$login' impossible"); |
|
| 100 | + |
|
| 101 | + return []; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -112,36 +112,36 @@ discard block |
||
| 112 | 112 | * @return array |
| 113 | 113 | */ |
| 114 | 114 | function auth_ldap_connect($serveur = '') { |
| 115 | - include_spip('base/connect_sql'); |
|
| 116 | - static $connexions_ldap = []; |
|
| 117 | - if (isset($connexions_ldap[$serveur])) { |
|
| 118 | - return $connexions_ldap[$serveur]; |
|
| 119 | - } |
|
| 120 | - $connexion = spip_connect($serveur); |
|
| 121 | - if (!is_array($connexion['ldap'])) { |
|
| 122 | - if ($connexion['authentification']['ldap']) { |
|
| 123 | - $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | - unset($GLOBALS['ldap_link']); |
|
| 125 | - if (is_readable($f)) { |
|
| 126 | - include_once($f); |
|
| 127 | - }; |
|
| 128 | - if (isset($GLOBALS['ldap_link'])) { |
|
| 129 | - $connexion['ldap'] = [ |
|
| 130 | - 'link' => $GLOBALS['ldap_link'], |
|
| 131 | - 'base' => $GLOBALS['ldap_base'] |
|
| 132 | - ]; |
|
| 133 | - } else { |
|
| 134 | - spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 135 | - } |
|
| 136 | - if (isset($GLOBALS['ldap_champs'])) { |
|
| 137 | - $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 138 | - } |
|
| 139 | - } else { |
|
| 140 | - spip_log("connection LDAP $serveur inconnue"); |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 115 | + include_spip('base/connect_sql'); |
|
| 116 | + static $connexions_ldap = []; |
|
| 117 | + if (isset($connexions_ldap[$serveur])) { |
|
| 118 | + return $connexions_ldap[$serveur]; |
|
| 119 | + } |
|
| 120 | + $connexion = spip_connect($serveur); |
|
| 121 | + if (!is_array($connexion['ldap'])) { |
|
| 122 | + if ($connexion['authentification']['ldap']) { |
|
| 123 | + $f = _DIR_CONNECT . $connexion['authentification']['ldap']; |
|
| 124 | + unset($GLOBALS['ldap_link']); |
|
| 125 | + if (is_readable($f)) { |
|
| 126 | + include_once($f); |
|
| 127 | + }; |
|
| 128 | + if (isset($GLOBALS['ldap_link'])) { |
|
| 129 | + $connexion['ldap'] = [ |
|
| 130 | + 'link' => $GLOBALS['ldap_link'], |
|
| 131 | + 'base' => $GLOBALS['ldap_base'] |
|
| 132 | + ]; |
|
| 133 | + } else { |
|
| 134 | + spip_log("connection LDAP $serveur mal definie dans $f"); |
|
| 135 | + } |
|
| 136 | + if (isset($GLOBALS['ldap_champs'])) { |
|
| 137 | + $connexion['ldap']['attributes'] = $GLOBALS['ldap_champs']; |
|
| 138 | + } |
|
| 139 | + } else { |
|
| 140 | + spip_log("connection LDAP $serveur inconnue"); |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + return $connexions_ldap[$serveur] = $connexion['ldap']; |
|
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | /** |
@@ -155,52 +155,52 @@ discard block |
||
| 155 | 155 | * Le login trouvé ou chaine vide si non trouvé |
| 156 | 156 | */ |
| 157 | 157 | function auth_ldap_search($login, #[\SensitiveParameter] $pass, $checkpass = true, $serveur = '') { |
| 158 | - // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 159 | - $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 160 | - if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 161 | - return ''; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - // verifier la connexion |
|
| 165 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 166 | - return ''; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $ldap_link = $ldap['link'] ?? null; |
|
| 170 | - $ldap_base = $ldap['base'] ?? null; |
|
| 171 | - $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 172 | - |
|
| 173 | - $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 174 | - |
|
| 175 | - // Tenter une recherche pour essayer de retrouver le DN |
|
| 176 | - foreach ($logins as $att) { |
|
| 177 | - $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 178 | - $info = @ldap_get_entries($ldap_link, $result); |
|
| 179 | - // Ne pas accepter les resultats si plus d'une entree |
|
| 180 | - // (on veut un attribut unique) |
|
| 181 | - |
|
| 182 | - if (is_array($info) and $info['count'] == 1) { |
|
| 183 | - $dn = $info[0]['dn']; |
|
| 184 | - if (!$checkpass) { |
|
| 185 | - return $dn; |
|
| 186 | - } |
|
| 187 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 188 | - return $dn; |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if ($checkpass and !isset($dn)) { |
|
| 194 | - // Si echec, essayer de deviner le DN |
|
| 195 | - foreach ($logins as $att) { |
|
| 196 | - $dn = "$att=$login_search, $ldap_base"; |
|
| 197 | - if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 198 | - return "$att=$login_search, $ldap_base"; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return ''; |
|
| 158 | + // Securite anti-injection et contre un serveur LDAP laxiste |
|
| 159 | + $login_search = preg_replace('/[^-@._\s\d\w]/', '', $login); |
|
| 160 | + if (!strlen($login_search) or ($checkpass and !strlen($pass))) { |
|
| 161 | + return ''; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + // verifier la connexion |
|
| 165 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 166 | + return ''; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $ldap_link = $ldap['link'] ?? null; |
|
| 170 | + $ldap_base = $ldap['base'] ?? null; |
|
| 171 | + $desc = !empty($ldap['attributes']) ? $ldap['attributes'] : $GLOBALS['ldap_attributes']; |
|
| 172 | + |
|
| 173 | + $logins = is_array($desc['login']) ? $desc['login'] : [$desc['login']]; |
|
| 174 | + |
|
| 175 | + // Tenter une recherche pour essayer de retrouver le DN |
|
| 176 | + foreach ($logins as $att) { |
|
| 177 | + $result = @ldap_search($ldap_link, $ldap_base, "$att=$login_search", ['dn']); |
|
| 178 | + $info = @ldap_get_entries($ldap_link, $result); |
|
| 179 | + // Ne pas accepter les resultats si plus d'une entree |
|
| 180 | + // (on veut un attribut unique) |
|
| 181 | + |
|
| 182 | + if (is_array($info) and $info['count'] == 1) { |
|
| 183 | + $dn = $info[0]['dn']; |
|
| 184 | + if (!$checkpass) { |
|
| 185 | + return $dn; |
|
| 186 | + } |
|
| 187 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 188 | + return $dn; |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if ($checkpass and !isset($dn)) { |
|
| 194 | + // Si echec, essayer de deviner le DN |
|
| 195 | + foreach ($logins as $att) { |
|
| 196 | + $dn = "$att=$login_search, $ldap_base"; |
|
| 197 | + if (@ldap_bind($ldap_link, $dn, $pass)) { |
|
| 198 | + return "$att=$login_search, $ldap_base"; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return ''; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -212,40 +212,40 @@ discard block |
||
| 212 | 212 | * @return array |
| 213 | 213 | */ |
| 214 | 214 | function auth_ldap_retrouver($dn, $desc = [], $serveur = '') { |
| 215 | - // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 215 | + // Lire les infos sur l'utilisateur a partir de son DN depuis LDAP |
|
| 216 | 216 | |
| 217 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 218 | - spip_log("ldap $serveur injoignable"); |
|
| 217 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 218 | + spip_log("ldap $serveur injoignable"); |
|
| 219 | 219 | |
| 220 | - return []; |
|
| 221 | - } |
|
| 220 | + return []; |
|
| 221 | + } |
|
| 222 | 222 | |
| 223 | - $ldap_link = $ldap['link']; |
|
| 224 | - if (!$desc) { |
|
| 225 | - $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 226 | - unset($desc['login']); |
|
| 227 | - } |
|
| 228 | - $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 223 | + $ldap_link = $ldap['link']; |
|
| 224 | + if (!$desc) { |
|
| 225 | + $desc = $ldap['attributes'] ?: $GLOBALS['ldap_attributes']; |
|
| 226 | + unset($desc['login']); |
|
| 227 | + } |
|
| 228 | + $result = @ldap_read($ldap_link, $dn, 'objectClass=*', array_values($desc)); |
|
| 229 | 229 | |
| 230 | - if (!$result) { |
|
| 231 | - return []; |
|
| 232 | - } |
|
| 230 | + if (!$result) { |
|
| 231 | + return []; |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | - // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 235 | - $val = @ldap_get_entries($ldap_link, $result); |
|
| 236 | - if (!is_array($val) or !is_array($val[0])) { |
|
| 237 | - return []; |
|
| 238 | - } |
|
| 239 | - $val = $val[0]; |
|
| 234 | + // Recuperer les donnees du premier (unique?) compte de l'auteur |
|
| 235 | + $val = @ldap_get_entries($ldap_link, $result); |
|
| 236 | + if (!is_array($val) or !is_array($val[0])) { |
|
| 237 | + return []; |
|
| 238 | + } |
|
| 239 | + $val = $val[0]; |
|
| 240 | 240 | |
| 241 | - // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 242 | - include_spip('inc/charsets'); |
|
| 241 | + // Convertir depuis UTF-8 (jeu de caracteres par defaut) |
|
| 242 | + include_spip('inc/charsets'); |
|
| 243 | 243 | |
| 244 | - foreach ($desc as $k => $v) { |
|
| 245 | - $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 246 | - } |
|
| 244 | + foreach ($desc as $k => $v) { |
|
| 245 | + $desc[$k] = importer_charset($val[strtolower($v)][0], 'utf-8'); |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - return $desc; |
|
| 248 | + return $desc; |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | 259 | function auth_ldap_retrouver_login($login, $serveur = '') { |
| 260 | - return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 260 | + return auth_ldap_search($login, '', false, $serveur) ? $login : ''; |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -277,9 +277,9 @@ discard block |
||
| 277 | 277 | * Message d'erreur si login non valide, chaîne vide sinon |
| 278 | 278 | */ |
| 279 | 279 | function auth_ldap_verifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur = 0, $serveur = '') { |
| 280 | - include_spip('auth/spip'); |
|
| 280 | + include_spip('auth/spip'); |
|
| 281 | 281 | |
| 282 | - return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 282 | + return auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur); |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | /** |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | * ``` |
| 301 | 301 | */ |
| 302 | 302 | function auth_ldap_autoriser_modifier_pass($serveur = '') { |
| 303 | - return true; |
|
| 303 | + return true; |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | /** |
@@ -318,23 +318,23 @@ discard block |
||
| 318 | 318 | * Informe du succès ou de l'echec du changement du mot de passe |
| 319 | 319 | */ |
| 320 | 320 | function auth_ldap_modifier_pass($login, #[\SensitiveParameter] $new_pass, $id_auteur, $serveur = '') { |
| 321 | - if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 327 | - $link = $ldap['link']; |
|
| 328 | - include_spip('inc/session'); |
|
| 329 | - $dn = session_get('ldap_dn'); |
|
| 330 | - if ('' == $dn) { |
|
| 331 | - return false; |
|
| 332 | - } |
|
| 333 | - if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 334 | - return false; |
|
| 335 | - } |
|
| 336 | - $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 337 | - $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 338 | - |
|
| 339 | - return $success; |
|
| 321 | + if (is_null($new_pass) or auth_ldap_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + if (!$ldap = auth_ldap_connect($serveur)) { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | + $link = $ldap['link']; |
|
| 328 | + include_spip('inc/session'); |
|
| 329 | + $dn = session_get('ldap_dn'); |
|
| 330 | + if ('' == $dn) { |
|
| 331 | + return false; |
|
| 332 | + } |
|
| 333 | + if (!ldap_bind($link, $dn, session_get('ldap_password'))) { |
|
| 334 | + return false; |
|
| 335 | + } |
|
| 336 | + $encoded_pass = '{MD5}' . base64_encode(pack('H*', md5($new_pass))); |
|
| 337 | + $success = ldap_mod_replace($link, $dn, ['userPassword' => $encoded_pass]); |
|
| 338 | + |
|
| 339 | + return $success; |
|
| 340 | 340 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
@@ -21,28 +21,28 @@ discard block |
||
| 21 | 21 | * @param array $arbre |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_pipelines_dist(&$arbre) { |
| 24 | - $pipes = null; |
|
| 25 | - $tag = null; |
|
| 26 | - $pipeline = []; |
|
| 27 | - if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | - foreach ($pipes as $tag => $p) { |
|
| 29 | - if (!is_array($p[0])) { |
|
| 30 | - [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | - $pipeline[] = $att; |
|
| 32 | - } else { |
|
| 33 | - foreach ($p as $pipe) { |
|
| 34 | - $att = []; |
|
| 35 | - if (is_array($pipe)) { |
|
| 36 | - foreach ($pipe as $k => $t) { |
|
| 37 | - $att[$k] = trim(end($t)); |
|
| 38 | - } |
|
| 39 | - } |
|
| 40 | - $pipeline[] = $att; |
|
| 41 | - } |
|
| 42 | - } |
|
| 43 | - } |
|
| 44 | - unset($arbre[$tag]); |
|
| 45 | - } |
|
| 24 | + $pipes = null; |
|
| 25 | + $tag = null; |
|
| 26 | + $pipeline = []; |
|
| 27 | + if (spip_xml_match_nodes(',^pipeline,', $arbre, $pipes)) { |
|
| 28 | + foreach ($pipes as $tag => $p) { |
|
| 29 | + if (!is_array($p[0])) { |
|
| 30 | + [$tag, $att] = spip_xml_decompose_tag($tag); |
|
| 31 | + $pipeline[] = $att; |
|
| 32 | + } else { |
|
| 33 | + foreach ($p as $pipe) { |
|
| 34 | + $att = []; |
|
| 35 | + if (is_array($pipe)) { |
|
| 36 | + foreach ($pipe as $k => $t) { |
|
| 37 | + $att[$k] = trim(end($t)); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + $pipeline[] = $att; |
|
| 41 | + } |
|
| 42 | + } |
|
| 43 | + } |
|
| 44 | + unset($arbre[$tag]); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - return $pipeline; |
|
| 47 | + return $pipeline; |
|
| 48 | 48 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | $champs['source'] = $source ?: 'spip'; |
| 94 | 94 | |
| 95 | 95 | $champs['login'] = ''; |
| 96 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 96 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 97 | 97 | $champs['webmestre'] = 'non'; |
| 98 | 98 | if (empty($champs['imessage'])) { |
| 99 | 99 | $champs['imessage'] = 'oui'; |
@@ -313,7 +313,7 @@ discard block |
||
| 313 | 313 | $champs['pass'] = $c['pass']; |
| 314 | 314 | } |
| 315 | 315 | |
| 316 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 316 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 317 | 317 | |
| 318 | 318 | if ( |
| 319 | 319 | isset($c['statut']) |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | // commencer par traiter les cas particuliers des logins et pass |
| 374 | 374 | // avant les autres ecritures en base |
| 375 | 375 | if (isset($champs['login']) or isset($champs['pass'])) { |
| 376 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 376 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 377 | 377 | include_spip('inc/auth'); |
| 378 | 378 | if (isset($champs['login']) and strlen($champs['login'])) { |
| 379 | 379 | if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
@@ -381,7 +381,7 @@ discard block |
||
| 381 | 381 | } |
| 382 | 382 | } |
| 383 | 383 | if (isset($champs['pass']) and strlen($champs['pass'])) { |
| 384 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 384 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur)); |
|
| 385 | 385 | if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
| 386 | 386 | $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
| 387 | 387 | } |
@@ -394,7 +394,7 @@ discard block |
||
| 394 | 394 | if (!(is_countable($champs) ? count($champs) : 0)) { |
| 395 | 395 | return implode(' ', array_map('_T', $erreurs)); |
| 396 | 396 | } |
| 397 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 397 | + sql_updateq('spip_auteurs', $champs, 'id_auteur='.$id_auteur); |
|
| 398 | 398 | |
| 399 | 399 | // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
| 400 | 400 | if ( |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -36,41 +36,41 @@ discard block |
||
| 36 | 36 | */ |
| 37 | 37 | function action_editer_auteur_dist($arg = null) { |
| 38 | 38 | |
| 39 | - if (is_null($arg)) { |
|
| 40 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 41 | - $arg = $securiser_action(); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - |
|
| 45 | - // si id_auteur n'est pas un nombre, c'est une creation |
|
| 46 | - if (!$id_auteur = intval($arg)) { |
|
| 47 | - if (($id_auteur = auteur_inserer()) > 0) { |
|
| 48 | - # cf. GROS HACK |
|
| 49 | - # recuperer l'eventuel logo charge avant la creation |
|
| 50 | - # ils ont un id = 0-id_auteur de la session |
|
| 51 | - $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 52 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 53 | - foreach (['on', 'off'] as $type) { |
|
| 54 | - if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 55 | - if ($logo = reset($logo)) { |
|
| 56 | - rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // Enregistre l'envoi dans la BD |
|
| 64 | - $err = ''; |
|
| 65 | - if ($id_auteur > 0) { |
|
| 66 | - $err = auteur_modifier($id_auteur); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if ($err) { |
|
| 70 | - spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return [$id_auteur, $err]; |
|
| 39 | + if (is_null($arg)) { |
|
| 40 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 41 | + $arg = $securiser_action(); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + |
|
| 45 | + // si id_auteur n'est pas un nombre, c'est une creation |
|
| 46 | + if (!$id_auteur = intval($arg)) { |
|
| 47 | + if (($id_auteur = auteur_inserer()) > 0) { |
|
| 48 | + # cf. GROS HACK |
|
| 49 | + # recuperer l'eventuel logo charge avant la creation |
|
| 50 | + # ils ont un id = 0-id_auteur de la session |
|
| 51 | + $id_hack = 0 - $GLOBALS['visiteur_session']['id_auteur']; |
|
| 52 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 53 | + foreach (['on', 'off'] as $type) { |
|
| 54 | + if ($logo = $chercher_logo($id_hack, 'id_auteur', $type)) { |
|
| 55 | + if ($logo = reset($logo)) { |
|
| 56 | + rename($logo, str_replace($id_hack, $id_auteur, $logo)); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // Enregistre l'envoi dans la BD |
|
| 64 | + $err = ''; |
|
| 65 | + if ($id_auteur > 0) { |
|
| 66 | + $err = auteur_modifier($id_auteur); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if ($err) { |
|
| 70 | + spip_log("echec editeur auteur: $err", _LOG_ERREUR); |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return [$id_auteur, $err]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -87,64 +87,64 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | function auteur_inserer($source = null, $set = null) { |
| 89 | 89 | |
| 90 | - // Ce qu'on va demander comme modifications |
|
| 91 | - $champs = []; |
|
| 92 | - $champs['source'] = $source ?: 'spip'; |
|
| 93 | - |
|
| 94 | - $champs['login'] = ''; |
|
| 95 | - $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 96 | - $champs['webmestre'] = 'non'; |
|
| 97 | - if (empty($champs['imessage'])) { |
|
| 98 | - $champs['imessage'] = 'oui'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - if ($set) { |
|
| 102 | - $champs = array_merge($champs, $set); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Envoyer aux plugins |
|
| 106 | - $champs = pipeline( |
|
| 107 | - 'pre_insertion', |
|
| 108 | - [ |
|
| 109 | - 'args' => [ |
|
| 110 | - 'table' => 'spip_auteurs', |
|
| 111 | - ], |
|
| 112 | - 'data' => $champs |
|
| 113 | - ] |
|
| 114 | - ); |
|
| 115 | - $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 116 | - pipeline( |
|
| 117 | - 'post_insertion', |
|
| 118 | - [ |
|
| 119 | - 'args' => [ |
|
| 120 | - 'table' => 'spip_auteurs', |
|
| 121 | - 'id_objet' => $id_auteur |
|
| 122 | - ], |
|
| 123 | - 'data' => $champs |
|
| 124 | - ] |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Appeler une notification |
|
| 128 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 129 | - $notifications( |
|
| 130 | - 'auteur_inserer', |
|
| 131 | - $id_auteur, |
|
| 132 | - [ |
|
| 133 | - 'champs' => $champs, |
|
| 134 | - ] |
|
| 135 | - ); |
|
| 136 | - $notifications( |
|
| 137 | - 'objet_inserer', |
|
| 138 | - $id_auteur, |
|
| 139 | - [ |
|
| 140 | - 'objet' => 'auteur', |
|
| 141 | - 'id_objet' => $id_auteur, |
|
| 142 | - 'champs' => $champs, |
|
| 143 | - ] |
|
| 144 | - ); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $id_auteur; |
|
| 90 | + // Ce qu'on va demander comme modifications |
|
| 91 | + $champs = []; |
|
| 92 | + $champs['source'] = $source ?: 'spip'; |
|
| 93 | + |
|
| 94 | + $champs['login'] = ''; |
|
| 95 | + $champs['statut'] = '5poubelle'; // inutilisable tant qu'il n'a pas ete renseigne et institue |
|
| 96 | + $champs['webmestre'] = 'non'; |
|
| 97 | + if (empty($champs['imessage'])) { |
|
| 98 | + $champs['imessage'] = 'oui'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if ($set) { |
|
| 102 | + $champs = array_merge($champs, $set); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Envoyer aux plugins |
|
| 106 | + $champs = pipeline( |
|
| 107 | + 'pre_insertion', |
|
| 108 | + [ |
|
| 109 | + 'args' => [ |
|
| 110 | + 'table' => 'spip_auteurs', |
|
| 111 | + ], |
|
| 112 | + 'data' => $champs |
|
| 113 | + ] |
|
| 114 | + ); |
|
| 115 | + $id_auteur = sql_insertq('spip_auteurs', $champs); |
|
| 116 | + pipeline( |
|
| 117 | + 'post_insertion', |
|
| 118 | + [ |
|
| 119 | + 'args' => [ |
|
| 120 | + 'table' => 'spip_auteurs', |
|
| 121 | + 'id_objet' => $id_auteur |
|
| 122 | + ], |
|
| 123 | + 'data' => $champs |
|
| 124 | + ] |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Appeler une notification |
|
| 128 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 129 | + $notifications( |
|
| 130 | + 'auteur_inserer', |
|
| 131 | + $id_auteur, |
|
| 132 | + [ |
|
| 133 | + 'champs' => $champs, |
|
| 134 | + ] |
|
| 135 | + ); |
|
| 136 | + $notifications( |
|
| 137 | + 'objet_inserer', |
|
| 138 | + $id_auteur, |
|
| 139 | + [ |
|
| 140 | + 'objet' => 'auteur', |
|
| 141 | + 'id_objet' => $id_auteur, |
|
| 142 | + 'champs' => $champs, |
|
| 143 | + ] |
|
| 144 | + ); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $id_auteur; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -169,70 +169,70 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | function auteur_modifier($id_auteur, $set = null, $force_update = false) { |
| 171 | 171 | |
| 172 | - include_spip('inc/modifier'); |
|
| 173 | - include_spip('inc/filtres'); |
|
| 174 | - $c = collecter_requests( |
|
| 175 | - // include list |
|
| 176 | - objet_info('auteur', 'champs_editables'), |
|
| 177 | - // exclude list |
|
| 178 | - $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 179 | - // donnees eventuellement fournies |
|
| 180 | - $set |
|
| 181 | - ); |
|
| 182 | - |
|
| 183 | - if ( |
|
| 184 | - $err = objet_modifier_champs( |
|
| 185 | - 'auteur', |
|
| 186 | - $id_auteur, |
|
| 187 | - [ |
|
| 188 | - 'data' => $set, |
|
| 189 | - 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 190 | - ], |
|
| 191 | - $c |
|
| 192 | - ) |
|
| 193 | - ) { |
|
| 194 | - return $err; |
|
| 195 | - } |
|
| 196 | - $session = $c; |
|
| 197 | - |
|
| 198 | - $err = ''; |
|
| 199 | - if (!$force_update) { |
|
| 200 | - // Modification de statut, changement de rubrique ? |
|
| 201 | - $c = collecter_requests( |
|
| 202 | - // include list |
|
| 203 | - [ |
|
| 204 | - 'statut', |
|
| 205 | - 'new_login', |
|
| 206 | - 'new_pass', |
|
| 207 | - 'login', |
|
| 208 | - 'pass', |
|
| 209 | - 'webmestre', |
|
| 210 | - 'restreintes', |
|
| 211 | - 'id_parent' |
|
| 212 | - ], |
|
| 213 | - // exclude list |
|
| 214 | - [], |
|
| 215 | - // donnees eventuellement fournies |
|
| 216 | - $set |
|
| 217 | - ); |
|
| 218 | - if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 219 | - $c['login'] = $c['new_login']; |
|
| 220 | - } |
|
| 221 | - if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 222 | - $c['pass'] = $c['new_pass']; |
|
| 223 | - } |
|
| 224 | - $err = auteur_instituer($id_auteur, $c); |
|
| 225 | - $session = array_merge($session, $c); |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - // .. mettre a jour les sessions de cet auteur |
|
| 229 | - include_spip('inc/session'); |
|
| 230 | - $session['id_auteur'] = $id_auteur; |
|
| 231 | - unset($session['new_login']); |
|
| 232 | - unset($session['new_pass']); |
|
| 233 | - actualiser_sessions($session); |
|
| 234 | - |
|
| 235 | - return $err; |
|
| 172 | + include_spip('inc/modifier'); |
|
| 173 | + include_spip('inc/filtres'); |
|
| 174 | + $c = collecter_requests( |
|
| 175 | + // include list |
|
| 176 | + objet_info('auteur', 'champs_editables'), |
|
| 177 | + // exclude list |
|
| 178 | + $force_update ? [] : ['webmestre', 'pass', 'login'], |
|
| 179 | + // donnees eventuellement fournies |
|
| 180 | + $set |
|
| 181 | + ); |
|
| 182 | + |
|
| 183 | + if ( |
|
| 184 | + $err = objet_modifier_champs( |
|
| 185 | + 'auteur', |
|
| 186 | + $id_auteur, |
|
| 187 | + [ |
|
| 188 | + 'data' => $set, |
|
| 189 | + 'nonvide' => ['nom' => _T('ecrire:item_nouvel_auteur')] |
|
| 190 | + ], |
|
| 191 | + $c |
|
| 192 | + ) |
|
| 193 | + ) { |
|
| 194 | + return $err; |
|
| 195 | + } |
|
| 196 | + $session = $c; |
|
| 197 | + |
|
| 198 | + $err = ''; |
|
| 199 | + if (!$force_update) { |
|
| 200 | + // Modification de statut, changement de rubrique ? |
|
| 201 | + $c = collecter_requests( |
|
| 202 | + // include list |
|
| 203 | + [ |
|
| 204 | + 'statut', |
|
| 205 | + 'new_login', |
|
| 206 | + 'new_pass', |
|
| 207 | + 'login', |
|
| 208 | + 'pass', |
|
| 209 | + 'webmestre', |
|
| 210 | + 'restreintes', |
|
| 211 | + 'id_parent' |
|
| 212 | + ], |
|
| 213 | + // exclude list |
|
| 214 | + [], |
|
| 215 | + // donnees eventuellement fournies |
|
| 216 | + $set |
|
| 217 | + ); |
|
| 218 | + if (isset($c['new_login']) and !isset($c['login'])) { |
|
| 219 | + $c['login'] = $c['new_login']; |
|
| 220 | + } |
|
| 221 | + if (isset($c['new_pass']) and !isset($c['pass'])) { |
|
| 222 | + $c['pass'] = $c['new_pass']; |
|
| 223 | + } |
|
| 224 | + $err = auteur_instituer($id_auteur, $c); |
|
| 225 | + $session = array_merge($session, $c); |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + // .. mettre a jour les sessions de cet auteur |
|
| 229 | + include_spip('inc/session'); |
|
| 230 | + $session['id_auteur'] = $id_auteur; |
|
| 231 | + unset($session['new_login']); |
|
| 232 | + unset($session['new_pass']); |
|
| 233 | + actualiser_sessions($session); |
|
| 234 | + |
|
| 235 | + return $err; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -253,9 +253,9 @@ discard block |
||
| 253 | 253 | * @return string |
| 254 | 254 | */ |
| 255 | 255 | function auteur_associer($id_auteur, $objets, $qualif = null) { |
| 256 | - include_spip('action/editer_liens'); |
|
| 256 | + include_spip('action/editer_liens'); |
|
| 257 | 257 | |
| 258 | - return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 258 | + return objet_associer(['auteur' => $id_auteur], $objets, $qualif); |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -274,9 +274,9 @@ discard block |
||
| 274 | 274 | * @return string |
| 275 | 275 | */ |
| 276 | 276 | function auteur_dissocier($id_auteur, $objets) { |
| 277 | - include_spip('action/editer_liens'); |
|
| 277 | + include_spip('action/editer_liens'); |
|
| 278 | 278 | |
| 279 | - return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 279 | + return objet_dissocier(['auteur' => $id_auteur], $objets); |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -297,9 +297,9 @@ discard block |
||
| 297 | 297 | * @return bool|int |
| 298 | 298 | */ |
| 299 | 299 | function auteur_qualifier($id_auteur, $objets, $qualif) { |
| 300 | - include_spip('action/editer_liens'); |
|
| 300 | + include_spip('action/editer_liens'); |
|
| 301 | 301 | |
| 302 | - return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 302 | + return objet_qualifier_liens(['auteur' => $id_auteur], $objets, $qualif); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | |
@@ -318,160 +318,160 @@ discard block |
||
| 318 | 318 | * @return bool|string |
| 319 | 319 | */ |
| 320 | 320 | function auteur_instituer($id_auteur, $c, $force_webmestre = false) { |
| 321 | - if (!$id_auteur = intval($id_auteur)) { |
|
| 322 | - return false; |
|
| 323 | - } |
|
| 324 | - $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 325 | - $champs = []; |
|
| 326 | - |
|
| 327 | - // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 328 | - if (isset($c['login']) and strlen($c['login'])) { |
|
| 329 | - $champs['login'] = $c['login']; |
|
| 330 | - } |
|
| 331 | - if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 332 | - $champs['pass'] = $c['pass']; |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 336 | - |
|
| 337 | - if ( |
|
| 338 | - isset($c['statut']) |
|
| 339 | - and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 340 | - ) { |
|
| 341 | - $statut = $champs['statut'] = $c['statut']; |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - // Restreindre avant de declarer l'auteur |
|
| 345 | - // (section critique sur les droits) |
|
| 346 | - if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 347 | - if (is_array($c['restreintes'])) { |
|
| 348 | - $c['restreintes'][] = $c['id_parent']; |
|
| 349 | - } else { |
|
| 350 | - $c['restreintes'] = [$c['id_parent']]; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - if ( |
|
| 355 | - isset($c['webmestre']) |
|
| 356 | - and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 357 | - ) { |
|
| 358 | - $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 362 | - if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 363 | - $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // Envoyer aux plugins |
|
| 367 | - $champs = pipeline( |
|
| 368 | - 'pre_edition', |
|
| 369 | - [ |
|
| 370 | - 'args' => [ |
|
| 371 | - 'table' => 'spip_auteurs', |
|
| 372 | - 'id_objet' => $id_auteur, |
|
| 373 | - 'action' => 'instituer', |
|
| 374 | - 'statut_ancien' => $statut_ancien, |
|
| 375 | - ], |
|
| 376 | - 'data' => $champs |
|
| 377 | - ] |
|
| 378 | - ); |
|
| 379 | - |
|
| 380 | - if ( |
|
| 381 | - isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 382 | - and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 383 | - ) { |
|
| 384 | - $rubriques = array_map('intval', $c['restreintes']); |
|
| 385 | - $rubriques = array_unique($rubriques); |
|
| 386 | - $rubriques = array_diff($rubriques, [0]); |
|
| 387 | - auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 388 | - auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - $flag_ecrire_acces = false; |
|
| 392 | - // commencer par traiter les cas particuliers des logins et pass |
|
| 393 | - // avant les autres ecritures en base |
|
| 394 | - if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 395 | - $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 396 | - include_spip('inc/auth'); |
|
| 397 | - if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 398 | - if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 399 | - $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 400 | - } |
|
| 401 | - } |
|
| 402 | - if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 403 | - $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 404 | - if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 405 | - $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - unset($champs['login']); |
|
| 409 | - unset($champs['pass']); |
|
| 410 | - $flag_ecrire_acces = true; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 414 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 415 | - } |
|
| 416 | - sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 417 | - |
|
| 418 | - // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 419 | - if ( |
|
| 420 | - $flag_ecrire_acces |
|
| 421 | - or isset($champs['statut']) |
|
| 422 | - ) { |
|
| 423 | - include_spip('inc/acces'); |
|
| 424 | - ecrire_acces(); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - // Invalider les caches |
|
| 428 | - include_spip('inc/invalideur'); |
|
| 429 | - suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 430 | - |
|
| 431 | - // Pipeline |
|
| 432 | - pipeline( |
|
| 433 | - 'post_edition', |
|
| 434 | - [ |
|
| 435 | - 'args' => [ |
|
| 436 | - 'table' => 'spip_auteurs', |
|
| 437 | - 'id_objet' => $id_auteur, |
|
| 438 | - 'action' => 'instituer', |
|
| 439 | - 'statut_ancien' => $statut_ancien, |
|
| 440 | - ], |
|
| 441 | - 'data' => $champs |
|
| 442 | - ] |
|
| 443 | - ); |
|
| 444 | - |
|
| 445 | - // Notifications |
|
| 446 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 447 | - $notifications( |
|
| 448 | - 'auteur_instituer', |
|
| 449 | - $id_auteur, |
|
| 450 | - [ |
|
| 451 | - 'statut' => $statut, |
|
| 452 | - 'statut_ancien' => $statut_ancien, |
|
| 453 | - 'champs' => $champs, |
|
| 454 | - ] |
|
| 455 | - ); |
|
| 456 | - $notifications( |
|
| 457 | - 'objet_instituer', |
|
| 458 | - $id_auteur, |
|
| 459 | - [ |
|
| 460 | - 'objet' => 'auteur', |
|
| 461 | - 'id_objet' => $id_auteur, |
|
| 462 | - 'statut' => $statut, |
|
| 463 | - 'statut_ancien' => $statut_ancien, |
|
| 464 | - 'champs' => $champs, |
|
| 465 | - ] |
|
| 466 | - ); |
|
| 467 | - |
|
| 468 | - // Rétro-compat |
|
| 469 | - $notifications( |
|
| 470 | - 'instituerauteur', |
|
| 471 | - $id_auteur, |
|
| 472 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 473 | - ); |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - return implode(' ', array_map('_T', $erreurs)); |
|
| 321 | + if (!$id_auteur = intval($id_auteur)) { |
|
| 322 | + return false; |
|
| 323 | + } |
|
| 324 | + $erreurs = []; // contiendra les differentes erreurs a traduire par _T() |
|
| 325 | + $champs = []; |
|
| 326 | + |
|
| 327 | + // les memoriser pour les faire passer dans le pipeline pre_edition |
|
| 328 | + if (isset($c['login']) and strlen($c['login'])) { |
|
| 329 | + $champs['login'] = $c['login']; |
|
| 330 | + } |
|
| 331 | + if (isset($c['pass']) and strlen($c['pass'])) { |
|
| 332 | + $champs['pass'] = $c['pass']; |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + $statut = $statut_ancien = sql_getfetsel('statut', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 336 | + |
|
| 337 | + if ( |
|
| 338 | + isset($c['statut']) |
|
| 339 | + and (autoriser('modifier', 'auteur', $id_auteur, null, ['statut' => $c['statut']])) |
|
| 340 | + ) { |
|
| 341 | + $statut = $champs['statut'] = $c['statut']; |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + // Restreindre avant de declarer l'auteur |
|
| 345 | + // (section critique sur les droits) |
|
| 346 | + if (isset($c['id_parent']) and $c['id_parent']) { |
|
| 347 | + if (is_array($c['restreintes'])) { |
|
| 348 | + $c['restreintes'][] = $c['id_parent']; |
|
| 349 | + } else { |
|
| 350 | + $c['restreintes'] = [$c['id_parent']]; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + if ( |
|
| 355 | + isset($c['webmestre']) |
|
| 356 | + and ($force_webmestre or autoriser('modifier', 'auteur', $id_auteur, null, ['webmestre' => '?'])) |
|
| 357 | + ) { |
|
| 358 | + $champs['webmestre'] = $c['webmestre'] == 'oui' ? 'oui' : 'non'; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + // si statut change et n'est pas 0minirezo, on force webmestre a non |
|
| 362 | + if (isset($c['statut']) and $c['statut'] !== '0minirezo') { |
|
| 363 | + $champs['webmestre'] = $c['webmestre'] = 'non'; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // Envoyer aux plugins |
|
| 367 | + $champs = pipeline( |
|
| 368 | + 'pre_edition', |
|
| 369 | + [ |
|
| 370 | + 'args' => [ |
|
| 371 | + 'table' => 'spip_auteurs', |
|
| 372 | + 'id_objet' => $id_auteur, |
|
| 373 | + 'action' => 'instituer', |
|
| 374 | + 'statut_ancien' => $statut_ancien, |
|
| 375 | + ], |
|
| 376 | + 'data' => $champs |
|
| 377 | + ] |
|
| 378 | + ); |
|
| 379 | + |
|
| 380 | + if ( |
|
| 381 | + isset($c['restreintes']) and is_array($c['restreintes']) |
|
| 382 | + and autoriser('modifier', 'auteur', $id_auteur, null, ['restreint' => $c['restreintes']]) |
|
| 383 | + ) { |
|
| 384 | + $rubriques = array_map('intval', $c['restreintes']); |
|
| 385 | + $rubriques = array_unique($rubriques); |
|
| 386 | + $rubriques = array_diff($rubriques, [0]); |
|
| 387 | + auteur_dissocier($id_auteur, ['rubrique' => '*']); |
|
| 388 | + auteur_associer($id_auteur, ['rubrique' => $rubriques]); |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + $flag_ecrire_acces = false; |
|
| 392 | + // commencer par traiter les cas particuliers des logins et pass |
|
| 393 | + // avant les autres ecritures en base |
|
| 394 | + if (isset($champs['login']) or isset($champs['pass'])) { |
|
| 395 | + $auth_methode = sql_getfetsel('source', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 396 | + include_spip('inc/auth'); |
|
| 397 | + if (isset($champs['login']) and strlen($champs['login'])) { |
|
| 398 | + if (!auth_modifier_login($auth_methode, $champs['login'], $id_auteur)) { |
|
| 399 | + $erreurs[] = 'ecrire:impossible_modifier_login_auteur'; |
|
| 400 | + } |
|
| 401 | + } |
|
| 402 | + if (isset($champs['pass']) and strlen($champs['pass'])) { |
|
| 403 | + $champs['login'] = sql_getfetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur)); |
|
| 404 | + if (!auth_modifier_pass($auth_methode, $champs['login'], $champs['pass'], $id_auteur)) { |
|
| 405 | + $erreurs[] = 'ecrire:impossible_modifier_pass_auteur'; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + unset($champs['login']); |
|
| 409 | + unset($champs['pass']); |
|
| 410 | + $flag_ecrire_acces = true; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 414 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 415 | + } |
|
| 416 | + sql_updateq('spip_auteurs', $champs, 'id_auteur=' . $id_auteur); |
|
| 417 | + |
|
| 418 | + // .. mettre a jour les fichiers .htpasswd et .htpasswd-admin |
|
| 419 | + if ( |
|
| 420 | + $flag_ecrire_acces |
|
| 421 | + or isset($champs['statut']) |
|
| 422 | + ) { |
|
| 423 | + include_spip('inc/acces'); |
|
| 424 | + ecrire_acces(); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + // Invalider les caches |
|
| 428 | + include_spip('inc/invalideur'); |
|
| 429 | + suivre_invalideur("id='auteur/$id_auteur'"); |
|
| 430 | + |
|
| 431 | + // Pipeline |
|
| 432 | + pipeline( |
|
| 433 | + 'post_edition', |
|
| 434 | + [ |
|
| 435 | + 'args' => [ |
|
| 436 | + 'table' => 'spip_auteurs', |
|
| 437 | + 'id_objet' => $id_auteur, |
|
| 438 | + 'action' => 'instituer', |
|
| 439 | + 'statut_ancien' => $statut_ancien, |
|
| 440 | + ], |
|
| 441 | + 'data' => $champs |
|
| 442 | + ] |
|
| 443 | + ); |
|
| 444 | + |
|
| 445 | + // Notifications |
|
| 446 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 447 | + $notifications( |
|
| 448 | + 'auteur_instituer', |
|
| 449 | + $id_auteur, |
|
| 450 | + [ |
|
| 451 | + 'statut' => $statut, |
|
| 452 | + 'statut_ancien' => $statut_ancien, |
|
| 453 | + 'champs' => $champs, |
|
| 454 | + ] |
|
| 455 | + ); |
|
| 456 | + $notifications( |
|
| 457 | + 'objet_instituer', |
|
| 458 | + $id_auteur, |
|
| 459 | + [ |
|
| 460 | + 'objet' => 'auteur', |
|
| 461 | + 'id_objet' => $id_auteur, |
|
| 462 | + 'statut' => $statut, |
|
| 463 | + 'statut_ancien' => $statut_ancien, |
|
| 464 | + 'champs' => $champs, |
|
| 465 | + ] |
|
| 466 | + ); |
|
| 467 | + |
|
| 468 | + // Rétro-compat |
|
| 469 | + $notifications( |
|
| 470 | + 'instituerauteur', |
|
| 471 | + $id_auteur, |
|
| 472 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien] |
|
| 473 | + ); |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + return implode(' ', array_map('_T', $erreurs)); |
|
| 477 | 477 | } |
@@ -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 | /** |
@@ -29,24 +29,24 @@ discard block |
||
| 29 | 29 | */ |
| 30 | 30 | function action_instituer_objet_dist($arg = null) { |
| 31 | 31 | |
| 32 | - if (is_null($arg)) { |
|
| 33 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | - $arg = $securiser_action(); |
|
| 35 | - } |
|
| 32 | + if (is_null($arg)) { |
|
| 33 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 34 | + $arg = $securiser_action(); |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | - if (!$statut) { |
|
| 39 | - $statut = _request('statut_nouv'); |
|
| 40 | - } // cas POST |
|
| 41 | - if (!$statut) { |
|
| 42 | - return; |
|
| 43 | - } // impossible mais sait-on jamais |
|
| 37 | + [$objet, $id_objet, $statut] = preg_split('/\W/', $arg); |
|
| 38 | + if (!$statut) { |
|
| 39 | + $statut = _request('statut_nouv'); |
|
| 40 | + } // cas POST |
|
| 41 | + if (!$statut) { |
|
| 42 | + return; |
|
| 43 | + } // impossible mais sait-on jamais |
|
| 44 | 44 | |
| 45 | - if ( |
|
| 46 | - $id_objet = intval($id_objet) |
|
| 47 | - and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | - ) { |
|
| 49 | - include_spip('action/editer_objet'); |
|
| 50 | - objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | - } |
|
| 45 | + if ( |
|
| 46 | + $id_objet = intval($id_objet) |
|
| 47 | + and autoriser('instituer', $objet, $id_objet, '', ['statut' => $statut]) |
|
| 48 | + ) { |
|
| 49 | + include_spip('action/editer_objet'); |
|
| 50 | + objet_modifier($objet, $id_objet, ['statut' => $statut]); |
|
| 51 | + } |
|
| 52 | 52 | } |
@@ -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 | /** |
@@ -25,41 +25,41 @@ discard block |
||
| 25 | 25 | **/ |
| 26 | 26 | function action_instituer_langue_rubrique_dist() { |
| 27 | 27 | |
| 28 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | - $arg = $securiser_action(); |
|
| 30 | - $changer_lang = _request('changer_lang'); |
|
| 28 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 29 | + $arg = $securiser_action(); |
|
| 30 | + $changer_lang = _request('changer_lang'); |
|
| 31 | 31 | |
| 32 | - [$id_rubrique, $id_parent] = preg_split('/\W/', $arg); |
|
| 32 | + [$id_rubrique, $id_parent] = preg_split('/\W/', $arg); |
|
| 33 | 33 | |
| 34 | - if ( |
|
| 35 | - $changer_lang |
|
| 36 | - and $id_rubrique > 0 |
|
| 37 | - and $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 38 | - and ($GLOBALS['meta']['multi_secteurs'] == 'non' or $id_parent == 0) |
|
| 39 | - ) { |
|
| 40 | - if ($changer_lang != 'herit') { |
|
| 41 | - sql_updateq( |
|
| 42 | - 'spip_rubriques', |
|
| 43 | - ['lang' => $changer_lang, 'langue_choisie' => 'oui'], |
|
| 44 | - "id_rubrique=$id_rubrique" |
|
| 45 | - ); |
|
| 46 | - } else { |
|
| 47 | - if ($id_parent == 0) { |
|
| 48 | - $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 49 | - } else { |
|
| 50 | - $langue_parent = sql_getfetsel('lang', 'spip_rubriques', "id_rubrique=$id_parent"); |
|
| 51 | - } |
|
| 52 | - sql_updateq( |
|
| 53 | - 'spip_rubriques', |
|
| 54 | - ['lang' => $langue_parent, 'langue_choisie' => 'non'], |
|
| 55 | - "id_rubrique=$id_rubrique" |
|
| 56 | - ); |
|
| 57 | - } |
|
| 58 | - include_spip('inc/rubriques'); |
|
| 59 | - calculer_langues_rubriques(); |
|
| 34 | + if ( |
|
| 35 | + $changer_lang |
|
| 36 | + and $id_rubrique > 0 |
|
| 37 | + and $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 38 | + and ($GLOBALS['meta']['multi_secteurs'] == 'non' or $id_parent == 0) |
|
| 39 | + ) { |
|
| 40 | + if ($changer_lang != 'herit') { |
|
| 41 | + sql_updateq( |
|
| 42 | + 'spip_rubriques', |
|
| 43 | + ['lang' => $changer_lang, 'langue_choisie' => 'oui'], |
|
| 44 | + "id_rubrique=$id_rubrique" |
|
| 45 | + ); |
|
| 46 | + } else { |
|
| 47 | + if ($id_parent == 0) { |
|
| 48 | + $langue_parent = $GLOBALS['meta']['langue_site']; |
|
| 49 | + } else { |
|
| 50 | + $langue_parent = sql_getfetsel('lang', 'spip_rubriques', "id_rubrique=$id_parent"); |
|
| 51 | + } |
|
| 52 | + sql_updateq( |
|
| 53 | + 'spip_rubriques', |
|
| 54 | + ['lang' => $langue_parent, 'langue_choisie' => 'non'], |
|
| 55 | + "id_rubrique=$id_rubrique" |
|
| 56 | + ); |
|
| 57 | + } |
|
| 58 | + include_spip('inc/rubriques'); |
|
| 59 | + calculer_langues_rubriques(); |
|
| 60 | 60 | |
| 61 | - // invalider les caches marques de cette rubrique |
|
| 62 | - include_spip('inc/invalideur'); |
|
| 63 | - suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 64 | - } |
|
| 61 | + // invalider les caches marques de cette rubrique |
|
| 62 | + include_spip('inc/invalideur'); |
|
| 63 | + suivre_invalideur("id='rubrique/$id_rubrique'"); |
|
| 64 | + } |
|
| 65 | 65 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -35,14 +35,14 @@ discard block |
||
| 35 | 35 | * @return void |
| 36 | 36 | */ |
| 37 | 37 | function action_supprimer_lien_dist($arg = null) { |
| 38 | - if (is_null($arg)) { |
|
| 39 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 40 | - $arg = $securiser_action(); |
|
| 41 | - } |
|
| 38 | + if (is_null($arg)) { |
|
| 39 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 40 | + $arg = $securiser_action(); |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - $arg = explode('-', $arg); |
|
| 44 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 43 | + $arg = explode('-', $arg); |
|
| 44 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 45 | 45 | |
| 46 | - include_spip('action/editer_liens'); |
|
| 47 | - objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 46 | + include_spip('action/editer_liens'); |
|
| 47 | + objet_dissocier([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 48 | 48 | } |
@@ -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 | /** |
@@ -34,14 +34,14 @@ discard block |
||
| 34 | 34 | * @return void |
| 35 | 35 | */ |
| 36 | 36 | function action_ajouter_lien_dist($arg = null) { |
| 37 | - if (is_null($arg)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - } |
|
| 37 | + if (is_null($arg)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | - $arg = explode('-', $arg); |
|
| 43 | - [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 42 | + $arg = explode('-', $arg); |
|
| 43 | + [$objet_source, $ids, $objet_lie, $idl] = $arg; |
|
| 44 | 44 | |
| 45 | - include_spip('action/editer_liens'); |
|
| 46 | - objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 45 | + include_spip('action/editer_liens'); |
|
| 46 | + objet_associer([$objet_source => $ids], [$objet_lie => $idl]); |
|
| 47 | 47 | } |