Completed
Push — master ( d8d4cc...6b056b )
by cam
07:55
created

autoriser.php ➔ autoriser_previsualiser_dist()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 5
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2017                                                *
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 (isset($opt['webmestre']) and $opt['webmestre']) {
954
			return false;
955 View Code Duplication
		} elseif ((isset($opt['statut']) and $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...
956
			or (isset($opt['restreintes']) and $opt['restreintes'])
957
			or $opt['email']
958
		) {
959
			return false;
960
		} elseif ($id == $qui['id_auteur']) {
961
			return true;
962
		} else {
963
			return false;
964
		}
965
	}
966
967
	// Un admin restreint peut modifier/creer un auteur non-admin mais il
968
	// n'a le droit ni de le promouvoir admin, ni de changer les rubriques
969
	if ($qui['restreint']) {
970
		if (isset($opt['webmestre']) and $opt['webmestre']) {
971
			return false;
972 View Code Duplication
		} elseif ((isset($opt['statut']) and ($opt['statut'] == '0minirezo'))
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...
973
			or (isset($opt['restreintes']) and $opt['restreintes'])
974
		) {
975
			return false;
976
		} else {
977
			if ($id == $qui['id_auteur']) {
978
				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...
979
					return false;
980
				} else {
981
					return true;
982
				}
983
			} else {
984
				if ($id_auteur = intval($id)) {
985
					$t = sql_fetsel('statut', 'spip_auteurs', "id_auteur=$id_auteur");
986
					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...
987
						return true;
988
					} else {
989
						return false;
990
					}
991
				} // id = 0 => creation
992
				else {
993
					return true;
994
				}
995
			}
996
		}
997
	}
998
999
	// Un admin complet fait ce qu'il veut
1000
	// sauf se degrader
1001
	if ($id == $qui['id_auteur'] && (isset($opt['statut']) and $opt['statut'])) {
1002
		return false;
1003
	} elseif (isset($opt['webmestre'])
1004
				and $opt['webmestre']
1005
				and (defined('_ID_WEBMESTRES')
1006
				or !autoriser('webmestre'))) {
1007
		// et toucher au statut webmestre si il ne l'est pas lui meme
1008
		// ou si les webmestres sont fixes par constante (securite)
1009
		return false;
1010
	} // et modifier un webmestre si il ne l'est pas lui meme
1011
	elseif (intval($id) and autoriser('webmestre', '', 0, $id) and !autoriser('webmestre')) {
1012
		return false;
1013
	} else {
1014
		return true;
1015
	}
1016
}
1017
1018
1019
/**
1020
 * Autorisation d'associer un auteur sur un objet
1021
 *
1022
 * Il faut pouvoir modifier l'objet en question
1023
 *
1024
 * @param  string $faire Action demandée
1025
 * @param  string $type Type d'objet sur lequel appliquer l'action
1026
 * @param  int $id Identifiant de l'objet
1027
 * @param  array $qui Description de l'auteur demandant l'autorisation
1028
 * @param  array $opt Options de cette autorisation
1029
 * @return bool          true s'il a le droit, false sinon
1030
 **/
1031
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...
1032
	return autoriser('modifier', $type, $id, $qui, $opt);
1033
}
1034
1035
1036
/**
1037
 * Autorisation d'upload FTP
1038
 *
1039
 * Il faut être administrateur.
1040
 *
1041
 * @param  string $faire Action demandée
1042
 * @param  string $type Type d'objet sur lequel appliquer l'action
1043
 * @param  int $id Identifiant de l'objet
1044
 * @param  array $qui Description de l'auteur demandant l'autorisation
1045
 * @param  array $opt Options de cette autorisation
1046
 * @return bool          true s'il a le droit, false sinon
1047
 **/
1048
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...
1049
	return $qui['statut'] == '0minirezo';
1050
}
1051
1052
/**
1053
 * Autorisation d'activer le mode debug
1054
 *
1055
 * Il faut être administrateur.
1056
 *
1057
 * @param  string $faire Action demandée
1058
 * @param  string $type Type d'objet sur lequel appliquer l'action
1059
 * @param  int $id Identifiant de l'objet
1060
 * @param  array $qui Description de l'auteur demandant l'autorisation
1061
 * @param  array $opt Options de cette autorisation
1062
 * @return bool          true s'il a le droit, false sinon
1063
 **/
1064
function autoriser_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...
1065
	return $qui['statut'] == '0minirezo';
