Completed
Push — master ( 1d2283...7fdd0e )
by cam
04:59
created

autoriser.php ➔ autoriser_phpinfos()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 5
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Système de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright © avec tendresse depuis 2001                                 *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Rivière, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribué sous licence GNU/GPL.     *
10
 *  Pour plus de détails voir le fichier COPYING.txt ou l'aide en ligne.   *
11
\***************************************************************************/
12
13
/**
14
 * Gestion de l'API autoriser et fonctions d'autorisations de SPIP
15
 *
16
 * @package SPIP\Core\Autorisations
17
 **/
18
if (!defined('_ECRIRE_INC_VERSION')) {
19
	return;
20
}
21
22
include_spip('base/abstract_sql');
23
24
// Constantes surchargeables, cf. plugin autorite
25
26
/**
27
 * Gérer les admins restreints ?
28
 *
29
 * @todo une option à activer
30
 */
31
defined('_ADMINS_RESTREINTS') || define('_ADMINS_RESTREINTS', true);
32
33
/** Statut par defaut à la creation */
34
defined('_STATUT_AUTEUR_CREATION') || define('_STATUT_AUTEUR_CREATION', '1comite');
35
36
/** statuts associables a des rubriques (separes par des virgules) */
37
defined('_STATUT_AUTEUR_RUBRIQUE') || define('_STATUT_AUTEUR_RUBRIQUE', _ADMINS_RESTREINTS ? '0minirezo' : '');
38
39
40
if (!function_exists('autoriser')) {
41
	/**
42
	 * Autoriser une action
43
	 *
44
	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
45
	 * une certaine action. Cette fonction est le point d'entrée de toutes
46
	 * les autorisations.
47
	 *
48
	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
49
	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
50
	 * dans cet ordre :
51
	 *
52
	 * - autoriser_{type}_{faire}, sinon avec _dist
53
	 * - autoriser_{type}, sinon avec _dist
54
	 * - autoriser_{faire}, sinon avec _dist
55
	 * - autoriser_{defaut}, sinon avec _dist
56
	 *
57
	 * Seul le premier argument est obligatoire.
58
	 *
59
	 * @note
60
	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
61
	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
62
	 *     cette valeur.
63
	 *
64
	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
65
	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
66
	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
67
	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
68
	 *
69
	 * @note
70
	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
71
	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
72
	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
73
	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
74
	 *     quel serait le type, quel serait l'action ?
75
	 *
76
	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
77
	 *     la fonction d'autorisation correspondante ne l'aura pas.
78
	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
79
	 *
80
	 * @api
81
	 * @see autoriser_dist()
82
	 *
83
	 * @param string $faire
84
	 *   une action ('modifier', 'publier'...)
85
	 * @param string $type
86
	 *   type d'objet ou nom de table ('article')
87
	 * @param int $id
88
	 *   id de l'objet sur lequel on veut agir
89
	 * @param null|int|array $qui
90
	 *   - si null on prend alors visiteur_session
91
	 *   - un id_auteur (on regarde dans la base)
92
	 *   - un tableau auteur complet, y compris [restreint]
93
	 * @param null|array $opt
94
	 *   options sous forme de tableau associatif
95
	 * @return bool
96
	 *   true si la personne peut effectuer l'action
97
	 */
98
	function autoriser($faire, $type = '', $id = 0, $qui = null, $opt = null) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99
		// Charger les fonctions d'autorisation supplementaires
100
		static $pipe;
101
		if (!isset($pipe)) {
102
			$pipe = 1;
103
			pipeline('autoriser');
104
		}
105
106
		$args = func_get_args();
107
108
		return call_user_func_array('autoriser_dist', $args);
109
	}
110
}
111
112
113
// mes_fonctions peut aussi declarer des autorisations, il faut donc le charger
114
// mais apres la fonction autoriser()
115
if ($f = find_in_path('mes_fonctions.php')) {
116
	global $dossier_squelettes;
117
	include_once(_ROOT_CWD . $f);
118
}
119
120
121
/**
122
 * Autoriser une action
123
 *
124
 * Voir autoriser() pour une description complète
125
 *
126
 * @see autoriser()
127
 *
128
 * @param string $faire
129
 *   une action ('modifier', 'publier'...)
130
 * @param string $type
131
 *   type d'objet ou nom de table ('article')
132
 * @param int $id
133
 *   id de l'objet sur lequel on veut agir
134
 * @param null|int|array $qui
135
 *   si null on prend alors visiteur_session
136
 *   un id_auteur (on regarde dans la base)
137
 *   un tableau auteur complet, y compris [restreint]
138
 * @param null|array $opt
139
 *   options sous forme de tableau associatif
140
 * @return bool
141
 *   true si la personne peut effectuer l'action
142
 */
143
function autoriser_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) {
144
145
	// Qui ? visiteur_session ?
146
	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
147
	if ($qui === null or $qui === '') {
148
		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
149
		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
150
	} elseif (is_numeric($qui)) {
151
		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
152
	}
153
154
	// Admins restreints, on construit ici (pas generique mais...)
155
	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
156
	if (_ADMINS_RESTREINTS and is_array($qui)) {
157
		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
158
	}
159
160
	spip_log(
161
		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
162
		'autoriser' . _LOG_DEBUG
163
	);
164
165
	// passer par objet_type pour avoir les alias
166
	// et supprimer les _
167
	$type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
168
169
	// Si une exception a ete decretee plus haut dans le code, l'appliquer
170
	if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
171
		and autoriser_exception($faire, $type, $id, 'verifier')
172
	) {
173
		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
174
		return true;
175
	}
176
177
	// Chercher une fonction d'autorisation
178
	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
179
	// autoriser_faire[_dist], autoriser_defaut[_dist]
180
	$fonctions = $type
181
		? array(
182
			'autoriser_' . $type . '_' . $faire,
183
			'autoriser_' . $type . '_' . $faire . '_dist',
184
			'autoriser_' . $type,
185
			'autoriser_' . $type . '_dist',
186
			'autoriser_' . $faire,
187
			'autoriser_' . $faire . '_dist',
188
			'autoriser_defaut',
189
			'autoriser_defaut_dist'
190
		)
191
		: array(
192
			'autoriser_' . $faire,
193
			'autoriser_' . $faire . '_dist',
194
			'autoriser_defaut',
195
			'autoriser_defaut_dist'
196
		);
197
198
	foreach ($fonctions as $f) {
199
		if (function_exists($f)) {
200
			$a = $f($faire, $type, $id, $qui, $opt);
201
			break;
202
		}
203
	}
204
205
	spip_log(
206
		"$f($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : ' . ($a ? 'OK' : 'niet'),
0 ignored issues
show
Bug introduced by
The variable $f seems to be defined by a foreach iteration on line 198. Are you sure the iterator is never empty, otherwise this variable is not defined?

It seems like you are relying on a variable being defined by an iteration:

foreach ($a as $b) {
}

// $b is defined here only if $a has elements, for example if $a is array()
// then $b would not be defined here. To avoid that, we recommend to set a
// default value for $b.


// Better
$b = 0; // or whatever default makes sense in your context
foreach ($a as $b) {
}

// $b is now guaranteed to be defined here.
Loading history...
Bug introduced by
The variable $a does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
207
		'autoriser' . _LOG_DEBUG
208
	);
209
210
	return $a;
211
}
212
213
// une globale pour aller au plus vite dans la fonction generique ci dessus
214
$GLOBALS['autoriser_exception'] = array();
215
216
/**
217
 * Accorder une autorisation exceptionnel pour le hit en cours, ou la revoquer
218
 *
219
 * https://code.spip.net/@autoriser_exception
220
 *
221
 * @param string $faire Action demandée
222
 * @param string $type Type d'objet sur lequel appliquer l'action
223
 * @param int $id Identifiant de l'objet
224
 * @param bool $autoriser accorder (true) ou revoquer (false)
225
 * @return bool
226
 */
227
function autoriser_exception($faire, $type, $id, $autoriser = true) {
228
	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
229
	static $autorisation;
230
	if ($autoriser === 'verifier') {
231
		return isset($autorisation[$faire][$type][$id]);
232
	}
233
	if ($autoriser === true) {
234
		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
235
	}
236
	if ($autoriser === false) {
237
		unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
238
		unset($autorisation[$faire][$type][$id]);
239
	}
240
241
	return false;
242
}
243
244
245
/**
246
 * Autorisation par defaut
247
 *
248
 * Les admins complets OK, les autres non
249
 *
250
 * @param  string $faire Action demandée
251
 * @param  string $type Type d'objet sur lequel appliquer l'action
252
 * @param  int $id Identifiant de l'objet
253
 * @param  array $qui Description de l'auteur demandant l'autorisation
254
 * @param  array $opt Options de cette autorisation
255
 * @return bool          true s'il a le droit, false sinon
256
 **/
