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

logo_.php ➔ balise_LOGO__dist()   F

Complexity

Conditions 22
Paths 3072

Size

Total Lines 77
Code Lines 55

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 22
eloc 55
nc 3072
nop 1
dl 0
loc 77
rs 2.3278
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
//
16
// Fonction des balises #LOGO_XXXX
17
// (les balises portant ce type de nom sont traitees en bloc ici)
18
//
19
20
// http://doc.spip.org/@balise_LOGO__dist
21
function balise_LOGO__dist ($p) {
22
23
	preg_match(",^LOGO_([A-Z_]+?)(|_NORMAL|_SURVOL|_RUBRIQUE)$,i", $p->nom_champ, $regs);
24
	$type = strtolower($regs[1]);
25
	$suite_logo = $regs[2];
26
27
	// cas de #LOGO_SITE_SPIP
28
	if ($type == 'site_spip') {
29
		$type = 'site';
30
		$_id_objet = "\"'0'\"";
31
		$id_objet = 'id_syndic'; # parait faux mais donne bien "siteNN"
32
	} else {
33
		$id_objet = "id_".$type;
34
		if ($id_objet == 'id_site') $id_objet = "id_syndic"; # correction
35
		$_id_objet = champ_sql($id_objet, $p);
36
	}
37
38
	$fichier = ($p->etoile === '**') ? -1 : 0;
39
	$coord = array();
40
	$align = $lien = '';
41
	$mode_logo = '';
42
43
	if ($p->param AND !$p->param[0][0]) {
44
		$params = $p->param[0];
45
		array_shift($params);
46
		foreach($params as $a) {
47
			if ($a[0]->type === 'texte') {
48
				$n = $a[0]->texte;
49
				if (is_numeric($n))
50
					$coord[]= $n;
51
				elseif (in_array($n,array('top','left','right','center','bottom')))
52
					$align = $n;
53
				elseif (in_array($n,array('auto','icone','apercu','vignette')))
54
					$mode_logo = $n;
55
			}
56
			else $lien =  calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
57
58
		}
59
	}
60
61
	$coord_x = !$coord  ? 0 : intval(array_shift($coord));
62
	$coord_y = !$coord  ? 0 : intval(array_shift($coord));
63
	
64
	if ($p->etoile === '*') {
65
		include_spip('balise/url_');
66
		$lien = generer_generer_url_arg($type, $p, $_id_objet);
67
	}
68
69
	$connect = $p->id_boucle ?$p->boucles[$p->id_boucle]->sql_serveur :'';
70
	if ($type == 'document') {
71
		$qconnect = _q($connect);
72
		$doc = "quete_document($_id_objet, $qconnect)";
73
		if ($fichier)
74
			$code = "quete_logo_file($doc, $qconnect)";
75
		else $code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
76
		// (x=non-faux ? y : '') pour affecter x en retournant y
77
		if ($p->descr['documents'])
78
		  $code = '(($doublons["documents"] .= ",". '
79
		    . $_id_objet
80
		    . ") ? $code : '')";
81
	}
82
	elseif ($connect) {
83
		$code = "''";
84
		spip_log("Les logos distants ne sont pas prevus");
85
	} else {
86
		$code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
87
	}
88
89
	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
90
	if ($coord_x OR $coord_y) {
91
		$code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))";
92
	}
93
94
	$p->code = $code;
95
	$p->interdire_scripts = false;
96
	return $p;
97
}
98
99
function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite)
100
{
101
	$code = "quete_logo('$id_objet', '" .
102
		(($suite == '_SURVOL') ? 'off' : 
103
		(($suite == '_NORMAL') ? 'on' : 'ON')) .
104
		"', $_id_objet," .
105
		(($suite == '_RUBRIQUE') ? 
106
		champ_sql("id_rubrique", $p) :
107
		(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
108
		", " . intval($fichier) . ")";
109
110
	if ($fichier) return $code;
111
112
	$code = "\n((!is_array(\$l = $code)) ? '':\n (" .
113
		     '"<img class=\"spip_logos\" alt=\"\"' .
114
		    ($align ? " align=\\\"$align\\\"" : '')
115
		    . ' src=\"$l[0]\"" . $l[2] .  ($l[1] ? " onmouseover=\"this.src=\'$l[1]\'\" onmouseout=\"this.src=\'$l[0]\'\"" : "") . \' />\'))';
116
117
	if (!$lien) return $code;
118
119
	return ('(strlen($logo='.$code.')?\'<a href="\' .' . $lien . ' . \'">\' . $logo . \'</a>\':\'\')');
120
121
}
122
123
124
125
?>
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...
126