PageRenderTime 48ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 0ms

/spip/ecrire/inc/statistiques.php

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