257
function autoriser_defaut_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
258
	return
259
		$qui['statut'] == '0minirezo'
260
		and !$qui['restreint'];
261
}
262
263
/**
264
 * Autorisation a se loger ? Retourne true pour tous les statuts sauf 5poubelle
265
 * Peut etre surchargee pour interdire statut=nouveau a se connecter
266
 * et forcer l'utilisation du lien de confirmation email pour valider le compte
267
 *
268
 * @param $faire
269
 * @param $type
270
 * @param $id
271
 * @param $qui
272
 * @param $opt
273
 * @return bool
274
 */
275
function autoriser_loger_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
276
	if ($qui['statut'] == '5poubelle') {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !($qui['statut'] == '5poubelle');.
Loading history...
277
		return false;
278
	}
279
	return true;
280
}
281
282
/**
283
 * Autorisation d'accès à l'espace privé ?
284
 *
285
 * @param  string $faire Action demandée
286
 * @param  string $type Type d'objet sur lequel appliquer l'action
287
 * @param  int $id Identifiant de l'objet
288
 * @param  array $qui Description de l'auteur demandant l'autorisation
289
 * @param  array $opt Options de cette autorisation
290
 * @return bool          true s'il a le droit, false sinon
291
 **/
292
function autoriser_ecrire_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
293
	return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
294
}
295
296
/**
297
 * Autorisation de créer un contenu
298
 *
299
 * Accordée par defaut ceux qui accèdent à l'espace privé,
300
 * peut-être surchargée au cas par cas
301
 *
302
 * @param  string $faire Action demandée
303
 * @param  string $type Type d'objet sur lequel appliquer l'action
304
 * @param  int $id Identifiant de l'objet
305
 * @param  array $qui Description de l'auteur demandant l'autorisation
306
 * @param  array $opt Options de cette autorisation
307
 * @return bool          true s'il a le droit, false sinon
308
 **/
309
function autoriser_creer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
310
	return in_array($qui['statut'], array('0minirezo', '1comite'));
311
}
312
313
/**
314
 * Autorisation de prévisualiser un contenu
315
 *
316
 * @uses test_previsualiser_objet_champ()
317
 * @uses decrire_token_previsu()
318
 *
319
 * @param  string $faire Action demandée
320
 * @param  string $type Type d'objet sur lequel appliquer l'action
321
 * @param  int $id Identifiant de l'objet
322
 * @param  array $qui Description de l'auteur demandant l'autorisation
323
 * @param  array $opt Options de cette autorisation
324
 * @return bool          true s'il a le droit, false sinon
325
 **/
326
function autoriser_previsualiser_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
327
328
	// Le visiteur a-t-il un statut prevu par la config ?
329
	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
330
		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
331
	}
332
333
	// A-t-on un token de prévisualisation valable ?
334
	include_spip('inc/securiser_action');
335
	if (decrire_token_previsu()) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return (bool) decrire_token_previsu();.
Loading history...
336
		return true;
337
	}
338
339
	return false;
340
}
341
342
/**
343
 * Teste qu'un objet éditorial peut être prévisualisé
344
 *
345
 * Cela permet ainsi de commander l'affichage dans l'espace prive du bouton "previsualiser"
346
 * voir `prive/objets/infos/article.html` etc.
347
 *
348
 * Cela dépend du statut actuel de l'objet d'une part, et d'autre part de la
349
 * clé `previsu` dans le tableau `statut` de la déclaration de l'objet éditorial.
350
 * Cette clé `previsu` liste des statuts, séparés par des virgules,
351
 * qui ont le droit d'avoir une prévisualisation. La présence de `xx/auteur` indique que pour le
352
 * statut `xx`, l'auteur en cours doit être un des auteurs de l'objet éditorial en question
353
 * pour que ce statut autorise la prévisualisation.
354
 *
355
 * Exemple pour les articles : `'previsu' => 'publie,prop,prepa/auteur',`
356
 *
357
 * @uses lister_tables_objets_sql()
358
 *
359
 * @param  string $type Type d'objet sur lequel appliquer l'action
0 ignored issues
show
Documentation introduced by
Should the type for parameter $type not be string|null?

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
360
 * @param  int $id Identifiant de l'objet
361
 * @param  array $qui Description de l'auteur demandant l'autorisation
362
 * @param  array $opt Options de cette autorisation
363
 * @return boolean True si autorisé, false sinon.
364
 */
365
function test_previsualiser_objet_champ($type = null, $id = 0, $qui = array(), $opt = array()) {
0 ignored issues
show
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
366
367
	// si pas de type et statut fourni, c'est une autorisation generale => OK
368
	if (!$type) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $type of type string|null is loosely compared to false; this is ambiguous if the string can be empty. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For string values, the empty string '' is a special case, in particular the following results might be unexpected:

''   == false // true
''   == null  // true
'ab' == false // false
'ab' == null  // false

// It is often better to use strict comparison
'' === false // false
'' === null  // false
Loading history...
369
		return true;
370
	}
371
372
	include_spip('base/objets');
373
	$infos = lister_tables_objets_sql(table_objet_sql($type));
374
	if (isset($infos['statut'])) {
375
		foreach ($infos['statut'] as $c) {
376
			if (isset($c['publie'])) {
377
				if (!isset($c['previsu'])) {
378
					return false;
379
				} // pas de previsu definie => NIET
380
				$champ = $c['champ'];
381
				if (!isset($opt[$champ])) {
382
					return false;
383
				} // pas de champ passe a la demande => NIET
384
				$previsu = explode(',', $c['previsu']);
385
				// regarder si ce statut est autorise pour l'auteur
386
				if (in_array($opt[$champ] . '/auteur', $previsu)) {
387
388
					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
389
					// sinon l’auteur en session
390
					include_spip('inc/securiser_action');
391 View Code Duplication
					if ($desc = decrire_token_previsu()) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
392
						$id_auteur = $desc['id_auteur'];
393
					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
394
						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
395
					} else {
396
						$id_auteur = null;
397
					}
398
399
					if (!$id_auteur) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $id_auteur of type integer|null is loosely compared to false; this is ambiguous if the integer can be zero. You might want to explicitly use === null instead.

In PHP, under loose comparison (like ==, or !=, or switch conditions), values of different types might be equal.

For integer values, zero is a special case, in particular the following results might be unexpected:

0   == false // true
0   == null  // true
123 == false // false
123 == null  // false

// It is often better to use strict comparison
0 === false // false
0 === null  // false
Loading history...
400
						return false;
401
					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
402
						// dans ce cas (admin en general), pas de filtrage sur ce statut
403
					} elseif (!sql_countsel(
404
						'spip_auteurs_liens',
405
						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
406
					)) {
407
						return false;
408
					} // pas auteur de cet objet => NIET
409
				} elseif (!in_array($opt[$champ], $previsu)) {
410
					// le statut n'est pas dans ceux definis par la previsu => NIET
411
					return false;
412
				}
413
			}
414
		}
415
	}
416
417
	return true;
418
}
419
420
/**
421
 * Autorisation de changer de langue un contenu
422
 *
423
 * @param  string $faire Action demandée
424
 * @param  string $type Type d'objet sur lequel appliquer l'action
425
 * @param  int $id Identifiant de l'objet
426
 * @param  array $qui Description de l'auteur demandant l'autorisation
427
 * @param  array $opt Options de cette autorisation
428
 * @return bool          true s'il a le droit, false sinon
429
 **/
430
function autoriser_changerlangue_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
431
	$multi_objets = explode(',', lire_config('multi_objets'));
432
	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
433
	$table = table_objet_sql($type);
434
	if (in_array($table, $multi_objets)
435
		or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
436
		$multi_secteurs = lire_config('multi_secteurs');
437
		$champs = objet_info($type, 'field');
438
		if ($multi_secteurs == 'oui'
439
			and array_key_exists('id_rubrique', $champs)) {
440
			// multilinguisme par secteur et objet rattaché à une rubrique
441
			$primary = id_table_objet($type);
442
			if ($table != 'spip_rubriques') {
443
				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
444
			} else {
445
				$id_rubrique = $id;
446
			}
447
			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
448
			if (!$id_secteur > 0) {
449
				$id_secteur = $id_rubrique;
450
			}
451
			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
452
			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
453
			if ($langue_secteur != $langue_objet) {
454
				// configuration incohérente, on laisse l'utilisateur corriger la situation
455
				return true;
456
			}
457
			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
458
				return false;
459
			} else {
460
				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
461
				if ($id_parent != 0) {
462
					// sous-rubriques : pas de choix de langue
463
					return false;
464
				}
465
			}
466
		}