1066
}
1067
1068
/**
1069
 * Liste les rubriques d'un auteur
1070
 *
1071
 * Renvoie la liste des rubriques liées à cet auteur, independamment de son
1072
 * statut (pour les admins restreints, il faut donc aussi vérifier statut)
1073
 *
1074
 * Mémorise le resultat dans un tableau statique indéxé par les id_auteur.
1075
 * On peut reinitialiser un élément en passant un 2e argument non vide
1076
 *
1077
 * @param int $id_auteur Identifiant de l'auteur
1078
 * @param bool $raz Recalculer le résultat connu pour cet auteur
1079
 * @return array          Liste des rubriques
1080
 **/
1081
function liste_rubriques_auteur($id_auteur, $raz = false) {
1082
	static $restreint = array();
1083
1084
	if (!$id_auteur = intval($id_auteur)) {
1085
		return array();
1086
	}
1087
	if ($raz) {
1088
		unset($restreint[$id_auteur]);
1089
	} elseif (isset($restreint[$id_auteur])) {
1090
		return $restreint[$id_auteur];
1091
	}
1092
1093
	$rubriques = array();
1094
	if ((!isset($GLOBALS['meta']['version_installee'])
1095
		or $GLOBALS['meta']['version_installee'] > 16428)
1096
		and $r = sql_allfetsel(
1097
			'id_objet',
1098
			'spip_auteurs_liens',
1099
			'id_auteur=' . intval($id_auteur) . " AND objet='rubrique' AND id_objet!=0"
1100
		)
1101
		and count($r)
1102
	) {
1103
		$r = array_map('reset', $r);
1104
1105
		// recuperer toute la branche, au format chaine enumeration
1106
		include_spip('inc/rubriques');
1107
		$r = calcul_branche_in($r);
1108
		$r = explode(',', $r);
1109
1110
		// passer les rubriques en index, elimine les doublons
1111
		$r = array_flip($r);
1112
		// recuperer les index seuls
1113
		$r = array_keys($r);
1114
		// combiner pour avoir un tableau id_rubrique=>id_rubrique
1115
		// est-ce vraiment utile ? (on preserve la forme donnee par le code precedent)
1116
		$rubriques = array_combine($r, $r);
1117
	}
1118
1119
	// Affecter l'auteur session le cas echeant
1120 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...
1121
		and $GLOBALS['visiteur_session']['id_auteur'] == $id_auteur
1122
	) {
1123
		$GLOBALS['visiteur_session']['restreint'] = $rubriques;
1124
	}
1125
1126
1127
	return $restreint[$id_auteur] = $rubriques;
1128
}
1129
1130
/**
1131
 * Autorisation de modifier l'URL d'un objet
1132
 *
1133
 * Il faut pouvoir modifier l'objet.
1134
 *
1135
 * @param  string $faire Action demandée
1136
 * @param  string $type Type d'objet sur lequel appliquer l'action
1137
 * @param  int $id Identifiant de l'objet
1138
 * @param  array $qui Description de l'auteur demandant l'autorisation
1139
 * @param  array $opt Options de cette autorisation
1140
 * @return bool          true s'il a le droit, false sinon
1141
 **/
1142
function autoriser_modifierurl_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...
1143
	return autoriser('modifier', $type, $id, $qui, $opt);
1144
}
1145
1146
/**
1147
 * Autorisation de prévisualiser une rubrique
1148
 *
1149
 * Il faut pouvoir prévisualiser.
1150
 *
1151
 * @param  string $faire Action demandée
1152
 * @param  string $type Type d'objet sur lequel appliquer l'action
1153
 * @param  int $id Identifiant de l'objet
1154
 * @param  array $qui Description de l'auteur demandant l'autorisation
1155
 * @param  array $opt Options de cette autorisation
1156
 * @return bool          true s'il a le droit, false sinon
1157
 **/
1158
function autoriser_rubrique_previsualiser_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $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...
1159
	return autoriser('previsualiser');
1160
}
1161
1162
/**
1163
 * Autorisation d'iconifier une rubrique (mettre un logo)
1164
 *
1165
 * Il faut pouvoir publier dans la rubrique.
1166
 *
1167
 * @param  string $faire Action demandée
1168
 * @param  string $type Type d'objet sur lequel appliquer l'action
1169
 * @param  int $id Identifiant de l'objet
1170
 * @param  array $qui Description de l'auteur demandant l'autorisation
1171
 * @param  array $opt Options de cette autorisation
1172
 * @return bool          true s'il a le droit, false sinon
1173
 **/
