[SPIP] v3.2.1-->v3.2.3
[lhc/web/www.git] / www / plugins-dist / statistiques / prive / squelettes / contenu / stats_lang_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/@statistiques_lang_ok
20 function affiche_stats_lang($critere) {
21 global $spip_lang_right;
22
23 $taille = 450;
24 //
25 // Statistiques par langue
26 //
27
28 $out = "";
29 $r = sql_fetsel("SUM($critere) AS total_visites", "spip_articles");
30
31 $visites = 1;
32 // attention a '0.0'
33 if ($r and $r['total_visites'] > 0) {
34 $total_visites = $r['total_visites'];
35 } else {
36 $total_visites = 1;
37 }
38
39 $result = sql_select("lang, SUM(" . $critere . ") AS cnt", "spip_articles", "statut='publie' ", "lang");
40
41 $out .= "\n<table cellpadding='2' cellspacing='0' border='0' width='100%' style='border: 1px solid #aaaaaa;'>";
42 $ifond = 1;
43
44 $visites_abs = 0;
45 while ($row = sql_fetch($result)) {
46
47 $lang = $row['lang'];
48 if ($row['cnt']) {
49 $visites = round($row['cnt'] / $total_visites * $taille);
50 $pourcent = round($row['cnt'] / $total_visites * 100);
51 }
52
53 if ($visites > 0) {
54
55 if ($ifond == 0) {
56 $ifond = 1;
57 $couleur = "white";
58 } else {
59 $ifond = 0;
60 $couleur = "eeeeee";
61 }
62
63 $out .= "\n<tr style='background-color: $couleur'>";
64 $dir = lang_dir($lang, '', ' dir="rtl"');
65 $out .= "<td style='width: 100%; border-bottom: 1px solid #cccccc;'><p $dir><span style='float: $spip_lang_right;'>$pourcent%</span>" . traduire_nom_langue($lang) . "</p></td>";
66
67 $out .= "<td style='border-bottom: 1px solid #cccccc;'>";
68 $out .= "\n<table cellpadding='0' cellspacing='0' border='0' width='" . ($taille + 5) . "'>";
69 $out .= "\n<tr><td style='align:$spip_lang_right; background-color: #eeeeee; border: 1px solid #999999; white-space: nowrap;'>";
70 if ($visites_abs > 0) {
71 $out .= "<img src='" . chemin_image('rien.gif') . "' width='$visites_abs' height='10' alt=' ' />";
72 }
73 if ($visites > 0) {
74 $out .= "<img src='" . chemin_image('rien.gif') . "' class='couleur_langue' style='border: 0px;' width='$visites' height='8' alt=' ' />";
75 }
76 $out .= "</td></tr></table>\n";
77
78 $out .= "</td>";
79 $out .= "</tr>";
80 $visites_abs += $visites;
81 }
82 }
83 $out .= "</table>\n";
84
85 return $out;
86 }