X-Git-Url: http://git.cyclocoop.org/?p=velocampus%2Fweb%2Fwww.git;a=blobdiff_plain;f=www%2Fecrire%2Finc%2Fstatistiques.php;fp=www%2Fecrire%2Finc%2Fstatistiques.php;h=26e1494f1275fd44de9ef7ed54b28b7d314c7cbb;hp=0000000000000000000000000000000000000000;hb=80b4d3e85f78d402ed2e73f8f5d1bf4c19962eed;hpb=aaf970bf4cdaf76689ecc10609048e18d073820c
diff --git a/www/ecrire/inc/statistiques.php b/www/ecrire/inc/statistiques.php
new file mode 100644
index 0000000..26e1494
--- /dev/null
+++ b/www/ecrire/inc/statistiques.php
@@ -0,0 +1,669 @@
+ 0", "", "popularite DESC",'','',$serveur);
+ $out = '';
+ while ($row = sql_fetch($result,$serveur)) {
+ $l_article = $row['id_article'];
+ $liste++;
+ $classement[$l_article] = $liste;
+
+ if ($liste <= 30) {
+ $articles_vus[] = $l_article;
+ $out .= statistiques_populaires($row, $id_article, $liste);
+ }
+ }
+ $recents = array();
+ $q = sql_select("id_article", "spip_articles", "statut='publie' AND popularite > 0", "", "date DESC", "10",'',$serveur);
+ while ($r = sql_fetch($q,$serveur))
+ if (!in_array($r['id_article'], $articles_vus))
+ $recents[]= $r['id_article'];
+
+ if ($recents) {
+ $result = sql_select("id_article, titre, popularite, visites", "spip_articles", "statut='publie' AND " . sql_in('id_article', $recents), "", "popularite DESC",'','',$serveur);
+
+ $out .= "
[...]
" .
+ "";
+ while ($row = sql_fetch($result,$serveur)) {
+ $l_article = $row["id_article"];
+ $out .= statistiques_populaires($row, $id_article, $classement[$l_article]);
+ }
+ }
+
+ return !$out ? '' : (
+ "\n"
+ ."
"
+ .typo(_T('info_visites_plus_populaires'))
+ ."
"
+
+ ."
"._T('info_comment_lire_tableau')."
"._T('texte_comment_lire_tableau')."
"
+
+ ."
"
+ ."
");
+}
+
+function statistiques_populaires($row, $id_article, $classement)
+{
+ $titre = typo(supprime_img($row['titre'], ''));
+ $l_article = $row['id_article'];
+
+ if ($l_article == $id_article){
+ return "- $classement.$titre
";
+ } else {
+ $visites = $row['visites'];
+ $popularite = round($row['popularite']);
+ return "- $classement. $popularite, 'visites' => $visites))."'>$titre
";
+ }
+}
+
+// http://doc.spip.org/@aff_statistique_visites_par_visites
+function aff_statistique_visites_par_visites($serveur='', $id_article=0, $classement= array()) {
+ $res = "";
+ // Par visites depuis le debut
+ $result = sql_select("id_article, titre, popularite, visites", "spip_articles", "statut='publie' AND popularite > 0", "", "visites DESC", "30",'',$serveur);
+
+ while ($row = sql_fetch($result,$serveur)) {
+ $titre = typo(supprime_img($row['titre'],''));
+ $l_article = $row['id_article'];
+
+ if ($l_article == $id_article){
+ $res.= "- "
+ . $classement[$l_article]
+ . ".$titre
";
+ } else {
+ $t = _T('info_popularite_4',
+ array('popularite' => round($row['popularite']), 'visites' => $row['visites']));
+ $h = generer_url_ecrire("statistiques_visites","id_article=$l_article");
+ $out = "$titre";
+ $res.= "- "
+ . $classement[$l_article]
+ . ".$out
";
+ }
+ }
+
+ if (!$res) return '';
+
+ return ""
+ . "
"
+ . typo(_T('info_affichier_visites_articles_plus_visites'))
+ . "
';
+}
+
+// http://doc.spip.org/@http_img_rien
+function http_img_rien($width, $height, $class='', $title='') {
+ return http_img_pack('rien.gif', $title,
+ "width='$width' height='$height'"
+ . (!$class ? '' : (" class='$class'"))
+ . (!$title ? '' : (" title=\"$title\"")));
+}
+
+// Donne la hauteur du graphe en fonction de la valeur maximale
+// Doit etre un entier "rond", pas trop eloigne du max, et dont
+// les graduations (divisions par huit) soient jolies :
+// on prend donc le plus proche au-dessus de x de la forme 12,16,20,40,60,80,100
+// http://doc.spip.org/@maxgraph
+function maxgraph($max) {
+
+ switch ($n =strlen($max)) {
+ case 0:
+ return 1;
+ case 1:
+ return 16;
+ case 2:
+ return (floor($max / 8) + 1) * 8;
+ case 3:
+ return (floor($max / 80) + 1) * 80;
+ default:
+ $dix = 2 * pow(10, $n-2);
+ return (floor($max / $dix) + 1) * $dix;
+ }
+}
+
+// http://doc.spip.org/@cadre_stat
+function cadre_stat($stats, $table, $id_article)
+{
+ if (!$stats) return '';
+ return debut_cadre_relief("statistiques-24.gif", true)
+ . join('', $stats)
+ . fin_cadre_relief(true)
+ . statistiques_mode($table, $id_article);
+}
+
+// http://doc.spip.org/@statistiques_collecte_date
+function statistiques_collecte_date($count, $date, $table, $where, $serveur)
+{
+ $result = sql_select("$count AS n, $date AS d", $table, $where, 'd', 'd', '','', $serveur);
+ $log = array();
+
+ while ($r = sql_fetch($result,$serveur)) $log[$r['d']] = $r['n'];
+ return $log;
+}
+
+// http://doc.spip.org/@statistiques_tous
+function statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $duree, $interval, $total, $popularite, $liste='', $classement=array(), $script='')
+{
+ $r = array_keys($log);
+ $date_fin = max($r);
+ $today = strtotime(date('Y-m-d 01:00:01'));
+ if ($today-$date_fin>$interval){
+ $log[$today] = 0;
+ $r = array_keys($log);
+ $date_fin = max($r);
+ }
+ $date_debut = min($r);
+ $date_premier = sql_getfetsel("UNIX_TIMESTAMP($order) AS d", $table, $where, '', $order, 1,'',$serveur);
+ $last = $log[$date_fin];
+ $max = max($log);
+ $maxgraph = maxgraph($max);
+ $rapport = 200 / $maxgraph;
+ $agreg = ceil(count($log) / 420);
+ $x = ceil(($date_fin-$date_debut)/$interval);
+ $largeur = ($agreg > 1) ? 1 : (!$x ? 420 : floor(420 / $x));
+
+ if ($largeur > 50) $largeur = 50; elseif ($largeur < 1) $largeur = 1;
+
+ list($moyenne,$prec, $res) = stat_log1($log, $agreg, $date_fin, $largeur, $rapport, $interval, $script);
+
+ $stats = "\n" .
+ "\n"
+ . "\n"
+ . "\n" . http_img_rien(1, 200) . " | "
+ . $res
+ . (!is_array($liste) ? '' : // prevision que pour les visites
+ statistiques_prevision($id_article, $largeur, $moyenne, $rapport, $popularite, $last))
+ . "\n"
+ . http_img_rien(1, 1) ." | "
+ . " "
+ . " | \n"
+ . http_img_rien(3, 1, 'trait_bas') ." | "
+ . "\n" . http_img_rien(5, 1) ." | "
+ . "\n"
+ . statistiques_echelle($maxgraph)
+ . " | "
+ . "
";
+
+ $total = "" . _T('info_total') ." " . $total."";
+
+ if (is_array($liste)) {
+ $liste = statistiques_classement($id_article, $classement, $liste);
+ $legend = statistiques_nom_des_mois($date_debut, $date_fin, $largeur, $interval,$agreg)
+ . ""
+ . _T('texte_statistiques_visites')
+ . "
";
+ $resume = statistiques_resume($max, $moyenne, $last, $prec, $popularite);
+ } else {
+ $legend = "" .
+ affdate_heure(date("Y-m-d H:i:s", $date_debut)) .
+ " | " .
+ affdate_heure(date("Y-m-d H:i:s", $date_fin)) .
+ ' |
';
+ $resume = '';
+ }
+
+ $legend .=
+ ""
+ . $resume
+ . "\n"
+ . $total
+ . $liste
+ . " |
";
+
+ $x = (!$duree) ? 1 : (420/ $duree);
+ $zoom = statistiques_zoom($id_article, $x, $date_premier, $date_debut, $date_fin);
+ return array($zoom, $stats, $mark, $legend);
+}
+
+// http://doc.spip.org/@statistiques_resume
+function statistiques_resume($max, $moyenne, $last, $prec, $popularite)
+{
+ return "\n"
+ . _T('info_maximum')." "
+ . $max . " "
+ . _T('info_moyenne')." "
+ . round($moyenne). " | "
+ . "\n"
+ . ''
+ . _T('info_aujourdhui')
+ . ' '
+ . $last
+ . (($prec <= 0) ? '' :
+ (' '
+ ._T('info_hier').' '.$prec))
+ . (!$popularite ? '' :
+ (" "._T('info_popularite_5').' '.$popularite))
+ . " | ";
+}
+
+// http://doc.spip.org/@statistiques_classement
+function statistiques_classement($id_article, $classement, $liste)
+{
+ if ($id_article) {
+ if ($classement[$id_article] > 0) {
+ if ($classement[$id_article] == 1)
+ $ch = _T('info_classement_1', array('liste' => $liste));
+ else
+ $ch = _T('info_classement_2', array('liste' => $liste));
+ return "
".$classement[$id_article].$ch;
+ }
+ } else
+ return "
"
+ ._T('info_popularite_2')." "
+ . ceil($GLOBALS['meta']['popularite_total'])
+ . "";
+}
+
+// http://doc.spip.org/@statistiques_zoom
+function statistiques_zoom($id_article, $largeur_abs, $date_premier, $date_debut, $date_fin)
+{
+ if ($largeur_abs > 1) {
+ $inc = ceil($largeur_abs / 5);
+ $duree_plus = 420 / ($largeur_abs - $inc);
+ $duree_moins = 420 / ($largeur_abs + $inc);
+ }
+
+ if ($largeur_abs == 1) {
+ $duree_plus = 840;
+ $duree_moins = 210;
+ }
+
+ if ($largeur_abs < 1) {
+ $duree_plus = 420 * ((1/$largeur_abs) + 1);
+ $duree_moins = 420 * ((1/$largeur_abs) - 1);
+ }
+
+ $pour_article = $id_article ? "&id_article=$id_article" : '';
+
+ $zoom = '';
+
+ if ($date_premier < $date_debut)
+ $zoom= lien_ou_expose(generer_url_ecrire("statistiques_visites","duree=$duree_plus$pour_article"),
+ http_img_pack('loupe-moins.gif',
+ _T('info_zoom'). '-',
+ "style='border: 0px; vertical-align: middle;'"), false, '',
+ " ");
+ if ( (($date_fin - $date_debut) / (24*3600)) > 30)
+ $zoom .= lien_ou_expose(generer_url_ecrire("statistiques_visites","duree=$duree_moins$pour_article"),
+ http_img_pack('loupe-plus.gif',
+ _T('info_zoom'). '+',
+ "style='border: 0px; vertical-align: middle;'"), false, '',
+ " ");
+
+ return $zoom;
+}
+
+// Presentation graphique
+// (rq: on n'affiche pas le jour courant, c'est a la charge de la prevision)
+// http://doc.spip.org/@stat_log1
+function stat_log1($log, $agreg, $date_today, $largeur, $rapport, $interval, $script) {
+ $res = '';
+ $rien = http_img_rien($largeur, 1, 'trait_bas', '');
+ $test_agreg = $decal = $date_prec = $val_prec = $moyenne = 0;
+ foreach ($log as $key => $value) {
+ if ($key == $date_today) break;
+ $test_agreg ++;
+ if ($test_agreg != $agreg) continue;
+ $test_agreg = 0;
+ if ($decal == 30) $decal = 0;
+ $decal ++;
+ $evol[$decal] = $value;
+ // Inserer des jours vides si pas d'entrees
+ if ($date_prec > 0) {
+ $ecart = (($key-$date_prec)/$agreg)-$interval;
+ for ($i=$interval; $i <= $ecart; $i+=$interval){
+ if ($decal == 30) $decal = 0;
+ $decal ++;
+ $evol[$decal] = $value;
+ $m = statistiques_moyenne($evol);
+ $m = statistiques_vides($date_prec+$i, $largeur, $rapport, $m, $script);
+ $res .= "\n$m | ";
+ }
+ }
+ $moyenne = round(statistiques_moyenne($evol),2);
+ $hauteur = round($value * $rapport) - 1;
+ $m = ($hauteur <= 0) ? '' : statistiques_jour($key, $value, $largeur, $moyenne, $hauteur, $rapport, (date("w",$key) == "0"), $script);
+ $res .= "\n$m$rien | \n";
+ $date_prec = $key;
+ $val_prec = $value;
+ }
+ return array($moyenne, $val_prec, $res);
+}
+
+// http://doc.spip.org/@statistiques_href
+function statistiques_href($jour, $moyenne, $script, $value='')
+{
+ $ce_jour=date("Y-m-d H:i:s", $jour);
+ $title = nom_jour($ce_jour) . ' '
+ . ($script ? affdate_heure($ce_jour) :
+ (affdate_jourcourt($ce_jour) .' '.
+ (" | " ._T('info_visites')." $value | " ._T('info_moyenne')." "
+ . round($moyenne,2))));
+ return attribut_html(supprimer_tags($title));
+}
+
+// http://doc.spip.org/@statistiques_vides
+function statistiques_vides($prec, $largeur, $rapport, $moyenne, $script)
+{
+ $hauteur_moyenne = round($moyenne*$rapport)-1;
+ $title = statistiques_href($prec, $moyenne, $script);
+ $tagtitle = $script ? '' : $title;
+ if ($hauteur_moyenne > 1) {
+ $res = http_img_rien($largeur,1, 'trait_moyen', $tagtitle)
+ . http_img_rien($largeur, $hauteur_moyenne, '', $tagtitle);
+ } else $res = '';
+ $res .= http_img_rien($largeur,1,'trait_bas', $tagtitle);
+ if (!$script) return $res;
+ return "$res";
+}
+
+
+// http://doc.spip.org/@statistiques_prevision
+function statistiques_prevision($id_article, $largeur, $moyenne, $rapport, $val_popularite, $visites_today)
+{
+ $hauteur = round($visites_today * $rapport) - 1;
+ // $total_absolu = $total_absolu + $visites_today;
+ // prevision de visites jusqu'a minuit
+ // basee sur la moyenne (site) ou popularite (article)
+ if (! $id_article) $val_popularite = $moyenne;
+ $prevision = (1 - (date("H")*60 + date("i"))/(24*60)) * $val_popularite;
+ $hauteurprevision = ceil($prevision * $rapport);
+ // preparer le texte de survol (prevision)
+ $tagtitle= attribut_html(supprimer_tags(_T('info_aujourdhui')." $visites_today → ".(round($prevision,0)+$visites_today)));
+
+ $res .= "\n";
+ if ($hauteur+$hauteurprevision>0)
+ // Afficher la barre tout en haut
+ $res .= http_img_rien($largeur, 1, "trait_haut");
+ if ($hauteurprevision>0)
+ // afficher la barre previsionnelle
+ $res .= http_img_rien($largeur, $hauteurprevision,'couleur_prevision', $tagtitle);
+ // afficher la barre deja realisee
+ if ($hauteur>0)
+ $res .= http_img_rien($largeur, $hauteur, 'couleur_realise', $tagtitle);
+ // et afficher la ligne de base
+ $res .= http_img_rien($largeur, 1, 'trait_bas')
+ . " | ";
+
+ return $res;
+}
+
+// Dimanche en couleur foncee
+// http://doc.spip.org/@statistiques_jour
+function statistiques_jour($key, $value, $largeur, $moyenne, $hauteur, $rapport, $dimanche, $script)
+{
+ $hauteur_moyenne = round($moyenne * $rapport) - 1;
+ $title= statistiques_href($key, $moyenne, $script, $value);
+ $tagtitle = $script ? '' : $title;
+ $couleur = $dimanche ? "couleur_dimanche" : "couleur_jour";
+ if ($hauteur_moyenne > $hauteur) {
+ $difference = ($hauteur_moyenne - $hauteur) -1;
+
+ $res = http_img_rien($largeur, 1,'trait_moyen',$tagtitle)
+ . http_img_rien($largeur, $difference, '', $tagtitle)
+ . http_img_rien($largeur, 1, "trait_haut", $tagtitle)
+ . http_img_rien($largeur, $hauteur, $couleur, $tagtitle);
+ } else if ($hauteur_moyenne < $hauteur) {
+ $difference = ($hauteur - $hauteur_moyenne) -1;
+ $res = http_img_rien($largeur,1,"trait_haut", $tagtitle)
+ . http_img_rien($largeur, $difference, $couleur, $tagtitle)
+ . http_img_rien($largeur,1,"trait_moyen", $tagtitle)
+ . http_img_rien($largeur, $hauteur_moyenne, $couleur, $tagtitle);
+ } else {
+ $res = http_img_rien($largeur, 1, "trait_haut", $tagtitle)
+ . http_img_rien($largeur, $hauteur, $couleur, $tagtitle);
+ }
+ if ($script)
+ $script .= "&date=$key";
+ else {
+ $y = date("Y", $key);
+ $m = date("m", $key);
+ $d = date("d", $key);
+ $script = generer_url_ecrire('calendrier',
+ "type=semaine&annee=$y&mois=$m&jour=$d");
+ }
+ return "$res";
+}
+
+// http://doc.spip.org/@statistiques_nom_des_mois
+function statistiques_nom_des_mois($date_debut, $date_today, $largeur, $pas, $agreg)
+{
+ global $spip_lang_left;
+
+ $res = '';
+ $largeur /= ($pas*$agreg);
+ $gauche_prec = -50;
+ for ($jour = $date_debut; $jour <= $date_today; $jour += $pas) {
+ if (date("d", $jour) == "1") {
+ $newy = (date("m", $jour) == 1);
+ $gauche = floor(($jour - $date_debut) * $largeur);
+ if ($gauche - $gauche_prec >= 40 OR $newy) {
+ $afficher = $newy ?
+ ("".annee(date("Y-m-d", $jour))."")
+ : nom_mois(date("Y-m-d", $jour));
+
+ $res .= "".$afficher."
";
+ $gauche_prec = $gauche;
+ if ($gauche > 400) break; //400px max
+ }
+ }
+ }
+ return "$res
";
+}
+
+// http://doc.spip.org/@statistiques_par_mois
+function statistiques_par_mois($entrees, $script){
+
+ $maxgraph = maxgraph(max($entrees));
+ $rapport = 200/$maxgraph;
+ $largeur = floor(420 / (count($entrees)));
+ if ($largeur < 1) $largeur = 1;
+ if ($largeur > 50) $largeur = 50;
+ $decal = 0;
+ $tab_moyenne = array();
+
+ $all = '';
+
+ foreach($entrees as $key=>$value) {
+ $key = substr($key,0,4).'-'.substr($key,4,2);
+ $mois = affdate_mois_annee($key);
+ if ($decal == 30) $decal = 0;
+ $decal ++;
+ $tab_moyenne[$decal] = $value;
+ $moyenne = statistiques_moyenne($tab_moyenne);
+ $hauteur_moyenne = round($moyenne * $rapport) - 1;
+ $hauteur = round($value * $rapport) - 1;
+ $res = '';
+ $title= attribut_html(supprimer_tags("$mois | "
+ ._T('info_total')." ".$value));
+ $tagtitle = $script ? '' : $title;
+ if ($hauteur > 0){
+ if ($hauteur_moyenne > $hauteur) {
+ $difference = ($hauteur_moyenne - $hauteur) -1;
+ $res .= http_img_rien($largeur, 1, 'trait_moyen');
+ $res .= http_img_rien($largeur, $difference, '', $tagtitle);
+ $res .= http_img_rien($largeur,1,"trait_haut");
+ if (preg_match(",-01,",$key)){ // janvier en couleur foncee
+ $res .= http_img_rien($largeur,$hauteur,"couleur_janvier", $tagtitle);
+ } else {
+ $res .= http_img_rien($largeur,$hauteur,"couleur_mois", $tagtitle);
+ }
+ }
+ else if ($hauteur_moyenne < $hauteur) {
+ $difference = ($hauteur - $hauteur_moyenne) -1;
+ $res .= http_img_rien($largeur,1,"trait_haut", $tagtitle);
+ if (preg_match(",-01,",$key)){ // janvier en couleur foncee
+ $couleur = 'couleur_janvier';
+ } else {
+ $couleur = 'couleur_mois';
+ }
+ $res .= http_img_rien($largeur,$difference, $couleur, $tagtitle);
+ $res .= http_img_rien($largeur,1,'trait_moyen',$tagtitle);
+ $res .= http_img_rien($largeur,$hauteur_moyenne, $couleur, $tagtitle);
+ } else {
+ $res .= http_img_rien($largeur,1,"trait_haut", $tagtitle);
+ if (preg_match(",-01,",$key)){ // janvier en couleur foncee
+ $res .= http_img_rien($largeur, $hauteur, "couleur_janvier", $tagtitle);
+ } else {
+ $res .= http_img_rien($largeur,$hauteur, "couleur_mois", $tagtitle);
+ }
+ }
+ }
+ $res .= http_img_rien($largeur,1,'trait_bas', $tagtitle);
+
+ if (!$script) {
+ $y = annee($key);
+ $m = mois($key);
+ $href = generer_url_ecrire('calendrier', "type=mois&annee=$y&mois=$m&jour=1");
+ } else $href = "$script&date=$key";
+
+ $all .= "\n'
+ . $res
+ . " | \n";
+ }
+
+ return
+ "\n"
+ . "\n"
+ . "\n"
+ . "\n" . http_img_rien(1, 200) ." | "
+ . $all
+ . "\n" . http_img_rien(1, 1)
+ . " | "
+ . "
| "
+ . "\n"
+ . http_img_rien(3, 1, 'trait_bas') ." | "
+ . "\n" . http_img_rien(5, 1) ." | "
+ . "\n"
+ . statistiques_echelle($maxgraph)
+ . " |
";
+ }
+
+// http://doc.spip.org/@statistiques_echelle
+function statistiques_echelle($maxgraph)
+{
+ return recuperer_fond('prive/stats/echelle', array('echelle' => $maxgraph));
+}
+
+// http://doc.spip.org/@statistiques_moyenne
+function statistiques_moyenne($tab)
+{
+ if (!$tab) return 0;
+ $moyenne = 0;
+ foreach($tab as $v) $moyenne += $v;
+ return $moyenne / count($tab);
+}
+
+
+// http://doc.spip.org/@statistiques_signatures_dist
+function statistiques_signatures_dist($duree, $interval, $type, $id_article, $serveur)
+{
+ $where = "id_article=$id_article";
+ $total = sql_countsel("spip_signatures", $where);
+ if (!$total) return '';
+
+ $order = 'date_time';
+ if ($duree)
+ $where .= " AND $order > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL $duree $type)";
+
+ $log = statistiques_collecte_date('COUNT(*)', "(FLOOR(UNIX_TIMESTAMP($order) / $interval) * $interval)", 'spip_signatures', $where, $serveur);
+
+ $script = generer_url_ecrire('controle_petition', "id_article=$id_article");
+ if (count($log) > 1) {
+ $res = statistiques_tous($log, $id_article, "spip_signatures", "id_article=$id_article", "date_time", $serveur, $duree, $interval, $total, 0, '', array(), $script);
+ $res = gros_titre(_T('titre_page_statistiques_signatures_jour'),'', false) . cadre_stat($res, 'spip_signatures', $id_article);
+ } else $res = '';
+
+ $mois = statistiques_collecte_date( "COUNT(*)",
+ "DATE_FORMAT(date_time,'%Y%m')",
+ "spip_signatures",
+ "date_time > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL 2700 DAY)"
+ . (" AND id_article=$id_article"),
+ $serveur);
+
+ return "
"
+ . $res
+ . (!$mois ? '' : (
+ "
"
+ . gros_titre(_T('titre_page_statistiques_signatures_mois'),'', false)
+ . statistiques_par_mois($mois, $script)))
+ . ($res ? '' : statistiques_mode("spip_signatures", $id_article))
+;
+}
+
+// http://doc.spip.org/@statistiques_forums_dist
+function statistiques_forums_dist($duree, $interval, $type, $id_article, $serveur)
+{
+ $where = "id_article=$id_article AND statut='publie'";
+ $total = sql_countsel("spip_forum", $where);
+ if (!$total) return '';
+ $order = 'date_heure';
+ $interval = 24 * 3600;
+ $oldscore = 420;
+ $oldlog = array();
+ while ($interval >= 1) {
+ $log = statistiques_collecte_date('COUNT(*)', "(FLOOR(UNIX_TIMESTAMP($order) / $interval) * $interval)", 'spip_forum', $where, $serveur);
+ if (count($log) > 3) break;
+ $oldlog = $log;
+ $oldinterval = $interval;
+ $interval /= ($interval>3600) ? 24 : 60;
+ }
+ if (count($log) > 20) {
+ $interval = $oldinterval;
+ $log = $oldlog;
+ }
+ $script = generer_url_ecrire('articles_forum', "id_article=$id_article");
+ $date = sql_getfetsel('UNIX_TIMESTAMP(date)', 'spip_articles', $where);
+ $back = 10*ceil((time()-$date) / 3600);
+ $jour = statistiques_tous($log, $id_article, "spip_forum", $where, "date_heure", $serveur, $back, $interval, $total, 0, '', array(), $script);
+
+ return "
"
+ . gros_titre(_T('titre_page_statistiques_messages_forum'),'', false)
+ . cadre_stat($jour, 'spip_forum', $id_article);
+}
+
+// Le bouton pour CSV
+
+// http://doc.spip.org/@statistiques_mode
+function statistiques_mode($table, $id=0)
+{
+ global $spip_lang_left;
+ $t = str_replace('spip_', '', $table);
+ $fond = (strstr($t, 'visites') ? 'statistiques' : $t);
+ $args = array();
+ if ($id) {
+ $fond .= "_article";
+ $args['id_article'] = $id;
+ }
+ include_spip('inc/acces');
+ $args = param_low_sec($fond, $args, '', 'transmettre');
+ $url = generer_url_public('transmettre', $args);
+ return "CSV";
+}
+?>