1174
function autoriser_rubrique_iconifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

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

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

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

Loading history...
1175
	return autoriser('publierdans', 'rubrique', $id, $qui, $opt);
1176
}
1177
1178
/**
1179
 * Autorisation d'iconifier un auteur (mettre un logo)
1180
 *
1181
 * Il faut un administrateur ou que l'auteur soit celui qui demande l'autorisation
1182
 *
1183
 * @param  string $faire Action demandée
1184
 * @param  string $type Type d'objet sur lequel appliquer l'action
1185
 * @param  int $id Identifiant de l'objet
1186
 * @param  array $qui Description de l'auteur demandant l'autorisation
1187
 * @param  array $opt Options de cette autorisation
1188
 * @return bool          true s'il a le droit, false sinon
1189
 **/
1190
function autoriser_auteur_iconifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $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...
1191
	return (($id == $qui['id_auteur']) or
1192
		(($qui['statut'] == '0minirezo') and !$qui['restreint']));
1193
}
1194
1195
/**
1196
 * Autorisation d'iconifier un objet (mettre un logo)
1197
 *
1198
 * Il faut pouvoir modifier l'objet
1199
 *
1200
 * @param  string $faire Action demandée
1201
 * @param  string $type Type d'objet sur lequel appliquer l'action
1202
 * @param  int $id Identifiant de l'objet
1203
 * @param  array $qui Description de l'auteur demandant l'autorisation
1204
 * @param  array $opt Options de cette autorisation
1205
 * @return bool          true s'il a le droit, false sinon
1206
 **/
1207
function autoriser_iconifier_dist($faire, $type, $id, $qui, $opt) {
0 ignored issues
show
Unused Code introduced by
The parameter $faire is not used and could be removed.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Loading history...
1378
	return true;
1379
}
1380
1381
/**
1382
 * Autorisation de voir le menu auteurs
1383
 *
1384
 * Toujours OK
1385
 *
1386
 * @param  string $faire Action demandée
1387
 * @param  string $type Type d'objet sur lequel appliquer l'action
1388
 * @param  int $id Identifiant de l'objet
1389
 * @param  array $qui Description de l'auteur demandant l'autorisation
1390
 * @param  array $opt Options de cette autorisation
1391
 * @return bool          true s'il a le droit, false sinon
1392
 **/
1393
function autoriser_auteurs_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...
1394
	return true;
1395
}
1396
1397
/**
1398
 * Autorisation de voir le menu articles
1399
 *
1400
 * Toujours OK
1401
 *
1402
 * @param  string $faire Action demandée
1403
 * @param  string $type Type d'objet sur lequel appliquer l'action
1404
 * @param  int $id Identifiant de l'objet
1405
 * @param  array $qui Description de l'auteur demandant l'autorisation
1406
 * @param  array $opt Options de cette autorisation
1407
 * @return bool          true s'il a le droit, false sinon
1408
 **/
1409
function autoriser_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...
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...
1410
	return true;
1411
}
1412
1413
/**
1414
 * Autorisation de voir le menu rubriques
1415
 *
1416
 * Toujours OK
1417
 *
1418
 * @param  string $faire Action demandée
1419
 * @param  string $type Type d'objet sur lequel appliquer l'action
1420
 * @param  int $id Identifiant de l'objet
1421
 * @param  array $qui Description de l'auteur demandant l'autorisation
1422
 * @param  array $opt Options de cette autorisation
1423
 * @return bool          true s'il a le droit, false sinon
1424
 **/
1425
function autoriser_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...
Unused Code introduced by
The parameter $id is not used and could be removed.

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

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

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

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

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

Loading history...
1426
	return true;
1427
}
1428
1429
/**
1430
 * Autorisation de voir le menu articlecreer
1431
 *
1432
 * Il faut au moins une rubrique présente.
1433
 *
1434
 * @param  string $faire Action demandée
1435
 * @param  string $type Type d'objet sur lequel appliquer l'action
1436
 * @param  int $id Identifiant de l'objet
1437
 * @param  array $qui Description de l'auteur demandant l'autorisation
1438
 * @param  array $opt Options de cette autorisation
1439
 * @return bool          true s'il a le droit, false sinon
1440
 **/
1441
function autoriser_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...
1442
	return verifier_table_non_vide();
