Completed
Push — master ( 164dff...8e25c1 )
by cam
11:58
created

autoriser.php ➔ autoriser_modifierurl_dist()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 5
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2018                                                *
7
 *  Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James  *
8
 *                                                                         *
9
 *  Ce programme est un logiciel libre distribue sous licence GNU/GPL.     *
10
 *  Pour plus de details 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
// mes_fonctions peut aussi declarer des autorisations, donc il faut donc le charger
40
if ($f = find_in_path('mes_fonctions.php')) {
41
	global $dossier_squelettes;
42
	include_once(_ROOT_CWD . $f);
43
}
44
45
46
if (!function_exists('autoriser')) {
47
	/**
48
	 * Autoriser une action
49
	 *
50
	 * Teste si une personne (par défaut le visiteur en cours) peut effectuer
51
	 * une certaine action. Cette fonction est le point d'entrée de toutes
52
	 * les autorisations.
53
	 *
54
	 * La fonction se charge d'appeler des fonctions d'autorisations spécifiques
55
	 * aux actions demandées si elles existent. Elle cherche donc les fonctions
56
	 * dans cet ordre :
57
	 *
58
	 * - autoriser_{type}_{faire}, sinon avec _dist
59
	 * - autoriser_{type}, sinon avec _dist
60
	 * - autoriser_{faire}, sinon avec _dist
61
	 * - autoriser_{defaut}, sinon avec _dist
62
	 *
63
	 * Seul le premier argument est obligatoire.
64
	 *
65
	 * @note
66
	 *     Le paramètre `$type` attend par défaut un type d'objet éditorial, et à ce titre,
67
	 *     la valeur transmise se verra appliquer la fonction 'objet_type' pour uniformiser
68
	 *     cette valeur.
69
	 *
70
	 *     Si ce paramètre n'a rien n'a voir avec un objet éditorial, par exemple
71
	 *     'statistiques', un souligné avant le terme est ajouté afin d'indiquer
72
	 *     explicitement à la fonction autoriser de ne pas transformer la chaîne en type
73
	 *     d'objet. Cela donne pour cet exemple : `autoriser('detruire', '_statistiques')`
74
	 *
75
	 * @note
76
	 *     Le paramètre `$type`, en plus de l'uniformisation en type d'objet, se voit retirer
77
	 *     tous les soulignés du terme. Ainsi le type d'objet `livre_art` deviendra `livreart`
78
	 *     et SPIP cherchera une fonction `autoriser_livreart_{faire}`. Ceci permet
79
	 *     d'éviter une possible confusion si une fonction `autoriser_livre_art` existait :
80
	 *     quel serait le type, quel serait l'action ?
81
	 *
82
	 *     Pour résumer, si le type d'objet éditorial a un souligné, tel que 'livre_art',
83
	 *     la fonction d'autorisation correspondante ne l'aura pas.
84
	 *     Exemple : `function autoriser_livreart_modifier_dist(...){...}`
85
	 *
86
	 * @api
87
	 * @see autoriser_dist()
88
	 *
89
	 * @param string $faire
90
	 *   une action ('modifier', 'publier'...)
91
	 * @param string $type
92
	 *   type d'objet ou nom de table ('article')
93
	 * @param int $id
94
	 *   id de l'objet sur lequel on veut agir
95
	 * @param null|int|array $qui
96
	 *   - si null on prend alors visiteur_session
97
	 *   - un id_auteur (on regarde dans la base)
98
	 *   - un tableau auteur complet, y compris [restreint]
99
	 * @param null|array $opt
100
	 *   options sous forme de tableau associatif
101
	 * @return bool
102
	 *   true si la personne peut effectuer l'action
103
	 */
104
	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...
105
		// Charger les fonctions d'autorisation supplementaires
106
		static $pipe;
107
		if (!isset($pipe)) {
108
			$pipe = 1;
109
			pipeline('autoriser');
110
		}
111
112
		$args = func_get_args();
113
114
		return call_user_func_array('autoriser_dist', $args);
115
	}
116
}
117
118
119
/**
120
 * Autoriser une action
121
 *
122
 * Voir autoriser() pour une description complète
123
 *
124
 * @see autoriser()
125
 *
126
 * @param string $faire
127
 *   une action ('modifier', 'publier'...)
128
 * @param string $type
129
 *   type d'objet ou nom de table ('article')
130
 * @param int $id
131
 *   id de l'objet sur lequel on veut agir
132
 * @param null|int|array $qui
133
 *   si null on prend alors visiteur_session
134
 *   un id_auteur (on regarde dans la base)
135
 *   un tableau auteur complet, y compris [restreint]
136
 * @param null|array $opt
137
 *   options sous forme de tableau associatif
138
 * @return bool
139
 *   true si la personne peut effectuer l'action
140
 */
141
function autoriser_dist($faire, $type = '', $id = 0, $qui = null, $opt = null) {
142
143
	// Qui ? visiteur_session ?
144
	// si null ou '' (appel depuis #AUTORISER) on prend l'auteur loge
145
	if ($qui === null or $qui === '') {
146
		$qui = $GLOBALS['visiteur_session'] ? $GLOBALS['visiteur_session'] : array();
147
		$qui = array_merge(array('statut' => '', 'id_auteur' => 0, 'webmestre' => 'non'), $qui);
148
	} elseif (is_numeric($qui)) {
149
		$qui = sql_fetsel('*', 'spip_auteurs', 'id_auteur=' . $qui);
150
	}
151
152
	// Admins restreints, on construit ici (pas generique mais...)
153
	// le tableau de toutes leurs rubriques (y compris les sous-rubriques)
154
	if (_ADMINS_RESTREINTS and is_array($qui)) {
155
		$qui['restreint'] = isset($qui['id_auteur']) ? liste_rubriques_auteur($qui['id_auteur']) : array();
156
	}
157
158
	spip_log(
159
		"autoriser $faire $type $id (" . (isset($qui['nom']) ? $qui['nom'] : '') . ') ?',
160
		'autoriser' . _LOG_DEBUG
161
	);
162
163
	// passer par objet_type pour avoir les alias
164
	// et supprimer les _
165
	$type = str_replace('_', '', strncmp($type, '_', 1) == 0 ? $type : objet_type($type, false));
166
167
	// Si une exception a ete decretee plus haut dans le code, l'appliquer
168
	if (isset($GLOBALS['autoriser_exception'][$faire][$type][$id])
169
		and autoriser_exception($faire, $type, $id, 'verifier')
170
	) {
171
		spip_log("autoriser ($faire, $type, $id, " . (isset($qui['nom']) ? $qui['nom'] : '') . ') : OK Exception', 'autoriser' . _LOG_DEBUG);
172
		return true;
173
	}
174
175
	// Chercher une fonction d'autorisation
176
	// Dans l'ordre on va chercher autoriser_type_faire[_dist], autoriser_type[_dist],
177
	// autoriser_faire[_dist], autoriser_defaut[_dist]
178
	$fonctions = $type
179
		? array(
180
			'autoriser_' . $type . '_' . $faire,
181
			'autoriser_' . $type . '_' . $faire . '_dist',
182
			'autoriser_' . $type,
183
			'autoriser_' . $type . '_dist',
184
			'autoriser_' . $faire,
185
			'autoriser_' . $faire . '_dist',
186
			'autoriser_defaut',
187
			'autoriser_defaut_dist'
188
		)
189
		: array(
190
			'autoriser_' . $faire,
191
			'autoriser_' . $faire . '_dist',
192
			'autoriser_defaut',
193
			'autoriser_defaut_dist'
194
		);
195
196
	foreach ($fonctions as $f) {
197
		if (function_exists($f)) {
198
			$a = $f($faire, $type, $id, $qui, $opt);
199
			break;
200
		}
201
	}
202
203
	spip_log(
204
		"$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 196. 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...
205
		'autoriser' . _LOG_DEBUG
206
	);
207
208
	return $a;
209
}
210
211
// une globale pour aller au plus vite dans la fonction generique ci dessus
212
$GLOBALS['autoriser_exception'] = array();
213
214
/**
215
 * Accorder une autorisation exceptionnel pour le hit en cours, ou la revoquer
216
 *
217
 * http://code.spip.net/@autoriser_exception
218
 *
219
 * @param string $faire Action demandée
220
 * @param string $type Type d'objet sur lequel appliquer l'action
221
 * @param int $id Identifiant de l'objet
222
 * @param bool $autoriser accorder (true) ou revoquer (false)
223
 * @return bool
224
 */
225
function autoriser_exception($faire, $type, $id, $autoriser = true) {
226
	// une static innaccessible par url pour verifier que la globale est positionnee a bon escient
227
	static $autorisation;
228
	if ($autoriser === 'verifier') {
229
		return isset($autorisation[$faire][$type][$id]);
230
	}
231
	if ($autoriser === true) {
232
		$GLOBALS['autoriser_exception'][$faire][$type][$id] = $autorisation[$faire][$type][$id] = true;
233
	}
234
	if ($autoriser === false) {
235
		unset($GLOBALS['autoriser_exception'][$faire][$type][$id]);
236
		unset($autorisation[$faire][$type][$id]);
237
	}
238
239
	return false;
240
}
241
242
243
/**
244
 * Autorisation par defaut
245
 *
246
 * Les admins complets OK, les autres non
247
 *
248
 * @param  string $faire Action demandée
249
 * @param  string $type Type d'objet sur lequel appliquer l'action
250
 * @param  int $id Identifiant de l'objet
251
 * @param  array $qui Description de l'auteur demandant l'autorisation
252
 * @param  array $opt Options de cette autorisation
253
 * @return bool          true s'il a le droit, false sinon
254
 **/
255
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...
256
	return
257
		$qui['statut'] == '0minirezo'
258
		and !$qui['restreint'];
259
}
260
261
/**
262
 * Autorisation a se loger ? Retourne true pour tous les statuts sauf 5poubelle
263
 * Peut etre surchargee pour interdire statut=nouveau a se connecter
264
 * et forcer l'utilisation du lien de confirmation email pour valider le compte
265
 *
266
 * @param $faire
267
 * @param $type
268
 * @param $id
269
 * @param $qui
270
 * @param $opt
271
 * @return bool
272
 */
273
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...
274
	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...
275
		return false;
276
	}
277
	return true;
278
}
279
280
/**
281
 * Autorisation d'accès à l'espace privé ?
282
 *
283
 * @param  string $faire Action demandée
284
 * @param  string $type Type d'objet sur lequel appliquer l'action
285
 * @param  int $id Identifiant de l'objet
286
 * @param  array $qui Description de l'auteur demandant l'autorisation
287
 * @param  array $opt Options de cette autorisation
288
 * @return bool          true s'il a le droit, false sinon
289
 **/
290
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...
291
	return isset($qui['statut']) and in_array($qui['statut'], array('0minirezo', '1comite'));
292
}
293
294
/**
295
 * Autorisation de créer un contenu
296
 *
297
 * Accordée par defaut ceux qui accèdent à l'espace privé,
298
 * peut-être surchargée au cas par cas
299
 *
300
 * @param  string $faire Action demandée
301
 * @param  string $type Type d'objet sur lequel appliquer l'action
302
 * @param  int $id Identifiant de l'objet
303
 * @param  array $qui Description de l'auteur demandant l'autorisation
304
 * @param  array $opt Options de cette autorisation
305
 * @return bool          true s'il a le droit, false sinon
306
 **/
307
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...
308
	return in_array($qui['statut'], array('0minirezo', '1comite'));
309
}
310
311
/**
312
 * Autorisation de prévisualiser un contenu
313
 *
314
 * @uses test_previsualiser_objet_champ()
315
 * @uses decrire_token_previsu()
316
 *
317
 * @param  string $faire Action demandée
318
 * @param  string $type Type d'objet sur lequel appliquer l'action
319
 * @param  int $id Identifiant de l'objet
320
 * @param  array $qui Description de l'auteur demandant l'autorisation
321
 * @param  array $opt Options de cette autorisation
322
 * @return bool          true s'il a le droit, false sinon
323
 **/
324
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...
325
326
	// Le visiteur a-t-il un statut prevu par la config ?
327
	if (strpos($GLOBALS['meta']['preview'], ',' . $qui['statut'] . ',') !== false) {
328
		return test_previsualiser_objet_champ($type, $id, $qui, $opt);
329
	}
330
331
	// A-t-on un token de prévisualisation valable ?
332
	include_spip('inc/securiser_action');
333
	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...
334
		return true;
335
	}
336
337
	return false;
338
}
339
340
/**
341
 * Teste qu'un objet éditorial peut être prévisualisé
342
 *
343
 * Cela permet ainsi de commander l'affichage dans l'espace prive du bouton "previsualiser"
344
 * voir `prive/objets/infos/article.html` etc.
345
 *
346
 * Cela dépend du statut actuel de l'objet d'une part, et d'autre part de la
347
 * clé `previsu` dans le tableau `statut` de la déclaration de l'objet éditorial.
348
 * Cette clé `previsu` liste des statuts, séparés par des virgules,
349
 * qui ont le droit d'avoir une prévisualisation. La présence de `xx/auteur` indique que pour le
350
 * statut `xx`, l'auteur en cours doit être un des auteurs de l'objet éditorial en question
351
 * pour que ce statut autorise la prévisualisation.
352
 *
353
 * Exemple pour les articles : `'previsu' => 'publie,prop,prepa/auteur',`
354
 *
355
 * @uses lister_tables_objets_sql()
356
 *
357
 * @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...
358
 * @param  int $id Identifiant de l'objet
359
 * @param  array $qui Description de l'auteur demandant l'autorisation
360
 * @param  array $opt Options de cette autorisation
361
 * @return boolean True si autorisé, false sinon.
362
 */
363
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...
364
365
	// si pas de type et statut fourni, c'est une autorisation generale => OK
366
	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...
367
		return true;
368
	}
369
370
	include_spip('base/objets');
371
	$infos = lister_tables_objets_sql(table_objet_sql($type));
372
	if (isset($infos['statut'])) {
373
		foreach ($infos['statut'] as $c) {
374
			if (isset($c['publie'])) {
375
				if (!isset($c['previsu'])) {
376
					return false;
377
				} // pas de previsu definie => NIET
378
				$champ = $c['champ'];
379
				if (!isset($opt[$champ])) {
380
					return false;
381
				} // pas de champ passe a la demande => NIET
382
				$previsu = explode(',', $c['previsu']);
383
				// regarder si ce statut est autorise pour l'auteur
384
				if (in_array($opt[$champ] . '/auteur', $previsu)) {
385
386
					// retrouver l’id_auteur qui a filé un lien de prévisu éventuellement,
387
					// sinon l’auteur en session
388
					include_spip('inc/securiser_action');
389 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...
390
						$id_auteur = $desc['id_auteur'];
391
					} elseif (isset($GLOBALS['visiteur_session']['id_auteur'])) {
392
						$id_auteur = intval($GLOBALS['visiteur_session']['id_auteur']);
393
					} else {
394
						$id_auteur = null;
395
					}
396
397
					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...
398
						return false;
399
					} elseif(autoriser('previsualiser' . $opt[$champ], $type, '', $id_auteur)) {
400
						// dans ce cas (admin en general), pas de filtrage sur ce statut
401
					} elseif (!sql_countsel(
402
						'spip_auteurs_liens',
403
						'id_auteur=' . intval($id_auteur) . ' AND objet=' . sql_quote($type) . ' AND id_objet=' . intval($id)
404
					)) {
405
						return false;
406
					} // pas auteur de cet objet => NIET
407
				} elseif (!in_array($opt[$champ], $previsu)) {
408
					// le statut n'est pas dans ceux definis par la previsu => NIET
409
					return false;
410
				}
411
			}
412
		}
413
	}
414
415
	return true;
416
}
417
418
/**
419
 * Autorisation de changer de langue un contenu
420
 *
421
 * @param  string $faire Action demandée
422
 * @param  string $type Type d'objet sur lequel appliquer l'action
423
 * @param  int $id Identifiant de l'objet
424
 * @param  array $qui Description de l'auteur demandant l'autorisation
425
 * @param  array $opt Options de cette autorisation
426
 * @return bool          true s'il a le droit, false sinon
427
 **/
428
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...
429
	$multi_objets = explode(',', lire_config('multi_objets'));
430
	$gerer_trad_objets = explode(',', lire_config('gerer_trad_objets'));
431
	$table = table_objet_sql($type);
432
	if (in_array($table, $multi_objets)
433
		or in_array($table, $gerer_trad_objets)) { // affichage du formulaire si la configuration l'accepte
434
		$multi_secteurs = lire_config('multi_secteurs');
435
		$champs = objet_info($type, 'field');
436
		if ($multi_secteurs == 'oui'
437
			and array_key_exists('id_rubrique', $champs)) {
438
			// multilinguisme par secteur et objet rattaché à une rubrique
439
			$primary = id_table_objet($type);
440
			if ($table != 'spip_rubriques') {
441
				$id_rubrique = sql_getfetsel('id_rubrique', "$table", "$primary=" . intval($id));
442
			} else {
443
				$id_rubrique = $id;
444
			}
445
			$id_secteur = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique));
