Advertisement
Guest User

connext.php

a guest
Aug 14th, 2019
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.26 KB | None | 0 0
  1. <?php
  2. require_once('core.php');
  3. global $db;
  4. $json = array();
  5. $servers_data = getArray("SELECT id, players_online, votes, uptime FROM php_servers ORDER BY votes DESC, status DESC, players_online DESC, name ASC");
  6. $i = 0;
  7. if ($servers_data) {
  8. foreach($servers_data as $key => $data)
  9. {
  10. $i += 1;
  11. // Check if .json file exists
  12. if (file_exists(dirname(__FILE__).'/serversData/'.$data['id'].'.json')) {
  13. // Open & Decode json file & its data
  14. $file = file_get_contents(dirname(__FILE__).'/serversData/'.$data['id'].'.json');
  15. $json = json_decode($file, true);
  16. // Push New Data to "Rows" array
  17. array_push(
  18. $json['rows'],
  19. array(
  20. 'c' =>
  21. array(
  22. array('v' => date('M d'), 'f' => null),
  23. array('v' => $data['votes'], 'f' => null),
  24. array('v' => $i, 'f' => null),
  25. array('v' => $data['players_online'], 'f' => null),
  26. array('v' => round($data['uptime']), 'f' => null)
  27. )
  28. )
  29. );
  30. // Save New formated .json file
  31. if ($json) {
  32. file_put_contents(dirname(__FILE__).'/serversData/'.$data['id'].'.json', json_encode($json));
  33. } else {
  34. echo 'Add Servers First to query statistics!';
  35. }
  36.  
  37. } else {
  38. // Create Data File if doesn't exist
  39. $oldjson = dirname(__FILE__).'/cron/DO_NOT_DELETE.json';
  40. $newjson = dirname(__FILE__).'/serversData/'.$data['id'].'.json';
  41. copy($oldjson, $newjson);
  42.  
  43. // Open & Decode json file & its data
  44. $file = file_get_contents(dirname(__FILE__).'/serversData/'.$data['id'].'.json');
  45. $json = json_decode($file, true);
  46.  
  47. // Push New Data to "Rows" array
  48. array_push(
  49. $json['rows'],
  50. array(
  51. 'c' =>
  52. array(
  53. array('v' => date('M d'), 'f' => null),
  54. array('v' => $data['votes'], 'f' => null),
  55. array('v' => $i, 'f' => null),
  56. array('v' => $data['players_online'], 'f' => null),
  57. array('v' => round($data['uptime']), 'f' => null)
  58. )
  59. )
  60. );
  61. // Save New formated .json file
  62. if ($json) {
  63. file_put_contents(dirname(__FILE__).'/serversData/'.$data['id'].'.json', json_encode($json));
  64. } else {
  65. echo 'Add Servers First to query statistics!';
  66. }
  67. }
  68. }
  69. echo "Executed successfully!";
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement