Oppaitime's version of Gazelle
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

users.php 8.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?
  2. if (!list($Countries, $Rank, $CountryUsers, $CountryMax, $CountryMin, $LogIncrements) = $Cache->get_value('geodistribution')) {
  3. include_once(SERVER_ROOT.'/classes/charts.class.php');
  4. $DB->query('
  5. SELECT Code, Users
  6. FROM users_geodistribution');
  7. $Data = $DB->to_array();
  8. $Count = $DB->record_count() - 1;
  9. $CountryMinThreshold = Min($Count, 30);
  10. $CountryMax = ceil(log(Max(1, $Data[0][1])) / log(2)) + 1;
  11. $CountryMin = floor(log(Max(1, $Data[$CountryMinThreshold][1])) / log(2));
  12. $CountryRegions = array('RS' => array('RS-KM')); // Count Kosovo as Serbia as it doesn't have a TLD
  13. foreach ($Data as $Key => $Item) {
  14. list($Country, $UserCount) = $Item;
  15. $Countries[] = $Country;
  16. $CountryUsers[] = number_format((((log($UserCount) / log(2)) - $CountryMin) / ($CountryMax - $CountryMin)) * 100, 2);
  17. $Rank[] = round((1 - ($Key / $Count)) * 100);
  18. if (isset($CountryRegions[$Country])) {
  19. foreach ($CountryRegions[$Country] as $Region) {
  20. $Countries[] = $Region;
  21. $Rank[] = end($Rank);
  22. }
  23. }
  24. }
  25. reset($Rank);
  26. for ($i = $CountryMin; $i <= $CountryMax; $i++) {
  27. $LogIncrements[] = Format::human_format(pow(2, $i));
  28. }
  29. $Cache->cache_value('geodistribution', array($Countries, $Rank, $CountryUsers, $CountryMax, $CountryMin, $LogIncrements), 0);
  30. }
  31. if (!$ClassDistribution = $Cache->get_value('class_distribution')) {
  32. include_once(SERVER_ROOT.'/classes/charts.class.php');
  33. $DB->query("
  34. SELECT p.Name, COUNT(m.ID) AS Users
  35. FROM users_main AS m
  36. JOIN permissions AS p ON m.PermissionID = p.ID
  37. WHERE m.Enabled = '1'
  38. GROUP BY p.Name
  39. ORDER BY Users DESC");
  40. $ClassSizes = $DB->to_array();
  41. $Pie = new PIE_CHART(750, 400, array('Other' => 1, 'Percentage' => 1));
  42. foreach ($ClassSizes as $ClassSize) {
  43. list($Label, $Users) = $ClassSize;
  44. $Pie->add($Label, $Users);
  45. }
  46. $Pie->transparent();
  47. $Pie->color('FF33CC');
  48. $Pie->generate();
  49. $ClassDistribution = $Pie->url();
  50. $Cache->cache_value('class_distribution', $ClassDistribution, 3600 * 24 * 14);
  51. }
  52. if (!$PlatformDistribution = $Cache->get_value('platform_distribution')) {
  53. include_once(SERVER_ROOT.'/classes/charts.class.php');
  54. $DB->query("
  55. SELECT OperatingSystem, COUNT(UserID) AS Users
  56. FROM users_sessions
  57. GROUP BY OperatingSystem
  58. ORDER BY Users DESC");
  59. $Platforms = $DB->to_array();
  60. $Pie = new PIE_CHART(750, 400, array('Other' => 1, 'Percentage' => 1));
  61. foreach ($Platforms as $Platform) {
  62. list($Label, $Users) = $Platform;
  63. $Pie->add($Label, $Users);
  64. }
  65. $Pie->transparent();
  66. $Pie->color('8A00B8');
  67. $Pie->generate();
  68. $PlatformDistribution = $Pie->url();
  69. $Cache->cache_value('platform_distribution', $PlatformDistribution, 3600 * 24 * 14);
  70. }
  71. if (!$BrowserDistribution = $Cache->get_value('browser_distribution')) {
  72. include_once(SERVER_ROOT.'/classes/charts.class.php');
  73. $DB->query("
  74. SELECT Browser, COUNT(UserID) AS Users
  75. FROM users_sessions
  76. GROUP BY Browser
  77. ORDER BY Users DESC");
  78. $Browsers = $DB->to_array();
  79. $Pie = new PIE_CHART(750, 400, array('Other' => 1, 'Percentage' => 1));
  80. foreach ($Browsers as $Browser) {
  81. list($Label, $Users) = $Browser;
  82. $Pie->add($Label, $Users);
  83. }
  84. $Pie->transparent();
  85. $Pie->color('008AB8');
  86. $Pie->generate();
  87. $BrowserDistribution = $Pie->url();
  88. $Cache->cache_value('browser_distribution', $BrowserDistribution, 3600 * 24 * 14);
  89. }
  90. //Timeline generation
  91. if (!list($Labels, $InFlow, $OutFlow, $Max) = $Cache->get_value('users_timeline')) {
  92. $DB->query("
  93. SELECT DATE_FORMAT(JoinDate,'%b %y') AS Month, COUNT(UserID)
  94. FROM users_info
  95. GROUP BY Month
  96. ORDER BY JoinDate DESC");
  97. $TimelineIn = array_reverse($DB->to_array());
  98. $DB->query("
  99. SELECT DATE_FORMAT(BanDate,'%b %y') AS Month, COUNT(UserID)
  100. FROM users_info
  101. WHERE BanDate > 0
  102. GROUP BY Month
  103. ORDER BY BanDate DESC");
  104. $TimelineOut = array_reverse($DB->to_array());
  105. foreach ($TimelineIn as $Month) {
  106. list($Label, $Amount) = $Month;
  107. if ($Amount > $Max) {
  108. $Max = $Amount;
  109. }
  110. }
  111. foreach ($TimelineOut as $Month) {
  112. list($Label, $Amount) = $Month;
  113. if ($Amount > $Max) {
  114. $Max = $Amount;
  115. }
  116. }
  117. $Labels = array();
  118. foreach ($TimelineIn as $Month) {
  119. list($Label, $Amount) = $Month;
  120. $Labels[] = $Label;
  121. $InFlow[] = number_format(($Amount / $Max) * 100, 4);
  122. }
  123. foreach ($TimelineOut as $Month) {
  124. list($Label, $Amount) = $Month;
  125. $OutFlow[] = number_format(($Amount / $Max) * 100, 4);
  126. }
  127. $Cache->cache_value('users_timeline', array($Labels, $InFlow, $OutFlow, $Max), mktime(0, 0, 0, date('n') + 1, 2)); //Tested: fine for Dec -> Jan
  128. }
  129. //End timeline generation
  130. View::show_header('Detailed User Statistics');
  131. ?>
  132. <h3 id="User_Flow"><a href="#User_Flow">User Flow</a></h3>
  133. <div class="box pad center">
  134. <img src="<?=str_replace(['+','%26%2339%3B'],['%2B','%27'],ImageTools::process('https://chart.googleapis.com/chart?cht=lc&chs=880x160&chco=000D99,99000D&chg=0,-1,1,1&chxt=y,x&chxs=0,h&chxl=1:|'.implode('|', $Labels).'&chxr=0,0,'.$Max.'&chd=t:'.implode(',', $InFlow).'|'.implode(',', $OutFlow).'&chls=2,4,0&chdl=New+Registrations|Disabled+Users&chf=bg,s,FFFFFF00&.png'))?>" alt="User Flow Chart" />
  135. </div>
  136. <br />
  137. <h3 id="User_Classes"><a href="#User_Classes">User Classes</a></h3>
  138. <div class="box pad center">
  139. <img src="<?=preg_replace('/\+/','%2B',ImageTools::process($ClassDistribution.'&.png'))?>" alt="User Class Distribution" />
  140. </div>
  141. <br />
  142. <h3 id="User_Platforms"><a href="#User_Platforms">User Platforms</a></h3>
  143. <div class="box pad center">
  144. <img src="<?=preg_replace('/\+/','%2B',ImageTools::process($PlatformDistribution.'&.png'))?>" alt="User Platform Distribution" />
  145. </div>
  146. <br />
  147. <h3 id="User_Browsers"><a href="#User_Browsers">User Browsers</a></h3>
  148. <div class="box pad center">
  149. <img src="<?=preg_replace('/\+/','%2B',ImageTools::process($BrowserDistribution.'&.png'))?>" alt="User Browsers Market Share" />
  150. </div>
  151. <br />
  152. <h3 id="Geo_Dist_Map"><a href="#Geo_Dist_Map">Geographical Distribution Map</a></h3>
  153. <div class="box center">
  154. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-55,-180,73,180&amp;chs=440x220&amp;chd=t:'.implode(',', $Rank).'&amp;chco=FFFFFF,EDEDED,1F0066&amp;chld='.implode('|', $Countries).'&amp;chf=bg,s,CCD6FF&.png')?>" alt="Geographical Distribution Map - Worldwide" />
  155. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=37,-26,65,67&amp;chs=440x220&amp;chs=440x220&amp;chd=t:'.implode(',', $Rank).'&amp;chco=FFFFFF,EDEDED,1F0066&amp;chld='.implode('|', $Countries).'&amp;chf=bg,s,CCD6FF&.png')?>" alt="Geographical Distribution Map - Europe" />
  156. <br />
  157. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-46,-132,24,21.5&amp;chs=440x220&amp;chd=t:'.implode(',', $Rank).'&amp;chco=FFFFFF,EDEDED,1F0066&amp;chld='.implode('|', $Countries).'&amp;chf=bg,s,CCD6FF&.png')?>" alt="Geographical Distribution Map - South America" />
  158. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-11,22,50,160&amp;chs=440x220&amp;chd=t:'.implode(',', $Rank).'&amp;chco=FFFFFF,EDEDED,1F0066&amp;chld='.implode('|', $Countries).'&amp;chf=bg,s,CCD6FF&.png')?>" alt="Geographical Distribution Map - Asia" />
  159. <br />
  160. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=-36,-57,37,100&amp;chs=440x220&amp;chd=t:'.implode(',', $Rank).'&amp;chco=FFFFFF,EDEDED,1F0066&amp;chld='.implode('|', $Countries).'&amp;chf=bg,s,CCD6FF&.png')?>" alt="Geographical Distribution Map - Africa" />
  161. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?cht=map:fixed=14.8,15,45,86&amp;chs=440x220&amp;chd=t:'.implode(',', $Rank).'&amp;chco=FFFFFF,EDEDED,1F0066&amp;chld='.implode('|', $Countries).'&amp;chf=bg,s,CCD6FF&.png')?>" alt="Geographical Distribution Map - Middle East" />
  162. <br />
  163. <img src="<?=ImageTools::process('https://chart.googleapis.com/chart?chxt=y,x&amp;chg=0,-1,1,1&amp;chxs=0,h&amp;cht=bvs&amp;chco=76A4FB&amp;chs=880x300&amp;chd=t:'.implode(',', array_slice($CountryUsers, 0, 31)).'&amp;chxl=1:|'.implode('|', array_slice($Countries, 0, 31)).'|0:|'.implode('|', $LogIncrements).'&amp;chf=bg,s,FFFFFF00&.png')?>" alt="Number of users by country" />
  164. </div>
  165. <?
  166. View::show_footer();