Completed
Push — spip-2-stable ( d79e3d )
by cam
30:47 queued 16:59
created

naviguer.php ➔ contenu_naviguer()   F

Complexity

Conditions 22
Paths 3744

Size

Total Lines 129
Code Lines 64

Duplication

Lines 31
Ratio 24.03 %

Importance

Changes 0
Metric Value
cc 22
eloc 64
nc 3744
nop 2
dl 31
loc 129
rs 2
c 0
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/presentation');
16
include_spip('inc/forum');
17
18
// http://doc.spip.org/@exec_naviguer_dist
19
function exec_naviguer_dist()
20
{
21
	exec_naviguer_args(intval(_request('id_rubrique')),
22
			   _request('cherche_mot'),
23
			   intval(_request('select_groupe')));
24
}
25
26
// http://doc.spip.org/@exec_naviguer_args
27
function exec_naviguer_args($id_rubrique, $cherche_mot, $select_groupe)
28
{
29
	if (!$id_rubrique) {
30
		$lang = $statut = $titre = $extra = $id_parent=$id_secteur='';
0 ignored issues
show
Unused Code introduced by
$extra is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
31
		$ze_logo = "racine-site-24.gif";
32
		$row = array();
33
	} else {
34
		$row = sql_fetsel('id_parent, id_secteur, titre, statut, lang, descriptif, texte', 'spip_rubriques', "id_rubrique=$id_rubrique");
35
36
		if (!$row OR !autoriser('voir','rubrique',$id_rubrique)) {
37
			include_spip('inc/minipres');
38
			echo minipres();
39
		} else {
40
			$id_parent=$row['id_parent'];
41
			$id_secteur=$row['id_secteur'];
42
			$titre=$row['titre'];
43
			$statut = $row['statut'];
44
			$lang = $row["lang"];
45
46
			if ($id_parent == 0) $ze_logo = "secteur-24.gif";
47
			else $ze_logo = "rubrique-24.gif";
48
		}
49
	}
50
51
	if ($ze_logo) {
52
	pipeline('exec_init',array('args'=>array('exec'=>'naviguer','id_rubrique'=>$id_rubrique),'data'=>''));
53
54
	$commencer_page = charger_fonction('commencer_page', 'inc');
55
	echo $commencer_page(($titre ? ("&laquo; ".textebrut(typo($titre))." &raquo;") :
0 ignored issues
show
Bug introduced by
The variable $titre 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...
56
		    _T('titre_naviguer_dans_le_site')),
57
		   "naviguer",
58
		   "rubriques",
59
		   $id_rubrique);
60
61
	echo debut_grand_cadre(true);
62
	if ($id_rubrique  > 0)
63
		echo afficher_hierarchie($id_parent,_T('titre_cadre_interieur_rubrique'),$id_rubrique,'rubrique',$id_secteur,(!$GLOBALS['connect_toutes_rubriques']));
0 ignored issues
show
Bug introduced by
The variable $id_parent 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...
Bug introduced by
The variable $id_secteur 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...
64
	else $titre = _T('info_racine_site').": ". $GLOBALS['meta']["nom_site"];
65
66
	echo fin_grand_cadre(true);
67
68
	echo debut_gauche('', true);
69
70
	$flag_editable = autoriser('publierdans','rubrique',$id_rubrique);
71
72
	if ($flag_editable AND !$id_parent) {
73
		list($from, $where) = critere_statut_controle_forum('prop', $id_rubrique);
74
		$n_forums = sql_countsel($from, $where);
75
	} else 	$n_forums = 0;
76
77
	changer_typo($lang);
0 ignored issues
show
Bug introduced by
The variable $lang 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...
78
	echo infos_naviguer($id_rubrique, $statut, $row, $n_forums);
0 ignored issues
show
Bug introduced by
The variable $statut 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...
79
80
	$iconifier = charger_fonction('iconifier', 'inc');
81
	echo $iconifier('id_rubrique', $id_rubrique, 'naviguer', false, $flag_editable);
82
83
84
	echo pipeline('affiche_gauche',array('args'=>array('exec'=>'naviguer','id_rubrique'=>$id_rubrique),'data'=>''));
85
86
	echo creer_colonne_droite('', true);
87
	echo raccourcis_naviguer($id_rubrique, $id_parent);
88
	echo pipeline('affiche_droite',array('args'=>array('exec'=>'naviguer','id_rubrique'=>$id_rubrique),'data'=>''));
89
	echo debut_droite('', true);
90
91
	$haut = montre_naviguer($id_rubrique, $titre, $id_parent, $ze_logo, $flag_editable);
0 ignored issues
show
Bug introduced by
The variable $ze_logo 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...
92
93
	$boucles = contenu_naviguer($id_rubrique, $id_parent, $ze_logo, $flag_editable);
0 ignored issues
show
Unused Code introduced by
The call to contenu_naviguer() has too many arguments starting with $ze_logo.

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...
94
95
	if ($id_rubrique > 0) {
96
		$editer_mots = charger_fonction('editer_mots', 'inc');
97
		$editer_mots = $editer_mots('rubrique', $id_rubrique,  $cherche_mot,  $select_groupe, $flag_editable, true, 'naviguer');
98
	} else $editer_mots = '';
99
100
	echo naviguer_droite($row, $id_rubrique, $id_parent, $id_secteur, $haut, $n_forums, $editer_mots, $flag_editable, $boucles),
101
	  fin_gauche(),
102
	  fin_page();
103
	}
104
}
105
106
// http://doc.spip.org/@naviguer_droite
107
function naviguer_droite($row, $id_rubrique, $id_parent, $id_secteur, $haut, $n_forums, $editer_mots, $flag_editable, $boucles)
0 ignored issues
show
Unused Code introduced by
The parameter $row is not used and could be removed.

