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

logo_.php ➔ balise_LOGO__dist()   F

Complexity

Conditions 23
Paths 4096

Size

Total Lines 76
Code Lines 53

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 23
eloc 53
c 0
b 0
f 0
nc 4096
nop 1
dl 0
loc 76
rs 2.3819

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
	}
32
33
	$id_objet = id_table_objet($type);
34
	if (!isset($_id_objet) OR !$_id_objet)
35
		$_id_objet = champ_sql($id_objet, $p);
36
37
	$fichier = ($p->etoile === '**') ? -1 : 0;
38
	$coord = array();
39
	$align = $lien = '';
40
	$mode_logo = '';
41
42
	if ($p->param AND !$p->param[0][0]) {
43
		$params = $p->param[0];
44
		array_shift($params);
45
		foreach($params as $a) {
46
			if ($a[0]->type === 'texte') {
47
				$n = $a[0]->texte;
48
				if (is_numeric($n))
49
					$coord[]= $n;
50
				elseif (in_array($n,array('top','left','right','center','bottom')))
51
					$align = $n;
52
				elseif (in_array($n,array('auto','icone','apercu','vignette')))
53
					$mode_logo = $n;
54
			}
55
			else $lien =  calculer_liste($a, $p->descr, $p->boucles, $p->id_boucle);
56
57
		}
58
	}
59
60
	$coord_x = !$coord  ? 0 : intval(array_shift($coord));
61
	$coord_y = !$coord  ? 0 : intval(array_shift($coord));
62
	
63
	if ($p->etoile === '*') {
64
		include_spip('balise/url_');
65
		$lien = generer_generer_url_arg($type, $p, $_id_objet);
66
	}
67
68
	$connect = $p->id_boucle ?$p->boucles[$p->id_boucle]->sql_serveur :'';
69
	if ($type == 'document') {
70
		$qconnect = _q($connect);
71
		$doc = "quete_document($_id_objet, $qconnect)";
72
		if ($fichier)
73
			$code = "quete_logo_file($doc, $qconnect)";
74
		else $code = "quete_logo_document($doc, " . ($lien ? $lien : "''") . ", '$align', '$mode_logo', $coord_x, $coord_y, $qconnect)";
75
		// (x=non-faux ? y : '') pour affecter x en retournant y
76
		if ($p->descr['documents'])
77
		  $code = '(($doublons["documents"] .= ",". '
78
		    . $_id_objet
79
		    . ") ? $code : '')";
80
	}
81
	elseif ($connect) {
82
		$code = "''";
83
		spip_log("Les logos distants ne sont pas prevus");
84
	} else {
85
		$code = logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite_logo);
86
	}
87
88
	// demande de reduction sur logo avec ecriture spip 2.1 : #LOGO_xxx{200, 0}
89
	if ($coord_x OR $coord_y) {
90
		$code = "filtrer('image_graver',filtrer('image_reduire',".$code.", '$coord_x', '$coord_y'))"; 
91
	} 
92
93
	$p->code = $code;
94
	$p->interdire_scripts = false;
95
	return $p;
96
}
97
98
function logo_survol($id_objet, $_id_objet, $type, $align, $fichier, $lien, $p, $suite)
99
{
100
	$code = "quete_logo('$id_objet', '" .
101
		(($suite == '_SURVOL') ? 'off' : 
102
		(($suite == '_NORMAL') ? 'on' : 'ON')) .
103
		"', $_id_objet," .
104
		(($suite == '_RUBRIQUE') ? 
105
		champ_sql("id_rubrique", $p) :
106
		(($type == 'rubrique') ? "quete_parent($_id_objet)" : "''")) .
107
		", " . intval($fichier) . ")";
108
109
	if ($fichier) return $code;
110
111
	$code = "\n((!is_array(\$l = $code)) ? '':\n (" .
112
		     '"<img class=\"spip_logos\" alt=\"\"' .
113
		    ($align ? " align=\\\"$align\\\"" : '')
114
		    . ' src=\"$l[0]\"" . $l[2] .  ($l[1] ? " onmouseover=\"this.src=\'$l[1]\'\" onmouseout=\"this.src=\'$l[0]\'\"" : "") . \' />\'))';
115
116
	if (!$lien) return $code;
117
118
	return ('(strlen($logo='.$code.')?\'<a href="\' .' . $lien . ' . \'">\' . $logo . \'</a>\':\'\')');
119
120
}
121
122
123
124
?>
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...
125