446
			if (!$id_secteur > 0) {
447
				$id_secteur = $id_rubrique;
448
			}
449
			$langue_secteur = sql_getfetsel('lang', 'spip_rubriques', 'id_rubrique=' . intval($id_secteur));
450
			$langue_objet = sql_getfetsel('lang', "$table", "$primary=" . intval($id));
451
			if ($langue_secteur != $langue_objet) {
452
				// configuration incohérente, on laisse l'utilisateur corriger la situation
453
				return true;
454
			}
455
			if ($table != 'spip_rubriques') { // le choix de la langue se fait seulement sur les rubriques
456
				return false;
457
			} else {
458
				$id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id));
459
				if ($id_parent != 0) {
460
					// sous-rubriques : pas de choix de langue
461
					return false;
462
				}
463
			}
464
		}
465
	} else {
466
		return false;
467
	}
468
469
	return autoriser('modifier', $type, $id, $qui, $opt);
470
}
471
472
/**
473
 * Autorisation de changer le lien de traduction
474
 *
475
 * @param  string $faire Action demandée
476
 * @param  string $type Type d'objet sur lequel appliquer l'action
477
 * @param  int $id Identifiant de l'objet
478
 * @param  array $qui Description de l'auteur demandant l'autorisation
479
 * @param  array $opt Options de cette autorisation
480
 * @return bool          true s'il a le droit, false sinon
481
 **/
482
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...
483
	return autoriser('modifier', $type, $id, $qui, $opt);
484
}
485
486
/**
487
 * Autorisation de changer la date d'un contenu
488
 *
489
 * @param  string $faire Action demandée
490
 * @param  string $type Type d'objet sur lequel appliquer l'action
491
 * @param  int $id Identifiant de l'objet
492
 * @param  array $qui Description de l'auteur demandant l'autorisation
493
 * @param  array $opt Options de cette autorisation
494
 * @return bool          true s'il a le droit, false sinon
495
 **/
496
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...
497
	if (!isset($opt['statut'])) {
498
		$table = table_objet($type);
499
		$trouver_table = charger_fonction('trouver_table', 'base');
500
		$desc = $trouver_table($table);
501
		if (!$desc) {
502
			return false;
503
		}
504 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...
505
			$statut = sql_getfetsel('statut', $desc['table'], id_table_objet($type) . '=' . intval($id));
506
		} else {
507
			$statut = 'publie';
508
		} // pas de statut => publie
509
	} else {
510
		$statut = $opt['statut'];
511
	}
512
513
	if ($statut == 'publie'
514
		or ($statut == 'prop' and $type == 'article' and $GLOBALS['meta']['post_dates'] == 'non')) {
515
		return autoriser('modifier', $type, $id);
516
	}
517
518
	return false;
519
}
520
521
/**
522
 * Autorisation d'instituer un contenu
523
 *
524
 * C'est à dire de changer son statut ou son parent.
525
 * Par défaut, il faut l'autorisation de modifier le contenu
526
 *
527
 * @param  string $faire Action demandée
528
 * @param  string $type Type d'objet sur lequel appliquer l'action
529
 * @param  int $id Identifiant de l'objet
530
 * @param  array $qui Description de l'auteur demandant l'autorisation
531
 * @param  array $opt Options de cette autorisation
532
 * @return bool          true s'il a le droit, false sinon
533
 **/
534
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...
535
	return autoriser('modifier', $type, $id, $qui, $opt);
536
}
537
538
/**
539
 * Autorisation de publier dans une rubrique $id
540
 *
541
 * Il faut être administrateur ou administrateur restreint de la rubrique
542
 *
543
 * @param  string $faire Action demandée
544
 * @param  string $type Type d'objet sur lequel appliquer l'action
545
 * @param  int $id Identifiant de l'objet
546
 * @param  array $qui Description de l'auteur demandant l'autorisation
547
 * @param  array $opt Options de cette autorisation
548
 * @return bool          true s'il a le droit, false sinon
549
 **/
550
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...
551
	return
552
		($qui['statut'] == '0minirezo')
553
		and (
554
			!$qui['restreint'] or !$id
555
			or in_array($id, $qui['restreint'])
556
		);
557
}
558
559
/**
560
 * Autorisation de créer une rubrique
561
 *
562
 * Il faut être administrateur pour pouvoir publier à la racine
563
 *
564
 * @param  string $faire Action demandée
565
 * @param  string $type Type d'objet sur lequel appliquer l'action
566
 * @param  int $id Identifiant de l'objet
567
 * @param  array $qui Description de l'auteur demandant l'autorisation
568
 * @param  array $opt Options de cette autorisation
569
 * @return bool          true s'il a le droit, false sinon
570
 **/
571
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...
572
	return
573
		((!$id and autoriser('defaut', null, null, $qui, $opt))
574
			or $id and autoriser('creerrubriquedans', 'rubrique', $id, $qui, $opt)
575
		);
576
}
577
578
/**
579
 * Autorisation de créer une sous rubrique dans une rubrique $id
580
 *
581
 * Il faut être administrateur et pouvoir publier dans la rubrique
582
 *
583
 * @param  string $faire Action demandée
584
 * @param  string $type Type d'objet sur lequel appliquer l'action
585
 * @param  int $id Identifiant de l'objet
586
 * @param  array $qui Description de l'auteur demandant l'autorisation
587
 * @param  array $opt Options de cette autorisation
588
 * @return bool          true s'il a le droit, false sinon
589
 **/
590
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...
591
	return
592
		($id or ($qui['statut'] == '0minirezo' and !$qui['restreint']))
593
		and autoriser('voir', 'rubrique', $id)
594
		and autoriser('publierdans', 'rubrique', $id);
595
}
596
597
/**
598
 * Autorisation de créer un article dans une rubrique $id
599
 *
600
 * Il faut pouvoir voir la rubrique et pouvoir créer un article…
601
 *
602
 * @param  string $faire Action demandée
603
 * @param  string $type Type d'objet sur lequel appliquer l'action
604
 * @param  int $id Identifiant de l'objet
605
 * @param  array $qui Description de l'auteur demandant l'autorisation
606
 * @param  array $opt Options de cette autorisation
607
 * @return bool          true s'il a le droit, false sinon
608
 **/
609
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...
610
	return
611
		$id
612
		and autoriser('voir', 'rubrique', $id)
613
		and autoriser('creer', 'article');
614
}
615
616
617
/**
618
 * Autorisation de modifier une rubrique $id
619
 *
620
 * Il faut pouvoir publier dans cette rubrique
621
 *
622
 * @param  string $faire Action demandée
623
 * @param  string $type Type d'objet sur lequel appliquer l'action
624
 * @param  int $id Identifiant de l'objet
625
 * @param  array $qui Description de l'auteur demandant l'autorisation
626
 * @param  array $opt Options de cette autorisation
627
 * @return bool          true s'il a le droit, false sinon
628
 **/
629
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...
630
	return
631
		autoriser('publierdans', 'rubrique', $id, $qui, $opt);
632
}
633
634
/**
635
 * Autorisation de supprimer une rubrique $id
636
 *
637
 * Il faut quelle soit vide (pas d'enfant) et qu'on ait le droit de la modifier
638
 *
639
 * @param  string $faire Action demandée
640
 * @param  string $type Type d'objet sur lequel appliquer l'action
641
 * @param  int $id Identifiant de l'objet
642
 * @param  array $qui Description de l'auteur demandant l'autorisation
643
 * @param  array $opt Options de cette autorisation
644
 * @return bool          true s'il a le droit, false sinon
645
 **/
646
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...
647
	if (!$id = intval($id)) {
648
		return false;
649
	}
650
651
	if (sql_countsel('spip_rubriques', 'id_parent=' . intval($id))) {
652
		return false;
653
	}
654
655
	if (sql_countsel('spip_articles', 'id_rubrique=' . intval($id) . " AND (statut<>'poubelle')")) {
656
		return false;
657
	}
658
659
	$compte = pipeline(
660
		'objet_compte_enfants',
661
		array('args' => array('objet' => 'rubrique', 'id_objet' => $id), 'data' => array())
662
	);
663
	foreach ($compte as $objet => $n) {
664
		if ($n) {
665
			return false;
666
		}
667
	}
668
669
	return autoriser('modifier', 'rubrique', $id);
670
}
671
672
673
/**
674
 * Autorisation de modifier un article $id
675
 *
676
 * Il faut pouvoir publier dans le parent
677
 * ou, si on change le statut en proposé ou préparation être auteur de l'article
678
 *
679
 * @param  string $faire Action demandée
680
 * @param  string $type Type d'objet sur lequel appliquer l'action
681
 * @param  int $id Identifiant de l'objet
682
 * @param  array $qui Description de l'auteur demandant l'autorisation
683
 * @param  array $opt Options de cette autorisation
684
 * @return bool          true s'il a le droit, false sinon
685
 **/