This check looks from parameters that have 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_secteur is not used and could be removed.

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

Loading history...
108
{
109
	global $spip_lang_right, $connect_toutes_rubriques;
110
111
	$onglet_proprietes =
112
		$editer_mots
113
		. langue_naviguer($id_rubrique, $id_parent, $flag_editable)
114
		. pipeline('affiche_milieu',array('args'=>array('exec'=>'naviguer','id_rubrique'=>$id_rubrique),'data'=>''))
115
	;
116
117
	$type = 'rubrique';
118
	$contexte = array('id'=>$id_rubrique,'id_rubrique'=>$id_rubrique);
119
	$fond = recuperer_fond("prive/contenu/$type",$contexte);
120
	// permettre aux plugin de faire des modifs ou des ajouts
121
	$fond = pipeline('afficher_contenu_objet',
122
			array(
123
			'args'=>array(
124
				'type'=>$type,
125
				'id_objet'=>$id_rubrique,
126
				'contexte'=>$contexte),
127
			'data'=> $fond));
128
	
129
	$onglet_contenu = "<div id='wysiwyg'>$fond</div>"
130
		. (_INTERFACE_ONGLETS? $boucles:"");
131
132
	include_spip('inc/presenter_enfants');
133
	$onglet_enfants =
134
	  afficher_enfant_rub($id_rubrique, false, true)
135
	  .(_INTERFACE_ONGLETS?"":
136
	   (autoriser('creerrubriquedans','rubrique',$id_rubrique)?"<div style='clear:$spip_lang_right;'>" .
137
	    (!$id_rubrique
138
		    ? icone_inline(_T('icone_creer_rubrique'), generer_url_ecrire("rubriques_edit","new=oui&retour=nav"), "secteur-24.gif", "creer.gif",$spip_lang_right)
139
		    : icone_inline(_T('icone_creer_sous_rubrique'), generer_url_ecrire("rubriques_edit","new=oui&retour=nav&id_parent=$id_rubrique"), "rubrique-24.gif", "creer.gif",$spip_lang_right))
140
	    ."</div>":""))
141
	  . "<div class='nettoyeur'></div>"
142
	  . $boucles;
143
144
	$onglet_enfants = pipeline('affiche_enfants',array('args'=>array('exec'=>'naviguer','id_rubrique'=>$id_rubrique),'data'=>$onglet_enfants));
145
146
	$documenter_objet = charger_fonction('documenter_objet','inc');
147
	$onglet_documents =
148
		($id_rubrique > 0 ? $documenter_objet($id_rubrique, "rubrique", 'naviguer', $flag_editable) :"" )
149
	;
150
151
	if ($n_forums)
152
	  $onglet_interactivite = icone_inline(_T('icone_suivi_forum', array('nb_forums' => $n_forums)), generer_url_ecrire("controle_forum","id_rubrique=$id_rubrique"), "suivi-forum-24.gif", "", 'center');
153
	else $onglet_interactivite = "";
154
155
	return
156
	  pipeline('afficher_fiche_objet',array('args'=>array('type'=>'rubrique','id'=>$id_rubrique),'data'=>
157
	  "<div class='fiche_objet'>".
158
		$haut.
159
		(_INTERFACE_ONGLETS?
160
		 afficher_onglets_pages(array(
161
			'sousrub'=> _T('onglet_sous_rubriques'),
162
			'voir' => _T('onglet_contenu'),
163
			'props' => _T('onglet_proprietes'),
164
			'docs' => _T('onglet_documents'),
165
			'interactivite' => _T('onglet_interactivite')),
166
					array(
167
			'voir'=>$onglet_contenu,
168
			'sousrub'=>$onglet_enfants,
169
			'props'=>$onglet_proprietes,
170
			'docs'=>$onglet_documents,
171
			'interactivite'=>$onglet_interactivite
172
			))
173
		 :$onglet_contenu.$onglet_proprietes).
174
	  "</div>".
175
	  (_INTERFACE_ONGLETS?"":$onglet_enfants.$onglet_documents.$onglet_interactivite)
176
				));
177
}
178
179
// http://doc.spip.org/@infos_naviguer
180
function infos_naviguer($id_rubrique, $statut, $row, $n_forums)
0 ignored issues
show
Unused Code introduced by
The parameter $statut is not used and could be removed.

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

