Completed
Push — spip-3.0 ( 5d8b58 )
by cam
53:01 queued 42:30
created

admin_plugin.php ➔ admin_plug_args()   F

Complexity

Conditions 19
Paths 18432

Size

Total Lines 144
Code Lines 77

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 19
eloc 77
c 0
b 0
f 0
nc 18432
nop 3
dl 0
loc 144
rs 2

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
		$new = actualise_plugins_actifs();
34
		if ($new AND _request('actualise')<2) {
35
			include_spip('inc/headers');
36
			redirige_par_entete(parametre_url(self(),'actualise',_request('actualise')+1,'&'));
37
		}
38
		else {
39
			admin_plug_args(_request('voir'), _request('erreur'), _request('format'));
40
		}
41
	}
42
}
43
44
function admin_plug_args($quoi, $erreur, $format)
45
{
46
	if (!$quoi) $quoi = 'actifs';
47
	// empecher l'affichage des erreurs dans le bandeau, on le donne ensuite
48
	// format brut par plugin
49
	$GLOBALS['erreurs_activation_raw'] = plugin_donne_erreurs(true, false);
50
	// format resume mis en forme
51
	$erreur_activation = plugin_donne_erreurs();
52
	$commencer_page = charger_fonction('commencer_page', 'inc');
53
	echo $commencer_page(_T('icone_admin_plugin'), "configuration", "plugin");
54
55
	echo debut_gauche('plugin',true);
0 ignored issues
show
Unused Code introduced by
The call to debut_gauche() has too many arguments starting with 'plugin'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
56
	echo recuperer_fond('prive/squelettes/navigation/configurer',array('exec'=>'admin_plugin'));
57
58
	echo pipeline('affiche_gauche',
59
		array(
60
		'args'=>array('exec'=>'admin_plugin'),
61
		'data'=>afficher_librairies()
62
		)
63
	);
64
65
	echo debut_droite('plugin', true);
0 ignored issues
show
Unused Code introduced by
The call to debut_droite() has too many arguments starting with 'plugin'.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
66
	echo gros_titre(_T('icone_admin_plugin'),'',false);
0 ignored issues
show
Unused Code introduced by
The call to gros_titre() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
67
68
	// Barre d'onglets de premier niveau
69
	echo barre_onglets("plugins", "plugins_actifs");
70
	// Barre d'onglets de second niveau
71
	$onglet2 = $quoi=='actifs' ? 'plugins_actifs' : 'admin_plugin';
72
	echo debut_onglet('onglets_simple second');
73
	echo onglet(_T('plugins_tous_liste'), generer_url_ecrire("admin_plugin", "voir=tous"), 'admin_plugin', $onglet2);
74
	echo onglet(_T('plugins_actifs_liste'), generer_url_ecrire("admin_plugin"), 'plugins_actifs', $onglet2);
75
	echo fin_onglet();
76
77
	// message d'erreur au retour d'une operation
78
	if ($erreur)
79
		echo "<div class='error'>$erreur</div>";
80
	if ($erreur_activation){
81
		echo "<div class='error'>$erreur_activation</div>";
82
	}
83
84
	// la mise a jour de cette meta a ete faite par ecrire_plugin_actifs
85
	$actifs = unserialize($GLOBALS['meta']['plugin']);
86
	$lcpa = $actifs + unserialize($GLOBALS['meta']['plugin_attente']);
87
88
	// Les affichages se basent sur le repertoire, pas sur le nom
89
	$actifs = liste_chemin_plugin($actifs, '');
90
	if (defined('_DIR_PLUGINS_SUPPL'))
91
		$lcpas = liste_chemin_plugin($lcpa,_DIR_PLUGINS_SUPPL);
92
	$lcpa = liste_chemin_plugin($lcpa);
93
	
94
	// on installe les plugins maintenant,
95
	// cela permet aux scripts d'install de faire des affichages (moches...)
96
	plugin_installes_meta();
97
98
	echo "<div class='liste-plugins formulaire_spip'>";
99
	echo debut_cadre_trait_couleur('plugin-24.png',true,'',_T('plugins_liste'), 'plugins');
100
101
	if ($quoi!=='actifs'){
102
		$lpf = liste_plugin_files();
103
		if ($lpf)
104
			echo "<p>"._T('texte_presente_plugin')."</p>";
105
		else {
106
			if (!@is_dir(_DIR_PLUGINS))
107
				echo  "<p>"._T('plugin_info_automatique_ftp',array('rep'=>joli_repertoire(_DIR_PLUGINS)))
108
							. " &mdash; "._T('plugin_info_automatique_creer')."</p>";
109
		}
110
		$lcpaffiche = $lpf;
111
		if (defined('_DIR_PLUGINS_SUPPL'))
112
			$lcpaffichesup = liste_plugin_files(_DIR_PLUGINS_SUPPL);
113
	}
114
	else {
115
		// la liste
116
		// $quoi=='actifs'
117
		$lcpaffiche = $lcpa;
118
		if (defined('_DIR_PLUGINS_SUPPL'))
119
			$lcpaffichesup = $lcpas;
0 ignored issues
show
Bug introduced by
The variable $lcpas 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...
120
	}
121
122
	if ($quoi=='actifs' OR $lpf){
0 ignored issues
show
Bug introduced by
The variable $lpf 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...
123
		$nb = count($lcpa);
124
		if (defined('_DIR_PLUGINS_SUPPL'))
125
			$nb += count($lcpas);
126
		echo "<h3>".sinon(singulier_ou_pluriel($nb, 'plugins_actif_un', 'plugins_actifs', 'count'), _T('plugins_actif_aucun'))."</h3>";
127
	}
128
129
	if (empty($format))
130
	  $format = 'liste';
131
	elseif (!in_array($format,array('liste','repertoires')))
132
		$format = 'repertoires';
133
134
	$afficher = charger_fonction("afficher_$format",'plugins');
135
	$corps = $afficher(self(),$lcpaffiche, $lcpa, $actifs);
136
	if (defined('_DIR_PLUGINS_SUPPL'))
137
		$corps .= $afficher(self(),$lcpaffichesup, $lcpas, $actifs, _DIR_PLUGINS_SUPPL);
0 ignored issues
show
Bug introduced by
The variable $lcpaffichesup 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...
138
139
	if ($corps)
140
	  $corps .= "\n<div class='boutons' style='display:none;'>"
141
	    .  "<input type='submit' class='submit save' value='"._T('bouton_enregistrer')
142
	    ."' />"
143
	    . "</div>";
144
145
	echo redirige_action_post('activer_plugins','activer','admin_plugin','', $corps);
146
147
	echo fin_cadre_trait_couleur(true);
0 ignored issues
show
Unused Code introduced by
The call to fin_cadre_trait_couleur() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
148
149
	if ($quoi=='actifs')
150
		echo affiche_les_plugins_verrouilles($actifs);
151
	echo "</div>";
152
	
153
	echo 	http_script("
154
	jQuery(function(){
155
		jQuery('.plugins li.item a[rel=info]').click(function(){
156
			var li = jQuery(this).parents('li').eq(0);
157
			var prefix = li.find('input.checkbox').attr('name');
158
			if (!jQuery('div.details',li).html()) {
159
				jQuery('div.details',li).prepend(ajax_image_searching).load(
160
					jQuery(this).attr('href').replace(/admin_plugin|plugins/, 'info_plugin'), function(){
161
						li.addClass('on');
162
					}
163
				);
164
			}
165
			else {
166
				if (jQuery('div.details',li).toggle().is(':visible'))
167
					li.addClass('on');
168
				else
169
					li.removeClass('on');
170
			}
171
			return false;
172
		});
173
		jQuery('.plugins li.item input.checkbox').change(function(){
174
			jQuery(this).parents('form').eq(0).find('.boutons').slideDown();
175
		});
176
	});
177
	");
178
179
	echo pipeline('affiche_milieu',
180
		array(
181
		'args'=>array('exec'=>'admin_plugin'),
182
		'data'=>''
183
		)
184
	);
185
186
	echo fin_gauche(), fin_page();
187
}
188
189
function affiche_les_plugins_verrouilles($actifs)
190
{
191
	if ((!$liste = liste_plugin_files(_DIR_PLUGINS_DIST))) return '';
192
193
	$afficher = charger_fonction("afficher_liste",'plugins');
194
	$liste = $afficher(self(), $liste, array(), $actifs, _DIR_PLUGINS_DIST);
195
196
	return 
197
		"<div id='plugins_dist'>"
198
		. debut_cadre_trait_couleur('',true,'',_T('plugins_liste_dist'), 'liste_plugins_dist')
199
		. "<p>"
200
		. _T('plugin_info_plugins_dist_1', array('plugins_dist' => joli_repertoire(_DIR_PLUGINS_DIST)))
201
		. '<br />'. _T('plugin_info_plugins_dist_2')
202
		. "</p>"
203
		. $liste
204
		. fin_cadre_trait_couleur(true)
0 ignored issues
show
Unused Code introduced by
The call to fin_cadre_trait_couleur() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
205
		. "</div>\n";
206
}
207
208
/**
209
 * Afficher la liste des librairies presentes
210
 *
211
 * @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...
212
 */
213
function afficher_librairies(){
214
215
	if (!$libs = liste_librairies()) return '';
216
	ksort($libs);
217
	$res = debut_cadre_enfonce('', true, '', _T('plugin_librairies_installees'));
218
	$res .= '<dl>';
219
	foreach ($libs as $lib => $rep)
220
		$res .= "<dt>$lib</dt><dd>".joli_repertoire($rep)."</dd>\n";
221
	$res .= '</dl>';
222
	$res .= fin_cadre_enfonce(true);
0 ignored issues
show
Unused Code introduced by
The call to fin_cadre_enfonce() has too many arguments starting with true.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
223
	return $res;
224
}
225
226
227
/**
228
 * Faire la liste des librairies disponibles
229
 * retourne un array ( nom de la lib => repertoire , ... )
230
 *
231
 * @return array
232
 */
233
// http://doc.spip.org/@liste_librairies
234
function liste_librairies() {
235
	$libs = array();
236
	foreach (array_reverse(creer_chemin()) as $d) {
237
		if (is_dir($dir = $d.'lib/')
238
		AND $t = @opendir($dir)) {
239 View Code Duplication
			while (($f = readdir($t)) !== false) {
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...
240
				if ($f[0] != '.'
241
				AND is_dir("$dir/$f"))
242
					$libs[$f] = $dir;
243
			}
244
		}
245
	}
246
	return $libs;
247
}
248
?>
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...
249