1443
}
1444
1445
1446
/**
1447
 * Autorisation de voir le menu auteurcreer
1448
 *
1449
 * Il faut pouvoir créer un auteur !
1450
 *
1451
 * @see autoriser_auteur_creer_dist()
1452
 *
1453
 * @param  string $faire Action demandée
1454
 * @param  string $type Type d'objet sur lequel appliquer l'action
1455
 * @param  int $id Identifiant de l'objet
1456
 * @param  array $qui Description de l'auteur demandant l'autorisation
1457
 * @param  array $opt Options de cette autorisation
1458
 * @return bool          true s'il a le droit, false sinon
1459
 **/
1460
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...
1461
	return autoriser('creer', 'auteur', $id, $qui, $opt);
1462
}
1463
1464
/**
1465
 * Autorisation de voir le menu suiviedito
1466
 *
1467
 * Il faut être administrateur (y compris restreint).
1468
 *
1469
 * @param  string $faire Action demandée
1470
 * @param  string $type Type d'objet sur lequel appliquer l'action
1471
 * @param  int $id Identifiant de l'objet
1472
 * @param  array $qui Description de l'auteur demandant l'autorisation
1473
 * @param  array $opt Options de cette autorisation
1474
 * @return bool          true s'il a le droit, false sinon
1475
 **/
1476
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...
1477
	return $qui['statut'] == '0minirezo';
1478
}
1479
1480
/**
1481
 * Autorisation de voir le menu synchro
1482
 *
1483
 * Il faut être administrateur (y compris restreint).
1484
 *
1485
 * @param  string $faire Action demandée
1486
 * @param  string $type Type d'objet sur lequel appliquer l'action
1487
 * @param  int $id Identifiant de l'objet
1488
 * @param  array $qui Description de l'auteur demandant l'autorisation
1489
 * @param  array $opt Options de cette autorisation
1490
 * @return bool          true s'il a le droit, false sinon
1491
 **/
1492
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...
1493
	return $qui['statut'] == '0minirezo';
1494
}
1495
1496
/**
1497
 * Autorisation de voir le menu configurer_interactions
1498
 *
1499
 * Il faut avoir accès à la page configurer_interactions
1500
 *
1501
 * @param  string $faire Action demandée
1502
 * @param  string $type Type d'objet sur lequel appliquer l'action
1503
 * @param  int $id Identifiant de l'objet
1504
 * @param  array $qui Description de l'auteur demandant l'autorisation
1505
 * @param  array $opt Options de cette autorisation
1506
 * @return bool          true s'il a le droit, false sinon
1507
 **/
1508
function autoriser_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...
1509
    return autoriser('configurer', '_interactions', $id, $qui, $opt);
1510
}
1511
1512
/**
1513
 * Autorisation de voir le menu configurer_langue
1514
 *
1515
 * Il faut avoir accès à la page configurer_langue
1516
 *
1517
 * @param  string $faire Action demandée
1518
 * @param  string $type Type d'objet sur lequel appliquer l'action
1519
 * @param  int $id Identifiant de l'objet
1520
 * @param  array $qui Description de l'auteur demandant l'autorisation
1521
 * @param  array $opt Options de cette autorisation
1522
 * @return bool          true s'il a le droit, false sinon
1523
 **/
1524
function autoriser_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...
1525
    return autoriser('configurer', '_langue', $id, $qui, $opt);
1526
}
1527
1528
/**
1529
 * Autorisation de voir le menu configurer_multilinguisme
1530
 *
1531
 * Il faut avoir accès à la page configurer_multilinguisme
1532
 *
1533
 * @param  string $faire Action demandée
1534
 * @param  string $type Type d'objet sur lequel appliquer l'action
1535
 * @param  int $id Identifiant de l'objet
1536
 * @param  array $qui Description de l'auteur demandant l'autorisation
1537
 * @param  array $opt Options de cette autorisation
1538
 * @return bool          true s'il a le droit, false sinon
1539
 **/
1540
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...
1541
    return autoriser('configurer', '_multilinguisme', $id, $qui, $opt);
1542
}
1543
1544
/**
1545
 * Autorisation de voir le menu configurer_contenu
1546
 *
1547
 * Il faut avoir accès à la page configurer_contenu
1548
 *
1549
 * @param  string $faire Action demandée
1550
 * @param  string $type Type d'objet sur lequel appliquer l'action
1551
 * @param  int $id Identifiant de l'objet
1552
 * @param  array $qui Description de l'auteur demandant l'autorisation
1553
 * @param  array $opt Options de cette autorisation
1554
 * @return bool          true s'il a le droit, false sinon
1555
 **/
