stats.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. if (!defined('N')) {
  3. echo('You probably meant <a href="'.preg_replace('/\.php$/','',$_SERVER['REQUEST_URI']).'">this</a>.');
  4. exit(0);
  5. }
  6. $lc=localeconv();
  7. require '../lib/fnum.php';
  8. require '../lib/realfloat.php';// had to resort to this because php 7.3 has a bug: when echoing a float, it uses the decimal separator of the locale that was set with setlocale, making a mess when the separator is different than "." with stuff expecting it to be "."
  9. require '../lib/supplangs.php';
  10. echo('</nav>
  11. <div class="scrwide">
  12. <div class="scrwidein">
  13. <section class="sectcontm">
  14. <h3>'._('Statistics for the last 30 days').'</h3>
  15. <script language="JavaScript">
  16. </script>
  17. '.N);
  18. function sp($num,$sing,$plur) {
  19. if ($num==1)
  20. return($sing);
  21. else
  22. return($plur);
  23. }
  24. $link=mysqli_connect($conf['db_host'],$conf['db_user_name'],$conf['db_user_password'],$conf['db_name'],$conf['db_port'],$conf['db_socket']) or muorimeglio(_('Couldn’t connect to database: ').mysqli_connect_error().' ['.mysqli_connect_errno().']',false);
  25. mysqli_set_charset($link,'utf8mb4');
  26. $now=time();
  27. $tdstart=gmmktime(0,0,0,gmdate('n',$now),gmdate('j',$now),gmdate('Y',$now));
  28. $limit=$tdstart-(30*24*60*60);
  29. $res=mysqli_query($link,'SELECT MAX(Visits) AS MaxVisits, MAX(Hits) AS MaxHits FROM ZStats WHERE TS >= '.$limit) or muorimeglio(__LINE__.': '.mysqli_error($link),true);
  30. $row=mysqli_fetch_assoc($res);
  31. $maxvisits=$row['MaxVisits'];
  32. $maxhits=$row['MaxHits'];
  33. $res=mysqli_query($link,'SELECT * FROM ZStats WHERE TS >= '.$limit.' ORDER BY TS DESC') or muorimeglio(__LINE__.': '.mysqli_error($link),true);
  34. $hpmap=array(
  35. 'home'=>_('Guide'),
  36. 'instances'=>_('Instances'),
  37. 'users'=>_('Users'),
  38. 'links'=>_('Links'),
  39. 'about'=>_('About'),
  40. 'stats'=>_('Statistics'),
  41. 'contribute'=>_('Contribute'),
  42. '404'=>'404'
  43. );
  44. while ($row=mysqli_fetch_assoc($res)) {
  45. $hl=explode(';',$row['HitsLang']);
  46. $buf=array();
  47. foreach($hl as $key=>$val) {
  48. $val=explode(':',$val);
  49. if (array_key_exists($val[0],$supplangs))// needed when you (temporarily) subtract a lang code from $supplangs in lib/supplangs.php
  50. $buf[$supplangs[$val[0]]['trname']]=$val[1];
  51. }
  52. arsort($buf);
  53. $hl='';
  54. foreach($buf as $key=>$val) $hl.=$key.': '.fnum($val,$lc,0).'; ';
  55. $hl=_('Hits per language').': '.substr($hl,0,-2);
  56. $hp=explode(';',$row['HitsPage']);
  57. $buf=array();
  58. foreach($hp as $key=>$val) {
  59. $val=explode(':',$val);
  60. $buf[$hpmap[$val[0]]]=$val[1];
  61. }
  62. arsort($buf);
  63. $hp='';
  64. foreach($buf as $key=>$val) $hp.=$key.': '.fnum($val,$lc,0).'; ';
  65. $hp=_('Hits per page').': '.substr($hp,0,-2);
  66. echo('<div class="info1st">'.gmdate('d/m/Y',$row['TS']).': '.fnum($row['Visits'],$lc,0).' <span class="visitslab">'.sp($row['Visits'],_('visit'),_('visits')).'</span>, '.fnum($row['Hits'],$lc,0).' <span class="hitslab">'.sp($row['Hits'],_('hit'),_('hits')).'</span></div>'.N);
  67. echo('<div class="info">'.$hl.'</div>'.N);
  68. echo('<div class="info">'.$hp.'</div>'.N);
  69. echo('<div class="visits" style="width:'.rf($row['Visits']*100/$maxvisits).'%"></div>'.N);
  70. echo('<div class="hits" style="width:'.rf($row['Hits']*100/$maxhits).'%"></div>'.N);
  71. }
  72. mysqli_close($link);
  73. echo('</section>
  74. </div>
  75. </div>'.N);
  76. ?>