686
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...
687
	$r = sql_fetsel('id_rubrique,statut', 'spip_articles', 'id_article=' . sql_quote($id));
688
689
	return
690
		$r
691
		and
692
		(
693
			autoriser('publierdans', 'rubrique', $r['id_rubrique'], $qui, $opt)
694
			or (
695
				(!isset($opt['statut']) or $opt['statut'] !== 'publie')
696
				and in_array($qui['statut'], array('0minirezo', '1comite'))
697
				and in_array($r['statut'], array('prop', 'prepa', 'poubelle'))
698
				and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur'])
699
			)
700
		);
701
}
702
703
/**
704
 * Autorisation de créer un article
705
 *
706
 * Il faut qu'une rubrique existe et être au moins rédacteur
707
 *
708
 * @param  string $faire Action demandée
709
 * @param  string $type Type d'objet sur lequel appliquer l'action
710
 * @param  int $id Identifiant de l'objet
711
 * @param  array $qui Description de l'auteur demandant l'autorisation
712
 * @param  array $opt Options de cette autorisation
713
 * @return bool          true s'il a le droit, false sinon
714
 **/
715
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...
716
	return (sql_countsel('spip_rubriques') > 0 and in_array($qui['statut'], array('0minirezo', '1comite')));
717
}
718
719
/**
720
 * Autorisation de voir un article
721
 *
722
 * Il faut être admin ou auteur de l'article, sinon il faut que l'article
723
 * soit publié ou proposé.
724
 *
725
 * Peut-être appelée sans $id, mais avec un $opt['statut'] pour tester
726
 * la liste des status autorisés en fonction de $qui['statut']
727
 *
728
 * @param  string $faire Action demandée
729
 * @param  string $type Type d'objet sur lequel appliquer l'action
730
 * @param  int $id Identifiant de l'objet
731
 * @param  array $qui Description de l'auteur demandant l'autorisation
732
 * @param  array $opt Options de cette autorisation
733
 * @return bool          true s'il a le droit, false sinon
734
 */
735
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...
736
	if ($qui['statut'] == '0minirezo') {
737
		return true;
738
	}
739
	// cas des articles : depend du statut de l'article et de l'auteur
740 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...
741
		$statut = $opt['statut'];
742
	} else {
743
		if (!$id) {
744
			return false;
745
		}
746
		$statut = sql_getfetsel('statut', 'spip_articles', 'id_article=' . intval($id));
747
	}
748
749
	return
750
		// si on est pas auteur de l'article,
751
		// seuls les propose et publies sont visibles
752
		in_array($statut, array('prop', 'publie'))
753
		// sinon si on est auteur, on a le droit de le voir, evidemment !
754
		or
755
		($id
756
			and $qui['id_auteur']
757
			and auteurs_objet('article', $id, 'id_auteur=' . $qui['id_auteur']));
758
}
759
760
761
/**
762
 * Autorisation de voir un objet
763
 *
764
 * Tout est visible par défaut, sauf les auteurs où il faut au moins être rédacteur.
765
 *
766
 * @param  string $faire Action demandée
767
 * @param  string $type Type d'objet sur lequel appliquer l'action
768
 * @param  int $id Identifiant de l'objet
769
 * @param  array $qui Description de l'auteur demandant l'autorisation
770
 * @param  array $opt Options de cette autorisation
771
 * @return bool          true s'il a le droit, false sinon
772
 **/
773
function autoriser_voir_dist($faire, $type, $id, $qui, $opt) {
774
	# securite, mais on aurait pas du arriver ici !
775
	if (function_exists($f = 'autoriser_' . $type . '_voir')
776
		or function_exists($f = 'autoriser_' . $type . '_voir_dist')) {
777
		return $f($faire, $type, $id, $qui, $opt);
778
	}
779
780
	if ($qui['statut'] == '0minirezo') {
781
		return true;
782
	}
783
	// admins et redacteurs peuvent voir un auteur
784
	if ($type == 'auteur') {
785
		return in_array($qui['statut'], array('0minirezo', '1comite'));
786
	}
787
	// sinon par defaut tout est visible
788
	// sauf cas particuliers traites separemment (ie article)
789
	return true;
790
}
791
792
793
/**
794
 * Autorisation de webmestre
795
 *
796
 * Est-on webmestre ? Signifie qu'on n'a même pas besoin de passer par ftp
797
 * pour modifier les fichiers, cf. notamment inc/admin
798
 *
799
 * Soit la liste des webmestres est définie via une constante _ID_WEBMESTRES,
800
 * soit on regarde l'état "webmestre" de l'auteur
801
 *
802
 * @param  string $faire Action demandée
803
 * @param  string $type Type d'objet sur lequel appliquer l'action
804
 * @param  int $id Identifiant de l'objet
805
 * @param  array $qui Description de l'auteur demandant l'autorisation
806
 * @param  array $opt Options de cette autorisation
807
 * @return bool          true s'il a le droit, false sinon
808
 **/
809
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...
810
	return
811
		(defined('_ID_WEBMESTRES') ?
812
			in_array($qui['id_auteur'], explode(':', _ID_WEBMESTRES))
813
			: $qui['webmestre'] == 'oui')
814
		and $qui['statut'] == '0minirezo'
815
		and !$qui['restreint'];
816
}
817
818
/**
819
 * Autorisation Configurer le site
820
 *
821
 * Il faut être administrateur complet
822
 *
823
 * @param  string $faire Action demandée
824
 * @param  string $type Type d'objet sur lequel appliquer l'action
825
 * @param  int $id Identifiant de l'objet
826
 * @param  array $qui Description de l'auteur demandant l'autorisation
827
 * @param  array $opt Options de cette autorisation
828
 * @return bool          true s'il a le droit, false sinon
829
 **/
830
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...
831
	return
832
		$qui['statut'] == '0minirezo'
833
		and !$qui['restreint'];
834
}
835
836
/**
837
 * Autorisation de sauvegarder la base de données
838
 *
839
 * Il faut être administrateur (y compris restreint)
840
 *
841
 * @param  string $faire Action demandée
842
 * @param  string $type Type d'objet sur lequel appliquer l'action
843
 * @param  int $id Identifiant de l'objet
844
 * @param  array $qui Description de l'auteur demandant l'autorisation
845
 * @param  array $opt Options de cette autorisation
846
 * @return bool          true s'il a le droit, false sinon
847
 **/
848
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...
849
	return
850
		$qui['statut'] == '0minirezo';
851
}
852
853
/**
854
 * Autorisation d'effacer la base de données
855
 *
856
 * Il faut être webmestre
857
 *
858
 * @param  string $faire Action demandée
859
 * @param  string $type Type d'objet sur lequel appliquer l'action
860
 * @param  int $id Identifiant de l'objet
861
 * @param  array $qui Description de l'auteur demandant l'autorisation
862
 * @param  array $opt Options de cette autorisation
863
 * @return bool          true s'il a le droit, false sinon
864
 **/
865
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...
866
	return
867
		autoriser('webmestre', null, null, $qui, $opt);
868
}
869
870
/**
871
 * Autorisation de prévisualiser un auteur
872
 *
873
 * Il faut être administrateur ou que l'auteur à prévisualiser
874
 * ait au moins publié un article
875
 *
876
 * @param  string $faire Action demandée
877
 * @param  string $type Type d'objet sur lequel appliquer l'action
878
 * @param  int $id Identifiant de l'objet
879
 * @param  array $qui Description de l'auteur demandant l'autorisation
880
 * @param  array $opt Options de cette autorisation
881
 * @return bool          true s'il a le droit, false sinon
882
 **/
883
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...
884
	// les admins peuvent "previsualiser" une page auteur
885
	if ($qui['statut'] == '0minirezo'
886
		and !$qui['restreint']
887
	) {
888
		return true;
889
	}
890
	// "Voir en ligne" si l'auteur a un article publie
891
	$n = sql_fetsel(
892
		'A.id_article',
893
		'spip_auteurs_liens AS L LEFT JOIN spip_articles AS A ON (L.objet=\'article\' AND L.id_objet=A.id_article)',
894
		"A.statut='publie' AND L.id_auteur=" . sql_quote($id)
895
	);
896
897
	return $n ? true : false;