1556
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...
1557
    return autoriser('configurer', '_contenu', $id, $qui, $opt);
1558
}
1559
1560
/**
1561
 * Autorisation de voir le menu configurer_avancees
1562
 *
1563
 * Il faut avoir accès à la page configurer_avancees
1564
 *
1565
 * @param  string $faire Action demandée
1566
 * @param  string $type Type d'objet sur lequel appliquer l'action
1567
 * @param  int $id Identifiant de l'objet
1568
 * @param  array $qui Description de l'auteur demandant l'autorisation
1569
 * @param  array $opt Options de cette autorisation
1570
 * @return bool          true s'il a le droit, false sinon
1571
 **/
1572
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...
1573
    return autoriser('configurer', '_avancees', $id, $qui, $opt);
1574
}
1575
1576
/**
1577
 * Autorisation de voir le menu admin_plugin
1578
 *
1579
 * Il faut avoir accès à la page admin_plugin
1580
 *
1581
 * @param  string $faire Action demandée
1582
 * @param  string $type Type d'objet sur lequel appliquer l'action
1583
 * @param  int $id Identifiant de l'objet
1584
 * @param  array $qui Description de l'auteur demandant l'autorisation
1585
 * @param  array $opt Options de cette autorisation
1586
 * @return bool          true s'il a le droit, false sinon
1587
 **/
1588
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...
1589
    return autoriser('configurer', '_plugins', $id, $qui, $opt);
1590
}
1591
1592
/**
1593
 * Autorisation de voir le menu admin_tech
1594
 *
1595
 * Il faut avoir accès à la page admin_tech
1596
 *
1597
 * @param  string $faire Action demandée
1598
 * @param  string $type Type d'objet sur lequel appliquer l'action
1599
 * @param  int $id Identifiant de l'objet
1600
 * @param  array $qui Description de l'auteur demandant l'autorisation
1601
 * @param  array $opt Options de cette autorisation
1602
 * @return bool          true s'il a le droit, false sinon
1603
 **/
1604
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...
1605
    return autoriser('detruire', $type, $id, $qui, $opt);
1606
}
1607
1608
/**
1609
 * Autorisation de purger la queue de travaux
1610
 *
1611
 * Il faut être webmestre.
1612
 *
1613
 * @param  string $faire Action demandée
1614
 * @param  string $type Type d'objet sur lequel appliquer l'action
1615
 * @param  int $id Identifiant de l'objet
1616
 * @param  array $qui Description de l'auteur demandant l'autorisation
1617
 * @param  array $opt Options de cette autorisation
1618
 * @return bool          true s'il a le droit, false sinon
1619
 **/
1620
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...
1621
	return autoriser('webmestre');
1622
}
1623
1624
1625
/**
1626
 * Autorisation l'échafaudage de squelettes en Z
1627
 *
1628
 * Il faut être dans l'espace privé (et authentifié),
1629
 * sinon il faut être webmestre (pas de fuite d'informations publiées)
1630
 *
1631
 * @param  string $faire Action demandée
1632
 * @param  string $type Type d'objet sur lequel appliquer l'action
1633
 * @param  int $id Identifiant de l'objet
1634
 * @param  array $qui Description de l'auteur demandant l'autorisation
1635
 * @param  array $opt Options de cette autorisation
1636
 * @return bool          true s'il a le droit, false sinon
1637
 **/
1638
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...
1639
	if (test_espace_prive()) {
1640
		return intval($qui['id_auteur']) ? true : false;
1641
	} else {
1642
		return autoriser('webmestre', '', $id, $qui, $opt);
1643
	}
1644
}
1645
1646
1647
/**
1648
 * Retourne les identifiants d'auteurs liés à un objet
1649
 *
1650
 * @param string $objet
1651
 * @param int $id_objet
1652
 * @param string|array $cond
1653
 *     Condition(s) supplémentaire(s) pour le where de la requête
1654
 * @return int[]
1655
 *     Identifiants d'auteurs
1656
 */
