forked from roshanisharma/nodequery-widget
-
Notifications
You must be signed in to change notification settings - Fork 0
/
widget.php
58 lines (44 loc) · 1.36 KB
/
widget.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
header('Content-Type: image/png');
/* Require NodeQuery Libraries */
require_once("nodequery/Server.php");
require_once("nodequery/Client.php");
require_once("nodequery/Request.php");
/* Require Widget Classes */
require_once("class/WidgetConfig.php");
require_once("class/WidgetDatabase.php");
require_once("class/BaseTheme.php");
$config = new WidgetConfig("conf.json");
$database = new WidgetDatabase($config->get("database"));
/* Require Theme Class */
require_once("themes/" . $config->themeClass . ".php");
$identifier = md5($config->themeClass . ":" . $config->serverName);
$database->add($identifier, time());
$nextUpdate = $database->get($identifier);
$fileName = "data/" . $identifier . ".png";
if ($nextUpdate > time())
{
readfile($fileName);
return;
}
$nodequery = new NodeQuery\Client($config->get("api_key"));
$servers = $nodequery->servers();
$database->set($identifier, time() + $config->get("interval"));
$database->save();
// Set the environment variable for GD.
putenv('GDFONTPATH=' . realpath('.'));
foreach ($servers["data"][0] as $data)
{
if ($data["name"] == $config->serverName)
{
$server = $data;
}
}
$theme = new $config->themeClass();
$theme->render($server, $config, $database);
$theme->canvas->setImageFormat('png');
$theme->canvas->writeImage($fileName);
/* Clean the output buffer before rendering. */
ob_clean();
echo $theme->canvas;
?>