3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
6 * Copyright (c) 2001-2014 *
7 * Arnaud Martin, Antoine Pitrou, Philippe Riviere, Emmanuel Saint-James *
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 \***************************************************************************/
13 if (!defined('_ECRIRE_INC_VERSION')) return;
15 include_spip('inc/presentation');
16 include_spip('inc/statistiques');
18 // http://doc.spip.org/@exec_statistiques_visites_dist
19 function exec_statistiques_visites_dist()
21 $id_article = intval(_request('id_article'));
22 $type = _request('type');
23 if (!preg_match('/^\w+$/', $type)) $type = 'day';
24 $duree = intval(_request('duree'));
25 if (!$duree) $duree = 105;
26 $interval = intval(_request('interval'));
30 else $interval = 3600;
33 // nombre de referers a afficher
34 $limit = intval(_request('limit'));
35 if ($limit == 0) $limit = 100;
37 if (!autoriser('voirstats', $id_article ?
'article':'', $id_article)) {
38 include_spip('inc/minipres');
40 } else exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit);
44 // http://doc.spip.org/@exec_statistiques_visites_args
45 function exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit,$serveur='')
47 $titre = $pourarticle = "";
50 $row = sql_fetsel("titre, visites, popularite", "spip_articles", "statut='publie' AND id_article=$id_article",'','','','',$serveur);
53 $titre = typo($row['titre']);
54 $total_absolu = $row['visites'];
55 $val_popularite = round($row['popularite']);
58 $row = sql_fetsel("SUM(visites) AS total_absolu", "spip_visites",'','','','','',$serveur);
59 $total_absolu = $row ?
$row['total_absolu'] : 0;
63 if ($titre) $pourarticle = " "._T('info_pour')." « $titre »";
65 if ($row = sql_fetsel('valeur','spip_meta',"nom='nom_site'",'','','','',$serveur)){
66 $titre = $row['valeur'].($titre?
" / $titre":"");
70 $commencer_page = charger_fonction('commencer_page', 'inc');
71 echo $commencer_page(_T('titre_page_statistiques_visites').$pourarticle, "statistiques_visites", "statistiques");
72 echo gros_titre(_T('titre_evolution_visite')."<html>".aide("confstat")."</html>",'', false);
73 // barre_onglets("statistiques", "evolution");
74 if ($titre) echo gros_titre($titre,'', false);
76 echo debut_gauche('', true);
77 echo "<div class='cadre cadre-e' style='padding: 5px;'>";
78 echo "<div class='cadre_padding verdana1 spip_x-small'>";
79 echo typo(_T('info_afficher_visites'));
83 echo "<li><b><a href='" . generer_url_ecrire("statistiques_visites","") . "'>"._T('info_tout_site')."</a></b></li>";
85 echo "<li><b>"._T('titre_page_articles_tous')."</b></li>";
92 $classement = array();
94 echo aff_statistique_visites_popularite($serveur, $id_article, $classement, $liste);
96 // Par visites depuis le debut
97 $result = aff_statistique_visites_par_visites($serveur, $id_article, $classement);
99 if ($result OR $id_article)
100 echo creer_colonne_droite('', true);
103 echo bloc_des_raccourcis(icone_horizontale(_T('icone_retour_article'), generer_url_ecrire("articles","id_article=$id_article"), "article-24.gif","rien.gif", false));
107 echo debut_droite('', true);
110 $table = "spip_visites_articles";
111 $table_ref = "spip_referers_articles";
112 $where = "id_article=$id_article";
115 $table = "spip_visites";
116 $table_ref = "spip_referers";
122 $where2 = $duree ?
"$order > DATE_SUB(".sql_quote(date('Y-m-d H:i:s')).",INTERVAL $duree $type)": '';
123 if ($where) $where2 = $where2 ?
"$where2 AND $where" : $where;
125 // sur certains SQL, la division produit un entier tronque a la valeur inferieure
126 // on ne peut donc faire un CEIL, il faut faire un FLOOR
127 $log = statistiques_collecte_date('visites', "(FLOOR((UNIX_TIMESTAMP($order)+$interval-1) / $interval) * $interval)", $table, $where2, $serveur);
130 $res = statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $duree, $interval, $total_absolu, $val_popularite, $classement, $liste);
132 $mois = statistiques_collecte_date("SUM(visites)",
133 "DATE_FORMAT($order,'%Y%m')",
135 "$order > DATE_SUB(NOW(),INTERVAL 2700 DAY)"
136 . ($where ?
" AND $where" : ''),
139 if (count($mois)>1) {
140 $res[] = "<br /><span class='verdana1 spip_small'><b>"
141 . _T('info_visites_par_mois')
143 . statistiques_par_mois($mois, '');
145 echo cadre_stat($res, $table, $id_article);
148 $signatures = charger_fonction('signatures', 'statistiques');
149 echo $signatures($duree, $interval, $type, $id_article, $serveur);
151 Il faudra optimiser les requetes de ces stats c'est vraiment trop horrible :
152 plusieurs secondes d'attente sur un site comme contrib.
153 par ailleurs, l'affichage presente des defauts :
154 cf http://trac.rezo.net/trac/spip/ticket/1598
155 $forums = charger_fonction('forums', 'statistiques');
156 echo $forums($duree, $interval, $type, $id_article, $serveur);
161 $referenceurs = charger_fonction('referenceurs', 'inc');
162 $res = $referenceurs($id_article, "visites", $table_ref, $where, '', $limit);
166 // Le lien pour en afficher "plus"
167 $args = ($id_article?
"id_article=$id_article&" : '') . "limit=" . strval($limit+
200);
169 $plus = generer_url_ecrire('statistiques_visites', $args);
171 $plus = "<div style='text-align:right;'><b><a href='$plus'>+++</a></b></div>";
173 $titre = _T("onglet_origine_visites")
175 . ($n == 1 ?
_T('info_site') : _T('info_sites'))
177 echo '<br />', gros_titre($titre,'', false);
178 echo "<div style='overflow:hidden;' class='verdana1 spip_small'><br />";
179 echo "<ul class='referers'><li>";
180 echo join("</li><li>\n",$res);
186 echo fin_gauche(), fin_page();