467
	} else {
468
		return false;
469
	}
470
471
	return autoriser('modifier', $type, $id, $qui, $opt);
472
}
473
474
/**
475
 * Autorisation de changer le lien de traduction
476
 *
477
 * @param  string $faire Action demandée
478
 * @param  string $type Type d'objet sur lequel appliquer l'action
479
 * @param  int $id Identifiant de l'objet
480
 * @param  array $qui Description de l'auteur demandant l'autorisation
481
 * @param  array $opt Options de cette autorisation
482
 * @return bool          true s'il a le droit, false sinon
483
 **/
484
function autoriser_changertraduction_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
485
	return autoriser('modifier', $type, $id, $qui, $opt);
486
}
487
488
/**
489
 * Autorisation de changer la date d'un contenu
490
 *
491
 * @param  string $faire Action demandée
492
 * @param  string $type Type d'objet sur lequel appliquer l'action
493
 * @param  int $id Identifiant de l'objet
494
 * @param  array $qui Description de l'auteur demandant l'autorisation
495
 * @param  array $opt Options de cette autorisation
496
 * @return bool          true s'il a le droit, false sinon
497
 **/
498
function autoriser_dater_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
499
	$table = table_objet($type);
500
	$trouver_table = charger_fonction('trouver_table', 'base');
501
	$desc = $trouver_table($table);
502
	if (!$desc) {
503
		return false;
504
	}
505
	
506
	if (!isset($opt['statut'])) {
507 View Code Duplication
		if (isset($desc['field']['statut'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
508
			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
509
		} else {
510
			$statut = 'publie';
511
		} // pas de statut => publie
512
	} else {
513
		$statut = $opt['statut'];
514
	}
515
	
516
	// Liste des statuts publiés pour cet objet
517
	if (isset($desc['statut'][0]['publie'])) {
518
		$statuts_publies = explode(',', $desc['statut'][0]['publie']);
519
	}
520
	// Sinon en dur le statut "publie"
521
	else {
522
		$statuts_publies = array('publie');
523
	}
524
	
525
	if (
526
		in_array($statut, $statuts_publies)
527
		// Ou cas particulier géré en dur ici pour les articles
528
		or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')
529
	) {
530
		return autoriser('modifier', $type, $id);
531
	}
532
533
	return false;
534
}
535
536
/**
537
 * Autorisation d'instituer un contenu
538
 *
539
 * C'est à dire de changer son statut ou son parent.
540
 * Par défaut, il faut l'autorisation de modifier le contenu
541
 *
542
 * @param  string $faire Action demandée
543
 * @param  string $type Type d'objet sur lequel appliquer l'action
544
 * @param  int $id Identifiant de l'objet
545
 * @param  array $qui Description de l'auteur demandant l'autorisation
546
 * @param  array $opt Options de cette autorisation
547
 * @return bool          true s'il a le droit, false sinon
548
 **/
549
function autoriser_instituer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
550
	return autoriser('modifier', $type, $id, $qui, $opt);
551
}
552
553
/**
554
 * Autorisation de publier dans une rubrique $id
555
 *
556
 * Il faut être administrateur ou administrateur restreint de la rubrique
557
 *
558
 * @param  string $faire Action demandée
559
 * @param  string $type Type d'objet sur lequel appliquer l'action
560
 * @param  int $id Identifiant de l'objet
561
 * @param  array $qui Description de l'auteur demandant l'autorisation
562
 * @param  array $opt Options de cette autorisation
563
 * @return bool          true s'il a le droit, false sinon
564
 **/
565
function autoriser_rubrique_publierdans_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
566
	return
567
		($qui['statut'] == '0minirezo')
568
		and (
569
			!$qui['restreint'] or !$id
570
			or in_array($id, $qui['restreint'])
571
		);
572
}
573
574
/**
575
 * Autorisation de créer une rubrique
576
 *
577
 * Il faut être administrateur pour pouvoir publier à la racine
578
 *
579
 * @param  string $faire Action demandée
580
 * @param  string $type Type d'objet sur lequel appliquer l'action
581
 * @param  int $id Identifiant de l'objet
582
 * @param  array $qui Description de l'auteur demandant l'autorisation
583
 * @param  array $opt Options de cette autorisation
584
 * @return bool          true s'il a le droit, false sinon
585
 **/
586
function autoriser_rubrique_creer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
587
	return
588
		((!$id and autoriser('defaut', null, null, $qui, $opt))
589
			or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt)
590
		);
591
}
592
593
/**
594
 * Autorisation de créer une sous rubrique dans une rubrique $id
595
 *
596
 * Il faut être administrateur et pouvoir publier dans la rubrique
597
 *
598
 * @param  string $faire Action demandée
599
 * @param  string $type Type d'objet sur lequel appliquer l'action
600
 * @param  int $id Identifiant de l'objet
601
 * @param  array $qui Description de l'auteur demandant l'autorisation
602
 * @param  array $opt Options de cette autorisation
603
 * @return bool          true s'il a le droit, false sinon
604
 **/
605
function autoriser_rubrique_creerrubriquedans_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
606
	return
607
		($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
608
		and autoriser('voir', 'rubrique', $id)
609
		and autoriser('publierdans', 'rubrique', $id);
610
}
611
612
/**
613
 * Autorisation de créer un article dans une rubrique $id
614
 *
615
 * Il faut pouvoir voir la rubrique et pouvoir créer un article…
616
 *
617
 * @param  string $faire Action demandée
618
 * @param  string $type Type d'objet sur lequel appliquer l'action
619
 * @param  int $id Identifiant de l'objet
620
 * @param  array $qui Description de l'auteur demandant l'autorisation
621
 * @param  array $opt Options de cette autorisation
622
 * @return bool          true s'il a le droit, false sinon
623
 **/
624
function autoriser_rubrique_creerarticledans_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
625
	return
626
		$id
627
		and autoriser('voir', 'rubrique', $id)
628
		and autoriser('creer', 'article');
629
}
630
631
632
/**
633
 * Autorisation de modifier une rubrique $id
634
 *
635
 * Il faut pouvoir publier dans cette rubrique
636
 *
637
 * @param  string $faire Action demandée
638
 * @param  string $type Type d'objet sur lequel appliquer l'action
639
 * @param  int $id Identifiant de l'objet
640
 * @param  array $qui Description de l'auteur demandant l'autorisation
641
 * @param  array $opt Options de cette autorisation
642
 * @return bool          true s'il a le droit, false sinon
643
 **/
644
function autoriser_rubrique_modifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
645
	return
646
		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
647
}
648
649
/**
650
 * Autorisation de supprimer une rubrique $id
651
 *
652
 * Il faut quelle soit vide (pas d'enfant) et qu'on ait le droit de la modifier
653
 *
654
 * @param  string $faire Action demandée
655
 * @param  string $type Type d'objet sur lequel appliquer l'action
656
 * @param  int $id Identifiant de l'objet
657
 * @param  array $qui Description de l'auteur demandant l'autorisation
658
 * @param  array $opt Options de cette autorisation
659
 * @return bool          true s'il a le droit, false sinon
660
 **/
661
function autoriser_rubrique_supprimer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
662
	if (!$id = intval($id)) {
663
		return false;
664
	}
665
666
	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
667
		return false;
668
	}
669
670
	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
671
		return false;
672
	}
673
674
	$compte = pipeline(
675
		'objet_compte_enfants',
676
		array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
677
	);
678
	foreach ($compte as $objet => $n) {
679
		if ($n) {
680
			return false;
681
		}
682
	}
683
684
	return autoriser('modifier', 'rubrique', $id);
685
}
686
687
688
/**
689
 * Autorisation de modifier un article $id
690
 *
691
 * Il faut pouvoir publier dans le parent
692
 * ou, si on change le statut en proposé ou préparation être auteur de l'article
693
 *
694
 * @param  string $faire Action demandée
695
 * @param  string $type Type d'objet sur lequel appliquer l'action
696
 * @param  int $id Identifiant de l'objet
697
 * @param  array $qui Description de l'auteur demandant l'autorisation
698
 * @param  array $opt Options de cette autorisation
699
 * @return bool          true s'il a le droit, false sinon
700
 **/
701
function autoriser_article_modifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
702
	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
703
704
	return
705
		$r
706
		and
707
		(
708
			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
709
			or (
710
				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
711
				and in_array($qui['statut'], array('0minirezo', '1comite'))
712
				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
713
				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
714
			)
715
		);
