PageRenderTime 191ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 1ms

/modules/visitstat/stats_in.php

https://bitbucket.org/meianki/voguersurlavague
PHP | 933 lines | 640 code | 121 blank | 172 comment | 94 complexity | 02c5ed3ac2b48383049509bc7bbef8f9 MD5 | raw file
Possible License(s): BSD-3-Clause, AGPL-1.0
  1. <?
  2. /*
  3. -------------------------------------------------------------------------
  4. AllMyStats V1.37 - Statistiques de fréquentation visiteurs et robots
  5. -------------------------------------------------------------------------
  6. Copyright (C) 2000 - Cédric TATANGELO (Cedstat)
  7. Copyright (C) 2008 - Herve Seywert
  8. -------------------------------------------------------------------------
  9. Web: http://www.wertronic.com
  10. -------------------------------------------------------------------------
  11. Ce programme est libre, vous pouvez le redistribuer et/ou le modifier
  12. selon les termes de la Licence Publique Génrale GNU publiée par la Free
  13. Software Foundation .
  14. -------------------------------------------------------------------------
  15. Fichier stats_in.php ? appelé pour un acc?s public (ou non si $public = false;) au cumul des statistiques du mois en cours
  16. Le déclenchement des mises ? jour et la création du fichier cache est effectuée par les visiteurs
  17. suivant le réglage en minutes de l'interval entre 2 mises ? jour (variable $delai_mise_cache)
  18. Exemple:
  19. $delai_mise_cache est réglé sur 5 (minutes)
  20. Une mise ? jour et une mise en cache a été effectuée ? 12H00 : pour tous les visiteurs entre 12H00 et 12H05 c'est le fichier cache qui sera afffiché
  21. Le 1er visiteur apr?s 12H05 declenchera un calcul et une mise en cache des stats du mois en cours.
  22. Cette solution permet de ne pas recalculer ? chaque visiteur tous les statistiques, et donc menage les ressources serveur.
  23. Note
  24. Ne pas oublier de mettre les mois écoulés en cache via l'admin, simplement visualiser le cumul, afin d'alléger les calculs du mois en cours
  25. -----------------------------------------
  26. Ajout suffixe différent pour chaque combinaison pour permettre plusieurs configurations dans des pages différentes
  27. */
  28. //######################################################## Configuration #######################################################################
  29. $public = false; //true pour acc?s public si false on ne peut y accéder seulement si l'on est connecté ? l'admin
  30. $html_body = false; // Si nouvelle page = true - Si intégré dans une page existante = false
  31. //------------------------------------------------------------------------------
  32. /*
  33. //Si ce fichier est appelé ? partir d'une ou d'autres pages ? l'aide de
  34. require_once('allmystats/stats_in.php'); // Chemin vers allmystats stats_in.php
  35. il est possible de déplacer ces variables juste avant le require, ce qui permet suivant les pages qui l'appellent d'afficher ce que l'on veut
  36. Dans ce cas commenter les lignes ci-dessous et voir les fichiers exemples dans /exemple_stats_in
  37. */
  38. //Si le stats_in.php est appelé directement par un simple lien vers stats_in.php, décommenter les lignes ci-dessous ( supprimer /* et */ )
  39. /*
  40. $html_body = true; // Si nouvelle page = true - Si intégré dans une page existante = false
  41. $display_graph_by_day = true; //true ou false ,affichage du graphique viteurs & pages visitées / jour
  42. $display_keywords = true; //true ou false ,affichage du tabbleau des mots clés
  43. $display_page_view = true; //true ou false ,affichage du tabbleau pages visitées
  44. $display_org_geo = true; //true ou false ,affichage du tabbleau origine géographique
  45. $AfficheOS = true; //Affichage OS
  46. $AfficheNav = true; //Affichage Navigateurs utilisés
  47. $AfficheRobots = true; //Affichage des robots
  48. $delai_mise_cache = 5; //defaut 5 .Délai en minutes entre 2 mises ? jour du fichier cache du mois en cours. Permet de ne pas surcharger le serveur
  49. */
  50. //------------------------------------------------------------------------------
  51. //#################################################################################################################################################
  52. include_once('application_top.php');
  53. require ("config_allmystats.php");
  54. require('includes/mysql_tables.php');
  55. require ("includes/langues/$langue.php");
  56. mysql_connect($mysql_host,$mysql_login,$mysql_pass);
  57. mysql_select_db($mysql_dbnom);
  58. $mois = trim(date('m/Y',strtotime($UTC." hours", strtotime(date("Y-m-d H:i:s")))));
  59. /*
  60. //--------------------------------------------
  61. //Bouton de test force la mise en cache
  62. ?>
  63. <form name="form" method="post" action="<? $PHP_SELF ?>">
  64. <input class="submit" name="archive_encours" type="submit" value="<? echo "Force: Mise ? jour du cache pour le mois en cours"; ?>" alt="<? echo "Force: Mise ? jour du cache pour le mois en cours"; ?>" >
  65. </form>
  66. <?
  67. //------------------------------------------
  68. */
  69. //$path_allmystats_abs est défini dans config_allmystats.php
  70. echo '<link rel="stylesheet" type="text/css" href="'.$path_allmystats_abs.'stylesheet_stats_in.css">';
  71. $mois_Visualise = $mois;
  72. $Mois_Annee = explode("/", $mois_Visualise);
  73. $format_date_file_name = $Mois_Annee[1].'-'.$Mois_Annee[0];
  74. //---------- Construction du suffixe fichier cache -------------------
  75. $suffixe = "";
  76. if ($display_graph_by_day) {
  77. $suffixe .= "gd";
  78. }
  79. if ($display_keywords) {
  80. $suffixe .= "kw";
  81. }
  82. if ($display_page_view) {
  83. $suffixe .= "pv";
  84. }
  85. if ($display_org_geo) {
  86. $suffixe .= "ge";
  87. }
  88. if ($AfficheOS) {
  89. $suffixe .= "os";
  90. }
  91. if ($AfficheNav) {
  92. $suffixe .= "na";
  93. }
  94. if ($AfficheRobots) {
  95. $suffixe .= "ro";
  96. }
  97. //-------------------------------------------------------------------
  98. //Mise en en forme ($AllBots) pour preg_match des bot connus (dans la table + bot en générale (bot, spider , etc)
  99. $result1=mysql_query("select bot_name, org_name, crawler_url, crawler_info from ".TABLE_CRAWLER." ");
  100. $AllBots = '/Bot|Slurp|Scooter|Spider|crawl|';
  101. while($row=mysql_fetch_array($result1)){
  102. $Form_chaine = str_replace('/','\/',$row['bot_name']);
  103. $Form_chaine = str_replace('+','\+',$Form_chaine);
  104. $Form_chaine = str_replace('(','\(',$Form_chaine);
  105. $Form_chaine = str_replace(')','\)',$Form_chaine);
  106. $AllBots .= $Form_chaine.'|';
  107. }
  108. $AllBots = substr($AllBots,0,strlen($AllBots)-1); //supp last |
  109. $AllBots .= '/i';
  110. //-----------------------------------------------------------------------------
  111. //------------------------ Mise en tableau de la table bad user agent ---------
  112. unset($Matrice_bad_user_agent);
  113. $Bad_User_Agent=mysql_query("select * from ".TABLE_BAD_USER_AGENT.""); //
  114. while($bad_agents=mysql_fetch_array($Bad_User_Agent)){ // Mise en tableau des bad agents
  115. $Matrice_bad_user_agent[] = array($bad_agents['user_agent'], $bad_agents['info'],$bad_agents['type']);
  116. }
  117. //-----------------------------------------------------------------------------
  118. // Sinon fait: //Warning: filemtime() [function.filemtime]: SAFE MODE Restriction in effect. ? Pour $path_allmystats_abs
  119. $Racine_abs = str_replace($_SERVER['PHP_SELF'],"",$_SERVER['SCRIPT_FILENAME']);
  120. $path_allmystats = $Racine_abs.$path_allmystats_abs;
  121. $cache_mois_in = "";
  122. if( ($user_login!=$_SESSION['userlogin'] || $passwd!=$_SESSION['userpass']) && $public==false) {
  123. echo "<br><br><center><strong>Vous n'?tes pas autorisé ? visiter cette page</center></strong><br>";
  124. exit;
  125. } else {
  126. if ( date('YmdHi') >= date ("YmdHi", @filemtime($path_allmystats."cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php")) + $delai_mise_cache || isset($archive_encours) ){
  127. //echo "<br><strong>Todo mise en cache</strong><br>";
  128. $action_cache_mois_in = true;
  129. msg_temporaire("Opération en cours, veuillez patienter...");
  130. echo '<p align="center"><big><strong>Statistiques site: '.$site." - Mois: ".$mois_Visualise.'</strong></big><br>Derni?re mise ? jour: '.date('d/m/Y ? H:i').'<br></p>';
  131. } else {
  132. //echo "<br><strong>Pas de mise en cache ? faire</strong><br>";
  133. $action_cache_mois_in = false;
  134. echo "<center>Derni?re mise ? jour: ".date("d/m/Y ? H:i", filemtime($path_allmystats."cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php"))."</center>" ; //Date de d?rni?re mise ? jour du fichier
  135. include_once($path_allmystats."cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php");
  136. }
  137. }
  138. //-------------------------------------------------------------------
  139. if ($action_cache_mois_in) {
  140. //----------------------------------------------
  141. //Calcul Nb visiteurs et pages hors bot Robots
  142. $result=mysql_query("select * from ".TABLE_VISITEUR." where date like '%$mois'");
  143. $NbpageVues_HorsBots=0;
  144. $NbVisites_HorsBots=0;
  145. while($row=mysql_fetch_array($result)){
  146. if(!preg_match($AllBots, $row[agent])) {
  147. //---------------------------------------
  148. $User_Agent=$row[agent];
  149. $trash=false;
  150. for($nb_bad_user_agent=0;$nb_bad_user_agent<count($Matrice_bad_user_agent);$nb_bad_user_agent++){
  151. if ($Matrice_bad_user_agent[$nb_bad_user_agent][0] == $User_Agent && $Matrice_bad_user_agent[$nb_bad_user_agent][2]=='S') {
  152. $trash=true;
  153. }
  154. }
  155. //---------------------------------------
  156. }
  157. if(!preg_match($AllBots, $row[agent]) && $trash==false) {
  158. $NbpageVues_HorsBots = $NbpageVues_HorsBots+$row[nb_visite];
  159. $NbVisites_HorsBots = $NbVisites_HorsBots+1;
  160. }
  161. }
  162. //----------------------------------------------
  163. // -------------------------------------- Affichage -----------------------------------------------------------------------
  164. $show_footer = '<div align="center"><a href="http://allmystats.wertronic.com" target="_blank" class="Style1">AllMyStats</a> Powered by <a href="http://www.wertronic.com" target="_blank" class="Style1">Wertronic</a></div><br>';
  165. $show_cumul_page = $show_footer;
  166. /*
  167. if($display_counter) {
  168. $show_cumul_page = "Nombre de visiteurs: ".$NbVisites_HorsBots. "<br />""Nombre de pages vues: ".$NbpageVues_HorsBots;
  169. }
  170. */
  171. ################################################################################################################################################################
  172. //#############################################################################################
  173. // Graphique visiteurs et page visitées par Jour (todo en fonction car dans car existe aussi dans cumulpage.php, stats_in.php, histomaois.php)
  174. //---------------------------------------------------------------------------------------------
  175. if ($display_graph_by_day) {
  176. //recup des données
  177. $result=mysql_query("select agent, referer, date, code, ip, nb_visite from ".TABLE_VISITEUR." where date like '%$mois' order by code ASC");
  178. unset ($val_jour);
  179. while($row=mysql_fetch_array($result)){
  180. if(!preg_match($AllBots, $row['agent']) && $trash==false) {
  181. $date_comp = $row['date'];
  182. $cpt_jour = substr($date_comp,0,2)+0; // + 0 pour faire disparaitre les 0 devant 01, 02, 03 etc (aussi simple qu'une regex)
  183. $val_jour[$cpt_jour][0] = $val_jour[$cpt_jour][0] + 1;
  184. $val_jour[$cpt_jour][1] = $val_jour[$cpt_jour][1] + $row['nb_visite'];
  185. $total_nb_visiteurs = $total_nb_visiteurs + 1;
  186. $total_nb_pages_visitees = $total_nb_pages_visitees + $row['nb_visite'];
  187. //Nombre max de pages visité, pour height graph
  188. if($val_jour[$cpt_jour][1]>$max_pages){
  189. $max_pages=$val_jour[$cpt_jour][1];
  190. }
  191. //Pour affichage echelle y
  192. if($max_pages!=0){
  193. $indice_echelle = bcdiv($val_jour[$cpt_jour][1],$max_pages,2); $hauteur=bcmul($indice_echelle,180.00,2);
  194. if ($MaxHauteur_echelle <= $hauteur) { $MaxHauteur_echelle = $hauteur; $EchyMin = '0'; }
  195. } else { // pour ne pas afficher 0 si $max_pages = 0
  196. $EchyMin = '';
  197. $max_pages = '';
  198. }
  199. }
  200. }
  201. $Nb_jours = substr($date_comp,0,2);
  202. $graph_byday = "";
  203. //---------- Affichage --------------------------------------------------------------------
  204. $graph_byday .= "
  205. <TABLE align=center CELLPADDING=1 CELLSPACING=0 class=TABLEBORDER>
  206. <TBODY>
  207. <TR>
  208. <TD class=\"TDstatsin\"><!-- Data BEGIN -->
  209. <TABLE CELLPADDING=5 CELLSPACING=0 class=TABLEFRAME><!-- header -->
  210. <TBODY>
  211. <TR>
  212. <TH class=TABLETITLE>"
  213. .$MSG_STAT_GRAF_JOUR_TITRE." (".$MSG_ROBOTS_EXCLUS.") - ".$mois."
  214. </TH>
  215. </TR>
  216. <TR>
  217. <TD colSpan=2 class=\"TDstatsin\"><!-- Rows BEGIN -->
  218. <small>Total visiteurs = ".$total_nb_visiteurs."<br>
  219. Total pages visitées = ".$total_nb_pages_visitees."</small>
  220. <TABLE border=0 CELLPADDING=2 CELLSPACING=0 class=TABLEDATA>
  221. <TBODY>
  222. <TR>
  223. <td rowspan=\"2\" class=\"TDstatsin\">
  224. <B><SPAN class=PAGESVUES>".$MSG_PAGESVISITES."</SPAN><BR>
  225. &
  226. <SPAN class=VISITES>".$MSG_VISITE."</SPAN></B>
  227. </TD>";
  228. $graph_byday .= "
  229. <td nowrap=nowrap valign=\"top\" class=\"TDstatsin\">".$max_pages."</td>
  230. <td rowspan=\"2\" valign=\"bottom\" class=\"TDstatsin\"><img src=\"".$path_allmystats_abs."images/histo-v_black.gif\" height=\"".$MaxHauteur_echelle."\" width=\"1\" alt=\"\" title=\"\"></td>";
  231. for($i=1;$i<=$Nb_jours;$i++){
  232. $graph_byday .= "<td rowspan=\"2\" valign=\"bottom\" class=\"TDstatsin\">";
  233. if($max_pages!=0) {
  234. $indice=bcdiv($val_jour[$i][1],$max_pages,2); $hauteur=bcmul($indice,180.00,2);
  235. }
  236. $graph_byday .= "<img src=\"".$path_allmystats_abs."images/histo-v.gif\" height=\"".$hauteur."\" width=\"7\" alt=\"".$val_jour[$i][1]."\" title=\"".$val_jour[$i][1]."\">";
  237. if($max_pages!=0){
  238. $indice=bcdiv($val_jour[$i][0],$max_pages,2); $hauteur=bcmul($indice,180.00,2);
  239. }
  240. $graph_byday .= "<img src=\"".$path_allmystats_abs."images/histo-vv.gif\" height=\"".$hauteur."\" width=\"7\" alt=\"".$val_jour[$i][0]."\" title=\"".$val_jour[$i][0]."\"></td>";
  241. }
  242. $graph_byday .= "
  243. </TR>
  244. <tr>
  245. <td align=\"right\" valign=\"bottom\" class=\"TDstatsin\">".$EchyMin."</td>
  246. </tr>
  247. <tr>
  248. <td class=\"TDstatsin\"><B>". $MSG_GRAF_JOUR."</B></TD>
  249. <td align=center class=\"TDstatsin\">&nbsp;</td><td align=center class=\"TDstatsin\">&nbsp;</td>"; // Pour echelle x
  250. //----------------- calcul jour du mois et week end pour echelle x ------------------------
  251. $jm = explode("/",$mois);
  252. $nbjourdumois = maxDaysInMonth($jm[0], $jm[1]);
  253. // Premier samedi du mois (6eme jour de la semaine) fonction get_first_day
  254. $premiersamedi = strftime("%d", get_first_day(6, $jm[0], $jm[1]));
  255. $weekend = "/";
  256. if ($premiersamedi == 7) { $weekend .= sprintf("%02d",1).'|'; } //Le 1er jour du mois est un dimanche
  257. for($i=$premiersamedi;$i<=$nbjourdumois;$i=$i+7){
  258. $week = $i;
  259. $week = $week+0;
  260. $weekend .= sprintf("%02d",$week).'|';
  261. $weekend .= sprintf("%02d",$week+1) .'|';
  262. }
  263. $weekend = substr($weekend,0,strlen($weekend)-1); //supp last |
  264. $weekend .= "/";
  265. //------------------ Affichage echelle x -----------------
  266. for($i=1;$i<=$nbjourdumois;$i++){
  267. $num=$i;
  268. if(!preg_match($weekend, sprintf("%02d",$num))) { //$num+0 pour supprimer les 0 devant 01, 02 ,03 etc
  269. $graph_byday .= "<td align=center class=\"TDstatsin\">". sprintf("%02d", $num)."</td>";
  270. } else {
  271. $graph_byday .= "<td align=center class=\"TDstatsin\"><b><font color=#990000>". sprintf("%02d", $num)."</font></b></td>";
  272. }
  273. }
  274. //---------------------------------------------------------------------------------------
  275. $graph_byday .= "
  276. </TR></TBODY></TABLE><!-- Rows END --></TD></TR><!-- footer -->
  277. <TR>
  278. </TR></TBODY></TABLE><!-- Data END --></TD></TR></TBODY></TABLE><br>";
  279. //echo $graph_byday; //Affichage graph
  280. $show_cumul_page .= $graph_byday;
  281. $graph_byday ="";
  282. } // End if ($display_graph_by_day) {
  283. ################################################################################################################################################################
  284. //-------------------- Affichage tableau keywords -----------------------------
  285. if ($display_keywords) {
  286. $show_cumul_page .= "
  287. <table align=center cellpadding=1 cellspacing=0 class=TABLEBORDER>
  288. <tr>
  289. <td class=\"TDstatsin\"><!-- Data BEGIN -->
  290. <table cellpadding=5 cellspacing=0 class=TABLEFRAME><!-- header -->
  291. <tr>
  292. <th class=tabletitle>". $MSG_REF_TITRE. ' '. $mois."</th>
  293. </tr>
  294. <tr>
  295. <td colSpan=2 class=\"TDstatsin\"><!-- Rows BEGIN -->
  296. <table border=1 cellpadding=2 cellspacing=0 class=TABLEDATA>
  297. <tr>
  298. <th class=\"THstatsin\">". $MSG_REFERANT."</th>
  299. <th class=\"THstatsin\">". $MSG_REF_MOTCLE."</th>
  300. <th class=\"THstatsin\">". $MSG_VISITEURS."</th>
  301. </tr>";
  302. require "config_moteur.php";
  303. //-------------------------------------------------------------------------------------------
  304. unset($Tab_referer);
  305. $result=mysql_query("select * from ".TABLE_VISITEUR." where date like '%$mois' order by referer");
  306. $nb_unknow = 0;
  307. while($row=mysql_fetch_array($result)){
  308. $referer=parse_url($row[referer]);
  309. if(!preg_match($AllBots, $row['agent'])) { // && $trash == false A voir exlus aussi les "bad user agent"
  310. //--------------------- extraction mots clés -------------
  311. $url=parse_url($site);
  312. $ref=$referer["host"];
  313. if($ref<>$url["host"]){
  314. //Pour les adwords l'url est trouvée car dans visiteur.php est ajouté au referer $Referer = urldecode($Url_syndication[0]). '?googlesyndication=1' ou '&googlesyndication=1';
  315. $test_keword[] = array($ref,MotsCles($row[referer],$ref));
  316. }
  317. //--------------- ext referer et nb visite ---------------
  318. if ($row['referer']) { //
  319. $Tab_referer[] = $referer['host'];
  320. } else { //Visiteurs avec user agent et referer vide modif 31-08-2009
  321. $Tab_referer[] = "Unknown or direct";
  322. $nb_unknow = $nb_unknow + 1;
  323. }
  324. }
  325. }
  326. //Attention array_unique ne garde que les clés différentes mais garde la chronologie --> faire usort($Tab_referer, "CompareValeurs"); apr?s
  327. $Tab_referer_unique = @array_unique($Tab_referer);
  328. @usort($Tab_referer_unique, "CompareValeurs");
  329. unset($Tab_aff_ref);
  330. for($i=0;$i<count($Tab_referer_unique);$i++){
  331. $result_agent = mysql_query("select agent from ".TABLE_VISITEUR." where referer like '%".$Tab_referer_unique[$i]."%' and agent NOT REGEXP '".$AllBots."' and date like '%$mois'");
  332. $test_agent = mysql_fetch_array($result_agent);
  333. //if(!preg_match($AllBots, $test_agent['agent'])) n'est pas nécessaire mais certainement plus rapide comme ça
  334. if(!preg_match($AllBots, $test_agent['agent'])) { // && $trash == false A voir exlus aussi les "bad user agent" modif 31-08-2009
  335. if (trim($Tab_referer_unique[$i])<>'') {
  336. // compte le nombre de visiteurs par referant
  337. if ( strstr(trim($Tab_referer_unique[$i]), 'google') ) {
  338. $result = mysql_query("select count(*) as somme from ".TABLE_VISITEUR." where referer like '%".$Tab_referer_unique[$i]."%' and agent NOT REGEXP '".$AllBots."' and date like '%$mois'");
  339. } else {
  340. $result = mysql_query("select count(*) as somme from ".TABLE_VISITEUR." where referer like '%".$Tab_referer_unique[$i]."%' and agent NOT REGEXP '".$AllBots."' and referer not like '%source=web%' and referer not like '%source=hp%' and date like '%$mois'");
  341. }
  342. if (!$result) {
  343. echo 'Impossible d\'exécuter la requ?te : ' . mysql_error();
  344. exit;
  345. }
  346. $row_nb_visites=mysql_fetch_row($result);
  347. //------------------------------------------
  348. //tab mots clé/referant
  349. for($i2=0;$i2<count($test_keword);$i2++){
  350. if(strstr($test_keword[$i2][0],$Tab_referer_unique[$i])) {
  351. $referer_kew[$i] .= $test_keword[$i2][1].' ';
  352. }
  353. }
  354. //------------------------------------------
  355. if ($row_nb_visites[0] == 0){ //si = 0 => referer vide (donc result mysql vide) user agent et referer vide modif 31-08-2009
  356. $row_nb_visites[0] = $nb_unknow;
  357. }
  358. $Tab_aff_ref[] = array($row_nb_visites[0], $Tab_referer_unique[$i],$referer_kew[$i]); //dans ce sens car on trie sur nb visites
  359. }
  360. }
  361. }
  362. //--------------------------------------------------
  363. // Mise en forme mots clés googlesyndication et Affichage
  364. @array_multisort($Tab_aff_ref,SORT_DESC);
  365. for($i=0;$i<count($Tab_aff_ref);$i++){
  366. $Mots_by_referer = str_replace('] [', ']+-+[', $Tab_aff_ref[$i][2]);
  367. $Mots_by_referer = str_replace('] [', ']+-+[', $Mots_by_referer); // car certains comportent 2 espaces --> A voir o? ils sont mis ou supprimmer espaces multiples
  368. $Mots_by_referer = str_replace('] [', ']+-+[', $Mots_by_referer);// car certains comportent 3 espaces --> A voir o? ils sont mis
  369. $Mots_by_referer = strtolower($Mots_by_referer); // Tout en minuscule
  370. unset($Tab_motcles);
  371. $Tab_motcles = explode('+-+',$Mots_by_referer);
  372. for($j=0;$j<count($Tab_motcles);$j++){
  373. $Tab_motcles[$j] = trim($Tab_motcles[$j]);
  374. }
  375. unset($Tab_motcles_unique);
  376. $Tab_motcles_unique = array_unique($Tab_motcles);
  377. //----------------------
  378. unset($tab_keywords);
  379. for($j=0;$j<count($Tab_motcles_unique);$j++){
  380. if (trim($Tab_motcles_unique[$j])) {
  381. $tab_keywords[] = array($Tab_motcles_unique[$j], substr_count($Mots_by_referer, $Tab_motcles_unique[$j]));
  382. }
  383. }
  384. // Obtient une liste de colonnes
  385. unset($Mot);
  386. unset($Nb);
  387. if ($tab_keywords) {
  388. foreach ($tab_keywords as $key => $row) {
  389. $Mot[$key] = $row[0];
  390. $Nb[$key] = $row[1];
  391. }
  392. }
  393. // Trie les données par volume croissant
  394. // Ajoute $tab_keywords en tant que dernier param?tre, pour trier par la clé commune
  395. @array_multisort($Nb, SORT_DESC, $tab_keywords);
  396. //---------------------------------------------------------------
  397. //Affichage
  398. $lenmax=35;
  399. if (strlen($Tab_aff_ref[$i][1])>$lenmax) {
  400. $chaine1=substr($Tab_aff_ref[$i][1], 0, $lenmax);
  401. $chaine2=substr($Tab_aff_ref[$i][1], $lenmax);
  402. $Tab_aff_ref[$i][1] = $chaine1."<br>".$chaine2;
  403. }
  404. //-----------------------------
  405. //Pour affichage googlesyndication
  406. $show_cumul_page .= "<tr><td valign=top class=\"TDstatsin\">".$Tab_aff_ref[$i][1]."</td>
  407. <td nowrap class=\"TDstatsin\">";
  408. if (count($Tab_motcles_unique)>1) {
  409. $show_cumul_page .= "<span> Différents: ". count($Tab_motcles_unique)."</span>";
  410. }
  411. for($j=0;$j<count($tab_keywords);$j++){ //Affiche les phrases clés
  412. if (strstr($tab_keywords[$j][0],'googlesyndication=1')) {
  413. $tab_keywords[$j][0] = str_replace('?googlesyndication=1', '<font color=#666666>&nbsp;&nbsp;'.utf8_encode($MSG_ADWORDS_CONTENT_NETWORK).'</font><br>', $tab_keywords[$j][0]);
  414. $tab_keywords[$j][0] = str_replace(htmlentities('&googlesyndication=1'), '<font color=#666666>&nbsp;&nbsp;'.utf8_encode($MSG_ADWORDS_CONTENT_NETWORK).'</font><br>', $tab_keywords[$j][0]);//ici il faut htmlentities('&googlesyndication=1'), voir si ne serait pas mieux au niveau de config moteur
  415. $tab_keywords[$j][0] = substr(trim($tab_keywords[$j][0]),0,-5); //supp le dernier '<br> '
  416. }
  417. $show_cumul_page .= "<br><span><font color=#990000>".utf8_decode(urldecode($tab_keywords[$j][0]))."</font></span>";
  418. }
  419. $show_cumul_page .= "&nbsp;</td>
  420. <td nowrap class=\"TDstatsin\">";
  421. $show_cumul_page .= "<span> Total: ".$Tab_aff_ref[$i][0]."</span>";
  422. for($j=0;$j<count($tab_keywords);$j++){ //affiche le nombre de visite pour chaque mot ou référant
  423. $show_cumul_page .= "<br><span><font color=#990000>".utf8_decode(urldecode($tab_keywords[$j][1]))."</font></span>";
  424. }
  425. $show_cumul_page .= "&nbsp;</td></tr>";
  426. //----------------------------
  427. }
  428. //--------------------------------------------------
  429. unset($Tab_referer);
  430. unset($Tab_referer_unique);
  431. unset($row_nb_visites);
  432. unset($Tab_aff_ref);
  433. $show_cumul_page .= '
  434. </table><!-- Rows END --></td></tr><tr>
  435. </tr><!-- no footer --></table><!-- Data END --></td></tr></table><br>' ;
  436. } // End if ($display_keywords ) {
  437. //------------------------ Affichage pages visités --------------------------------------------------------
  438. if ($display_page_view) {
  439. if ($mois==""){
  440. $mois = date('m/Y',strtotime($UTC." hours", strtotime(date("Y-m-d H:i:s"))));
  441. }
  442. $result=mysql_query("select * from ".TABLE_VISITEUR." v,".TABLE_PAGE." p where date like '%$mois' and v.code=p.code order by heure");
  443. $nb_visite=0;
  444. $heure_premier="";
  445. while($row=mysql_fetch_array($result)){
  446. if($heure_premier==""){
  447. $heure_premier=$row[heure];
  448. }
  449. $nb_visite=$nb_visite+$row[nb_visite]; //Pour calcul %
  450. $heure_dernier=$row[heure];
  451. }
  452. $max_visite=$NbpageVues_HorsBots;
  453. $result=mysql_query("select * from ".TABLE_VISITEUR." v,".TABLE_PAGE." p where v.date like '%$mois' and v.code=p.code order by page");
  454. $row=mysql_fetch_array($result);
  455. $url=$row[page];
  456. $nb_url=0;
  457. $nb_vis=0;
  458. $result=mysql_query("select * from ".TABLE_VISITEUR." v,".TABLE_PAGE." p where v.date like '%$mois' and v.code=p.code order by page");
  459. while($row=mysql_fetch_array($result)){
  460. $page=$row[page];
  461. if(!preg_match($AllBots, $row[agent])) {
  462. //---------------------------------------
  463. $User_Agent=$row[agent];
  464. $trash=false;
  465. for($nb_bad_user_agent=0;$nb_bad_user_agent<count($Matrice_bad_user_agent);$nb_bad_user_agent++){
  466. if ($Matrice_bad_user_agent[$nb_bad_user_agent][0] == $User_Agent && $Matrice_bad_user_agent[$nb_bad_user_agent][2]=='S') {
  467. $trash=true;
  468. }
  469. }
  470. //---------------------------------------
  471. }
  472. if(!preg_match($AllBots, $row[agent]) && $trash==false) {
  473. if($url==$page){
  474. $nb_url=$nb_url+$row[nb_visite];
  475. $nb_vis++;
  476. } else {
  477. $nb=$nb_url*100;
  478. if($max_visite!=0){
  479. $pourcent=bcdiv($nb,$max_visite,2);
  480. }
  481. $page_vue[]= array($url,$nb_vis, $nb_url, $pourcent);
  482. $url=$page;
  483. $nb_url=$row[nb_visite];
  484. $nb_vis=1;
  485. }
  486. }
  487. } // Fin if(!preg_match($AllBots, $row[agent])) {
  488. $nb=$nb_url*100;
  489. if($max_visite!=0){
  490. $pourcent=bcdiv($nb,$max_visite,2);
  491. }
  492. $show_cumul_page .= '
  493. <table align=center cellpadding=1 cellspacing=0 class=TABLEBORDER>
  494. <tr>
  495. <td class="TDstatsin"><!-- Data BEGIN -->
  496. <table cellpadding=5 cellspacing=0 class=TABLEFRAME><!-- header -->
  497. <tr>
  498. <th class=tabletitle>'. $MSG_PAGESVISITES.' ('.$MSG_ROBOTS_EXCLUS.')<br>'.$mois.'</th>
  499. </tr>
  500. <tr>
  501. <td colSpan=2 class="TDstatsin"><!-- Rows BEGIN -->
  502. <table border=1 cellpadding=2 cellspacing=0 class=TABLEDATA>
  503. <tr>
  504. <th valign="top" align="right" class="THstatsin">'. $MSG_TOTAL.' : <br><br></th>
  505. <td valign="top" align="center"class="TDstatsin">'. $NbVisites_HorsBots.'<br></td>
  506. <td valign="top" align="center" class="TDstatsin">'. $NbpageVues_HorsBots.'<br></td>
  507. <td valign="top" align="center" class="TDstatsin">&nbsp;<br></td>
  508. </tr>
  509. <tr>
  510. <th class="THstatsin">'.$MSG_PAGE.'</th>
  511. <th class="THstatsin">'.$MSG_VISITE.'</th>
  512. <th class="THstatsin">'.$MSG_PAGESVISITES.'</th>
  513. <th class="THstatsin">'.$MSG_PAGES_POURCENTAGE.'</th></tr>';
  514. $page_vue[]= array($url,$nb_vis, $nb_url, $pourcent);
  515. @usort($page_vue, "CompareValeurs");
  516. $cpt=0;
  517. while ($page_vue[$cpt][0]<>""){
  518. $show_cumul_page .= "<tr><td class=\"TDstatsin\">".utf8_decode($page_vue[$cpt][0])."</td><td align=center class=\"TDstatsin\">".$page_vue[$cpt][1]."</td><td align=center class=\"TDstatsin\">".$page_vue[$cpt][2]."</td><td align=center class=\"TDstatsin\">".$page_vue[$cpt][3]."%</td></tr>";
  519. $cpt++;
  520. }
  521. $show_cumul_page .= '
  522. </table><!-- Rows END --></td></tr><!-- no footer --></table><!-- Data END --></td></tr></table><BR>
  523. ';
  524. } // End de if ($display_page_view) {
  525. //############################################################################################
  526. //------------ Affichage Origine géographique des viteurs (hors robots) ----------------------
  527. if ($display_org_geo) {
  528. $result=mysql_query("select agent, nb_visite ,domaine from ".TABLE_VISITEUR." where date like '%$mois'");
  529. while($row=mysql_fetch_array($result)){
  530. $Country[] .= $row['domaine'];
  531. }
  532. $Country = @array_unique($Country);
  533. @array_multisort ($Country, SORT_ASC);
  534. //----------------------------------
  535. //Important mise ? 0 des variables
  536. unset($Tab_country_pages_visiteurs);
  537. for($i=0;$i<count($Country);$i++){ //Comment faire autrement
  538. $Nb_visites = 'Nb_'.$Country[$i];
  539. $$Nb_visites = 0;
  540. $Nb_pages_visites = $Country[$i];
  541. $$Nb_pages_visites = 0;
  542. }
  543. //-----------------------------------
  544. $result=mysql_query("select * from ".TABLE_VISITEUR." where date like '%$mois'");
  545. while($row=mysql_fetch_array($result)){
  546. //---------------------------------------
  547. $User_Agent=$row[agent];
  548. $trash=false;
  549. for($nb_bad_user_agent=0;$nb_bad_user_agent<count($Matrice_bad_user_agent);$nb_bad_user_agent++){
  550. if ($Matrice_bad_user_agent[$nb_bad_user_agent][0] == $User_Agent && $Matrice_bad_user_agent[$nb_bad_user_agent][2]=='S') {
  551. $trash=true;
  552. }
  553. }
  554. //---------------------------------------
  555. if(!preg_match($AllBots, $row[agent]) && $trash==false) {
  556. for($i=0;$i<count($Country);$i++){
  557. if($row[domaine]==$Country[$i]) {
  558. $Nb_visites = 'Nb_'.$Country[$i];
  559. $$Nb_visites = $$Nb_visites + 1;
  560. $Nb_pages_visites = $Country[$i];
  561. $$Nb_pages_visites = $$Nb_pages_visites + $row['nb_visite'];
  562. $Tab_country_pages_visiteurs[$i] = array($Country[$i],$$Nb_pages_visites,$$Nb_visites);
  563. }
  564. }
  565. }
  566. }
  567. //--------- Affichage des résultats --------------------------
  568. @usort($Tab_country_pages_visiteurs,"CompareValeurs");
  569. $indice = bcdiv(1,($Tab_country_pages_visiteurs[0][1]/300),2); //proportion en rapport au plus grand nb de pages visités
  570. $show_cumul_page .= '
  571. <table align=center cellpadding=1 cellspacing=0 class=TABLEBORDER>
  572. <tr>
  573. <td class=\"TDstatsin\"><!-- Data BEGIN -->
  574. <table align=center cellpadding=5 cellspacing=0 class=TABLEFRAME><!-- header -->
  575. <tr>
  576. <th class=tabletitle>'.$MSG_DOMAIN_TITRE.' ('.$MSG_ROBOTS_EXCLUS.')</th>
  577. </tr>
  578. <tr>
  579. <td colSpan=2 class=\"TDstatsin\"><!-- Rows BEGIN -->
  580. <table border=1 cellpadding=2 cellspacing=0 class=TABLEDATA>
  581. <tr>
  582. <th class=\"THstatsin\">'.$MSG_DOMAIN.' ('.count($Tab_country_pages_visiteurs).')</th>
  583. <th class=\"THstatsin\">'.$MSG_NB_VISITEURS.'</th>
  584. <th class=\"THstatsin\">'.$MSG_PAGESVISITES.'</th>
  585. </tr>
  586. ';
  587. for($i=0;$i<count($Tab_country_pages_visiteurs);$i++){
  588. if ($Tab_country_pages_visiteurs[$i][0]=='') { $Tab_country_pages_visiteurs[$i][0] = $MSG_ORIGIN_UNKNOWN;}
  589. $show_cumul_page .= "<tr>
  590. <td class=\"TDstatsin\">
  591. <b>".$Tab_country_pages_visiteurs[$i][0]."</b>
  592. </td>
  593. <td align=\"left\" class=\"TDstatsin\">
  594. <img src=\"".$path_allmystats_abs."images/histo-h.gif\" width=\"";
  595. $hauteur=bcmul($Tab_country_pages_visiteurs[$i][2],$indice,2);
  596. $show_cumul_page .= $hauteur . "\" height=\"8\">".$Tab_country_pages_visiteurs[$i][2].
  597. "</td>
  598. <td align=\"left\" class=\"TDstatsin\">
  599. <img src=\"".$path_allmystats_abs."images/histo-h.gif\" width=\"";
  600. $hauteur=bcmul($Tab_country_pages_visiteurs[$i][1],$indice,2);
  601. $show_cumul_page .= $hauteur."\" height=\"8\">".$Tab_country_pages_visiteurs[$i][1].
  602. "</td>";
  603. }
  604. $show_cumul_page .= '
  605. </table><!-- Rows END --></td></tr><!-- no footer --></table><!-- Data END --></td></tr></table><br>
  606. ';
  607. } // End if ($display_org_geo) {
  608. //--------------------------------------------------------------------------
  609. echo $show_cumul_page; // Affichage des tableaux
  610. $result=mysql_query("select * from ".TABLE_VISITEUR." where date like '%$mois'");
  611. $nbr_result=mysql_num_rows($result);
  612. //$AfficheOS=true;
  613. //$AfficheNav=true;
  614. //$AfficheRobots=true;
  615. $dislpay_button_tool_bots = "false"; //Important "false" entre guillemets car affiche le bouton si $dislpay_button_tool_bots = "";
  616. ?>
  617. <table width="90%" border="0" align="center">
  618. <tr>
  619. <td align="center"><?
  620. include_once('tab_os_nav_robots.php'); //Calcul et affichage des tableaux
  621. mysql_close(); ?>
  622. </td>
  623. </tr>
  624. </table>
  625. <?
  626. message($msg , ""); //efface le message Patientez
  627. //--------- Footer -------------------
  628. echo $show_footer ;
  629. //----------------------------------
  630. ########################################## Mise en cache du mois encours actuel ######################################################################################
  631. $mois_actuelle = date('m/Y',strtotime($UTC." hours", strtotime(date("Y-m-d H:i:s"))));
  632. $mois_Visualise = $mois;
  633. $Mois_Annee_visualise = explode("/", $mois_Visualise);
  634. $mois_visualise = $Mois_Annee_visualise[0]; // mois
  635. $annee_visualise = $Mois_Annee_visualise[1]; //année
  636. $Mois_Annee_actuelle = explode("/", $mois_actuelle);
  637. $mois_actuelle = $Mois_Annee_actuelle[0];
  638. $annee_actuelle = $Mois_Annee_actuelle[1];
  639. if ($action_cache_mois_in || isset($archive_encours) ) { //on met en cache
  640. if (!is_dir($path_allmystats."cache")) {
  641. mkdir ($path_allmystats."cache");
  642. }
  643. //--------------------------------------------------------------------------------------
  644. //Ne sert pas pour ici (stats_in) mais est pour l'instant nécessaire pour les pages mises en cache avec cumulpage.php
  645. if (!is_dir($path_allmystats."cache/images")) {
  646. mkdir ($path_allmystats."cache/images");
  647. }
  648. if (!file_exists("cache/images/histo-v_black.gif")) {
  649. copy($path_allmystats."images/histo-v_black.gif", $path_allmystats."cache/images/histo-v_black.gif");
  650. }
  651. if (!file_exists("cache/images/histo-v.gif")) {
  652. copy($path_allmystats."images/histo-v.gif", $path_allmystats."cache/images/histo-v.gif");
  653. }
  654. if (!file_exists("cache/images/histo-vv.gif")) {
  655. copy($path_allmystats."images/histo-vv.gif", $path_allmystats."cache/images/histo-vv.gif");
  656. }
  657. if (!file_exists("cache/images/histo-h.gif")) {
  658. copy($path_allmystats."images/histo-h.gif", $path_allmystats."cache/images/histo-h.gif");
  659. }
  660. //--------------------------------------------------------------------------------------
  661. $Mois_Annee = explode("/", $mois_Visualise);
  662. $format_date_file_name = $Mois_Annee[1].'-'.$Mois_Annee[0];
  663. //$Fnm = $path_allmystats."cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php"; //erreur open_basedir restriction in effect PHP5.2??
  664. //$Fnm = "//".$path_allmystats_abs.$site."_".$format_date_file_name."-".$suffixe.".php"; //erreur open_basedir restriction in effect PHP5.2??
  665. //$Fnm = "stats/allmystats/cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php"; //OK si appelle ? partir de la racine
  666. //$Fnm = "/stats/allmystats/cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php";//erreur open_basedir restriction in effect PHP5.2??
  667. //---------- Pour contourner le pb open_basedir restriction in effect avec fopen ----------------
  668. $nbSlashes = substr_count($_SERVER['SCRIPT_NAME'], '/'); // on compte le nombre total de slashes contenu dans le lien relatif du fichier courant
  669. $nbSlashes --; // on ne compte pas le slash de la racine (placé au début du lien relatif)
  670. $remontee = ''; // on initialise la remontée dans l'arborescence
  671. for($i = 0; $i < $nbSlashes; $i++)
  672. {
  673. $remontee .= '../';
  674. }
  675. //------------------------------------------------------------------------------------------------
  676. //Supprime 1er "/" de $path_allmystats_abs Important si $remontee = ""
  677. substr('abcdef', 1);
  678. $path_allmystats_rel = substr($path_allmystats_abs, 1);
  679. $Fnm = $remontee.$path_allmystats_rel."cache/stats_".$site."_".$format_date_file_name."-".$suffixe.".php";
  680. if (!$inF = @fopen($Fnm,"w")){
  681. echo "Erreur create file<br />";
  682. }
  683. //$inF = fopen($Fnm,"w");
  684. if ($html_body) {
  685. $page_html =
  686. '<?
  687. if( ($user_login!=$_SESSION["userlogin"] || $passwd!=$_SESSION["userpass"]) && $public==false) {
  688. echo "<br><br><center><strong>Vous n\'?tes pas autorisé ? visiter cette page</center></strong><br>";
  689. exit;
  690. }
  691. ?>
  692. <html>
  693. <head>
  694. <title>AllMyStats - '. $site.' - '.$format_date_file_name.'</title>
  695. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  696. <link rel="stylesheet" type="text/css" href="../stylesheet_stats_in.css">
  697. </head>
  698. <body><table width="100%" border="0" align="center">
  699. <tr>
  700. <td align="center"><big><strong>Statistiques site: '.$site." - Mois: ".$mois_Visualise.'</strong></big><br><br></td>
  701. </tr>
  702. <tr>
  703. <td align="center">'.$show_cumul_page . $show_page_os_nav_robots.$show_footer.'</td>
  704. </tr>
  705. </table></body></html>';
  706. } else {
  707. $page_html =
  708. '<?
  709. if( ($user_login!=$_SESSION["userlogin"] || $passwd!=$_SESSION["userpass"]) && $public==false) {
  710. echo "<br><br><center><strong>Vous n\'?tes pas autorisé ? visiter cette page</center></strong><br>";
  711. exit;
  712. }
  713. ?>
  714. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  715. <link rel="stylesheet" type="text/css" href="../stylesheet_stats_in.css">
  716. <table width="100%" border="0" align="center">
  717. <tr>
  718. <td align="center"><big><strong>Statistiques site: '.$site." - Mois: ".$mois_Visualise.'</strong></big><br><br></td>
  719. </tr>
  720. <tr>
  721. <td align="center">'.$show_cumul_page . $show_page_os_nav_robots.$show_footer.'</td>
  722. </tr>
  723. </table>';
  724. }
  725. if(!@fwrite($inF,$page_html)){
  726. echo "Erreur write file<br />";
  727. }
  728. //fwrite($inF,$page_html);
  729. if(!@fclose($inF)){
  730. echo "Erreur close file";
  731. }
  732. //fclose($inF);
  733. }
  734. } // End if ($action_cache_mois_in) {
  735. //-------------------------------------------------------------------------------------------
  736. //#########################################"## Functions ######################################################
  737. //Il faut la fonction CompareValeurs($val1, $val2) qui ne se trouve normalement seulement dans index_frame.php
  738. function CompareValeurs($val1, $val2) {
  739. if ($val2[1] == $val1[1])
  740. return(strcmp($val1[0],$val2[0]));
  741. else
  742. return($val2[1] - $val1[1]);
  743. }
  744. function msg_temporaire ($temp_msg) {
  745. //ob_flush();
  746. flush();
  747. ?>
  748. <p align="center" ID="cache"><strong><big><font color="#FF0000"><?php echo $temp_msg;?></font></big></strong></p>
  749. <script type="text/javascript">
  750. // Le message d'attente est masqué par défaut au cas ou java script
  751. // serait désactivé sur le navigateur client donc on l'affiche :
  752. document.getElementById("cache" ).style.visibility = "visible";
  753. </script>
  754. <?
  755. //ob_flush();
  756. flush();
  757. }
  758. function message($msg, $title){
  759. ?>
  760. <script type="text/javascript">
  761. document.getElementById("cache" ).style.visibility = "hidden";
  762. </script>
  763. <?php
  764. //flush();
  765. }
  766. //-------------------------------------------------------------------------------------------
  767. //TODO rep functions car existe aussi dans cumulpage.php, stats_in.php, histomaois.php
  768. /**
  769. * Fonction retournant le nombre de jours dans un mois.
  770. * @param integer $month Mois de 1 ? 12
  771. * @param integer $year Année
  772. * @return integer Nombre de jours
  773. */
  774. function maxDaysInMonth($month, $year)
  775. {
  776. $days = cal_days_in_month(CAL_GREGORIAN, $month, $year);
  777. return $days;
  778. }
  779. /**
  780. *
  781. * Gets the first weekday of that month and year
  782. *
  783. * @param int The day of the week (0 = sunday, 1 = monday ... , 6 = saturday)
  784. * @param int The month (if false use the current month)
  785. * @param int The year (if false use the current year)
  786. *
  787. * @return int The timestamp of the first day of that month
  788. *
  789. **/
  790. function get_first_day($day_number=1, $month=false, $year=false)
  791. {
  792. $month = ($month === false) ? strftime("%m"): $month;
  793. $year = ($year === false) ? strftime("%Y"): $year;
  794. $first_day = 1 + ((7+$day_number - strftime("%w", mktime(0,0,0,$month, 1, $year)))%7);
  795. return mktime(0,0,0,$month, $first_day, $year);
  796. }
  797. //##############################################################################################################
  798. ?>