898
}
899
900
901
/**
902
 * Autorisation de créer un auteur
903
 *
904
 * Il faut être administrateur (restreint compris).
905
 *
906
 * @note
907
 *     Seuls les administrateurs complets ont accès à tous les
908
 *     champs du formulaire d'édition d'un auteur. À la création
909
 *     d'un auteur, son statut est 'poubelle'. C'est l'autorisation
910
 *     de modifier qui permet de changer les informations sensibles
911
 *     (statut, login, pass, etc.) à l'institution.
912
 *
913
 * @see auteur_inserer()
914
 * @see auteur_instituer()
915
 * @see autoriser_auteur_modifier_dist()
916
 *
917
 * @param  string $faire Action demandée
918
 * @param  string $type Type d'objet sur lequel appliquer l'action
919
 * @param  int $id Identifiant de l'objet
920
 * @param  array $qui Description de l'auteur demandant l'autorisation
921
 * @param  array $opt Options de cette autorisation
922
 * @return bool          true s'il a le droit, false sinon
923
 **/
924
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...
925
	return ($qui['statut'] == '0minirezo');
926
}
927
928
929
/**
930
 * Autorisation de modifier un auteur
931
 *
932
 * Attention tout depend de ce qu'on veut modifier. Il faut être au moins
933
 * rédacteur, mais on ne peut pas promouvoir (changer le statut) un auteur
934
 * avec des droits supérieurs au sien.
935
 *
936
 * @param  string $faire Action demandée
937
 * @param  string $type Type d'objet sur lequel appliquer l'action
938
 * @param  int $id Identifiant de l'objet
939
 * @param  array $qui Description de l'auteur demandant l'autorisation
940
 * @param  array $opt Options de cette autorisation
941
 * @return bool          true s'il a le droit, false sinon
942
 **/
943
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...
944
945
	// Ni admin ni redacteur => non
946
	if (!in_array($qui['statut'], array('0minirezo', '1comite'))) {
947
		return false;
948
	}
949
950
	// Un redacteur peut modifier ses propres donnees mais ni son login/email
951
	// ni son statut (qui sont le cas echeant passes comme option)
952
	if ($qui['statut'] == '1comite') {
953
		if (!empty($opt['webmestre'])) {
954
			return false;
955
		} elseif (
956
			!empty($opt['statut'])
957
			or !empty($opt['restreintes'])
958
			or !empty($opt['email'])
959
		) {
960
			return false;
961
		} elseif ($id == $qui['id_auteur']) {
962
			return true;
963
		} else {
964
			return false;
965
		}
966
	}
967
968
	// Un admin restreint peut modifier/creer un auteur non-admin mais il
969
	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
970
	if ($qui['restreint']) {
971
		if (isset($opt['webmestre']) and $opt['webmestre']) {
972
			return false;
973
		} elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
974
			or (isset($opt['restreintes']) and $opt['restreintes'])
975
		) {
976
			return false;
977
		} else {
978
			if ($id == $qui['id_auteur']) {
979
				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...
980
					return false;
981
				} else {
982
					return true;
983
				}
984
			} else {
985
				if ($id_auteur = intval($id)) {
986
					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
987
					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...
988
						return true;
989
					} else {
990
						return false;
991
					}
992
				} // id = 0 => creation
993
				else {
994
					return true;
995
				}
996
			}
997
		}
998
	}
999
1000
	// Un admin complet fait ce qu'il veut
1001
	// sauf se degrader
1002
	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1003
		return false;
1004
	} elseif (isset($opt['webmestre'])
1005
				and $opt['webmestre']
1006
				and (defined('_ID_WEBMESTRES')
1007
				or !autoriser('webmestre'))) {
1008
		// et toucher au statut webmestre si il ne l'est pas lui meme
1009
		// ou si les webmestres sont fixes par constante (securite)
1010
		return false;
1011
	} // et modifier un webmestre si il ne l'est pas lui meme
1012
	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1013
		return false;
1014
	} else {
1015
		return true;
1016
	}
1017
}
1018
1019
1020
/**
1021
 * Autorisation d'associer un auteur sur un objet
1022
 *
1023
 * Il faut pouvoir modifier l'objet en question
1024
 *
1025
 * @param  string $faire Action demandée
1026
 * @param  string $type Type d'objet sur lequel appliquer l'action
1027
 * @param  int $id Identifiant de l'objet
1028
 * @param  array $qui Description de l'auteur demandant l'autorisation
1029
 * @param  array $opt Options de cette autorisation
1030
 * @return bool          true s'il a le droit, false sinon
1031
 **/
1032
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...
1033
	return autoriser('modifier', $type, $id, $qui, $opt);
1034
}
1035
1036
1037
/**
1038
 * Autorisation d'upload FTP
1039
 *
1040
 * Il faut être administrateur.
1041
 *
1042
 * @param  string $faire Action demandée
1043
 * @param  string $type Type d'objet sur lequel appliquer l'action
1044
 * @param  int $id Identifiant de l'objet
1045
 * @param  array $qui Description de l'auteur demandant l'autorisation
1046
 * @param  array $opt Options de cette autorisation
1047
 * @return bool          true s'il a le droit, false sinon
1048
 **/
1049
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...
1050
	return $qui['statut'] == '0minirezo';
1051
}
1052
1053
/**
1054
 * Autorisation d'activer le mode debug
1055
 *
1056
 * Il faut être administrateur.
1057
 *
1058
 * @param  string $faire Action demandée
1059
 * @param  string $type Type d'objet sur lequel appliquer l'action
1060
 * @param  int $id Identifiant de l'objet
1061
 * @param  array $qui Description de l'auteur demandant l'autorisation
1062
 * @param  array $opt Options de cette autorisation
1063
 * @return bool          true s'il a le droit, false sinon
1064
 **/
1065
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...
1066
	return $qui['statut'] == '0minirezo';
1067
}
1068
1069
/**
1070
 * Liste les rubriques d'un auteur
1071
 *
1072
 * Renvoie la liste des rubriques liées à cet auteur, independamment de son
1073
 * statut (pour les admins restreints, il faut donc aussi vérifier statut)
1074
 *
1075
 * Mémorise le resultat dans un tableau statique indéxé par les id_auteur.
1076
 * On peut reinitialiser un élément en passant un 2e argument non vide
1077
 *
1078
 * @param int $id_auteur Identifiant de l'auteur
1079
 * @param bool $raz Recalculer le résultat connu pour cet auteur
1080
 * @return array          Liste des rubriques
1081
 **/
1082
function liste_rubriques_auteur($id_auteur, $raz = false) {
1083
	static $restreint = array();
1084
1085
	if (!$id_auteur = intval($id_auteur)) {
1086
		return array();
1087
	}
1088
	if ($raz) {
1089
		unset($restreint[$id_auteur]);
1090
	} elseif (isset($restreint[$id_auteur])) {
1091
		return $restreint[$id_auteur];
1092
	}
1093
1094
	$rubriques = array();
1095
	if ((!isset($GLOBALS['meta']['version_installee'])
1096
		or $GLOBALS['meta']['version_installee'] > 16428)
1097
		and $r = sql_allfetsel(
1098
			'id_objet',
1099
			'spip_auteurs_liens',
1100
			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1101
		)
1102
		and count($r)
1103
	) {
1104
		$r = array_map('reset', $r);
1105
1106
		// recuperer toute la branche, au format chaine enumeration
1107
		include_spip('inc/rubriques');
1108
		$r = calcul_branche_in($r);
1109
		$r = explode(',', $r);
1110
1111
		// passer les rubriques en index, elimine les doublons
1112
		$r = array_flip($r);
1113
		// recuperer les index seuls
1114
		$r = array_keys($r);
1115
		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1116
		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1117
		$rubriques = array_combine($r, $r);
1118
	}
1119
1120
	// Affecter l'auteur session le cas echeant
1121 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...
1122
		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1123
	) {
1124
		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1125
	}
1126
1127
1128
	return $restreint[$id_auteur] = $rubriques;
1129
}
1130
1131
/**
1132
 * Autorisation de prévisualiser une rubrique
1133
 *
1134
 * Il faut pouvoir prévisualiser.
1135
 *
1136
 * @param  string $faire Action demandée
1137
 * @param  string $type Type d'objet sur lequel appliquer l'action
1138
 * @param  int $id Identifiant de l'objet
1139
 * @param  array $qui Description de l'auteur demandant l'autorisation
1140
 * @param  array $opt Options de cette autorisation
1141
 * @return bool          true s'il a le droit, false sinon
1142
 **/
1143
function autoriser_rubrique_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 $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...
1144
	return autoriser('previsualiser');
1145
}
1146
1147
/**
1148
 * Autorisation d'iconifier une rubrique (mettre un logo)
1149
 *
1150
 * Il faut pouvoir publier dans la rubrique.
1151
 *
1152
 * @param  string $faire Action demandée
1153
 * @param  string $type Type d'objet sur lequel appliquer l'action
1154
 * @param  int $id Identifiant de l'objet
1155
 * @param  array $qui Description de l'auteur demandant l'autorisation
1156
 * @param  array $opt Options de cette autorisation
1157
 * @return bool          true s'il a le droit, false sinon
1158
 **/
