@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Autorisations |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | include_spip('base/abstract_sql'); |
@@ -37,89 +37,89 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | if (!function_exists('autoriser')) { |
| 40 | - /** |
|
| 41 | - * Autoriser une action |
|
| 42 | - * |
|
| 43 | - * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | - * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | - * les autorisations. |
|
| 46 | - * |
|
| 47 | - * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | - * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | - * dans cet ordre : |
|
| 50 | - * |
|
| 51 | - * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | - * - autoriser_{type}, sinon avec _dist |
|
| 53 | - * - autoriser_{faire}, sinon avec _dist |
|
| 54 | - * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | - * |
|
| 56 | - * Seul le premier argument est obligatoire. |
|
| 57 | - * |
|
| 58 | - * @note |
|
| 59 | - * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | - * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | - * cette valeur. |
|
| 62 | - * |
|
| 63 | - * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | - * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | - * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | - * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | - * |
|
| 68 | - * @note |
|
| 69 | - * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | - * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | - * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | - * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | - * quel serait le type, quel serait l'action ? |
|
| 74 | - * |
|
| 75 | - * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | - * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | - * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | - * |
|
| 79 | - * @api |
|
| 80 | - * @see autoriser_dist() |
|
| 81 | - * @see objet_type() |
|
| 82 | - * |
|
| 83 | - * @param string $faire |
|
| 84 | - * une action ('modifier', 'publier'...) |
|
| 85 | - * @param string|null $type |
|
| 86 | - * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | - * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | - * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | - * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | - * Les soulignés seront retirés (cf. la note). |
|
| 91 | - * @param string|int|null $id |
|
| 92 | - * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | - * - null: non utile pour l’autorisation |
|
| 94 | - * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | - * - string: identifiant textuel |
|
| 96 | - * @param null|int|array $qui |
|
| 97 | - * - si null on prend alors visiteur_session |
|
| 98 | - * - un id_auteur (on regarde dans la base) |
|
| 99 | - * - un tableau auteur complet, y compris [restreint] |
|
| 100 | - * @param array $opt |
|
| 101 | - * options sous forme de tableau associatif |
|
| 102 | - * @return bool |
|
| 103 | - * true si la personne peut effectuer l'action |
|
| 104 | - */ |
|
| 105 | - function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | - // Charger les fonctions d'autorisation supplementaires |
|
| 107 | - static $pipe; |
|
| 108 | - if (!isset($pipe)) { |
|
| 109 | - $pipe = 1; |
|
| 110 | - pipeline('autoriser'); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | - } |
|
| 40 | + /** |
|
| 41 | + * Autoriser une action |
|
| 42 | + * |
|
| 43 | + * Teste si une personne (par défaut le visiteur en cours) peut effectuer |
|
| 44 | + * une certaine action. Cette fonction est le point d'entrée de toutes |
|
| 45 | + * les autorisations. |
|
| 46 | + * |
|
| 47 | + * La fonction se charge d'appeler des fonctions d'autorisations spécifiques |
|
| 48 | + * aux actions demandées si elles existent. Elle cherche donc les fonctions |
|
| 49 | + * dans cet ordre : |
|
| 50 | + * |
|
| 51 | + * - autoriser_{type}_{faire}, sinon avec _dist |
|
| 52 | + * - autoriser_{type}, sinon avec _dist |
|
| 53 | + * - autoriser_{faire}, sinon avec _dist |
|
| 54 | + * - autoriser_{defaut}, sinon avec _dist |
|
| 55 | + * |
|
| 56 | + * Seul le premier argument est obligatoire. |
|
| 57 | + * |
|
| 58 | + * @note |
|
| 59 | + * Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre, |
|
| 60 | + * la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser |
|
| 61 | + * cette valeur. |
|
| 62 | + * |
|
| 63 | + * Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple |
|
| 64 | + * 'statistiques', un souligné avant le terme est ajouté afin d'indiquer |
|
| 65 | + * explicitement à la fonction autoriser de ne pas transformer la chaîne en type |
|
| 66 | + * d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')` |
|
| 67 | + * |
|
| 68 | + * @note |
|
| 69 | + * Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer |
|
| 70 | + * tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart` |
|
| 71 | + * et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet |
|
| 72 | + * d'éviter une possible confusion si une fonction `autoriser_livre_art` existait : |
|
| 73 | + * quel serait le type, quel serait l'action ? |
|
| 74 | + * |
|
| 75 | + * Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art', |
|
| 76 | + * la fonction d'autorisation correspondante ne l'aura pas. |
|
| 77 | + * Exemple : `function autoriser_livreart_modifier_dist(...){...}` |
|
| 78 | + * |
|
| 79 | + * @api |
|
| 80 | + * @see autoriser_dist() |
|
| 81 | + * @see objet_type() |
|
| 82 | + * |
|
| 83 | + * @param string $faire |
|
| 84 | + * une action ('modifier', 'publier'...) |
|
| 85 | + * @param string|null $type |
|
| 86 | + * Type d’objet ou élément sur lequel appliquer l’action. |
|
| 87 | + * - null: indifférent à tout type d’élément ou objet éditorial |
|
| 88 | + * - string: objet éditorial (objet_type() est appliqué pour homogénéiser l’entrée) |
|
| 89 | + * - _string: autre élément (avec un souligné en premier caractère, désactive objet_type()). |
|
| 90 | + * Les soulignés seront retirés (cf. la note). |
|
| 91 | + * @param string|int|null $id |
|
| 92 | + * id de l'objet ou élément sur lequel on veut agir, si pertinent. |
|
| 93 | + * - null: non utile pour l’autorisation |
|
| 94 | + * - int: identifiant numérique (cas de tous les objets éditoriaux de SPIP) |
|
| 95 | + * - string: identifiant textuel |
|
| 96 | + * @param null|int|array $qui |
|
| 97 | + * - si null on prend alors visiteur_session |
|
| 98 | + * - un id_auteur (on regarde dans la base) |
|
| 99 | + * - un tableau auteur complet, y compris [restreint] |
|
| 100 | + * @param array $opt |
|
| 101 | + * options sous forme de tableau associatif |
|
| 102 | + * @return bool |
|
| 103 | + * true si la personne peut effectuer l'action |
|
| 104 | + */ |
|
| 105 | + function autoriser(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
|
| 106 | + // Charger les fonctions d'autorisation supplementaires |
|
| 107 | + static $pipe; |
|
| 108 | + if (!isset($pipe)) { |
|
| 109 | + $pipe = 1; |
|
| 110 | + pipeline('autoriser'); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + return autoriser_dist($faire, $type, $id, $qui, $opt); |
|
| 114 | + } |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | // mes_fonctions peut aussi declarer des autorisations, il faut donc le charger |
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | - global $dossier_squelettes; |
|
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 121 | + global $dossier_squelettes; |
|
| 122 | + include_once(_ROOT_CWD . $f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -150,84 +150,84 @@ discard block |
||
| 150 | 150 | */ |
| 151 | 151 | function autoriser_dist(string $faire, ?string $type = '', $id = null, $qui = null, array $opt = []): bool { |
| 152 | 152 | |
| 153 | - if ($type === null) { |
|
| 154 | - $type = ''; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // Qui ? visiteur_session ? |
|
| 158 | - // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | - if ($qui === null || $qui === '') { |
|
| 160 | - $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | - $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | - } elseif (is_numeric($qui)) { |
|
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | - if (!$qui) { |
|
| 165 | - return false; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | - // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | - if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | - $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - spip_log( |
|
| 176 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | - 'autoriser' . _LOG_DEBUG |
|
| 178 | - ); |
|
| 179 | - |
|
| 180 | - $type = autoriser_type($type); |
|
| 181 | - |
|
| 182 | - // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 183 | - if ( |
|
| 184 | - isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 185 | - && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 186 | - ) { |
|
| 187 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 188 | - return true; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - // Chercher une fonction d'autorisation |
|
| 192 | - // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 193 | - // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 194 | - $fonctions = $type |
|
| 195 | - ? [ |
|
| 196 | - 'autoriser_' . $type . '_' . $faire, |
|
| 197 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | - 'autoriser_' . $type, |
|
| 199 | - 'autoriser_' . $type . '_dist', |
|
| 200 | - 'autoriser_' . $faire, |
|
| 201 | - 'autoriser_' . $faire . '_dist', |
|
| 202 | - 'autoriser_defaut', |
|
| 203 | - 'autoriser_defaut_dist' |
|
| 204 | - ] |
|
| 205 | - : [ |
|
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 208 | - 'autoriser_defaut', |
|
| 209 | - 'autoriser_defaut_dist' |
|
| 210 | - ]; |
|
| 211 | - |
|
| 212 | - $a = false; |
|
| 213 | - foreach ($fonctions as $f) { |
|
| 214 | - if (function_exists($f)) { |
|
| 215 | - $a = $f($faire, $type, $id, $qui, $opt); |
|
| 216 | - break; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - spip_log( |
|
| 221 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | - 'autoriser' . _LOG_DEBUG |
|
| 223 | - ); |
|
| 224 | - |
|
| 225 | - if (!is_bool($a)) { |
|
| 226 | - trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 227 | - $a = (bool) $a; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - return $a; |
|
| 153 | + if ($type === null) { |
|
| 154 | + $type = ''; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // Qui ? visiteur_session ? |
|
| 158 | + // si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge |
|
| 159 | + if ($qui === null || $qui === '') { |
|
| 160 | + $qui = $GLOBALS['visiteur_session'] ?: []; |
|
| 161 | + $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
|
| 162 | + } elseif (is_numeric($qui)) { |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 164 | + if (!$qui) { |
|
| 165 | + return false; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // Admins restreints, on construit ici (pas generique mais...) |
|
| 170 | + // le tableau de toutes leurs rubriques (y compris les sous-rubriques) |
|
| 171 | + if (_ADMINS_RESTREINTS && is_array($qui)) { |
|
| 172 | + $qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : []; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + spip_log( |
|
| 176 | + "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | + 'autoriser' . _LOG_DEBUG |
|
| 178 | + ); |
|
| 179 | + |
|
| 180 | + $type = autoriser_type($type); |
|
| 181 | + |
|
| 182 | + // Si une exception a ete decretee plus haut dans le code, l'appliquer |
|
| 183 | + if ( |
|
| 184 | + isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
|
| 185 | + && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
|
| 186 | + ) { |
|
| 187 | + spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 188 | + return true; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + // Chercher une fonction d'autorisation |
|
| 192 | + // Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist], |
|
| 193 | + // autoriser_faire[_dist], autoriser_defaut[_dist] |
|
| 194 | + $fonctions = $type |
|
| 195 | + ? [ |
|
| 196 | + 'autoriser_' . $type . '_' . $faire, |
|
| 197 | + 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | + 'autoriser_' . $type, |
|
| 199 | + 'autoriser_' . $type . '_dist', |
|
| 200 | + 'autoriser_' . $faire, |
|
| 201 | + 'autoriser_' . $faire . '_dist', |
|
| 202 | + 'autoriser_defaut', |
|
| 203 | + 'autoriser_defaut_dist' |
|
| 204 | + ] |
|
| 205 | + : [ |
|
| 206 | + 'autoriser_' . $faire, |
|
| 207 | + 'autoriser_' . $faire . '_dist', |
|
| 208 | + 'autoriser_defaut', |
|
| 209 | + 'autoriser_defaut_dist' |
|
| 210 | + ]; |
|
| 211 | + |
|
| 212 | + $a = false; |
|
| 213 | + foreach ($fonctions as $f) { |
|
| 214 | + if (function_exists($f)) { |
|
| 215 | + $a = $f($faire, $type, $id, $qui, $opt); |
|
| 216 | + break; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + spip_log( |
|
| 221 | + "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | + 'autoriser' . _LOG_DEBUG |
|
| 223 | + ); |
|
| 224 | + |
|
| 225 | + if (!is_bool($a)) { |
|
| 226 | + trigger_error(sprintf('Function %s should returns a boolean instead of %s (casts as boolean). This will trigger fatal error in future versions.', $f, gettype($a)), \E_USER_DEPRECATED); |
|
| 227 | + $a = (bool) $a; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + return $a; |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | // une globale pour aller au plus vite dans la fonction generique ci dessus |
@@ -247,31 +247,31 @@ discard block |
||
| 247 | 247 | * @return bool |
| 248 | 248 | */ |
| 249 | 249 | function autoriser_exception(string $faire, ?string $type = '', $id = null, $autoriser = true): bool { |
| 250 | - // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 251 | - static $autorisation; |
|
| 252 | - // Tolérance avec certains appels |
|
| 253 | - if ($id === null) { |
|
| 254 | - $id = 0; |
|
| 255 | - } |
|
| 256 | - $type = autoriser_type($type); |
|
| 257 | - if ($autoriser === 'verifier') { |
|
| 258 | - return isset($autorisation[$faire][$type][$id]); |
|
| 259 | - } |
|
| 260 | - if ($autoriser === true) { |
|
| 261 | - $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 262 | - } |
|
| 263 | - if ($autoriser === false) { |
|
| 264 | - if ($id === '*') { |
|
| 265 | - unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 266 | - unset($autorisation[$faire][$type]); |
|
| 267 | - } |
|
| 268 | - else { |
|
| 269 | - unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 270 | - unset($autorisation[$faire][$type][$id]); |
|
| 271 | - } |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - return false; |
|
| 250 | + // une static innaccessible par url pour verifier que la globale est positionnee a bon escient |
|
| 251 | + static $autorisation; |
|
| 252 | + // Tolérance avec certains appels |
|
| 253 | + if ($id === null) { |
|
| 254 | + $id = 0; |
|
| 255 | + } |
|
| 256 | + $type = autoriser_type($type); |
|
| 257 | + if ($autoriser === 'verifier') { |
|
| 258 | + return isset($autorisation[$faire][$type][$id]); |
|
| 259 | + } |
|
| 260 | + if ($autoriser === true) { |
|
| 261 | + $GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true; |
|
| 262 | + } |
|
| 263 | + if ($autoriser === false) { |
|
| 264 | + if ($id === '*') { |
|
| 265 | + unset($GLOBALS['autoriser_exception'][$faire][$type]); |
|
| 266 | + unset($autorisation[$faire][$type]); |
|
| 267 | + } |
|
| 268 | + else { |
|
| 269 | + unset($GLOBALS['autoriser_exception'][$faire][$type][$id]); |
|
| 270 | + unset($autorisation[$faire][$type][$id]); |
|
| 271 | + } |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + return false; |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
@@ -284,13 +284,13 @@ discard block |
||
| 284 | 284 | * - Les _ sont supprimés |
| 285 | 285 | */ |
| 286 | 286 | function autoriser_type(?string $type = ''): string { |
| 287 | - // passer par objet_type pour avoir les alias |
|
| 288 | - // sauf si _ est le premier caractère. |
|
| 289 | - if ($type && $type[0] !== '_') { |
|
| 290 | - $type = objet_type($type, false); |
|
| 291 | - } |
|
| 292 | - // et supprimer les _ |
|
| 293 | - return str_replace('_', '', (string) $type); |
|
| 287 | + // passer par objet_type pour avoir les alias |
|
| 288 | + // sauf si _ est le premier caractère. |
|
| 289 | + if ($type && $type[0] !== '_') { |
|
| 290 | + $type = objet_type($type, false); |
|
| 291 | + } |
|
| 292 | + // et supprimer les _ |
|
| 293 | + return str_replace('_', '', (string) $type); |
|
| 294 | 294 | } |
| 295 | 295 | |
| 296 | 296 | |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | * @return bool true s'il a le droit, false sinon |
| 310 | 310 | **/ |
| 311 | 311 | function autoriser_defaut_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 312 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 312 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 313 | 313 | } |
| 314 | 314 | |
| 315 | 315 | /** |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | * @return bool true s'il a le droit, false sinon |
| 330 | 330 | */ |
| 331 | 331 | function autoriser_loger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 332 | - return $qui['statut'] !== '5poubelle'; |
|
| 332 | + return $qui['statut'] !== '5poubelle'; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @return bool true s'il a le droit, false sinon |
| 346 | 346 | **/ |
| 347 | 347 | function autoriser_ecrire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 348 | - return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 348 | + return isset($qui['statut']) && in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 349 | 349 | } |
| 350 | 350 | |
| 351 | 351 | /** |
@@ -364,7 +364,7 @@ discard block |
||
| 364 | 364 | * @return bool true s'il a le droit, false sinon |
| 365 | 365 | **/ |
| 366 | 366 | function autoriser_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 367 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 367 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | /** |
@@ -384,14 +384,14 @@ discard block |
||
| 384 | 384 | **/ |
| 385 | 385 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 386 | 386 | |
| 387 | - // Le visiteur a-t-il un statut prevu par la config ? |
|
| 388 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 389 | - return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 390 | - } |
|
| 387 | + // Le visiteur a-t-il un statut prevu par la config ? |
|
| 388 | + if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 389 | + return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
|
| 390 | + } |
|
| 391 | 391 | |
| 392 | - // A-t-on un token de prévisualisation valable ? |
|
| 393 | - include_spip('inc/securiser_action'); |
|
| 394 | - return (bool) decrire_token_previsu(); |
|
| 392 | + // A-t-on un token de prévisualisation valable ? |
|
| 393 | + include_spip('inc/securiser_action'); |
|
| 394 | + return (bool) decrire_token_previsu(); |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | /** |
@@ -420,58 +420,58 @@ discard block |
||
| 420 | 420 | */ |
| 421 | 421 | function test_previsualiser_objet_champ(string $type = '', $id = null, array $qui = [], array $opt = []): bool { |
| 422 | 422 | |
| 423 | - // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 424 | - if (!$type) { |
|
| 425 | - return true; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - include_spip('base/objets'); |
|
| 429 | - $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 430 | - if (isset($infos['statut'])) { |
|
| 431 | - foreach ($infos['statut'] as $c) { |
|
| 432 | - if (isset($c['publie'])) { |
|
| 433 | - if (!isset($c['previsu'])) { |
|
| 434 | - return false; |
|
| 435 | - } // pas de previsu definie => NIET |
|
| 436 | - $champ = $c['champ']; |
|
| 437 | - if (!isset($opt[$champ])) { |
|
| 438 | - return false; |
|
| 439 | - } // pas de champ passe a la demande => NIET |
|
| 440 | - $previsu = explode(',', (string) $c['previsu']); |
|
| 441 | - // regarder si ce statut est autorise pour l'auteur |
|
| 442 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 443 | - // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 444 | - // sinon l’auteur en session |
|
| 445 | - include_spip('inc/securiser_action'); |
|
| 446 | - if ($desc = decrire_token_previsu()) { |
|
| 447 | - $id_auteur = $desc['id_auteur']; |
|
| 448 | - } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 449 | - $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 450 | - } else { |
|
| 451 | - $id_auteur = null; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - if (!$id_auteur) { |
|
| 455 | - return false; |
|
| 456 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 457 | - // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 458 | - } elseif ( |
|
| 459 | - !sql_countsel( |
|
| 460 | - 'spip_auteurs_liens', |
|
| 461 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 462 | - ) |
|
| 463 | - ) { |
|
| 464 | - return false; |
|
| 465 | - } // pas auteur de cet objet => NIET |
|
| 466 | - } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 467 | - // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 468 | - return false; |
|
| 469 | - } |
|
| 470 | - } |
|
| 471 | - } |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - return true; |
|
| 423 | + // si pas de type et statut fourni, c'est une autorisation generale => OK |
|
| 424 | + if (!$type) { |
|
| 425 | + return true; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + include_spip('base/objets'); |
|
| 429 | + $infos = lister_tables_objets_sql(table_objet_sql($type)); |
|
| 430 | + if (isset($infos['statut'])) { |
|
| 431 | + foreach ($infos['statut'] as $c) { |
|
| 432 | + if (isset($c['publie'])) { |
|
| 433 | + if (!isset($c['previsu'])) { |
|
| 434 | + return false; |
|
| 435 | + } // pas de previsu definie => NIET |
|
| 436 | + $champ = $c['champ']; |
|
| 437 | + if (!isset($opt[$champ])) { |
|
| 438 | + return false; |
|
| 439 | + } // pas de champ passe a la demande => NIET |
|
| 440 | + $previsu = explode(',', (string) $c['previsu']); |
|
| 441 | + // regarder si ce statut est autorise pour l'auteur |
|
| 442 | + if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 443 | + // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
|
| 444 | + // sinon l’auteur en session |
|
| 445 | + include_spip('inc/securiser_action'); |
|
| 446 | + if ($desc = decrire_token_previsu()) { |
|
| 447 | + $id_auteur = $desc['id_auteur']; |
|
| 448 | + } elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 449 | + $id_auteur = (int) $GLOBALS['visiteur_session']['id_auteur']; |
|
| 450 | + } else { |
|
| 451 | + $id_auteur = null; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + if (!$id_auteur) { |
|
| 455 | + return false; |
|
| 456 | + } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 457 | + // dans ce cas (admin en general), pas de filtrage sur ce statut |
|
| 458 | + } elseif ( |
|
| 459 | + !sql_countsel( |
|
| 460 | + 'spip_auteurs_liens', |
|
| 461 | + 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 462 | + ) |
|
| 463 | + ) { |
|
| 464 | + return false; |
|
| 465 | + } // pas auteur de cet objet => NIET |
|
| 466 | + } elseif (!in_array($opt[$champ], $previsu)) { |
|
| 467 | + // le statut n'est pas dans ceux definis par la previsu => NIET |
|
| 468 | + return false; |
|
| 469 | + } |
|
| 470 | + } |
|
| 471 | + } |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + return true; |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -487,49 +487,49 @@ discard block |
||
| 487 | 487 | * @return bool true s'il a le droit, false sinon |
| 488 | 488 | **/ |
| 489 | 489 | function autoriser_changerlangue_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 490 | - $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 491 | - $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 492 | - $table = table_objet_sql($type); |
|
| 493 | - if ( |
|
| 494 | - in_array($table, $multi_objets) |
|
| 495 | - || in_array($table, $gerer_trad_objets) |
|
| 496 | - ) { // affichage du formulaire si la configuration l'accepte |
|
| 497 | - $multi_secteurs = lire_config('multi_secteurs'); |
|
| 498 | - $champs = objet_info($type, 'field'); |
|
| 499 | - if ( |
|
| 500 | - $multi_secteurs === 'oui' |
|
| 501 | - && array_key_exists('id_rubrique', $champs) |
|
| 502 | - ) { |
|
| 503 | - // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 504 | - $primary = id_table_objet($type); |
|
| 505 | - $id_rubrique = $table != 'spip_rubriques' |
|
| 506 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 507 | - : $id; |
|
| 508 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 509 | - if (!$id_secteur > 0) { |
|
| 510 | - $id_secteur = $id_rubrique; |
|
| 511 | - } |
|
| 512 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 513 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 514 | - if ($langue_secteur != $langue_objet) { |
|
| 515 | - // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 516 | - return true; |
|
| 517 | - } |
|
| 518 | - if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 519 | - return false; |
|
| 520 | - } else { |
|
| 521 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 522 | - if ($id_parent != 0) { |
|
| 523 | - // sous-rubriques : pas de choix de langue |
|
| 524 | - return false; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } else { |
|
| 529 | - return false; |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 490 | + $multi_objets = explode(',', (string) lire_config('multi_objets')); |
|
| 491 | + $gerer_trad_objets = explode(',', (string) lire_config('gerer_trad_objets')); |
|
| 492 | + $table = table_objet_sql($type); |
|
| 493 | + if ( |
|
| 494 | + in_array($table, $multi_objets) |
|
| 495 | + || in_array($table, $gerer_trad_objets) |
|
| 496 | + ) { // affichage du formulaire si la configuration l'accepte |
|
| 497 | + $multi_secteurs = lire_config('multi_secteurs'); |
|
| 498 | + $champs = objet_info($type, 'field'); |
|
| 499 | + if ( |
|
| 500 | + $multi_secteurs === 'oui' |
|
| 501 | + && array_key_exists('id_rubrique', $champs) |
|
| 502 | + ) { |
|
| 503 | + // multilinguisme par secteur et objet rattaché à une rubrique |
|
| 504 | + $primary = id_table_objet($type); |
|
| 505 | + $id_rubrique = $table != 'spip_rubriques' |
|
| 506 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 507 | + : $id; |
|
| 508 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 509 | + if (!$id_secteur > 0) { |
|
| 510 | + $id_secteur = $id_rubrique; |
|
| 511 | + } |
|
| 512 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 513 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 514 | + if ($langue_secteur != $langue_objet) { |
|
| 515 | + // configuration incohérente, on laisse l'utilisateur corriger la situation |
|
| 516 | + return true; |
|
| 517 | + } |
|
| 518 | + if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
|
| 519 | + return false; |
|
| 520 | + } else { |
|
| 521 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 522 | + if ($id_parent != 0) { |
|
| 523 | + // sous-rubriques : pas de choix de langue |
|
| 524 | + return false; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } else { |
|
| 529 | + return false; |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 533 | 533 | } |
| 534 | 534 | |
| 535 | 535 | /** |
@@ -545,7 +545,7 @@ discard block |
||
| 545 | 545 | * @return bool true s'il a le droit, false sinon |
| 546 | 546 | **/ |
| 547 | 547 | function autoriser_changertraduction_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 548 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 548 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 549 | 549 | } |
| 550 | 550 | |
| 551 | 551 | /** |
@@ -561,38 +561,38 @@ discard block |
||
| 561 | 561 | * @return bool true s'il a le droit, false sinon |
| 562 | 562 | **/ |
| 563 | 563 | function autoriser_dater_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 564 | - $table = table_objet($type); |
|
| 565 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 566 | - $desc = $trouver_table($table); |
|
| 567 | - if (!$desc) { |
|
| 568 | - return false; |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - if (!isset($opt['statut'])) { |
|
| 572 | - if (isset($desc['field']['statut'])) { |
|
| 573 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 574 | - } else { |
|
| 575 | - $statut = 'publie'; |
|
| 576 | - } // pas de statut => publie |
|
| 577 | - } else { |
|
| 578 | - $statut = $opt['statut']; |
|
| 579 | - } |
|
| 580 | - |
|
| 581 | - // Liste des statuts publiés pour cet objet |
|
| 582 | - // Sinon en dur le statut "publie" |
|
| 583 | - $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 584 | - ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 585 | - : ['publie']; |
|
| 586 | - |
|
| 587 | - if ( |
|
| 588 | - in_array($statut, $statuts_publies) |
|
| 589 | - // Ou cas particulier géré en dur ici pour les articles |
|
| 590 | - || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 591 | - ) { |
|
| 592 | - return autoriser('modifier', $type, $id); |
|
| 593 | - } |
|
| 594 | - |
|
| 595 | - return false; |
|
| 564 | + $table = table_objet($type); |
|
| 565 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 566 | + $desc = $trouver_table($table); |
|
| 567 | + if (!$desc) { |
|
| 568 | + return false; |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + if (!isset($opt['statut'])) { |
|
| 572 | + if (isset($desc['field']['statut'])) { |
|
| 573 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 574 | + } else { |
|
| 575 | + $statut = 'publie'; |
|
| 576 | + } // pas de statut => publie |
|
| 577 | + } else { |
|
| 578 | + $statut = $opt['statut']; |
|
| 579 | + } |
|
| 580 | + |
|
| 581 | + // Liste des statuts publiés pour cet objet |
|
| 582 | + // Sinon en dur le statut "publie" |
|
| 583 | + $statuts_publies = isset($desc['statut'][0]['publie']) |
|
| 584 | + ? explode(',', (string) $desc['statut'][0]['publie']) |
|
| 585 | + : ['publie']; |
|
| 586 | + |
|
| 587 | + if ( |
|
| 588 | + in_array($statut, $statuts_publies) |
|
| 589 | + // Ou cas particulier géré en dur ici pour les articles |
|
| 590 | + || $statut === 'prop' && $type === 'article' && $GLOBALS['meta']['post_dates'] === 'non' |
|
| 591 | + ) { |
|
| 592 | + return autoriser('modifier', $type, $id); |
|
| 593 | + } |
|
| 594 | + |
|
| 595 | + return false; |
|
| 596 | 596 | } |
| 597 | 597 | |
| 598 | 598 | /** |
@@ -611,7 +611,7 @@ discard block |
||
| 611 | 611 | * @return bool true s'il a le droit, false sinon |
| 612 | 612 | **/ |
| 613 | 613 | function autoriser_instituer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 614 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 614 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 615 | 615 | } |
| 616 | 616 | |
| 617 | 617 | /** |
@@ -629,9 +629,9 @@ discard block |
||
| 629 | 629 | * @return bool true s'il a le droit, false sinon |
| 630 | 630 | **/ |
| 631 | 631 | function autoriser_rubrique_publierdans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 632 | - return |
|
| 633 | - $qui['statut'] === '0minirezo' |
|
| 634 | - && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 632 | + return |
|
| 633 | + $qui['statut'] === '0minirezo' |
|
| 634 | + && (!$qui['restreint'] || !$id || in_array($id, $qui['restreint'])); |
|
| 635 | 635 | } |
| 636 | 636 | |
| 637 | 637 | /** |
@@ -649,12 +649,12 @@ discard block |
||
| 649 | 649 | * @return bool true s'il a le droit, false sinon |
| 650 | 650 | **/ |
| 651 | 651 | function autoriser_rubrique_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 652 | - if (!empty($opt['id_parent'])) { |
|
| 653 | - return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 654 | - } |
|
| 655 | - else { |
|
| 656 | - return autoriser('defaut', null, 0, $qui, $opt); |
|
| 657 | - } |
|
| 652 | + if (!empty($opt['id_parent'])) { |
|
| 653 | + return autoriser('creerrubriquedans', 'rubrique', $opt['id_parent'], $qui); |
|
| 654 | + } |
|
| 655 | + else { |
|
| 656 | + return autoriser('defaut', null, 0, $qui, $opt); |
|
| 657 | + } |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -672,8 +672,8 @@ discard block |
||
| 672 | 672 | * @return bool true s'il a le droit, false sinon |
| 673 | 673 | **/ |
| 674 | 674 | function autoriser_rubrique_creerrubriquedans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 675 | - return |
|
| 676 | - ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 675 | + return |
|
| 676 | + ($id || $qui['statut'] === '0minirezo' && !$qui['restreint']) && autoriser('voir', 'rubrique', $id) && autoriser('publierdans', 'rubrique', $id); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -691,10 +691,10 @@ discard block |
||
| 691 | 691 | * @return bool true s'il a le droit, false sinon |
| 692 | 692 | **/ |
| 693 | 693 | function autoriser_rubrique_creerarticledans_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 694 | - return |
|
| 695 | - $id |
|
| 696 | - && autoriser('voir', 'rubrique', $id) |
|
| 697 | - && autoriser('creer', 'article'); |
|
| 694 | + return |
|
| 695 | + $id |
|
| 696 | + && autoriser('voir', 'rubrique', $id) |
|
| 697 | + && autoriser('creer', 'article'); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -713,7 +713,7 @@ discard block |
||
| 713 | 713 | * @return bool true s'il a le droit, false sinon |
| 714 | 714 | **/ |
| 715 | 715 | function autoriser_rubrique_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 716 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 716 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 717 | 717 | } |
| 718 | 718 | |
| 719 | 719 | /** |
@@ -731,29 +731,29 @@ discard block |
||
| 731 | 731 | * @return bool true s'il a le droit, false sinon |
| 732 | 732 | **/ |
| 733 | 733 | function autoriser_rubrique_supprimer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 734 | - if (!$id = (int) $id) { |
|
| 735 | - return false; |
|
| 736 | - } |
|
| 734 | + if (!$id = (int) $id) { |
|
| 735 | + return false; |
|
| 736 | + } |
|
| 737 | 737 | |
| 738 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 739 | - return false; |
|
| 740 | - } |
|
| 738 | + if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 739 | + return false; |
|
| 740 | + } |
|
| 741 | 741 | |
| 742 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 743 | - return false; |
|
| 744 | - } |
|
| 742 | + if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 743 | + return false; |
|
| 744 | + } |
|
| 745 | 745 | |
| 746 | - $compte = pipeline( |
|
| 747 | - 'objet_compte_enfants', |
|
| 748 | - ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 749 | - ); |
|
| 750 | - foreach ($compte as $objet => $n) { |
|
| 751 | - if ($n) { |
|
| 752 | - return false; |
|
| 753 | - } |
|
| 754 | - } |
|
| 746 | + $compte = pipeline( |
|
| 747 | + 'objet_compte_enfants', |
|
| 748 | + ['args' => ['objet' => 'rubrique', 'id_objet' => $id], 'data' => []] |
|
| 749 | + ); |
|
| 750 | + foreach ($compte as $objet => $n) { |
|
| 751 | + if ($n) { |
|
| 752 | + return false; |
|
| 753 | + } |
|
| 754 | + } |
|
| 755 | 755 | |
| 756 | - return autoriser('modifier', 'rubrique', $id); |
|
| 756 | + return autoriser('modifier', 'rubrique', $id); |
|
| 757 | 757 | } |
| 758 | 758 | |
| 759 | 759 | |
@@ -773,20 +773,20 @@ discard block |
||
| 773 | 773 | * @return bool true s'il a le droit, false sinon |
| 774 | 774 | **/ |
| 775 | 775 | function autoriser_article_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 776 | - if (!$id) { |
|
| 777 | - return false; |
|
| 778 | - } |
|
| 779 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 776 | + if (!$id) { |
|
| 777 | + return false; |
|
| 778 | + } |
|
| 779 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 780 | 780 | |
| 781 | - return $r && ( |
|
| 782 | - autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 783 | - || ( |
|
| 784 | - (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 785 | - && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 786 | - && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 787 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 788 | - ) |
|
| 789 | - ); |
|
| 781 | + return $r && ( |
|
| 782 | + autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
|
| 783 | + || ( |
|
| 784 | + (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
|
| 785 | + && in_array($qui['statut'], ['0minirezo', '1comite']) |
|
| 786 | + && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
|
| 787 | + && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 788 | + ) |
|
| 789 | + ); |
|
| 790 | 790 | } |
| 791 | 791 | |
| 792 | 792 | /** |
@@ -804,13 +804,13 @@ discard block |
||
| 804 | 804 | * @return bool true s'il a le droit, false sinon |
| 805 | 805 | **/ |
| 806 | 806 | function autoriser_article_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 807 | - if (!empty($opt['id_parent'])) { |
|
| 808 | - // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 809 | - return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 810 | - } |
|
| 811 | - else { |
|
| 812 | - return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 813 | - } |
|
| 807 | + if (!empty($opt['id_parent'])) { |
|
| 808 | + // creerarticledans rappelle autoriser(creer,article) sans id, donc on verifiera condition du else aussi |
|
| 809 | + return autoriser('creerarticledans', 'rubrique', $opt['id_parent'], $qui); |
|
| 810 | + } |
|
| 811 | + else { |
|
| 812 | + return (sql_countsel('spip_rubriques') > 0 && in_array($qui['statut'], ['0minirezo', '1comite'])); |
|
| 813 | + } |
|
| 814 | 814 | } |
| 815 | 815 | |
| 816 | 816 | /** |
@@ -832,26 +832,26 @@ discard block |
||
| 832 | 832 | * @return bool true s'il a le droit, false sinon |
| 833 | 833 | */ |
| 834 | 834 | function autoriser_article_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 835 | - if ($qui['statut'] === '0minirezo') { |
|
| 836 | - return true; |
|
| 837 | - } |
|
| 838 | - // cas des articles : depend du statut de l'article et de l'auteur |
|
| 839 | - if (isset($opt['statut'])) { |
|
| 840 | - $statut = $opt['statut']; |
|
| 841 | - } else { |
|
| 842 | - if (!$id) { |
|
| 843 | - return false; |
|
| 844 | - } |
|
| 845 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 846 | - } |
|
| 835 | + if ($qui['statut'] === '0minirezo') { |
|
| 836 | + return true; |
|
| 837 | + } |
|
| 838 | + // cas des articles : depend du statut de l'article et de l'auteur |
|
| 839 | + if (isset($opt['statut'])) { |
|
| 840 | + $statut = $opt['statut']; |
|
| 841 | + } else { |
|
| 842 | + if (!$id) { |
|
| 843 | + return false; |
|
| 844 | + } |
|
| 845 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 846 | + } |
|
| 847 | 847 | |
| 848 | - return |
|
| 849 | - // si on est pas auteur de l'article, |
|
| 850 | - // seuls les propose et publies sont visibles |
|
| 851 | - in_array($statut, ['prop', 'publie']) |
|
| 852 | - // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 848 | + return |
|
| 849 | + // si on est pas auteur de l'article, |
|
| 850 | + // seuls les propose et publies sont visibles |
|
| 851 | + in_array($statut, ['prop', 'publie']) |
|
| 852 | + // sinon si on est auteur, on a le droit de le voir, evidemment ! |
|
| 853 | 853 | |
| 854 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 854 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | |
@@ -870,24 +870,24 @@ discard block |
||
| 870 | 870 | * @return bool true s'il a le droit, false sinon |
| 871 | 871 | **/ |
| 872 | 872 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 873 | - # securite, mais on aurait pas du arriver ici ! |
|
| 874 | - if ( |
|
| 875 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 876 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 877 | - ) { |
|
| 878 | - return $f($faire, $type, $id, $qui, $opt); |
|
| 879 | - } |
|
| 873 | + # securite, mais on aurait pas du arriver ici ! |
|
| 874 | + if ( |
|
| 875 | + function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 876 | + || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 877 | + ) { |
|
| 878 | + return $f($faire, $type, $id, $qui, $opt); |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - if ($qui['statut'] === '0minirezo') { |
|
| 882 | - return true; |
|
| 883 | - } |
|
| 884 | - // admins et redacteurs peuvent voir un auteur |
|
| 885 | - if ($type === 'auteur') { |
|
| 886 | - return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 887 | - } |
|
| 888 | - // sinon par defaut tout est visible |
|
| 889 | - // sauf cas particuliers traites separemment (ie article) |
|
| 890 | - return true; |
|
| 881 | + if ($qui['statut'] === '0minirezo') { |
|
| 882 | + return true; |
|
| 883 | + } |
|
| 884 | + // admins et redacteurs peuvent voir un auteur |
|
| 885 | + if ($type === 'auteur') { |
|
| 886 | + return in_array($qui['statut'], ['0minirezo', '1comite']); |
|
| 887 | + } |
|
| 888 | + // sinon par defaut tout est visible |
|
| 889 | + // sauf cas particuliers traites separemment (ie article) |
|
| 890 | + return true; |
|
| 891 | 891 | } |
| 892 | 892 | |
| 893 | 893 | |
@@ -909,10 +909,10 @@ discard block |
||
| 909 | 909 | * @return bool true s'il a le droit, false sinon |
| 910 | 910 | **/ |
| 911 | 911 | function autoriser_webmestre_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 912 | - return |
|
| 913 | - $qui['webmestre'] === 'oui' |
|
| 914 | - && $qui['statut'] === '0minirezo' |
|
| 915 | - && !$qui['restreint']; |
|
| 912 | + return |
|
| 913 | + $qui['webmestre'] === 'oui' |
|
| 914 | + && $qui['statut'] === '0minirezo' |
|
| 915 | + && !$qui['restreint']; |
|
| 916 | 916 | } |
| 917 | 917 | |
| 918 | 918 | /** |
@@ -930,7 +930,7 @@ discard block |
||
| 930 | 930 | * @return bool true s'il a le droit, false sinon |
| 931 | 931 | **/ |
| 932 | 932 | function autoriser_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 933 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 933 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | /** |
@@ -948,7 +948,7 @@ discard block |
||
| 948 | 948 | * @return bool true s'il a le droit, false sinon |
| 949 | 949 | **/ |
| 950 | 950 | function autoriser_sauvegarder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 951 | - return $qui['statut'] === '0minirezo'; |
|
| 951 | + return $qui['statut'] === '0minirezo'; |
|
| 952 | 952 | } |
| 953 | 953 | |
| 954 | 954 | /** |
@@ -966,7 +966,7 @@ discard block |
||
| 966 | 966 | * @return bool true s'il a le droit, false sinon |
| 967 | 967 | **/ |
| 968 | 968 | function autoriser_detruire_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 969 | - return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 969 | + return autoriser('webmestre', null, 0, $qui, $opt); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | /** |
@@ -985,23 +985,23 @@ discard block |
||
| 985 | 985 | * @return bool true s'il a le droit, false sinon |
| 986 | 986 | **/ |
| 987 | 987 | function autoriser_auteur_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 988 | - // les admins peuvent "previsualiser" une page auteur |
|
| 989 | - if ( |
|
| 990 | - $qui['statut'] === '0minirezo' |
|
| 991 | - && !$qui['restreint'] |
|
| 992 | - ) { |
|
| 993 | - return true; |
|
| 994 | - } elseif ($id === 0) { |
|
| 995 | - return false; |
|
| 996 | - } |
|
| 997 | - // "Voir en ligne" si l'auteur a un article publie |
|
| 998 | - $n = sql_fetsel( |
|
| 999 | - 'A.id_article', |
|
| 1000 | - 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 1001 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1002 | - ); |
|
| 988 | + // les admins peuvent "previsualiser" une page auteur |
|
| 989 | + if ( |
|
| 990 | + $qui['statut'] === '0minirezo' |
|
| 991 | + && !$qui['restreint'] |
|
| 992 | + ) { |
|
| 993 | + return true; |
|
| 994 | + } elseif ($id === 0) { |
|
| 995 | + return false; |
|
| 996 | + } |
|
| 997 | + // "Voir en ligne" si l'auteur a un article publie |
|
| 998 | + $n = sql_fetsel( |
|
| 999 | + 'A.id_article', |
|
| 1000 | + 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
|
| 1001 | + "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1002 | + ); |
|
| 1003 | 1003 | |
| 1004 | - return (bool) $n; |
|
| 1004 | + return (bool) $n; |
|
| 1005 | 1005 | } |
| 1006 | 1006 | |
| 1007 | 1007 | |
@@ -1030,7 +1030,7 @@ discard block |
||
| 1030 | 1030 | * @return bool true s'il a le droit, false sinon |
| 1031 | 1031 | **/ |
| 1032 | 1032 | function autoriser_auteur_creer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1033 | - return ($qui['statut'] === '0minirezo'); |
|
| 1033 | + return ($qui['statut'] === '0minirezo'); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | |
| 1036 | 1036 | |
@@ -1051,62 +1051,62 @@ discard block |
||
| 1051 | 1051 | * @return bool true s'il a le droit, false sinon |
| 1052 | 1052 | **/ |
| 1053 | 1053 | function autoriser_auteur_modifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1054 | - $id = (int) $id; |
|
| 1055 | - |
|
| 1056 | - // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1057 | - // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1058 | - if ($qui['statut'] != '0minirezo') { |
|
| 1059 | - return $id == $qui['id_auteur'] |
|
| 1060 | - && empty($opt['statut']) |
|
| 1061 | - && empty($opt['webmestre']) |
|
| 1062 | - && empty($opt['restreintes']) |
|
| 1063 | - && empty($opt['login']); |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1067 | - // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1068 | - if ($qui['restreint']) { |
|
| 1069 | - if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1070 | - return false; |
|
| 1071 | - } elseif ( |
|
| 1072 | - isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1073 | - ) { |
|
| 1074 | - return false; |
|
| 1075 | - } else { |
|
| 1076 | - if ($id == $qui['id_auteur']) { |
|
| 1077 | - if (isset($opt['statut']) && $opt['statut']) { |
|
| 1078 | - return false; |
|
| 1079 | - } else { |
|
| 1080 | - return true; |
|
| 1081 | - } |
|
| 1082 | - } else { |
|
| 1083 | - if ($id_auteur = (int) $id) { |
|
| 1084 | - $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1085 | - if ($t && $t['statut'] != '0minirezo') { |
|
| 1086 | - return true; |
|
| 1087 | - } else { |
|
| 1088 | - return false; |
|
| 1089 | - } |
|
| 1090 | - } else { |
|
| 1091 | - // id = 0 => creation |
|
| 1092 | - return true; |
|
| 1093 | - } |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1099 | - if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1100 | - return false; |
|
| 1101 | - } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1102 | - // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1103 | - return false; |
|
| 1104 | - } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1105 | - // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1106 | - return false; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - return true; |
|
| 1054 | + $id = (int) $id; |
|
| 1055 | + |
|
| 1056 | + // Si pas admin : seulement le droit de modifier ses donnees perso, mais pas statut ni login |
|
| 1057 | + // la modif de l'email doit etre verifiee ou notifiee si possible, mais c'est a l'interface de gerer ca |
|
| 1058 | + if ($qui['statut'] != '0minirezo') { |
|
| 1059 | + return $id == $qui['id_auteur'] |
|
| 1060 | + && empty($opt['statut']) |
|
| 1061 | + && empty($opt['webmestre']) |
|
| 1062 | + && empty($opt['restreintes']) |
|
| 1063 | + && empty($opt['login']); |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + // Un admin restreint peut modifier/creer un auteur non-admin mais il |
|
| 1067 | + // n'a le droit ni de le promouvoir admin, ni de changer les rubriques |
|
| 1068 | + if ($qui['restreint']) { |
|
| 1069 | + if (isset($opt['webmestre']) && $opt['webmestre']) { |
|
| 1070 | + return false; |
|
| 1071 | + } elseif ( |
|
| 1072 | + isset($opt['statut']) && $opt['statut'] === '0minirezo' || isset($opt['restreintes']) && $opt['restreintes'] |
|
| 1073 | + ) { |
|
| 1074 | + return false; |
|
| 1075 | + } else { |
|
| 1076 | + if ($id == $qui['id_auteur']) { |
|
| 1077 | + if (isset($opt['statut']) && $opt['statut']) { |
|
| 1078 | + return false; |
|
| 1079 | + } else { |
|
| 1080 | + return true; |
|
| 1081 | + } |
|
| 1082 | + } else { |
|
| 1083 | + if ($id_auteur = (int) $id) { |
|
| 1084 | + $t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur"); |
|
| 1085 | + if ($t && $t['statut'] != '0minirezo') { |
|
| 1086 | + return true; |
|
| 1087 | + } else { |
|
| 1088 | + return false; |
|
| 1089 | + } |
|
| 1090 | + } else { |
|
| 1091 | + // id = 0 => creation |
|
| 1092 | + return true; |
|
| 1093 | + } |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + // Un admin complet fait ce qu'il veut, sauf se degrader |
|
| 1099 | + if ($id == $qui['id_auteur'] && (isset($opt['statut']) && $opt['statut'])) { |
|
| 1100 | + return false; |
|
| 1101 | + } elseif (isset($opt['webmestre']) && $opt['webmestre'] && !autoriser('webmestre')) { |
|
| 1102 | + // et toucher au statut webmestre si il ne l'est pas lui même |
|
| 1103 | + return false; |
|
| 1104 | + } elseif ((int) $id && !autoriser('webmestre') && autoriser('webmestre', '', 0, $id)) { |
|
| 1105 | + // et modifier un webmestre si il ne l'est pas lui meme |
|
| 1106 | + return false; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + return true; |
|
| 1110 | 1110 | } |
| 1111 | 1111 | |
| 1112 | 1112 | |
@@ -1125,7 +1125,7 @@ discard block |
||
| 1125 | 1125 | * @return bool true s'il a le droit, false sinon |
| 1126 | 1126 | **/ |
| 1127 | 1127 | function autoriser_associerauteurs_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1128 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1128 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1129 | 1129 | } |
| 1130 | 1130 | |
| 1131 | 1131 | |
@@ -1144,7 +1144,7 @@ discard block |
||
| 1144 | 1144 | * @return bool true s'il a le droit, false sinon |
| 1145 | 1145 | **/ |
| 1146 | 1146 | function autoriser_chargerftp_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1147 | - return $qui['statut'] === '0minirezo'; |
|
| 1147 | + return $qui['statut'] === '0minirezo'; |
|
| 1148 | 1148 | } |
| 1149 | 1149 | |
| 1150 | 1150 | /** |
@@ -1162,7 +1162,7 @@ discard block |
||
| 1162 | 1162 | * @return bool true s'il a le droit, false sinon |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function autoriser_debug_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1165 | - return $qui['statut'] === '0minirezo'; |
|
| 1165 | + return $qui['statut'] === '0minirezo'; |
|
| 1166 | 1166 | } |
| 1167 | 1167 | |
| 1168 | 1168 | /** |
@@ -1179,53 +1179,53 @@ discard block |
||
| 1179 | 1179 | * @return array Liste des rubriques |
| 1180 | 1180 | **/ |
| 1181 | 1181 | function liste_rubriques_auteur($id_auteur, $raz = false) { |
| 1182 | - static $restreint = []; |
|
| 1183 | - |
|
| 1184 | - if (!$id_auteur = (int) $id_auteur) { |
|
| 1185 | - return []; |
|
| 1186 | - } |
|
| 1187 | - if ($raz) { |
|
| 1188 | - unset($restreint[$id_auteur]); |
|
| 1189 | - } elseif (isset($restreint[$id_auteur])) { |
|
| 1190 | - return $restreint[$id_auteur]; |
|
| 1191 | - } |
|
| 1192 | - |
|
| 1193 | - $rubriques = []; |
|
| 1194 | - if ( |
|
| 1195 | - (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1196 | - && ($r = sql_allfetsel( |
|
| 1197 | - 'id_objet', |
|
| 1198 | - 'spip_auteurs_liens', |
|
| 1199 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1200 | - )) |
|
| 1201 | - && (is_countable($r) ? count($r) : 0) |
|
| 1202 | - ) { |
|
| 1203 | - $r = array_column($r, 'id_objet'); |
|
| 1204 | - |
|
| 1205 | - // recuperer toute la branche, au format chaine enumeration |
|
| 1206 | - include_spip('inc/rubriques'); |
|
| 1207 | - $r = calcul_branche_in($r); |
|
| 1208 | - $r = explode(',', (string) $r); |
|
| 1209 | - |
|
| 1210 | - // passer les rubriques en index, elimine les doublons |
|
| 1211 | - $r = array_flip($r); |
|
| 1212 | - // recuperer les index seuls |
|
| 1213 | - $r = array_keys($r); |
|
| 1214 | - // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1215 | - // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1216 | - $rubriques = array_combine($r, $r); |
|
| 1217 | - } |
|
| 1218 | - |
|
| 1219 | - // Affecter l'auteur session le cas echeant |
|
| 1220 | - if ( |
|
| 1221 | - isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1222 | - && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1223 | - ) { |
|
| 1224 | - $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1225 | - } |
|
| 1226 | - |
|
| 1227 | - |
|
| 1228 | - return $restreint[$id_auteur] = $rubriques; |
|
| 1182 | + static $restreint = []; |
|
| 1183 | + |
|
| 1184 | + if (!$id_auteur = (int) $id_auteur) { |
|
| 1185 | + return []; |
|
| 1186 | + } |
|
| 1187 | + if ($raz) { |
|
| 1188 | + unset($restreint[$id_auteur]); |
|
| 1189 | + } elseif (isset($restreint[$id_auteur])) { |
|
| 1190 | + return $restreint[$id_auteur]; |
|
| 1191 | + } |
|
| 1192 | + |
|
| 1193 | + $rubriques = []; |
|
| 1194 | + if ( |
|
| 1195 | + (!isset($GLOBALS['meta']['version_installee']) || $GLOBALS['meta']['version_installee'] > 16428) |
|
| 1196 | + && ($r = sql_allfetsel( |
|
| 1197 | + 'id_objet', |
|
| 1198 | + 'spip_auteurs_liens', |
|
| 1199 | + 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1200 | + )) |
|
| 1201 | + && (is_countable($r) ? count($r) : 0) |
|
| 1202 | + ) { |
|
| 1203 | + $r = array_column($r, 'id_objet'); |
|
| 1204 | + |
|
| 1205 | + // recuperer toute la branche, au format chaine enumeration |
|
| 1206 | + include_spip('inc/rubriques'); |
|
| 1207 | + $r = calcul_branche_in($r); |
|
| 1208 | + $r = explode(',', (string) $r); |
|
| 1209 | + |
|
| 1210 | + // passer les rubriques en index, elimine les doublons |
|
| 1211 | + $r = array_flip($r); |
|
| 1212 | + // recuperer les index seuls |
|
| 1213 | + $r = array_keys($r); |
|
| 1214 | + // combiner pour avoir un tableau id_rubrique=>id_rubrique |
|
| 1215 | + // est-ce vraiment utile ? (on preserve la forme donnee par le code precedent) |
|
| 1216 | + $rubriques = array_combine($r, $r); |
|
| 1217 | + } |
|
| 1218 | + |
|
| 1219 | + // Affecter l'auteur session le cas echeant |
|
| 1220 | + if ( |
|
| 1221 | + isset($GLOBALS['visiteur_session']['id_auteur']) |
|
| 1222 | + && $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur |
|
| 1223 | + ) { |
|
| 1224 | + $GLOBALS['visiteur_session']['restreint'] = $rubriques; |
|
| 1225 | + } |
|
| 1226 | + |
|
| 1227 | + |
|
| 1228 | + return $restreint[$id_auteur] = $rubriques; |
|
| 1229 | 1229 | } |
| 1230 | 1230 | |
| 1231 | 1231 | /** |
@@ -1243,7 +1243,7 @@ discard block |
||
| 1243 | 1243 | * @return bool true s'il a le droit, false sinon |
| 1244 | 1244 | **/ |
| 1245 | 1245 | function autoriser_rubrique_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1246 | - return autoriser('previsualiser'); |
|
| 1246 | + return autoriser('previsualiser'); |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | /** |
@@ -1261,7 +1261,7 @@ discard block |
||
| 1261 | 1261 | * @return bool true s'il a le droit, false sinon |
| 1262 | 1262 | **/ |
| 1263 | 1263 | function autoriser_rubrique_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1264 | - return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1264 | + return autoriser('publierdans', 'rubrique', $id, $qui, $opt); |
|
| 1265 | 1265 | } |
| 1266 | 1266 | |
| 1267 | 1267 | /** |
@@ -1279,8 +1279,8 @@ discard block |
||
| 1279 | 1279 | * @return bool true s'il a le droit, false sinon |
| 1280 | 1280 | **/ |
| 1281 | 1281 | function autoriser_auteur_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1282 | - $id = (int) $id; |
|
| 1283 | - return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1282 | + $id = (int) $id; |
|
| 1283 | + return ($id == $qui['id_auteur'] || $qui['statut'] === '0minirezo' && !$qui['restreint']); |
|
| 1284 | 1284 | } |
| 1285 | 1285 | |
| 1286 | 1286 | /** |
@@ -1298,8 +1298,8 @@ discard block |
||
| 1298 | 1298 | * @return bool true s'il a le droit, false sinon |
| 1299 | 1299 | **/ |
| 1300 | 1300 | function autoriser_iconifier_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1301 | - // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1302 | - return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1301 | + // par defaut, on a le droit d'iconifier si on a le droit de modifier |
|
| 1302 | + return autoriser('modifier', $type, $id, $qui, $opt); |
|
| 1303 | 1303 | } |
| 1304 | 1304 | |
| 1305 | 1305 | |
@@ -1319,7 +1319,7 @@ discard block |
||
| 1319 | 1319 | * @return true |
| 1320 | 1320 | **/ |
| 1321 | 1321 | function autoriser_ok_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1322 | - return true; |
|
| 1322 | + return true; |
|
| 1323 | 1323 | } |
| 1324 | 1324 | |
| 1325 | 1325 | /** |
@@ -1338,7 +1338,7 @@ discard block |
||
| 1338 | 1338 | * @return false |
| 1339 | 1339 | **/ |
| 1340 | 1340 | function autoriser_niet_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1341 | - return false; |
|
| 1341 | + return false; |
|
| 1342 | 1342 | } |
| 1343 | 1343 | |
| 1344 | 1344 | /** |
@@ -1356,7 +1356,7 @@ discard block |
||
| 1356 | 1356 | * @return bool true s'il a le droit, false sinon |
| 1357 | 1357 | **/ |
| 1358 | 1358 | function autoriser_base_reparer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1359 | - return autoriser('detruire') && !_request('reinstall'); |
|
| 1359 | + return autoriser('detruire') && !_request('reinstall'); |
|
| 1360 | 1360 | } |
| 1361 | 1361 | |
| 1362 | 1362 | /** |
@@ -1374,7 +1374,7 @@ discard block |
||
| 1374 | 1374 | * @return true |
| 1375 | 1375 | **/ |
| 1376 | 1376 | function autoriser_infosperso_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1377 | - return true; |
|
| 1377 | + return true; |
|
| 1378 | 1378 | } |
| 1379 | 1379 | |
| 1380 | 1380 | /** |
@@ -1392,7 +1392,7 @@ discard block |
||
| 1392 | 1392 | * @return true |
| 1393 | 1393 | **/ |
| 1394 | 1394 | function autoriser_langage_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1395 | - return true; |
|
| 1395 | + return true; |
|
| 1396 | 1396 | } |
| 1397 | 1397 | |
| 1398 | 1398 | /** |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | * @return bool true s'il a le droit, false sinon |
| 1411 | 1411 | **/ |
| 1412 | 1412 | function autoriser_configurerlangage_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1413 | - return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1413 | + return autoriser('configurer', '_langage', $id, $qui, $opt); |
|
| 1414 | 1414 | } |
| 1415 | 1415 | |
| 1416 | 1416 | /** |
@@ -1428,7 +1428,7 @@ discard block |
||
| 1428 | 1428 | * @return true |
| 1429 | 1429 | **/ |
| 1430 | 1430 | function autoriser_preferences_configurer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1431 | - return true; |
|
| 1431 | + return true; |
|
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | /** |
@@ -1446,7 +1446,7 @@ discard block |
||
| 1446 | 1446 | * @return bool true s'il a le droit, false sinon |
| 1447 | 1447 | **/ |
| 1448 | 1448 | function autoriser_configurerpreferences_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1449 | - return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1449 | + return autoriser('configurer', '_preferences', $id, $qui, $opt); |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | /** |
@@ -1464,7 +1464,7 @@ discard block |
||
| 1464 | 1464 | * @return bool true s'il a le droit, false sinon |
| 1465 | 1465 | **/ |
| 1466 | 1466 | function autoriser_menudeveloppement_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1467 | - return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1467 | + return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev']) && $GLOBALS['visiteur_session']['prefs']['activer_menudev'] === 'oui'); |
|
| 1468 | 1468 | } |
| 1469 | 1469 | |
| 1470 | 1470 | /** |
@@ -1483,7 +1483,7 @@ discard block |
||
| 1483 | 1483 | * @return true |
| 1484 | 1484 | **/ |
| 1485 | 1485 | function autoriser_menugrandeentree_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1486 | - return true; |
|
| 1486 | + return true; |
|
| 1487 | 1487 | } |
| 1488 | 1488 | |
| 1489 | 1489 | /** |
@@ -1501,7 +1501,7 @@ discard block |
||
| 1501 | 1501 | * @return true |
| 1502 | 1502 | **/ |
| 1503 | 1503 | function autoriser_auteurs_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1504 | - return true; |
|
| 1504 | + return true; |
|
| 1505 | 1505 | } |
| 1506 | 1506 | |
| 1507 | 1507 | /** |
@@ -1519,7 +1519,7 @@ discard block |
||
| 1519 | 1519 | * @return bool true s'il a le droit, false sinon |
| 1520 | 1520 | **/ |
| 1521 | 1521 | function autoriser_auteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1522 | - return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1522 | + return autoriser('voir', '_auteurs', $id, $qui, $opt); |
|
| 1523 | 1523 | } |
| 1524 | 1524 | |
| 1525 | 1525 | /** |
@@ -1537,7 +1537,7 @@ discard block |
||
| 1537 | 1537 | * @return true |
| 1538 | 1538 | **/ |
| 1539 | 1539 | function autoriser_articles_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1540 | - return true; |
|
| 1540 | + return true; |
|
| 1541 | 1541 | } |
| 1542 | 1542 | |
| 1543 | 1543 | /** |
@@ -1555,7 +1555,7 @@ discard block |
||
| 1555 | 1555 | * @return bool true s'il a le droit, false sinon |
| 1556 | 1556 | **/ |
| 1557 | 1557 | function autoriser_articles_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1558 | - return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1558 | + return autoriser('voir', '_articles', $id, $qui, $opt); |
|
| 1559 | 1559 | } |
| 1560 | 1560 | |
| 1561 | 1561 | /** |
@@ -1573,7 +1573,7 @@ discard block |
||
| 1573 | 1573 | * @return true |
| 1574 | 1574 | **/ |
| 1575 | 1575 | function autoriser_rubriques_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1576 | - return true; |
|
| 1576 | + return true; |
|
| 1577 | 1577 | } |
| 1578 | 1578 | |
| 1579 | 1579 | /** |
@@ -1591,7 +1591,7 @@ discard block |
||
| 1591 | 1591 | * @return bool true s'il a le droit, false sinon |
| 1592 | 1592 | **/ |
| 1593 | 1593 | function autoriser_rubriques_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1594 | - return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1594 | + return autoriser('voir', '_rubriques', $id, $qui, $opt); |
|
| 1595 | 1595 | } |
| 1596 | 1596 | |
| 1597 | 1597 | /** |
@@ -1609,7 +1609,7 @@ discard block |
||
| 1609 | 1609 | * @return bool true s'il a le droit, false sinon |
| 1610 | 1610 | **/ |
| 1611 | 1611 | function autoriser_articlecreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1612 | - return verifier_table_non_vide(); |
|
| 1612 | + return verifier_table_non_vide(); |
|
| 1613 | 1613 | } |
| 1614 | 1614 | |
| 1615 | 1615 | |
@@ -1630,7 +1630,7 @@ discard block |
||
| 1630 | 1630 | * @return bool true s'il a le droit, false sinon |
| 1631 | 1631 | **/ |
| 1632 | 1632 | function autoriser_auteurcreer_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1633 | - return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1633 | + return autoriser('creer', 'auteur', $id, $qui, $opt); |
|
| 1634 | 1634 | } |
| 1635 | 1635 | |
| 1636 | 1636 | /** |
@@ -1648,11 +1648,11 @@ discard block |
||
| 1648 | 1648 | * @return bool true s'il a le droit, false sinon |
| 1649 | 1649 | **/ |
| 1650 | 1650 | function autoriser_visiteurs_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1651 | - include_spip('base/abstract_sql'); |
|
| 1652 | - return |
|
| 1653 | - $qui['statut'] === '0minirezo' |
|
| 1654 | - && !$qui['restreint'] |
|
| 1655 | - && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1651 | + include_spip('base/abstract_sql'); |
|
| 1652 | + return |
|
| 1653 | + $qui['statut'] === '0minirezo' |
|
| 1654 | + && !$qui['restreint'] |
|
| 1655 | + && ($GLOBALS['meta']['accepter_visiteurs'] != 'non' || sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0); |
|
| 1656 | 1656 | } |
| 1657 | 1657 | |
| 1658 | 1658 | /** |
@@ -1670,7 +1670,7 @@ discard block |
||
| 1670 | 1670 | * @return bool true s'il a le droit, false sinon |
| 1671 | 1671 | **/ |
| 1672 | 1672 | function autoriser_suiviedito_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1673 | - return $qui['statut'] === '0minirezo'; |
|
| 1673 | + return $qui['statut'] === '0minirezo'; |
|
| 1674 | 1674 | } |
| 1675 | 1675 | |
| 1676 | 1676 | /** |
@@ -1688,7 +1688,7 @@ discard block |
||
| 1688 | 1688 | * @return bool true s'il a le droit, false sinon |
| 1689 | 1689 | **/ |
| 1690 | 1690 | function autoriser_synchro_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1691 | - return $qui['statut'] === '0minirezo'; |
|
| 1691 | + return $qui['statut'] === '0minirezo'; |
|
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | /** |
@@ -1706,7 +1706,7 @@ discard block |
||
| 1706 | 1706 | * @return bool true s'il a le droit, false sinon |
| 1707 | 1707 | **/ |
| 1708 | 1708 | function autoriser_configurerinteractions_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1709 | - return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1709 | + return autoriser('configurer', '_interactions', $id, $qui, $opt); |
|
| 1710 | 1710 | } |
| 1711 | 1711 | |
| 1712 | 1712 | /** |
@@ -1724,7 +1724,7 @@ discard block |
||
| 1724 | 1724 | * @return bool true s'il a le droit, false sinon |
| 1725 | 1725 | **/ |
| 1726 | 1726 | function autoriser_configurerlangue_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1727 | - return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1727 | + return autoriser('configurer', '_langue', $id, $qui, $opt); |
|
| 1728 | 1728 | } |
| 1729 | 1729 | |
| 1730 | 1730 | /** |
@@ -1742,7 +1742,7 @@ discard block |
||
| 1742 | 1742 | * @return bool true s'il a le droit, false sinon |
| 1743 | 1743 | **/ |
| 1744 | 1744 | function autoriser_configurermultilinguisme_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1745 | - return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1745 | + return autoriser('configurer', '_multilinguisme', $id, $qui, $opt); |
|
| 1746 | 1746 | } |
| 1747 | 1747 | |
| 1748 | 1748 | /** |
@@ -1760,7 +1760,7 @@ discard block |
||
| 1760 | 1760 | * @return bool true s'il a le droit, false sinon |
| 1761 | 1761 | **/ |
| 1762 | 1762 | function autoriser_configurercontenu_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1763 | - return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1763 | + return autoriser('configurer', '_contenu', $id, $qui, $opt); |
|
| 1764 | 1764 | } |
| 1765 | 1765 | |
| 1766 | 1766 | /** |
@@ -1778,7 +1778,7 @@ discard block |
||
| 1778 | 1778 | * @return bool true s'il a le droit, false sinon |
| 1779 | 1779 | **/ |
| 1780 | 1780 | function autoriser_configureravancees_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1781 | - return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1781 | + return autoriser('configurer', '_avancees', $id, $qui, $opt); |
|
| 1782 | 1782 | } |
| 1783 | 1783 | |
| 1784 | 1784 | /** |
@@ -1796,7 +1796,7 @@ discard block |
||
| 1796 | 1796 | * @return bool true s'il a le droit, false sinon |
| 1797 | 1797 | **/ |
| 1798 | 1798 | function autoriser_adminplugin_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1799 | - return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1799 | + return autoriser('configurer', '_plugins', $id, $qui, $opt); |
|
| 1800 | 1800 | } |
| 1801 | 1801 | |
| 1802 | 1802 | /** |
@@ -1814,7 +1814,7 @@ discard block |
||
| 1814 | 1814 | * @return bool true s'il a le droit, false sinon |
| 1815 | 1815 | **/ |
| 1816 | 1816 | function autoriser_admintech_menu_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1817 | - return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1817 | + return autoriser('detruire', $type, $id, $qui, $opt); |
|
| 1818 | 1818 | } |
| 1819 | 1819 | |
| 1820 | 1820 | /** |
@@ -1832,7 +1832,7 @@ discard block |
||
| 1832 | 1832 | * @return bool true s'il a le droit, false sinon |
| 1833 | 1833 | **/ |
| 1834 | 1834 | function autoriser_queue_purger_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1835 | - return autoriser('webmestre'); |
|
| 1835 | + return autoriser('webmestre'); |
|
| 1836 | 1836 | } |
| 1837 | 1837 | |
| 1838 | 1838 | |
@@ -1852,11 +1852,11 @@ discard block |
||
| 1852 | 1852 | * @return bool true s'il a le droit, false sinon |
| 1853 | 1853 | **/ |
| 1854 | 1854 | function autoriser_echafauder_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1855 | - if (test_espace_prive()) { |
|
| 1856 | - return (bool) (int) $qui['id_auteur']; |
|
| 1857 | - } else { |
|
| 1858 | - return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1859 | - } |
|
| 1855 | + if (test_espace_prive()) { |
|
| 1856 | + return (bool) (int) $qui['id_auteur']; |
|
| 1857 | + } else { |
|
| 1858 | + return autoriser('webmestre', '', $id, $qui, $opt); |
|
| 1859 | + } |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | |
@@ -1871,27 +1871,27 @@ discard block |
||
| 1871 | 1871 | * Identifiants d'auteurs |
| 1872 | 1872 | */ |
| 1873 | 1873 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1874 | - $objet = objet_type($objet); |
|
| 1875 | - $where = [ |
|
| 1876 | - 'objet=' . sql_quote($objet), |
|
| 1877 | - 'id_objet=' . (int) $id_objet |
|
| 1878 | - ]; |
|
| 1879 | - if (!empty($cond)) { |
|
| 1880 | - if (is_array($cond)) { |
|
| 1881 | - $where = array_merge($where, $cond); |
|
| 1882 | - } else { |
|
| 1883 | - $where[] = $cond; |
|
| 1884 | - } |
|
| 1885 | - } |
|
| 1886 | - $auteurs = sql_allfetsel( |
|
| 1887 | - 'id_auteur', |
|
| 1888 | - 'spip_auteurs_liens', |
|
| 1889 | - $where |
|
| 1890 | - ); |
|
| 1891 | - if (is_array($auteurs)) { |
|
| 1892 | - return array_column($auteurs, 'id_auteur'); |
|
| 1893 | - } |
|
| 1894 | - return []; |
|
| 1874 | + $objet = objet_type($objet); |
|
| 1875 | + $where = [ |
|
| 1876 | + 'objet=' . sql_quote($objet), |
|
| 1877 | + 'id_objet=' . (int) $id_objet |
|
| 1878 | + ]; |
|
| 1879 | + if (!empty($cond)) { |
|
| 1880 | + if (is_array($cond)) { |
|
| 1881 | + $where = array_merge($where, $cond); |
|
| 1882 | + } else { |
|
| 1883 | + $where[] = $cond; |
|
| 1884 | + } |
|
| 1885 | + } |
|
| 1886 | + $auteurs = sql_allfetsel( |
|
| 1887 | + 'id_auteur', |
|
| 1888 | + 'spip_auteurs_liens', |
|
| 1889 | + $where |
|
| 1890 | + ); |
|
| 1891 | + if (is_array($auteurs)) { |
|
| 1892 | + return array_column($auteurs, 'id_auteur'); |
|
| 1893 | + } |
|
| 1894 | + return []; |
|
| 1895 | 1895 | } |
| 1896 | 1896 | |
| 1897 | 1897 | /** |
@@ -1904,7 +1904,7 @@ discard block |
||
| 1904 | 1904 | */ |
| 1905 | 1905 | function acces_restreint_rubrique($id_rubrique) { |
| 1906 | 1906 | |
| 1907 | - return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1907 | + return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique])); |
|
| 1908 | 1908 | } |
| 1909 | 1909 | |
| 1910 | 1910 | |
@@ -1917,12 +1917,12 @@ discard block |
||
| 1917 | 1917 | * @return bool true si un parent existe |
| 1918 | 1918 | */ |
| 1919 | 1919 | function verifier_table_non_vide($table = 'spip_rubriques') { |
| 1920 | - static $done = []; |
|
| 1921 | - if (!isset($done[$table])) { |
|
| 1922 | - $done[$table] = sql_countsel($table) > 0; |
|
| 1923 | - } |
|
| 1920 | + static $done = []; |
|
| 1921 | + if (!isset($done[$table])) { |
|
| 1922 | + $done[$table] = sql_countsel($table) > 0; |
|
| 1923 | + } |
|
| 1924 | 1924 | |
| 1925 | - return $done[$table]; |
|
| 1925 | + return $done[$table]; |
|
| 1926 | 1926 | } |
| 1927 | 1927 | |
| 1928 | 1928 | /** |
@@ -1949,12 +1949,12 @@ discard block |
||
| 1949 | 1949 | */ |
| 1950 | 1950 | function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) { |
| 1951 | 1951 | |
| 1952 | - $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1953 | - return match ($s) { |
|
| 1954 | - 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1955 | - 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1956 | - default => false, |
|
| 1957 | - }; |
|
| 1952 | + $s = array_search($quoi, $GLOBALS['liste_des_statuts']); |
|
| 1953 | + return match ($s) { |
|
| 1954 | + 'info_redacteurs' => $GLOBALS['meta']['accepter_inscriptions'] === 'oui', |
|
| 1955 | + 'info_visiteurs' => $GLOBALS['meta']['accepter_visiteurs'] === 'oui' || $GLOBALS['meta']['forums_publics'] === 'abo', |
|
| 1956 | + default => false, |
|
| 1957 | + }; |
|
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | /** |
@@ -1972,7 +1972,7 @@ discard block |
||
| 1972 | 1972 | * @return bool true s'il a le droit, false sinon |
| 1973 | 1973 | **/ |
| 1974 | 1974 | function autoriser_inscription_relancer_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1975 | - return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1975 | + return $qui['statut'] === '0minirezo' && !$qui['restreint']; |
|
| 1976 | 1976 | } |
| 1977 | 1977 | |
| 1978 | 1978 | /** |
@@ -1990,5 +1990,5 @@ discard block |
||
| 1990 | 1990 | * @return bool true s'il a le droit, false sinon |
| 1991 | 1991 | **/ |
| 1992 | 1992 | function autoriser_phpinfos_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 1993 | - return autoriser('webmestre'); |
|
| 1993 | + return autoriser('webmestre'); |
|
| 1994 | 1994 | } |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | // mais apres la fonction autoriser() |
| 120 | 120 | if ($f = find_in_path('mes_fonctions.php')) { |
| 121 | 121 | global $dossier_squelettes; |
| 122 | - include_once(_ROOT_CWD . $f); |
|
| 122 | + include_once(_ROOT_CWD.$f); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | $qui = $GLOBALS['visiteur_session'] ?: []; |
| 161 | 161 | $qui = array_merge(['statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'], $qui); |
| 162 | 162 | } elseif (is_numeric($qui)) { |
| 163 | - $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui); |
|
| 163 | + $qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur='.$qui); |
|
| 164 | 164 | if (!$qui) { |
| 165 | 165 | return false; |
| 166 | 166 | } |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | spip_log( |
| 176 | - "autoriser $faire $type $id (" . ($qui['nom'] ?? '') . ') ?', |
|
| 177 | - 'autoriser' . _LOG_DEBUG |
|
| 176 | + "autoriser $faire $type $id (".($qui['nom'] ?? '').') ?', |
|
| 177 | + 'autoriser'._LOG_DEBUG |
|
| 178 | 178 | ); |
| 179 | 179 | |
| 180 | 180 | $type = autoriser_type($type); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | isset($GLOBALS['autoriser_exception'][$faire][$type][$id]) |
| 185 | 185 | && autoriser_exception($faire, $type, $id, 'verifier') || isset($GLOBALS['autoriser_exception'][$faire][$type]['*']) && autoriser_exception($faire, $type, '*', 'verifier') |
| 186 | 186 | ) { |
| 187 | - spip_log("autoriser ($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG); |
|
| 187 | + spip_log("autoriser ($faire, $type, $id, ".($qui['nom'] ?? '').') : OK Exception', 'autoriser'._LOG_DEBUG); |
|
| 188 | 188 | return true; |
| 189 | 189 | } |
| 190 | 190 | |
@@ -193,18 +193,18 @@ discard block |
||
| 193 | 193 | // autoriser_faire[_dist], autoriser_defaut[_dist] |
| 194 | 194 | $fonctions = $type |
| 195 | 195 | ? [ |
| 196 | - 'autoriser_' . $type . '_' . $faire, |
|
| 197 | - 'autoriser_' . $type . '_' . $faire . '_dist', |
|
| 198 | - 'autoriser_' . $type, |
|
| 199 | - 'autoriser_' . $type . '_dist', |
|
| 200 | - 'autoriser_' . $faire, |
|
| 201 | - 'autoriser_' . $faire . '_dist', |
|
| 196 | + 'autoriser_'.$type.'_'.$faire, |
|
| 197 | + 'autoriser_'.$type.'_'.$faire.'_dist', |
|
| 198 | + 'autoriser_'.$type, |
|
| 199 | + 'autoriser_'.$type.'_dist', |
|
| 200 | + 'autoriser_'.$faire, |
|
| 201 | + 'autoriser_'.$faire.'_dist', |
|
| 202 | 202 | 'autoriser_defaut', |
| 203 | 203 | 'autoriser_defaut_dist' |
| 204 | 204 | ] |
| 205 | 205 | : [ |
| 206 | - 'autoriser_' . $faire, |
|
| 207 | - 'autoriser_' . $faire . '_dist', |
|
| 206 | + 'autoriser_'.$faire, |
|
| 207 | + 'autoriser_'.$faire.'_dist', |
|
| 208 | 208 | 'autoriser_defaut', |
| 209 | 209 | 'autoriser_defaut_dist' |
| 210 | 210 | ]; |
@@ -218,8 +218,8 @@ discard block |
||
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | spip_log( |
| 221 | - "$f($faire, $type, $id, " . ($qui['nom'] ?? '') . ') : ' . ($a ? 'OK' : 'niet'), |
|
| 222 | - 'autoriser' . _LOG_DEBUG |
|
| 221 | + "$f($faire, $type, $id, ".($qui['nom'] ?? '').') : '.($a ? 'OK' : 'niet'), |
|
| 222 | + 'autoriser'._LOG_DEBUG |
|
| 223 | 223 | ); |
| 224 | 224 | |
| 225 | 225 | if (!is_bool($a)) { |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | function autoriser_previsualiser_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 386 | 386 | |
| 387 | 387 | // Le visiteur a-t-il un statut prevu par la config ? |
| 388 | - if (str_contains((string) $GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',')) { |
|
| 388 | + if (str_contains((string) $GLOBALS['meta']['preview'], ','.$qui['statut'].',')) { |
|
| 389 | 389 | return test_previsualiser_objet_champ($type, $id, $qui, $opt); |
| 390 | 390 | } |
| 391 | 391 | |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | } // pas de champ passe a la demande => NIET |
| 440 | 440 | $previsu = explode(',', (string) $c['previsu']); |
| 441 | 441 | // regarder si ce statut est autorise pour l'auteur |
| 442 | - if (in_array($opt[$champ] . '/auteur', $previsu)) { |
|
| 442 | + if (in_array($opt[$champ].'/auteur', $previsu)) { |
|
| 443 | 443 | // retrouver l’id_auteur qui a filé un lien de prévisu éventuellement, |
| 444 | 444 | // sinon l’auteur en session |
| 445 | 445 | include_spip('inc/securiser_action'); |
@@ -453,12 +453,12 @@ discard block |
||
| 453 | 453 | |
| 454 | 454 | if (!$id_auteur) { |
| 455 | 455 | return false; |
| 456 | - } elseif (autoriser('previsualiser' . $opt[$champ], $type, 0, $id_auteur)) { |
|
| 456 | + } elseif (autoriser('previsualiser'.$opt[$champ], $type, 0, $id_auteur)) { |
|
| 457 | 457 | // dans ce cas (admin en general), pas de filtrage sur ce statut |
| 458 | 458 | } elseif ( |
| 459 | 459 | !sql_countsel( |
| 460 | 460 | 'spip_auteurs_liens', |
| 461 | - 'id_auteur=' . (int) $id_auteur . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . (int) $id |
|
| 461 | + 'id_auteur='.(int) $id_auteur.' AND objet='.sql_quote($type).' AND id_objet='.(int) $id |
|
| 462 | 462 | ) |
| 463 | 463 | ) { |
| 464 | 464 | return false; |
@@ -503,14 +503,14 @@ discard block |
||
| 503 | 503 | // multilinguisme par secteur et objet rattaché à une rubrique |
| 504 | 504 | $primary = id_table_objet($type); |
| 505 | 505 | $id_rubrique = $table != 'spip_rubriques' |
| 506 | - ? sql_getfetsel('id_rubrique', "$table", "$primary=" . (int) $id) |
|
| 506 | + ? sql_getfetsel('id_rubrique', "$table", "$primary=".(int) $id) |
|
| 507 | 507 | : $id; |
| 508 | - $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 508 | + $id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 509 | 509 | if (!$id_secteur > 0) { |
| 510 | 510 | $id_secteur = $id_rubrique; |
| 511 | 511 | } |
| 512 | - $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . (int) $id_secteur); |
|
| 513 | - $langue_objet = sql_getfetsel('lang', "$table", "$primary=" . (int) $id); |
|
| 512 | + $langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique='.(int) $id_secteur); |
|
| 513 | + $langue_objet = sql_getfetsel('lang', "$table", "$primary=".(int) $id); |
|
| 514 | 514 | if ($langue_secteur != $langue_objet) { |
| 515 | 515 | // configuration incohérente, on laisse l'utilisateur corriger la situation |
| 516 | 516 | return true; |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques |
| 519 | 519 | return false; |
| 520 | 520 | } else { |
| 521 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id); |
|
| 521 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique='.(int) $id); |
|
| 522 | 522 | if ($id_parent != 0) { |
| 523 | 523 | // sous-rubriques : pas de choix de langue |
| 524 | 524 | return false; |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | |
| 571 | 571 | if (!isset($opt['statut'])) { |
| 572 | 572 | if (isset($desc['field']['statut'])) { |
| 573 | - $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . (int) $id); |
|
| 573 | + $statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type).'='.(int) $id); |
|
| 574 | 574 | } else { |
| 575 | 575 | $statut = 'publie'; |
| 576 | 576 | } // pas de statut => publie |
@@ -735,11 +735,11 @@ discard block |
||
| 735 | 735 | return false; |
| 736 | 736 | } |
| 737 | 737 | |
| 738 | - if (sql_countsel('spip_rubriques', 'id_parent=' . (int) $id)) { |
|
| 738 | + if (sql_countsel('spip_rubriques', 'id_parent='.(int) $id)) { |
|
| 739 | 739 | return false; |
| 740 | 740 | } |
| 741 | 741 | |
| 742 | - if (sql_countsel('spip_articles', 'id_rubrique=' . (int) $id . " AND (statut<>'poubelle')")) { |
|
| 742 | + if (sql_countsel('spip_articles', 'id_rubrique='.(int) $id." AND (statut<>'poubelle')")) { |
|
| 743 | 743 | return false; |
| 744 | 744 | } |
| 745 | 745 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | if (!$id) { |
| 777 | 777 | return false; |
| 778 | 778 | } |
| 779 | - $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id)); |
|
| 779 | + $r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article='.sql_quote($id)); |
|
| 780 | 780 | |
| 781 | 781 | return $r && ( |
| 782 | 782 | autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt) |
@@ -784,7 +784,7 @@ discard block |
||
| 784 | 784 | (!isset($opt['statut']) || !in_array($opt['statut'], ['publie', 'refuse'], true)) |
| 785 | 785 | && in_array($qui['statut'], ['0minirezo', '1comite']) |
| 786 | 786 | && in_array($r['statut'], ['prop', 'prepa', 'poubelle']) |
| 787 | - && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']) |
|
| 787 | + && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']) |
|
| 788 | 788 | ) |
| 789 | 789 | ); |
| 790 | 790 | } |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | if (!$id) { |
| 843 | 843 | return false; |
| 844 | 844 | } |
| 845 | - $statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . (int) $id); |
|
| 845 | + $statut = sql_getfetsel('statut', 'spip_articles', 'id_article='.(int) $id); |
|
| 846 | 846 | } |
| 847 | 847 | |
| 848 | 848 | return |
@@ -851,7 +851,7 @@ discard block |
||
| 851 | 851 | in_array($statut, ['prop', 'publie']) |
| 852 | 852 | // sinon si on est auteur, on a le droit de le voir, evidemment ! |
| 853 | 853 | |
| 854 | - || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']); |
|
| 854 | + || $id && $qui['id_auteur'] && auteurs_objet('article', $id, 'id_auteur='.$qui['id_auteur']); |
|
| 855 | 855 | } |
| 856 | 856 | |
| 857 | 857 | |
@@ -872,8 +872,8 @@ discard block |
||
| 872 | 872 | function autoriser_voir_dist(string $faire, string $type, $id, array $qui, array $opt): bool { |
| 873 | 873 | # securite, mais on aurait pas du arriver ici ! |
| 874 | 874 | if ( |
| 875 | - function_exists($f = 'autoriser_' . $type . '_voir') |
|
| 876 | - || function_exists($f = 'autoriser_' . $type . '_voir_dist') |
|
| 875 | + function_exists($f = 'autoriser_'.$type.'_voir') |
|
| 876 | + || function_exists($f = 'autoriser_'.$type.'_voir_dist') |
|
| 877 | 877 | ) { |
| 878 | 878 | return $f($faire, $type, $id, $qui, $opt); |
| 879 | 879 | } |
@@ -998,7 +998,7 @@ discard block |
||
| 998 | 998 | $n = sql_fetsel( |
| 999 | 999 | 'A.id_article', |
| 1000 | 1000 | 'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)', |
| 1001 | - "A.statut='publie' AND L.id_auteur=" . sql_quote($id) |
|
| 1001 | + "A.statut='publie' AND L.id_auteur=".sql_quote($id) |
|
| 1002 | 1002 | ); |
| 1003 | 1003 | |
| 1004 | 1004 | return (bool) $n; |
@@ -1196,7 +1196,7 @@ discard block |
||
| 1196 | 1196 | && ($r = sql_allfetsel( |
| 1197 | 1197 | 'id_objet', |
| 1198 | 1198 | 'spip_auteurs_liens', |
| 1199 | - 'id_auteur=' . (int) $id_auteur . " AND objet='rubrique' AND id_objet!=0" |
|
| 1199 | + 'id_auteur='.(int) $id_auteur." AND objet='rubrique' AND id_objet!=0" |
|
| 1200 | 1200 | )) |
| 1201 | 1201 | && (is_countable($r) ? count($r) : 0) |
| 1202 | 1202 | ) { |
@@ -1873,8 +1873,8 @@ discard block |
||
| 1873 | 1873 | function auteurs_objet($objet, $id_objet, $cond = '') { |
| 1874 | 1874 | $objet = objet_type($objet); |
| 1875 | 1875 | $where = [ |
| 1876 | - 'objet=' . sql_quote($objet), |
|
| 1877 | - 'id_objet=' . (int) $id_objet |
|
| 1876 | + 'objet='.sql_quote($objet), |
|
| 1877 | + 'id_objet='.(int) $id_objet |
|
| 1878 | 1878 | ]; |
| 1879 | 1879 | if (!empty($cond)) { |
| 1880 | 1880 | if (is_array($cond)) { |