[SPIP] +2.1.12
[velocampus/web/www.git] / www / ecrire / inc / statistiques.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2011 *
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 // http://doc.spip.org/@aff_statistique_visites_popularite
16 function aff_statistique_visites_popularite($serveur, $id_article, &$classement, &$liste){
17 // Par popularite
18 $result = sql_select("id_article, titre, popularite, visites", "spip_articles", "statut='publie' AND popularite > 0", "", "popularite DESC",'','',$serveur);
19 $out = '';
20 while ($row = sql_fetch($result,$serveur)) {
21 $l_article = $row['id_article'];
22 $liste++;
23 $classement[$l_article] = $liste;
24
25 if ($liste <= 30) {
26 $articles_vus[] = $l_article;
27 $out .= statistiques_populaires($row, $id_article, $liste);
28 }
29 }
30 $recents = array();
31 $q = sql_select("id_article", "spip_articles", "statut='publie' AND popularite > 0", "", "date DESC", "10",'',$serveur);
32 while ($r = sql_fetch($q,$serveur))
33 if (!in_array($r['id_article'], $articles_vus))
34 $recents[]= $r['id_article'];
35
36 if ($recents) {
37 $result = sql_select("id_article, titre, popularite, visites", "spip_articles", "statut='publie' AND " . sql_in('id_article', $recents), "", "popularite DESC",'','',$serveur);
38
39 $out .= "</ul><div style='text-align: center'>[...]</div>" .
40 "<ul class='classement'>";
41 while ($row = sql_fetch($result,$serveur)) {
42 $l_article = $row["id_article"];
43 $out .= statistiques_populaires($row, $id_article, $classement[$l_article]);
44 }
45 }
46
47 return !$out ? '' : (
48 "<div class='cadre cadre-e'>\n"
49 ."<div class='cadre_padding verdana1 spip_x-small'>"
50 .typo(_T('info_visites_plus_populaires'))
51 ."<ul class='classement'>"
52 .$out
53
54 ."</ul>"
55
56 ."<div class='arial11'><b>"._T('info_comment_lire_tableau')."</b><br />"._T('texte_comment_lire_tableau')."</div>"
57
58 ."</div>"
59 ."</div>");
60 }
61
62 function statistiques_populaires($row, $id_article, $classement)
63 {
64 $titre = typo(supprime_img($row['titre'], ''));
65 $l_article = $row['id_article'];
66
67 if ($l_article == $id_article){
68 return "<li class='on'><em>$classement.</em>$titre</li>";
69 } else {
70 $visites = $row['visites'];
71 $popularite = round($row['popularite']);
72 return "<li><em>$classement.</em><a href='" . generer_url_ecrire("statistiques_visites","id_article=$l_article") . "' title='"._T('info_popularite_3', array('popularite' => $popularite, 'visites' => $visites))."'>$titre</a></li>";
73 }
74 }
75
76 // http://doc.spip.org/@aff_statistique_visites_par_visites
77 function aff_statistique_visites_par_visites($serveur='', $id_article=0, $classement= array()) {
78 $res = "";
79 // Par visites depuis le debut
80 $result = sql_select("id_article, titre, popularite, visites", "spip_articles", "statut='publie' AND popularite > 0", "", "visites DESC", "30",'',$serveur);
81
82 while ($row = sql_fetch($result,$serveur)) {
83 $titre = typo(supprime_img($row['titre'],''));
84 $l_article = $row['id_article'];
85
86 if ($l_article == $id_article){
87 $res.= "<li class='on'><em>"
88 . $classement[$l_article]
89 . ".</em>$titre</li>";
90 } else {
91 $t = _T('info_popularite_4',
92 array('popularite' => round($row['popularite']), 'visites' => $row['visites']));
93 $h = generer_url_ecrire("statistiques_visites","id_article=$l_article");
94 $out = "<a href='$h'\ntitle='$t'>$titre</a>";
95 $res.= "<li><em>"
96 . $classement[$l_article]
97 . ".</em>$out</li>";
98 }
99 }
100
101 if (!$res) return '';
102
103 return "<div class='cadre cadre-e' style='padding: 5px;'>"
104 . "<div class='cadre_padding verdana1 spip_x-small'>"
105 . typo(_T('info_affichier_visites_articles_plus_visites'))
106 . "<ul class='classement'>"
107 . $res
108 . '</ul></div></div>';
109 }
110
111 // http://doc.spip.org/@http_img_rien
112 function http_img_rien($width, $height, $class='', $title='') {
113 return http_img_pack('rien.gif', $title,
114 "width='$width' height='$height'"
115 . (!$class ? '' : (" class='$class'"))
116 . (!$title ? '' : (" title=\"$title\"")));
117 }
118
119 // Donne la hauteur du graphe en fonction de la valeur maximale
120 // Doit etre un entier "rond", pas trop eloigne du max, et dont
121 // les graduations (divisions par huit) soient jolies :
122 // on prend donc le plus proche au-dessus de x de la forme 12,16,20,40,60,80,100
123 // http://doc.spip.org/@maxgraph
124 function maxgraph($max) {
125
126 switch ($n =strlen($max)) {
127 case 0:
128 return 1;
129 case 1:
130 return 16;
131 case 2:
132 return (floor($max / 8) + 1) * 8;
133 case 3:
134 return (floor($max / 80) + 1) * 80;
135 default:
136 $dix = 2 * pow(10, $n-2);
137 return (floor($max / $dix) + 1) * $dix;
138 }
139 }
140
141 // http://doc.spip.org/@cadre_stat
142 function cadre_stat($stats, $table, $id_article)
143 {
144 if (!$stats) return '';
145 return debut_cadre_relief("statistiques-24.gif", true)
146 . join('', $stats)
147 . fin_cadre_relief(true)
148 . statistiques_mode($table, $id_article);
149 }
150
151 // http://doc.spip.org/@statistiques_collecte_date
152 function statistiques_collecte_date($count, $date, $table, $where, $serveur)
153 {
154 $result = sql_select("$count AS n, $date AS d", $table, $where, 'd', 'd', '','', $serveur);
155 $log = array();
156
157 while ($r = sql_fetch($result,$serveur)) $log[$r['d']] = $r['n'];
158 return $log;
159 }
160
161 // http://doc.spip.org/@statistiques_tous
162 function statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $duree, $interval, $total, $popularite, $liste='', $classement=array(), $script='')
163 {
164 $r = array_keys($log);
165 $date_fin = max($r);
166 $today = strtotime(date('Y-m-d 01:00:01'));
167 if ($today-$date_fin>$interval){
168 $log[$today] = 0;
169 $r = array_keys($log);
170 $date_fin = max($r);
171 }
172 $date_debut = min($r);
173 $date_premier = sql_getfetsel("UNIX_TIMESTAMP($order) AS d", $table, $where, '', $order, 1,'',$serveur);
174 $last = $log[$date_fin];
175 $max = max($log);
176 $maxgraph = maxgraph($max);
177 $rapport = 200 / $maxgraph;
178 $agreg = ceil(count($log) / 420);
179 $x = ceil(($date_fin-$date_debut)/$interval);
180 $largeur = ($agreg > 1) ? 1 : (!$x ? 420 : floor(420 / $x));
181
182 if ($largeur > 50) $largeur = 50; elseif ($largeur < 1) $largeur = 1;
183
184 list($moyenne,$prec, $res) = stat_log1($log, $agreg, $date_fin, $largeur, $rapport, $interval, $script);
185
186 $stats = "\n<table cellpadding='0' cellspacing='0' border='0'><tr>" .
187 "\n<td ".http_style_background("fond-stats.gif").">"
188 . "\n<table cellpadding='0' cellspacing='0' border='0' class='bottom'><tr>"
189 . "\n<td style='background-color: black'>" . http_img_rien(1, 200) . "</td>"
190 . $res
191 . (!is_array($liste) ? '' : // prevision que pour les visites
192 statistiques_prevision($id_article, $largeur, $moyenne, $rapport, $popularite, $last))
193 . "\n<td style='background-color: black'>"
194 . http_img_rien(1, 1) ."</td>"
195 . "</tr></table>"
196 . "</td>\n<td "
197 . http_style_background("fond-stats.gif")." valign='bottom'>"
198 . http_img_rien(3, 1, 'trait_bas') ."</td>"
199 . "\n<td>" . http_img_rien(5, 1) ."</td>"
200 . "\n<td valign='top'>"
201 . statistiques_echelle($maxgraph)
202 . "</td>"
203 . "</tr></table>";
204
205 $total = "<b>" . _T('info_total') ." " . $total."</b>";
206
207 if (is_array($liste)) {
208 $liste = statistiques_classement($id_article, $classement, $liste);
209 $legend = statistiques_nom_des_mois($date_debut, $date_fin, $largeur, $interval,$agreg)
210 . "<span class='arial1 spip_x-small'>"
211 . _T('texte_statistiques_visites')
212 . "</span><br />";
213 $resume = statistiques_resume($max, $moyenne, $last, $prec, $popularite);
214 } else {
215 $legend = "<table width='100%'><tr><td width='50%'>" .
216 affdate_heure(date("Y-m-d H:i:s", $date_debut)) .
217 "</td><td width='50%' align='right'>" .
218 affdate_heure(date("Y-m-d H:i:s", $date_fin)) .
219 '</td></tr></table>';
220 $resume = '';
221 }
222
223 $legend .=
224 "<table cellpadding='0' cellspacing='0' border='0' width='100%'><tr style='width:100%;'>"
225 . $resume
226 . "\n<td valign='top' style='width: 33%; ' class='verdana1'>"
227 . $total
228 . $liste
229 . "</td></tr></table>";
230
231 $x = (!$duree) ? 1 : (420/ $duree);
232 $zoom = statistiques_zoom($id_article, $x, $date_premier, $date_debut, $date_fin);
233 return array($zoom, $stats, $mark, $legend);
234 }
235
236 // http://doc.spip.org/@statistiques_resume
237 function statistiques_resume($max, $moyenne, $last, $prec, $popularite)
238 {
239 return "\n<td valign='top' style='width: 33%; ' class='verdana1'>"
240 . _T('info_maximum')." "
241 . $max . "<br />"
242 . _T('info_moyenne')." "
243 . round($moyenne). "</td>"
244 . "\n<td valign='top' style='width: 33%; ' class='verdana1'>"
245 . '<a href="'
246 . generer_url_ecrire("statistiques_referers")
247 . '" title="'._T('titre_liens_entrants').'">'
248 . _T('info_aujourdhui')
249 . '</a> '
250 . $last
251 . (($prec <= 0) ? '' :
252 ('<br /><a href="'
253 . generer_url_ecrire("statistiques_referers","jour=veille")
254 .'" title="'._T('titre_liens_entrants').'">'
255 ._T('info_hier').'</a> '.$prec))
256 . (!$popularite ? '' :
257 ("<br />"._T('info_popularite_5').' '.$popularite))
258 . "</td>";
259 }
260
261 // http://doc.spip.org/@statistiques_classement
262 function statistiques_classement($id_article, $classement, $liste)
263 {
264 if ($id_article) {
265 if ($classement[$id_article] > 0) {
266 if ($classement[$id_article] == 1)
267 $ch = _T('info_classement_1', array('liste' => $liste));
268 else
269 $ch = _T('info_classement_2', array('liste' => $liste));
270 return "<br />".$classement[$id_article].$ch;
271 }
272 } else
273 return "<span class='spip_x-small'><br />"
274 ._T('info_popularite_2')." "
275 . ceil($GLOBALS['meta']['popularite_total'])
276 . "</span>";
277 }
278
279 // http://doc.spip.org/@statistiques_zoom
280 function statistiques_zoom($id_article, $largeur_abs, $date_premier, $date_debut, $date_fin)
281 {
282 if ($largeur_abs > 1) {
283 $inc = ceil($largeur_abs / 5);
284 $duree_plus = 420 / ($largeur_abs - $inc);
285 $duree_moins = 420 / ($largeur_abs + $inc);
286 }
287
288 if ($largeur_abs == 1) {
289 $duree_plus = 840;
290 $duree_moins = 210;
291 }
292
293 if ($largeur_abs < 1) {
294 $duree_plus = 420 * ((1/$largeur_abs) + 1);
295 $duree_moins = 420 * ((1/$largeur_abs) - 1);
296 }
297
298 $pour_article = $id_article ? "&id_article=$id_article" : '';
299
300 $zoom = '';
301
302 if ($date_premier < $date_debut)
303 $zoom= lien_ou_expose(generer_url_ecrire("statistiques_visites","duree=$duree_plus$pour_article"),
304 http_img_pack('loupe-moins.gif',
305 _T('info_zoom'). '-',
306 "style='border: 0px; vertical-align: middle;'"), false, '',
307 "&nbsp;");
308 if ( (($date_fin - $date_debut) / (24*3600)) > 30)
309 $zoom .= lien_ou_expose(generer_url_ecrire("statistiques_visites","duree=$duree_moins$pour_article"),
310 http_img_pack('loupe-plus.gif',
311 _T('info_zoom'). '+',
312 "style='border: 0px; vertical-align: middle;'"), false, '',
313 "&nbsp;");
314
315 return $zoom;
316 }
317
318 // Presentation graphique
319 // (rq: on n'affiche pas le jour courant, c'est a la charge de la prevision)
320 // http://doc.spip.org/@stat_log1
321 function stat_log1($log, $agreg, $date_today, $largeur, $rapport, $interval, $script) {
322 $res = '';
323 $rien = http_img_rien($largeur, 1, 'trait_bas', '');
324 $test_agreg = $decal = $date_prec = $val_prec = $moyenne = 0;
325 foreach ($log as $key => $value) {
326 if ($key == $date_today) break;
327 $test_agreg ++;
328 if ($test_agreg != $agreg) continue;
329 $test_agreg = 0;
330 if ($decal == 30) $decal = 0;
331 $decal ++;
332 $evol[$decal] = $value;
333 // Inserer des jours vides si pas d'entrees
334 if ($date_prec > 0) {
335 $ecart = (($key-$date_prec)/$agreg)-$interval;
336 for ($i=$interval; $i <= $ecart; $i+=$interval){
337 if ($decal == 30) $decal = 0;
338 $decal ++;
339 $evol[$decal] = $value;
340 $m = statistiques_moyenne($evol);
341 $m = statistiques_vides($date_prec+$i, $largeur, $rapport, $m, $script);
342 $res .= "\n<td style='width: ${largeur}px'>$m</td>";
343 }
344 }
345 $moyenne = round(statistiques_moyenne($evol),2);
346 $hauteur = round($value * $rapport) - 1;
347 $m = ($hauteur <= 0) ? '' : statistiques_jour($key, $value, $largeur, $moyenne, $hauteur, $rapport, (date("w",$key) == "0"), $script);
348 $res .= "\n<td style='width: ${largeur}px'>$m$rien</td>\n";
349 $date_prec = $key;
350 $val_prec = $value;
351 }
352 return array($moyenne, $val_prec, $res);
353 }
354
355 // http://doc.spip.org/@statistiques_href
356 function statistiques_href($jour, $moyenne, $script, $value='')
357 {
358 $ce_jour=date("Y-m-d H:i:s", $jour);
359 $title = nom_jour($ce_jour) . ' '
360 . ($script ? affdate_heure($ce_jour) :
361 (affdate_jourcourt($ce_jour) .' '.
362 (" | " ._T('info_visites')." $value | " ._T('info_moyenne')." "
363 . round($moyenne,2))));
364 return attribut_html(supprimer_tags($title));
365 }
366
367 // http://doc.spip.org/@statistiques_vides
368 function statistiques_vides($prec, $largeur, $rapport, $moyenne, $script)
369 {
370 $hauteur_moyenne = round($moyenne*$rapport)-1;
371 $title = statistiques_href($prec, $moyenne, $script);
372 $tagtitle = $script ? '' : $title;
373 if ($hauteur_moyenne > 1) {
374 $res = http_img_rien($largeur,1, 'trait_moyen', $tagtitle)
375 . http_img_rien($largeur, $hauteur_moyenne, '', $tagtitle);
376 } else $res = '';
377 $res .= http_img_rien($largeur,1,'trait_bas', $tagtitle);
378 if (!$script) return $res;
379 return "<a href='$script' title='$title'>$res</a>";
380 }
381
382
383 // http://doc.spip.org/@statistiques_prevision
384 function statistiques_prevision($id_article, $largeur, $moyenne, $rapport, $val_popularite, $visites_today)
385 {
386 $hauteur = round($visites_today * $rapport) - 1;
387 // $total_absolu = $total_absolu + $visites_today;
388 // prevision de visites jusqu'a minuit
389 // basee sur la moyenne (site) ou popularite (article)
390 if (! $id_article) $val_popularite = $moyenne;
391 $prevision = (1 - (date("H")*60 + date("i"))/(24*60)) * $val_popularite;
392 $hauteurprevision = ceil($prevision * $rapport);
393 // preparer le texte de survol (prevision)
394 $tagtitle= attribut_html(supprimer_tags(_T('info_aujourdhui')." $visites_today &rarr; ".(round($prevision,0)+$visites_today)));
395
396 $res .= "\n<td style='width: ${largeur}px'>";
397 if ($hauteur+$hauteurprevision>0)
398 // Afficher la barre tout en haut
399 $res .= http_img_rien($largeur, 1, "trait_haut");
400 if ($hauteurprevision>0)
401 // afficher la barre previsionnelle
402 $res .= http_img_rien($largeur, $hauteurprevision,'couleur_prevision', $tagtitle);
403 // afficher la barre deja realisee
404 if ($hauteur>0)
405 $res .= http_img_rien($largeur, $hauteur, 'couleur_realise', $tagtitle);
406 // et afficher la ligne de base
407 $res .= http_img_rien($largeur, 1, 'trait_bas')
408 . "</td>";
409
410 return $res;
411 }
412
413 // Dimanche en couleur foncee
414 // http://doc.spip.org/@statistiques_jour
415 function statistiques_jour($key, $value, $largeur, $moyenne, $hauteur, $rapport, $dimanche, $script)
416 {
417 $hauteur_moyenne = round($moyenne * $rapport) - 1;
418 $title= statistiques_href($key, $moyenne, $script, $value);
419 $tagtitle = $script ? '' : $title;
420 $couleur = $dimanche ? "couleur_dimanche" : "couleur_jour";
421 if ($hauteur_moyenne > $hauteur) {
422 $difference = ($hauteur_moyenne - $hauteur) -1;
423
424 $res = http_img_rien($largeur, 1,'trait_moyen',$tagtitle)
425 . http_img_rien($largeur, $difference, '', $tagtitle)
426 . http_img_rien($largeur, 1, "trait_haut", $tagtitle)
427 . http_img_rien($largeur, $hauteur, $couleur, $tagtitle);
428 } else if ($hauteur_moyenne < $hauteur) {
429 $difference = ($hauteur - $hauteur_moyenne) -1;
430 $res = http_img_rien($largeur,1,"trait_haut", $tagtitle)
431 . http_img_rien($largeur, $difference, $couleur, $tagtitle)
432 . http_img_rien($largeur,1,"trait_moyen", $tagtitle)
433 . http_img_rien($largeur, $hauteur_moyenne, $couleur, $tagtitle);
434 } else {
435 $res = http_img_rien($largeur, 1, "trait_haut", $tagtitle)
436 . http_img_rien($largeur, $hauteur, $couleur, $tagtitle);
437 }
438 if ($script)
439 $script .= "&amp;date=$key";
440 else {
441 $y = date("Y", $key);
442 $m = date("m", $key);
443 $d = date("d", $key);
444 $script = generer_url_ecrire('calendrier',
445 "type=semaine&annee=$y&mois=$m&jour=$d");
446 }
447 return "<a href='$script' title='$title'>$res</a>";
448 }
449
450 // http://doc.spip.org/@statistiques_nom_des_mois
451 function statistiques_nom_des_mois($date_debut, $date_today, $largeur, $pas, $agreg)
452 {
453 global $spip_lang_left;
454
455 $res = '';
456 $largeur /= ($pas*$agreg);
457 $gauche_prec = -50;
458 for ($jour = $date_debut; $jour <= $date_today; $jour += $pas) {
459 if (date("d", $jour) == "1") {
460 $newy = (date("m", $jour) == 1);
461 $gauche = floor(($jour - $date_debut) * $largeur);
462 if ($gauche - $gauche_prec >= 40 OR $newy) {
463 $afficher = $newy ?
464 ("<b>".annee(date("Y-m-d", $jour))."</b>")
465 : nom_mois(date("Y-m-d", $jour));
466
467 $res .= "<div class='arial0' style='border-$spip_lang_left: 1px solid black; padding-$spip_lang_left: 2px; padding-top: 3px; position: absolute; $spip_lang_left: ".$gauche."px; top: -1px;'>".$afficher."</div>";
468 $gauche_prec = $gauche;
469 if ($gauche > 400) break; //400px max
470 }
471 }
472 }
473 return "<div style='position: relative; height: 15px'>$res</div>";
474 }
475
476 // http://doc.spip.org/@statistiques_par_mois
477 function statistiques_par_mois($entrees, $script){
478
479 $maxgraph = maxgraph(max($entrees));
480 $rapport = 200/$maxgraph;
481 $largeur = floor(420 / (count($entrees)));
482 if ($largeur < 1) $largeur = 1;
483 if ($largeur > 50) $largeur = 50;
484 $decal = 0;
485 $tab_moyenne = array();
486
487 $all = '';
488
489 foreach($entrees as $key=>$value) {
490 $key = substr($key,0,4).'-'.substr($key,4,2);
491 $mois = affdate_mois_annee($key);
492 if ($decal == 30) $decal = 0;
493 $decal ++;
494 $tab_moyenne[$decal] = $value;
495 $moyenne = statistiques_moyenne($tab_moyenne);
496 $hauteur_moyenne = round($moyenne * $rapport) - 1;
497 $hauteur = round($value * $rapport) - 1;
498 $res = '';
499 $title= attribut_html(supprimer_tags("$mois | "
500 ._T('info_total')." ".$value));
501 $tagtitle = $script ? '' : $title;
502 if ($hauteur > 0){
503 if ($hauteur_moyenne > $hauteur) {
504 $difference = ($hauteur_moyenne - $hauteur) -1;
505 $res .= http_img_rien($largeur, 1, 'trait_moyen');
506 $res .= http_img_rien($largeur, $difference, '', $tagtitle);
507 $res .= http_img_rien($largeur,1,"trait_haut");
508 if (preg_match(",-01,",$key)){ // janvier en couleur foncee
509 $res .= http_img_rien($largeur,$hauteur,"couleur_janvier", $tagtitle);
510 } else {
511 $res .= http_img_rien($largeur,$hauteur,"couleur_mois", $tagtitle);
512 }
513 }
514 else if ($hauteur_moyenne < $hauteur) {
515 $difference = ($hauteur - $hauteur_moyenne) -1;
516 $res .= http_img_rien($largeur,1,"trait_haut", $tagtitle);
517 if (preg_match(",-01,",$key)){ // janvier en couleur foncee
518 $couleur = 'couleur_janvier';
519 } else {
520 $couleur = 'couleur_mois';
521 }
522 $res .= http_img_rien($largeur,$difference, $couleur, $tagtitle);
523 $res .= http_img_rien($largeur,1,'trait_moyen',$tagtitle);
524 $res .= http_img_rien($largeur,$hauteur_moyenne, $couleur, $tagtitle);
525 } else {
526 $res .= http_img_rien($largeur,1,"trait_haut", $tagtitle);
527 if (preg_match(",-01,",$key)){ // janvier en couleur foncee
528 $res .= http_img_rien($largeur, $hauteur, "couleur_janvier", $tagtitle);
529 } else {
530 $res .= http_img_rien($largeur,$hauteur, "couleur_mois", $tagtitle);
531 }
532 }
533 }
534 $res .= http_img_rien($largeur,1,'trait_bas', $tagtitle);
535
536 if (!$script) {
537 $y = annee($key);
538 $m = mois($key);
539 $href = generer_url_ecrire('calendrier', "type=mois&annee=$y&mois=$m&jour=1");
540 } else $href = "$script&amp;date=$key";
541
542 $all .= "\n<td style='width: ${largeur}px'><a href='"
543 . $href
544 . '\' title="'
545 . $title
546 . '">'
547 . $res
548 . "</a></td>\n";
549 }
550
551 return
552 "\n<table cellpadding='0' cellspacing='0' border='0'><tr>"
553 . "\n<td ".http_style_background("fond-stats.gif").">"
554 . "\n<table cellpadding='0' cellspacing='0' border='0' class='bottom'><tr>"
555 . "\n<td class='trait_bas'>" . http_img_rien(1, 200) ."</td>"
556 . $all
557 . "\n<td style='background-color: black'>" . http_img_rien(1, 1)
558 . "</td>"
559 . "</tr></table></td>"
560 . "\n<td ".http_style_background("fond-stats.gif")." valign='bottom'>"
561 . http_img_rien(3, 1, 'trait_bas') ."</td>"
562 . "\n<td>" . http_img_rien(5, 1) ."</td>"
563 . "\n<td valign='top'>"
564 . statistiques_echelle($maxgraph)
565 . "</td></tr></table>";
566 }
567
568 // http://doc.spip.org/@statistiques_echelle
569 function statistiques_echelle($maxgraph)
570 {
571 return recuperer_fond('prive/stats/echelle', array('echelle' => $maxgraph));
572 }
573
574 // http://doc.spip.org/@statistiques_moyenne
575 function statistiques_moyenne($tab)
576 {
577 if (!$tab) return 0;
578 $moyenne = 0;
579 foreach($tab as $v) $moyenne += $v;
580 return $moyenne / count($tab);
581 }
582
583
584 // http://doc.spip.org/@statistiques_signatures_dist
585 function statistiques_signatures_dist($duree, $interval, $type, $id_article, $serveur)
586 {
587 $where = "id_article=$id_article";
588 $total = sql_countsel("spip_signatures", $where);
589 if (!$total) return '';
590
591 $order = 'date_time';
592 if ($duree)
593 $where .= " AND $order > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL $duree $type)";
594
595 $log = statistiques_collecte_date('COUNT(*)', "(FLOOR(UNIX_TIMESTAMP($order) / $interval) * $interval)", 'spip_signatures', $where, $serveur);
596
597 $script = generer_url_ecrire('controle_petition', "id_article=$id_article");
598 if (count($log) > 1) {
599 $res = statistiques_tous($log, $id_article, "spip_signatures", "id_article=$id_article", "date_time", $serveur, $duree, $interval, $total, 0, '', array(), $script);
600 $res = gros_titre(_T('titre_page_statistiques_signatures_jour'),'', false) . cadre_stat($res, 'spip_signatures', $id_article);
601 } else $res = '';
602
603 $mois = statistiques_collecte_date( "COUNT(*)",
604 "DATE_FORMAT(date_time,'%Y%m')",
605 "spip_signatures",
606 "date_time > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL 2700 DAY)"
607 . (" AND id_article=$id_article"),
608 $serveur);
609
610 return "<br />"
611 . $res
612 . (!$mois ? '' : (
613 "<br />"
614 . gros_titre(_T('titre_page_statistiques_signatures_mois'),'', false)
615 . statistiques_par_mois($mois, $script)))
616 . ($res ? '' : statistiques_mode("spip_signatures", $id_article))
617 ;
618 }
619
620 // http://doc.spip.org/@statistiques_forums_dist
621 function statistiques_forums_dist($duree, $interval, $type, $id_article, $serveur)
622 {
623 $where = "id_article=$id_article AND statut='publie'";
624 $total = sql_countsel("spip_forum", $where);
625 if (!$total) return '';
626 $order = 'date_heure';
627 $interval = 24 * 3600;
628 $oldscore = 420;
629 $oldlog = array();
630 while ($interval >= 1) {
631 $log = statistiques_collecte_date('COUNT(*)', "(FLOOR(UNIX_TIMESTAMP($order) / $interval) * $interval)", 'spip_forum', $where, $serveur);
632 if (count($log) > 3) break;
633 $oldlog = $log;
634 $oldinterval = $interval;
635 $interval /= ($interval>3600) ? 24 : 60;
636 }
637 if (count($log) > 20) {
638 $interval = $oldinterval;
639 $log = $oldlog;
640 }
641 $script = generer_url_ecrire('articles_forum', "id_article=$id_article");
642 $date = sql_getfetsel('UNIX_TIMESTAMP(date)', 'spip_articles', $where);
643 $back = 10*ceil((time()-$date) / 3600);
644 $jour = statistiques_tous($log, $id_article, "spip_forum", $where, "date_heure", $serveur, $back, $interval, $total, 0, '', array(), $script);
645
646 return "<br />"
647 . gros_titre(_T('titre_page_statistiques_messages_forum'),'', false)
648 . cadre_stat($jour, 'spip_forum', $id_article);
649 }
650
651 // Le bouton pour CSV
652
653 // http://doc.spip.org/@statistiques_mode
654 function statistiques_mode($table, $id=0)
655 {
656 global $spip_lang_left;
657 $t = str_replace('spip_', '', $table);
658 $fond = (strstr($t, 'visites') ? 'statistiques' : $t);
659 $args = array();
660 if ($id) {
661 $fond .= "_article";
662 $args['id_article'] = $id;
663 }
664 include_spip('inc/acces');
665 $args = param_low_sec($fond, $args, '', 'transmettre');
666 $url = generer_url_public('transmettre', $args);
667 return "<a style='float: $spip_lang_left;' href='$url'>CSV</a>";
668 }
669 ?>