Completed
Push — spip-2.1 ( b6b097 )
by cam
42:28 queued 30:44
created

admin_plugin.php ➔ exec_admin_plugin_dist()   F

Complexity

Conditions 26
Paths 12289

Size

Total Lines 173
Code Lines 93

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 26
eloc 93
nc 12289
nop 1
dl 0
loc 173
rs 2
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2016                                                *
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
if (!defined('_ECRIRE_INC_VERSION')) return;
14
15
include_spip('inc/config');
16
include_spip('inc/plugin');
17
include_spip('inc/presentation');
18
include_spip('inc/layer');
19
include_spip('inc/actions');
20
include_spip('inc/securiser_action');
21
22
// http://doc.spip.org/@exec_admin_plugin_dist
23
function exec_admin_plugin_dist($retour='') {
0 ignored issues
show
Unused Code introduced by
The parameter $retour is not used and could be removed.

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

Loading history...
24
25
	if (!autoriser('configurer', 'plugins')) {
26
		include_spip('inc/minipres');
27
		echo minipres();
28
	} else {
29
	// on fait la verif du path avant tout,
30
	// et l'installation des qu'on est dans la colonne principale
31
	// si jamais la liste des plugins actifs change, il faut faire un refresh du hit
32
	// pour etre sur que les bons fichiers seront charges lors de l'install
33
	if (actualise_plugins_actifs()==-1 AND _request('actualise')<2){
34
		include_spip('inc/headers');
35
		redirige_par_entete(parametre_url(self(),'actualise',_request('actualise')+1,'&'));
36
	}
37
38
	if ($erreur_activation = isset($GLOBALS['meta']['plugin_erreur_activation'])){
39
		$erreur_activation = $GLOBALS['meta']['plugin_erreur_activation'];
40
		// l'effacement reel de la meta se fera au moment de l'affichage
41
		// mais on la vide pour ne pas l'afficher dans le bandeau haut
42
		unset($GLOBALS['meta']['plugin_erreur_activation']);
43
	}
44
45
	$format = '';
46
	if (_request('format')!==NULL)
47
		$format = _request('format'); // liste ou repertoires
48
49
	$commencer_page = charger_fonction('commencer_page', 'inc');
50
	echo $commencer_page(_T('icone_admin_plugin'), "configuration", "plugin");
51
	echo "<br />\n";
52
	echo "<br />\n";
53
54
	$quoi = _request('voir');
55
	$quoi = $quoi ? $quoi : 'actifs';
56
57
	echo gros_titre(_T('icone_admin_plugin'),'',false);
58
	echo barre_onglets("plugins", $quoi=='actifs'?"plugins_actifs":"admin_plugin");
59
60
	echo debut_gauche('plugin',true);
61
	echo debut_boite_info(true);
62
	$s = "";
63
	$s .= _T('info_gauche_admin_tech');
64
	echo $s;
65
	echo fin_boite_info(true);
66
67
	// la valeur de retour de la fonction ci-dessus n'est pas compatible
68
	// avec ce que fait actualise_plugins_actifs, il faut recalculer. A revoir.
69
	$lcpa = liste_chemin_plugin_actifs();
70
71
	echo pipeline('affiche_gauche',
72
		array(
73
		'args'=>array('exec'=>'admin_plugin'),
74
		'data'=>afficher_librairies()
75
		)
76
	);
77
78
	echo debut_droite('plugin', true);
79
80
	// message d'erreur au retour d'un operation
81
	if (_request('erreur')){
82
		echo "<div class='erreur_message-plugins'>" . _T(_request('erreur')) . "</div>";
83
	}
84
	if ($erreur_activation){
85
		echo "<div class='erreur_message-plugins'>" . $erreur_activation . "</div>";
86
		effacer_meta('plugin_erreur_activation');
87
	}
88
89
90
	// on fait l'installation ici,
91
	// cela permet aux scripts d'install de faire des affichages (moches...)
92
	installe_plugins();
93
94
	$lpf = liste_plugin_files();
95
	$plugins_interessants = @array_keys(unserialize($GLOBALS['meta']['plugins_interessants']));
96
	if (!is_array($plugins_interessants))
97
		$plugins_interessants = array();
98
99
	echo "<div class='liste-plugins formulaire_spip'>";
100
101
	echo debut_cadre_trait_couleur('plugin-24.gif',true,'',_T('plugins_liste'),
102
	'plugins');
103
104
	if ($quoi!=='actifs'){
105
		if ($lpf)
106
			echo "<p>"._T('texte_presente_plugin')."</p>";
107
		else {
108
			if (!@is_dir(_DIR_PLUGINS))
109
				echo  "<p>"._T('plugin_info_automatique_ftp',array('rep'=>joli_repertoire(_DIR_PLUGINS)))
110
							. " &mdash; "._T('plugin_info_automatique_creer')."</p>";
111
		}
112
	}
113
114
	if ($quoi=='actifs' OR $lpf)
115
		echo "<h3>".sinon(
116
						singulier_ou_pluriel(count($lcpa), 'plugins_actif_un', 'plugins_actifs', 'count'),
117
						_T('plugins_actif_aucun')
118
						)."</h3>";
119
120
	$sub = "\n<div class='boutons'>"
121
	.  "<input type='submit' class='submit save' value='"._T('bouton_enregistrer')
122
	."' />"
123
	. "</div>";
124
125
	$no_button = false;
126
127
	// la liste
128
	if ($quoi=='actifs'){
129
		$aff = affiche_les_plugins($lcpa, $lcpa, $format);
130
		$no_button = !strlen($aff);
131
		$corps = $aff;
132
	}
133
	elseif ($quoi=='tous')
134
		$corps = affiche_les_plugins($lpf, $lcpa, $format);
135
	else {
136
		$dir_auto = substr(_DIR_PLUGINS_AUTO, strlen(_DIR_PLUGINS));
137
		$lcpaffiche = array();
138
		foreach ($lpf as $f)
139
			if (!strpos($f, '/')
140
			OR ($dir_auto AND substr($f, 0, strlen($dir_auto)) == $dir_auto)
141
			OR in_array($f, $lcpa)
142
			OR in_array($f, $plugins_interessants))
143
				$lcpaffiche[] = $f;
144
145
		$corps = affiche_les_plugins($lcpaffiche, $lcpa, $format);
146
	}
147
148
	if (!$no_button)
149
		$corps .= "\n<br />" . $sub;
150
151
	echo redirige_action_post('activer_plugins','activer','admin_plugin','', $corps);
152
153
	echo fin_cadre_trait_couleur(true);
154
155
	if ($quoi=='actifs')
156
		echo affiche_les_extensions(liste_chemin_plugin_actifs(_DIR_EXTENSIONS));
157
	echo "</div>";
158
	
159
	echo 	http_script("
160
	jQuery(function(){
161
		jQuery('#plugins .boutons').hide();
162
		jQuery('.plugins li.item a[rel=info]').click(function(){
163
			var li = jQuery(this).parents('li').eq(0);
164
			var prefix = li.find('input.checkbox').attr('name');
165
			if (!jQuery('div.details',li).html()) {
166
				jQuery('div.details',li).prepend(ajax_image_searching).load(
167
					jQuery(this).attr('href').replace(/admin_plugin|plugins/, 'info_plugin'), function(){
168
						li.addClass('on');
169
					}
170
				);
171
			}
172
			else {
173
				if (jQuery('div.details',li).toggle().is(':visible'))
174
					li.addClass('on');
175
				else
176
					li.removeClass('on');
177
			}
178
			return false;
179
		});
180
		jQuery('.plugins li.item input.checkbox').change(function(){
181
			jQuery(this).parents('form').eq(0).find('.boutons').slideDown();
182
		});
183
	});
184
	");
185
186
	echo pipeline('affiche_milieu',
187
		array(
188
		'args'=>array('exec'=>'admin_plugin'),
189
		'data'=>''
190
		)
191
	);
192
193
	echo fin_gauche(), fin_page();
194
	}
195
}
196
197
function affiche_les_extensions($liste_plugins_actifs){
198
	$res = "";
199
	if ($liste_extensions = liste_plugin_files(_DIR_EXTENSIONS)) {
200
		$res .= "<div id='extensions'>";
201
		$res .= debut_cadre_trait_couleur('',true,'',_T('plugins_liste_extensions'),
202
		'liste_extensions');
203
		$res .= "<p>"
204
			._T('plugin_info_extension_1', array('extensions' => joli_repertoire(_DIR_EXTENSIONS)))
205
			. '<br />'. _T('plugin_info_extension_2')
206
			."</p>";
207
208
		$format = 'liste';
209
		$afficher = charger_fonction("afficher_$format",'plugins');
210
		$res .= $afficher(self(), $liste_extensions,$liste_plugins_actifs, _DIR_EXTENSIONS);
211
212
		$res .= fin_cadre_trait_couleur(true);
213
		$res .= "</div>\n";
214
	}
215
	return $res;
216
}
217
218
// http://doc.spip.org/@affiche_les_plugins
219
function affiche_les_plugins($liste_plugins, $liste_plugins_actifs, $format='liste'){
220
	if (!$format)
221
		$format = 'liste';
222
	if (!in_array($format,array('liste','repertoires')))
223
		$format = 'repertoires';
224
225
	$afficher = charger_fonction("afficher_$format",'plugins');
226
	$res = $afficher(self(), $liste_plugins,$liste_plugins_actifs);
227
228
	if (!$res) return "";
229
#	var_dump(spip_timer('cachexml'));
230
231
232
	return	$res;
233
}
234
235
/**
236
 * Afficher la liste des librairies presentes
237
 *
238
 * @return <type>
0 ignored issues
show
Documentation introduced by
The doc-type <type> could not be parsed: Unknown type name "<" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
239
 */
240
function afficher_librairies(){
241
	$res = "";
242
	// Lister les librairies disponibles
243
	if ($libs = plugins_liste_librairies()) {
244
		$res .= debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
245
		ksort($libs);
246
		$res .= '<dl>';
247
		foreach ($libs as $lib => $rep)
248
			$res .= "<dt>$lib</dt><dd>".joli_repertoire($rep)."</dd>";
249
		$res .= '</dl>';
250
		$res .= fin_cadre_enfonce(true);
251
	}
252
	return $res;
253
}
254
255
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
256