1657
function auteurs_objet($objet, $id_objet, $cond = '') {
1658
	$objet = objet_type($objet);
1659
	$where = array(
1660
		'objet=' . sql_quote($objet),
1661
		'id_objet=' . intval($id_objet)
1662
	);
1663
	if (!empty($cond)) {
1664
		if (is_array($cond)) {
1665
			$where = array_merge($where, $cond);
1666
		} else {
1667
			$where[] = $cond;
1668
		}
1669
	}
1670
	$auteurs = sql_allfetsel(
1671
		'id_auteur',
1672
		'spip_auteurs_liens',
1673
		$where
1674
	);
1675
	if (is_array($auteurs)) {
1676
		return array_map('reset', $auteurs);
1677
	}
1678
	return array();
1679
}
1680
1681
/**
1682
 * Lister les auteurs d'un article
1683
 *
1684
 * @deprecated utiliser auteurs_objets()
1685
 * @param int $id_article Identifiant de l'article
1686
 * @param string $cond Condition en plus dans le where de la requête
1687
 * @return array|bool
1688
 *     - array : liste des id_auteur trouvés
1689
 *     - false : serveur SQL indisponible
1690
 */
1691
function auteurs_article($id_article, $cond = '') {
1692
	return sql_allfetsel(
1693
		'id_auteur',
1694
		'spip_auteurs_liens',
1695
		"objet='article' AND id_objet=$id_article" . ($cond ? " AND $cond" : '')
1696
	);
1697
}
1698
1699
1700
/**
1701
 * Tester si on est admin restreint sur une rubrique donnée
1702
 *
1703
 * Fonction générique utilisee dans des autorisations ou assimilée
1704
 *
1705
 * @param int $id_rubrique Identifiant de la rubrique
1706
 * @return bool             true si administrateur de cette rubrique, false sinon.
1707
 */
1708
function acces_restreint_rubrique($id_rubrique) {
1709
1710
	return (isset($GLOBALS['connect_id_rubrique'][$id_rubrique]));
1711
}
1712
1713
1714
/**
1715
 * Verifier qu'il existe au moins un parent
1716
 *
1717
 * Fonction utilisee dans des autorisations des boutons / menus du prive des objets enfants (articles, breves, sites)
1718
 *
1719
 * @param string $table la table a vérifier
1720
 * @return bool             true si un parent existe
1721
 */
1722
function verifier_table_non_vide($table = 'spip_rubriques') {
1723
	static $done = array();
1724
	if (!isset($done[$table])) {
1725
		$done[$table] = sql_countsel($table) > 0;
1726
	}
1727
1728
	return $done[$table];
1729
}
1730
1731
/**
1732
 * Détermine la possibilité de s'inscire sur le site
1733
 *
1734
 * Pour un statut et un éventuel id_rubrique donné, indique,
1735
 * à l'aide de la liste globale des statuts (tableau mode => nom du mode)
1736
 * si le visiteur peut s'inscrire sur le site.
1737
 *
1738
 * Utile pour le formulaire d'inscription.
1739
 *
1740
 * Par défaut, seuls `6forum` et `1comite` sont possibles, les autres sont
1741
 * en `false`. Pour un nouveau mode il suffit de définir l'autorisation
1742
 * spécifique.
1743
 *
1744
 * @param  string $faire Action demandée
1745
 * @param  string $quoi Statut demandé
1746
 * @param  int $id Identifiant éventuel, par exemple de rubrique
1747
 * @param  array $qui Description de l'auteur demandant l'autorisation
1748
 * @param  array $opt Options de cette autorisation
1749
 * @return bool          true s'il a le droit, false sinon
1750
 */
1751
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...
1752
1753
	$s = array_search($quoi, $GLOBALS['liste_des_statuts']);
1754
	switch ($s) {
1755
		case 'info_redacteurs':
1756
			return ($GLOBALS['meta']['accepter_inscriptions'] == 'oui');
1757
		case 'info_visiteurs':
1758
			return ($GLOBALS['meta']['accepter_visiteurs'] == 'oui' or $GLOBALS['meta']['forums_publics'] == 'abo');
1759
	}
1760
1761
	return false;
1762
}
1763
1764
1765
/**
1766
 * Autorisation à voir le phpinfo
1767
 *
1768
 * Il faut être webmestre
1769
 *
1770
 * @param  string $faire Action demandée
1771
 * @param  string $type Type d'objet sur lequel appliquer l'action
1772
 * @param  int $id Identifiant de l'objet
1773
 * @param  array $qui Description de l'auteur demandant l'autorisation
1774
 * @param  array $opt Options de cette autorisation
1775
 * @return bool          true s'il a le droit, false sinon
1776
 **/
1777
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...
1778
	return autoriser('webmestre');
1779
}
1780