Guest User

Untitled

a guest
Jul 15th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.29 KB | None | 0 0
  1. <?php
  2. /* Copyright 2008 by zerophr34k.com */
  3. function xml2array($text) {
  4. $reg_exp = '/<(.*?)>(.*?)<\/\\1>/s';
  5. preg_match_all($reg_exp, $text, $match);
  6. foreach ($match[1] as $key=>$val) {
  7. if (preg_match($reg_exp, $match[2][$key])) {
  8. $array[$val][] = xml2array($match[2][$key]);
  9. } else {
  10. $array[$val] = $match[2][$key];
  11. }
  12. }
  13. return $array;
  14. }
  15.  
  16. class StatsXML {
  17. // ///// Variables /////
  18. var $info;
  19. // ///// Constructor /////
  20. function StatsXML($file) {
  21. $xml = @file_get_contents($file);
  22. // ATTENTION: DON'T modify the following 2 rows!
  23. $bad = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
  24. <?xml-stylesheet type=\"text/xsl\" href=\"server_stats.xsl\"?>";
  25. $good = "";
  26. $xml = str_replace($bad, $good, $xml);
  27. $this->info = xml2array($xml);
  28. }
  29. // ///// Functions /////
  30. function getAll() {
  31. return $this->info;
  32. }
  33.  
  34. function getLatency() {
  35. return $this->info['serverpage'][0]['status'][0]['avglat'];
  36. }
  37. function getGMcount() {
  38. return $this->info['serverpage'][0]['status'][0]['gmcount'];
  39. }
  40. function getOnlinePlayers() {
  41. return $this->info['serverpage'][0]['status'][0]['oplayers'];
  42. }
  43. function getQplayers() {
  44. return $this->info['serverpage'][0]['status'][0]['qplayers'];
  45. }
  46. function getUptime() {
  47. return $this->info['serverpage'][0]['status'][0]['uptime'];
  48. }
  49.  
  50. function getHorde() {
  51. return $this->info['serverpage'][0]['status'][0]['horde'];
  52. }
  53.  
  54. function getAlliance() {
  55. return $this->info['serverpage'][0]['status'][0]['alliance'];
  56. }
  57.  
  58. function getGMs() {
  59. return $this->info['serverpage'][0]['status'][0]['gmcount'];
  60. }
  61.  
  62. function getConPeak() {
  63. return $this->info['serverpage'][0]['status'][0]['peakcount'];
  64. }
  65. function getAccCon() {
  66. return $this->info['serverpage'][0]['status'][0]['acceptedconns'];
  67. }
  68. function getServerVersion() {
  69. return $this->info['serverpage'][0]['status'][0]['platform'];
  70. }
  71.  
  72. function getPlayersArray() {
  73. if ( is_array( $this->info['serverpage'][0]['sessions'][0]['plr'] ) )
  74. return $this->info['serverpage'][0]['sessions'][0]['plr'];
  75. return array();
  76. }
  77. function getGMsArray() {
  78. if ( is_array( $this->info['serverpage'][0]['gms'][0]['gmplr'] ) )
  79. return $this->info['serverpage'][0]['gms'][0]['gmplr'];
  80. return array();
  81. }
  82. }
  83. ?>
Add Comment
Please, Sign In to add comment