1159
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...
1160
	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1161
}
1162
1163
/**
1164
 * Autorisation d'iconifier un auteur (mettre un logo)
1165
 *
1166
 * Il faut un administrateur ou que l'auteur soit celui qui demande l'autorisation
1167
 *
1168
 * @param  string $faire Action demandée
1169
 * @param  string $type Type d'objet sur lequel appliquer l'action
1170
 * @param  int $id Identifiant de l'objet
1171
 * @param  array $qui Description de l'auteur demandant l'autorisation
1172
 * @param  array $opt Options de cette autorisation
1173
 * @return bool          true s'il a le droit, false sinon
1174
 **/
1175
function autoriser_auteur_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...
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...
1176
	return (($id == $qui['id_auteur']) or
1177
		(($qui['statut'] == '0minirezo') and !$qui['restreint']));
1178
}
1179
1180
/**
1181
 * Autorisation d'iconifier un objet (mettre un logo)
1182
 *
1183
 * Il faut pouvoir modifier l'objet
1184
 *
1185
 * @param  string $faire Action demandée
1186
 * @param  string $type Type d'objet sur lequel appliquer l'action
1187
 * @param  int $id Identifiant de l'objet
1188
 * @param  array $qui Description de l'auteur demandant l'autorisation
1189
 * @param  array $opt Options de cette autorisation
1190
 * @return bool          true s'il a le droit, false sinon
1191
 **/
1192
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...
1193
	// par defaut, on a le droit d'iconifier si on a le droit de modifier
1194
	return autoriser('modifier', $type, $id, $qui, $opt);
1195
}
1196
1197
1198
/**
1199
 * Autorisation OK
1200
 *
1201
 * Autorise toujours !
1202
 * Fonction sans surprise pour permettre les tests.
1203
 *
1204
 * @param  string $faire Action demandée
1205
 * @param  string $type Type d'objet sur lequel appliquer l'action
1206
 * @param  int $id Identifiant de l'objet
1207
 * @param  array $qui Description de l'auteur demandant l'autorisation
1208
 * @param  array $opt Options de cette autorisation
1209
 * @return bool          true
1210
 **/
1211
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...
1212
	return true;
1213
}
1214
1215
/**
1216
 * Autorisation NIET
1217
 *
1218
 * Refuse toujours !
1219
 * Fonction sans surprise pour permettre les tests.
1220
 *
1221
 * @param  string $faire Action demandée
1222
 * @param  string $type Type d'objet sur lequel appliquer l'action
1223
 * @param  int $id Identifiant de l'objet
1224
 * @param  array $qui Description de l'auteur demandant l'autorisation
1225
 * @param  array $opt Options de cette autorisation
1226
 * @return bool          false
1227
 **/
1228
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...
1229
	return false;
1230
}
1231
1232
/**
1233
 * Autorisation de réparer la base de données
1234
 *
1235
 * Il faut pouvoir la détruire (et ne pas être en cours de réinstallation)
1236
 *
1237
 * @param  string $faire Action demandée
1238
 * @param  string $type Type d'objet sur lequel appliquer l'action
1239
 * @param  int $id Identifiant de l'objet
1240
 * @param  array $qui Description de l'auteur demandant l'autorisation
1241
 * @param  array $opt Options de cette autorisation
1242
 * @return bool          false
1243
 **/
1244
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...
1245
	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...
1246
		return false;
1247
	}
1248
1249
	return true;
1250
}
1251
1252
/**
1253
 * Autorisation de voir l'onglet infosperso
1254
 *
1255
 * Toujours OK
1256
 *
1257
 * @param  string $faire Action demandée
1258
 * @param  string $type Type d'objet sur lequel appliquer l'action
1259
 * @param  int $id Identifiant de l'objet
1260
 * @param  array $qui Description de l'auteur demandant l'autorisation
1261
 * @param  array $opt Options de cette autorisation
1262
 * @return bool          true s'il a le droit, false sinon
1263
 **/
1264
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...
1265
	return true;
1266
}
1267
1268
/**
1269
 * Autorisation de voir le formulaire configurer_langage
1270
 *
1271
 * Toujours OK
1272
 *
1273
 * @param  string $faire Action demandée
1274
 * @param  string $type Type d'objet sur lequel appliquer l'action
1275
 * @param  int $id Identifiant de l'objet
1276
 * @param  array $qui Description de l'auteur demandant l'autorisation
1277
 * @param  array $opt Options de cette autorisation
1278
 * @return bool          true s'il a le droit, false sinon
1279
 **/
1280
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...
1281
	return true;
1282
}
1283
1284
/**
1285
 * Autorisation de voir l'onglet configurerlangage
1286
 *
1287
 * Calquée sur l'autorisation de voir le formulaire configurer_langage
1288
 *
1289
 * @param  string $faire Action demandée
1290
 * @param  string $type Type d'objet sur lequel appliquer l'action
1291
 * @param  int $id Identifiant de l'objet
1292
 * @param  array $qui Description de l'auteur demandant l'autorisation
1293
 * @param  array $opt Options de cette autorisation
1294
 * @return bool          true s'il a le droit, false sinon
1295
 **/
1296
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...
1297
	return autoriser('configurer', '_langage', $id, $qui, $opt);
1298
}
1299
1300
/**
1301
 * Autorisation de voir le formulaire configurer_preferences
1302
 *
1303
 * Toujours OK
1304
 *
1305
 * @param  string $faire Action demandée
1306
 * @param  string $type Type d'objet sur lequel appliquer l'action
1307
 * @param  int $id Identifiant de l'objet
1308
 * @param  array $qui Description de l'auteur demandant l'autorisation
1309
 * @param  array $opt Options de cette autorisation
1310
 * @return bool          true s'il a le droit, false sinon
1311
 **/
1312
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...
1313
	return true;
1314
}
1315
1316
/**
1317
 * Autorisation de voir l'onglet configurerpreferences
1318
 *
1319
 * Calquée sur l'autorisation de voir le formulaire configurer_preferences
1320
 *
1321
 * @param  string $faire Action demandée
1322
 * @param  string $type Type d'objet sur lequel appliquer l'action
1323
 * @param  int $id Identifiant de l'objet
1324
 * @param  array $qui Description de l'auteur demandant l'autorisation
1325
 * @param  array $opt Options de cette autorisation
1326
 * @return bool          true s'il a le droit, false sinon
1327
 **/
1328
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...
1329
	return autoriser('configurer', '_preferences', $id, $qui, $opt);
1330
}
1331
1332
/**
1333
 * Autorisation d'afficher le menu développement
1334
 *
1335
 * Dépend de la préférences utilisateur
1336
 *
1337
 * @param  string $faire Action demandée
1338
 * @param  string $type Type d'objet sur lequel appliquer l'action
1339
 * @param  int $id Identifiant de l'objet
1340
 * @param  array $qui Description de l'auteur demandant l'autorisation
1341
 * @param  array $opt Options de cette autorisation
1342
 * @return bool          true s'il a le droit, false sinon
1343
 **/
1344
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...
1345
	return (isset($GLOBALS['visiteur_session']['prefs']['activer_menudev'])
1346
		and $GLOBALS['visiteur_session']['prefs']['activer_menudev'] == 'oui');
1347
}
1348
1349
/**
1350
 * Autorisation d'afficher une grande entrée de menu
1351
 *
1352
 * Par defaut les grandes entrees (accueil, édition, publication, etc.)
1353
 * sont visibles de tous
1354
 *
1355
 * @param  string $faire Action demandée
1356
 * @param  string $type Type d'objet sur lequel appliquer l'action
1357
 * @param  int $id Identifiant de l'objet
1358
 * @param  array $qui Description de l'auteur demandant l'autorisation
1359
 * @param  array $opt Options de cette autorisation
1360
 * @return bool          true s'il a le droit, false sinon
1361
 **/
1362
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...
1363
	return true;
1364
}
1365
1366
/**
1367
 * Autorisation de voir la page auteurs
1368
 *
1369
 * Toujours OK
1370
 *
1371
 * @param  string $faire Action demandée
1372
 * @param  string $type Type d'objet sur lequel appliquer l'action
1373
 * @param  int $id Identifiant de l'objet
1374
 * @param  array $qui Description de l'auteur demandant l'autorisation
1375
 * @param  array $opt Options de cette autorisation
1376
 * @return bool          true s'il a le droit, false sinon
1377
 **/
