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

menu_navigation.php ➔ exec_menu_navigation_dist()   F

Complexity

Conditions 13
Paths 1600

Size

Total Lines 97
Code Lines 66

Duplication

Lines 45
Ratio 46.39 %

Importance

Changes 0
Metric Value
cc 13
eloc 66
nc 1600
nop 0
dl 45
loc 97
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
17
// http://doc.spip.org/@exec_menu_navigation_dist
18
function exec_menu_navigation_dist() {
19
	global $connect_id_auteur, $spip_lang_left;
20
21
	$id_rubrique = intval(_request('id_rubrique'));
22
23
	$gadget = '<div style="width: 300px;">';
24
25
	$vos_articles = sql_select("articles.id_article, articles.id_rubrique, articles.titre, articles.statut", "spip_articles AS articles, spip_auteurs_articles AS lien", "articles.id_article=lien.id_article AND lien.id_auteur=$connect_id_auteur AND articles.statut='prepa'", "articles.date", "articles.date DESC", "5");
26
	$vos = '';
27 View Code Duplication
	while($row = sql_fetch($vos_articles)) {
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...
28
		$id_article = $row['id_article'];
29
		$titre = typo(sinon($row['titre'], _T('ecrire:info_sans_titre')));
30
		$statut = $row['statut'];
31
		$h = generer_url_ecrire("articles","id_article=$id_article");
32
		$vos .= "<a class='$statut spip_xx-small' href='$h'>$titre</a>\n";
33
	}
34 View Code Duplication
	if ($vos) {
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...
35
		$t = _T('info_en_cours_validation');
36
		$gadget .= debut_cadre('bandeau-rubriques',"article-24.gif",'',afficher_plus(generer_url_ecrire("articles_page")).$t)
37
		. "\n<div class='plan-articles'>\n"
38
		. $vos
39
		. "</div>"
40
		. fin_cadre('bandeau-rubriques');
41
	}
42
	
43
	$vos_articles = sql_select("id_article, id_rubrique, titre, statut", "spip_articles", "statut='prop'", "date", "date DESC", "5");
44
	$vos = '';
45 View Code Duplication
	while($row = sql_fetch($vos_articles)) {
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...
46
		$id_article = $row['id_article'];
47
		$titre = sinon($row['titre'], _T('ecrire:info_sans_titre'));
48
		$statut = $row['statut'];
49
		$h = generer_url_ecrire("articles","id_article=$id_article");
50
		$vos .= "<a class='$statut' href='$h'>$titre</a>";
51
	}
52 View Code Duplication
	if ($vos) {
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...
53
		$gadget .= debut_cadre('bandeau-rubriques',"article-24.gif",'',afficher_plus(generer_url_ecrire())._T('info_articles_proposes'))
54
		. "<div class='plan-articles'>"
55
		. $vos
56
		. "</div>"
57
		. fin_cadre('bandeau-rubriques');
58
	}
59
60
	$vos_articles = sql_select("id_breve,titre,statut", "spip_breves", "statut='prop'", "date_heure", "date_heure DESC", "5");
61
	$vos = '';
62
	while($row = sql_fetch($vos_articles)) {
63
		$id_breve = $row['id_breve'];
64
		$titre = typo(sinon($row['titre'], _T('ecrire:info_sans_titre')));
65
		$statut = $row['statut'];
66
		$vos .= "<a class='$statut spip_xx-small' href='" . generer_url_ecrire("breves_voir","id_breve=$id_breve") . "'>$titre</a>";
67
	}
68 View Code Duplication
	if ($vos) {
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...
69
		$gadget .= debut_cadre('bandeau-rubriques',"breve-24.gif",'',afficher_plus(generer_url_ecrire("breves"))._T('info_breves_valider'))
70
		. "<div class='plan-articles'>"
71
		. $vos
72
		. "</div>"
73
		. fin_cadre('bandeau-rubriques');
74
	}
75
76
	$une_rubrique = sql_getfetsel('id_rubrique', 'spip_rubriques', '','','', 1);
77
	if ($une_rubrique) {
78
79
		$gadget .= "<div>&nbsp;</div>";
80 View Code Duplication
		if ($id_rubrique > 0) {
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...
81
			$dans_rub = "&id_rubrique=$id_rubrique";
82
			$dans_parent = "&id_parent=$id_rubrique";
83
		} else $dans_rub = $dans_parent = '';
84
		if (autoriser('creerrubriquedans', 'rubrique', $id_rubrique)) {	
85
#			$gadget .= "<div style='width: 140px; float: $spip_lang_left;'>";
86
			if ($id_rubrique > 0)
87
				$gadget .= icone_horizontale_display(_T('icone_creer_sous_rubrique'), generer_url_ecrire("rubriques_edit","new=oui$dans_parent"), "rubrique-24.gif", "creer.gif", false);
88
			else 
89
				$gadget .= icone_horizontale_display(_T('icone_creer_rubrique'), generer_url_ecrire("rubriques_edit","new=oui"), "rubrique-24.gif", "creer.gif", false);
90
#			$gadget .= "</div>";
91
		}		
92
#		$gadget .= "<div style='width: 140px; float: $spip_lang_left;'>";
93
		$gadget .= icone_horizontale_display(_T('icone_ecrire_article'), generer_url_ecrire("articles_edit","new=oui$dans_rub"), "article-24.gif","creer.gif", false);
94
#		$gadget .= "</div>";
95
			
96 View Code Duplication
		if ($GLOBALS['meta']["activer_breves"] != "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...
97
#			$gadget .= "<div style='width: 140px;  float: $spip_lang_left;'>";
98
			$gadget .= icone_horizontale_display(_T('icone_nouvelle_breve'), generer_url_ecrire("breves_edit","new=oui$dans_rub"), "breve-24.gif","creer.gif", false);
99
#			$gadget .= "</div>";
100
		}
101
			
102
		if (autoriser('creersitedans', 'rubrique', $une_rubrique)) {
103
			$gadget .= # "<div style='width: 140px; float: $spip_lang_left;'>" .
104
			 icone_horizontale_display(_T('info_sites_referencer'), generer_url_ecrire("sites_edit","new=oui$dans_rub"), "site-24.gif","creer.gif", false)
105
			#. "</div>"
106
;
107
		}
108
			
109
	}
110
111
	$gadget .="</div>";
112
113
	ajax_retour($gadget);
114
}
115
?>
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...
116