Loading history...
181
{
182
	$boite = pipeline ('boite_infos', array('data' => '',
183
		'args' => array(
184
			'type'=>'rubrique',
185
			'id' => $id_rubrique,
186
			'row' => $row,
187
			'n_forums' => $n_forums
188
		)
189
	));
190
191
	$navigation =
192
	  ($boite ?debut_boite_info(true). $boite . fin_boite_info(true):"");
193
194
	$res = sql_allfetsel("A.nom, A.id_auteur", "spip_auteurs AS A LEFT JOIN spip_auteurs_rubriques AS R ON A.id_auteur=R.id_auteur", "A.statut = '0minirezo' AND R.id_rubrique=$id_rubrique");
195
196
	if (!$res) return $navigation;
197
198
	$img = http_img_pack('admin-12.gif','','');
199
	foreach ($res as $k => $row) {
200
		$h = generer_url_ecrire('auteur_infos', "id_auteur=" .$row['id_auteur']);
201
		$res[$k] = "$img <a href='$h'>" . $row['nom'] . '</a>';
202
	}
203
	$res = corriger_typo(join('<br />', $res));
204
205
	$navigation .= debut_cadre_relief("fiche-perso-24.gif", true, '', _T('info_administrateurs')). $res . fin_cadre_relief(true);
206
207
	return $navigation;
208
}
209
210
211
// http://doc.spip.org/@raccourcis_naviguer
212
function raccourcis_naviguer($id_rubrique, $id_parent)
213
{
214
	$res = icone_horizontale(_T('icone_tous_articles'), generer_url_ecrire("articles_page"), "article-24.gif", '',false);
215
216
	$n = sql_countsel('spip_rubriques');
217
	if ($n) {
218 View Code Duplication
		if (autoriser('creerarticledans','rubrique',$id_rubrique))
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...
219
		  $res .= icone_horizontale(_T('icone_ecrire_article'), generer_url_ecrire("articles_edit","id_rubrique=$id_rubrique&new=oui"), "article-24.gif","creer.gif", false);
220
221
		$activer_breves = $GLOBALS['meta']["activer_breves"];
0 ignored issues
show
Unused Code introduced by
$activer_breves is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
222 View Code Duplication
		if (autoriser('creerbrevedans','rubrique',$id_rubrique,NULL,array('id_parent'=>$id_parent))) {
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...
223
		  $res .= icone_horizontale(_T('icone_nouvelle_breve'), generer_url_ecrire("breves_edit","id_rubrique=$id_rubrique&new=oui"), "breve-24.gif","creer.gif", false);
224
		}
225
	}
226
	else {
227
		// Post-install = ici pas de rubrique, veuillez en creer une
228
		if (autoriser('creerrubriquedans','rubrique',$id_rubrique))
229
			$res .= "<br />"._T('info_creation_rubrique');
230
	}
231
232
	echo bloc_des_raccourcis($res);
233
}
234
235
// http://doc.spip.org/@langue_naviguer
236
function langue_naviguer($id_rubrique, $id_parent, $flag_editable)
237
{
238
	$res = "";
239
	if ($id_rubrique>0 AND $GLOBALS['meta']['multi_rubriques'] == 'oui' AND ($GLOBALS['meta']['multi_secteurs'] == 'non' OR $id_parent == 0) AND $flag_editable) {
240
241
		$row = sql_fetsel("lang, langue_choisie", "spip_rubriques", "id_rubrique=$id_rubrique");
242
		$langue_rubrique = $row['lang'];
243
		$langue_choisie_rubrique = $row['langue_choisie'];
0 ignored issues
show
Unused Code introduced by
$langue_choisie_rubrique is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
244
		$langue_parent = '';
245
		if ($id_parent) {
246
			$row = sql_fetsel("lang", "spip_rubriques", "id_rubrique=$id_parent");
247
			$langue_parent = $row['lang'];
248
		}
249
		if (!$langue_parent)
250
			$langue_parent = $GLOBALS['meta']['langue_site'];
251
		if (!$langue_rubrique)
252
			$langue_rubrique = $langue_parent;
253
254
		$res .= debut_cadre_enfonce('langues-24.gif', true);
255
		#$res .= bouton_block_depliable(_T('titre_langue_rubrique')."&nbsp; (".traduire_nom_langue($langue_rubrique).")",false,'languesrubrique');
256
257
		#$res .= debut_block_depliable(false,'languesrubrique');
258
		$res .= "<div class='langue'>";
259
		if ($menu = liste_options_langues('changer_lang', $langue_rubrique, $langue_parent)) {
260
			$lien = redirige_action_auteur('instituer_langue_rubrique', "$id_rubrique-$id_parent","naviguer","id_rubrique=$id_rubrique");
261
			$lien = ("\nonchange=\"document.location.href='$lien" .
262
				 "&amp;changer_lang='+this.options[this.selectedIndex].value\"");
263
			$res .= select_langues('changer_lang', $lien, $menu, _T('titre_langue_rubrique'));
264
		}
265
		$res .=  "</div>\n";
266
		#$res .=  fin_block();
267
		$res .=  fin_cadre_enfonce(true);
268
	}
269
	return $res;
270
}
271
272
// http://doc.spip.org/@contenu_naviguer
273
function contenu_naviguer($id_rubrique, $id_parent) {
274
275
	global  $spip_lang_right;
276
277
	//
278
	// Verifier les boucles a mettre en relief
279
	//
280
281
	$relief = sql_countsel('spip_articles', "id_rubrique=$id_rubrique AND statut='prop'");
282
283
	if (!$relief) {
284
		$relief = sql_countsel('spip_breves', "id_rubrique=$id_rubrique AND (statut='prepa' OR statut='prop')");
285
	}
286
287
	if (!$relief AND $GLOBALS['meta']['activer_sites'] != 'non') {
288
		$relief = sql_countsel('spip_syndic', "id_rubrique=$id_rubrique AND statut='prop'");
289
	}
290
291
	if (!$relief AND $GLOBALS['meta']['activer_syndic'] != 'non'
292
	AND autoriser('publierdans','rubrique',$id_rubrique)) {
293
		$relief = sql_countsel('spip_syndic', "id_rubrique=$id_rubrique AND (syndication='off' OR syndication='sus') AND statut='publie'");
294
	}
295
296
	$res = '';
297
298
	if ($relief) {
299
300
		$encours = "";
301
		//
302
		// Les articles a valider
303
		//
304
		$encours .= afficher_objets('article',_T('info_articles_proposes'),	array('WHERE' => "id_rubrique=$id_rubrique AND statut='prop'", 'ORDER BY' => "date DESC"));
305
306
		//
307
		// Les breves a valider
308
		//
309
		$encours .= afficher_objets('breve','<b>' . _T('info_breves_valider') . '</b>', array("FROM" => 'spip_breves', 'WHERE' => "id_rubrique=$id_rubrique AND (statut='prepa' OR statut='prop')", 'ORDER BY' => "date_heure DESC"), true);
310
311
		//
312
		// Les sites references a valider
313
		//
314 View Code Duplication
		if ($GLOBALS['meta']['activer_sites'] != 'non') {
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...
315
			$encours .= afficher_objets('site','<b>' . _T('info_site_valider') . '</b>', array("FROM" => 'spip_syndic', 'WHERE' => "id_rubrique=$id_rubrique AND statut='prop'", 'ORDER BY' => "nom_site"));
316
		}
317
318
		//
319
		// Les sites a probleme
320
		//
321 View Code Duplication
		if ($GLOBALS['meta']['activer_sites'] != 'non'
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...
322
		AND autoriser('publierdans','rubrique',$id_rubrique)) {
323
324
			$encours .= afficher_objets('site','<b>' . _T('avis_sites_syndiques_probleme') . '</b>', array('FROM' => 'spip_syndic', 'WHERE' => "id_rubrique=$id_rubrique AND (syndication='off' OR syndication='sus') AND statut='publie'", 'ORDER BY' => "nom_site"));
325
		}
326
327
		// Les articles syndiques en attente de validation
328
		if ($id_rubrique == 0
329
		AND autoriser('publierdans','rubrique',$id_rubrique)) {
330
331
			$cpt = sql_countsel("spip_syndic_articles", "statut='dispo'");
332 View Code Duplication
			if ($cpt)
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...
333
				$encours .= "<br /><small><a href='" .
334
					generer_url_ecrire("sites_tous") .
335
					"' style='color: black;'>" .
336
					$cpt .
337
					" " .
338
					_T('info_liens_syndiques_1') .
339
					" " .
340
					_T('info_liens_syndiques_2') .
341
					"</a></small>";
342
		}
343
344
		$res .= debut_cadre_couleur_foncee("",true, "", _T('texte_en_cours_validation')
345
				. (($GLOBALS['meta']['forum_prive_objets'] != 'non')
346
					? ' '._T('texte_en_cours_validation_forum')
347
					: '' )
348
				)
349
			. pipeline('rubrique_encours',array('args'=>array('type'=>'rubrique','id_objet'=>$id_rubrique),'data'=>$encours))
350
			. fin_cadre_couleur(true);
351
	}
352
353
	$n = sql_countsel('spip_rubriques');
354
	$bouton_article = $bouton_breves = $bouton_sites = "";
355
	if ($n && !_INTERFACE_ONGLETS) {
356 View Code Duplication
		if (autoriser('creerarticledans','rubrique',$id_rubrique))
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...
357
		  $bouton_article .= icone_inline(_T('icone_ecrire_article'), generer_url_ecrire("articles_edit","id_rubrique=$id_rubrique&new=oui"), "article-24.gif","creer.gif", $spip_lang_right)
358
		  . "<div class='nettoyeur'></div>";
359
360
		$activer_breves = $GLOBALS['meta']["activer_breves"];
0 ignored issues
show
Unused Code introduced by
$activer_breves is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
361 View Code Duplication
		if (autoriser('creerbrevedans','rubrique',$id_rubrique,NULL,array('id_parent'=>$id_parent)))
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...
362
		  $bouton_breves .= icone_inline(_T('icone_nouvelle_breve'), generer_url_ecrire("breves_edit","id_rubrique=$id_rubrique&new=oui"), "breve-24.gif","creer.gif", $spip_lang_right)
363
		  . "<div class='nettoyeur'></div>";
364
365 View Code Duplication
		if (autoriser('creersitedans','rubrique',$id_rubrique))
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...
366
			$bouton_sites .= icone_inline(_T('info_sites_referencer'), generer_url_ecrire('sites_edit', "id_rubrique=$id_rubrique"), "site-24.gif", "creer.gif", $spip_lang_right)
367
		  . "<div class='nettoyeur'></div>";
368
	}
369
370
	//////////  Les articles en cours de redaction
371
	/////////////////////////
372
373
  $res .= afficher_objets('article',_T('info_tous_articles_en_redaction'), array("WHERE" => "statut='prepa' AND id_rubrique=$id_rubrique", 'ORDER BY' => "date DESC"));
374
375
376
	//////////  Les articles publies
377
	/////////////////////////
378
379
	define('_TRI_ARTICLES_RUBRIQUE', 'date DESC');  # 0+titre,titre
380
	$res .= afficher_objets('article',_T('info_tous_articles_presents'), array("WHERE" => "statut='publie' AND id_rubrique=$id_rubrique", 'ORDER BY' => _TRI_ARTICLES_RUBRIQUE));
381
382
	// si une rubrique n'a pas/plus d'article publie, afficher les eventuels articles refuses
383
	// pour permettre de la vider et la supprimer eventuellement
384
	if (sql_countsel("spip_articles", "statut='publie' AND id_rubrique=".intval($id_rubrique), $groupby, $having)==0)
0 ignored issues
show
Bug introduced by
The variable $groupby does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
Bug introduced by
The variable $having does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
385
		$res .= afficher_objets('article',_T('info_tous_articles_refuses'), array("WHERE" => "statut='refuse' AND id_rubrique=$id_rubrique", 'ORDER BY' => _TRI_ARTICLES_RUBRIQUE));
386
387
  $res .= $bouton_article;
388
389
	//// Les breves
390
391
	$res .= afficher_objets('breve','<b>' . _T('icone_ecrire_nouvel_article') . '</b>', array("FROM" => 'spip_breves', 'WHERE' => "id_rubrique=$id_rubrique AND statut != 'prop' AND statut != 'prepa'", 'ORDER BY' => "date_heure DESC"));
392
  $res .= $bouton_breves;
393
394
	//// Les sites references
395
396 View Code Duplication
	if ($GLOBALS['meta']["activer_sites"] == 'oui') {
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...
397
		$res .= afficher_objets('site','<b>' . _T('titre_sites_references_rubrique') . '</b>', array("FROM" => 'spip_syndic', 'WHERE' => "id_rubrique=$id_rubrique AND statut!='refuse' AND statut != 'prop' AND syndication NOT IN ('off','sus')", 'ORDER BY' => 'nom_site'));
398
 		$res .= $bouton_sites;
399
	}
400
	return $res;
401
}
402
403
404
405
// http://doc.spip.org/@montre_naviguer
406
function montre_naviguer($id_rubrique, $titre, $id_parent, $ze_logo, $flag_editable)
407
{
408
	global $spip_lang_right;
409
410
	if ($flag_editable
411
	AND $id_rubrique > 0) {
412
		$actions = icone_inline(_T('icone_modifier_rubrique'),
413
			generer_url_ecrire("rubriques_edit",
414
				"id_rubrique=$id_rubrique&retour=nav"), $ze_logo, "edit.gif", $spip_lang_right);
415
416
		// Supprimer cette rubrique (si vide)
417
		if (tester_rubrique_vide($id_rubrique))
418
			$actions .= icone_inline(_T('icone_supprimer_rubrique'),
419
				redirige_action_auteur('supprimer', "rubrique-$id_rubrique", "naviguer","id_rubrique=$id_parent"), $ze_logo, "supprimer.gif", $spip_lang_right);
420
	}
421
	else
422
		$actions = ''; // rubrique non editable
423
424
	return
425
	  "<div class='bandeau_actions'>$actions</div>" .
426
	  gros_titre((!acces_restreint_rubrique($id_rubrique) ? '' :
427
	  http_img_pack("admin-12.gif",'', "width='12' height='12'",
428
			      _T('info_administrer_rubrique'))) .
429
	     $titre,'', false)
430
		. "<div class='nettoyeur'></div>\n";
431
}
432
433
// http://doc.spip.org/@tester_rubrique_vide
434
function tester_rubrique_vide($id_rubrique) {
435
	if (sql_countsel('spip_rubriques', "id_parent=$id_rubrique"))
436
		return false;
437
438
	if (sql_countsel('spip_articles', "id_rubrique=$id_rubrique AND (statut<>'poubelle')"))
439
		return false;
440
441
	if (sql_countsel('spip_breves', "id_rubrique=$id_rubrique AND (statut='publie' OR statut='prop')"))
442
		return false;
443
444
	if (sql_countsel('spip_syndic', "id_rubrique=$id_rubrique AND (statut='publie' OR statut='prop')"))
445
		return false;
446
447
	if (sql_countsel('spip_documents_liens', "id_objet=".intval($id_rubrique)." AND objet='rubrique'"))
448
		return false;
449
450
	$compte = pipeline('objet_compte_enfants',array('args'=>array('objet'=>'rubrique','id_objet'=>$id_rubrique),'data'=>array()));
451
	foreach($compte as $objet => $n)
452
		if ($n)
453
			return false;
454
455
	return true;
456
}
457
458
// http://doc.spip.org/@bouton_supprimer_naviguer
459
function bouton_supprimer_naviguer($id_rubrique, $id_parent, $ze_logo, $flag_editable)
460
{
461
	if (($id_rubrique>0) AND tester_rubrique_vide($id_rubrique) AND $flag_editable)
462
	  return icone_inline(_T('icone_supprimer_rubrique'), redirige_action_auteur('supprimer', "rubrique-$id_rubrique", "naviguer","id_rubrique=$id_parent"), $ze_logo, "supprimer.gif") . "</div>";
463
	return "";
464
}
465
466
?>
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...
467