716
}
717
718
/**
719
 * Autorisation de créer un article
720
 *
721
 * Il faut qu'une rubrique existe et être au moins rédacteur
722
 *
723
 * @param  string $faire Action demandée
724
 * @param  string $type Type d'objet sur lequel appliquer l'action
725
 * @param  int $id Identifiant de l'objet
726
 * @param  array $qui Description de l'auteur demandant l'autorisation
727
 * @param  array $opt Options de cette autorisation
728
 * @return bool          true s'il a le droit, false sinon
729
 **/
730
function autoriser_article_creer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
731
	return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
732
}
733
734
/**
735
 * Autorisation de voir un article
736
 *
737
 * Il faut être admin ou auteur de l'article, sinon il faut que l'article
738
 * soit publié ou proposé.
739
 *
740
 * Peut-être appelée sans $id, mais avec un $opt['statut'] pour tester
741
 * la liste des status autorisés en fonction de $qui['statut']
742
 *
743
 * @param  string $faire Action demandée
744
 * @param  string $type Type d'objet sur lequel appliquer l'action
745
 * @param  int $id Identifiant de l'objet
746
 * @param  array $qui Description de l'auteur demandant l'autorisation
747
 * @param  array $opt Options de cette autorisation
748
 * @return bool          true s'il a le droit, false sinon
749
 */
750
function autoriser_article_voir_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
751
	if ($qui['statut'] == '0minirezo') {
752
		return true;
753
	}
754
	// cas des articles : depend du statut de l'article et de l'auteur
755 View Code Duplication
	if (isset($opt['statut'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
756
		$statut = $opt['statut'];
757
	} else {
758
		if (!$id) {
759
			return false;
760
		}
761
		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
762
	}
763
764
	return
765
		// si on est pas auteur de l'article,
766
		// seuls les propose et publies sont visibles
767
		in_array($statut, array('prop', 'publie'))
768
		// sinon si on est auteur, on a le droit de le voir, evidemment !
769
		or
770
		($id
771
			and $qui['id_auteur']
772
			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
773
}
774
775
776
/**
777
 * Autorisation de voir un objet
778
 *
779
 * Tout est visible par défaut, sauf les auteurs où il faut au moins être rédacteur.
780
 *
781
 * @param  string $faire Action demandée
782
 * @param  string $type Type d'objet sur lequel appliquer l'action
783
 * @param  int $id Identifiant de l'objet
784
 * @param  array $qui Description de l'auteur demandant l'autorisation
785
 * @param  array $opt Options de cette autorisation
786
 * @return bool          true s'il a le droit, false sinon
787
 **/
788
function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
789
	# securite, mais on aurait pas du arriver ici !
790
	if (function_exists($f = 'autoriser_' . $type . '_voir')
791
		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
792
		return $f($faire, $type, $id, $qui, $opt);
793
	}
794
795
	if ($qui['statut'] == '0minirezo') {
796
		return true;
797
	}
798
	// admins et redacteurs peuvent voir un auteur
799
	if ($type == 'auteur') {
800
		return in_array($qui['statut'], array('0minirezo', '1comite'));
801
	}
802
	// sinon par defaut tout est visible
803
	// sauf cas particuliers traites separemment (ie article)
804
	return true;
805
}
806
807
808
/**
809
 * Autorisation de webmestre
810
 *
811
 * Est-on webmestre ? Signifie qu'on n'a même pas besoin de passer par ftp
812
 * pour modifier les fichiers, cf. notamment inc/admin
813
 *
814
 * Soit la liste des webmestres est définie via une constante _ID_WEBMESTRES,
815
 * soit on regarde l'état "webmestre" de l'auteur
816
 *
817
 * @param  string $faire Action demandée
818
 * @param  string $type Type d'objet sur lequel appliquer l'action
819
 * @param  int $id Identifiant de l'objet
820
 * @param  array $qui Description de l'auteur demandant l'autorisation
821
 * @param  array $opt Options de cette autorisation
822
 * @return bool          true s'il a le droit, false sinon
823
 **/
824
function autoriser_webmestre_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
825
	return
826
		(defined('_ID_WEBMESTRES') ?
827
			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
828
			: $qui['webmestre'] == 'oui')
829
		and $qui['statut'] == '0minirezo'
830
		and !$qui['restreint'];
831
}
832
833
/**
834
 * Autorisation Configurer le site
835
 *
836
 * Il faut être administrateur complet
837
 *
838
 * @param  string $faire Action demandée
839
 * @param  string $type Type d'objet sur lequel appliquer l'action
840
 * @param  int $id Identifiant de l'objet
841
 * @param  array $qui Description de l'auteur demandant l'autorisation
842
 * @param  array $opt Options de cette autorisation
843
 * @return bool          true s'il a le droit, false sinon
844
 **/
845
function autoriser_configurer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
846
	return
847
		$qui['statut'] == '0minirezo'
848
		and !$qui['restreint'];
849
}
850
851
/**
852
 * Autorisation de sauvegarder la base de données
853
 *
854
 * Il faut être administrateur (y compris restreint)
855
 *
856
 * @param  string $faire Action demandée
857
 * @param  string $type Type d'objet sur lequel appliquer l'action
858
 * @param  int $id Identifiant de l'objet
859
 * @param  array $qui Description de l'auteur demandant l'autorisation
860
 * @param  array $opt Options de cette autorisation
861
 * @return bool          true s'il a le droit, false sinon
862
 **/
863
function autoriser_sauvegarder_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
864
	return
865
		$qui['statut'] == '0minirezo';
866
}
867
868
/**
869
 * Autorisation d'effacer la base de données
870
 *
871
 * Il faut être webmestre
872
 *
873
 * @param  string $faire Action demandée
874
 * @param  string $type Type d'objet sur lequel appliquer l'action
875
 * @param  int $id Identifiant de l'objet
876
 * @param  array $qui Description de l'auteur demandant l'autorisation
877
 * @param  array $opt Options de cette autorisation
878
 * @return bool          true s'il a le droit, false sinon
879
 **/
880
function autoriser_detruire_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
881
	return
882
		autoriser('webmestre', null, null, $qui, $opt);
883
}
884
885
/**
886
 * Autorisation de prévisualiser un auteur
887
 *
888
 * Il faut être administrateur ou que l'auteur à prévisualiser
889
 * ait au moins publié un article
890
 *
891
 * @param  string $faire Action demandée
892
 * @param  string $type Type d'objet sur lequel appliquer l'action
893
 * @param  int $id Identifiant de l'objet
894
 * @param  array $qui Description de l'auteur demandant l'autorisation
895
 * @param  array $opt Options de cette autorisation
896
 * @return bool          true s'il a le droit, false sinon
897
 **/
898
function autoriser_auteur_previsualiser_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
899
	// les admins peuvent "previsualiser" une page auteur
900
	if ($qui['statut'] == '0minirezo'
901
		and !$qui['restreint']
902
	) {
903
		return true;
904
	}
905
	// "Voir en ligne" si l'auteur a un article publie
906
	$n = sql_fetsel(
907
		'A.id_article',
908
		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
909
		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
910
	);
911
912
	return $n ? true : false;
913
}
914
915
916
/**
917
 * Autorisation de créer un auteur
918
 *
919
 * Il faut être administrateur (restreint compris).
920
 *
921
 * @note
922
 *     Seuls les administrateurs complets ont accès à tous les
923
 *     champs du formulaire d'édition d'un auteur. À la création
924
 *     d'un auteur, son statut est 'poubelle'. C'est l'autorisation
925
 *     de modifier qui permet de changer les informations sensibles
926
 *     (statut, login, pass, etc.) à l'institution.
927
 *
928
 * @see auteur_inserer()
929
 * @see auteur_instituer()
930
 * @see autoriser_auteur_modifier_dist()
931
 *
932
 * @param  string $faire Action demandée
933
 * @param  string $type Type d'objet sur lequel appliquer l'action
934
 * @param  int $id Identifiant de l'objet
935
 * @param  array $qui Description de l'auteur demandant l'autorisation
936
 * @param  array $opt Options de cette autorisation
937
 * @return bool          true s'il a le droit, false sinon
938
 **/
939
function autoriser_auteur_creer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
940
	return ($qui['statut'] == '0minirezo');
941
}
942
943
944
/**
945
 * Autorisation de modifier un auteur
946
 *
947
 * Attention tout depend de ce qu'on veut modifier. Il faut être au moins
948
 * rédacteur, mais on ne peut pas promouvoir (changer le statut) un auteur
949
 * avec des droits supérieurs au sien.
950
 *
951
 * @param  string $faire Action demandée
952
 * @param  string $type Type d'objet sur lequel appliquer l'action
953
 * @param  int $id Identifiant de l'objet
954
 * @param  array $qui Description de l'auteur demandant l'autorisation
955
 * @param  array $opt Options de cette autorisation
956
 * @return bool          true s'il a le droit, false sinon
957
 **/
