[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / statistiques / prive / squelettes / contenu / stats_repartition_fonctions.php
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 if (!defined("_ECRIRE_INC_VERSION")) {
14 return;
15 }
16
17 include_spip('inc/presentation');
18
19 // https://code.spip.net/@enfants
20 function enfants($id_parent, $critere, &$nombre_branche, &$nombre_rub) {
21 $result = sql_select("id_rubrique", "spip_rubriques", "id_parent=" . intval($id_parent));
22
23 $nombre = 0;
24
25 while ($row = sql_fetch($result)) {
26 $id_rubrique = $row['id_rubrique'];
27
28 $visites = intval(sql_getfetsel("SUM(" . $critere . ")", "spip_articles", "id_rubrique=" . intval($id_rubrique)));
29 $nombre_rub[$id_rubrique] = $visites;
30 $nombre_branche[$id_rubrique] = $visites;
31 $nombre += $visites + enfants($id_rubrique, $critere, $nombre_branche, $nombre_rub);
32 }
33 if (!isset($nombre_branche[$id_parent])) {
34 $nombre_branche[$id_parent] = 0;
35 }
36 $nombre_branche[$id_parent] += $nombre;
37
38 return $nombre;
39 }
40
41
42 // https://code.spip.net/@enfants_aff
43 function enfants_aff($id_parent, $decalage, $taille, $critere, $gauche = 0) {
44 global $spip_lang_right, $spip_lang_left;
45 static $total_site = null;
46 static $niveau = 0;
47 static $nombre_branche;
48 static $nombre_rub;
49 if (is_null($total_site)) {
50 $nombre_branche = array();
51 $nombre_rub = array();
52 $total_site = enfants(0, $critere, $nombre_branche, $nombre_rub);
53 if ($total_site < 1) {
54 $total_site = 1;
55 }
56 }
57 $visites_abs = 0;
58 $out = "";
59 $width = intval(floor(($nombre_branche[$id_parent] / $total_site) * $taille));
60 $width = "width:{$width}px;float:$spip_lang_left;";
61
62
63 $result = sql_select("id_rubrique, titre, descriptif", "spip_rubriques", "id_parent=$id_parent", '', '0+titre,titre');
64
65 while ($row = sql_fetch($result)) {
66 $id_rubrique = $row['id_rubrique'];
67 $titre = typo($row['titre']);
68 $descriptif = attribut_html(couper(typo($row['descriptif']), 80));
69
70 if ($nombre_branche[$id_rubrique] > 0 or $nombre_rub[$id_rubrique] > 0) {
71 $largeur_branche = floor(($nombre_branche[$id_rubrique] - $nombre_rub[$id_rubrique]) * $taille / $total_site);
72 $largeur_rub = floor($nombre_rub[$id_rubrique] * $taille / $total_site);
73
74 if ($largeur_branche + $largeur_rub > 0) {
75
76 if ($niveau == 0) {
77 $couleur = "#cccccc";
78 } else {
79 if ($niveau == 1) {
80 $couleur = "#eeeeee";
81 } else {
82 $couleur = "white";
83 }
84 }
85 $out .= "<table cellpadding='2' cellspacing='0' border='0' width='100%'>";
86 $out .= "\n<tr style='background-color: $couleur'>";
87 $out .= "\n<td style='border-bottom: 1px solid #aaaaaa; padding-$spip_lang_left: " . ($niveau * 20 + 5) . "px;'>";
88
89
90 if ($largeur_branche > 2) {
91 $out .= bouton_block_depliable("<a href='" . generer_url_entite($id_rubrique,
92 'rubrique') . "' style='color: black;' title=\"$descriptif\">$titre</a>", "incertain",
93 "stats$id_rubrique");
94 } else {
95 $out .= "<div class='rubsimple' style='padding-left: 18px;'>"
96 . "<a href='" . generer_url_entite($id_rubrique,
97 'rubrique') . "' style='color: black;' title=\"$descriptif\">$titre</a>"
98 . "</div>";
99 }
100 $out .= "</td>";
101
102
103 // pourcentage de visites dans la branche par rapport au total du site
104 $pourcent = round($nombre_branche[$id_rubrique] / $total_site * 1000) / 10;
105 $out .= "\n<td class='verdana1' style='text-align: $spip_lang_right; width: 40px; border-bottom: 1px solid #aaaaaa;'>$pourcent%</td>";
106
107
108 $out .= "\n<td align='right' style='border-bottom: 1px solid #aaaaaa; width:" . ($taille + 5) . "px'>";
109
110
111 $out .= "\n<table cellpadding='0' cellspacing='0' border='0' width='" . ($decalage + 1 + $gauche) . "'>";
112 $out .= "\n<tr>";
113 if ($gauche > 0) {
114 $out .= "<td style='width: " . $gauche . "px'></td>";
115 }
116 $out .= "\n<td style='border: 0px; white-space: nowrap;'>";
117 $out .= "<div style='border: 1px solid #999999; background-color: #dddddd; height: 1em; padding: 0px; margin: 0px;$width'>";
118 if ($visites_abs > 0) {
119 $out .= "<img src='" . chemin_image('rien.gif') . "' style='vertical-align: top; height: 1em; border: 0px; width: " . $visites_abs . "px;' alt= ' '/>";
120 }
121 if ($largeur_branche > 0) {
122 $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_cumul' style='vertical-align: top; height: 1em; border: 0px; width: " . $largeur_branche . "px;' alt=' ' />";
123 }
124 if ($largeur_rub > 0) {
125 $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_nombre' style='vertical-align: top; width: " . $largeur_rub . "px; height: 1em; border: 0px' alt=' ' />";
126 }
127 $out .= "</div>";
128 $out .= "</td></tr></table>\n";
129 $out .= "</td></tr></table>";
130 }
131 }
132
133 if (isset($largeur_branche) && ($largeur_branche > 0)) {
134 $niveau++;
135 $out .= debut_block_depliable(false, "stats$id_rubrique");
136 $out .= enfants_aff($id_rubrique, $largeur_branche, $taille, $critere, $visites_abs + $gauche);
137 $out .= fin_block();
138 $niveau--;
139 }
140 $visites_abs = $visites_abs + round($nombre_branche[$id_rubrique] / $total_site * $taille);
141 }
142
143 return $out;
144 }