[SPIP] ~2.1.12 -->2.1.25
[velocampus/web/www.git] / www / ecrire / exec / statistiques_visites.php
1 <?php
2
3 /***************************************************************************\
4 * SPIP, Systeme de publication pour l'internet *
5 * *
6 * Copyright (c) 2001-2014 *
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 include_spip('inc/presentation');
16 include_spip('inc/statistiques');
17
18 // http://doc.spip.org/@exec_statistiques_visites_dist
19 function exec_statistiques_visites_dist()
20 {
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'));
27 if (!$interval) {
28 if ($type == 'day')
29 $interval = 3600*24;
30 else $interval = 3600;
31 }
32
33 // nombre de referers a afficher
34 $limit = intval(_request('limit'));
35 if ($limit == 0) $limit = 100;
36
37 if (!autoriser('voirstats', $id_article ? 'article':'', $id_article)) {
38 include_spip('inc/minipres');
39 echo minipres();
40 } else exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit);
41 }
42
43
44 // http://doc.spip.org/@exec_statistiques_visites_args
45 function exec_statistiques_visites_args($id_article, $duree, $interval, $type, $limit,$serveur='')
46 {
47 $titre = $pourarticle = "";
48
49 if ($id_article){
50 $row = sql_fetsel("titre, visites, popularite", "spip_articles", "statut='publie' AND id_article=$id_article",'','','','',$serveur);
51
52 if ($row) {
53 $titre = typo($row['titre']);
54 $total_absolu = $row['visites'];
55 $val_popularite = round($row['popularite']);
56 }
57 } else {
58 $row = sql_fetsel("SUM(visites) AS total_absolu", "spip_visites",'','','','','',$serveur);
59 $total_absolu = $row ? $row['total_absolu'] : 0;
60 $val_popularite = 0;
61 }
62
63 if ($titre) $pourarticle = " "._T('info_pour')." &laquo; $titre &raquo;";
64 if ($serveur) {
65 if ($row = sql_fetsel('valeur','spip_meta',"nom='nom_site'",'','','','',$serveur)){
66 $titre = $row['valeur'].($titre?" / $titre":"");
67 }
68 }
69
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);
75
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'));
80 echo "<ul>";
81
82 if ($id_article>0) {
83 echo "<li><b><a href='" . generer_url_ecrire("statistiques_visites","") . "'>"._T('info_tout_site')."</a></b></li>";
84 } else {
85 echo "<li><b>"._T('titre_page_articles_tous')."</b></li>";
86 }
87
88 echo "</ul>";
89 echo "</div>";
90 echo "</div>";
91
92 $classement = array();
93 $liste = 0;
94 echo aff_statistique_visites_popularite($serveur, $id_article, $classement, $liste);
95
96 // Par visites depuis le debut
97 $result = aff_statistique_visites_par_visites($serveur, $id_article, $classement);
98
99 if ($result OR $id_article)
100 echo creer_colonne_droite('', true);
101
102 if ($id_article) {
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));
104 }
105 echo $result;
106
107 echo debut_droite('', true);
108
109 if ($id_article) {
110 $table = "spip_visites_articles";
111 $table_ref = "spip_referers_articles";
112 $where = "id_article=$id_article";
113
114 } else {
115 $table = "spip_visites";
116 $table_ref = "spip_referers";
117 $where = "";
118 }
119
120 $order = "date";
121
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;
124
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);
128
129 if ($log)
130 $res = statistiques_tous($log, $id_article, $table, $where, $order, $serveur, $duree, $interval, $total_absolu, $val_popularite, $classement, $liste);
131
132 $mois = statistiques_collecte_date("SUM(visites)",
133 "DATE_FORMAT($order,'%Y%m')",
134 $table,
135 "$order > DATE_SUB(NOW(),INTERVAL 2700 DAY)"
136 . ($where ? " AND $where" : ''),
137 $serveur);
138
139 if (count($mois)>1) {
140 $res[] = "<br /><span class='verdana1 spip_small'><b>"
141 . _T('info_visites_par_mois')
142 . "</b></span>"
143 . statistiques_par_mois($mois, '');
144 }
145 echo cadre_stat($res, $table, $id_article);
146
147 if ($id_article) {
148 $signatures = charger_fonction('signatures', 'statistiques');
149 echo $signatures($duree, $interval, $type, $id_article, $serveur);
150 /*
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);
157 */
158 }
159
160
161 $referenceurs = charger_fonction('referenceurs', 'inc');
162 $res = $referenceurs($id_article, "visites", $table_ref, $where, '', $limit);
163
164 if ($res) {
165
166 // Le lien pour en afficher "plus"
167 $args = ($id_article?"id_article=$id_article&" : '') . "limit=" . strval($limit+200);
168 $n = count($res);
169 $plus = generer_url_ecrire('statistiques_visites', $args);
170 if ($plus) {
171 $plus = "<div style='text-align:right;'><b><a href='$plus'>+++</a></b></div>";
172 }
173 $titre = _T("onglet_origine_visites")
174 . " ($n "
175 . ($n == 1 ? _T('info_site') : _T('info_sites'))
176 . ")";
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);
181 echo "</li></ul>";
182 echo $plus;
183 echo "<br /></div>";
184 }
185
186 echo fin_gauche(), fin_page();
187 }
188 ?>