1378
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...
1379
	return true;
1380
}
1381
1382
/**
1383
 * Autorisation de voir le menu auteurs
1384
 *
1385
 * Toujours OK
1386
 *
1387
 * @param  string $faire Action demandée
1388
 * @param  string $type Type d'objet sur lequel appliquer l'action
1389
 * @param  int $id Identifiant de l'objet
1390
 * @param  array $qui Description de l'auteur demandant l'autorisation
1391
 * @param  array $opt Options de cette autorisation
1392
 * @return bool          true s'il a le droit, false sinon
1393
 **/
1394
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...
1395
	return autoriser('voir', '_auteurs', $id, $qui, $opt);
1396
}
1397
1398
/**
1399
 * Autorisation de voir la page articles
1400
 *
1401
 * Toujours OK
1402
 *
1403
 * @param  string $faire Action demandée
1404
 * @param  string $type Type d'objet sur lequel appliquer l'action
1405
 * @param  int $id Identifiant de l'objet
1406
 * @param  array $qui Description de l'auteur demandant l'autorisation
1407
 * @param  array $opt Options de cette autorisation
1408
 * @return bool          true s'il a le droit, false sinon
1409
 **/
1410
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...
1411
	return true;
1412
}
1413
1414
/**
1415
 * Autorisation de voir le menu articles
1416
 *
1417
 * Toujours OK
1418
 *
1419
 * @param  string $faire Action demandée
1420
 * @param  string $type Type d'objet sur lequel appliquer l'action
1421
 * @param  int $id Identifiant de l'objet
1422
 * @param  array $qui Description de l'auteur demandant l'autorisation
1423
 * @param  array $opt Options de cette autorisation
1424
 * @return bool          true s'il a le droit, false sinon
1425
 **/
1426
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...
1427
	return autoriser('voir', '_articles', $id, $qui, $opt);
1428
}
1429
1430
/**
1431
 * Autorisation de voir la page rubriques
1432
 *
1433
 * Toujours OK
1434
 *
1435
 * @param  string $faire Action demandée
1436
 * @param  string $type Type d'objet sur lequel appliquer l'action
1437
 * @param  int $id Identifiant de l'objet
1438
 * @param  array $qui Description de l'auteur demandant l'autorisation
1439
 * @param  array $opt Options de cette autorisation
1440
 * @return bool          true s'il a le droit, false sinon
1441
 **/
1442
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...
1443
	return true;
1444
}
1445
1446
/**
1447
 * Autorisation de voir le menu rubriques
1448
 *
1449
 * Toujours OK
1450
 *
1451
 * @param  string $faire Action demandée
1452
 * @param  string $type Type d'objet sur lequel appliquer l'action
1453
 * @param  int $id Identifiant de l'objet
1454
 * @param  array $qui Description de l'auteur demandant l'autorisation
1455
 * @param  array $opt Options de cette autorisation
1456
 * @return bool          true s'il a le droit, false sinon
1457
 **/
1458
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...
1459
	return autoriser('voir', '_rubriques', $id, $qui, $opt);
1460
}
1461
1462
/**
1463
 * Autorisation de voir le menu articlecreer
1464
 *
1465
 * Il faut au moins une rubrique présente.
1466
 *
1467
 * @param  string $faire Action demandée
1468
 * @param  string $type Type d'objet sur lequel appliquer l'action
1469
 * @param  int $id Identifiant de l'objet
1470
 * @param  array $qui Description de l'auteur demandant l'autorisation
1471
 * @param  array $opt Options de cette autorisation
1472
 * @return bool          true s'il a le droit, false sinon
1473
 **/
1474
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...
1475
	return verifier_table_non_vide();
1476
}
1477
1478
1479
/**
1480
 * Autorisation de voir le menu auteurcreer
1481
 *
1482
 * Il faut pouvoir créer un auteur !
1483
 *
1484
 * @see autoriser_auteur_creer_dist()
1485
 *
1486
 * @param  string $faire Action demandée
1487
 * @param  string $type Type d'objet sur lequel appliquer l'action
1488
 * @param  int $id Identifiant de l'objet
1489
 * @param  array $qui Description de l'auteur demandant l'autorisation
1490
 * @param  array $opt Options de cette autorisation
1491
 * @return bool          true s'il a le droit, false sinon
1492
 **/
1493
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...
1494
	return autoriser('creer', 'auteur', $id, $qui, $opt);
1495
}
1496
1497
/**
1498
 * Autorisation de voir le menu "afficher les visiteurs"
1499
 *
1500
 * Être admin complet et il faut qu'il en existe ou que ce soit activé en config
1501
 *
1502
 * @param  string $faire Action demandée
1503
 * @param  string $type Type d'objet sur lequel appliquer l'action
1504
 * @param  int $id Identifiant de l'objet
1505
 * @param  array $qui Description de l'auteur demandant l'autorisation
1506
 * @param  array $opt Options de cette autorisation
1507
 * @return bool          true s'il a le droit, false sinon
1508
 **/
1509
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...
1510
	include_spip('base/abstract_sql');
1511
	return 
1512
		$qui['statut'] == '0minirezo' and !$qui['restreint']
1513
		and (
1514
			$GLOBALS['meta']["accepter_visiteurs"] != 'non'
1515
			or sql_countsel('spip_auteurs', 'statut in ("6forum", "nouveau")') > 0
1516
		);
1517
}
1518
1519
/**
1520
 * Autorisation de voir le menu suiviedito
1521
 *
1522
 * Il faut être administrateur (y compris restreint).
1523
 *
1524
 * @param  string $faire Action demandée
1525
 * @param  string $type Type d'objet sur lequel appliquer l'action
1526
 * @param  int $id Identifiant de l'objet
1527
 * @param  array $qui Description de l'auteur demandant l'autorisation
1528
 * @param  array $opt Options de cette autorisation
1529
 * @return bool          true s'il a le droit, false sinon
1530
 **/
1531
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...
1532
	return $qui['statut'] == '0minirezo';
1533
}
1534
1535
/**
1536
 * Autorisation de voir le menu synchro
1537
 *
1538
 * Il faut être administrateur (y compris restreint).
1539
 *
1540
 * @param  string $faire Action demandée
1541
 * @param  string $type Type d'objet sur lequel appliquer l'action
1542
 * @param  int $id Identifiant de l'objet
1543
 * @param  array $qui Description de l'auteur demandant l'autorisation
1544
 * @param  array $opt Options de cette autorisation
1545
 * @return bool          true s'il a le droit, false sinon
1546
 **/
1547
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...
1548
	return $qui['statut'] == '0minirezo';
1549
}
1550
1551
/**
1552
 * Autorisation de voir le menu configurer_interactions
1553
 *
1554
 * Il faut avoir accès à la page configurer_interactions
1555
 *
1556
 * @param  string $faire Action demandée
1557
 * @param  string $type Type d'objet sur lequel appliquer l'action
1558
 * @param  int $id Identifiant de l'objet
1559
 * @param  array $qui Description de l'auteur demandant l'autorisation
1560
 * @param  array $opt Options de cette autorisation
1561
 * @return bool          true s'il a le droit, false sinon
1562
 **/
1563
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...
1564
    return autoriser('configurer', '_interactions', $id, $qui, $opt);
1565
}
1566
1567
/**
1568
 * Autorisation de voir le menu configurer_langue
1569
 *
1570
 * Il faut avoir accès à la page configurer_langue
1571
 *
1572
 * @param  string $faire Action demandée
1573
 * @param  string $type Type d'objet sur lequel appliquer l'action
1574
 * @param  int $id Identifiant de l'objet
1575
 * @param  array $qui Description de l'auteur demandant l'autorisation
1576
 * @param  array $opt Options de cette autorisation
1577
 * @return bool          true s'il a le droit, false sinon
1578
 **/
1579
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...
1580
    return autoriser('configurer', '_langue', $id, $qui, $opt);
1581
}
1582
1583
/**
1584
 * Autorisation de voir le menu configurer_multilinguisme
1585
 *
1586
 * Il faut avoir accès à la page configurer_multilinguisme
1587
 *
1588
 * @param  string $faire Action demandée
1589
 * @param  string $type Type d'objet sur lequel appliquer l'action
1590
 * @param  int $id Identifiant de l'objet
1591
 * @param  array $qui Description de l'auteur demandant l'autorisation
1592
 * @param  array $opt Options de cette autorisation
1593
 * @return bool          true s'il a le droit, false sinon
1594
 **/