958
function autoriser_auteur_modifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
959
960
	// Ni admin ni redacteur => non
961
	if (!in_array($qui['statut'], array('0minirezo', '1comite'))) {
962
		return false;
963
	}
964
965
	// Un redacteur peut modifier ses propres donnees mais ni son login/email
966
	// ni son statut (qui sont le cas echeant passes comme option)
967
	if ($qui['statut'] == '1comite') {
968
		if (!empty($opt['webmestre'])) {
969
			return false;
970
		} elseif (
971
			!empty($opt['statut'])
972
			or !empty($opt['restreintes'])
973
			or !empty($opt['email'])
974
		) {
975
			return false;
976
		} elseif ($id == $qui['id_auteur']) {
977
			return true;
978
		} else {
979
			return false;
980
		}
981
	}
982
983
	// Un admin restreint peut modifier/creer un auteur non-admin mais il
984
	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
985
	if ($qui['restreint']) {
986
		if (isset($opt['webmestre']) and $opt['webmestre']) {
987
			return false;
988
		} elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
989
			or (isset($opt['restreintes']) and $opt['restreintes'])
990
		) {
991
			return false;
992
		} else {
993
			if ($id == $qui['id_auteur']) {
994
				if (isset($opt['statut']) and $opt['statut']) {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return !(isset($opt['sta...]) and $opt['statut']);.
Loading history...
995
					return false;
996
				} else {
997
					return true;
998
				}
999
			} else {
1000
				if ($id_auteur = intval($id)) {
1001
					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
1002
					if ($t and $t['statut'] != '0minirezo') {
0 ignored issues
show
Coding Style introduced by
The if-else statement can be simplified to return $t and $t['statut'] != '0minirezo';.
Loading history...
1003
						return true;
1004
					} else {
1005
						return false;
1006
					}
1007
				} // id = 0 => creation
1008
				else {
1009
					return true;
1010
				}
1011
			}
1012
		}
1013
	}
1014
1015
	// Un admin complet fait ce qu'il veut
1016
	// sauf se degrader
1017
	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1018
		return false;
1019
	} elseif (isset($opt['webmestre'])
1020
				and $opt['webmestre']
1021
				and (defined('_ID_WEBMESTRES')
1022
				or !autoriser('webmestre'))) {
1023
		// et toucher au statut webmestre si il ne l'est pas lui meme
1024
		// ou si les webmestres sont fixes par constante (securite)
1025
		return false;
1026
	} // et modifier un webmestre si il ne l'est pas lui meme
1027
	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1028
		return false;
1029
	} else {
1030
		return true;
1031
	}
1032
}
1033
1034
1035
/**
1036
 * Autorisation d'associer un auteur sur un objet
1037
 *
1038
 * Il faut pouvoir modifier l'objet en question
1039
 *
1040
 * @param  string $faire Action demandée
1041
 * @param  string $type Type d'objet sur lequel appliquer l'action
1042
 * @param  int $id Identifiant de l'objet
1043
 * @param  array $qui Description de l'auteur demandant l'autorisation
1044
 * @param  array $opt Options de cette autorisation
1045
 * @return bool          true s'il a le droit, false sinon
1046
 **/
1047
function autoriser_associerauteurs_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1048
	return autoriser('modifier', $type, $id, $qui, $opt);
1049
}
1050
1051
1052
/**
1053
 * Autorisation d'upload FTP
1054
 *
1055
 * Il faut être administrateur.
1056
 *
1057
 * @param  string $faire Action demandée
1058
 * @param  string $type Type d'objet sur lequel appliquer l'action
1059
 * @param  int $id Identifiant de l'objet
1060
 * @param  array $qui Description de l'auteur demandant l'autorisation
1061
 * @param  array $opt Options de cette autorisation
1062
 * @return bool          true s'il a le droit, false sinon
1063
 **/
1064
function autoriser_chargerftp_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1065
	return $qui['statut'] == '0minirezo';
1066
}
1067
1068
/**
1069
 * Autorisation d'activer le mode debug
1070
 *
1071
 * Il faut être administrateur.
1072
 *
1073
 * @param  string $faire Action demandée
1074
 * @param  string $type Type d'objet sur lequel appliquer l'action
1075
 * @param  int $id Identifiant de l'objet
1076
 * @param  array $qui Description de l'auteur demandant l'autorisation
1077
 * @param  array $opt Options de cette autorisation
1078
 * @return bool          true s'il a le droit, false sinon
1079
 **/
1080
function autoriser_debug_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1081
	return $qui['statut'] == '0minirezo';
1082
}
1083
1084
/**
1085
 * Liste les rubriques d'un auteur
1086
 *
1087
 * Renvoie la liste des rubriques liées à cet auteur, independamment de son
1088
 * statut (pour les admins restreints, il faut donc aussi vérifier statut)
1089
 *
1090
 * Mémorise le resultat dans un tableau statique indéxé par les id_auteur.
1091
 * On peut reinitialiser un élément en passant un 2e argument non vide
1092
 *
1093
 * @param int $id_auteur Identifiant de l'auteur
1094
 * @param bool $raz Recalculer le résultat connu pour cet auteur
1095
 * @return array          Liste des rubriques
1096
 **/
1097
function liste_rubriques_auteur($id_auteur, $raz = false) {
1098
	static $restreint = array();
1099
1100
	if (!$id_auteur = intval($id_auteur)) {
1101
		return array();
1102
	}
1103
	if ($raz) {
1104
		unset($restreint[$id_auteur]);
1105
	} elseif (isset($restreint[$id_auteur])) {
1106
		return $restreint[$id_auteur];
1107
	}
1108
1109
	$rubriques = array();
1110
	if ((!isset($GLOBALS['meta']['version_installee'])
1111
		or $GLOBALS['meta']['version_installee'] > 16428)
1112
		and $r = sql_allfetsel(
1113
			'id_objet',
1114
			'spip_auteurs_liens',
1115
			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1116
		)
1117
		and count($r)
1118
	) {
1119
		$r = array_column($r, 'id_objet');
1120
1121
		// recuperer toute la branche, au format chaine enumeration
1122
		include_spip('inc/rubriques');
1123
		$r = calcul_branche_in($r);
0 ignored issues
show
Bug introduced by
It seems like $r can also be of type false or null; however, calcul_branche_in() does only seem to accept string|integer|array, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
1124
		$r = explode(',', $r);
1125
1126
		// passer les rubriques en index, elimine les doublons
1127
		$r = array_flip($r);
1128
		// recuperer les index seuls
1129
		$r = array_keys($r);
1130
		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1131
		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1132
		$rubriques = array_combine($r, $r);
1133
	}
1134
1135
	// Affecter l'auteur session le cas echeant
1136 View Code Duplication
	if (isset($GLOBALS['visiteur_session']['id_auteur'])
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
1137
		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1138
	) {
1139
		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1140
	}
1141
1142
1143
	return $restreint[$id_auteur] = $rubriques;
1144
}
1145
1146
/**
1147
 * Autorisation de prévisualiser une rubrique
1148
 *
1149
 * Il faut pouvoir prévisualiser.
1150
 *
1151
 * @param  string $faire Action demandée
1152
 * @param  string $type Type d'objet sur lequel appliquer l'action
1153
 * @param  int $id Identifiant de l'objet
1154
 * @param  array $qui Description de l'auteur demandant l'autorisation
1155
 * @param  array $opt Options de cette autorisation
1156
 * @return bool          true s'il a le droit, false sinon
1157
 **/
1158
function autoriser_rubrique_previsualiser_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1159
	return autoriser('previsualiser');
1160
}
1161
1162
/**
1163
 * Autorisation d'iconifier une rubrique (mettre un logo)
1164
 *
1165
 * Il faut pouvoir publier dans la rubrique.
1166
 *
1167
 * @param  string $faire Action demandée
1168
 * @param  string $type Type d'objet sur lequel appliquer l'action
1169
 * @param  int $id Identifiant de l'objet
1170
 * @param  array $qui Description de l'auteur demandant l'autorisation
1171
 * @param  array $opt Options de cette autorisation
1172
 * @return bool          true s'il a le droit, false sinon
1173
 **/
1174
function autoriser_rubrique_iconifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1175
	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1176
}
1177
1178
/**
1179
 * Autorisation d'iconifier un auteur (mettre un logo)
1180
 *
1181
 * Il faut un administrateur ou que l'auteur soit celui qui demande l'autorisation
1182
 *
1183
 * @param  string $faire Action demandée
1184
 * @param  string $type Type d'objet sur lequel appliquer l'action
1185
 * @param  int $id Identifiant de l'objet
1186
 * @param  array $qui Description de l'auteur demandant l'autorisation
1187
 * @param  array $opt Options de cette autorisation
1188
 * @return bool          true s'il a le droit, false sinon
1189
 **/
