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

signatures.php ➔ signatures_edit()   F

Complexity

Conditions 14
Paths 2016

Size

Total Lines 92
Code Lines 72

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 72
nc 2016
nop 4
dl 0
loc 92
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
// http://doc.spip.org/@message_de_signature
16
function message_de_signature($row)
17
{
18
	return propre(echapper_tags($row['message']));
19
}
20
21
// http://doc.spip.org/@inc_signatures_dist
22
function inc_signatures_dist($script, $id, $debut, $pas, $where, $order, $type='') {
23
24
	if ($id) { 
25
		$args = "id_article=$id&";
26
	}
27
	else $args = "";
28
29
	$t = sql_countsel("spip_signatures", $where);
30
	if ($t > $pas) {
31
		$res = navigation_pagination($t, $pas, generer_url_ecrire($script, $args), $debut, 'debut', false);
32
	} else $res = '';
33
34
	$limit = (!$pas AND !$debut) ? '' : (($debut ? "$debut," : "") . $pas);
35
36
	$arg = "debut=$debut&type=$type";
37
38
	$res .= "<br />\n";
39
	include_spip('inc/urls');
40
	$r = sql_allfetsel('*', 'spip_signatures', $where, '', $order, $limit);
41
	foreach($r as $k => $row)
42
		$r[$k] = signatures_edit($script, $id, $arg, $row);
43
44
	return $res."<br />\n" . join("<br />\n", $r);
45
}
46
47
// http://doc.spip.org/@signatures_edit
48
function signatures_edit($script, $id, $arg, $row) {
49
50
	global $spip_lang_right, $spip_lang_left;
51
	$id_signature = $row['id_signature'];
52
	$id_article = $row['id_article'];
53
	$date_time = $row['date_time'];
54
	$nom_email= typo(echapper_tags($row['nom_email']));
55
	$ad_email = echapper_tags($row['ad_email']);
56
	$nom_site = typo(echapper_tags($row['nom_site']));
57
	$url_site = echapper_tags($row['url_site']);
58
	$statut = $row['statut'];
59
60
	$res = !autoriser('modererpetition', 'article', $id_article) ? '' : true;
61
62
	if ($res) {
63
		if ($id) $arg .= "&id_article=$id_article";
64
		$arg .= "#signature$id_signature";
65
		$retour_s = redirige_action_auteur('editer_signatures', $id_signature, $script, $arg);
66
		$retour_a = redirige_action_auteur('editer_signatures', "-$id_signature", $script, $arg);
67
68
		if  ($statut=="poubelle"){
69
			$res = icone_inline (_T('icone_valider_signature'),
70
				$retour_s,
71
				"forum-interne-24.gif", 
72
				"creer.gif",
73
				"right",
74
				false);
75
		} else {
76
			$res = icone_inline (_T('icone_supprimer_signature'),
77
				$retour_a,
78
				"forum-interne-24.gif", 
79
				"supprimer.gif",
80
				"right",
81
				false);
82
			if ($statut<>"publie") {
83
				$res .= icone_inline (_T('icone_relancer_signataire'),
84
				$retour_s,
85
				"forum-interne-24.gif", 
86
				"creer.gif",
87
				"right",
88
				false);
89
			}
90
		}
91
		$res = "<div class='editer_auteurs'>$res</div>";
92
	}
93
94
	$res .= "<div class='spip_small date'>".date_interface($date_time)."</div>\n";
95
	if ($statut=="poubelle"){
96
		$res .= "<div class='spip_x-small info_statut'>"._T('info_message_efface')."</div>\n";
97
	}
98
	if (strlen($url_site)>6) {
99
		if (!$nom_site) $nom_site = _T('info_site');
100
		$res .= "<div class='site'><span class='spip_x-small'>"._T('info_site_web')."</span> <a href='$url_site'>$nom_site</a></div>\n";
101
		}
102
103
	if ($ad_email) $res .= signatures_edit_mail($id_article, $ad_email, $row);
104
105
	$res .= "<div class='texte'>" . message_de_signature($row) . "</div>";
106
		
107
	if (!$id) {
108
		if ($r = sql_fetsel("titre, id_rubrique", "spip_articles", "id_article=$id_article")) {
109
			$id_rubrique = $r['id_rubrique'];
110
			$titre_a = $r['titre'];
111
			$titre_r = supprimer_numero(sql_getfetsel("titre", "spip_rubriques", "id_rubrique=$id_rubrique"));
112
		        $href = generer_url_ecrire('naviguer', "id_rubrique=" . $id_rubrique);
113
			$h2 = generer_url_ecrire_article($id_article);
114
			$res .= "<div class='nettoyeur'></div><div class='reponse_a'><a title='$id_article' href='"
115
			  . $h2
116
			  . "'>"
117
			  . typo($titre_a)
118
			  . "</a><a class='reponse_a' style='float: $spip_lang_right; padding-$spip_lang_left: 4px;' href='$href' title='$id_rubrique'>"
119
			. typo($titre_r)
120
			. " </a></div>";
121
		}
122
	}
123
124
	$res = "<table class='signature' id='signature$id_signature' width='100%' cellpadding='3' cellspacing='0'>\n<tr><td class='verdana2 cartouche'>"
125
 		.  ($nom_site ? "$nom_site / " : "")
126
		.  $nom_email
127
		.  "</td></tr>"
128
		.  "\n<tr><td class='serif contenu'>"
129
		. $res
130
		. "</td></tr></table>\n";
131
		
132
	if ($statut=="poubelle") {
133
		$res = "<table class='signature' width='100%' cellpadding='2' cellspacing='0' border='0'><tr><td class='poubelle'>"
134
			. $res
135
			. "</td></tr></table>";
136
	}
137
138
	return $res;
139
}
140
141
function signatures_edit_mail($id_article, $ad_email, $row) {
142
143
	$email = attribut_html($ad_email);
144
	if (email_valide($ad_email)) {
145
		if ($row['statut'] != 'publie'
146
		AND autoriser('modererpetition', 'article', $id_article)) {
147
			include_spip('formulaires/signature');
148
			$url = generer_url_entite_absolue($id_article, 'article','','',true);
149
			list($titre, $url) = signature_langue($id_article, $url);
150
151
			list($sujet, $corps) = signature_demande_confirmation($id_article, $url, $row['nom_email'], $row['nom_site'], $row['url_site'], $row['message'], $titre, $row['statut']);
152
153
			include_spip('inc/filtres');
154
			$sujet = rawurlencode(filtrer_entites($sujet));
155
			$corps = rawurlencode(filtrer_entites($corps));
156
			$corps = "?subject=$sujet&amp;body=$corps";
157
		} else $corps = '';
158
		$email = "<a href=\"mailto:$ad_email$corps\">$email</a>";
159
	}
160
	return "<div class='ad_email'><span class='spip_x-small'>"
161
			._T('info_adresse_email')
162
			."</span> "
163
			. $email
164
			. "</div>\n";
165
166
}
167
?>
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...
168