1595
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...
1596
    return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1597
}
1598
1599
/**
1600
 * Autorisation de voir le menu configurer_contenu
1601
 *
1602
 * Il faut avoir accès à la page configurer_contenu
1603
 *
1604
 * @param  string $faire Action demandée
1605
 * @param  string $type Type d'objet sur lequel appliquer l'action
1606
 * @param  int $id Identifiant de l'objet
1607
 * @param  array $qui Description de l'auteur demandant l'autorisation
1608
 * @param  array $opt Options de cette autorisation
1609
 * @return bool          true s'il a le droit, false sinon
1610
 **/
1611
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...
1612
    return autoriser('configurer', '_contenu', $id, $qui, $opt);
1613
}
1614
1615
/**
1616
 * Autorisation de voir le menu configurer_avancees
1617
 *
1618
 * Il faut avoir accès à la page configurer_avancees
1619
 *
1620
 * @param  string $faire Action demandée
1621
 * @param  string $type Type d'objet sur lequel appliquer l'action
1622
 * @param  int $id Identifiant de l'objet
1623
 * @param  array $qui Description de l'auteur demandant l'autorisation
1624
 * @param  array $opt Options de cette autorisation
1625
 * @return bool          true s'il a le droit, false sinon
1626
 **/
1627
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...
1628
    return autoriser('configurer', '_avancees', $id, $qui, $opt);
1629
}
1630
1631
/**
1632
 * Autorisation de voir le menu admin_plugin
1633
 *
1634
 * Il faut avoir accès à la page admin_plugin
1635
 *
1636
 * @param  string $faire Action demandée
1637
 * @param  string $type Type d'objet sur lequel appliquer l'action
1638
 * @param  int $id Identifiant de l'objet
1639
 * @param  array $qui Description de l'auteur demandant l'autorisation
1640
 * @param  array $opt Options de cette autorisation
1641
 * @return bool          true s'il a le droit, false sinon
1642
 **/
1643
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...
1644
    return autoriser('configurer', '_plugins', $id, $qui, $opt);
1645
}
1646
1647
/**
1648
 * Autorisation de voir le menu admin_tech
1649
 *
1650
 * Il faut avoir accès à la page admin_tech
1651
 *
1652
 * @param  string $faire Action demandée
1653
 * @param  string $type Type d'objet sur lequel appliquer l'action
1654
 * @param  int $id Identifiant de l'objet
1655
 * @param  array $qui Description de l'auteur demandant l'autorisation
1656
 * @param  array $opt Options de cette autorisation
1657
 * @return bool          true s'il a le droit, false sinon
1658
 **/
1659
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...
1660
    return autoriser('detruire', $type, $id, $qui, $opt);
1661
}
1662
1663
/**
1664
 * Autorisation de purger la queue de travaux
1665
 *
1666
 * Il faut être webmestre.
1667
 *
1668
 * @param  string $faire Action demandée
1669
 * @param  string $type Type d'objet sur lequel appliquer l'action
1670
 * @param  int $id Identifiant de l'objet
1671
 * @param  array $qui Description de l'auteur demandant l'autorisation
1672
 * @param  array $opt Options de cette autorisation
1673
 * @return bool          true s'il a le droit, false sinon
1674
 **/
1675
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...
1676
	return autoriser('webmestre');
1677
}
1678
1679
1680
/**
1681
 * Autorisation l'échafaudage de squelettes en Z
1682
 *
1683
 * Il faut être dans l'espace privé (et authentifié),
1684
 * sinon il faut être webmestre (pas de fuite d'informations publiées)
1685
 *
1686
 * @param  string $faire Action demandée
1687
 * @param  string $type Type d'objet sur lequel appliquer l'action
1688
 * @param  int $id Identifiant de l'objet
1689
 * @param  array $qui Description de l'auteur demandant l'autorisation
1690
 * @param  array $opt Options de cette autorisation
1691
 * @return bool          true s'il a le droit, false sinon
1692
 **/
1693
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...
1694
	if (test_espace_prive()) {
1695
		return intval($qui['id_auteur']) ? true : false;
1696
	} else {
1697
		return autoriser('webmestre', '', $id, $qui, $opt);
1698
	}
1699
}
1700
1701
1702
/**
1703
 * Retourne les identifiants d'auteurs liés à un objet
1704
 *
1705
 * @param string $objet
1706
 * @param int $id_objet
1707
 * @param string|array $cond
1708
 *     Condition(s) supplémentaire(s) pour le where de la requête
1709
 * @return int[]
1710
 *     Identifiants d'auteurs
1711
 */
1712
function auteurs_objet($objet, $id_objet, $cond = '') {
1713
	$objet = objet_type($objet);
1714
	$where = array(
1715
		'objet=' . sql_quote($objet),
1716
		'id_objet=' . intval($id_objet)
1717
	);
1718
	if (!empty($cond)) {
1719
		if (is_array($cond)) {
1720
			$where = array_merge($where, $cond);
1721
		} else {
1722
			$where[] = $cond;
1723
		}
1724
	}
1725
	$auteurs = sql_allfetsel(
1726
		'id_auteur',
1727
		'spip_auteurs_liens',
1728
		$where
1729
	);
1730
	if (is_array($auteurs)) {
1731
		return array_map('reset', $auteurs);
1732
	}
1733
	return array();
1734
}
1735
1736
/**
1737
 * Lister les auteurs d'un article
1738
 *
1739
 * @deprecated utiliser auteurs_objets()
1740
 * @param int $id_article Identifiant de l'article
1741
 * @param string $cond Condition en plus dans le where de la requête
1742
 * @return array|bool
1743
 *     - array : liste des id_auteur trouvés
1744
 *     - false : serveur SQL indisponible
1745
 */
1746
function auteurs_article($id_article, $cond = '') {
1747
	return sql_allfetsel(
1748
		'id_auteur',
1749
		'spip_auteurs_liens',
1750
		"objet='article' AND id_objet=$id_article" . ($cond ? " AND $cond" : '')
1751
	);
1752
}
1753
1754
1755
/**
1756
 * Tester si on est admin restreint sur une rubrique donnée
1757
 *
1758
 * Fonction générique utilisee dans des autorisations ou assimilée
1759
 *
1760
 * @param int $id_rubrique Identifiant de la rubrique
1761
 * @return bool             true si administrateur de cette rubrique, false sinon.
1762
 */
1763
function acces_restreint_rubrique($id_rubrique) {
1764
1765
	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1766
}
1767
1768
1769
/**
1770
 * Verifier qu'il existe au moins un parent
1771
 *
1772
 * Fonction utilisee dans des autorisations des boutons / menus du prive des objets enfants (articles, breves, sites)
1773
 *
1774
 * @param string $table la table a vérifier
1775
 * @return bool             true si un parent existe
1776
 */
1777
function verifier_table_non_vide($table = 'spip_rubriques') {
1778
	static $done = array();
1779
	if (!isset($done[$table])) {
1780
		$done[$table] = sql_countsel($table) > 0;
1781
	}
1782
1783
	return $done[$table];
1784
}
1785
1786
/**
1787
 * Détermine la possibilité de s'inscire sur le site
1788
 *
1789
 * Pour un statut et un éventuel id_rubrique donné, indique,
1790
 * à l'aide de la liste globale des statuts (tableau mode => nom du mode)
1791
 * si le visiteur peut s'inscrire sur le site.
1792
 *
1793
 * Utile pour le formulaire d'inscription.
1794
 *
1795
 * Par défaut, seuls `6forum` et `1comite` sont possibles, les autres sont
1796
 * en `false`. Pour un nouveau mode il suffit de définir l'autorisation
1797
 * spécifique.
1798
 *
1799
 * @param  string $faire Action demandée
1800
 * @param  string $quoi Statut demandé
1801
 * @param  int $id Identifiant éventuel, par exemple de rubrique
1802
 * @param  array $qui Description de l'auteur demandant l'autorisation
1803
 * @param  array $opt Options de cette autorisation
1804
 * @return bool          true s'il a le droit, false sinon
1805
 */
1806
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...
1807
1808
	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1809
	switch ($s) {
1810
		case 'info_redacteurs':
1811
			return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1812
		case 'info_visiteurs':
1813
			return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1814
	}
1815
1816
	return false;
1817
}
1818
1819
1820
/**
1821
 * Autorisation à voir le phpinfo
1822
 *
1823
 * Il faut être webmestre
1824
 *
1825
 * @param  string $faire Action demandée
1826
 * @param  string $type Type d'objet sur lequel appliquer l'action
1827
 * @param  int $id Identifiant de l'objet
1828
 * @param  array $qui Description de l'auteur demandant l'autorisation
1829
 * @param  array $opt Options de cette autorisation
1830
 * @return bool          true s'il a le droit, false sinon
1831
 **/
1832
function autoriser_phpinfos($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...
1833
	return autoriser('webmestre');
1834
}
1835