1190
function autoriser_auteur_iconifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1191
	return (($id == $qui['id_auteur']) or
1192
		(($qui['statut'] == '0minirezo') and !$qui['restreint']));
1193
}
1194
1195
/**
1196
 * Autorisation d'iconifier un objet (mettre un logo)
1197
 *
1198
 * Il faut pouvoir modifier l'objet
1199
 *
1200
 * @param  string $faire Action demandée
1201
 * @param  string $type Type d'objet sur lequel appliquer l'action
1202
 * @param  int $id Identifiant de l'objet
1203
 * @param  array $qui Description de l'auteur demandant l'autorisation
1204
 * @param  array $opt Options de cette autorisation
1205
 * @return bool          true s'il a le droit, false sinon
1206
 **/
1207
function autoriser_iconifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1208
	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1209
	return autoriser('modifier', $type, $id, $qui, $opt);
1210
}
1211
1212
1213
/**
1214
 * Autorisation OK
1215
 *
1216
 * Autorise toujours !
1217
 * Fonction sans surprise pour permettre les tests.
1218
 *
1219
 * @param  string $faire Action demandée
1220
 * @param  string $type Type d'objet sur lequel appliquer l'action
1221
 * @param  int $id Identifiant de l'objet
1222
 * @param  array $qui Description de l'auteur demandant l'autorisation
1223
 * @param  array $opt Options de cette autorisation
1224
 * @return bool          true
1225
 **/
1226
function autoriser_ok_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1227
	return true;
1228
}
1229
1230
/**
1231
 * Autorisation NIET
1232
 *
1233
 * Refuse toujours !
1234
 * Fonction sans surprise pour permettre les tests.
1235
 *
1236
 * @param  string $faire Action demandée
1237
 * @param  string $type Type d'objet sur lequel appliquer l'action
1238
 * @param  int $id Identifiant de l'objet
1239
 * @param  array $qui Description de l'auteur demandant l'autorisation
1240
 * @param  array $opt Options de cette autorisation
1241
 * @return bool          false
1242
 **/
1243
function autoriser_niet_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1244
	return false;
1245
}
1246
1247
/**
1248
 * Autorisation de réparer la base de données
1249
 *
1250
 * Il faut pouvoir la détruire (et ne pas être en cours de réinstallation)
1251
 *
1252
 * @param  string $faire Action demandée
1253
 * @param  string $type Type d'objet sur lequel appliquer l'action
1254
 * @param  int $id Identifiant de l'objet
1255
 * @param  array $qui Description de l'auteur demandant l'autorisation
1256
 * @param  array $opt Options de cette autorisation
1257
 * @return bool          false
1258
 **/
1259
function autoriser_base_reparer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1260
	if (!autoriser('detruire') or _request('reinstall')) {
0 ignored issues
show
Unused Code introduced by
This if statement, and the following return statement can be replaced with return !(!autoriser('det..._request('reinstall'));.
Loading history...
1261
		return false;
1262
	}
1263
1264
	return true;
1265
}
1266
1267
/**
1268
 * Autorisation de voir l'onglet infosperso
1269
 *
1270
 * Toujours OK
1271
 *
1272
 * @param  string $faire Action demandée
1273
 * @param  string $type Type d'objet sur lequel appliquer l'action
1274
 * @param  int $id Identifiant de l'objet
1275
 * @param  array $qui Description de l'auteur demandant l'autorisation
1276
 * @param  array $opt Options de cette autorisation
1277
 * @return bool          true s'il a le droit, false sinon
1278
 **/
1279
function autoriser_infosperso_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1280
	return true;
1281
}
1282
1283
/**
1284
 * Autorisation de voir le formulaire configurer_langage
1285
 *
1286
 * Toujours OK
1287
 *
1288
 * @param  string $faire Action demandée
1289
 * @param  string $type Type d'objet sur lequel appliquer l'action
1290
 * @param  int $id Identifiant de l'objet
1291
 * @param  array $qui Description de l'auteur demandant l'autorisation
1292
 * @param  array $opt Options de cette autorisation
1293
 * @return bool          true s'il a le droit, false sinon
1294
 **/
1295
function autoriser_langage_configurer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1296
	return true;
1297
}
1298
1299
/**
1300
 * Autorisation de voir l'onglet configurerlangage
1301
 *
1302
 * Calquée sur l'autorisation de voir le formulaire configurer_langage
1303
 *
1304
 * @param  string $faire Action demandée
1305
 * @param  string $type Type d'objet sur lequel appliquer l'action
1306
 * @param  int $id Identifiant de l'objet
1307
 * @param  array $qui Description de l'auteur demandant l'autorisation
1308
 * @param  array $opt Options de cette autorisation
1309
 * @return bool          true s'il a le droit, false sinon
1310
 **/
1311
function autoriser_configurerlangage_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1312
	return autoriser('configurer', '_langage', $id, $qui, $opt);
1313
}
1314
1315
/**
1316
 * Autorisation de voir le formulaire configurer_preferences
1317
 *
1318
 * Toujours OK
1319
 *
1320
 * @param  string $faire Action demandée
1321
 * @param  string $type Type d'objet sur lequel appliquer l'action
1322
 * @param  int $id Identifiant de l'objet
1323
 * @param  array $qui Description de l'auteur demandant l'autorisation
1324
 * @param  array $opt Options de cette autorisation
1325
 * @return bool          true s'il a le droit, false sinon
1326
 **/
1327
function autoriser_preferences_configurer_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1328
	return true;
1329
}
1330
1331
/**
1332
 * Autorisation de voir l'onglet configurerpreferences
1333
 *
1334
 * Calquée sur l'autorisation de voir le formulaire configurer_preferences
1335
 *
1336
 * @param  string $faire Action demandée
1337
 * @param  string $type Type d'objet sur lequel appliquer l'action
1338
 * @param  int $id Identifiant de l'objet
1339
 * @param  array $qui Description de l'auteur demandant l'autorisation
1340
 * @param  array $opt Options de cette autorisation
1341
 * @return bool          true s'il a le droit, false sinon
1342
 **/
1343
function autoriser_configurerpreferences_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1344
	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1345
}
1346
1347
/**
1348
 * Autorisation d'afficher le menu développement
1349
 *
1350
 * Dépend de la préférences utilisateur
1351
 *
1352
 * @param  string $faire Action demandée
1353
 * @param  string $type Type d'objet sur lequel appliquer l'action
1354
 * @param  int $id Identifiant de l'objet
1355
 * @param  array $qui Description de l'auteur demandant l'autorisation
1356
 * @param  array $opt Options de cette autorisation
1357
 * @return bool          true s'il a le droit, false sinon
1358
 **/
1359
function autoriser_menudeveloppement_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1360
	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1361
		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1362
}
1363
1364
/**
1365
 * Autorisation d'afficher une grande entrée de menu
1366
 *
1367
 * Par defaut les grandes entrees (accueil, édition, publication, etc.)
1368
 * sont visibles de tous
1369
 *
1370
 * @param  string $faire Action demandée
1371
 * @param  string $type Type d'objet sur lequel appliquer l'action
1372
 * @param  int $id Identifiant de l'objet
1373
 * @param  array $qui Description de l'auteur demandant l'autorisation
1374
 * @param  array $opt Options de cette autorisation
1375
 * @return bool          true s'il a le droit, false sinon
1376
 **/
1377
function autoriser_menugrandeentree_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1378
	return true;
1379
}
1380
1381
/**
1382
 * Autorisation de voir la page auteurs
1383
 *
1384
 * Toujours OK
1385
 *
1386
 * @param  string $faire Action demandée
1387
 * @param  string $type Type d'objet sur lequel appliquer l'action
1388
 * @param  int $id Identifiant de l'objet
1389
 * @param  array $qui Description de l'auteur demandant l'autorisation
1390
 * @param  array $opt Options de cette autorisation
1391
 * @return bool          true s'il a le droit, false sinon
1392
 **/
1393
function autoriser_auteurs_voir_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1394
	return true;
1395
}
1396
1397
/**
1398
 * Autorisation de voir le menu auteurs
1399
 *
1400
 * Toujours OK
1401
 *
1402
 * @param  string $faire Action demandée
1403
 * @param  string $type Type d'objet sur lequel appliquer l'action
1404
 * @param  int $id Identifiant de l'objet
1405
 * @param  array $qui Description de l'auteur demandant l'autorisation
1406
 * @param  array $opt Options de cette autorisation
1407
 * @return bool          true s'il a le droit, false sinon
1408
 **/
1409
function autoriser_auteurs_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1410
	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1411
}
1412
1413
/**
1414
 * Autorisation de voir la page articles
1415
 *
1416
 * Toujours OK
1417
 *
1418
 * @param  string $faire Action demandée
1419
 * @param  string $type Type d'objet sur lequel appliquer l'action
1420
 * @param  int $id Identifiant de l'objet
1421
 * @param  array $qui Description de l'auteur demandant l'autorisation
1422
 * @param  array $opt Options de cette autorisation
1423
 * @return bool          true s'il a le droit, false sinon
1424
 **/
1425
function autoriser_articles_voir_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1426
	return true;
1427
}
1428
1429
/**
1430
 * Autorisation de voir le menu articles
1431
 *
1432
 * Toujours OK
1433
 *
1434
 * @param  string $faire Action demandée
1435
 * @param  string $type Type d'objet sur lequel appliquer l'action
1436
 * @param  int $id Identifiant de l'objet
1437
 * @param  array $qui Description de l'auteur demandant l'autorisation
1438
 * @param  array $opt Options de cette autorisation
1439
 * @return bool          true s'il a le droit, false sinon
1440
 **/
1441
function autoriser_articles_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1442
	return autoriser('voir', '_articles', $id, $qui, $opt);
1443
}
1444
1445
/**
1446
 * Autorisation de voir la page rubriques
1447
 *
1448
 * Toujours OK
1449
 *
1450
 * @param  string $faire Action demandée
1451
 * @param  string $type Type d'objet sur lequel appliquer l'action
1452
 * @param  int $id Identifiant de l'objet
1453
 * @param  array $qui Description de l'auteur demandant l'autorisation
1454
 * @param  array $opt Options de cette autorisation
1455
 * @return bool          true s'il a le droit, false sinon
1456
 **/
1457
function autoriser_rubriques_voir_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1458
	return true;
1459
}
1460
1461
/**
1462
 * Autorisation de voir le menu rubriques
1463
 *
1464
 * Toujours OK
1465
 *
1466
 * @param  string $faire Action demandée
1467
 * @param  string $type Type d'objet sur lequel appliquer l'action
1468
 * @param  int $id Identifiant de l'objet
1469
 * @param  array $qui Description de l'auteur demandant l'autorisation
1470
 * @param  array $opt Options de cette autorisation
1471
 * @return bool          true s'il a le droit, false sinon
1472
 **/
1473
function autoriser_rubriques_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1474
	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1475
}
1476
1477
/**
1478
 * Autorisation de voir le menu articlecreer
1479
 *
1480
 * Il faut au moins une rubrique présente.
1481
 *
1482
 * @param  string $faire Action demandée
1483
 * @param  string $type Type d'objet sur lequel appliquer l'action
1484
 * @param  int $id Identifiant de l'objet
1485
 * @param  array $qui Description de l'auteur demandant l'autorisation
1486
 * @param  array $opt Options de cette autorisation
1487
 * @return bool          true s'il a le droit, false sinon
1488
 **/
1489
function autoriser_articlecreer_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1490
	return verifier_table_non_vide();
1491
}
1492
1493
1494
/**
1495
 * Autorisation de voir le menu auteurcreer
1496
 *
1497
 * Il faut pouvoir créer un auteur !
1498
 *
1499
 * @see autoriser_auteur_creer_dist()
1500
 *
1501
 * @param  string $faire Action demandée
1502
 * @param  string $type Type d'objet sur lequel appliquer l'action
1503
 * @param  int $id Identifiant de l'objet
1504
 * @param  array $qui Description de l'auteur demandant l'autorisation
1505
 * @param  array $opt Options de cette autorisation
1506
 * @return bool          true s'il a le droit, false sinon
1507
 **/
1508
function autoriser_auteurcreer_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1509
	return autoriser('creer', 'auteur', $id, $qui, $opt);
1510
}
1511
1512
/**
1513
 * Autorisation de voir le menu "afficher les visiteurs"
1514
 *
1515
 * Être admin complet et il faut qu'il en existe ou que ce soit activé en config
1516
 *
1517
 * @param  string $faire Action demandée
1518
 * @param  string $type Type d'objet sur lequel appliquer l'action
1519
 * @param  int $id Identifiant de l'objet
1520
 * @param  array $qui Description de l'auteur demandant l'autorisation
1521
 * @param  array $opt Options de cette autorisation
1522
 * @return bool          true s'il a le droit, false sinon
1523
 **/
1524
function autoriser_visiteurs_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1525
	include_spip('base/abstract_sql');
1526
	return 
1527
		$qui['statut'] == '0minirezo' and !$qui['restreint']
1528
		and (
1529
			$GLOBALS['meta']["accepter_visiteurs"] != 'non'
1530
			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1531
		);
1532
}
1533
1534
/**
1535
 * Autorisation de voir le menu suiviedito
1536
 *
1537
 * Il faut être administrateur (y compris restreint).
1538
 *
1539
 * @param  string $faire Action demandée
1540
 * @param  string $type Type d'objet sur lequel appliquer l'action
1541
 * @param  int $id Identifiant de l'objet
1542
 * @param  array $qui Description de l'auteur demandant l'autorisation
1543
 * @param  array $opt Options de cette autorisation
1544
 * @return bool          true s'il a le droit, false sinon
1545
 **/
1546
function autoriser_suiviedito_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1547
	return $qui['statut'] == '0minirezo';
1548
}
1549
1550
/**
1551
 * Autorisation de voir le menu synchro
1552
 *
1553
 * Il faut être administrateur (y compris restreint).
1554
 *
1555
 * @param  string $faire Action demandée
1556
 * @param  string $type Type d'objet sur lequel appliquer l'action
1557
 * @param  int $id Identifiant de l'objet
1558
 * @param  array $qui Description de l'auteur demandant l'autorisation
1559
 * @param  array $opt Options de cette autorisation
1560
 * @return bool          true s'il a le droit, false sinon
1561
 **/
1562
function autoriser_synchro_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1563
	return $qui['statut'] == '0minirezo';
1564
}
1565
1566
/**
1567
 * Autorisation de voir le menu configurer_interactions
1568
 *
1569
 * Il faut avoir accès à la page configurer_interactions
1570
 *
1571
 * @param  string $faire Action demandée
1572
 * @param  string $type Type d'objet sur lequel appliquer l'action
1573
 * @param  int $id Identifiant de l'objet
1574
 * @param  array $qui Description de l'auteur demandant l'autorisation
1575
 * @param  array $opt Options de cette autorisation
1576
 * @return bool          true s'il a le droit, false sinon
1577
 **/
1578
function autoriser_configurerinteractions_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1579
    return autoriser('configurer', '_interactions', $id, $qui, $opt);
1580
}
1581
1582
/**
1583
 * Autorisation de voir le menu configurer_langue
1584
 *
1585
 * Il faut avoir accès à la page configurer_langue
1586
 *
1587
 * @param  string $faire Action demandée
1588
 * @param  string $type Type d'objet sur lequel appliquer l'action
1589
 * @param  int $id Identifiant de l'objet
1590
 * @param  array $qui Description de l'auteur demandant l'autorisation
1591
 * @param  array $opt Options de cette autorisation
1592
 * @return bool          true s'il a le droit, false sinon
1593
 **/
1594
function autoriser_configurerlangue_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1595
    return autoriser('configurer', '_langue', $id, $qui, $opt);
1596
}
1597
1598
/**
1599
 * Autorisation de voir le menu configurer_multilinguisme
1600
 *
1601
 * Il faut avoir accès à la page configurer_multilinguisme
1602
 *
1603
 * @param  string $faire Action demandée
1604
 * @param  string $type Type d'objet sur lequel appliquer l'action
1605
 * @param  int $id Identifiant de l'objet
1606
 * @param  array $qui Description de l'auteur demandant l'autorisation
1607
 * @param  array $opt Options de cette autorisation
1608
 * @return bool          true s'il a le droit, false sinon
1609
 **/
1610
function autoriser_configurermultilinguisme_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1611
    return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1612
}
1613
1614
/**
1615
 * Autorisation de voir le menu configurer_contenu
1616
 *
1617
 * Il faut avoir accès à la page configurer_contenu
1618
 *
1619
 * @param  string $faire Action demandée
1620
 * @param  string $type Type d'objet sur lequel appliquer l'action
1621
 * @param  int $id Identifiant de l'objet
1622
 * @param  array $qui Description de l'auteur demandant l'autorisation
1623
 * @param  array $opt Options de cette autorisation
1624
 * @return bool          true s'il a le droit, false sinon
1625
 **/
1626
function autoriser_configurercontenu_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1627
    return autoriser('configurer', '_contenu', $id, $qui, $opt);
