Completed
Push — master ( e11cc9...0b2559 )
by cam
04:14
created

chercher_logo.php ➔ inc_chercher_logo_dist()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 5
nop 4
dl 0
loc 30
rs 8.8177
c 0
b 0
f 0
1
<?php
2
3
/***************************************************************************\
4
 *  SPIP, Systeme de publication pour l'internet                           *
5
 *                                                                         *
6
 *  Copyright (c) 2001-2019                                                *
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
/**
14
 * Recherche de logo
15
 *
16
 * @package SPIP\Core\Logos
17
 **/
18
if (!defined('_ECRIRE_INC_VERSION')) {
19
	return;
20
}
21
22
/**
23
 * Cherche le logo d'un élément d'objet
24
 *
25
 * @global formats_logos Extensions possibles des logos
26
 * @uses type_du_logo()
27
 *
28
 * @param int $id
29
 *     Identifiant de l'objet
30
 * @param string $_id_objet
31
 *     Nom de la clé primaire de l'objet
32
 * @param string $mode
33
 *     Mode de survol du logo désiré (on ou off)
34
 * @return array
35
 *     - Liste (chemin complet du fichier, répertoire de logos, nom du logo, extension du logo, date de modification[, doc])
36
 *     - array vide aucun logo trouvé.
37
 **/
38
function inc_chercher_logo_dist($id, $_id_objet, $mode = 'on', $compat_old_logos = true) {
39
40
	$mode = preg_replace(",\W,", '', $mode);
41
	if ($mode) {
42
		// chercher dans la base
43
		$mode_document = 'logo' . $mode;
44
		$objet = objet_type($_id_objet);
45
		$doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', "D.mode=".sql_quote($mode_document)." AND L.objet=".sql_quote($objet)." AND id_objet=".intval($id));
46
		if ($doc) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $doc of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
47
			$d = get_spip_doc($doc['fichier']);
48
			return array($d, _DIR_IMG, basename($d), $d['extension'], @filemtime($d), $doc);
49
		}
50
51
		# deprecated TODO remove
52
		if ($compat_old_logos) {
53
			# attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval()
54
			$type = type_du_logo($_id_objet);
0 ignored issues
show
Deprecated Code introduced by
The function type_du_logo() has been deprecated with message: MAIS NE PAS SUPPRIMER CAR SERT POUR L'UPGRADE des logos et leur mise en base

This function has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed from the class and what other function to use instead.

Loading history...
55
			$nom = $type . $mode . intval($id);
56
57
			foreach ($GLOBALS['formats_logos'] as $format) {
58
				if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) {
59
					return array($d, _DIR_LOGOS, $nom, $format, @filemtime($d));
60
				}
61
			}
62
		}
63
	}
64
65
	# coherence de type pour servir comme filtre (formulaire_login)
66
	return array();
67
}
68
69
/**
70
 * Retourne le type de logo tel que `art` depuis le nom de clé primaire
71
 * de l'objet
72
 *
73
 * C'est par défaut le type d'objet, mais il existe des exceptions historiques
74
 * déclarées par la globale `$table_logos`
75
 *
76
 * @global table_logos Exceptions des types de logo
77
 *
78
 * @param string $_id_objet
79
 *     Nom de la clé primaire de l'objet
80
 * @return string
81
 *     Type du logo
82
 * @deprecated MAIS NE PAS SUPPRIMER CAR SERT POUR L'UPGRADE des logos et leur mise en base
83
 **/
84
function type_du_logo($_id_objet) {
85
	return isset($GLOBALS['table_logos'][$_id_objet])
86
		? $GLOBALS['table_logos'][$_id_objet]
87
		: objet_type(preg_replace(',^id_,', '', $_id_objet));
88
}
89
90
// Exceptions standards (historique)
91
$GLOBALS['table_logos'] = array(
92
	'id_article' => 'art',
93
	'id_auteur' => 'aut',
94
	'id_rubrique' => 'rub',
95
	'id_groupe' => 'groupe',
96
);
97