graph.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. if (!DEFINED('EGP'))
  3. exit(header('Refresh: 0; URL=http://' . $_SERVER['SERVER_NAME'] . '/404'));
  4. if ($go) {
  5. $sql->query('SELECT `key` FROM `graph` WHERE `server`="' . $id . '" LIMIT 1');
  6. $graph = $sql->get();
  7. $nmch = 'server_graph_full_' . $id;
  8. $time = isset($url['time']) ? $url['time'] : 'day';
  9. if (!in_array($time, array('day', 'week', 'month')))
  10. $time = 'day';
  11. // Выхлоп кеш графика
  12. if ($mcache->get($nmch) and file_exists(TEMP . (md5($graph['key'] . 'full_' . $time)) . '.png')) {
  13. header('Content-type: image/png');
  14. exit(file_get_contents(TEMP . (md5($graph['key'] . 'full_' . $time)) . '.png'));
  15. }
  16. include(LIB . 'games/graph/pData.php');
  17. include(LIB . 'games/graph/pDraw.php');
  18. include(LIB . 'games/graph/pImage.php');
  19. include(LIB . 'games/graph.php');
  20. graph::full($id, $server['slots_start'], $graph['key'], $time);
  21. $mcache->set($nmch, true, false, 300);
  22. header('Content-type: image/png');
  23. exit(file_get_contents(TEMP . (md5($graph['key'] . 'full_' . $time)) . '.png'));
  24. }
  25. $html->nav($server['address'], $cfg['http'] . 'servers/id/' . $id);
  26. $html->nav('Графики');
  27. if ($mcache->get('server_graph_' . $id) != '')
  28. $html->arr['main'] = $mcache->get('server_graph_' . $id);
  29. else {
  30. $sql->query('SELECT `key` FROM `graph` WHERE `server`="' . $id . '" LIMIT 1');
  31. // Если отсутствует ключ, создать
  32. if (!$sql->num()) {
  33. // Генерация ключа
  34. $key = md5($id . sys::key('graph'));
  35. $sql->query('INSERT INTO `graph` set `server`="' . $id . '", `key`="' . $key . '", `time`="0"');
  36. } else {
  37. $graph = $sql->get();
  38. $key = $graph['key'];
  39. }
  40. $html->get('graph', 'sections/servers/games');
  41. $html->set('id', $id);
  42. $html->set('key', $key);
  43. $html->set('address', $server['address']);
  44. $html->set('_img', '[img]');
  45. $html->pack('main');
  46. $mcache->set('server_graph_' . $id, $html->arr['main'], false, 4);
  47. }
  48. ?>