1628
}
1629
1630
/**
1631
 * Autorisation de voir le menu configurer_avancees
1632
 *
1633
 * Il faut avoir accès à la page configurer_avancees
1634
 *
1635
 * @param  string $faire Action demandée
1636
 * @param  string $type Type d'objet sur lequel appliquer l'action
1637
 * @param  int $id Identifiant de l'objet
1638
 * @param  array $qui Description de l'auteur demandant l'autorisation
1639
 * @param  array $opt Options de cette autorisation
1640
 * @return bool          true s'il a le droit, false sinon
1641
 **/
1642
function autoriser_configureravancees_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1643
    return autoriser('configurer', '_avancees', $id, $qui, $opt);
1644
}
1645
1646
/**
1647
 * Autorisation de voir le menu admin_plugin
1648
 *
1649
 * Il faut avoir accès à la page admin_plugin
1650
 *
1651
 * @param  string $faire Action demandée
1652
 * @param  string $type Type d'objet sur lequel appliquer l'action
1653
 * @param  int $id Identifiant de l'objet
1654
 * @param  array $qui Description de l'auteur demandant l'autorisation
1655
 * @param  array $opt Options de cette autorisation
1656
 * @return bool          true s'il a le droit, false sinon
1657
 **/
1658
function autoriser_adminplugin_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1659
    return autoriser('configurer', '_plugins', $id, $qui, $opt);
1660
}
1661
1662
/**
1663
 * Autorisation de voir le menu admin_tech
1664
 *
1665
 * Il faut avoir accès à la page admin_tech
1666
 *
1667
 * @param  string $faire Action demandée
1668
 * @param  string $type Type d'objet sur lequel appliquer l'action
1669
 * @param  int $id Identifiant de l'objet
1670
 * @param  array $qui Description de l'auteur demandant l'autorisation
1671
 * @param  array $opt Options de cette autorisation
1672
 * @return bool          true s'il a le droit, false sinon
1673
 **/
1674
function autoriser_admintech_menu_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1675
    return autoriser('detruire', $type, $id, $qui, $opt);
1676
}
1677
1678
/**
1679
 * Autorisation de purger la queue de travaux
1680
 *
1681
 * Il faut être webmestre.
1682
 *
1683
 * @param  string $faire Action demandée
1684
 * @param  string $type Type d'objet sur lequel appliquer l'action
1685
 * @param  int $id Identifiant de l'objet
1686
 * @param  array $qui Description de l'auteur demandant l'autorisation
1687
 * @param  array $opt Options de cette autorisation
1688
 * @return bool          true s'il a le droit, false sinon
1689
 **/
1690
function autoriser_queue_purger_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1691
	return autoriser('webmestre');
1692
}
1693
1694
1695
/**
1696
 * Autorisation l'échafaudage de squelettes en Z
1697
 *
1698
 * Il faut être dans l'espace privé (et authentifié),
1699
 * sinon il faut être webmestre (pas de fuite d'informations publiées)
1700
 *
1701
 * @param  string $faire Action demandée
1702
 * @param  string $type Type d'objet sur lequel appliquer l'action
1703
 * @param  int $id Identifiant de l'objet
1704
 * @param  array $qui Description de l'auteur demandant l'autorisation
1705
 * @param  array $opt Options de cette autorisation
1706
 * @return bool          true s'il a le droit, false sinon
1707
 **/
1708
function autoriser_echafauder_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1709
	if (test_espace_prive()) {
1710
		return intval($qui['id_auteur']) ? true : false;
1711
	} else {
1712
		return autoriser('webmestre', '', $id, $qui, $opt);
1713
	}
1714
}
1715
1716
1717
/**
1718
 * Retourne les identifiants d'auteurs liés à un objet
1719
 *
1720
 * @param string $objet
1721
 * @param int $id_objet
1722
 * @param string|array $cond
1723
 *     Condition(s) supplémentaire(s) pour le where de la requête
1724
 * @return int[]
0 ignored issues
show
Documentation introduced by
Should the return type not be null|false|array? Also, consider making the array more specific, something like array<String>, or String[].

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

If the return type contains the type array, this check recommends the use of a more specific type like String[] or array<String>.

Loading history...
1725
 *     Identifiants d'auteurs
1726
 */
1727
function auteurs_objet($objet, $id_objet, $cond = '') {
1728
	$objet = objet_type($objet);
1729
	$where = array(
1730
		'objet=' . sql_quote($objet),
1731
		'id_objet=' . intval($id_objet)
1732
	);
1733
	if (!empty($cond)) {
1734
		if (is_array($cond)) {
1735
			$where = array_merge($where, $cond);
1736
		} else {
1737
			$where[] = $cond;
1738
		}
1739
	}
1740
	$auteurs = sql_allfetsel(
1741
		'id_auteur',
1742
		'spip_auteurs_liens',
1743
		$where
1744
	);
1745
	if (is_array($auteurs)) {
1746
		return array_column($auteurs, 'id_auteur');
1747
	}
1748
	return array();
1749
}
1750
1751
/**
1752
 * Lister les auteurs d'un article
1753
 *
1754
 * @deprecated utiliser auteurs_objets()
1755
 * @param int $id_article Identifiant de l'article
1756
 * @param string $cond Condition en plus dans le where de la requête
1757
 * @return array|bool
1758
 *     - array : liste des id_auteur trouvés
1759
 *     - false : serveur SQL indisponible
1760
 */
1761
function auteurs_article($id_article, $cond = '') {
1762
	return sql_allfetsel(
1763
		'id_auteur',
1764
		'spip_auteurs_liens',
1765
		"objet='article' AND id_objet=" . intval($id_article) . ($cond ? " AND $cond" : '')
1766
	);
1767
}
1768
1769
1770
/**
1771
 * Tester si on est admin restreint sur une rubrique donnée
1772
 *
1773
 * Fonction générique utilisee dans des autorisations ou assimilée
1774
 *
1775
 * @param int $id_rubrique Identifiant de la rubrique
1776
 * @return bool             true si administrateur de cette rubrique, false sinon.
1777
 */
1778
function acces_restreint_rubrique($id_rubrique) {
1779
1780
	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1781
}
1782
1783
1784
/**
1785
 * Verifier qu'il existe au moins un parent
1786
 *
1787
 * Fonction utilisee dans des autorisations des boutons / menus du prive des objets enfants (articles, breves, sites)
1788
 *
1789
 * @param string $table la table a vérifier
1790
 * @return bool             true si un parent existe
1791
 */
1792
function verifier_table_non_vide($table = 'spip_rubriques') {
1793
	static $done = array();
1794
	if (!isset($done[$table])) {
1795
		$done[$table] = sql_countsel($table) > 0;
1796
	}
1797
1798
	return $done[$table];
1799
}
1800
1801
/**
1802
 * Détermine la possibilité de s'inscire sur le site
1803
 *
1804
 * Pour un statut et un éventuel id_rubrique donné, indique,
1805
 * à l'aide de la liste globale des statuts (tableau mode => nom du mode)
1806
 * si le visiteur peut s'inscrire sur le site.
1807
 *
1808
 * Utile pour le formulaire d'inscription.
1809
 *
1810
 * Par défaut, seuls `6forum` et `1comite` sont possibles, les autres sont
1811
 * en `false`. Pour un nouveau mode il suffit de définir l'autorisation
1812
 * spécifique.
1813
 *
1814
 * @param  string $faire Action demandée
1815
 * @param  string $quoi Statut demandé
1816
 * @param  int $id Identifiant éventuel, par exemple de rubrique
1817
 * @param  array $qui Description de l'auteur demandant l'autorisation
1818
 * @param  array $opt Options de cette autorisation
1819
 * @return bool          true s'il a le droit, false sinon
1820
 */
1821
function autoriser_inscrireauteur_dist($faire, $quoi, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1822
1823
	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1824
	switch ($s) {
1825
		case 'info_redacteurs':
1826
			return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1827
		case 'info_visiteurs':
1828
			return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1829
	}
1830
1831
	return false;
1832
}
1833
1834
1835
/**
1836
 * Autorisation à voir le phpinfo
1837
 *
1838
 * Il faut être webmestre
1839
 *
1840
 * @param  string $faire Action demandée
1841
 * @param  string $type Type d'objet sur lequel appliquer l'action
1842
 * @param  int $id Identifiant de l'objet
1843
 * @param  array $qui Description de l'auteur demandant l'autorisation
1844
 * @param  array $opt Options de cette autorisation
1845
 * @return bool          true s'il a le droit, false sinon
1846
 **/
1847
function autoriser_phpinfos_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $type is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $qui is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $opt is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1848
	return autoriser('webmestre');
1849
}
1850